KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > SwingUtilities


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: SwingUtilities.java,v $
11    Revision 1.15 2004/04/23 00:52:32 dannaab
12    Handle borders in a Swing-like way. Implement EmptyBorder & TitledBorder
13
14    Revision 1.14 2004/04/15 11:24:33 bobintetley
15    (Dan Naab) ComponentUI, UIDefaults/UIManager and Accessibility support.
16    (Antonio Weber) TableColumnModelListener implementation and support
17
18    Revision 1.13 2004/03/01 15:58:47 bobintetley
19    Various little bug fixes
20
21    Revision 1.12 2004/02/03 09:21:21 bobintetley
22    Fixed threading bug in invokeIn, and JComboBox hotkeys
23
24    Revision 1.11 2004/01/23 08:05:49 bobintetley
25    JComboBox fixes and better Action implementation
26
27    Revision 1.10 2004/01/20 15:52:56 bobintetley
28    Code from an anonymous developer
29
30    Revision 1.9 2004/01/20 07:38:05 bobintetley
31    Bug fixes and compatibility methods
32
33    Revision 1.8 2004/01/16 15:53:32 bobintetley
34    Many compatibility methods added to Container, Component, JInternalFrame,
35       UIManager, SwingUtilities, JTabbedPane, JPasswordField, JCheckBox
36       and JRadioButton.
37
38    Revision 1.7 2004/01/16 09:35:47 bobintetley
39    Full event dispatch thread support!
40
41    Revision 1.6 2003/12/22 14:17:30 bobintetley
42    One-off timer method and better layout management for tabbedPane
43
44    Revision 1.5 2003/12/17 15:24:33 bobintetley
45    Threading fixes
46
47    Revision 1.4 2003/12/16 15:47:45 bobintetley
48    Thread safety added to common methods
49
50    Revision 1.3 2003/12/16 14:51:16 bobintetley
51    Fixed hang when a window close event closes itself again
52
53    Revision 1.2 2003/12/14 09:13:38 bobintetley
54    Added CVS log to source headers
55
56 */

57
58 package swingwtx.swing;
59
60 import swingwt.awt.Component;
61 import swingwt.awt.Container;
62 import swingwtx.accessibility.Accessible;
63
64 public abstract class SwingUtilities implements SwingConstants {
65     
66     public static void invokeAndWait(Runnable JavaDoc run) {
67         invokeSync(run);
68     }
69     
70     public static void invokeLater(Runnable JavaDoc run) {
71         invokeAsync(run);
72     }
73     
74     /**
75      * Invokes a call asynchronously.
76      */

77     public static void invokeAsync(Runnable JavaDoc run) {
78         SwingWTUtils.checkEventDispatcher();
79         SwingWTUtils.getDisplay().asyncExec(run);
80     }
81     
82     /**
83      * Invokes a call synchronously. Since we use this a lot for SwingWT
84      * internals, we check to see if we are already on the dispatch thread
85      * (which is likely in many places) - if we are, we can just run
86      * the code right off without queuing it.
87      */

88     public static void invokeSync(Runnable JavaDoc run) {
89         SwingWTUtils.checkEventDispatcher();
90         if (Thread.currentThread().equals( SwingWTUtils.getDisplay().getThread() ))
91             run.run();
92         else
93             SwingWTUtils.getDisplay().syncExec(run);
94     }
95     
96     /**
97      * Invokes a call in a specified interval of time
98      */

99     public static void invokeIn(Runnable JavaDoc run, int milliseconds) {
100         SwingWTUtils.checkEventDispatcher();
101         SwingWTUtils.getDisplay().timerExec(milliseconds, run);
102     }
103     
104     public static void updateComponentTreeUI(Component c) {
105         if (c instanceof Container) ((Container) c).invalidate();
106         c.repaint();
107     }
108     
109     /**
110      * Searches the component hierarchy above comp for the first
111      * instance of class type c
112      */

113     public static Container getAncestorOfClass(Class JavaDoc c, Component comp) {
114         if(comp == null || c == null)
115             return null;
116         Container parent = comp.getParent();
117         while(parent != null && !(c.isInstance(parent)))
118             parent = parent.getParent();
119         return parent;
120     }
121     
122     // TODO: Implement Accessible support
123
public static int getAccessibleChildrenCount(Component component) { return 0; }
124     public static Accessible getAccessibleChild(Component component, int i) {
125         return component.getAccessibleContext().getAccessibleChild(i);
126     }
127         
128 }
129
Popular Tags