當前位置: 首頁>>代碼示例>>Java>>正文


Java RepaintManager.setDoubleBufferingEnabled方法代碼示例

本文整理匯總了Java中javax.swing.RepaintManager.setDoubleBufferingEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Java RepaintManager.setDoubleBufferingEnabled方法的具體用法?Java RepaintManager.setDoubleBufferingEnabled怎麽用?Java RepaintManager.setDoubleBufferingEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.RepaintManager的用法示例。


在下文中一共展示了RepaintManager.setDoubleBufferingEnabled方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
    if (pageIndex >= getComponentCount()) {
        mLastPage = -1;
        return NO_SUCH_PAGE;
    }

    // We do the following trick to avoid going through the work twice,
    // as we are called twice for each page, the first of which doesn't
    // seem to be used.
    if (mLastPage != pageIndex) {
        mLastPage = pageIndex;
    } else {
        Component comp = getComponent(pageIndex);
        RepaintManager mgr = RepaintManager.currentManager(comp);
        boolean saved = mgr.isDoubleBufferingEnabled();
        mgr.setDoubleBufferingEnabled(false);
        mOkToPaint = true;
        comp.print(graphics);
        mOkToPaint = false;
        mgr.setDoubleBufferingEnabled(saved);
    }
    return PAGE_EXISTS;
}
 
開發者ID:richardwilkes,項目名稱:gcs,代碼行數:25,代碼來源:CharacterSheet.java

示例2: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
	if (pageIndex > 0) {
		return NO_SUCH_PAGE;
	}
	else {
		Graphics2D g2d = (Graphics2D) g;
		RepaintManager currentManager = RepaintManager.currentManager(this);
		currentManager.setDoubleBufferingEnabled(false);
		Rectangle bounds = getContentBounds(Config.getInstance().getPrintPadding(), getGridElements());
		g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
		AffineTransform t = g2d.getTransform();
		double scale = Math.min(pageFormat.getImageableWidth() / bounds.width,
				pageFormat.getImageableHeight() / bounds.height);
		if (scale < 1) {
			t.scale(scale, scale);
			g2d.setTransform(t);
		}
		g2d.translate(-bounds.x, -bounds.y);
		paint(g2d);
		currentManager = RepaintManager.currentManager(this);
		currentManager.setDoubleBufferingEnabled(true);
		return PAGE_EXISTS;
	}
}
 
開發者ID:umlet,項目名稱:umlet,代碼行數:26,代碼來源:DrawPanel.java

示例3: paintImmediately

import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
 * Immediately repaints the surface.
 *
 * <p/>It's possible to turn off double-buffering for just the repaint calls invoked directly on the non double
 * buffered component. This can be done by overriding paintImmediately() (which is called as a result of repaint)
 * and getting the current RepaintManager and turning off double buffering in the RepaintManager before calling
 * super.paintImmediately(g).
 *
 * @param x The X coord to start painting at.
 * @param y The Y coord to start painting at.
 * @param w The width of the region to paint.
 * @param h The height of the region to paint.
 */
public void paintImmediately(int x, int y, int w, int h)
{
    RepaintManager repaintManager = null;
    boolean save = true;

    if (!isDoubleBuffered())
    {
        repaintManager = RepaintManager.currentManager(this);
        save = repaintManager.isDoubleBufferingEnabled();
        repaintManager.setDoubleBufferingEnabled(false);
    }

    super.paintImmediately(x, y, w, h);

    if (repaintManager != null)
    {
        repaintManager.setDoubleBufferingEnabled(save);
    }
}
 
開發者ID:rupertlssmith,項目名稱:lojix,代碼行數:33,代碼來源:Surface.java

示例4: paintWidget

import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
 * Paints the component widget.
 */
