1 /* MenuComponent.java -- Superclass of all AWT menu components
2    Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
3 
4 This file is part of GNU Classpath.
5 
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20 
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25 
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37 
38 
39 package java.awt;
40 
41 import java.awt.peer.MenuComponentPeer;
42 import java.io.Serializable;
43 
44 // FIXME: Java 1.0 event model unimplemented
45 
46 /**
47   * This is the superclass of all non-menu AWT widgets.
48   *
49   * @author Aaron M. Renn (arenn@urbanophile.com)
50   */
51 public abstract class MenuComponent implements Serializable
52 {
53 
54 /*
55  * Static Variables
56  */
57 
58 // Serialization Constant
59 private static final long serialVersionUID = -4536902356223894379L;
60 
61 /*************************************************************************/
62 
63 /*
64  * Instance Variables
65  */
66 
67   // FIXME: missing serialized fields `nameExplicitlySet',
68   // `newEventsOnly', and `accessibleContext'.
69 
70 // The font for this component
71 private Font font;
72 
73 // The name of the component
74 private String name;
75 
76 // The parent of this component
77 transient MenuContainer parent;
78 
79 // The native peer for this componet
80 transient MenuComponentPeer peer;
81 
82 // The synchronization locking object for this component
83 private transient Object tree_lock = this;
84 
85 // The toolkit for this object
86 private static transient Toolkit toolkit = Toolkit.getDefaultToolkit();
87 
88 /*************************************************************************/
89 
90 /*
91  * Constructors
92  */
93 
94 /**
95   * Default constructor for subclasses.
96   *
97   * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
98   */
99 public
MenuComponent()100 MenuComponent()
101 {
102   if (GraphicsEnvironment.isHeadless())
103     throw new HeadlessException ();
104 }
105 
106 /*************************************************************************/
107 
108 /*
109  * Instance Methods
110  */
111 
112 /**
113   * Returns the font in use for this component.
114   *
115   * @return The font for this component.
116   */
117 public Font
getFont()118 getFont()
119 {
120   return(font);
121 }
122 
123 /*************************************************************************/
124 
125 /**
126   * Sets the font for this component to the specified font.
127   *
128   * @param font The new font for this component.
129   */
130 public void
setFont(Font font)131 setFont(Font font)
132 {
133   this.font = font;
134 }
135 
136 /*************************************************************************/
137 
138 /**
139   * Returns the name of this component.
140   *
141   * @return The name of this component.
142   */
143 public String
getName()144 getName()
145 {
146   return(name);
147 }
148 
149 /*************************************************************************/
150 
151 /**
152   * Sets the name of this component to the specified name.
153   *
154   * @param name The new name of this component.
155   */
156 public void
setName(String name)157 setName(String name)
158 {
159   this.name = name;
160 }
161 
162 /*************************************************************************/
163 
164 /**
165   * Returns the parent of this component.
166   *
167   * @return The parent of this component.
168   */
169 public MenuContainer
getParent()170 getParent()
171 {
172   return(parent);
173 }
174 
175 /*************************************************************************/
176 
177 // Sets the parent of this component.
178 final void
setParent(MenuContainer parent)179 setParent(MenuContainer parent)
180 {
181   this.parent = parent;
182 }
183 
184 /*************************************************************************/
185 
186 /**
187   * Returns the native windowing system peer for this component.
188   *
189   * @return The peer for this component.
190   *
191   * @deprecated
192   */
193 public MenuComponentPeer
getPeer()194 getPeer()
195 {
196   return(peer);
197 }
198 
199 /*************************************************************************/
200 
201 // Sets the peer for this component.
202 final void
setPeer(MenuComponentPeer peer)203 setPeer(MenuComponentPeer peer)
204 {
205   this.peer = peer;
206 }
207 
208 /*************************************************************************/
209 
210 /**
211   * Destroys this component's native peer
212   */
213 public void
removeNotify()214 removeNotify()
215 {
216   if (peer != null)
217     peer.dispose();
218   peer = null;
219 }
220 
221 /*************************************************************************/
222 
223 /**
224   * Returns the toolkit in use for this component.
225   *
226   * @return The toolkit for this component.
227   */
228 final Toolkit
getToolkit()229 getToolkit()
230 {
231   return(toolkit);
232 }
233 
234 /*************************************************************************/
235 
236 /**
237   * Returns the object used for synchronization locks on this component
238   * when performing tree and layout functions.
239   *
240   * @return The synchronization lock for this component.
241   */
242 protected final Object
getTreeLock()243 getTreeLock()
244 {
245   return(tree_lock);
246 }
247 
248 /*************************************************************************/
249 
250 // The sync lock object for this component.
251 final void
setTreeLock(Object tree_lock)252 setTreeLock(Object tree_lock)
253 {
254   this.tree_lock = tree_lock;
255 }
256 
257 /*************************************************************************/
258 
259 /**
260   * AWT 1.0 event dispatcher.
261   *
262   * @deprecated Deprecated in favor of <code>dispatchEvent()</code>.
263   */
264 public boolean
postEvent(Event event)265 postEvent(Event event)
266 {
267   return(false);
268 }
269 
270 /*************************************************************************/
271 
272 /**
273   * Sends this event to this component or a subcomponent for processing.
274   *
275   * @param event The event to dispatch
276   */
277 public final void
dispatchEvent(AWTEvent event)278 dispatchEvent(AWTEvent event)
279 {
280   // See comment in Component.dispatchEvent().
281   dispatchEventImpl(event);
282 }
283 
284 void
dispatchEventImpl(AWTEvent e)285 dispatchEventImpl(AWTEvent e)
286 {
287   // This is overridden by subclasses that support events.
288 }
289 
290 /*************************************************************************/
291 
292 /**
293   * Processes the specified event.  In this class, this method simply
294   * calls one of the more specific event handlers.
295   *
296   * @param event The event to process.
297   */
298 protected void
processEvent(AWTEvent event)299 processEvent(AWTEvent event)
300 {
301 }
302 
303 /*************************************************************************/
304 
305 /**
306   * Returns a string representation of this component.
307   *
308   * @return A string representation of this component
309   */
310 public String
toString()311 toString()
312 {
313   return this.getClass().getName() + "[" + paramString() + "]";
314 }
315 
316 /*************************************************************************/
317 
318 /**
319   * Returns a debugging string for this component
320   */
321 protected String
paramString()322 paramString()
323 {
324   return "name=" + getName();
325 }
326 
327 // Accessibility API not yet implemented.
328 // public AccessibleContext getAccessibleContext()
329 
330 } // class Component
331