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 - text components


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

Hi list,


I just commited the attached patch to implement some stuff needed for 
JTextField and JTextArea.


Michael

2004-06-16  Michael Koch  <konqueror@gmx.de>

	* javax/swing/JTextArea.java: New file.
	* javax/swing/JTextField.java
	(actions): Removed.
	(notifyAction): New constant.
	(columns): New field.
	(JTextField): New constructors.
	(createDefaultModel): New method.
	(addActionListener): Reimplmemented.
	(removeActionListener): Reimplemented.
	(getActionListeners): New method.
	(fireActionPerformed): New method.
	(getColumns): New method.
	(setColumne): New method.
	* javax/swing/text/JTextComponent.java
	(AccessibleJTextComponent.serialVersionUID): New field.
	(serialVersionUID): Likewise.
	(DEFAULT_KEYMAP): Likewise.
	(FOCUS_ACCELERATOR_KEY): Likewise.
	(doc): Made private.
	(icon_gap): Likewise.
	(icon): Likewise.
	(align): Likewise.
	(JTextComponent): Some constructors removed.
	(getScrollableTracksViewportHeight): New method.
	(getScrollableTracksViewportWidth): Likewise.
	* Makefile.am: Added javax/swing/JTextArea.java.
	* Makefile.in: Regenerated.


- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA0ANeWSOgCCdjSDsRAjunAJ9Gic9vhML8axW4x6aS1sewCTF+dgCdGcUO
yJkwyn9ABsf6Qq0wN7K6ATA=
=6JpY
-----END PGP SIGNATURE-----
Index: javax/swing/JTextArea.java
===================================================================
RCS file: javax/swing/JTextArea.java
diff -N javax/swing/JTextArea.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ javax/swing/JTextArea.java	16 Jun 2004 08:19:32 -0000
@@ -0,0 +1,231 @@
+/* JTextArea.java -- 
+   Copyright (C) 2004  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+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.Dimension;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.PlainDocument;
+
+public class JTextArea extends JTextComponent
+{
+  private static final long serialVersionUID = -6141680179310439825L;
+  
+  private int rows;
+  private int columns;
+  private boolean wrapping;
+
+  /**
+   * Creates a new <code>JTextArea</code> object.
+   */
+  public JTextArea()
+  {
+    this(null, null, 0, 0);
+  }
+
+  /**
+   * Creates a new <code>JTextArea</code> object.
+   *
+   * @param text the initial text
+   */
+  public JTextArea(String text)
+  {
+    this(null, text, 0, 0);
+  }
+
+  /**
+   * Creates a new <code>JTextArea</code> object.
+   *
+   * @param rows the number of rows
+   * @param columns the number of cols
+   *
+   * @exception IllegalArgumentException if rows or columns are negative
+   */
+  public JTextArea(int rows, int columns)
+  {
+    this(null, null, rows, columns);
+  }
+
+  /**
+   * Creates a new <code>JTextArea</code> object.
+   *
+   * @param text the initial text
+   * @param rows the number of rows
+   * @param columns the number of cols
+   *
+   * @exception IllegalArgumentException if rows or columns are negative
+   */
+  public JTextArea(String text, int rows, int columns)
+  {
+    this(null, text, rows, columns);
+  }
+
+  /**
+   * Creates a new <code>JTextArea</code> object.
+   *
+   * @param the document model to use
+   */
+  public JTextArea(Document doc)
+  {
+    this(doc, null, 0, 0);
+  }
+
+  /**
+   * Creates a new <code>JTextArea</code> object.
+   *
+   * @param the document model to use
+   * @param text the initial text
+   * @param rows the number of rows
+   * @param columns the number of cols
+   *
+   * @exception IllegalArgumentException if rows or columns are negative
+   */
+  public JTextArea(Document doc, String text, int rows, int columns)
+  {
+    setDocument(doc == null ? createDefaultModel() : doc);
+    setText(text);
+    setRows(rows);
+    setColumns(columns);
+  }
+
+  /**
+   * Appends some text.
+   *
+   * @param toAppend the text to append
+   */
+  public void append(String toAppend)
+  {
+    setText(getText() + toAppend);
+  }
+
+  /**
+   * Creates the default document model.
+   *
+   * @return a new default model
+   */
+  protected Document createDefaultModel()
+  {
+    return new PlainDocument();
+  }
+
+
+  public boolean getScrollableTracksViewportWidth()
+  {
+    return wrapping ? true : super.getScrollableTracksViewportWidth();
+  }
+
+  /**
+   * Returns the UI class ID string.
+   *
+   * @return the string "TextAreaUI"
+   */
+  public String getUIClassID()
+  {
+    return "TextAreaUI";
+  }
+
+  /**
+   * Returns the current number of columns.
+   *
+   * @return number of columns
+   */
+  public int getColumns()
+  {
+    return columns;
+  }
+  
+  /**
+   * Sets the number of rows.
+   *
+   * @param columns number of columns
+   *
+   * @exception IllegalArgumentException if columns is negative
+   */
+  public void setColumns(int columns)
+  {
+    if (columns < 0)
+      throw new IllegalArgumentException();
+
+    this.columns = columns;
+  }
+
+  /**
+   * Returns the current number of rows.
+   *
+   * @return number of rows
+   */
+  public int getRows()
+  {
+    return rows;
+  }
+
+  /**
+   * Sets the number of rows.
+   *
+   * @param columns number of columns
+   *
+   * @exception IllegalArgumentException if rows is negative
+   */
+  public void setRows(int rows)
+  {
+    if (rows < 0)
+      throw new IllegalArgumentException();
+
+    this.rows = rows;
+  }
+
+  /**
+   * Checks whethet line wrapping is enabled.
+   *
+   * @return true if line wrapping is enabled, false otherwise
+   */
+  public boolean getLineWrap()
+  {
+    return wrapping;
+  }
+
+  /**
+   * Enables/disables line wrapping.
+   *
+   * @param wrapping true to enable line wrapping, false otherwise
+   */
+  public void setLineWrap(boolean wrapping)
+  {
+    this.wrapping = wrapping;
+  }
+}
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextField.java,v
retrieving revision 1.2.18.3
diff -u -b -B -r1.2.18.3 JTextField.java
--- javax/swing/JTextField.java	10 Jun 2004 08:49:07 -0000	1.2.18.3
+++ javax/swing/JTextField.java	16 Jun 2004 08:19:32 -0000
@@ -37,13 +37,16 @@
 
 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
 {
   /**
@@ -71,24 +74,144 @@
   }
 
   private static final long serialVersionUID = 353853209832607592L;
-  Vector actions = new Vector();
 
+  public static final String notifyAction = "notify-field-accept";
+  
+  private int columns;
+
+  /**
+   * Creates a new instance of <code>JTextField</code>.
+   */
   public JTextField()
   {
+    this(null, null, 0);
+  }
+
+  /**
+   * 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);
+  }
+
+  /**
+   * 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);
+  }
+
+  /**
+   * 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();
+  }
+
+  /**
+   * 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);
+  }
+
+  /**
+   * 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 JTextField(int a)
+  /**
+   * Returns all registered <code>ActionListener</code> objects.
+   *
+   * @return an array of listeners
+   */
+  public ActionListener[] getActionListeners()
   {
+    return (ActionListener[]) getListeners(ActionListener.class);
   }
 
-  public void addActionListener(ActionListener l)
+  /**
+   * Sends an action event to all registered
+   * <code>ActionListener</code> objects.
+   */
+  protected void fireActionPerformed()
   {
-    actions.addElement(l);
+    ActionEvent event = new ActionEvent(this, 0, notifyAction);
+    ActionListener[] listeners = getActionListeners();
+
+    for (int index = 0; index < listeners.length; ++index)
+      listeners[index].actionPerformed(event);
   }
 
-  public void removeActionListener(ActionListener l)
+  /**
+   * Returns the number of columns of this text field.
+   *
+   * @return the number of columns
+   */
+  public int getColumns()
+  {
+    return columns;
+  }
+
+  public void setColumns(int columns)
   {
-    actions.removeElement(l);
+    if (columns < 0)
+      throw new IllegalArgumentException();
+
+    this.columns = columns;
+    // FIXME: Invalidate layout.
   }
 
   public void selectAll()
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.4
diff -u -b -B -r1.4.2.4 JTextComponent.java
--- javax/swing/text/JTextComponent.java	11 Jun 2004 08:05:18 -0000	1.4.2.4
+++ javax/swing/text/JTextComponent.java	16 Jun 2004 08:19:32 -0000
@@ -1,5 +1,5 @@
 /* JTextComponent.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -44,6 +44,8 @@
 import java.awt.Insets;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.awt.event.InputMethodListener;
+
 import javax.accessibility.Accessible;
 import javax.accessibility.AccessibleContext;
 import javax.accessibility.AccessibleRole;
@@ -51,6 +53,7 @@
 import javax.accessibility.AccessibleText;
 import javax.swing.Icon;
 import javax.swing.JComponent;
+import javax.swing.JViewport;
 import javax.swing.KeyStroke;
 import javax.swing.Scrollable;
 import javax.swing.UIManager;
@@ -76,6 +79,8 @@
   public class AccessibleJTextComponent extends AccessibleJComponent
     implements AccessibleText, CaretListener, DocumentListener
   {
+    private static final long serialVersionUID = 7664188944091413696L;
+
     /**
      * caretPos
      */
@@ -282,46 +287,18 @@
     }
   } // class KeyBinding
 
