下面列出了怎么用javax.swing.RepaintManager的API类实例代码及写法,或者点击链接到github查看源代码。
public void testPropertySheetRepaintsCellOnPropertyChange() throws Exception {
if (!canSafelyRunFocusTests()) {
return;
}
Node n = new TNode(new SingleTagEditor());
setCurrentNode(n, ps);
Rectangle test = ps.table.getCellRect(1, 1, true);
RM rm = new RM(test, ps.table);
RepaintManager.setCurrentManager(rm);
sleep();
sleep();
Node.Property prop = n.getPropertySets()[0].getProperties()[0];
prop.setValue("new value");
Thread.currentThread().sleep(1000);
sleep();
rm.assertRectRepainted();
}
@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;
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
/**
* Retrieve the accessor object for the RepaintManager class.
*/
public static RepaintManagerAccessor getRepaintManagerAccessor() {
if (repaintManagerAccessor == null) {
unsafe.ensureClassInitialized(RepaintManager.class);
}
return repaintManagerAccessor;
}
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
public static void setDelegateRepaintManager(JComponent component,
RepaintManager repaintManager) {
/* setting up flag in AppContext to speed up lookups in case
* there are no delegate RepaintManagers used.
*/
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
Boolean.TRUE);
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
repaintManager);
}
@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);
}
@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);
}
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
public static void setDelegateRepaintManager(JComponent component,
RepaintManager repaintManager) {
/* setting up flag in AppContext to speed up lookups in case
* there are no delegate RepaintManagers used.
*/
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
Boolean.TRUE);
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
repaintManager);
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
/**
* Retrieve the accessor object for the RepaintManager class.
*/
public static RepaintManagerAccessor getRepaintManagerAccessor() {
if (repaintManagerAccessor == null) {
unsafe.ensureClassInitialized(RepaintManager.class);
}
return repaintManagerAccessor;
}
@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);
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
/**
* Retrieve the accessor object for the RepaintManager class.
*/
public static RepaintManagerAccessor getRepaintManagerAccessor() {
if (repaintManagerAccessor == null) {
unsafe.ensureClassInitialized(RepaintManager.class);
}
return repaintManagerAccessor;
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
public static void setDelegateRepaintManager(JComponent component,
RepaintManager repaintManager) {
/* setting up flag in AppContext to speed up lookups in case
* there are no delegate RepaintManagers used.
*/
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
Boolean.TRUE);
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
repaintManager);
}
/**
* Retrieve the accessor object for the RepaintManager class.
*/
public static RepaintManagerAccessor getRepaintManagerAccessor() {
if (repaintManagerAccessor == null) {
unsafe.ensureClassInitialized(RepaintManager.class);
}
return repaintManagerAccessor;
}
private static boolean registerDelegate(JComponent c,
RepaintManager repaintManager) {
boolean rv = false;
try {
Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
Method method = clazz.getMethod("setDelegateRepaintManager",
JComponent.class, RepaintManager.class);
method.invoke(clazz, c, repaintManager);
rv = true;
} catch (Exception ignore) {
}
return rv;
}
/**
* Initial point of the next frame (invoked by the animation timer).
*
* @param e action event.
*/
@Override
public void actionPerformed(ActionEvent e) {
updatePhase();
RepaintManager manager = RepaintManager.currentManager(glassPane);
manager.markCompletelyDirty(glassPane);
manager.paintDirtyRegions();
}
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
public static void setDelegateRepaintManager(JComponent component,
RepaintManager repaintManager) {
/* setting up flag in AppContext to speed up lookups in case
* there are no delegate RepaintManagers used.
*/
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
Boolean.TRUE);
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
repaintManager);
}
private static void doShowBusyCursor(boolean busy) {
JFrame mainWindow = (JFrame)WindowManager.getDefault().getMainWindow();
if(busy){
RepaintManager.currentManager(mainWindow).paintDirtyRegions();
mainWindow.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
mainWindow.getGlassPane().setVisible(true);
mainWindow.repaint();
} else {
mainWindow.getGlassPane().setVisible(false);
mainWindow.getGlassPane().setCursor(null);
mainWindow.repaint();
}
}
/**
* Restore stored scroll position.
*/
private void restoreScrollPosition(boolean delayScrollWithMarkingDirtyRegion) {
if (visibleTreePosition != null) {
JTree tree = getJTree();
if (tree != null) {
int row = tree.getRowForPath(visibleTreePosition.getPath());
if (row != -1) {
Rectangle bounds = tree.getRowBounds(row);
if (bounds != null) {
int scrollY = bounds.y - visibleTreePosition.getOffset();
JViewport viewport = mainScrollPane.getViewport();
Rectangle rect = viewport.getViewRect();
rect.y = scrollY;
if (!rect.isEmpty()) {
JComponent view = (JComponent) viewport.getView();
if (delayScrollWithMarkingDirtyRegion) {
RepaintManager.currentManager(viewport).addDirtyRegion(
view,
rect.x, rect.x, rect.width, rect.height);
}
ignoreScrollAdjustment = true;
try {
view.scrollRectToVisible(
rect);
} finally {
ignoreScrollAdjustment = false;
}
}
}
}
}
}
}
/**
* A helper method that performs some cleanup and disconnects the component from the AWT and the Swing-Framework to
* avoid memory-leaks.
*/
protected final void cleanUp() {
if ( component instanceof JComponent && isOwnPeerConnected() == false ) {
final JComponent jc = (JComponent) component;
RepaintManager.currentManager( jc ).removeInvalidComponent( jc );
RepaintManager.currentManager( jc ).markCompletelyClean( jc );
}
contentPane.removeAll();
RepaintManager.currentManager( contentPane ).removeInvalidComponent( contentPane );
RepaintManager.currentManager( contentPane ).markCompletelyClean( contentPane );
peerSupply.dispose();
}
/**
* Retrieve the accessor object for the RepaintManager class.
*/
public static RepaintManagerAccessor getRepaintManagerAccessor() {
if (repaintManagerAccessor == null) {
unsafe.ensureClassInitialized(RepaintManager.class);
}
return repaintManagerAccessor;
}
@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);
}
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
public static void setDelegateRepaintManager(JComponent component,
RepaintManager repaintManager) {
/* setting up flag in AppContext to speed up lookups in case
* there are no delegate RepaintManagers used.
*/
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
Boolean.TRUE);
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
repaintManager);
}
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
public static void setDelegateRepaintManager(JComponent component,
RepaintManager repaintManager) {
/* setting up flag in AppContext to speed up lookups in case
* there are no delegate RepaintManagers used.
*/
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
Boolean.TRUE);
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
repaintManager);
}
@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);
}
/**
* Retrieve the accessor object for the RepaintManager class.
*/
public static RepaintManagerAccessor getRepaintManagerAccessor() {
if (repaintManagerAccessor == null) {
unsafe.ensureClassInitialized(RepaintManager.class);
}
return repaintManagerAccessor;
}