1 |
/* JApplet.java -- |
/* JApplet.java -- |
2 |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
|
|
|
38 |
package javax.swing; |
package javax.swing; |
39 |
|
|
40 |
import java.applet.Applet; |
import java.applet.Applet; |
48 |
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
49 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
50 |
|
|
51 |
public class JApplet extends Applet implements RootPaneContainer |
|
52 |
|
public class JApplet extends Applet |
53 |
|
implements RootPaneContainer |
54 |
{ |
{ |
55 |
private static final long serialVersionUID = 7269359214497372587L; |
private static final long serialVersionUID = 7269359214497372587L; |
56 |
|
public static final int HIDE_ON_CLOSE = 0; |
57 |
|
public static final int EXIT_ON_CLOSE = 1; |
58 |
|
public static final int DISPOSE_ON_CLOSE = 2; |
59 |
|
public static final int DO_NOTHING_ON_CLOSE = 3; |
60 |
|
private int close_action = EXIT_ON_CLOSE; |
61 |
|
private boolean checking; |
62 |
|
protected JRootPane rootPane; |
63 |
|
|
64 |
|
public JApplet() |
65 |
|
{ |
66 |
|
frameInit(); |
67 |
|
} |
68 |
|
|
69 |
public final static int HIDE_ON_CLOSE = 0; |
public JApplet(String title) |
70 |
public final static int EXIT_ON_CLOSE = 1; |
{ |
71 |
public final static int DISPOSE_ON_CLOSE = 2; |
frameInit(); |
72 |
public final static int DO_NOTHING_ON_CLOSE = 3; |
} |
73 |
|
|
74 |
private int close_action = EXIT_ON_CLOSE; |
protected void frameInit() |
75 |
private boolean checking; |
{ |
76 |
protected JRootPane rootPane; |
super.setLayout(new BorderLayout(1, 1)); |
77 |
|
getRootPane(); // will do set/create |
78 |
public JApplet() |
} |
|
{ |
|
|
frameInit(); |
|
|
} |
|
|
|
|
|
public JApplet(String title) |
|
|
{ |
|
|
frameInit(); |
|
|
} |
|
|
|
|
|
protected void frameInit() |
|
|
{ |
|
|
super.setLayout(new BorderLayout(1, 1)); |
|
|
getRootPane(); // will do set/create |
|
|
} |
|
79 |
|
|
80 |
public Dimension getPreferredSize() |
public Dimension getPreferredSize() |
81 |
{ |
{ |
82 |
Dimension d = super.getPreferredSize(); |
Dimension d = super.getPreferredSize(); |
83 |
System.out.println("JFrame.getPrefSize(): " + d + " , comp="+ getComponentCount () + ", layout=" + getLayout()); |
System.out.println("JFrame.getPrefSize(): " + d + " , comp=" |
84 |
|
+ getComponentCount() + ", layout=" + getLayout()); |
85 |
return d; |
return d; |
86 |
} |
} |
87 |
|
|
88 |
public void setLayout(LayoutManager manager) |
public void setLayout(LayoutManager manager) |
89 |
{ super.setLayout(manager); } |
{ |
90 |
|
super.setLayout(manager); |
91 |
|
} |
92 |
|
|
93 |
|
public void setLayeredPane(JLayeredPane layeredPane) |
94 |
|
{ |
95 |
|
getRootPane().setLayeredPane(layeredPane); |
96 |
|
} |
97 |
|
|
98 |
|
public JLayeredPane getLayeredPane() |
99 |
|
{ |
100 |
|
return getRootPane().getLayeredPane(); |
101 |
|
} |
102 |
|
|
103 |
|
public JRootPane getRootPane() |
104 |
|
{ |
105 |
|
if (rootPane == null) |
106 |
|
setRootPane(createRootPane()); |
107 |
|
return rootPane; |
108 |
|
} |
109 |
|
|
110 |
public void setLayeredPane(JLayeredPane layeredPane) |
public void setRootPane(JRootPane root) |
111 |
{ getRootPane().setLayeredPane(layeredPane); } |
{ |
112 |
|
if (rootPane != null) |
113 |
public JLayeredPane getLayeredPane() |
remove(rootPane); |
114 |
{ return getRootPane().getLayeredPane(); } |
|
115 |
|
rootPane = root; |
116 |
public JRootPane getRootPane() |
add(rootPane, BorderLayout.CENTER); |
117 |
{ |
} |
|
if (rootPane == null) |
|
|
setRootPane(createRootPane()); |
|
|
return rootPane; |
|
|
} |
|
|
|
|
|
public void setRootPane(JRootPane root) |
|
|
{ |
|
|
if (rootPane != null) |
|
|
remove(rootPane); |
|
|
|
|
|
rootPane = root; |
|
|
add(rootPane, BorderLayout.CENTER); |
|
|
} |
|
|
|
|
|
public JRootPane createRootPane() |
|
|
{ return new JRootPane(); } |
|
|
|
|
|
public Container getContentPane() |
|
|
{ return getRootPane().getContentPane(); } |
|
|
|
|
|
public void setContentPane(Container contentPane) |
|
|
{ getRootPane().setContentPane(contentPane); } |
|
|
|
|
|
public Component getGlassPane() |
|
|
{ return getRootPane().getGlassPane(); } |
|
|
|
|
|
public void setGlassPane(Component glassPane) |
|
|
{ getRootPane().setGlassPane(glassPane); } |
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////// |
|
|
protected void addImpl(Component comp, Object constraints, int index) |
|
|
{ super.addImpl(comp, constraints, index); } |
|
|
|
|
|
public AccessibleContext getAccessibleContext() |
|
|
{ return null; } |
|
|
|
|
|
int getDefaultCloseOperation() |
|
|
{ return close_action; } |
|
|
|
|
|
|
|
|
public JMenuBar getJMenuBar() |
|
|
{ return getRootPane().getJMenuBar(); } |
|
|
|
|
|
public void setJMenuBar(JMenuBar menubar) |
|
|
{ getRootPane().setJMenuBar(menubar); } |
|
|
|
|
|
|
|
|
protected String paramString() |
|
|
{ return "JFrame"; } |
|
|
|
|
|
protected void processKeyEvent(KeyEvent e) |
|
|
{ super.processKeyEvent(e); } |
|
|
|
|
|
protected void processWindowEvent(WindowEvent e) |
|
|
{ |
|
|
// System.out.println("PROCESS_WIN_EV-1: " + e); |
|
|
|
|
|
// super.processWindowEvent(e); |
|
|
|
|
|
// System.out.println("PROCESS_WIN_EV-2: " + e); |
|
|
switch (e.getID()) |
|
|
{ |
|
|
case WindowEvent.WINDOW_CLOSING: |
|
|
{ |
|
|
switch(close_action) |
|
|
{ |
|
|
case EXIT_ON_CLOSE: |
|
|
{ |
|
|
System.out.println("user requested exit on close"); |
|
|
System.exit(1); |
|
|
break; |
|
|
} |
|
|
case DISPOSE_ON_CLOSE: |
|
|
{ |
|
|
System.out.println("user requested dispose on close"); |
|
|
//dispose(); |
|
|
break; |
|
|
} |
|
|
case HIDE_ON_CLOSE: |
|
|
|
|
|
case DO_NOTHING_ON_CLOSE: |
|
|
break; |
|
|
} |
|
|
break; |
|
|
} |
|
|
|
|
|
case WindowEvent.WINDOW_CLOSED: |
|
|
case WindowEvent.WINDOW_OPENED: |
|
|
case WindowEvent.WINDOW_ICONIFIED: |
|
|
case WindowEvent.WINDOW_DEICONIFIED: |
|
|
case WindowEvent.WINDOW_ACTIVATED: |
|
|
case WindowEvent.WINDOW_DEACTIVATED: |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void remove(Component comp) |
|
|
{ getContentPane().remove(comp); } |
|
|
|
|
|
|
|
|
void setDefaultCloseOperation(int operation) |
|
|
{ close_action = operation; } |
|
|
|
|
|
|
|
|
|
|
|
protected boolean isRootPaneCheckingEnabled() |
|
|
{ return checking; } |
|
118 |
|
|
119 |
|
public JRootPane createRootPane() |
120 |
|
{ |
121 |
|
return new JRootPane(); |
122 |
|
} |
123 |
|
|
124 |
protected void setRootPaneCheckingEnabled(boolean enabled) |
public Container getContentPane() |
125 |
{ checking = enabled; } |
{ |
126 |
|
return getRootPane().getContentPane(); |
127 |
|
} |
128 |
|
|
129 |
public void update(Graphics g) |
public void setContentPane(Container contentPane) |
130 |
{ paint(g); } |
{ |
131 |
|
getRootPane().setContentPane(contentPane); |
132 |
|
} |
133 |
|
|
134 |
|
public Component getGlassPane() |
135 |
|
{ |
136 |
|
return getRootPane().getGlassPane(); |
137 |
|
} |
138 |
|
|
139 |
|
public void setGlassPane(Component glassPane) |
140 |
|
{ |
141 |
|
getRootPane().setGlassPane(glassPane); |
142 |
|
} |
143 |
|
|
144 |
|
///////////////////////////////////////////////////////////////////////////////// |
145 |
|
protected void addImpl(Component comp, Object constraints, int index) |
146 |
|
{ |
147 |
|
super.addImpl(comp, constraints, index); |
148 |
|
} |
149 |
|
|
150 |
|
public AccessibleContext getAccessibleContext() |
151 |
|
{ |
152 |
|
return null; |
153 |
|
} |
154 |
|
|
155 |
|
int getDefaultCloseOperation() |
156 |
|
{ |
157 |
|
return close_action; |
158 |
|
} |
159 |
|
|
160 |
|
public JMenuBar getJMenuBar() |
161 |
|
{ |
162 |
|
return getRootPane().getJMenuBar(); |
163 |
|
} |
164 |
|
|
165 |
|
public void setJMenuBar(JMenuBar menubar) |
166 |
|
{ |
167 |
|
getRootPane().setJMenuBar(menubar); |
168 |
|
} |
169 |
|
|
170 |
|
protected String paramString() |
171 |
|
{ |
172 |
|
return "JFrame"; |
173 |
|
} |
174 |
|
|
175 |
|
protected void processKeyEvent(KeyEvent e) |
176 |
|
{ |
177 |
|
super.processKeyEvent(e); |
178 |
|
} |
179 |
|
|
180 |
|
protected void processWindowEvent(WindowEvent e) |
181 |
|
{ |
182 |
|
// System.out.println("PROCESS_WIN_EV-1: " + e); |
183 |
|
// super.processWindowEvent(e); |
184 |
|
// System.out.println("PROCESS_WIN_EV-2: " + e); |
185 |
|
switch (e.getID()) |
186 |
|
{ |
187 |
|
case WindowEvent.WINDOW_CLOSING: |
188 |
|
{ |
189 |
|
switch (close_action) |
190 |
|
{ |
191 |
|
case EXIT_ON_CLOSE: |
192 |
|
{ |
193 |
|
System.out.println("user requested exit on close"); |
194 |
|
System.exit(1); |
195 |
|
break; |
196 |
|
} |
197 |
|
case DISPOSE_ON_CLOSE: |
198 |
|
{ |
199 |
|
System.out.println("user requested dispose on close"); |
200 |
|
//dispose(); |
201 |
|
break; |
202 |
|
} |
203 |
|
case HIDE_ON_CLOSE: |
204 |
|
case DO_NOTHING_ON_CLOSE: |
205 |
|
break; |
206 |
|
} |
207 |
|
break; |
208 |
|
} |
209 |
|
case WindowEvent.WINDOW_CLOSED: |
210 |
|
case WindowEvent.WINDOW_OPENED: |
211 |
|
case WindowEvent.WINDOW_ICONIFIED: |
212 |
|
case WindowEvent.WINDOW_DEICONIFIED: |
213 |
|
case WindowEvent.WINDOW_ACTIVATED: |
214 |
|
case WindowEvent.WINDOW_DEACTIVATED: |
215 |
|
break; |
216 |
|
} |
217 |
|
} |
218 |
|
|
219 |
|
public void remove(Component comp) |
220 |
|
{ |
221 |
|
getContentPane().remove(comp); |
222 |
|
} |
223 |
|
|
224 |
|
void setDefaultCloseOperation(int operation) |
225 |
|
{ |
226 |
|
close_action = operation; |
227 |
|
} |
228 |
|
|
229 |
|
protected boolean isRootPaneCheckingEnabled() |
230 |
|
{ |
231 |
|
return checking; |
232 |
|
} |
233 |
|
|
234 |
|
protected void setRootPaneCheckingEnabled(boolean enabled) |
235 |
|
{ |
236 |
|
checking = enabled; |
237 |
|
} |
238 |
|
|
239 |
|
public void update(Graphics g) |
240 |
|
{ |
241 |
|
paint(g); |
242 |
|
} |
243 |
} |
} |