[Schmitzm-commits] r1568 - in trunk/schmitzm-core/src: main/java/de/schmitzm/swing test/java/de/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 28 15:07:10 CEST 2011


Author: mojays
Date: 2011-04-28 15:07:09 +0200 (Thu, 28 Apr 2011)
New Revision: 1568

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java
Log:


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java	2011-04-27 16:21:12 UTC (rev 1567)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java	2011-04-28 13:07:09 UTC (rev 1568)
@@ -9,6 +9,8 @@
 import javax.swing.JFormattedTextField;
 import javax.swing.text.DateFormatter;
 import javax.swing.text.DefaultFormatterFactory;
+import javax.swing.text.Document;
+import javax.swing.text.PlainDocument;
 
 import de.schmitzm.lang.LangUtil;
 
@@ -21,6 +23,9 @@
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
  */
 public abstract class DateTextField extends JFormattedTextField {
+  /** Holds the maximum input length for the text field. */
+  protected int inputLimit = -1;
+  
   /**
    * Creates a new input field.
    * @param format date format
@@ -29,6 +34,8 @@
    */
   public DateTextField(DateFormat format, int maxInputLength, String value) {
     super(format);
+    this.inputLimit = maxInputLength;
+    
     // To allow NULL-Entries, we create a new DateFormatter
     AbstractFormatter formatter = new DateFormatter(format) {
       // allow NULL inputs
@@ -41,25 +48,25 @@
     setFormatterFactory( new DefaultFormatterFactory(formatter) );
 
 //    setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
-    if ( maxInputLength > 0 )
-      setColumns(maxInputLength);
-    //MS: Klappt in Verbindung mit dem JFormattedTextField leider
-    //    nicht richtig.
-    //setDocument(new LimitedDocument(maxInputLength, LimitedDocument.STYLE_DOTTED_DATE));
+    if ( inputLimit > 0 )
+      setColumns(inputLimit);
+//    //MS: Klappt in Verbindung mit dem JFormattedTextField leider
+//    //    nicht richtig.
+//    setDocument(new LimitedDocument(inputLimit, LimitedDocument.STYLE_DOTTED_DATE));
     if ( value != null ) {
       setText(value);
       select(0, getText().length());
     }
   }
 
-  /**
-   * Creates a new input field.
-   * @param format date format
-   * @param maxInputLength maximum number of accepted digits (-1 = unlimited)
-   */
-  public DateTextField(DateFormat format, int maxInputLength) {
-    this(format, maxInputLength, null);
-  }
+//  /**
+//   * Creates a new input field.
+//   * @param format date format
+//   * @param maxInputLength maximum number of accepted digits (-1 = unlimited)
+//   */
+//  public DateTextField(DateFormat format, int maxInputLength) {
+//    this(format, maxInputLength, null);
+//  }
 
   /**
    * Creates a new input field.
@@ -90,6 +97,11 @@
     this(formatPattern, null);
   }
   
+//  @Override
+//  protected Document createDefaultModel() {
+//    return new LimitedDocument(10, LimitedDocument.STYLE_DOTTED_DATE);
+//  }
+
   /**
    * In case of incomplete inputs this method calls
    * {@link #completeInput(String)} to create a valid

Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java	2011-04-27 16:21:12 UTC (rev 1567)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java	2011-04-28 13:07:09 UTC (rev 1568)
@@ -24,6 +24,7 @@
 
 		Format format = new SimpleDateFormat("dd.MM.yyyy");
 
+		JTextField field = new DateTextField.German();
 //		JFormattedTextField field = new JFormattedTextField(format) {
 //			@Override
 //			public void commitEdit() throws ParseException {
@@ -41,7 +42,6 @@
 //				}
 //			}
 //		};
-		JTextField field = new DateTextField.German();
 //		field.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
 //		field.setText("dd.MM.yyyy");
 //		field.setColumns(10);



More information about the Schmitzm-commits mailing list