[Schmitzm-commits] r1559 - trunk/schmitzm-core/src/main/java/de/schmitzm/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Apr 19 19:45:10 CEST 2011
Author: mojays
Date: 2011-04-19 19:45:09 +0200 (Tue, 19 Apr 2011)
New Revision: 1559
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/LimitedDocument.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
LimitedDocument: BugFix: does not work correctly with length-limit -1
SwingUtil: helper methods for limited textfield and limited textfield celleditor
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/LimitedDocument.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/LimitedDocument.java 2011-04-18 12:13:29 UTC (rev 1558)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/LimitedDocument.java 2011-04-19 17:45:09 UTC (rev 1559)
@@ -9,6 +9,9 @@
* upper oder lowercase contents.
*/
public class LimitedDocument extends PlainDocument {
+ /** Constant for no limit */
+ public static final int STYLE_NO_LIMIT = -1;
+
/** Document style to do no conversion to
* upper or lower case. */
public static final int STYLE_CASESENSITIVE = 0;
@@ -26,7 +29,7 @@
/** Holds the conversion style for the document. */
protected int style = STYLE_CASESENSITIVE;
/** Holds the character limit for the document. */
- protected int limit = -1;
+ protected int limit = STYLE_NO_LIMIT;
/**
* Creates a new document with no limit and no
@@ -103,7 +106,7 @@
if (str == null) return;
// Check limit
- if ( (getLength() + str.length()) > getLimit() )
+ if ( getLimit() >= 0 && (getLength() + str.length()) > getLimit() )
return;
// Check/Perform style
switch ( getStyle() ) {
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2011-04-18 12:13:29 UTC (rev 1558)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2011-04-19 17:45:09 UTC (rev 1559)
@@ -65,6 +65,9 @@
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
+import javax.swing.BorderFactory;
+import javax.swing.CellEditor;
+import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JDialog;
@@ -77,8 +80,10 @@
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
+import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
+import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
@@ -1467,8 +1472,31 @@
throw new RuntimeException("Not on EDT!");
}
}
+
+ /**
+ * Creates limited text input field.
+ * @param limit limits the character count
+ * @param style see styled in {@link LimitedDocument}
+ */
+ public static JTextField createLimitedTextField(int limit, int style) {
+ LimitedDocument doc = new LimitedDocument(limit, style);
+ JTextField field = new JTextField();
+ field.setDocument(doc);
+ return field;
+ }
+
+ /**
+ * Creates a {@link CellEditor} for limited text input.
+ * @param limit limits the character count
+ * @param style see styled in {@link LimitedDocument}
+ */
+ public static TableCellEditor createLimitedCellEditor(int limit, int style) {
+ JTextField field = createLimitedTextField(limit, style);
+ field.setBorder( BorderFactory.createEmptyBorder() );
+ return new DefaultCellEditor(field);
+ }
- /**
+ /**
* Returns the default background color for the current L&F.
*/
public static Color getDefaultBackground() {
More information about the Schmitzm-commits
mailing list