1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52: import ;
53: import ;
54:
55:
61: public class JWindow extends Window implements Accessible, RootPaneContainer
62: {
63:
66: protected class AccessibleJWindow extends Window.AccessibleAWTWindow
67: {
68:
71: public AccessibleJWindow()
72: {
73: super();
74:
75: }
76: }
77:
78: private static final long serialVersionUID = 5420698392125238833L;
79:
80: protected JRootPane rootPane;
81:
82:
85: protected boolean rootPaneCheckingEnabled = false;
86:
87: protected AccessibleContext accessibleContext;
88:
89:
94: private boolean initStageDone = false;
95:
96: public JWindow()
97: {
98: super(SwingUtilities.getOwnerFrame());
99: windowInit();
100: }
101:
102: public JWindow(GraphicsConfiguration gc)
103: {
104: super(SwingUtilities.getOwnerFrame(), gc);
105: windowInit();
106: }
107:
108: public JWindow(Frame owner)
109: {
110: super(owner);
111: windowInit();
112: }
113:
114: public JWindow(Window owner)
115: {
116: super(owner);
117: windowInit();
118: }
119:
120: public JWindow(Window owner, GraphicsConfiguration gc)
121: {
122: super(owner, gc);
123: windowInit();
124: }
125:
126: protected void windowInit()
127: {
128: super.setLayout(new BorderLayout(1, 1));
129: getRootPane();
130:
131: initStageDone = true;
132: }
133:
134: public Dimension getPreferredSize()
135: {
136: return super.getPreferredSize();
137: }
138:
139: public void setLayout(LayoutManager manager)
140: {
141:
142:
143: if (initStageDone)
144: {
145: if (isRootPaneCheckingEnabled())
146: throw new Error("Cannot set layout. Use getContentPane().setLayout()"
147: + " instead.");
148: getContentPane().setLayout(manager);
149: }
150: else
151: super.setLayout(manager);
152: }
153:
154: public void setLayeredPane(JLayeredPane layeredPane)
155: {
156: getRootPane().setLayeredPane(layeredPane);
157: }
158:
159: public JLayeredPane getLayeredPane()
160: {
161: return getRootPane().getLayeredPane();
162: }
163:
164: public JRootPane getRootPane()
165: {
166: if (rootPane == null)
167: setRootPane(createRootPane());
168: return rootPane;
169: }
170:
171: protected void setRootPane(JRootPane root)
172: {
173: if (rootPane != null)
174: remove(rootPane);
175:
176: rootPane = root;
177: add(rootPane, BorderLayout.CENTER);
178: }
179:
180: protected JRootPane createRootPane()
181: {
182: return new JRootPane();
183: }
184:
185: public Container getContentPane()
186: {
187: return getRootPane().getContentPane();
188: }
189:
190: public void setContentPane(Container contentPane)
191: {
192: getRootPane().setContentPane(contentPane);
193: }
194:
195: public Component getGlassPane()
196: {
197: return getRootPane().getGlassPane();
198: }
199:
200: public void setGlassPane(Component glassPane)
201: {
202: getRootPane().setGlassPane(glassPane);
203: }
204:
205:
206: protected void addImpl(Component comp, Object constraints, int index)
207: {
208:
209:
210: if (!initStageDone)
211: super.addImpl(comp, constraints, index);
212: else
213: {
214: if (isRootPaneCheckingEnabled())
215: throw new Error("Do not use add() on JWindow directly. Use "
216: + "getContentPane().add() instead");
217: getContentPane().add(comp, constraints, index);
218: }
219: }
220:
221: public void remove(Component comp)
222: {
223:
224:
225: if (comp == rootPane)
226: super.remove(rootPane);
227: else
228: getContentPane().remove(comp);
229: }
230:
231: protected boolean isRootPaneCheckingEnabled()
232: {
233: return rootPaneCheckingEnabled;
234: }
235:
236: protected void setRootPaneCheckingEnabled(boolean enabled)
237: {
238: rootPaneCheckingEnabled = enabled;
239: }
240:
241: public void update(Graphics g)
242: {
243: paint(g);
244: }
245:
246: protected void processKeyEvent(KeyEvent e)
247: {
248: super.processKeyEvent(e);
249: }
250:
251: public AccessibleContext getAccessibleContext()
252: {
253: if (accessibleContext == null)
254: accessibleContext = new AccessibleJWindow();
255: return accessibleContext;
256: }
257:
258: protected String paramString()
259: {
260: return "JWindow";
261: }
262: }