[cp-patches] FYI: JComponent - 4 methods implemented

David Gilbert david.gilbert at object-refinery.com
Wed Jun 28 13:01:13 UTC 2006


This patch (committed) implements 4 methods that were introduced in JDK 1.5:

2006-06-28  David Gilbert  <david.gilbert at object-refinery.com>

	* javax/swing/JComponent.java
	(componentPopupMenu): New field,
	(inheritsPopupMenu): New field,
	(getInheritsPopupMenu): Implemented,
	(setInheritsPopupMenu): Likewise,
	(getComponentPopupMenu): Likewise,
	(setComponentPopupMenu): Likewise,
	* javax/swing/JLabel.java
	(JLabel(String, Icon, int)): Set inheritsPopupMenu to true.

I'm guessing the menus need to be dealt with by the UI classes, but that is not 
implemented yet.  Mauve tests to follow.

Regards,

Dave
-------------- next part --------------
Index: javax/swing/JComponent.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.132
diff -u -r1.132 JComponent.java
--- javax/swing/JComponent.java	27 Jun 2006 08:58:36 -0000	1.132
+++ javax/swing/JComponent.java	28 Jun 2006 12:51:58 -0000
@@ -572,6 +572,21 @@
    */
    String toolTipText;
 
+  /**
+   * The popup menu for the component.
+   * 
+   * @see #getComponentPopupMenu()
+   * @see #setComponentPopupMenu(JPopupMenu)
+   */
+  JPopupMenu componentPopupMenu;
+   
+  /**
+   * A flag that controls whether the {@link #getComponentPopupMenu()} method
+   * looks to the component's parent when the <code>componentPopupMenu</code>
+   * field is <code>null</code>.
+   */
+  boolean inheritsPopupMenu;
+  
   /** 
    * <p>Whether to double buffer this component when painting. This flag
    * should generally be <code>true</code>, to ensure good painting
@@ -1524,8 +1539,90 @@
   {
     return getToolTipText();
   }
+  
+  /**
+   * Returns the flag that controls whether or not the component inherits its
+   * parent's popup menu when no popup menu is specified for this component.
+   * 
+   * @return A boolean.
+   * 
+   * @since 1.5
+   * 
+   * @see #setInheritsPopupMenu(boolean)
+   */
+  public boolean getInheritsPopupMenu()
+  {
+    return inheritsPopupMenu; 
+  }
+  
+  /**
+   * Sets the flag that controls whether or not the component inherits its
+   * parent's popup menu when no popup menu is specified for this component.
+   * This is a bound property with the property name 'inheritsPopupMenu'.
+   * 
+   * @param inherit  the new flag value.
+   * 
+   * @since 1.5
+   * 
+   * @see #getInheritsPopupMenu()
+   */
+  public void setInheritsPopupMenu(boolean inherit)
+  {
+    if (inheritsPopupMenu != inherit)
+      {
+        inheritsPopupMenu = inherit;
+        this.firePropertyChange("inheritsPopupMenu", ! inherit, inherit);
+      }
+  }
+  
+  /**
+   * Returns the popup menu for this component.  If the popup menu is 
+   * <code>null</code> AND the {@link #getInheritsPopupMenu()} method returns
+   * <code>true</code>, this method will return the parent's popup menu (if it
+   * has one).
+   * 
+   * @return The popup menu (possibly <code>null</code>.
+   * 
+   * @since 1.5
+   * 
+   * @see #setComponentPopupMenu(JPopupMenu)
+   * @see #getInheritsPopupMenu()
+   */
+  public JPopupMenu getComponentPopupMenu()
+  {
+    if (componentPopupMenu == null && getInheritsPopupMenu())
+      {
+        Container parent = getParent(); 
+        if (parent instanceof JComponent)
+          return ((JComponent) parent).getComponentPopupMenu();
+        else
+          return null;
+      }
+    else
+      return componentPopupMenu;
+  }
 
   /**
+   * Sets the popup menu for this component (this is a bound property with 
+   * the property name 'componentPopupMenu').
+   * 
+   * @param popup  the popup menu (<code>null</code> permitted).
+   *
+   * @since 1.5
+   * 
+   * @see #getComponentPopupMenu()
+   */
+  public void setComponentPopupMenu(JPopupMenu popup)
+  {
+    if (componentPopupMenu != popup)
+      {
+        JPopupMenu old = componentPopupMenu;
+        componentPopupMenu = popup;
+        firePropertyChange("componentPopupMenu", old, popup);
+      }
+  }
+  
+  /**
    * Return the top level ancestral container (usually a {@link
    * java.awt.Window} or {@link java.applet.Applet}) which this component is
    * contained within, or <code>null</code> if no ancestors exist.
Index: javax/swing/JLabel.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JLabel.java,v
retrieving revision 1.40
diff -u -r1.40 JLabel.java
--- javax/swing/JLabel.java	22 Jun 2006 15:44:51 -0000	1.40
+++ javax/swing/JLabel.java	28 Jun 2006 12:51:59 -0000
@@ -436,6 +436,7 @@
     this.icon = icon;
     this.horizontalAlignment = horizontalAlignment;
     setAlignmentX(0.0F);
+    setInheritsPopupMenu(true);
     updateUI();
   }
 


More information about the Classpath-patches mailing list