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: private static final long serialVersionUID = 5420698392125238833L;
64:
65: protected JRootPane rootPane;
66:
67:
70: protected boolean rootPaneCheckingEnabled = false;
71:
72: protected AccessibleContext accessibleContext;
73:
74:
79: private boolean initStageDone = false;
80:
81: public JWindow()
82: {
83: super(SwingUtilities.getOwnerFrame());
84: windowInit();
85: }
86:
87: public JWindow(GraphicsConfiguration gc)
88: {
89: super(SwingUtilities.getOwnerFrame(), gc);
90: windowInit();
91: }
92:
93: public JWindow(Frame owner)
94: {
95: super(owner);
96: windowInit();
97: }
98:
99: public JWindow(Window owner)
100: {
101: super(owner);
102: windowInit();
103: }
104:
105: public JWindow(Window owner, GraphicsConfiguration gc)
106: {
107: super(owner, gc);
108: windowInit();
109: }
110:
111: protected void windowInit()
112: {
113: super.setLayout(new BorderLayout(1, 1));
114: getRootPane();
115:
116: initStageDone = true;
117: }
118:
119: public Dimension getPreferredSize()
120: {
121: return super.getPreferredSize();
122: }
123:
124: public void setLayout(LayoutManager manager)
125: {
126:
127:
128: if (initStageDone)
129: {
130: if (isRootPaneCheckingEnabled())
131: throw new Error("Cannot set layout. Use getContentPane().setLayout()"
132: + " instead.");
133: getContentPane().setLayout(manager);
134: }
135: else
136: super.setLayout(manager);
137: }
138:
139: public void setLayeredPane(JLayeredPane layeredPane)
140: {
141: getRootPane().setLayeredPane(layeredPane);
142: }
143:
144: public JLayeredPane getLayeredPane()
145: {
146: return getRootPane().getLayeredPane();
147: }
148:
149: public JRootPane getRootPane()
150: {
151: if (rootPane == null)
152: setRootPane(createRootPane());
153: return rootPane;
154: }
155:
156: protected void setRootPane(JRootPane root)
157: {
158: if (rootPane != null)
159: remove(rootPane);
160:
161: rootPane = root;
162: add(rootPane, BorderLayout.CENTER);
163: }
164:
165: protected JRootPane createRootPane()
166: {
167: return new JRootPane();
168: }
169:
170: public Container getContentPane()
171: {
172: return getRootPane().getContentPane();
173: }
174:
175: public void setContentPane(Container contentPane)
176: {
177: getRootPane().setContentPane(contentPane);
178: }
179:
180: public Component getGlassPane()
181: {
182: return getRootPane().getGlassPane();
183: }
184:
185: public void setGlassPane(Component glassPane)
186: {
187: getRootPane().setGlassPane(glassPane);
188: }
189:
190:
191: protected void addImpl(Component comp, Object constraints, int index)
192: {
193:
194:
195: if (!initStageDone)
196: super.addImpl(comp, constraints, index);
197: else
198: {
199: if (isRootPaneCheckingEnabled())
200: throw new Error("Do not use add() on JWindow directly. Use "
201: + "getContentPane().add() instead");
202: getContentPane().add(comp, constraints, index);
203: }
204: }
205:
206: public void remove(Component comp)
207: {
208:
209:
210: if (comp == rootPane)
211: super.remove(rootPane);
212: else
213: getContentPane().remove(comp);
214: }
215:
216: protected boolean isRootPaneCheckingEnabled()
217: {
218: return rootPaneCheckingEnabled;
219: }
220:
221: protected void setRootPaneCheckingEnabled(boolean enabled)
222: {
223: rootPaneCheckingEnabled = enabled;
224: }
225:
226: public void update(Graphics g)
227: {
228: paint(g);
229: }
230:
231: protected void processKeyEvent(KeyEvent e)
232: {
233: super.processKeyEvent(e);
234: }
235:
236: public AccessibleContext getAccessibleContext()
237: {
238: return null;
239: }
240:
241: protected String paramString()
242: {
243: return "JWindow";
244: }
245: }