[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: JFormattedTextField fix
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: JFormattedTextField fix |
Date: |
Mon, 13 Jun 2005 15:08:51 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
I committed the following fix.
2005-06-13 Roman Kennke <address@hidden>
* javax/swing/JFormattedTextField.java
(setValue): Creates an AbstractFormatter instance based on the type
of the value beeing set.
(createFormatter): New helper method.
/Roman
Index: javax/swing/JFormattedTextField.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JFormattedTextField.java,v
retrieving revision 1.14
diff -u -r1.14 JFormattedTextField.java
--- javax/swing/JFormattedTextField.java 13 Jun 2005 11:57:07 -0000
1.14
+++ javax/swing/JFormattedTextField.java 13 Jun 2005 13:04:43 -0000
@@ -42,7 +42,10 @@
import java.io.Serializable;
import java.text.Format;
import java.text.ParseException;
+import java.util.Date;
+import javax.swing.text.DateFormatter;
+import javax.swing.text.DefaultFormatter;
import javax.swing.text.Document;
import javax.swing.text.DocumentFilter;
import javax.swing.text.NavigationFilter;
@@ -298,7 +301,7 @@
return;
// format value
- AbstractFormatter formatter = formatterFactory.getFormatter(this);
+ AbstractFormatter formatter = createFormatter(newValue);
try
{
setText(formatter.valueToString(newValue));
@@ -312,4 +315,33 @@
value = newValue;
firePropertyChange("value", oldValue, newValue);
}
+
+ /**
+ * A helper method that attempts to create a formatter that is suitable
+ * to format objects of the type like <code>value</code>.
+ *
+ * If <code>formatterFactory</code> is not null and the returned formatter
+ * is also not <code>null</code> then this formatter is used. Otherwise we
+ * try to create one based on the type of <code>value</code>.
+ *
+ * @param value an object which should be formatted by the formatter
+ *
+ * @return a formatter able to format objects of the class of
+ * <code>value</code>
+ */
+ AbstractFormatter createFormatter(Object value)
+ {
+ AbstractFormatter formatter = null;
+ if (formatterFactory != null
+ && formatterFactory.getFormatter(this) != null)
+ formatter = formatterFactory.getFormatter(this);
+ else
+ {
+ if (value instanceof Date)
+ formatter = new DateFormatter();
+ else
+ formatter = new DefaultFormatter();
+ }
+ return formatter;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: JFormattedTextField fix,
Roman Kennke <=