[Pixelle-commit] SF.net SVN: pixelle:[217] trunk/pixelle/src/com/mebigfatguy/pixelle/utils/ Integer
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-11-22 01:56:55
|
Revision: 217
http://pixelle.svn.sourceforge.net/pixelle/?rev=217&view=rev
Author: dbrosius
Date: 2008-11-22 01:56:50 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
a swing document to inforce integer entry
Added Paths:
-----------
trunk/pixelle/src/com/mebigfatguy/pixelle/utils/IntegerDocument.java
Added: trunk/pixelle/src/com/mebigfatguy/pixelle/utils/IntegerDocument.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/utils/IntegerDocument.java (rev 0)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/utils/IntegerDocument.java 2008-11-22 01:56:50 UTC (rev 217)
@@ -0,0 +1,46 @@
+/*
+ * pixelle - Graphics algorithmic editor
+ * Copyright (C) 2008 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.pixelle.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.PlainDocument;
+
+
+public class IntegerDocument extends PlainDocument
+{
+ private static final long serialVersionUID = -4300414460486882975L;
+
+ private static final Pattern INTEGERPATTERN = Pattern.compile("-?[0-9]*");
+
+ @Override
+ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+ String start = getText(0, offs);
+ String end = getText(offs, this.getLength() - offs);
+ String newIntegerString = (start + str + end).trim();
+
+ Matcher m = INTEGERPATTERN.matcher(newIntegerString);
+ if (m.matches()) {
+ super.insertString(offs, str, a);
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/pixelle/src/com/mebigfatguy/pixelle/utils/IntegerDocument.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|