KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > JRootPane


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: JRootPane.java,v $
11    Revision 1.2 2004/04/28 08:38:12 bobintetley
12    Hierarchy fixes, code cleanup for base classes, additional javadocs and use of flag to identify JComponent descendants with peers
13
14    Revision 1.1 2004/03/22 15:10:22 bobintetley
15    JRootPane and JLayeredPane implementation
16
17
18 */

19
20 package swingwtx.swing;
21
22 import swingwt.awt.*;
23
24 /**
25  * RootPane implementation. Handles containing of all other components
26  * for windows and internal frames. Manages default buttons and a
27  * few other bits and bobs. Ok, so the hierarchy has a bit more in
28  * it than "real" swing, but it shouldn't cause any problems.
29  *
30  * @author Robin Rawson-Tetley
31  */

32 public class JRootPane extends JPanel {
33     
34     public static final int NONE = 0;
35     public static final int FRAME = 1;
36     public static final int PLAIN_DIALOG = 2;
37     public static final int INFORMATION_DIALOG = 3;
38     public static final int ERROR_DIALOG = 4;
39     public static final int COLOR_CHOOSER_DIALOG = 5;
40     public static final int FILE_CHOOSER_DIALOG = 6;
41     public static final int QUESTION_DIALOG = 7;
42     public static final int WARNING_DIALOG = 8;
43     
44     protected int windowDecorationStyle = 0;
45     protected Container contentPane = null;
46     protected JMenuBar menu = null;
47     protected JButton defaultButton = null;
48     protected Component glassPane = null; // Here for completeness, but SWT doesn't need transparent
49
// component overlay for catching keystrokes since we're already native
50
protected JLayeredPane layeredPane = null;
51     protected Window parentWindow = null;
52     
53     public JRootPane() {
54         this(null);
55     }
56     
57     public JRootPane(Window parentWindow) {
58         this.parentWindow = parentWindow;
59         setLayout(new JRootPane.RootPaneLayout());
60         setGlassPane(createGlassPane());
61         setLayeredPane(createLayeredPane());
62         setContentPane(createContentPane());
63     }
64     
65     protected Container createContentPane() {
66         JPanel content = new JPanel();
67         content.setLayout(new BorderLayout()); // Default BorderLayout for root panes
68
return content;
69     }
70     
71     protected Component createGlassPane() {
72         return new JPanel();
73     }
74     
75     protected JLayeredPane createLayeredPane() {
76         return new JLayeredPane();
77     }
78     
79     public int getWindowDecorationStyle() {
80         return windowDecorationStyle;
81     }
82     
83     public void setWindowDecorationStyle(int windowStyle) {
84         windowDecorationStyle = windowStyle;
85     }
86     
87     public Container getContentPane() {
88         return contentPane;
89     }
90     
91     public void setContentPane(Container content) {
92         if (contentPane != null)
93             this.removeAll();
94         contentPane = content;
95         this.add(contentPane);
96     }
97     
98     public Component getGlassPane() {
99         return glassPane;
100     }
101     
102     public JLayeredPane getLayeredPane() {
103         return layeredPane;
104     }
105     
106     public void setGlassPane(Component glassPane) {
107         this.glassPane = glassPane;
108     }
109     
110     public void setLayeredPane(JLayeredPane layeredPane) {
111         this.layeredPane = layeredPane;
112     }
113     
114     public void setJMenuBar(final JMenuBar menu) {
115         this.menu = menu;
116         try {
117             SwingUtilities.invokeSync(new Runnable JavaDoc() {
118                 public void run() {
119                     try {
120                         menu.setSwingWTParent(((org.eclipse.swt.widgets.Shell)parentWindow.getPeer()));
121                     }
122                     catch (Exception JavaDoc e) {
123                         e.printStackTrace();
124                     }
125                 }
126             });
127         }
128         catch (Exception JavaDoc e) {
129             e.printStackTrace();
130         }
131     }
132     
133     public void setMenuBar(MenuBar menu) { setJMenuBar((JMenuBar) menu); }
134     public MenuBar getMenuBar() { return (MenuBar) menu; }
135     public JMenuBar getJMenuBar() { return this.menu; }
136     
137     public JButton getDefaultButton() { return defaultButton; }
138     
139     public void setDefaultButton(final JButton defaultButton) {
140         this.defaultButton = defaultButton;
141         defaultButton.setDefaultButtonParent(this);
142         SwingUtilities.invokeSync(new Runnable JavaDoc() {
143             public void run() {
144                 if (SwingWTUtils.isSWTControlAvailable(peer) && defaultButton.getPeer() != null)
145                     peer.getShell().setDefaultButton((org.eclipse.swt.widgets.Button) defaultButton.getPeer());
146             }
147         });
148     }
149     
150     /**
151      * Since components live in this on all frames, returns true as the
152      * root for which validation down should be performed when laying
153      * out components
154      */

155     public boolean isValidateRoot() {
156         return true;
157     }
158     
159     /** Returns true - native widgets! */
160     public boolean isOptimizedDrawingEnabled() {
161         return true;
162     }
163     
164     /** NOT IMPLEMENTED */
165     public void addNotify() { }
166     /** NOT MIMPLEMENTED */
167     public void removeNotify() { }
168     
169     /** RootPane layout - one component and it fills the whole damn thing */
170     private class RootPaneLayout extends FillLayout { }
171     
172 }
173
Popular Tags