diff options
Diffstat (limited to 'libjava/javax/swing/JTextField.java')
-rw-r--r-- | libjava/javax/swing/JTextField.java | 206 |
1 files changed, 159 insertions, 47 deletions
diff --git a/libjava/javax/swing/JTextField.java b/libjava/javax/swing/JTextField.java index 95fceaf50c6..46d35929a28 100644 --- a/libjava/javax/swing/JTextField.java +++ b/libjava/javax/swing/JTextField.java @@ -1,4 +1,4 @@ -/* JTextField.java -- +/* JTextField.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,73 +35,185 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Vector; - import javax.accessibility.AccessibleStateSet; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import javax.swing.text.PlainDocument; + -public class JTextField extends JEditorPane +public class JTextField extends JTextComponent + implements SwingConstants { + /** + * AccessibleJTextField + */ + protected class AccessibleJTextField extends AccessibleJTextComponent + { + private static final long serialVersionUID = 8255147276740453036L; - /** - * AccessibleJTextField - */ - protected class AccessibleJTextField extends AccessibleJTextComponent { + /** + * Constructor AccessibleJTextField + */ + protected AccessibleJTextField() + { + } - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- + /** + * getAccessibleStateSet + * @return AccessibleStateSet + */ + public AccessibleStateSet getAccessibleStateSet() + { + return null; + } + } - /** - * Constructor AccessibleJTextField - * @param component TODO - */ - protected AccessibleJTextField(JTextField component) { - super(component); - // TODO - } // AccessibleJTextField() + private static final long serialVersionUID = 353853209832607592L; + public static final String notifyAction = "notify-field-accept"; + + private int columns; - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + /** + * Creates a new instance of <code>JTextField</code>. + */ + public JTextField() + { + this(null, null, 0); + } - /** - * getAccessibleStateSet - * @returns AccessibleStateSet - */ - public AccessibleStateSet getAccessibleStateSet() { - return null; // TODO - } // getAccessibleStateSet() + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param text the initial text + */ + public JTextField(String text) + { + this(null, text, 0); + } + + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param columns the number of columns + * + * @exception IllegalArgumentException if columns %lt; 0 + */ + public JTextField(int columns) + { + this(null, null, columns); + } + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param text the initial text + * @param columns the number of columns + * + * @exception IllegalArgumentException if columns %lt; 0 + */ + public JTextField(String text, int columns) + { + this(null, text, columns); + } - } // AccessibleJTextField + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param doc the document to use + * @param text the initial text + * @param columns the number of columns + * + * @exception IllegalArgumentException if columns %lt; 0 + */ + public JTextField(Document doc, String text, int columns) + { + if (doc == null) + doc = createDefaultModel(); + setDocument(doc); + setText(text); + setColumns(columns); + } - Vector actions = new Vector(); + /** + * Creates the default model for this text field. + * This implementation returns an instance of <code>PlainDocument</code>. + * + * @return a new instance of the default model + */ + protected Document createDefaultModel() + { + return new PlainDocument(); + } - public JTextField() + /** + * Adds a new listener object to this text field. + * + * @param listener the listener to add + */ + public void addActionListener(ActionListener listener) { + listenerList.add(ActionListener.class, listener); } - public JTextField(int a) - { - } + /** + * Removes a listener object from this text field. + * + * @param listener the listener to remove + */ + public void removeActionListener(ActionListener listener) + { + listenerList.remove(ActionListener.class, listener); + } - public void addActionListener(ActionListener l) - { - actions.addElement(l); - } + /** + * Returns all registered <code>ActionListener</code> objects. + * + * @return an array of listeners + */ + public ActionListener[] getActionListeners() + { + return (ActionListener[]) getListeners(ActionListener.class); + } - public void removeActionListener(ActionListener l) - { - actions.removeElement(l); - } + /** + * Sends an action event to all registered + * <code>ActionListener</code> objects. + */ + protected void fireActionPerformed() + { + ActionEvent event = new ActionEvent(this, 0, notifyAction); + ActionListener[] listeners = getActionListeners(); - public void selectAll() - { - } + for (int index = 0; index < listeners.length; ++index) + listeners[index].actionPerformed(event); + } + + /** + * Returns the number of columns of this text field. + * + * @return the number of columns + */ + public int getColumns() + { + return columns; + } + + public void setColumns(int columns) + { + if (columns < 0) + throw new IllegalArgumentException(); + + this.columns = columns; + // FIXME: Invalidate layout. + } + + public void selectAll() + { + } } |