[Polycasso-commit] SF.net SVN: polycasso:[89] trunk/polycasso/src/com/mebigfatguy/polycasso/ Intege
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-28 23:18:54
|
Revision: 89
http://polycasso.svn.sourceforge.net/polycasso/?rev=89&view=rev
Author: dbrosius
Date: 2009-11-28 23:18:46 +0000 (Sat, 28 Nov 2009)
Log Message:
-----------
a document that only allows integer characters
Added Paths:
-----------
trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java 2009-11-28 23:18:46 UTC (rev 89)
@@ -0,0 +1,43 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009 MeBigFatGuy.com
+ * Copyright 2009 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+import java.awt.Toolkit;
+
+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 = -6755728406523769124L;
+
+ @Override
+ public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException {
+ StringBuilder text = new StringBuilder(getText(0, getLength()));
+ try {
+ text.insert(pos, insertStr);
+ Integer.parseInt(text.toString());
+ super.insertString(pos, insertStr, atts);
+ } catch (Exception e) {
+ Toolkit.getDefaultToolkit().beep();
+ }
+ }
+
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/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.
|