01: /*
02: * Copyright 2005-2008 Kirill Grouchnikov, based on work by
03: * Sun Microsystems, Inc. All rights reserved.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18: */
19: package docrobot;
20:
21: import java.awt.Component;
22: import java.awt.Container;
23: import java.util.Map;
24:
25: import javax.swing.JComponent;
26:
27: import org.jvnet.lafwidget.LafWidgetUtilities;
28:
29: public class RobotUtilities {
30: /**
31: * Makes the specified component and all its descendants previewable.
32: *
33: * @param comp
34: * Component.
35: * @param dbSnapshot
36: * The "snapshot" map that will contain the original
37: * double-buffer status of the specified component and all its
38: * descendants. Key is {@link JComponent}, value is
39: * {@link Boolean}.
40: */
41: public static void makePreviewable(Component comp,
42: Map<Component, Boolean> dbSnapshot) {
43: if (comp instanceof JComponent) {
44: JComponent jcomp = (JComponent) comp;
45: // if (jcomp.getParent() instanceof CellRendererPane) {
46: // System.out.println(jcomp.getClass().getSimpleName() + ":"
47: // + jcomp.hashCode());
48: // }
49: dbSnapshot.put(jcomp, Boolean.valueOf(jcomp
50: .isDoubleBuffered()));
51: jcomp.setDoubleBuffered(false);
52: }
53: if (comp instanceof Container) {
54: Container cont = (Container) comp;
55: for (int i = 0; i < cont.getComponentCount(); i++)
56: RobotUtilities.makePreviewable(cont.getComponent(i),
57: dbSnapshot);
58: }
59: }
60:
61: /**
62: * Restores the regular (non-previewable) status of the specified component
63: * and all its descendants.
64: *
65: * @param comp
66: * Component.
67: * @param dbSnapshot
68: * The "snapshot" map that contains the original double-buffer
69: * status of the specified component and all its descendants. Key
70: * is {@link JComponent}, value is {@link Boolean}.
71: */
72: public static void restorePreviewable(Component comp,
73: Map<Component, Boolean> dbSnapshot) {
74: if (comp instanceof JComponent) {
75: JComponent jcomp = (JComponent) comp;
76: if (dbSnapshot.containsKey(comp)) {
77: jcomp.setDoubleBuffered(dbSnapshot.get(comp));
78: } else {
79: // this can happen in case the application has
80: // renderers (combos, ...). Take the property from the parent
81: Component parent = comp.getParent();
82: if (parent instanceof JComponent) {
83: jcomp.setDoubleBuffered(dbSnapshot.get(parent));
84: }
85: }
86: }
87: if (comp instanceof Container) {
88: Container cont = (Container) comp;
89: for (int i = 0; i < cont.getComponentCount(); i++)
90: RobotUtilities.restorePreviewable(cont.getComponent(i),
91: dbSnapshot);
92: }
93: }
94: }
|