This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] Patch: javax.swing - InputMap and ActionMap


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I just commited the attached patch to fix some things with InputMap 
and ActionMap in javax.swing.


Michael


2004-07-10  Michael Koch  <konqueror@gmx.de>

	* javax/swing/ActionMap.java:
	Fixed javadocs all over.
	(serialVersionUID): Made private.
	(parent): Don't explicitely initialize with default value.
	(get): SImplified.
	(keys): Reimplemented.
	(allKeys): Likewise.
	(convertSet): Removed.
	* javax/swing/ComponentInputMap.java:
	Fixed javadocs all over.
	(ComponentInputMap): Implemented.
	(put): Likewise.
	(clear): Likewise.
	(remove): Likewise.
	(SetParent): Likewise.
	(getComponent): Likewise.
	* javax/swing/InputMap.java:
	Fixed javadocs all over.
	(serialVersionUID): Made private.
	(parent): Don't explicitely initialize with default value.
	(get): SImplified.
	(keys): Reimplemented.
	(allKeys): Likewise.
	(convertSet): Removed.
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA78S8WSOgCCdjSDsRAsP/AJ9JjKXJKU2elCF8glgv4Cgt65gbKQCgml3N
7ltseDhEZdMStXrYH2YgHoY=
=WWbS
-----END PGP SIGNATURE-----
Index: javax/swing/ActionMap.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/ActionMap.java,v
retrieving revision 1.3.8.2
diff -u -b -B -r1.3.8.2 ActionMap.java
--- javax/swing/ActionMap.java	10 Jul 2004 09:44:06 -0000	1.3.8.2
+++ javax/swing/ActionMap.java	10 Jul 2004 10:23:47 -0000
@@ -56,7 +56,7 @@
 public class ActionMap
   implements Serializable
 {
-  static final long serialVersionUID = -6277518704513986346L;
+  private static final long serialVersionUID = -6277518704513986346L;
 
   /**
    * actionMap
@@ -66,29 +66,26 @@
   /**
    * parent
    */
-  private ActionMap parent = null;
+  private ActionMap parent;
 
   /**
-   * Constructor ActionMap
+   * Creates a new <code>ActionMap</code> instance.
    */
   public ActionMap()
   {
   }
 
   /**
-   * get
-   * @param key TODO
-   * @returns Action
+   * Returns an action associated with an object.
+   *
+   * @param key the key of the enty
+   *
+   * @return the action associated with key, may be null
    */
   public Action get(Object key)
   {
-    // Variables
-    Object result;
+    Object result = actionMap.get(key);
 
-    // Check Local store
-    result = actionMap.get(key);
-
-    // Check Parent
     if (result == null)
       result = parent.get(key);
 
@@ -96,9 +93,11 @@
   }
 
   /**
-   * put
-   * @param key TODO
-   * @param action TODO
+   * Puts a new <code>Action</code> into the <code>ActionMap</code>.
+   * If action is null an existing entry will be removed.
+   *
+   * @param key the key for the entry
+   * @param action the action.
    */
   public void put(Object key, Action action)
   {
@@ -109,8 +108,9 @@
   }
 
   /**
-   * remove
-   * @param key TODO
+   * Remove an entry from the <code>ActionMap</code>.
+   *
+   * @param key the key of the entry to remove
    */
   public void remove(Object key)
   {
@@ -118,8 +118,9 @@
   }
 
   /**
-   * getParent
-   * @returns ActionMap
+   * Returns the parent of this <code>ActionMap</code>.
+   *
+   * @return the parent, may be null.
    */
   public ActionMap getParent()
   {
@@ -127,8 +128,9 @@
   }
 
   /**
-   * setParent
-   * @param parentMap TODO
+   * Sets a parent for this <code>ActionMap</code>.
+   *
+   * @param parentMap the new parent
    */
   public void setParent(ActionMap parentMap)
   {
@@ -136,8 +138,9 @@
   }
 
   /**
-   * size
-   * @returns int
+   * Returns the number of entries in this <code>ActionMap</code>.
+   *
+   * @return the number of entries
    */
   public int size()
   {
@@ -145,7 +148,7 @@
   }
 
   /**
-   * clear
+   * Clears the <code>ActionMap</code>.
    */
   public void clear()
   {
@@ -153,67 +156,54 @@
   }
 
   /**
-   * keys
-   * @returns Object[]
+   * Returns all keys of entries in this <code>ActionMap</code>.
+   *
+   * @return an array of keys
    */
   public Object[] keys()
   {
-    return convertSet(actionMap.keySet());
+    return actionMap.keySet().toArray();
   }
 
   /**
-   * allKeys
-   * @returns Object[]
+   * Returns all keys of entries in this <code>ActionMap</code>
+   * and all its parents.
+   *
+   * @return an array of keys
    */
   public Object[] allKeys()
   {
-    // Variables
-    Set set;
-
-    // Initialize
-    set = new HashSet();
+    Set set = new HashSet();
 
-    // Get Key Sets
     if (parent != null)
       set.addAll(Arrays.asList(parent.allKeys()));
-    set.addAll(actionMap.keySet());
 
-    return convertSet(set);
-  } // allKeys()
-
-  private Object[] convertSet(Set set)
-  {
-    // Variables
-    int index;
-    Iterator iterator;
-    Object[] keys;
-
-    // Create Final array
-    keys = new Object[set.size()];
-    iterator = set.iterator();
-    index = 0;
-    while (iterator.hasNext())
-      keys[index++] = iterator.next();
-    return keys;
+    set.addAll(actionMap.keySet());
+    return set.toArray();
   }
 
   /**
    * writeObject
-   * @param stream TODO
-   * @exception IOException TODO
+   *
+   * @param stream the stream to write to
+   *
+   * @exception IOException If an error occurs
    */
-  private void writeObject(ObjectOutputStream value0) throws IOException
+  private void writeObject(ObjectOutputStream stream)
+    throws IOException
   {
     // TODO
   }
 
   /**
    * readObject
-   * @param stream TODO
-   * @exception ClassNotFoundException TODO
-   * @exception IOException TODO
+   *
+   * @param stream the stream to read from
+   *
+   * @exception ClassNotFoundException If the serialized class cannot be found
+   * @exception IOException If an error occurs
    */
-  private void readObject(ObjectInputStream value0)
+  private void readObject(ObjectInputStream stream)
     throws ClassNotFoundException, IOException
   {
     // TODO
Index: javax/swing/ComponentInputMap.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/ComponentInputMap.java,v
retrieving revision 1.1.52.1
diff -u -b -B -r1.1.52.1 ComponentInputMap.java
--- javax/swing/ComponentInputMap.java	10 Jul 2004 09:44:06 -0000	1.1.52.1
+++ javax/swing/ComponentInputMap.java	10 Jul 2004 10:23:47 -0000
@@ -45,61 +45,86 @@
 public class ComponentInputMap extends InputMap
 {
   /**
-   * component
+   * The component to notify.
    */
   private JComponent component;
 
   /**
-   * Constructor ComponentInputMap
-   * @param value0 TODO
+   * Creates <code>ComponentInputMap</code> object that notifies the given
+   * component about changes to it.
+   *
+   * @param comp the component to notify
+   *
+   * @exception IllegalArgumentException if comp is null
    */
-  public ComponentInputMap(JComponent value0)
+  public ComponentInputMap(JComponent comp)
   {
-    // TODO
+    if (comp == null)
+      throw new IllegalArgumentException();
+    
+    this.component = comp;
   }
 
   /**
-   * put
-   * @param keystroke TODO
-   * @param value TODO
+   * Puts a new entry into the <code>InputMap</code>.
+   * If actionMapKey is null an existing entry will be removed.
+   *
+   * @param keystroke the keystroke for the entry
+   * @param actionMapKey the action.
    */
   public void put(KeyStroke keystroke, Object value)
   {
-    // TODO
+    super.put(keystroke, value);
+    // FIXME: Notify component.
   }
 
   /**
-   * clear
+   * Clears the <code>InputMap</code>.
    */
   public void clear()
   {
-    // TODO
+    super.clear();
+    // FIXME: Notify component.
   }
 
   /**
-   * remove
-   * @param keystroke TODO
+   * Remove an entry from the <code>InputMap</code>.
+   *
+   * @param key the key of the entry to remove
    */
   public void remove(KeyStroke keystroke)
   {
-    // TODO
+    super.remove(keystroke);
+    // FIXME: Notify component.
   }
 
   /**
-   * setParent
-   * @param parent TODO
+   * Sets a parent for this <code>ComponentInputMap</code>.
+   *
+   * @param parentMap the new parent
+   *
+   * @exception IllegalArgument if parentMap is not a
+   * <code>ComponentInputMap</code> or not associated with the same component
    */
-  public void setParent(InputMap parent)
+  public void setParent(InputMap parentMap)
   {
-    // TODO
+    if (! (parentMap instanceof ComponentInputMap))
+      throw new IllegalArgumentException();
+
+    if (((ComponentInputMap) parentMap).getComponent() != component)
+      throw new IllegalArgumentException();
+   
+    super.setParent(parentMap);
+    // FIXME: Notify component.
   }
 
   /**
-   * getComponent
-   * @returns JComponent
+   * Returns the component to notify about changes.
+   *
+   * @return a <code>JComponent</code> object
    */
   public JComponent getComponent()
   {
-    return null; // TODO
+    return component;
   }
 }
Index: javax/swing/InputMap.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/InputMap.java,v
retrieving revision 1.3.18.1
diff -u -b -B -r1.3.18.1 InputMap.java
--- javax/swing/InputMap.java	10 Jul 2004 09:44:06 -0000	1.3.18.1
+++ javax/swing/InputMap.java	10 Jul 2004 10:23:47 -0000
@@ -58,7 +58,7 @@
 public class InputMap
   implements Serializable
 {
-  static final long serialVersionUID = -5429059542008604257L;
+  private static final long serialVersionUID = -5429059542008604257L;
 
   /**
    * inputMap
@@ -68,10 +68,10 @@
   /**
    * parent
    */
-  private InputMap parent = null;
+  private InputMap parent;
 
   /**
-   * Constructor InputMap
+   * Creates a new <code>InputMap</code> instance.
    */
   public InputMap()
   {
@@ -79,28 +79,27 @@
   }
 
   /**
-   * get
-   * @param value0 TODO
-   * @returns Object
+   * Returns the binding for keystroke.
+   *
+   * @param key the key of the enty
+   *
+   * @return the binding associated with keystroke may be null
    */
   public Object get(KeyStroke keystroke)
   {
-    // Variables
-    Object result;
+    Object result = inputMap.get(keystroke);
 
-    // Check Local store
-    result = inputMap.get(keystroke);
-
-    // Check Parent
     if (result == null)
       result = parent.get(keystroke);
     return result;
   }
 
   /**
-   * put
-   * @param keystroke TODO
-   * @param actionMapKey TODO
+   * Puts a new entry into the <code>InputMap</code>.
+   * If actionMapKey is null an existing entry will be removed.
+   *
+   * @param keystroke the keystroke for the entry
+   * @param actionMapKey the action.
    */
   public void put(KeyStroke keystroke, Object actionMapKey)
   {
@@ -111,8 +110,9 @@
   }
 
   /**
-   * remove
-   * @param keystroke TODO
+   * Remove an entry from the <code>InputMap</code>.
+   *
+   * @param key the key of the entry to remove
    */
   public void remove(KeyStroke keystroke)
   {
@@ -120,8 +120,9 @@
   }
 
   /**
-   * getParent
-   * @returns InputMap
+   * Returns the parent of this <code>InputMap</code>.
+   *
+   * @return the parent, may be null.
    */
   public InputMap getParent()
   {
@@ -129,8 +130,9 @@
   }
 
   /**
-   * setParent
-   * @param parentMap TODO
+   * Sets a parent for this <code>InputMap</code>.
+   *
+   * @param parentMap the new parent
    */
   public void setParent(InputMap parentMap)
   {
@@ -138,8 +140,9 @@
   }
 
   /**
-   * size
-   * @returns int
+   * Returns the number of entries in this <code>InputMap</code>.
+   *
+   * @return the number of entries
    */
   public int size()
   {
@@ -147,7 +150,7 @@
   }
 
   /**
-   * clear
+   * Clears the <code>InputMap</code>.
    */
   public void clear()
   {
@@ -155,54 +158,40 @@
   }
 
   /**
-   * keys
-   * @returns KeyStroke[]
+   * Returns all keys of entries in this <code>InputMap</code>.
+   *
+   * @return an array of keys
    */
   public KeyStroke[] keys()
   {
-    return convertSet(inputMap.keySet());
+    KeyStroke[] array = new KeyStroke[size()];
+    return (KeyStroke[]) inputMap.keySet().toArray(array);
   }
 
   /**
-   * allKeys
-   * @returns KeyStroke[]
+   * Returns all keys of entries in this <code>InputMap</code>
+   * and all its parents.
+   *
+   * @return an array of keys
    */
   public KeyStroke[] allKeys()
   {
-    // Variables
-    Set set;
-
-    // Initialize
-    set = new HashSet();
+    Set set = new HashSet();
 
-    // Get Key Sets
     if (parent != null)
       set.addAll(Arrays.asList(parent.allKeys()));
-    set.addAll(inputMap.keySet());
 
-    return convertSet(set);
-  } // allKeys()
-
-  private KeyStroke[] convertSet(Set set)
-  {
-    // Variables
-    int index;
-    Iterator iterator;
-    KeyStroke[] keys;
-
-    // Create Final array
-    keys = new KeyStroke[set.size()];
-    iterator = set.iterator();
-    index = 0;
-    while (iterator.hasNext())
-      keys[index++] = (KeyStroke) iterator.next();
-    return keys;
+    set.addAll(inputMap.keySet());
+    KeyStroke[] array = new KeyStroke[size()];
+    return (KeyStroke[]) set.toArray(array);
   }
 
   /**
    * writeObject
-   * @param stream TODO
-   * @exception IOException TODO
+   *
+   * @param stream the stream to write to
+   *
+   * @exception IOException If an error occurs
    */
   private void writeObject(ObjectOutputStream stream) throws IOException
   {
@@ -211,9 +200,11 @@
 
   /**
    * readObject
-   * @param stream TODO
-   * @exception ClassNotFoundException TODO
-   * @exception IOException TODO
+   *
+   * @param stream the stream to read from
+   *
+   * @exception ClassNotFoundException If the serialized class cannot be found
+   * @exception IOException If an error occurs
    */
   private void readObject(ObjectInputStream stream)
     throws ClassNotFoundException, IOException

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]