summaryrefslogtreecommitdiff
path: root/java/awt/Choice.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2002-01-22 22:00:14 +0000
committerTom Tromey <tromey@redhat.com>2002-01-22 22:00:14 +0000
commit055c02559944c80442c8b9e144a0ce39c92bc7ea (patch)
treee0347d2c7548b2f4d91778c307d5161eed7fc0a9 /java/awt/Choice.java
parent4ac669bb646a8eb472dcfe8ca6489f76084a4a94 (diff)
downloadclasspath-055c02559944c80442c8b9e144a0ce39c92bc7ea.tar.gz
* java/awt/PopupMenu.java (addNotify): New implementation from
libgcj. * java/awt/MenuBar.java (add): Handle case where menu already has a parent. (deleteShortcut): Delete shortcut from all menus. (remove(int)): New implementation from libgcj. (setHelpMenu): Likewise. * java/awt/MenuItem.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/MenuComponent.java (toString): Call paramString. (paramString): Compute string; don't call toString. * java/awt/Label.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/Checkbox.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/Button.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/MenuComponent.java (getTreeLock): Now protected. * java/awt/Panel.java (addNotify): Call superclass addNotify. * java/awt/PaintContext.java: New file from libgcj. * java/awt/MenuShortcut.java (equals(Object)): New method. (hashCode): Likewise. (toString): Use paramString and square brackets. * java/awt/MenuContainer.java (postEvent): Resurrected. * java/awt/Menu.java (menuSerializedDataVersion): New field. (addNotify): Use peer field directly. Call superclass addNotify. (add): New implementation from libgcj. (separator): New field. (addSeparator): New implementation from libgcj. (insertSeparator): Likewise. (removeAll): Removed redundant test. Always remove item 0. (paramString): Include tearOff, isHelpMenu, and superclass paramString. * java/awt/List.java (List()): Default to 4 rows. (addNotify): Use `peer' directly. Call superclass addNotify. (addItem(String)): Deprecated. (add(String)): Call add, not addItem. (add(String,int)): Do work here. (addItem(String,int)): Call add. Deprecated. (removeAll): Use `clear' on items. Use `peer' field directly. (remove(String)): Use remove, not delItem. (replaceItem): Likewise. (remove(int)): New implementation from libgcj. (delItem(int)): Use remove. (getSelectedIndex): New implementation from libgcj. (getSelectedIndexes): Likewise. (isIndexSelected): Remove redundant test. (setMultipleMode): Use `peer' field directly. (makeVisible): Likewise. (paramString): New implementation from libgcj. (delItems): Run loop in reverse direction. Use `peer' field directly. * java/awt/Insets.java (equals): Removed redundant test. (hashCode): New method. * java/awt/GridBagConstraints.java: New file from libgcj. * java/awt/FontMetrics.java (getMaxAdvance): Return -1. (toString): Use libgcj implementation. * java/awt/Font.java (ROMAN_BASELINE, CENTER_BASELINE, HANGING_BASELINE): New constants. (pointSize): New field. (Font): Initialize pointSize. (getStyle): New method. (getSize2D): Likewise. * java/awt/FileDialog.java (addNotify): Use `peer' field directly. Call superclass addNotify. (paramString): Don't include class name or brackets. Call superclass paramString. (setDirectory): Use `peer' field directly. (setFile): Likewise. (setFilenameFilter): Likewise. * java/awt/Dialog.java (Dialog(Dialog)): New constructor. (Dialog(Dialog,String)): Likewise. (Dialog(Dialog,String,boolean)): Likewise. (addNotify): Use `peer' field directly. Call superclass addNotify. (setTitle): Use `peer' field directly. (setResizable): Likewise. (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/Cursor.java: Merged with libgcj. * java/awt/Color.java (white, lightGray, gray, darkGray, black, red, pink, orange, yellow, green, magenta, cyan, blue): Set alpha value. (value): Initialize. (Color(int,boolean)): New constructor. (Color(int,int,int,int)): Likewise. (alphamask): New constant. (getAlpha): New method. (BRIGHT_STEP): New constant. (brighter, darker): New implementation from libgcj. (getTransparency): New method. (equals): Remove redundant test. Compare `value' fields directly. * java/awt/Choice.java (selectedIndex): Initialize to -1. (add): Throw exception if item is null. Use `peer' field directly. Select item if it is the first. (addItem): Call add. (addNotify): Use `peer' field directly. Call superclass addNotify. (getSelectedItem): Handle case where selectedIndex is -1. (insert): Use `peer' field directly. Only cast if peer is non-null. Handle case where `index' is too large. Select item if it is the first one. (paramString): Don't include class name or brackets. Call superclass paramString. (remove(String)): Throw exception if item not found. (remove(int)): Use `peer' field directly. Update selection. (removeAll): Correctly remove items. Remove redundant check. (select(String)): Throw exception if item not found. (select(int)): Use `peer' field directly. Don't cast unless peer is non-null. * java/awt/CheckboxMenuItem.java (addNotify): Use `peer' field directly. Call superclass addNotify. (paramString): Don't include class name or brackets. Call superclass paramString. (processEvent): Call superclass processEvent. (setState): Use `peer' field directly. Don't cast unless peer is non-null.
Diffstat (limited to 'java/awt/Choice.java')
-rw-r--r--java/awt/Choice.java110
1 files changed, 72 insertions, 38 deletions
diff --git a/java/awt/Choice.java b/java/awt/Choice.java
index f26a74bc6..68064356d 100644
--- a/java/awt/Choice.java
+++ b/java/awt/Choice.java
@@ -1,5 +1,5 @@
/* Choice.java -- Java choice button widget.
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -63,7 +63,7 @@ private Vector pItems = new Vector();
/**
* @serial The index of the selected item in the choice box.
*/
-private int selectedIndex;
+private int selectedIndex = -1;
// Listener chain
private ItemListener item_listeners;
@@ -139,11 +139,20 @@ getItem(int index)
public synchronized void
add(String item)
{
+ if (item == null)
+ throw new IllegalArgumentException ("item must be non-null");
+
pItems.addElement(item);
- ChoicePeer cp = (ChoicePeer)getPeer();
- if (cp != null)
- cp.add(item, getItemCount());
+ int i = pItems.size () - 1;
+ if (peer != null)
+ {
+ ChoicePeer cp = (ChoicePeer) peer;
+ cp.add (item, i);
+ }
+
+ if (i == 0)
+ select (0);
}
/*************************************************************************/
@@ -156,29 +165,36 @@ add(String item)
public synchronized void
addItem(String item)
{
- pItems.addElement(item);
-
- ChoicePeer cp = (ChoicePeer)getPeer();
- if (cp != null)
- cp.addItem(item, getItemCount());
+ add(item);
}
/*************************************************************************/
-/**
- * Inserts the specified item to this choice box at the specified index.
- *
- * @param item The item to add.
- * @param index The index at which the item should be inserted.
- */
+/** Inserts an item into this Choice. Existing items are shifted
+ * upwards. If the new item is the only item, then it is selected.
+ * If the currently selected item is shifted, then the first item is
+ * selected. If the currently selected item is not shifted, then it
+ * remains selected.
+ *
+ * @param item The item to add.
+ * @param index The index at which the item should be inserted.
+ */
public synchronized void
insert(String item, int index)
{
+ if (index > getItemCount ())
+ index = getItemCount ();
+
pItems.insertElementAt(item, index);
- ChoicePeer cp = (ChoicePeer)getPeer();
- if (cp != null)
- cp.addItem(item, getItemCount());
+ if (peer != null)
+ {
+ ChoicePeer cp = (ChoicePeer) peer;
+ cp.add (item, index);
+ }
+
+ if (getItemCount () == 1 || selectedIndex >= index)
+ select (0);
}
/*************************************************************************/
@@ -194,6 +210,9 @@ public synchronized void
remove(String item)
{
int index = pItems.indexOf(item);
+ if (index == -1)
+ throw new IllegalArgumentException ("item \""
+ + item + "\" not found in Choice");
remove(index);
}
@@ -211,9 +230,16 @@ remove(int index)
{
pItems.removeElementAt(index);
- ChoicePeer cp = (ChoicePeer)getPeer();
- if (cp != null)
- cp.remove(index);
+ if (peer != null)
+ {
+ ChoicePeer cp = (ChoicePeer) peer;
+ cp.remove (index);
+ }
+
+ if (index == selectedIndex)
+ select (0);
+ else if (selectedIndex > index)
+ --selectedIndex;
}
/*************************************************************************/
@@ -226,24 +252,27 @@ removeAll()
{
int count = getItemCount();
- if (count > 0)
- for (int i = 0; i < count; i++)
- remove(i);
-
- pItems = new Vector();
+ for (int i = 0; i < count; i++)
+ {
+ // Always remove 0.
+ remove(0);
+ }
}
/*************************************************************************/
/**
- * Returns the currently selected item.
+ * Returns the currently selected item, or null if no item is
+ * selected.
*
* @return The currently selected item.
*/
public synchronized String
getSelectedItem()
{
- return((String)pItems.elementAt(selectedIndex));
+ return (selectedIndex == -1
+ ? null
+ : ((String)pItems.elementAt(selectedIndex)));
}
/*************************************************************************/
@@ -256,6 +285,9 @@ getSelectedItem()
public synchronized Object[]
getSelectedObjects()
{
+ if (selectedIndex == -1)
+ return null;
+
Object[] objs = new Object[1];
objs[0] = pItems.elementAt(selectedIndex);
@@ -291,10 +323,11 @@ select(int index)
throw new IllegalArgumentException("Bad index: " + index);
this.selectedIndex = index;
-
- ChoicePeer cp = (ChoicePeer)getPeer();
- if (cp != null)
- cp.select(index);
+ if (peer != null)
+ {
+ ChoicePeer cp = (ChoicePeer) peer;
+ cp.select (index);
+ }
}
/*************************************************************************/
@@ -310,7 +343,8 @@ public synchronized void
select(String item)
{
int index = pItems.indexOf(item);
- select(index);
+ if (index >= 0)
+ select(index);
}
/*************************************************************************/
@@ -321,8 +355,9 @@ select(String item)
public void
addNotify()
{
- if (getPeer() == null)
- setPeer((ComponentPeer)getToolkit().createChoice(this));
+ if (peer == null)
+ peer = getToolkit ().createChoice (this);
+ super.addNotify ();
}
/*************************************************************************/
@@ -395,8 +430,7 @@ processItemEvent(ItemEvent event)
protected String
paramString()
{
- return(getClass().getName() + "(selectedIndex=" + selectedIndex + ")");
+ return ("selectedIndex=" + selectedIndex + "," + super.paramString());
}
} // class Choice
-