[Patchanim-commit] SF.net SVN: patchanim: [17] trunk/patchanim/src/com/mebigfatguy/patchanim/ gui/I
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-01-26 06:02:29
|
Revision: 17
http://patchanim.svn.sourceforge.net/patchanim/?rev=17&view=rev
Author: dbrosius
Date: 2008-01-25 22:02:34 -0800 (Fri, 25 Jan 2008)
Log Message:
-----------
document to enforce integer values
Added Paths:
-----------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java
Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java (rev 0)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java 2008-01-26 06:02:34 UTC (rev 17)
@@ -0,0 +1,50 @@
+/*
+ * patchanim - A bezier surface patch color blend gif builder
+ * 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.patchanim.gui;
+
+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 = -1526356835854424028L;
+
+ private static final Pattern INTEGERPATTERN = Pattern.compile("-?(:?[1-9][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();
+
+ if (newIntegerString.length() == 0)
+ super.insertString(offs, str, a);
+ else {
+ Matcher m = INTEGERPATTERN.matcher(newIntegerString);
+ if (m.matches()) {
+ super.insertString(offs, str, a);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|