/[classpath]/classpath/javax/swing/JFormattedTextField.java
ViewVC logotype

Diff of /classpath/javax/swing/JFormattedTextField.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by rabbit78, Mon Jun 13 11:57:07 2005 UTC revision 1.15 by rabbit78, Mon Jun 13 13:08:34 2005 UTC
# Line 42  import java.awt.event.FocusEvent; Line 42  import java.awt.event.FocusEvent;
42  import java.io.Serializable;  import java.io.Serializable;
43  import java.text.Format;  import java.text.Format;
44  import java.text.ParseException;  import java.text.ParseException;
45    import java.util.Date;
46    
47    import javax.swing.text.DateFormatter;
48    import javax.swing.text.DefaultFormatter;
49  import javax.swing.text.Document;  import javax.swing.text.Document;
50  import javax.swing.text.DocumentFilter;  import javax.swing.text.DocumentFilter;
51  import javax.swing.text.NavigationFilter;  import javax.swing.text.NavigationFilter;
# Line 298  public class JFormattedTextField extends Line 301  public class JFormattedTextField extends
301        return;        return;
302    
303      // format value      // format value
304      AbstractFormatter formatter = formatterFactory.getFormatter(this);      AbstractFormatter formatter = createFormatter(newValue);
305      try      try
306        {        {
307          setText(formatter.valueToString(newValue));          setText(formatter.valueToString(newValue));
# Line 312  public class JFormattedTextField extends Line 315  public class JFormattedTextField extends
315      value = newValue;      value = newValue;
316      firePropertyChange("value", oldValue, newValue);      firePropertyChange("value", oldValue, newValue);
317    }    }
318    
319      /**
320       * A helper method that attempts to create a formatter that is suitable
321       * to format objects of the type like <code>value</code>.
322       *
323       * If <code>formatterFactory</code> is not null and the returned formatter
324       * is also not <code>null</code> then this formatter is used. Otherwise we
325       * try to create one based on the type of <code>value</code>.
326       *
327       * @param value an object which should be formatted by the formatter
328       *
329       * @return a formatter able to format objects of the class of
330       *     <code>value</code>
331       */
332      AbstractFormatter createFormatter(Object value)
333      {
334        AbstractFormatter formatter = null;
335        if (formatterFactory != null
336            && formatterFactory.getFormatter(this) != null)
337         formatter = formatterFactory.getFormatter(this);
338       else
339         {
340           if (value instanceof Date)
341             formatter = new DateFormatter();
342           else
343             formatter = new DefaultFormatter();
344         }
345        return formatter;
346      }
347  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26