@Override
protected final void paintWidget() {
    RepaintManager rm = RepaintManager.currentManager(null);
    boolean isDoubleBuffered = component instanceof JComponent && rm.isDoubleBufferingEnabled();
    if (isDoubleBuffered) {
        rm.setDoubleBufferingEnabled(false);
    }
    Graphics2D graphics = getGraphics();
    Rectangle bounds = getClientArea();
    AffineTransform previousTransform = graphics.getTransform();
    graphics.translate(bounds.x, bounds.y);
    //double zoomFactor = getScene().getZoomFactor();
    //graphics.scale(1 / zoomFactor, 1 / zoomFactor);
    if (componentVisible) {
        componentWrapper.doPaint(graphics);
    } else {
        component.paint(graphics);
    }
    graphics.setTransform(previousTransform);
    if (isDoubleBuffered) {
        rm.setDoubleBufferingEnabled(true);
    }
}
 
開發者ID:Depter,項目名稱:JRLib,代碼行數:27,代碼來源:JRLibComponentWidget.java

示例5: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(java.awt.Graphics g, PageFormat pf, int page) throws PrinterException {
    if (page > 0) {
        // We have only one page, and 'page' is zero-based
        return NO_SUCH_PAGE;
    }

    Graphics2D g2d = (Graphics2D) g;
    
    // User (0,0) is typically outside the imageable area, so we must
    // translate by the X and Y values in the PageFormat to avoid clipping
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    // Scale plots to paper size.
    double scaleX = pf.getImageableWidth() / contentPane.getWidth();
    double scaleY = pf.getImageableHeight() / contentPane.getHeight();
    g2d.scale(scaleX, scaleY);

    // Disable double buffering
    RepaintManager currentManager = RepaintManager.currentManager(this);
    currentManager.setDoubleBufferingEnabled(false);

    // Now we perform our rendering
    contentPane.printAll(g);

    // Enable double buffering
    currentManager.setDoubleBufferingEnabled(true);

    // tell the caller that this page is part of the printed document
    return PAGE_EXISTS;
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:32,代碼來源:PlotPanel.java

示例6: getPages

import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public PrintPage[][] getPages(final int width, final int height, double d) {
    int printMaxHor = panel.getMaxWidth() / width + (panel.getMaxWidth() % width != 0 ? 1 : 0);
    int printMaxVert = panel.getMaxHeight() / height + (panel.getMaxHeight() % height != 0 ? 1 : 0);
    PrintPage[][] res = new PrintPage[printMaxHor][printMaxVert];
    for (int pv = 0; pv < printMaxVert; pv++) {
        for (int ph = 0; ph < printMaxHor; ph++) {
            final int pageHor = ph;
            final int pageVer = pv;
            PrintPage pp = new PrintPage() {
                @Override
                public void print(Graphics graphics) {
                    if (!(graphics instanceof Graphics2D)) {
                        return;
                    }
                    Graphics2D g2d = (Graphics2D) graphics;

                    AffineTransform tx = g2d.getTransform();

                    g2d.translate(-pageHor * width, -pageVer * height);

                    RepaintManager currentManager = RepaintManager.currentManager(panel);
                    currentManager.setDoubleBufferingEnabled(false);
                    g2d.setColor(Color.BLACK);
                    panel.paint(g2d);
                    currentManager.setDoubleBufferingEnabled(true);

                    g2d.setTransform(tx);
                }
            };
            res[pv][ph] = pp;
        }
    }
    return res;
}
 
開發者ID:vrsl,項目名稱:MDD-JPA,代碼行數:36,代碼來源:ErdModellerVisualElement.java

示例7: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
		throws PrinterException {
	// Get current page printing board
	TBoard printBoard = getBoard();
	// Get board bounds
	Dimension bounds = TBoardConstants.getSize(printBoard
			.getAttributes(printBoard.getModel()));
	// Transform graphics to 2D
	Graphics2D g2 = (Graphics2D) graphics;
	// Scale the image to fit the impession size
	double scaleWidth = pageFormat.getImageableWidth() / bounds.getWidth();
	double scaleHeight = pageFormat.getImageableHeight() / bounds.getHeight();
	// Set the scale size to the minimum of both
	if (scaleWidth > scaleHeight)
		scaleWidth = scaleHeight;
	else
		scaleHeight = scaleWidth;
	g2.scale(scaleWidth, scaleHeight);
	// Translate the graphics origin
	g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
	// Disable doube buffering
	RepaintManager currentManager = RepaintManager
			.currentManager(printBoard);
	currentManager.setDoubleBufferingEnabled(false);
	// Print
	printBoard.paint(g2);
	g2.translate(0f,0f);
	g2.drawString(printBoard.toString(), 30, 38);
	// Enable double buffering
	currentManager.setDoubleBufferingEnabled(true);
	return PAGE_EXISTS;
}
 
開發者ID:ProgettoRadis,項目名稱:ArasuiteIta,代碼行數:33,代碼來源:TBoardContainer.java

示例8: ChunkVisualizerMainForm

import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
 * Create the application.
 */
public ChunkVisualizerMainForm() {
    initialize();
    final RepaintManager currentManager = RepaintManager
            .currentManager(chunkInfoPanel);
    currentManager.setDoubleBufferingEnabled(true);
}
 
開發者ID:hapm,項目名稱:swu,代碼行數:10,代碼來源:ChunkVisualizerMainForm.java

示例9: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
	// For this helper, assume only 1 page for now
	if (pageIndex > 0)
		return NO_SUCH_PAGE;

	((Graphics2D)g).translate(pageFormat.getImageableX(), pageFormat.getImageableY());
	// turn off double-buffering (worsens speed/quality of printig) during paint, then reenable
	RepaintManager currentManager = RepaintManager.currentManager(component);
	currentManager.setDoubleBufferingEnabled(false);
	component.paint(g);
	currentManager.setDoubleBufferingEnabled(true);
	return PAGE_EXISTS;
}
 
