~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance-swingx/src/tools/java/docrobot/RobotUtilities.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2005-2008 Kirill Grouchnikov, based on work by
 
3
 * Sun Microsystems, Inc. All rights reserved.
 
4
 *
 
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.
 
9
 *
 
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
public class RobotUtilities {
 
28
        /**
 
29
         * Makes the specified component and all its descendants previewable.
 
30
         * 
 
31
         * @param comp
 
32
         *            Component.
 
33
         * @param dbSnapshot
 
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
 
37
         *            {@link Boolean}.
 
38
         */
 
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());
 
46
                        // }
 
47
                        dbSnapshot.put(jcomp, Boolean.valueOf(jcomp.isDoubleBuffered()));
 
48
                        jcomp.setDoubleBuffered(false);
 
49
                }
 
50
                if (comp instanceof Container) {
 
51
                        Container cont = (Container) comp;
 
52
                        for (int i = 0; i < cont.getComponentCount(); i++)
 
53
                                RobotUtilities
 
54
                                                .makePreviewable(cont.getComponent(i), dbSnapshot);
 
55
                }
 
56
        }
 
57
 
 
58
        /**
 
59
         * Restores the regular (non-previewable) status of the specified component
 
60
         * and all its descendants.
 
61
         * 
 
62
         * @param comp
 
63
         *            Component.
 
64
         * @param dbSnapshot
 
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}.
 
68
         */
 
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));
 
75
                        } else {
 
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));
 
81
                                }
 
82
                        }
 
83
                }
 
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),
 
88
                                                dbSnapshot);
 
89
                }
 
90
        }
 
91
}