[Patchanim-commit] SF.net SVN: patchanim: [35] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-01-27 03:54:41
|
Revision: 35 http://patchanim.svn.sourceforge.net/patchanim/?rev=35&view=rev Author: dbrosius Date: 2008-01-26 19:54:45 -0800 (Sat, 26 Jan 2008) Log Message: ----------- Add IntegerDocument back in for width, height, tween count, and hook up those settings to listeners. Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 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-27 03:54:45 UTC (rev 35) @@ -0,0 +1,46 @@ +/* + * 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 = 4081253155490713536L; + + 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/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 03:33:55 UTC (rev 34) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 03:54:45 UTC (rev 35) @@ -21,6 +21,8 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ResourceBundle; @@ -35,6 +37,8 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import com.mebigfatguy.patchanim.AnimationType; import com.mebigfatguy.patchanim.OutOfBoundsColor; @@ -69,7 +73,7 @@ { widthLabel = new JLabel(rb.getString(PatchAnimBundle.WIDTH)); - widthField = new JTextField(8); + widthField = new JTextField(new IntegerDocument(), "", 8); widthLabel.setLabelFor(widthField); JPanel p = Utils.createFormPanel(widthLabel, widthField); @@ -79,7 +83,7 @@ add(Box.createVerticalStrut(5)); { heightLabel = new JLabel(rb.getString(PatchAnimBundle.HEIGHT)); - heightField = new JTextField(8); + heightField = new JTextField(new IntegerDocument(), "", 8); heightLabel.setLabelFor(heightField); JPanel p = Utils.createFormPanel(heightLabel, heightField); @@ -111,7 +115,7 @@ add(Box.createVerticalStrut(5)); { tweenFramesLabel = new JLabel(rb.getString(PatchAnimBundle.TWEENFRAMES)); - tweenFramesField = new JTextField(8); + tweenFramesField = new JTextField(new IntegerDocument(), "", 8); tweenFramesLabel.setLabelFor(tweenFramesField); JPanel p = Utils.createFormPanel(tweenFramesLabel, tweenFramesField); Utils.limitPanelHeight(p, tweenFramesField); @@ -150,6 +154,49 @@ } }); + widthField.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent arg0) { + try { + document.setWidth(Integer.parseInt(widthField.getText())); + } catch (NumberFormatException nfe) { + document.setWidth(0); + } + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.fireSettingsChanged(); + } + }); + + + heightField.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent arg0) { + try { + document.setHeight(Integer.parseInt(heightField.getText())); + } catch (NumberFormatException nfe) { + document.setHeight(0); + } + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.fireSettingsChanged(); + } + }); + + tweenFramesField.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent arg0) { + try { + document.setTweenCount(Integer.parseInt(tweenFramesField.getText())); + } catch (NumberFormatException nfe) { + document.setTweenCount(0); + } + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.fireSettingsChanged(); + } + }); + animationCB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 03:33:55 UTC (rev 34) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 03:54:45 UTC (rev 35) @@ -26,6 +26,7 @@ import java.awt.image.BufferedImage; import java.lang.reflect.InvocationTargetException; import java.util.List; +import java.util.ResourceBundle; import javax.swing.JFrame; import javax.swing.JPanel; @@ -34,6 +35,7 @@ import com.mebigfatguy.patchanim.AnimationType; import com.mebigfatguy.patchanim.OutOfBoundsColor; import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; import com.mebigfatguy.patchanim.surface.CombinedPatch; import com.mebigfatguy.patchanim.surface.PatchGenerator; @@ -58,6 +60,13 @@ type = document.getAnimationType(); oob = document.getOutOfBoundsColor(); patches = document.getPatches(); + + if (width == 0) + width = 100; + if (height == 0) + height = 100; + if (tweenCount == 0) + tweenCount = 1; initComponents(); initListeners(); @@ -135,10 +144,12 @@ } private void initComponents() { + ResourceBundle rb = PatchAnimBundle.getBundle(); testPanel = new TestPanel(); setLayout(new BorderLayout(4, 4)); add(testPanel, BorderLayout.CENTER); pack(); + setTitle(rb.getString(PatchAnimBundle.TEST)); } private void initListeners() { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 03:33:55 UTC (rev 34) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 03:54:45 UTC (rev 35) @@ -48,7 +48,6 @@ public static final String REMOVE = "patchanim.remove"; public static final String COLOR = "patchanim.color"; - private static ResourceBundle rb = ResourceBundle.getBundle("com/mebigfatguy/patchanim/resources"); private PatchAnimBundle() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |