home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / MenuComponent.java < prev    next >
Text File  |  1996-05-03  |  3KB  |  113 lines

  1. /*
  2.  * @(#)MenuComponent.java    1.9 95/12/14 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.MenuComponentPeer;
  22.  
  23. /**
  24.  * The super class of all menu related components.
  25.  *
  26.  * @version     1.9, 14 Dec 1995
  27.  * @author     Arthur van Hoff
  28.  */
  29. public abstract class MenuComponent {
  30.     MenuComponentPeer peer;
  31.     MenuContainer parent;
  32.     Font font;
  33.  
  34.     /**
  35.      * Returns the parent container.
  36.      */
  37.     public MenuContainer getParent() {
  38.     return parent;
  39.     }
  40.  
  41.     /**
  42.      * Gets the MenuComponent's peer.  The peer allows us to modify the
  43.      * appearance of the menu component without changing the functionality of
  44.      * the menu component.
  45.      */
  46.     public MenuComponentPeer getPeer() {
  47.     return peer;
  48.     }
  49.  
  50.     /**
  51.      * Gets the font used for this MenuItem.
  52.      * @return the font if one is used; null otherwise.
  53.      */
  54.     public Font getFont() {
  55.     Font font = this.font;
  56.     if (font != null) {
  57.         return font;
  58.     }
  59.     MenuContainer parent = this.parent;
  60.     if (parent != null) {
  61.         return parent.getFont();
  62.     }
  63.     return null;
  64.     }
  65.  
  66.     /**
  67.      * Sets the font to be used for this MenuItem to the specified font.
  68.      * @param f the font to be set
  69.      */
  70.     public void setFont(Font f) {
  71.     font = f;
  72.     }
  73.  
  74.     /**
  75.      * Removes the menu component's peer.  The peer allows us to modify the
  76.      * appearance of the menu component without changing the functionality of
  77.      * the menu component.
  78.      */
  79.     public void removeNotify() {
  80.     MenuComponentPeer p = (MenuComponentPeer)this.peer;
  81.     if (p != null) {
  82.         p.dispose();
  83.         this.peer = null;
  84.     }
  85.     }
  86.  
  87.     /**
  88.      * Posts the specified event to the menu.
  89.      * @param evt the event which is to take place
  90.      */
  91.     public boolean postEvent(Event evt) {
  92.     MenuContainer parent = this.parent;
  93.     if (parent != null) {
  94.         parent.postEvent(evt);
  95.     }
  96.     return false;
  97.     }
  98.  
  99.     /**
  100.      * Returns the String parameter of this MenuComponent.
  101.      */
  102.     protected String paramString() {
  103.     return "";
  104.     }
  105.  
  106.     /**
  107.      * Returns the String representation of this MenuComponent's values.
  108.      */
  109.     public String toString() {
  110.     return getClass().getName() + "[" + paramString() + "]";
  111.     }
  112. }
  113.