[Patchanim-commit] SF.net SVN: patchanim: [34] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-01-27 03:34:19
|
Revision: 34
http://patchanim.svn.sourceforge.net/patchanim/?rev=34&view=rev
Author: dbrosius
Date: 2008-01-26 19:33:55 -0800 (Sat, 26 Jan 2008)
Log Message:
-----------
hook up out of bounds colors, and add settings changed listeners support
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java
trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java
trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java
trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java
Added Paths:
-----------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedEvent.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedListener.java
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -18,8 +18,18 @@
*/
package com.mebigfatguy.patchanim;
+import java.util.ResourceBundle;
+
+import com.mebigfatguy.patchanim.main.PatchAnimBundle;
+
public enum AnimationType {
None,
Cycle,
Wave;
+
+ @Override
+ public String toString() {
+ ResourceBundle rb = PatchAnimBundle.getBundle();
+ return rb.getString(PatchAnimBundle.ROOT + name().toLowerCase());
+ }
}
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -18,7 +18,17 @@
*/
package com.mebigfatguy.patchanim;
+import java.util.ResourceBundle;
+
+import com.mebigfatguy.patchanim.main.PatchAnimBundle;
+
public enum OutOfBoundsColor {
Clip,
Roll;
+
+ @Override
+ public String toString() {
+ ResourceBundle rb = PatchAnimBundle.getBundle();
+ return rb.getString(PatchAnimBundle.ROOT + name().toLowerCase());
+ }
}
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -21,6 +21,8 @@
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
@@ -34,6 +36,8 @@
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
+import com.mebigfatguy.patchanim.AnimationType;
+import com.mebigfatguy.patchanim.OutOfBoundsColor;
import com.mebigfatguy.patchanim.PatchAnimDocument;
import com.mebigfatguy.patchanim.main.PatchAnimBundle;
@@ -85,9 +89,9 @@
add(Box.createVerticalStrut(5));
{
animationLabel = new JLabel(rb.getString(PatchAnimBundle.ANIMATION));
- animationCB = new JComboBox(new Object[] { rb.getString(PatchAnimBundle.NONE),
- rb.getString(PatchAnimBundle.CYCLE),
- rb.getString(PatchAnimBundle.WAVE) });
+ animationCB = new JComboBox(new Object[] { AnimationType.None,
+ AnimationType.Cycle,
+ AnimationType.Wave });
animationLabel.setLabelFor(animationCB);
JPanel p = Utils.createFormPanel(animationLabel, animationCB);
@@ -97,8 +101,8 @@
add(Box.createVerticalStrut(5));
{
outOfBoundsLabel = new JLabel(rb.getString(PatchAnimBundle.OUTOFBOUNDSCOLOR));
- outOfBoundsColorCB = new JComboBox(new Object[] { rb.getString(PatchAnimBundle.CLIP),
- rb.getString(PatchAnimBundle.ROLL) });
+ outOfBoundsColorCB = new JComboBox(new Object[] { OutOfBoundsColor.Clip,
+ OutOfBoundsColor.Roll });
outOfBoundsLabel.setLabelFor(outOfBoundsColorCB);
JPanel p = Utils.createFormPanel(outOfBoundsLabel, outOfBoundsColorCB);
Utils.limitPanelHeight(p, outOfBoundsColorCB);
@@ -146,6 +150,28 @@
}
});
+ animationCB.addItemListener(new ItemListener() {
+
+ public void itemStateChanged(ItemEvent ie) {
+ if (ie.getStateChange() == ItemEvent.SELECTED) {
+ document.setAnimationType((AnimationType)ie.getItem());
+ PatchPanelMediator mediator = PatchPanelMediator.getMediator();
+ mediator.fireSettingsChanged();
+ }
+ }
+ });
+
+ outOfBoundsColorCB.addItemListener(new ItemListener() {
+
+ public void itemStateChanged(ItemEvent ie) {
+ if (ie.getStateChange() == ItemEvent.SELECTED) {
+ document.setOutOfBoundsColor((OutOfBoundsColor)ie.getItem());
+ PatchPanelMediator mediator = PatchPanelMediator.getMediator();
+ mediator.fireSettingsChanged();
+ }
+ }
+ });
+
testButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JTestFrame tf = new JTestFrame();
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -31,6 +31,8 @@
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
+import com.mebigfatguy.patchanim.OutOfBoundsColor;
+import com.mebigfatguy.patchanim.PatchAnimDocument;
import com.mebigfatguy.patchanim.PatchColor;
import com.mebigfatguy.patchanim.surface.CombinedPatch;
import com.mebigfatguy.patchanim.surface.PatchGenerator;
@@ -39,6 +41,7 @@
private static final int SAMPLE_SIZE = 200;
private PatchColor color;
private Color rgb;
+ private OutOfBoundsColor oob;
private BufferedImage image;
private PatchDecorator decorator;
@@ -90,30 +93,53 @@
recalcImage(color, currentPatch);
}
}
- });
+ });
+ mediator.addDocumentChangedListener(new DocumentChangedListener() {
+ public void documentChanged(DocumentChangedEvent dce) {
+ PatchAnimDocument doc = dce.getDocument();
+ oob = doc.getOutOfBoundsColor();
+ PatchPanelMediator mediator = PatchPanelMediator.getMediator();
+ recalcImage(color, mediator.getActivePatch());
+ }
+ });
+ mediator.addSettingsChangedListener(new SettingsChangedListener() {
+ public void settingsChanged(SettingsChangedEvent sce) {
+ oob = sce.getDocument().getOutOfBoundsColor();
+ PatchPanelMediator mediator = PatchPanelMediator.getMediator();
+ recalcImage(color, mediator.getActivePatch());
+ }
+ });
}
public void recalcImage(final PatchColor color, final CombinedPatch patch) {
Thread t = new Thread(new Runnable() {
public void run() {
if (color == PatchColor.Combined) {
- PatchGenerator.recalcCombinedImage(patch, image);
+ PatchGenerator.recalcCombinedImage(patch, image, oob);
} else {
- PatchGenerator.recalcIndexedImage(color, patch, image);
+ PatchGenerator.recalcIndexedImage(color, patch, image, oob);
}
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- invalidate();
- revalidate();
- repaint();
- }
- });
+ redraw();
}
});
t.start();
}
+ private void redraw() {
+ try {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ invalidate();
+ revalidate();
+ repaint();
+ }
+ });
+ } catch (Exception ie) {
+ //OK
+ }
+ }
+
@Override
public void paintComponent(Graphics g) {
Rectangle bounds = getBounds();
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -32,6 +32,7 @@
import javax.swing.SwingUtilities;
import com.mebigfatguy.patchanim.AnimationType;
+import com.mebigfatguy.patchanim.OutOfBoundsColor;
import com.mebigfatguy.patchanim.PatchAnimDocument;
import com.mebigfatguy.patchanim.surface.CombinedPatch;
import com.mebigfatguy.patchanim.surface.PatchGenerator;
@@ -44,6 +45,7 @@
private int width;
private int height;
private AnimationType type;
+ private OutOfBoundsColor oob;
private List<CombinedPatch> patches;
private BufferedImage image;
@@ -54,6 +56,7 @@
width = document.getWidth();
height = document.getHeight();
type = document.getAnimationType();
+ oob = document.getOutOfBoundsColor();
patches = document.getPatches();
initComponents();
@@ -68,7 +71,7 @@
animThread = new Thread(new Runnable() {
public void run() {
try {
- PatchGenerator.recalcCombinedImage(patches.get(0), image);
+ PatchGenerator.recalcCombinedImage(patches.get(0), image, oob);
while (!Thread.interrupted()) {
testPanel.redraw();
int lastPatch = patches.size() - 1;
@@ -78,7 +81,7 @@
CombinedPatch endPatch = patches.get(p+1);
for (int t = 0; t < tweenCount; t++) {
CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)tweenCount);
- PatchGenerator.recalcCombinedImage(tweenPatch, image);
+ PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
long now = System.currentTimeMillis();
long sleepTime = 100 - (now - lastRedraw);
if (sleepTime > 0)
@@ -97,7 +100,7 @@
CombinedPatch endPatch = patches.get(p);
for (int t = tweenCount - 1; t >= 0; t--) {
CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)tweenCount);
- PatchGenerator.recalcCombinedImage(tweenPatch, image);
+ PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
long now = System.currentTimeMillis();
long sleepTime = 100 - (now - lastRedraw);
if (sleepTime > 0)
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -31,6 +31,7 @@
private CombinedPatch activePatch;
private Set<DocumentChangedListener> dclisteners = new HashSet<DocumentChangedListener>();
private Set<ActivePatchChangedListener> apclisteners = new HashSet<ActivePatchChangedListener>();
+ private Set<SettingsChangedListener> sclisteners = new HashSet<SettingsChangedListener>();
private PatchPanelMediator() {
}
@@ -58,6 +59,17 @@
apclisteners.add(apcl);
}
+ public void addSettingsChangedListener(SettingsChangedListener scl) {
+ sclisteners.add(scl);
+ }
+
+ public void fireSettingsChanged() {
+ SettingsChangedEvent sce = new SettingsChangedEvent(this, document);
+ for (SettingsChangedListener scl : sclisteners) {
+ scl.settingsChanged(sce);
+ }
+ }
+
public CombinedPatch getActivePatch() {
return activePatch;
}
Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedEvent.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedEvent.java (rev 0)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedEvent.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -0,0 +1,38 @@
+/*
+ * 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.EventObject;
+
+import com.mebigfatguy.patchanim.PatchAnimDocument;
+
+public class SettingsChangedEvent extends EventObject {
+ private static final long serialVersionUID = 2005167344637800832L;
+
+ private PatchAnimDocument doc;
+
+ public SettingsChangedEvent(Object src, PatchAnimDocument document) {
+ super(src);
+ doc = document;
+ }
+
+ public PatchAnimDocument getDocument() {
+ return doc;
+ }
+}
Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedEvent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedListener.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedListener.java (rev 0)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedListener.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public interface SettingsChangedListener {
+ void settingsChanged(SettingsChangedEvent sce);
+}
Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/SettingsChangedListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -22,6 +22,7 @@
public class PatchAnimBundle {
+ public static final String ROOT = "patchanim.";
public static final String TITLE = "patchanim.title";
public static final String FILE = "patchanim.file";
public static final String NEW = "patchanim.new";
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-01-27 01:59:07 UTC (rev 33)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-01-27 03:33:55 UTC (rev 34)
@@ -23,6 +23,7 @@
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
+import com.mebigfatguy.patchanim.OutOfBoundsColor;
import com.mebigfatguy.patchanim.PatchColor;
public class PatchGenerator {
@@ -30,7 +31,10 @@
private PatchGenerator() {
}
- public static void recalcCombinedImage(CombinedPatch patch, BufferedImage image) {
+ public static void recalcCombinedImage(CombinedPatch patch, BufferedImage image, OutOfBoundsColor oob) {
+ if (patch == null)
+ return;
+
PatchCoords[] coords = new PatchCoords[3];
coords[0] = patch.getPatch(PatchColor.Red);
@@ -86,10 +90,18 @@
for (int k = 0; k < 3; k++) {
iValue[k] = (int)value[k];
- if (iValue[k] > 255)
- iValue[k] = 255;
- else if (iValue[k] < 0)
- iValue[k] = 0;
+ if (iValue[k] > 255) {
+ if (oob == OutOfBoundsColor.Clip)
+ iValue[k] = 255;
+ else
+ iValue[k] = iValue[k] & 0x00FF;
+ }
+ else if (iValue[k] < 0) {
+ if (oob == OutOfBoundsColor.Clip)
+ iValue[k] = 0;
+ else
+ iValue[k] = iValue[k] & 0x00FF;
+ }
}
int compValue = 0xFF000000 | (iValue[0] << 16) | (iValue[1] << 8) | iValue[2];
image.setRGB(iu, iv, compValue);
@@ -97,7 +109,10 @@
}
}
- public static void recalcIndexedImage(PatchColor color, CombinedPatch patch, BufferedImage image) {
+ public static void recalcIndexedImage(PatchColor color, CombinedPatch patch, BufferedImage image, OutOfBoundsColor oob) {
+ if (patch == null)
+ return;
+
PatchCoords coords = patch.getPatch(color);
double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3;
@@ -142,10 +157,18 @@
}
int iValue = (int)value;
- if (iValue > 255)
- iValue = 255;
- else if (iValue < 0)
- iValue = 0;
+ if (iValue > 255) {
+ if (oob == OutOfBoundsColor.Clip)
+ iValue = 255;
+ else
+ iValue = iValue & 0x00FF;
+ }
+ else if (iValue < 0) {
+ if (oob == OutOfBoundsColor.Clip)
+ iValue = 0;
+ else
+ iValue = iValue & 0x00FF;
+ }
if (color == PatchColor.Red)
iValue <<= 16;
else if (color == PatchColor.Green)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|