MenuComponent.java 7.4 KB

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