-  int icon_gap;
-  Icon icon;
-  int align;
-  Document doc;
-
-  public JTextComponent()
-  {
-    this("", null, 0);
-  }
-
-  public JTextComponent(Icon image)
-  {
-    this("", image, 0);
-  }
+  private static final long serialVersionUID = -8796518220218978795L;
 
-  public JTextComponent(Icon image, int horizontalAlignment)
-  {
-    this("", image, horizontalAlignment);
-  }
+  public static final String DEFAULT_KEYMAP = "default";
+  public static final String FOCUS_ACCELERATOR_KEY = "focusAcceleratorKey";
 
-  public JTextComponent(String text)
-  {
-    this(text, null, 0);
-  }
+  private Document doc;
+  private int icon_gap;
+  private Icon icon;
+  private int align;
 
-  public JTextComponent(String text, int horizontalAlignment)
-  {
-    this(text, null, horizontalAlignment);
-  }
-
-  public JTextComponent(String text, Icon icon, int horizontalAlignment)
+  public JTextComponent()
   {
-    setDocument(new PlainDocument());
-
-    // do the work.....
-    setText(text);
-    this.icon = icon;
-    this.align = horizontalAlignment;
-
-    // its an editor, so:
     enableEvents(AWTEvent.KEY_EVENT_MASK);
     updateUI();
   }
@@ -521,4 +498,20 @@
   {
     return 0;
   }
+
+  public boolean getScrollableTracksViewportHeight()
+  {
+    if (getParent() instanceof JViewport)
+      return ((JViewport) getParent()).getHeight() > getPreferredSize().height;
+
+    return false;
+  }
+
+  public boolean getScrollableTracksViewportWidth()
+  {
+    if (getParent() instanceof JViewport)
+      return ((JViewport) getParent()).getWidth() > getPreferredSize().width;
+
+    return false;
+  }
 }
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.361.2.14
diff -u -b -B -r1.361.2.14 Makefile.am
--- Makefile.am	9 Jun 2004 20:55:08 -0000	1.361.2.14
+++ Makefile.am	16 Jun 2004 08:19:33 -0000
@@ -1374,6 +1374,7 @@
 javax/swing/JScrollBar.java \
 javax/swing/JScrollPane.java \
 javax/swing/JTabbedPane.java \
+javax/swing/JTextArea.java \
 javax/swing/JTextField.java \
 javax/swing/JToggleButton.java \
 javax/swing/JToolTip.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.385.2.14
diff -u -b -B -r1.385.2.14 Makefile.in
--- Makefile.in	9 Jun 2004 20:55:08 -0000	1.385.2.14
+++ Makefile.in	16 Jun 2004 08:19:36 -0000
@@ -1079,6 +1079,7 @@
 javax/swing/JScrollBar.java \
 javax/swing/JScrollPane.java \
 javax/swing/JTabbedPane.java \
