diff options
Diffstat (limited to 'libjava/javax/swing/JPopupMenu.java')
-rw-r--r-- | libjava/javax/swing/JPopupMenu.java | 108 |
1 files changed, 46 insertions, 62 deletions
diff --git a/libjava/javax/swing/JPopupMenu.java b/libjava/javax/swing/JPopupMenu.java index 76f6362..00998b8 100644 --- a/libjava/javax/swing/JPopupMenu.java +++ b/libjava/javax/swing/JPopupMenu.java @@ -1,5 +1,5 @@ -/* JPopupMenu.java - Copyright (C) 2002, 2004 Free Software Foundation, Inc. +/* JPopupMenu.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,7 +41,6 @@ package javax.swing; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; -import java.awt.Graphics; import java.awt.GridBagConstraints; import java.awt.Insets; import java.awt.Panel; @@ -53,6 +52,7 @@ import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.ArrayList; import java.util.EventListener; import javax.accessibility.Accessible; @@ -92,12 +92,6 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement { private static final long serialVersionUID = -8336996630009646009L; - /** name for the UI delegate for this menuItem. */ - private static final String uiClassID = "PopupMenuUI"; - - /** Fire a PropertyChangeEvent when the "borderPainted" property changes. */ - public static final String LABEL_CHANGED_PROPERTY = "label"; - /* indicates if popup's menu border should be painted*/ private boolean borderPainted = true; @@ -142,19 +136,12 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement /* Field indicating if popup menu is visible or not */ private boolean visible = false; - /* Bound Property indicating visibility of the popup menu*/ - public static final String VISIBLE_CHANGED_PROPERTY = "visible"; - /** * Creates a new JPopupMenu object. */ public JPopupMenu() { - updateUI(); - - lightWeightPopupEnabled = DefaultLightWeightPopupEnabled; - selectionModel = new DefaultSingleSelectionModel(); - super.setVisible(false); + this(null); } /** @@ -164,7 +151,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement */ public JPopupMenu(String label) { + lightWeightPopupEnabled = getDefaultLightWeightPopupEnabled(); setLabel(label); + setSelectionModel(new DefaultSingleSelectionModel()); + super.setVisible(false); + updateUI(); } private void readObject(ObjectInputStream stream) @@ -177,12 +168,12 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * Adds given menu item to the popup menu - * - * @param item menu item to add to the popup menu - * - * @return menu item that was added to the popup menu - */ + * Adds given menu item to the popup menu + * + * @param item menu item to add to the popup menu + * + * @return menu item that was added to the popup menu + */ public JMenuItem add(JMenuItem item) { this.insert(item, -1); @@ -291,18 +282,6 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * Paints popup menu's border if borderPainted is true - * - * @param graphics graphics context used to paint this popup's menu border. - */ - protected void borderPainted(Graphics graphics) - { - if (borderPainted) - getBorder().paintBorder(this, graphics, 0, 0, getSize(null).width, - getSize(null).height); - } - - /** * Returns flag indicating if newly created JPopupMenu will use * heavyweight or lightweight container to display its menu items * @@ -386,10 +365,7 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement */ public void setSelectionModel(SingleSelectionModel model) { - if (selectionModel != model) - { - SingleSelectionModel oldModel = this.selectionModel; - } + selectionModel = model; } /** @@ -452,7 +428,7 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement /** * Sets label for this popup menu. This method fires PropertyChangeEvent * when the label property is changed. Please note that most - * of the Look & Feel will ignore this property. + * of the Look & Feel will ignore this property. * * @param label label for this popup menu */ @@ -461,8 +437,8 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement if (label != this.label) { String oldLabel = this.label; - this.label = label; - firePropertyChange(LABEL_CHANGED_PROPERTY, oldLabel, label); + this.label = label; + firePropertyChange("label", oldLabel, label); } } @@ -574,11 +550,14 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement */ public void setVisible(boolean visible) { + if (visible == isVisible()) + return; + boolean old = isVisible(); this.visible = visible; if (old != isVisible()) { - firePropertyChange(VISIBLE_CHANGED_PROPERTY, old, (boolean) isVisible()); + firePropertyChange("visible", old, isVisible()); if (visible) { firePopupMenuWillBecomeVisible(); @@ -619,11 +598,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement { // Subtract insets of the top-level container if popup menu's // top-left corner is inside it. - Insets insets = rootContainer.getInsets(); - popup.show(popupLocation.x - insets.left, - popupLocation.y - insets.top, size.width, - size.height); - } + Insets insets = rootContainer.getInsets(); + popup.show(popupLocation.x - insets.left, + popupLocation.y - insets.top, size.width, + size.height); + } } else { @@ -791,7 +770,17 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement */ protected String paramString() { - return "JPopupMenu"; + StringBuffer sb = new StringBuffer(); + sb.append(super.paramString()); + sb.append(",label="); + if (getLabel() != null) + sb.append(getLabel()); + sb.append(",lightWeightPopupEnabled=").append(isLightWeightPopupEnabled()); + sb.append(",margin="); + if (getMargin() != null) + sb.append(margin); + sb.append(",paintBorder=").append(isBorderPainted()); + return sb.toString(); } /** @@ -839,19 +828,22 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * Return subcomonents of this popup menu. + * Return subcomonents of this popup menu. This method returns only + * components that implement the <code>MenuElement</code> interface. * - * @return Array containing menuItem's of belonging to this popup menu. + * @return array of menu items belonging to this popup menu */ public MenuElement[] getSubElements() { Component[] items = getComponents(); - MenuElement[] subElements = new MenuElement[items.length]; + ArrayList subElements = new ArrayList(); for (int i = 0; i < items.length; i++) - subElements[i] = (MenuElement) items[i]; + if (items[i] instanceof MenuElement) + subElements.add(items[i]); - return subElements; + return (MenuElement[]) + subElements.toArray(new MenuElement[subElements.size()]); } /** @@ -1038,14 +1030,6 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement this.setBounds(x, y, width, height); this.show(); } - - /** - * Hides JWindow with menu item's from the screen. - */ - public void hide() - { - super.hide(); - } } /** |