diff options
author | Sven de Marothy <sven@physto.se> | 2006-07-30 08:52:22 +0000 |
---|---|---|
committer | Sven de Marothy <sven@physto.se> | 2006-07-30 08:52:22 +0000 |
commit | fbcab5251aa8d5256e1493cab1cd4ebf909b9395 (patch) | |
tree | 84de77be77fed9c5bb03d1700ed7139d99093aa5 /java/awt/Choice.java | |
parent | 4be6500b670845c78ad862d1863746eb67950fdb (diff) | |
download | classpath-fbcab5251aa8d5256e1493cab1cd4ebf909b9395.tar.gz |
2006-07-30 Sven de Marothy <sven@physto.se>
* java/awt/Choice:
Reformat, fix copyright year.
Diffstat (limited to 'java/awt/Choice.java')
-rw-r--r-- | java/awt/Choice.java | 720 |
1 files changed, 320 insertions, 400 deletions
diff --git a/java/awt/Choice.java b/java/awt/Choice.java index f1da94bbe..7e3334d45 100644 --- a/java/awt/Choice.java +++ b/java/awt/Choice.java @@ -1,5 +1,5 @@ /* Choice.java -- Java choice button widget. - Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,56 +51,47 @@ import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; /** - * This class implements a drop down choice list. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This class implements a drop down choice list. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public class Choice extends Component implements ItemSelectable, Serializable, Accessible { + /** + * The number used to generate the name returned by getName. + */ + private static transient long next_choice_number; -/* - * Static Variables - */ - -/** - * The number used to generate the name returned by getName. - */ -private static transient long next_choice_number; - -// Serialization constant -private static final long serialVersionUID = -4075310674757313071L; - -/*************************************************************************/ + // Serialization constant + private static final long serialVersionUID = -4075310674757313071L; -/* - * Instance Variables - */ - -/** - * @serial A list of items for the choice box, which can be <code>null</code>. - * This is package-private to avoid an accessor method. - */ -Vector pItems = new Vector(); + /** + * @serial A list of items for the choice box, which can be <code>null</code>. + * This is package-private to avoid an accessor method. + */ + Vector pItems = new Vector(); -/** - * @serial The index of the selected item in the choice box. - */ -private int selectedIndex = -1; + /** + * @serial The index of the selected item in the choice box. + */ + private int selectedIndex = -1; -// Listener chain -private ItemListener item_listeners; + /** + * ItemListener chain + */ + private ItemListener item_listeners; -/** - * This class provides accessibility support for the - * combo box. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ + /** + * This class provides accessibility support for the + * combo box. + * + * @author Jerry Quinn (jlquinn@optonline.net) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + */ protected class AccessibleAWTChoice - extends AccessibleAWTComponent - implements AccessibleAction + extends AccessibleAWTComponent + implements AccessibleAction { /** @@ -193,12 +184,6 @@ private ItemListener item_listeners; } } -/*************************************************************************/ - -/* - * Constructors - */ - /** * Initializes a new instance of <code>Choice</code>. * @@ -211,397 +196,332 @@ private ItemListener item_listeners; throw new HeadlessException (); } -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the number of items in the list. - * - * @return The number of items in the list. - */ -public int -getItemCount() -{ - return countItems (); -} - -/*************************************************************************/ - -/** - * Returns the number of items in the list. - * - * @return The number of items in the list. - * - * @deprecated This method is deprecated in favor of <code>getItemCount</code>. - */ -public int -countItems() -{ - return(pItems.size()); -} - -/*************************************************************************/ - -/** - * Returns the item at the specified index in the list. - * - * @param index The index into the list to return the item from. - * - * @exception ArrayIndexOutOfBoundsException If the index is invalid. - */ -public String -getItem(int index) -{ - return((String)pItems.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Adds the specified item to this choice box. - * - * @param item The item to add. - * - * @exception NullPointerException If the item's value is null - * - * @since 1.1 - */ -public synchronized void -add(String item) -{ - if (item == null) - throw new NullPointerException ("item must be non-null"); - - pItems.addElement(item); - - int i = pItems.size () - 1; - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, i); - } - else if (selectedIndex == -1) - select(0); -} + /** + * Returns the number of items in the list. + * + * @return The number of items in the list. + */ + public int getItemCount() + { + return countItems (); + } -/*************************************************************************/ + /** + * Returns the number of items in the list. + * + * @return The number of items in the list. + * + * @deprecated This method is deprecated in favor of <code>getItemCount</code>. + */ + public int countItems() + { + return pItems.size(); + } -/** - * Adds the specified item to this choice box. - * - * This method is oboslete since Java 2 platform 1.1. Please use @see add - * instead. - * - * @param item The item to add. - * - * @exception NullPointerException If the item's value is equal to null - */ -public synchronized void -addItem(String item) -{ - add(item); -} + /** + * Returns the item at the specified index in the list. + * + * @param index The index into the list to return the item from. + * + * @exception ArrayIndexOutOfBoundsException If the index is invalid. + */ + public String getItem(int index) + { + return (String)pItems.elementAt(index); + } -/*************************************************************************/ + /** + * Adds the specified item to this choice box. + * + * @param item The item to add. + * + * @exception NullPointerException If the item's value is null + * + * @since 1.1 + */ + public synchronized void add(String item) + { + if (item == null) + throw new NullPointerException ("item must be non-null"); -/** 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. - * - * @exception IllegalArgumentException If index is less than 0 - */ -public synchronized void -insert(String item, int index) -{ - if (index < 0) - throw new IllegalArgumentException ("index may not be less then 0"); + pItems.addElement(item); - if (index > getItemCount ()) - index = getItemCount (); + int i = pItems.size () - 1; + if (peer != null) + { + ChoicePeer cp = (ChoicePeer) peer; + cp.add (item, i); + } + else if (selectedIndex == -1) + select(0); + } - pItems.insertElementAt(item, index); + /** + * Adds the specified item to this choice box. + * + * This method is oboslete since Java 2 platform 1.1. Please use @see add + * instead. + * + * @param item The item to add. + * + * @exception NullPointerException If the item's value is equal to null + */ + public synchronized void addItem(String item) + { + add(item); + } - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, index); - } - else if (selectedIndex == -1 || selectedIndex >= index) - select(0); -} + /** 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. + * + * @exception IllegalArgumentException If index is less than 0 + */ + public synchronized void insert(String item, int index) + { + if (index < 0) + throw new IllegalArgumentException ("index may not be less then 0"); -/*************************************************************************/ + if (index > getItemCount ()) + index = getItemCount (); -/** - * Removes the specified item from the choice box. - * - * @param item The item to remove. - * - * @exception IllegalArgumentException If the specified item doesn't exist. - */ -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); -} + pItems.insertElementAt(item, index); -/*************************************************************************/ + if (peer != null) + { + ChoicePeer cp = (ChoicePeer) peer; + cp.add (item, index); + } + else if (selectedIndex == -1 || selectedIndex >= index) + select(0); + } -/** - * Removes the item at the specified index from the choice box. - * - * @param index The index of the item to remove. - * - * @exception IndexOutOfBoundsException If the index is not valid. - */ -public synchronized void -remove(int index) -{ - if ((index < 0) || (index > getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); + /** + * Removes the specified item from the choice box. + * + * @param item The item to remove. + * + * @exception IllegalArgumentException If the specified item doesn't exist. + */ + 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); + } - pItems.removeElementAt(index); + /** + * Removes the item at the specified index from the choice box. + * + * @param index The index of the item to remove. + * + * @exception IndexOutOfBoundsException If the index is not valid. + */ + public synchronized void remove(int index) + { + if ((index < 0) || (index > getItemCount())) + throw new IllegalArgumentException("Bad index: " + index); - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.remove (index); - } - else - { - if (getItemCount() == 0) - selectedIndex = -1; - else if (index == selectedIndex) - select(0); - } + pItems.removeElementAt(index); - if (selectedIndex > index) - --selectedIndex; -} + if (peer != null) + { + ChoicePeer cp = (ChoicePeer) peer; + cp.remove (index); + } + else + { + if (getItemCount() == 0) + selectedIndex = -1; + else if (index == selectedIndex) + select(0); + } -/*************************************************************************/ + if (selectedIndex > index) + --selectedIndex; + } -/** - * Removes all of the objects from this choice box. - */ -public synchronized void -removeAll() -{ - if (getItemCount() <= 0) - return; + /** + * Removes all of the objects from this choice box. + */ + public synchronized void removeAll() + { + if (getItemCount() <= 0) + return; - pItems.removeAllElements (); - - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.removeAll (); - } - - selectedIndex = -1; -} - -/*************************************************************************/ + pItems.removeAllElements (); -/** - * Returns the currently selected item, or null if no item is - * selected. - * - * @return The currently selected item. - */ -public synchronized String -getSelectedItem() -{ - return (selectedIndex == -1 - ? null - : ((String)pItems.elementAt(selectedIndex))); -} - -/*************************************************************************/ + if (peer != null) + { + ChoicePeer cp = (ChoicePeer) peer; + cp.removeAll (); + } -/** - * Returns an array with one row containing the selected item. - * - * @return An array containing the selected item. - */ -public synchronized Object[] -getSelectedObjects() -{ - if (selectedIndex == -1) - return null; + selectedIndex = -1; + } - Object[] objs = new Object[1]; - objs[0] = pItems.elementAt(selectedIndex); + /** + * Returns the currently selected item, or null if no item is + * selected. + * + * @return The currently selected item. + */ + public synchronized String getSelectedItem() + { + return (selectedIndex == -1 + ? null + : ((String)pItems.elementAt(selectedIndex))); + } - return(objs); -} + /** + * Returns an array with one row containing the selected item. + * + * @return An array containing the selected item. + */ + public synchronized Object[] getSelectedObjects() + { + if (selectedIndex == -1) + return null; -/*************************************************************************/ + Object[] objs = new Object[1]; + objs[0] = pItems.elementAt(selectedIndex); -/** - * Returns the index of the selected item. - * - * @return The index of the selected item. - */ -public int -getSelectedIndex() -{ - return(selectedIndex); -} + return objs; + } -/*************************************************************************/ + /** + * Returns the index of the selected item. + * + * @return The index of the selected item. + */ + public int getSelectedIndex() + { + return selectedIndex; + } -/** - * Forces the item at the specified index to be selected. - * - * @param index The index of the row to make selected. - * - * @exception IllegalArgumentException If the specified index is invalid. - */ -public synchronized void -select(int index) -{ - if ((index < 0) || (index >= getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); + /** + * Forces the item at the specified index to be selected. + * + * @param index The index of the row to make selected. + * + * @exception IllegalArgumentException If the specified index is invalid. + */ + public synchronized void select(int index) + { + if ((index < 0) || (index >= getItemCount())) + throw new IllegalArgumentException("Bad index: " + index); - if (pItems.size() > 0) { + if (pItems.size() > 0) { selectedIndex = index; ChoicePeer cp = (ChoicePeer) peer; if (cp != null) { - cp.select(index); + cp.select(index); } + } } -} -/*************************************************************************/ - -/** - * Forces the named item to be selected. - * - * @param item The item to be selected. - * - * @exception IllegalArgumentException If the specified item does not exist. - */ -public synchronized void -select(String item) -{ - int index = pItems.indexOf(item); - if (index >= 0) - select(index); -} - -/*************************************************************************/ - -/** - * Creates the native peer for this object. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createChoice (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Adds the specified listener to the list of registered listeners for - * this object. - * - * @param listener The listener to add. - */ -public synchronized void -addItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.add(item_listeners, listener); -} - -/*************************************************************************/ + /** + * Forces the named item to be selected. + * + * @param item The item to be selected. + * + * @exception IllegalArgumentException If the specified item does not exist. + */ + public synchronized void select(String item) + { + int index = pItems.indexOf(item); + if (index >= 0) + select(index); + } -/** - * Removes the specified listener from the list of registered listeners for - * this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} + /** + * Creates the native peer for this object. + */ + public void addNotify() + { + if (peer == null) + peer = getToolkit ().createChoice (this); + super.addNotify (); + } -/*************************************************************************/ + /** + * Adds the specified listener to the list of registered listeners for + * this object. + * + * @param listener The listener to add. + */ + public synchronized void addItemListener(ItemListener listener) + { + item_listeners = AWTEventMulticaster.add(item_listeners, listener); + } -/** - * Processes this event by invoking <code>processItemEvent()</code> if the - * event is an instance of <code>ItemEvent</code>, otherwise the event - * is passed to the superclass. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ItemEvent) - processItemEvent((ItemEvent)event); - else - super.processEvent(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} + /** + * Removes the specified listener from the list of registered listeners for + * this object. + * + * @param listener The listener to remove. + */ + public synchronized void removeItemListener(ItemListener listener) + { + item_listeners = AWTEventMulticaster.remove(item_listeners, listener); + } -/*************************************************************************/ + /** + * Processes this event by invoking <code>processItemEvent()</code> if the + * event is an instance of <code>ItemEvent</code>, otherwise the event + * is passed to the superclass. + * + * @param event The event to process. + */ + protected void processEvent(AWTEvent event) + { + if (event instanceof ItemEvent) + processItemEvent((ItemEvent)event); + else + super.processEvent(event); + } -/** - * Processes item event by dispatching to any registered listeners. - * - * @param event The event to process. - */ -protected void -processItemEvent(ItemEvent event) -{ - int index = pItems.indexOf((String) event.getItem()); - // Don't call back into the peers when selecting index here - if (event.getStateChange() == ItemEvent.SELECTED) - this.selectedIndex = index; - if (item_listeners != null) - item_listeners.itemStateChanged(event); -} + void dispatchEventImpl(AWTEvent e) + { + if (e.id <= ItemEvent.ITEM_LAST + && e.id >= ItemEvent.ITEM_FIRST + && (item_listeners != null || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) + processEvent(e); + else + super.dispatchEventImpl(e); + } -/*************************************************************************/ + /** + * Processes item event by dispatching to any registered listeners. + * + * @param event The event to process. + */ + protected void processItemEvent(ItemEvent event) + { + int index = pItems.indexOf((String) event.getItem()); + // Don't call back into the peers when selecting index here + if (event.getStateChange() == ItemEvent.SELECTED) + this.selectedIndex = index; + if (item_listeners != null) + item_listeners.itemStateChanged(event); + } -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -protected String -paramString() -{ - return ("selectedIndex=" + selectedIndex + "," + super.paramString()); -} + /** + * Returns a debugging string for this object. + * + * @return A debugging string for this object. + */ + protected String paramString() + { + return "selectedIndex=" + selectedIndex + "," + super.paramString(); + } /** * Returns an array of all the objects currently registered as FooListeners |