+javax/swing/JTextArea.java \
 javax/swing/JTextField.java \
 javax/swing/JToggleButton.java \
 javax/swing/JToolTip.java \
@@ -3093,14 +3094,14 @@
 javax/swing/JPanel.lo javax/swing/JRadioButton.lo \
 javax/swing/JRootPane.lo javax/swing/JScrollBar.lo \
 javax/swing/JScrollPane.lo javax/swing/JTabbedPane.lo \
-javax/swing/JTextField.lo javax/swing/JToggleButton.lo \
-javax/swing/JToolTip.lo javax/swing/JTree.lo javax/swing/JViewport.lo \
-javax/swing/JWindow.lo javax/swing/KeyStroke.lo \
-javax/swing/ListCellRenderer.lo javax/swing/ListModel.lo \
-javax/swing/ListSelectionModel.lo javax/swing/LookAndFeel.lo \
-javax/swing/Scrollable.lo javax/swing/SwingConstants.lo \
-javax/swing/SwingUtilities.lo javax/swing/Timer.lo \
-javax/swing/UIDefaults.lo javax/swing/UIManager.lo \
+javax/swing/JTextArea.lo javax/swing/JTextField.lo \
+javax/swing/JToggleButton.lo javax/swing/JToolTip.lo \
+javax/swing/JTree.lo javax/swing/JViewport.lo javax/swing/JWindow.lo \
+javax/swing/KeyStroke.lo javax/swing/ListCellRenderer.lo \
+javax/swing/ListModel.lo javax/swing/ListSelectionModel.lo \
+javax/swing/LookAndFeel.lo javax/swing/Scrollable.lo \
+javax/swing/SwingConstants.lo javax/swing/SwingUtilities.lo \
+javax/swing/Timer.lo javax/swing/UIDefaults.lo javax/swing/UIManager.lo \
 javax/swing/UnsupportedLookAndFeelException.lo \
 javax/swing/event/AncestorEvent.lo \
 javax/swing/event/AncestorListener.lo javax/swing/event/ChangeEvent.lo \
@@ -4981,14 +4982,14 @@
 .deps/javax/swing/JScrollBar.P .deps/javax/swing/JScrollPane.P \
 .deps/javax/swing/JSeparator.P .deps/javax/swing/JSlider.P \
 .deps/javax/swing/JSplitPane.P .deps/javax/swing/JTabbedPane.P \
-.deps/javax/swing/JTable.P .deps/javax/swing/JTextField.P \
-.deps/javax/swing/JTextPane.P .deps/javax/swing/JToggleButton.P \
-.deps/javax/swing/JToolBar.P .deps/javax/swing/JToolTip.P \
-.deps/javax/swing/JTree.P .deps/javax/swing/JViewport.P \
-.deps/javax/swing/JWindow.P .deps/javax/swing/KeyStroke.P \
-.deps/javax/swing/ListCellRenderer.P .deps/javax/swing/ListModel.P \
-.deps/javax/swing/ListSelectionModel.P .deps/javax/swing/LookAndFeel.P \
-.deps/javax/swing/MenuElement.P \
+.deps/javax/swing/JTable.P .deps/javax/swing/JTextArea.P \
+.deps/javax/swing/JTextField.P .deps/javax/swing/JTextPane.P \
+.deps/javax/swing/JToggleButton.P .deps/javax/swing/JToolBar.P \
+.deps/javax/swing/JToolTip.P .deps/javax/swing/JTree.P \
+.deps/javax/swing/JViewport.P .deps/javax/swing/JWindow.P \
+.deps/javax/swing/KeyStroke.P .deps/javax/swing/ListCellRenderer.P \
+.deps/javax/swing/ListModel.P .deps/javax/swing/ListSelectionModel.P \
+.deps/javax/swing/LookAndFeel.P .deps/javax/swing/MenuElement.P \
 .deps/javax/swing/MenuSelectionManager.P \
 .deps/javax/swing/MutableComboBoxModel.P \
 .deps/javax/swing/OverlayLayout.P .deps/javax/swing/Popup.P \

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