開發者ID:astangl,項目名稱:crostex,代碼行數:15,代碼來源:PrintHelper.java

示例10: testLeakingNbPresenterDescriptor

import javax.swing.RepaintManager; //導入方法依賴的package包/類
@RandomlyFails // NB-Core-Build #1189
public void testLeakingNbPresenterDescriptor () throws InterruptedException, InvocationTargetException {
    try {
        Class.forName("java.lang.AutoCloseable");
    } catch (ClassNotFoundException ex) {
        // this test is known to fail due to JDK bugs 7070542 & 7072167
        // which are unlikely to be fixed on JDK6. Thus, if AutoCloseable
        // is not present, skip the test
        return;
    }
    
    WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels(), null);
    wizardDescriptor.setModal (false);
    Dialog dialog = DialogDisplayer.getDefault ().createDialog (wizardDescriptor);
    WeakReference<WizardDescriptor> w = new WeakReference<WizardDescriptor> (wizardDescriptor);
    
    SwingUtilities.invokeAndWait (new EDTJob(dialog, true));
    assertShowing("button is visible", true, dialog);
    SwingUtilities.invokeAndWait (new EDTJob(dialog, false));
    assertShowing("button is no longer visible", false, dialog);
    boolean cancelled = wizardDescriptor.getValue() !=
        WizardDescriptor.FINISH_OPTION;
    Dialog d = new JDialog();
    
    // workaround for JDK bug 6575402
    JPanel p = new JPanel();
    d.setLayout(new BorderLayout());
    d.add(p, BorderLayout.CENTER);
    JButton btn = new JButton("Button");
    p.add(btn, BorderLayout.NORTH);
    
    SwingUtilities.invokeAndWait (new EDTJob(d, true));
    assertShowing("button is visible", true, btn);
    dialog.setBounds(Utilities.findCenterBounds(dialog.getSize()));
    SwingUtilities.invokeAndWait (new EDTJob(d, false));
    assertShowing("button is no longer visible", false, btn);

    assertNull ("BufferStrategy was disposed.", dialog.getBufferStrategy ());

    RepaintManager rm = RepaintManager.currentManager(dialog);
    rm.setDoubleBufferingEnabled(!rm.isDoubleBufferingEnabled());
    rm.setDoubleBufferingEnabled(!rm.isDoubleBufferingEnabled());
    
    dialog = null;
    wizardDescriptor = null;
    
    SwingUtilities.invokeAndWait (new Runnable() {

        @Override
        public void run() {
            Frame f = new Frame();
            f.setPreferredSize( new Dimension(100,100));
            f.setVisible( true );
            JDialog dlg = new JDialog(f);
            dlg.setVisible(true);
        }
    });

    assertGC ("Dialog disappears.", w);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:61,代碼來源:NbPresenterLeakTest.java

