Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]
    1   /*
    2    * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   package java.awt;
   26   
   27   import java.awt.peer.MenuComponentPeer;
   28   import java.awt.event.ActionEvent;
   29   import java.io.IOException;
   30   import java.io.ObjectInputStream;
   31   import sun.awt.AppContext;
   32   import sun.awt.SunToolkit;
   33   import javax.accessibility;
   34   
   35   /**
   36    * The abstract class <code>MenuComponent</code> is the superclass
   37    * of all menu-related components. In this respect, the class
   38    * <code>MenuComponent</code> is analogous to the abstract superclass
   39    * <code>Component</code> for AWT components.
   40    * <p>
   41    * Menu components receive and process AWT events, just as components do,
   42    * through the method <code>processEvent</code>.
   43    *
   44    * @author      Arthur van Hoff
   45    * @since       JDK1.0
   46    */
   47   public abstract class MenuComponent implements java.io.Serializable {
   48   
   49       static {
   50           /* ensure that the necessary native libraries are loaded */
   51           Toolkit.loadLibraries();
   52           if (!GraphicsEnvironment.isHeadless()) {
   53               initIDs();
   54           }
   55       }
   56   
   57       transient MenuComponentPeer peer;
   58       transient MenuContainer parent;
   59   
   60       /**
   61        * The <code>AppContext</code> of the <code>MenuComponent</code>.
   62        * This is set in the constructor and never changes.
   63        */
   64       transient AppContext appContext;
   65   
   66       /**
   67        * The menu component's font. This value can be
   68        * <code>null</code> at which point a default will be used.
   69        * This defaults to <code>null</code>.
   70        *
   71        * @serial
   72        * @see #setFont(Font)
   73        * @see #getFont()
   74        */
   75       Font font;
   76   
   77       /**
   78        * The menu component's name, which defaults to <code>null</code>.
   79        * @serial
   80        * @see #getName()
   81        * @see #setName(String)
   82        */
   83       private String name;
   84   
   85       /**
   86        * A variable to indicate whether a name is explicitly set.
   87        * If <code>true</code> the name will be set explicitly.
   88        * This defaults to <code>false</code>.
   89        * @serial
   90        * @see #setName(String)
   91        */
   92       private boolean nameExplicitlySet = false;
   93   
   94       /**
   95        * Defaults to <code>false</code>.
   96        * @serial
   97        * @see #dispatchEvent(AWTEvent)
   98        */
   99       boolean newEventsOnly = false;
  100   
  101       /*
  102        * Internal constants for serialization.
  103        */
  104       final static String actionListenerK = Component.actionListenerK;
  105       final static String itemListenerK = Component.itemListenerK;
  106   
  107       /*
  108        * JDK 1.1 serialVersionUID
  109        */
  110       private static final long serialVersionUID = -4536902356223894379L;
  111   
  112       /**
  113        * Creates a <code>MenuComponent</code>.
  114        * @exception HeadlessException if
  115        *    <code>GraphicsEnvironment.isHeadless</code>
  116        *    returns <code>true</code>
  117        * @see java.awt.GraphicsEnvironment#isHeadless
  118        */
  119       public MenuComponent() throws HeadlessException {
  120           GraphicsEnvironment.checkHeadless();
  121           appContext = AppContext.getAppContext();
  122       }
  123   
  124       /**
  125        * Constructs a name for this <code>MenuComponent</code>.
  126        * Called by <code>getName</code> when the name is <code>null</code>.
  127        * @return a name for this <code>MenuComponent</code>
  128        */
  129       String constructComponentName() {
  130           return null; // For strict compliance with prior platform versions, a MenuComponent
  131                        // that doesn't set its name should return null from
  132                        // getName()
  133       }
  134   
  135       /**
  136        * Gets the name of the menu component.
  137        * @return        the name of the menu component
  138        * @see           java.awt.MenuComponent#setName(java.lang.String)
  139        * @since         JDK1.1
  140        */
  141       public String getName() {
  142           if (name == null && !nameExplicitlySet) {
  143               synchronized(this) {
  144                   if (name == null && !nameExplicitlySet)
  145                       name = constructComponentName();
  146               }
  147           }
  148           return name;
  149       }
  150   
  151       /**
  152        * Sets the name of the component to the specified string.
  153        * @param         name    the name of the menu component
  154        * @see           java.awt.MenuComponent#getName
  155        * @since         JDK1.1
  156        */
  157       public void setName(String name) {
  158           synchronized(this) {
  159               this.name = name;
  160               nameExplicitlySet = true;
  161           }
  162       }
  163   
  164       /**
  165        * Returns the parent container for this menu component.
  166        * @return    the menu component containing this menu component,
  167        *                 or <code>null</code> if this menu component
  168        *                 is the outermost component, the menu bar itself
  169        */
  170       public MenuContainer getParent() {
  171           return getParent_NoClientCode();
  172       }
  173       // NOTE: This method may be called by privileged threads.
  174       //       This functionality is implemented in a package-private method
  175       //       to insure that it cannot be overridden by client subclasses.
  176       //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  177       final MenuContainer getParent_NoClientCode() {
  178           return parent;
  179       }
  180   
  181       /**
  182        * @deprecated As of JDK version 1.1,
  183        * programs should not directly manipulate peers.
  184        */
  185       @Deprecated
  186       public MenuComponentPeer getPeer() {
  187           return peer;
  188       }
  189   
  190       /**
  191        * Gets the font used for this menu component.
  192        * @return   the font used in this menu component, if there is one;
  193        *                  <code>null</code> otherwise
  194        * @see     java.awt.MenuComponent#setFont
  195        */
  196       public Font getFont() {
  197           Font font = this.font;
  198           if (font != null) {
  199               return font;
  200           }
  201           MenuContainer parent = this.parent;
  202           if (parent != null) {
  203               return parent.getFont();
  204           }
  205           return null;
  206       }
  207   
  208       // NOTE: This method may be called by privileged threads.
  209       //       This functionality is implemented in a package-private method
  210       //       to insure that it cannot be overridden by client subclasses.
  211       //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  212       final Font getFont_NoClientCode() {
  213           Font font = this.font;
  214           if (font != null) {
  215               return font;
  216           }
  217   
  218           // The MenuContainer interface does not have getFont_NoClientCode()
  219           // and it cannot, because it must be package-private. Because of
  220           // this, we must manually cast classes that implement
  221           // MenuContainer.
  222           Object parent = this.parent;
  223           if (parent != null) {
  224               if (parent instanceof Component) {
  225                   font = ((Component)parent).getFont_NoClientCode();
  226               } else if (parent instanceof MenuComponent) {
  227                   font = ((MenuComponent)parent).getFont_NoClientCode();
  228               }
  229           }
  230           return font;
  231       } // getFont_NoClientCode()
  232   
  233   
  234       /**
  235        * Sets the font to be used for this menu component to the specified
  236        * font. This font is also used by all subcomponents of this menu
  237        * component, unless those subcomponents specify a different font.
  238        * <p>
  239        * Some platforms may not support setting of all font attributes
  240        * of a menu component; in such cases, calling <code>setFont</code>
  241        * will have no effect on the unsupported font attributes of this
  242        * menu component.  Unless subcomponents of this menu component
  243        * specify a different font, this font will be used by those
  244        * subcomponents if supported by the underlying platform.
  245        *
  246        * @param     f   the font to be set
  247        * @see       #getFont
  248        * @see       Font#getAttributes
  249        * @see       java.awt.font.TextAttribute
  250        */
  251       public void setFont(Font f) {
  252           font = f;
  253           //Fixed 6312943: NullPointerException in method MenuComponent.setFont(Font)
  254           MenuComponentPeer peer = (MenuComponentPeer)this.peer;
  255           if (peer != null) {
  256               peer.setFont(f);
  257           }
  258       }
  259   
  260       /**
  261        * Removes the menu component's peer.  The peer allows us to modify the
  262        * appearance of the menu component without changing the functionality of
  263        * the menu component.
  264        */
  265       public void removeNotify() {
  266           synchronized (getTreeLock()) {
  267               MenuComponentPeer p = (MenuComponentPeer)this.peer;
  268               if (p != null) {
  269                   Toolkit.getEventQueue().removeSourceEvents(this, true);
  270                   this.peer = null;
  271                   p.dispose();
  272               }
  273           }
  274       }
  275   
  276       /**
  277        * Posts the specified event to the menu.
  278        * This method is part of the Java&nbsp;1.0 event system
  279        * and it is maintained only for backwards compatibility.
  280        * Its use is discouraged, and it may not be supported
  281        * in the future.
  282        * @param evt the event which is to take place
  283        * @deprecated As of JDK version 1.1, replaced by {@link
  284        * #dispatchEvent(AWTEvent) dispatchEvent}.
  285        */
  286       @Deprecated
  287       public boolean postEvent(Event evt) {
  288           MenuContainer parent = this.parent;
  289           if (parent != null) {
  290               parent.postEvent(evt);
  291           }
  292           return false;
  293       }
  294   
  295       /**
  296        * Delivers an event to this component or one of its sub components.
  297        * @param e the event
  298        */
  299       public final void dispatchEvent(AWTEvent e) {
  300           dispatchEventImpl(e);
  301       }
  302   
  303       void dispatchEventImpl(AWTEvent e) {
  304           EventQueue.setCurrentEventAndMostRecentTime(e);
  305   
  306           Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
  307   
  308           if (newEventsOnly ||
  309               (parent != null && parent instanceof MenuComponent &&
  310                ((MenuComponent)parent).newEventsOnly)) {
  311               if (eventEnabled(e)) {
  312                   processEvent(e);
  313               } else if (e instanceof ActionEvent && parent != null) {
  314                   e.setSource(parent);
  315                   ((MenuComponent)parent).dispatchEvent(e);
  316               }
  317   
  318           } else { // backward compatibility
  319               Event olde = e.convertToOld();
  320               if (olde != null) {
  321                   postEvent(olde);
  322               }
  323           }
  324       }
  325   
  326       // REMIND: remove when filtering is done at lower level
  327       boolean eventEnabled(AWTEvent e) {
  328           return false;
  329       }
  330       /**
  331        * Processes events occurring on this menu component.
  332        * <p>Note that if the event parameter is <code>null</code>
  333        * the behavior is unspecified and may result in an
  334        * exception.
  335        *
  336        * @param e the event
  337        * @since JDK1.1
  338        */
  339       protected void processEvent(AWTEvent e) {
  340       }
  341   
  342       /**
  343        * Returns a string representing the state of this
  344        * <code>MenuComponent</code>. This method is intended to be used
  345        * only for debugging purposes, and the content and format of the
  346        * returned string may vary between implementations. The returned
  347        * string may be empty but may not be <code>null</code>.
  348        *
  349        * @return     the parameter string of this menu component
  350        */
  351       protected String paramString() {
  352           String thisName = getName();
  353           return (thisName != null? thisName : "");
  354       }
  355   
  356       /**
  357        * Returns a representation of this menu component as a string.
  358        * @return  a string representation of this menu component
  359        */
  360       public String toString() {
  361           return getClass().getName() + "[" + paramString() + "]";
  362       }
  363   
  364       /**
  365        * Gets this component's locking object (the object that owns the thread
  366        * sychronization monitor) for AWT component-tree and layout
  367        * operations.
  368        * @return this component's locking object
  369        */
  370       protected final Object getTreeLock() {
  371           return Component.LOCK;
  372       }
  373   
  374       /**
  375        * Reads the menu component from an object input stream.
  376        *
  377        * @param s the <code>ObjectInputStream</code> to read
  378        * @exception HeadlessException if
  379        *   <code>GraphicsEnvironment.isHeadless</code> returns
  380        *   <code>true</code>
  381        * @serial
  382        * @see java.awt.GraphicsEnvironment#isHeadless
  383        */
  384       private void readObject(ObjectInputStream s)
  385           throws ClassNotFoundException, IOException, HeadlessException
  386       {
  387           GraphicsEnvironment.checkHeadless();
  388           s.defaultReadObject();
  389   
  390           appContext = AppContext.getAppContext();
  391       }
  392   
  393       /**
  394        * Initialize JNI field and method IDs.
  395        */
  396       private static native void initIDs();
  397   
  398   
  399       /*
  400        * --- Accessibility Support ---
  401        *
  402        *  MenuComponent will contain all of the methods in interface Accessible,
  403        *  though it won't actually implement the interface - that will be up
  404        *  to the individual objects which extend MenuComponent.
  405        */
  406   
  407       AccessibleContext accessibleContext = null;
  408   
  409       /**
  410        * Gets the <code>AccessibleContext</code> associated with
  411        * this <code>MenuComponent</code>.
  412        *
  413        * The method implemented by this base class returns <code>null</code>.
  414        * Classes that extend <code>MenuComponent</code>
  415        * should implement this method to return the
  416        * <code>AccessibleContext</code> associated with the subclass.
  417        *
  418        * @return the <code>AccessibleContext</code> of this
  419        *     <code>MenuComponent</code>
  420        * @since 1.3
  421        */
  422       public AccessibleContext getAccessibleContext() {
  423           return accessibleContext;
  424       }
  425   
  426       /**
  427        * Inner class of <code>MenuComponent</code> used to provide
  428        * default support for accessibility.  This class is not meant
  429        * to be used directly by application developers, but is instead
  430        * meant only to be subclassed by menu component developers.
  431        * <p>
  432        * The class used to obtain the accessible role for this object.
  433        * @since 1.3
  434        */
  435       protected abstract class AccessibleAWTMenuComponent
  436           extends AccessibleContext
  437           implements java.io.Serializable, AccessibleComponent,
  438                      AccessibleSelection
  439       {
  440           /*
  441            * JDK 1.3 serialVersionUID
  442            */
  443           private static final long serialVersionUID = -4269533416223798698L;
  444   
  445           /**
  446            * Although the class is abstract, this should be called by
  447            * all sub-classes.
  448            */
  449           protected AccessibleAWTMenuComponent() {
  450           }
  451   
  452           // AccessibleContext methods
  453           //
  454   
  455           /**
  456            * Gets the <code>AccessibleSelection</code> associated with this
  457            * object which allows its <code>Accessible</code> children to be selected.
  458            *
  459            * @return <code>AccessibleSelection</code> if supported by object;
  460            *      else return <code>null</code>
  461            * @see AccessibleSelection
  462            */
  463           public AccessibleSelection getAccessibleSelection() {
  464               return this;
  465           }
  466   
  467           /**
  468            * Gets the accessible name of this object.  This should almost never
  469            * return <code>java.awt.MenuComponent.getName</code>, as that
  470            * generally isn't a localized name, and doesn't have meaning for the
  471            * user.  If the object is fundamentally a text object (e.g. a menu item), the
  472            * accessible name should be the text of the object (e.g. "save").
  473            * If the object has a tooltip, the tooltip text may also be an
  474            * appropriate String to return.
  475            *
  476            * @return the localized name of the object -- can be <code>null</code>
  477            *         if this object does not have a name
  478            * @see AccessibleContext#setAccessibleName
  479            */
  480           public String getAccessibleName() {
  481               return accessibleName;
  482           }
  483   
  484           /**
  485            * Gets the accessible description of this object.  This should be
  486            * a concise, localized description of what this object is - what
  487            * is its meaning to the user.  If the object has a tooltip, the
  488            * tooltip text may be an appropriate string to return, assuming
  489            * it contains a concise description of the object (instead of just
  490            * the name of the object - e.g. a "Save" icon on a toolbar that
  491            * had "save" as the tooltip text shouldn't return the tooltip
  492            * text as the description, but something like "Saves the current
  493            * text document" instead).
  494            *
  495            * @return the localized description of the object -- can be
  496            *     <code>null</code> if this object does not have a description
  497            * @see AccessibleContext#setAccessibleDescription
  498            */
  499           public String getAccessibleDescription() {
  500               return accessibleDescription;
  501           }
  502   
  503           /**
  504            * Gets the role of this object.
  505            *
  506            * @return an instance of <code>AccessibleRole</code>
  507            *     describing the role of the object
  508            * @see AccessibleRole
  509            */
  510           public AccessibleRole getAccessibleRole() {
  511               return AccessibleRole.AWT_COMPONENT; // Non-specific -- overridden in subclasses
  512           }
  513   
  514           /**
  515            * Gets the state of this object.
  516            *
  517            * @return an instance of <code>AccessibleStateSet</code>
  518            *     containing the current state set of the object
  519            * @see AccessibleState
  520            */
  521           public AccessibleStateSet getAccessibleStateSet() {
  522               return MenuComponent.this.getAccessibleStateSet();
  523           }
  524   
  525           /**
  526            * Gets the <code>Accessible</code> parent of this object.
  527            * If the parent of this object implements <code>Accessible</code>,
  528            * this method should simply return <code>getParent</code>.
  529            *
  530            * @return the <code>Accessible</code> parent of this object -- can
  531            *    be <code>null</code> if this object does not have an
  532            *    <code>Accessible</code> parent
  533            */
  534           public Accessible getAccessibleParent() {
  535               if (accessibleParent != null) {
  536                   return accessibleParent;
  537               } else {
  538                   MenuContainer parent = MenuComponent.this.getParent();
  539                   if (parent instanceof Accessible) {
  540                       return (Accessible) parent;
  541                   }
  542               }
  543               return null;
  544           }
  545   
  546           /**
  547            * Gets the index of this object in its accessible parent.
  548            *
  549            * @return the index of this object in its parent; -1 if this
  550            *     object does not have an accessible parent
  551            * @see #getAccessibleParent
  552            */
  553           public int getAccessibleIndexInParent() {
  554               return MenuComponent.this.getAccessibleIndexInParent();
  555           }
  556   
  557           /**
  558            * Returns the number of accessible children in the object.  If all
  559            * of the children of this object implement <code>Accessible</code>,
  560            * then this method should return the number of children of this object.
  561            *
  562            * @return the number of accessible children in the object
  563            */
  564           public int getAccessibleChildrenCount() {
  565               return 0; // MenuComponents don't have children
  566           }
  567   
  568           /**
  569            * Returns the nth <code>Accessible</code> child of the object.
  570            *
  571            * @param i zero-based index of child
  572            * @return the nth Accessible child of the object
  573            */
  574           public Accessible getAccessibleChild(int i) {
  575               return null; // MenuComponents don't have children
  576           }
  577   
  578           /**
  579            * Returns the locale of this object.
  580            *
  581            * @return the locale of this object
  582            */
  583           public java.util.Locale getLocale() {
  584               MenuContainer parent = MenuComponent.this.getParent();
  585               if (parent instanceof Component)
  586                   return ((Component)parent).getLocale();
  587               else
  588                   return java.util.Locale.getDefault();
  589           }
  590   
  591           /**
  592            * Gets the <code>AccessibleComponent</code> associated with
  593            * this object if one exists.  Otherwise return <code>null</code>.
  594            *
  595            * @return the component
  596            */
  597           public AccessibleComponent getAccessibleComponent() {
  598               return this;
  599           }
  600   
  601   
  602           // AccessibleComponent methods
  603           //
  604           /**
  605            * Gets the background color of this object.
  606            *
  607            * @return the background color, if supported, of the object;
  608            *     otherwise, <code>null</code>
  609            */
  610           public Color getBackground() {
  611               return null; // Not supported for MenuComponents
  612           }
  613   
  614           /**
  615            * Sets the background color of this object.
  616            * (For transparency, see <code>isOpaque</code>.)
  617            *
  618            * @param c the new <code>Color</code> for the background
  619            * @see Component#isOpaque
  620            */
  621           public void setBackground(Color c) {
  622               // Not supported for MenuComponents
  623           }
  624   
  625           /**
  626            * Gets the foreground color of this object.
  627            *
  628            * @return the foreground color, if supported, of the object;
  629            *     otherwise, <code>null</code>
  630            */
  631           public Color getForeground() {
  632               return null; // Not supported for MenuComponents
  633           }
  634   
  635           /**
  636            * Sets the foreground color of this object.
  637            *
  638            * @param c the new <code>Color</code> for the foreground
  639            */
  640           public void setForeground(Color c) {
  641               // Not supported for MenuComponents
  642           }
  643   
  644           /**
  645            * Gets the <code>Cursor</code> of this object.
  646            *
  647            * @return the <code>Curso</code>, if supported, of the object;
  648            *     otherwise, <code>null</code>
  649            */
  650           public Cursor getCursor() {
  651               return null; // Not supported for MenuComponents
  652           }
  653   
  654           /**
  655            * Sets the <code>Cursor</code> of this object.
  656            * <p>
  657            * The method may have no visual effect if the Java platform
  658            * implementation and/or the native system do not support
  659            * changing the mouse cursor shape.
  660            * @param cursor the new <code>Cursor</code> for the object
  661            */
  662           public void setCursor(Cursor cursor) {
  663               // Not supported for MenuComponents
  664           }
  665   
  666           /**
  667            * Gets the <code>Font</code> of this object.
  668            *
  669            * @return the <code>Font</code>,if supported, for the object;
  670            *     otherwise, <code>null</code>
  671            */
  672           public Font getFont() {
  673               return MenuComponent.this.getFont();
  674           }
  675   
  676           /**
  677            * Sets the <code>Font</code> of this object.
  678            *
  679            * @param f the new <code>Font</code> for the object
  680            */
  681           public void setFont(Font f) {
  682               MenuComponent.this.setFont(f);
  683           }
  684   
  685           /**
  686            * Gets the <code>FontMetrics</code> of this object.
  687            *
  688            * @param f the <code>Font</code>
  689            * @return the FontMetrics, if supported, the object;
  690            *              otherwise, <code>null</code>
  691            * @see #getFont
  692            */
  693           public FontMetrics getFontMetrics(Font f) {
  694               return null; // Not supported for MenuComponents
  695           }
  696   
  697           /**
  698            * Determines if the object is enabled.
  699            *
  700            * @return true if object is enabled; otherwise, false
  701            */
  702           public boolean isEnabled() {
  703               return true; // Not supported for MenuComponents
  704           }
  705   
  706           /**
  707            * Sets the enabled state of the object.
  708            *
  709            * @param b if true, enables this object; otherwise, disables it
  710            */
  711           public void setEnabled(boolean b) {
  712               // Not supported for MenuComponents
  713           }
  714   
  715           /**
  716            * Determines if the object is visible.  Note: this means that the
  717            * object intends to be visible; however, it may not in fact be
  718            * showing on the screen because one of the objects that this object
  719            * is contained by is not visible.  To determine if an object is
  720            * showing on the screen, use <code>isShowing</code>.
  721            *
  722            * @return true if object is visible; otherwise, false
  723            */
  724           public boolean isVisible() {
  725               return true; // Not supported for MenuComponents
  726           }
  727   
  728           /**
  729            * Sets the visible state of the object.
  730            *
  731            * @param b if true, shows this object; otherwise, hides it
  732            */
  733           public void setVisible(boolean b) {
  734               // Not supported for MenuComponents
  735           }
  736   
  737           /**
  738            * Determines if the object is showing.  This is determined by checking
  739            * the visibility of the object and ancestors of the object.  Note:
  740            * this will return true even if the object is obscured by another
  741            * (for example, it happens to be underneath a menu that was pulled
  742            * down).
  743            *
  744            * @return true if object is showing; otherwise, false
  745            */
  746           public boolean isShowing() {
  747               return true; // Not supported for MenuComponents
  748           }
  749   
  750           /**
  751            * Checks whether the specified point is within this object's bounds,
  752            * where the point's x and y coordinates are defined to be relative to
  753            * the coordinate system of the object.
  754            *
  755            * @param p the <code>Point</code> relative to the coordinate
  756            *     system of the object
  757            * @return true if object contains <code>Point</code>; otherwise false
  758            */
  759           public boolean contains(Point p) {
  760               return false; // Not supported for MenuComponents
  761           }
  762   
  763           /**
  764            * Returns the location of the object on the screen.
  765            *
  766            * @return location of object on screen -- can be <code>null</code>
  767            *     if this object is not on the screen
  768            */
  769           public Point getLocationOnScreen() {
  770               return null; // Not supported for MenuComponents
  771           }
  772   
  773           /**
  774            * Gets the location of the object relative to the parent in the form
  775            * of a point specifying the object's top-left corner in the screen's
  776            * coordinate space.
  777            *
  778            * @return an instance of <code>Point</code> representing the
  779            *    top-left corner of the object's bounds in the coordinate
  780            *    space of the screen; <code>null</code> if
  781            *    this object or its parent are not on the screen
  782            */
  783           public Point getLocation() {
  784               return null; // Not supported for MenuComponents
  785           }
  786   
  787           /**
  788            * Sets the location of the object relative to the parent.
  789            */
  790           public void setLocation(Point p) {
  791               // Not supported for MenuComponents
  792           }
  793   
  794           /**
  795            * Gets the bounds of this object in the form of a
  796            * <code>Rectangle</code> object.
  797            * The bounds specify this object's width, height, and location
  798            * relative to its parent.
  799            *
  800            * @return a rectangle indicating this component's bounds;
  801            *     <code>null</code> if this object is not on the screen
  802            */
  803           public Rectangle getBounds() {
  804               return null; // Not supported for MenuComponents
  805           }
  806   
  807           /**
  808            * Sets the bounds of this object in the form of a
  809            * <code>Rectangle</code> object.
  810            * The bounds specify this object's width, height, and location
  811            * relative to its parent.
  812            *
  813            * @param r a rectangle indicating this component's bounds
  814            */
  815           public void setBounds(Rectangle r) {
  816               // Not supported for MenuComponents
  817           }
  818   
  819           /**
  820            * Returns the size of this object in the form of a
  821            * <code>Dimension</code> object. The height field of
  822            * the <code>Dimension</code> object contains this object's
  823            * height, and the width field of the <code>Dimension</code>
  824            * object contains this object's width.
  825            *
  826            * @return a <code>Dimension</code> object that indicates the
  827            *         size of this component; <code>null</code>
  828            *         if this object is not on the screen
  829            */
  830           public Dimension getSize() {
  831               return null; // Not supported for MenuComponents
  832           }
  833   
  834           /**
  835            * Resizes this object.
  836            *
  837            * @param d - the <code>Dimension</code> specifying the
  838            *    new size of the object
  839            */
  840           public void setSize(Dimension d) {
  841               // Not supported for MenuComponents
  842           }
  843   
  844           /**
  845            * Returns the <code>Accessible</code> child, if one exists,
  846            * contained at the local coordinate <code>Point</code>.
  847            * If there is no <code>Accessible</code> child, <code>null</code>
  848            * is returned.
  849            *
  850            * @param p the point defining the top-left corner of the
  851            *    <code>Accessible</code>, given in the coordinate space
  852            *    of the object's parent
  853            * @return the <code>Accessible</code>, if it exists,
  854            *    at the specified location; else <code>null</code>
  855            */
  856           public Accessible getAccessibleAt(Point p) {
  857               return null; // MenuComponents don't have children
  858           }
  859   
  860           /**
  861            * Returns whether this object can accept focus or not.
  862            *
  863            * @return true if object can accept focus; otherwise false
  864            */
  865           public boolean isFocusTraversable() {
  866               return true; // Not supported for MenuComponents
  867           }
  868   
  869           /**
  870            * Requests focus for this object.
  871            */
  872           public void requestFocus() {
  873               // Not supported for MenuComponents
  874           }
  875   
  876           /**
  877            * Adds the specified focus listener to receive focus events from this
  878            * component.
  879            *
  880            * @param l the focus listener
  881            */
  882           public void addFocusListener(java.awt.event.FocusListener l) {
  883               // Not supported for MenuComponents
  884           }
  885   
  886           /**
  887            * Removes the specified focus listener so it no longer receives focus
  888            * events from this component.
  889            *
  890            * @param l the focus listener
  891            */
  892           public void removeFocusListener(java.awt.event.FocusListener l) {
  893               // Not supported for MenuComponents
  894           }
  895   
  896           // AccessibleSelection methods
  897           //
  898   
  899           /**
  900            * Returns the number of <code>Accessible</code> children currently selected.
  901            * If no children are selected, the return value will be 0.
  902            *
  903            * @return the number of items currently selected
  904            */
  905            public int getAccessibleSelectionCount() {
  906                return 0;  //  To be fully implemented in a future release
  907            }
  908   
  909           /**
  910            * Returns an <code>Accessible</code> representing the specified
  911            * selected child in the object.  If there isn't a selection, or there are
  912            * fewer children selected than the integer passed in, the return
  913            * value will be <code>null</code>.
  914            * <p>Note that the index represents the i-th selected child, which
  915            * is different from the i-th child.
  916            *
  917            * @param i the zero-based index of selected children
  918            * @return the i-th selected child
  919            * @see #getAccessibleSelectionCount
  920            */
  921            public Accessible getAccessibleSelection(int i) {
  922                return null;  //  To be fully implemented in a future release
  923            }
  924   
  925           /**
  926            * Determines if the current child of this object is selected.
  927            *
  928            * @return true if the current child of this object is selected;
  929            *    else false
  930            * @param i the zero-based index of the child in this
  931            *      <code>Accessible</code> object
  932            * @see AccessibleContext#getAccessibleChild
  933            */
  934            public boolean isAccessibleChildSelected(int i) {
  935                return false;  //  To be fully implemented in a future release
  936            }
  937   
  938           /**
  939            * Adds the specified <code>Accessible</code> child of the object
  940            * to the object's selection.  If the object supports multiple selections,
  941            * the specified child is added to any existing selection, otherwise
  942            * it replaces any existing selection in the object.  If the
  943            * specified child is already selected, this method has no effect.
  944            *
  945            * @param i the zero-based index of the child
  946            * @see AccessibleContext#getAccessibleChild
  947            */
  948            public void addAccessibleSelection(int i) {
  949                  //  To be fully implemented in a future release
  950            }
  951   
  952           /**
  953            * Removes the specified child of the object from the object's
  954            * selection.  If the specified item isn't currently selected, this
  955            * method has no effect.
  956            *
  957            * @param i the zero-based index of the child
  958            * @see AccessibleContext#getAccessibleChild
  959            */
  960            public void removeAccessibleSelection(int i) {
  961                  //  To be fully implemented in a future release
  962            }
  963   
  964           /**
  965            * Clears the selection in the object, so that no children in the
  966            * object are selected.
  967            */
  968            public void clearAccessibleSelection() {
  969                  //  To be fully implemented in a future release
  970            }
  971   
  972           /**
  973            * Causes every child of the object to be selected
  974            * if the object supports multiple selections.
  975            */
  976            public void selectAllAccessibleSelection() {
  977                  //  To be fully implemented in a future release
  978            }
  979   
  980       } // inner class AccessibleAWTComponent
  981   
  982       /**
  983        * Gets the index of this object in its accessible parent.
  984        *
  985        * @return -1 if this object does not have an accessible parent;
  986        *      otherwise, the index of the child in its accessible parent.
  987        */
  988       int getAccessibleIndexInParent() {
  989           MenuContainer localParent = parent;
  990           if (!(localParent instanceof MenuComponent)) {
  991               // MenuComponents only have accessible index when inside MenuComponents
  992               return -1;
  993           }
  994           MenuComponent localParentMenu = (MenuComponent)localParent;
  995           return localParentMenu.getAccessibleChildIndex(this);
  996       }
  997   
  998       /**
  999        * Gets the index of the child within this MenuComponent.
 1000        *
 1001        * @param child MenuComponent whose index we are interested in.
 1002        * @return -1 if this object doesn't contain the child,
 1003        *      otherwise, index of the child.
 1004        */
 1005       int getAccessibleChildIndex(MenuComponent child) {
 1006           return -1; // Overridden in subclasses.
 1007       }
 1008   
 1009       /**
 1010        * Gets the state of this object.
 1011        *
 1012        * @return an instance of <code>AccessibleStateSet</code>
 1013        *     containing the current state set of the object
 1014        * @see AccessibleState
 1015        */
 1016       AccessibleStateSet getAccessibleStateSet() {
 1017           AccessibleStateSet states = new AccessibleStateSet();
 1018           return states;
 1019       }
 1020   
 1021   }

Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]