Java Code Examples for javax.swing.RepaintManager#currentManager()

The following examples show how to use javax.swing.RepaintManager#currentManager() . 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: bug6608456.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 2
Source File: JXPanel.java    From littleluck with Apache License 2.0 5 votes vote down vote up
/**
 * Set the alpha transparency level for this component. This automatically
 * causes a repaint of the component.
 *
 * @param alpha must be a value between 0 and 1 inclusive.
 */
public void setAlpha(float alpha) {
    if (alpha < 0 || alpha > 1) {
        throw new IllegalArgumentException("Alpha must be between 0 and 1 inclusive");
    }

    if (this.alpha != alpha) {
        float oldAlpha = this.alpha;
        this.alpha = alpha;
        if (alpha > 0f && alpha < 1f) {
            if (oldAlpha == 1) {
                //it used to be 1, but now is not. Save the oldOpaque
                oldOpaque = isOpaque();
                setOpaque(false);
            }

            //TODO this was quite the controversial choice, in automatically
            //replacing the repaint manager. In retrospect, I'd probably
            //opt for making this a manual choice. There really isn't a clear
            //win, no matter the approach.
            RepaintManager manager = RepaintManager.currentManager(this);
            if (!manager.getClass().isAnnotationPresent(TranslucentRepaintManager.class)) {
                RepaintManager.setCurrentManager(new RepaintManagerX());
            }
        } else if (alpha == 1) {
            //restore the oldOpaque if it was true (since opaque is false now)
            if (oldOpaque) {
                setOpaque(true);
            }
        }
        firePropertyChange("alpha", oldAlpha, alpha);
        repaint();
    }
}
 
Example 3
Source File: bug6608456.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 4
Source File: JXPanel.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
 * Set the alpha transparency level for this component. This automatically
 * causes a repaint of the component.
 *
 * @param alpha must be a value between 0 and 1 inclusive.
 */
public void setAlpha(float alpha) {
    if (alpha < 0 || alpha > 1) {
        throw new IllegalArgumentException("Alpha must be between 0 and 1 inclusive");
    }

    if (this.alpha != alpha) {
        float oldAlpha = this.alpha;
        this.alpha = alpha;
        if (alpha > 0f && alpha < 1f) {
            if (oldAlpha == 1) {
                //it used to be 1, but now is not. Save the oldOpaque
                oldOpaque = isOpaque();
                setOpaque(false);
            }

            //TODO this was quite the controversial choice, in automatically
            //replacing the repaint manager. In retrospect, I'd probably
            //opt for making this a manual choice. There really isn't a clear
            //win, no matter the approach.
            RepaintManager manager = RepaintManager.currentManager(this);
            if (!manager.getClass().isAnnotationPresent(TranslucentRepaintManager.class)) {
                RepaintManager.setCurrentManager(new RepaintManagerX());
            }
        } else if (alpha == 1) {
            //restore the oldOpaque if it was true (since opaque is false now)
            if (oldOpaque) {
                setOpaque(true);
            }
        }
        firePropertyChange("alpha", oldAlpha, alpha);
        repaint();
    }
}
 
Example 5
Source File: bug6608456.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 6
Source File: bug6608456.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 7
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** @param comp The component to revalidate. */
public static void revalidateImmediately(Component comp) {
    if (comp != null) {
        RepaintManager mgr = RepaintManager.currentManager(comp);
        mgr.validateInvalidComponents();
        mgr.paintDirtyRegions();
    }
}
 
Example 8
Source File: bug6608456.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 9
Source File: bug6608456.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 10
Source File: bug6608456.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 11
Source File: bug6608456.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 12
Source File: HexOrDecimalInputTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: bug6608456.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    if (RepaintManager.currentManager(c) == this) {
        testFuture.defaultCalled();
    } else {
        testFuture.delegateCalled();
    }
    super.addDirtyRegion(c, x, y, w, h);
}
 
Example 14
Source File: DebugRepaintManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void register(JComponent component) {
    if (RepaintManager.currentManager(component) != INSTANCE) {
        RepaintManager.setCurrentManager(INSTANCE);
    }
    INSTANCE.addLogComponent(component);
}
 
Example 15
Source File: NbPresenterLeakTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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 16
Source File: PrintUtils.java    From ApprovalTests.Java with Apache License 2.0 4 votes vote down vote up
public static void disableDoubleBuffering(Component c)
{
  RepaintManager currentManager = RepaintManager.currentManager(c);
  currentManager.setDoubleBufferingEnabled(false);
}
 
Example 17
Source File: PrintUtilities.java    From bigtable-sql with Apache License 2.0 4 votes vote down vote up
public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);
}
 
Example 18
Source File: PrintUtilities.java    From bigtable-sql with Apache License 2.0 4 votes vote down vote up
public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
}
 
Example 19
Source File: RepaintManagerDoubleBufferMaximumSize.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest() {
    RepaintManager repaintManager = RepaintManager.currentManager(frame);
    textArea.append("DoubleBufferMaximumSize: " + repaintManager.getDoubleBufferMaximumSize() + "\n");
}
 
Example 20
Source File: DrawingArea.java    From VanetSim with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}