This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: javax.swing.JTextArea
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Mon, 13 Sep 2004 14:07:27 +0200
- Subject: Patch: javax.swing.JTextArea
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to add some missing methods to
javax.swing.JTextField.
Michael
2004-09-13 Michael Koch <konqueror@gmx.de>
* javax/swing/JTextField.java
(action): New field.
(actionCommand): Likewise.
(actionPropertyChangeListener): Likewise.
(setHorizontalAlignment): Abort soon if new value == old value. Fire
event before repainting.
(postActionEvent): New method.
(getAction): Likewise.
(setAction): Likewise.
(getActionCommand): Likewise.
(setActionCommand): Likewise.
(createActionPropertyChangeListener): Likewise.
(configurePropertiesFromAction): Likewise.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBRY2CWSOgCCdjSDsRAko2AJ4kdjtQfyhiqjWm97REn8pxh7JLywCdEzAQ
tvbeZDmGPGaZXzmrC2VIrSM=
=V1po
-----END PGP SIGNATURE-----
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextField.java,v
retrieving revision 1.2.18.8
diff -u -r1.2.18.8 JTextField.java
--- javax/swing/JTextField.java 13 Sep 2004 10:26:19 -0000 1.2.18.8
+++ javax/swing/JTextField.java 13 Sep 2004 11:59:30 -0000
@@ -42,6 +42,8 @@
import java.awt.FontMetrics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import javax.accessibility.AccessibleStateSet;
import javax.swing.text.Document;
@@ -86,6 +88,14 @@
private int scrollOffset;
+ /** @since 1.3 */
+ private Action action;
+
+ /** @since 1.3 */
+ private String actionCommand;
+
+ private PropertyChangeListener actionPropertyChangeListener;
+
/**
* Creates a new instance of <code>JTextField</code>.
*/
@@ -244,11 +254,14 @@
public void setHorizontalAlignment(int newAlign)
{
+ if (align == newAlign)
+ return;
+
int oldAlign = align;
align = newAlign;
+ firePropertyChange("horizontalAlignment", oldAlign, newAlign);
invalidate();
repaint();
- firePropertyChange("horizontalAlignment", oldAlign, newAlign);
}
public void setFont(Font newFont)
@@ -296,6 +309,110 @@
scrollOffset = offset;
}
+ public void postActionEvent()
+ {
+ ActionEvent event = new ActionEvent(this, 0, actionCommand);
+ ActionListener[] listeners = getActionListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].actionPerformed(event);
+ }
+
+ /**
+ * @since 1.3
+ */
+ public Action getAction()
+ {
+ return action;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void setAction(Action newAction)
+ {
+ if (action == newAction)
+ return;
+
+ if (action != null)
+ {
+ removeActionListener(action);
+ action.removePropertyChangeListener(actionPropertyChangeListener);
+ actionPropertyChangeListener = null;
+ }
+
+ Action oldAction = action;
+ action = newAction;
+
+ if (action != null)
+ {
+ addActionListener(action);
+ actionPropertyChangeListener =
+ createActionPropertyChangeListener(action);
+ action.addPropertyChangeListener(actionPropertyChangeListener);
+ }
+
+ firePropertyChange("horizontalAlignment", oldAction, newAction);
+ }
+
+ /**
+ * @since 1.3
+ */
+ public String getActionCommand()
+ {
+ return actionCommand;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void setActionCommand(String command)
+ {
+ this.actionCommand = command;
+ }
+
+ /**
+ * @since 1.3
+ */
+ protected PropertyChangeListener createActionPropertyChangeListener(Action action)
+ {
+ return new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ // Update properties "action" and "horizontalAlignment".
+ String name = event.getPropertyName();
+
+ if (name.equals("enabled"))
+ {
+ boolean enabled = ((Boolean) event.getNewValue()).booleanValue();
+ JTextField.this.setEnabled(enabled);
+ }
+ else if (name.equals(Action.SHORT_DESCRIPTION))
+ {
+ JTextField.this.setToolTipText((String) event.getNewValue());
+ }
+ }
+ };
+ }
+
+ /**
+ * @since 1.3
+ */
+ protected void configurePropertiesFromAction(Action action)
+ {
+ if (action != null)
+ {
+ setEnabled(action.isEnabled());
+ setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));
+ }
+ else
+ {
+ setEnabled(true);
+ setToolTipText(null);
+ }
+ }
+
protected int getColumnWidth()
{
FontMetrics metrics = getToolkit().getFontMetrics(getFont());