| 1 | /* MenuComponent.java -- Superclass of all AWT menu components
|
|---|
| 2 | Copyright (C) 1999, 2000, 2002 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 |
|
|---|
| 43 | // FIXME: Java 1.0 event model unimplemented
|
|---|
| 44 |
|
|---|
| 45 | /**
|
|---|
| 46 | * This is the superclass of all non-menu AWT widgets.
|
|---|
| 47 | *
|
|---|
| 48 | * @author Aaron M. Renn ([email protected])
|
|---|
| 49 | */
|
|---|
| 50 | public abstract class MenuComponent implements java.io.Serializable
|
|---|
| 51 | {
|
|---|
| 52 |
|
|---|
| 53 | /*
|
|---|
| 54 | * Static Variables
|
|---|
| 55 | */
|
|---|
| 56 |
|
|---|
| 57 | // Serialization Constant
|
|---|
| 58 | private static final long serialVersionUID = -4536902356223894379L;
|
|---|
| 59 |
|
|---|
| 60 | /*************************************************************************/
|
|---|
| 61 |
|
|---|
| 62 | /*
|
|---|
| 63 | * Instance Variables
|
|---|
| 64 | */
|
|---|
| 65 |
|
|---|
| 66 | // FIXME: missing serialized fields `nameExplicitlySet',
|
|---|
| 67 | // `newEventsOnly', and `accessibleContext'.
|
|---|
| 68 |
|
|---|
| 69 | // The font for this component
|
|---|
| 70 | private Font font;
|
|---|
| 71 |
|
|---|
| 72 | // The name of the component
|
|---|
| 73 | private String name;
|
|---|
| 74 |
|
|---|
| 75 | // The parent of this component
|
|---|
| 76 | transient MenuContainer parent;
|
|---|
| 77 |
|
|---|
| 78 | // The native peer for this componet
|
|---|
| 79 | transient MenuComponentPeer peer;
|
|---|
| 80 |
|
|---|
| 81 | // The synchronization locking object for this component
|
|---|
| 82 | private transient Object tree_lock = this;
|
|---|
| 83 |
|
|---|
| 84 | // The toolkit for this object
|
|---|
| 85 | private static transient Toolkit toolkit = Toolkit.getDefaultToolkit();
|
|---|
| 86 |
|
|---|
| 87 | /*************************************************************************/
|
|---|
| 88 |
|
|---|
| 89 | /*
|
|---|
| 90 | * Constructors
|
|---|
| 91 | */
|
|---|
| 92 |
|
|---|
| 93 | /**
|
|---|
| 94 | * Default constructor for subclasses.
|
|---|
| 95 | */
|
|---|
| 96 | protected
|
|---|
| 97 | MenuComponent()
|
|---|
| 98 | {
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | /*************************************************************************/
|
|---|
| 102 |
|
|---|
| 103 | /*
|
|---|
| 104 | * Instance Methods
|
|---|
| 105 | */
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * Returns the font in use for this component.
|
|---|
| 109 | *
|
|---|
| 110 | * @return The font for this component.
|
|---|
| 111 | */
|
|---|
| 112 | public Font
|
|---|
| 113 | getFont()
|
|---|
| 114 | {
|
|---|
| 115 | return(font);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /*************************************************************************/
|
|---|
| 119 |
|
|---|
| 120 | /**
|
|---|
| 121 | * Sets the font for this component to the specified font.
|
|---|
| 122 | *
|
|---|
| 123 | * @param font The new font for this component.
|
|---|
| 124 | */
|
|---|
| 125 | public void
|
|---|
| 126 | setFont(Font font)
|
|---|
| 127 | {
|
|---|
| 128 | this.font = font;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | /*************************************************************************/
|
|---|
| 132 |
|
|---|
| 133 | /**
|
|---|
| 134 | * Returns the name of this component.
|
|---|
| 135 | *
|
|---|
| 136 | * @return The name of this component.
|
|---|
| 137 | */
|
|---|
| 138 | public String
|
|---|
| 139 | getName()
|
|---|
| 140 | {
|
|---|
| 141 | return(name);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | /*************************************************************************/
|
|---|
| 145 |
|
|---|
| 146 | /**
|
|---|
| 147 | * Sets the name of this component to the specified name.
|
|---|
| 148 | *
|
|---|
| 149 | * @param name The new name of this component.
|
|---|
| 150 | */
|
|---|
| 151 | public void
|
|---|
| 152 | setName(String name)
|
|---|
| 153 | {
|
|---|
| 154 | this.name = name;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | /*************************************************************************/
|
|---|
| 158 |
|
|---|
| 159 | /**
|
|---|
| 160 | * Returns the parent of this component.
|
|---|
| 161 | *
|
|---|
| 162 | * @return The parent of this component.
|
|---|
| 163 | */
|
|---|
| 164 | public MenuContainer
|
|---|
| 165 | getParent()
|
|---|
| 166 | {
|
|---|
| 167 | return(parent);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | /*************************************************************************/
|
|---|
| 171 |
|
|---|
| 172 | // Sets the parent of this component.
|
|---|
| 173 | final void
|
|---|
| 174 | setParent(MenuContainer parent)
|
|---|
| 175 | {
|
|---|
| 176 | this.parent = parent;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /*************************************************************************/
|
|---|
| 180 |
|
|---|
| 181 | /**
|
|---|
| 182 | * Returns the native windowing system peer for this component.
|
|---|
| 183 | *
|
|---|
| 184 | * @return The peer for this component.
|
|---|
| 185 | */
|
|---|
| 186 | public MenuComponentPeer
|
|---|
| 187 | getPeer()
|
|---|
| 188 | {
|
|---|
| 189 | return(peer);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | /*************************************************************************/
|
|---|
| 193 |
|
|---|
| 194 | // Sets the peer for this component.
|
|---|
| 195 | final void
|
|---|
| 196 | setPeer(MenuComponentPeer peer)
|
|---|
| 197 | {
|
|---|
| 198 | this.peer = peer;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | /*************************************************************************/
|
|---|
| 202 |
|
|---|
| 203 | /**
|
|---|
| 204 | * Destroys this component's native peer
|
|---|
| 205 | */
|
|---|
| 206 | public void
|
|---|
| 207 | removeNotify()
|
|---|
| 208 | {
|
|---|
| 209 | if (peer != null)
|
|---|
| 210 | peer.dispose();
|
|---|
| 211 | peer = null;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | /*************************************************************************/
|
|---|
| 215 |
|
|---|
| 216 | /**
|
|---|
| 217 | * Returns the toolkit in use for this component.
|
|---|
| 218 | *
|
|---|
| 219 | * @return The toolkit for this component.
|
|---|
| 220 | */
|
|---|
| 221 | final Toolkit
|
|---|
| 222 | getToolkit()
|
|---|
| 223 | {
|
|---|
| 224 | return(toolkit);
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | /*************************************************************************/
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * Returns the object used for synchronization locks on this component
|
|---|
| 231 | * when performing tree and layout functions.
|
|---|
| 232 | *
|
|---|
| 233 | * @return The synchronization lock for this component.
|
|---|
| 234 | */
|
|---|
| 235 | protected final Object
|
|---|
| 236 | getTreeLock()
|
|---|
| 237 | {
|
|---|
| 238 | return(tree_lock);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | /*************************************************************************/
|
|---|
| 242 |
|
|---|
| 243 | // The sync lock object for this component.
|
|---|
| 244 | final void
|
|---|
| 245 | setTreeLock(Object tree_lock)
|
|---|
| 246 | {
|
|---|
| 247 | this.tree_lock = tree_lock;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | /*************************************************************************/
|
|---|
| 251 |
|
|---|
| 252 | /**
|
|---|
| 253 | * AWT 1.0 event dispatcher.
|
|---|
| 254 | *
|
|---|
| 255 | * @deprecated Deprecated in favor of <code>dispatchEvent()</code>.
|
|---|
| 256 | */
|
|---|
| 257 | public boolean
|
|---|
| 258 | postEvent(Event event)
|
|---|
| 259 | {
|
|---|
| 260 | return(false);
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | /*************************************************************************/
|
|---|
| 264 |
|
|---|
| 265 | /**
|
|---|
| 266 | * Sends this event to this component or a subcomponent for processing.
|
|---|
| 267 | *
|
|---|
| 268 | * @param event The event to dispatch
|
|---|
| 269 | */
|
|---|
| 270 | public final void
|
|---|
| 271 | dispatchEvent(AWTEvent event)
|
|---|
| 272 | {
|
|---|
| 273 | // See comment in Component.dispatchEvent().
|
|---|
| 274 | dispatchEventImpl(event);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | void
|
|---|
| 278 | dispatchEventImpl(AWTEvent e)
|
|---|
| 279 | {
|
|---|
| 280 | // This is overridden by subclasses that support events.
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | /*************************************************************************/
|
|---|
| 284 |
|
|---|
| 285 | /**
|
|---|
| 286 | * Processes the specified event. In this class, this method simply
|
|---|
| 287 | * calls one of the more specific event handlers.
|
|---|
| 288 | *
|
|---|
| 289 | * @param event The event to process.
|
|---|
| 290 | */
|
|---|
| 291 | protected void
|
|---|
| 292 | processEvent(AWTEvent event)
|
|---|
| 293 | {
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | /*************************************************************************/
|
|---|
| 297 |
|
|---|
| 298 | /**
|
|---|
| 299 | * Returns a string representation of this component.
|
|---|
| 300 | *
|
|---|
| 301 | * @return A string representation of this component
|
|---|
| 302 | */
|
|---|
| 303 | public String
|
|---|
| 304 | toString()
|
|---|
| 305 | {
|
|---|
| 306 | return this.getClass().getName() + "[" + paramString() + "]";
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | /*************************************************************************/
|
|---|
| 310 |
|
|---|
| 311 | /**
|
|---|
| 312 | * Returns a debugging string for this component
|
|---|
| 313 | */
|
|---|
| 314 | protected String
|
|---|
| 315 | paramString()
|
|---|
| 316 | {
|
|---|
| 317 | return "name=" + getName();
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | // Accessibility API not yet implemented.
|
|---|
| 321 | // public AccessibleContext getAccessibleContext()
|
|---|
| 322 |
|
|---|
| 323 | } // class Component
|
|---|