2
* Copyright 2005-2008 Kirill Grouchnikov, based on work by
3
* Sun Microsystems, Inc. All rights reserved.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
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.
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
21
import java.awt.Component;
22
import java.awt.Container;
25
import javax.swing.JComponent;
27
public class RobotUtilities {
29
* Makes the specified component and all its descendants previewable.
34
* The "snapshot" map that will contain the original
35
* double-buffer status of the specified component and all its
36
* descendants. Key is {@link JComponent}, value is
39
public static void makePreviewable(Component comp,
40
Map<Component, Boolean> dbSnapshot) {
41
if (comp instanceof JComponent) {
42
JComponent jcomp = (JComponent) comp;
43
// if (jcomp.getParent() instanceof CellRendererPane) {
44
// System.out.println(jcomp.getClass().getSimpleName() + ":"
45
// + jcomp.hashCode());
47
dbSnapshot.put(jcomp, Boolean.valueOf(jcomp.isDoubleBuffered()));
48
jcomp.setDoubleBuffered(false);
50
if (comp instanceof Container) {
51
Container cont = (Container) comp;
52
for (int i = 0; i < cont.getComponentCount(); i++)
54
.makePreviewable(cont.getComponent(i), dbSnapshot);
59
* Restores the regular (non-previewable) status of the specified component
60
* and all its descendants.
65
* The "snapshot" map that contains the original double-buffer
66
* status of the specified component and all its descendants. Key
67
* is {@link JComponent}, value is {@link Boolean}.
69
public static void restorePreviewable(Component comp,
70
Map<Component, Boolean> dbSnapshot) {
71
if (comp instanceof JComponent) {
72
JComponent jcomp = (JComponent) comp;
73
if (dbSnapshot.containsKey(comp)) {
74
jcomp.setDoubleBuffered(dbSnapshot.get(comp));
76
// this can happen in case the application has
77
// renderers (combos, ...). Take the property from the parent
78
Component parent = comp.getParent();
79
if (parent instanceof JComponent) {
80
jcomp.setDoubleBuffered(dbSnapshot.get(parent));
84
if (comp instanceof Container) {
85
Container cont = (Container) comp;
86
for (int i = 0; i < cont.getComponentCount(); i++)
87
RobotUtilities.restorePreviewable(cont.getComponent(i),