示例11: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
 * Prints the specified page on the specified graphics using <code>pageFormat</code> for the page
 * format.
 * 
 * @param g The graphics to paint the graph on.
 * @param printFormat The page format to use for printing.
 * @param page The page to print
 * @return Returns {@link Printable#PAGE_EXISTS} or {@link Printable#NO_SUCH_PAGE}.
 */
public int print(Graphics g, PageFormat printFormat, int page) {
  int result = NO_SUCH_PAGE;

  // Disables double-buffering before printing
  RepaintManager currentManager = RepaintManager.currentManager(mxGraphComponent.this);
  currentManager.setDoubleBufferingEnabled(false);

  // Gets the current state of the view
  mxGraphView view = graph.getView();

  // Stores the old state of the view
  boolean eventsEnabled = view.isEventsEnabled();
  mxPoint translate = view.getTranslate();

  // Disables firing of scale events so that there is no
  // repaint or update of the original graph while pages
  // are being printed
  view.setEventsEnabled(false);

  // Uses the view to create temporary cell states for each cell
  mxTemporaryCellStates tempStates = new mxTemporaryCellStates(view, 1 / pageScale);

  try {
    view.setTranslate(new mxPoint(0, 0));

    mxGraphics2DCanvas canvas = createCanvas();
    canvas.setGraphics((Graphics2D) g);
    canvas.setScale(1 / pageScale);

    view.revalidate();

    mxRectangle graphBounds = graph.getGraphBounds();
    Dimension pSize =
        new Dimension((int) Math.ceil(graphBounds.getX() + graphBounds.getWidth()) + 1,
            (int) Math.ceil(graphBounds.getY() + graphBounds.getHeight()) + 1);

    int w = (int) (printFormat.getImageableWidth());
    int h = (int) (printFormat.getImageableHeight());
    int cols = (int) Math.max(Math.ceil((double) (pSize.width - 5) / (double) w), 1);
    int rows = (int) Math.max(Math.ceil((double) (pSize.height - 5) / (double) h), 1);

    if (page < cols * rows) {
      int dx = (int) ((page % cols) * printFormat.getImageableWidth());
      int dy = (int) (Math.floor(page / cols) * printFormat.getImageableHeight());

      g.translate(-dx + (int) printFormat.getImageableX(),
          -dy + (int) printFormat.getImageableY());
      g.setClip(dx, dy, (int) (dx + printFormat.getWidth()),
          (int) (dy + printFormat.getHeight()));

      graph.drawGraph(canvas);

      result = PAGE_EXISTS;
    }
  } finally {
    view.setTranslate(translate);

    tempStates.destroy();
    view.setEventsEnabled(eventsEnabled);

    // Enables double-buffering after printing
    currentManager.setDoubleBufferingEnabled(true);
  }

  return result;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:76,代碼來源:mxGraphComponent.java

示例12: print

import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
 * Prints the specified page on the specified graphics using
 * <code>pageFormat</code> for the page format.
 * 
 * @param g
 *            The graphics to paint the graph on.
 * @param printFormat
 *            The page format to use for printing.
 * @param page
 *            The page to print
 * @return Returns {@link Printable#PAGE_EXISTS} or
 *         {@link Printable#NO_SUCH_PAGE}.
 */
public int print(Graphics g, PageFormat printFormat, int page) {
	int result = NO_SUCH_PAGE;

	// Disables double-buffering before printing
	RepaintManager currentManager = RepaintManager.currentManager(mxGraphComponent.this);
	currentManager.setDoubleBufferingEnabled(false);

	// Gets the current state of the view
	mxGraphView view = graph.getView();

	// Stores the old state of the view
	boolean eventsEnabled = view.isEventsEnabled();
	mxPoint translate = view.getTranslate();

	// Disables firing of scale events so that there is no
	// repaint or update of the original graph while pages
	// are being printed
	view.setEventsEnabled(false);

	// Uses the view to create temporary cell states for each cell
	mxTemporaryCellStates tempStates = new mxTemporaryCellStates(view, 1 / pageScale);

	try {
		view.setTranslate(new mxPoint(0, 0));

		mxGraphics2DCanvas canvas = createCanvas();
		canvas.setGraphics((Graphics2D) g);
		canvas.setScale(1 / pageScale);

		view.revalidate();

		mxRectangle graphBounds = graph.getGraphBounds();
		Dimension pSize = new Dimension((int) Math.ceil(graphBounds.getX() + graphBounds.getWidth()) + 1,
				(int) Math.ceil(graphBounds.getY() + graphBounds.getHeight()) + 1);

		int w = (int) (printFormat.getImageableWidth());
		int h = (int) (printFormat.getImageableHeight());
		int cols = (int) Math.max(Math.ceil((double) (pSize.width - 5) / (double) w), 1);
		int rows = (int) Math.max(Math.ceil((double) (pSize.height - 5) / (double) h), 1);

		if (page < cols * rows) {
			int dx = (int) ((page % cols) * printFormat.getImageableWidth());
			int dy = (int) (Math.floor(page / cols) * printFormat.getImageableHeight());

			g.translate(-dx + (int) printFormat.getImageableX(), -dy + (int) printFormat.getImageableY());
			g.setClip(dx, dy, (int) (dx + printFormat.getWidth()), (int) (dy + printFormat.getHeight()));

			graph.drawGraph(canvas);

			result = PAGE_EXISTS;
		}
	} finally {
		view.setTranslate(translate);

		tempStates.destroy();
		view.setEventsEnabled(eventsEnabled);

		// Enables double-buffering after printing
		currentManager.setDoubleBufferingEnabled(true);
	}

	return result;
}
 
開發者ID:md-k-sarker,項目名稱:OWLAx,代碼行數:77,代碼來源:mxGraphComponent.java

示例13: disableDoubleBuffering

import javax.swing.RepaintManager; //導入方法依賴的package包/類
public static void disableDoubleBuffering(Component c) {
  RepaintManager currentManager = RepaintManager.currentManager(c);
  currentManager.setDoubleBufferingEnabled(false);
}
 
開發者ID:ddarriba,項目名稱:jmodeltest2,代碼行數:5,代碼來源:PrintUtilities.java

示例14: enableDoubleBuffering

import javax.swing.RepaintManager; //導入方法依賴的package包/類
public static void enableDoubleBuffering(Component c) {
  RepaintManager currentManager = RepaintManager.currentManager(c);
  currentManager.setDoubleBufferingEnabled(true);
}
 
開發者ID:ddarriba,項目名稱:jmodeltest2,代碼行數:5,代碼來源:PrintUtilities.java

示例15: disableDoubleBuffering

import javax.swing.RepaintManager; //導入方法依賴的package包/類
public static void disableDoubleBuffering(Component c)
{
	RepaintManager currentManager = RepaintManager.currentManager(c);
	currentManager.setDoubleBufferingEnabled(false);
}
 
開發者ID:TOMIGalway,項目名稱:cmoct-sourcecode,代碼行數:6,代碼來源:PrintUtilities.java


注:本文中的javax.swing.RepaintManager.setDoubleBufferingEnabled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。