[Patch][gui] TextAction
Michael Koch
konqueror@gmx.de
Wed Dec 29 15:48:00 GMT 2004
Hi list,
I just commited the attached patch to implement
javax.swing.text.TextAction. Some mauve testcases for this exist now
too.
Michael
2004-12-29 Michael Koch <konqueror@gmx.de>
* javax/swing/text/TextAction.java
(getTextComponent): Simplified. Added Javadoc.
(augmentList): Implemented. Added Javadoc.
(getFocusedComponent): Added javadoc.
-------------- next part --------------
Index: javax/swing/text/TextAction.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/TextAction.java,v
retrieving revision 1.2.8.3
diff -u -r1.2.8.3 TextAction.java
--- javax/swing/text/TextAction.java 22 Oct 2004 12:41:29 -0000 1.2.8.3
+++ javax/swing/text/TextAction.java 29 Dec 2004 13:34:31 -0000
@@ -39,6 +39,8 @@
package javax.swing.text;
import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.HashSet;
import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -59,33 +61,48 @@
}
/**
- * getTextComponent
- * @param event TODO
- * @return JTextComponent
+ * Returns the <code>JTextComponent</code> object associated with the given
+ * <code>ActionEvent</code>. If the source of the event is not a
+ * <code>JTextComponent</code> the currently focused text component is returned.
+ *
+ * @param event the action event
+ *
+ * @return the <code>JTextComponent</code>
*/
protected final JTextComponent getTextComponent(ActionEvent event)
{
- if (event.getSource() != null &&
- event.getSource() instanceof JTextComponent)
+ if (event.getSource() instanceof JTextComponent)
return (JTextComponent) event.getSource();
- else
- return getFocusedComponent();
+
+ return getFocusedComponent();
}
/**
- * augmentList
- * @param list1 TODO
- * @param list2 TODO
- * @return Action[]
+ * Creates a new array of <code>Action</code> containing both given arrays.
+ *
+ * @param list1 the first action array
+ * @param list2 the second action array
+ *
+ * @return the augmented array of actions
*/
public static final Action[] augmentList(Action[] list1, Action[] list2)
{
- return null; // TODO
+ HashSet actionSet = new HashSet();
+
+ for (int i = 0; i < list1.length; ++i)
+ actionSet.add(list1[i]);
+
+ for (int i = 0; i < list2.length; ++i)
+ actionSet.add(list2[i]);
+
+ ArrayList list = new ArrayList(actionSet);
+ return (Action[]) list.toArray(new Action[actionSet.size()]);
}
/**
- * getFocusedComponent
- * @return JTextComponent
+ * Returns the current focused <code>JTextComponent</code> object.
+ *
+ * @return the <code>JTextComponent</code>
*/
protected final JTextComponent getFocusedComponent()
{
More information about the Java-patches
mailing list