Java Code Examples for javax.swing.RepaintManager#setDoubleBufferingEnabled()
The following examples show how to use
javax.swing.RepaintManager#setDoubleBufferingEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CharacterSheet.java From gcs with Mozilla Public License 2.0 | 6 votes |
@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) { 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); } else { mLastPage = pageIndex; } return PAGE_EXISTS; }
Example 2
Source File: HexOrDecimalInputTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testCustomPaint() { HexOrDecimalInput input = new HexOrDecimalInput(); RepaintManager repaintManager = RepaintManager.currentManager(input); repaintManager.setDoubleBufferingEnabled(false); SpyPrintStream spy = new SpyPrintStream(); DebugGraphics.setLogStream(spy); DebugGraphics debugGraphics = new DebugGraphics(scratchGraphics()); debugGraphics.setDebugOptions(DebugGraphics.LOG_OPTION); Graphics2D g2d = new Graphics2DAdapter(debugGraphics); input.paintComponent(g2d); assertThat(spy.toString(), CoreMatchers.containsString("Dec")); spy.reset(); input.setHexMode(); input.paintComponent(g2d); assertThat(spy.toString(), CoreMatchers.containsString("Hex")); spy.reset(); input.setDecimalMode(); input.paintComponent(g2d); assertThat(spy.toString(), CoreMatchers.containsString("Dec")); }
Example 3
Source File: mxGraphComponent.java From blog-codes with Apache License 2.0 | 4 votes |
/** * 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; }
Example 4
Source File: NbPresenterLeakTest.java From netbeans with Apache License 2.0 | 4 votes |
@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); }
Example 5
Source File: PrintUtilities.java From bigtable-sql with Apache License 2.0 | 4 votes |
public static void disableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager(c); currentManager.setDoubleBufferingEnabled(false); }
Example 6
Source File: PrintUtilities.java From bigtable-sql with Apache License 2.0 | 4 votes |
public static void enableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager(c); currentManager.setDoubleBufferingEnabled(true); }
Example 7
Source File: PrintUtils.java From ApprovalTests.Java with Apache License 2.0 | 4 votes |
public static void disableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager(c); currentManager.setDoubleBufferingEnabled(false); }
Example 8
Source File: PrintUtils.java From ApprovalTests.Java with Apache License 2.0 | 4 votes |
public static void enableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager(c); currentManager.setDoubleBufferingEnabled(true); }
Example 9
Source File: DrawingArea.java From VanetSim with GNU General Public License v3.0 | 3 votes |
/** * Setting the <code>RepaintManager</code> like seen * <a href=http://java.sun.com/products/java-media/2D/samples/index.html>on the official examples for Java2D</a> * (link last time checked on 12.08.2008).<br> * This imitates the "On Screen" method used there and in some cases drastically improves performance (even when * DoubleBuffering of this <code>JComponent</code> is off the DoubleBuffering might still be on because the * DoubleBuffering is inherited from the main <code>JFrame</code>!). * * @param x the x coordinate for the bounding box to repaint * @param y the y coordinate for the bounding box to repaint * @param width the width * @param height the height */ public void paintImmediately(int x, int y, int width, int height){ RepaintManager repaintManager = null; boolean save = true; if (!isDoubleBuffered()) { repaintManager = RepaintManager.currentManager(this); save = repaintManager.isDoubleBufferingEnabled(); repaintManager.setDoubleBufferingEnabled(false); } super.paintImmediately(x, y, width, height); if (repaintManager != null) repaintManager.setDoubleBufferingEnabled(save); }