Thread: [Patchanim-commit] SF.net SVN: patchanim: [14] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-01-26 05:12:34
|
Revision: 14 http://patchanim.svn.sourceforge.net/patchanim/?rev=14&view=rev Author: dbrosius Date: 2008-01-25 21:12:25 -0800 (Fri, 25 Jan 2008) Log Message: ----------- R,G,B Sample patch drawing starting to work. Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-25 13:06:04 UTC (rev 13) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-26 05:12:25 UTC (rev 14) @@ -23,6 +23,7 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; +import java.awt.image.BufferedImage; import java.util.ResourceBundle; import javax.swing.Box; @@ -91,15 +92,11 @@ mediator.addActivePatchChangedListener(new ActivePatchChangedListener() { public void activePatchChanged(ActivePatchChangedEvent apce) { CombinedPatch currentPatch = apce.getActivePatch(); - if (color == PatchColor.Red) - coords = currentPatch.getRedPatch(); - else if (color == PatchColor.Green) - coords = currentPatch.getGreenPatch(); - else if (color == PatchColor.Blue) - coords = currentPatch.getBluePatch(); - else - return; - setColorField(); + coords = currentPatch.getPatch(color); + if (coords != null) { + setColorField(); + sample.recalcImage(color, currentPatch); + } } }); } @@ -113,7 +110,7 @@ } }); } - + public void drawDecoration(Graphics2D g, Rectangle bounds) { if (coords == null) return; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-25 13:06:04 UTC (rev 13) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-26 05:12:25 UTC (rev 14) @@ -31,11 +31,15 @@ import javax.swing.BorderFactory; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import com.mebigfatguy.patchanim.PatchColor; +import com.mebigfatguy.patchanim.surface.CombinedPatch; +import com.mebigfatguy.patchanim.surface.PatchCoords; public class JPatchSamplePanel extends JPanel { private static final int SAMPLE_SIZE = 200; + private static final int ORDER = 4; private PatchColor color; private Color rgb; private BufferedImage image; @@ -82,6 +86,80 @@ }); } + public void recalcImage(final PatchColor color, final CombinedPatch patch) { + Thread t = new Thread(new Runnable() { + public void run() { + if (color == PatchColor.Combined) { + + } else { + PatchCoords coords = patch.getPatch(color); + + double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3; + double v, v2, v3, oneMinusV, oneMinusV2, oneMinusV3; + double[] uCoeffs = new double[ORDER]; + double[] vCoeffs = new double[ORDER]; + + for (int iu = 0; iu < SAMPLE_SIZE; iu++) { + u = (double)iu / (double)SAMPLE_SIZE; + u2 = u * u; + u3 = u2 * u; + oneMinusU = 1.0 - u; + oneMinusU2 = oneMinusU * oneMinusU; + oneMinusU3 = oneMinusU2 * oneMinusU; + + uCoeffs[0] = oneMinusU3; + uCoeffs[1] = 3.0 * u * oneMinusU2; + uCoeffs[2] = 3.0 * u2 * oneMinusU; + uCoeffs[3] = u3; + + for (int iv = 0; iv < SAMPLE_SIZE; iv++) { + v = (double)iv / (double)SAMPLE_SIZE; + v2 = v * v; + v3 = v2 * v; + oneMinusV = 1.0 - v; + oneMinusV2 = oneMinusV * oneMinusV; + oneMinusV3 = oneMinusV2 * oneMinusV; + + vCoeffs[0] = oneMinusV3; + vCoeffs[1] = 3.0 * v * oneMinusV2; + vCoeffs[2] = 3.0 * v2 * oneMinusV; + vCoeffs[3] = v3; + + double value = 0.0; + for (int i = 0; i < ORDER; i++) { + for (int j = 0; j < ORDER; j++) { + value += coords.getCoordinate(i, j).getColor() * uCoeffs[i] * vCoeffs[j]; + } + } + + int iValue = (int)value; + if (iValue > 255) + iValue = 255; + else if (iValue < 0) + iValue = 0; + if (color == PatchColor.Red) + iValue <<= 16; + else if (color == PatchColor.Green) + iValue <<= 8; + iValue |= 0xFF000000; + + image.setRGB(iu, iv, iValue); + } + } + } + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + invalidate(); + revalidate(); + repaint(); + } + }); + } + }); + t.start(); + } + private void buildImage() { if (rgb == null) { image = new BufferedImage(SAMPLE_SIZE, SAMPLE_SIZE, BufferedImage.TYPE_3BYTE_BGR); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-01-25 13:06:04 UTC (rev 13) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-01-26 05:12:25 UTC (rev 14) @@ -19,25 +19,26 @@ package com.mebigfatguy.patchanim.surface; import java.io.Serializable; +import java.util.EnumMap; import java.util.Random; +import com.mebigfatguy.patchanim.PatchColor; + public class CombinedPatch implements Serializable { + private static final long serialVersionUID = 8732763987020552187L; + + private EnumMap<PatchColor, PatchCoords> patches = new EnumMap<PatchColor, PatchCoords>(PatchColor.class); - private PatchCoords red; - private PatchCoords green; - private PatchCoords blue; - public CombinedPatch() { - - red = buildRandomPatch(); - green = buildRandomPatch(); - blue = buildRandomPatch(); + patches.put(PatchColor.Red, buildRandomPatch()); + patches.put(PatchColor.Green, buildRandomPatch()); + patches.put(PatchColor.Blue, buildRandomPatch()); } public CombinedPatch(PatchCoords redPatch, PatchCoords greenPatch, PatchCoords bluePatch) { - red = redPatch; - green = greenPatch; - blue = bluePatch; + patches.put(PatchColor.Red, redPatch); + patches.put(PatchColor.Green, greenPatch); + patches.put(PatchColor.Blue, bluePatch); } private PatchCoords buildRandomPatch() { @@ -51,30 +52,14 @@ return new PatchCoords(coords); } - public PatchCoords getRedPatch() { - return red; + public PatchCoords getPatch(PatchColor color) { + return patches.get(color); } - public void setRedPatch(PatchCoords coords) { - red = coords; + public void setPatch(PatchColor color, PatchCoords coords) { + patches.put(color, coords); } - public PatchCoords getGreenPatch() { - return green; - } - - public void setGreenPatch(PatchCoords coords) { - green = coords; - } - - public PatchCoords getBluePatch() { - return blue; - } - - public void setBluePatch(PatchCoords coords) { - blue = coords; - } - @Override public String toString() { return "Patch Coordinates"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-01-25 13:06:04 UTC (rev 13) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-01-26 05:12:25 UTC (rev 14) @@ -30,12 +30,12 @@ coords = coordinates; } - public Coordinate getCoordinate(int u, int v) { - return coords[u][v]; + public Coordinate getCoordinate(int i, int j) { + return coords[i][j]; } - public void setCoordinate(int u, int v, Coordinate coordinate) { - coords[u][v] = coordinate; + public void setCoordinate(int i, int j, Coordinate coordinate) { + coords[i][j] = coordinate; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-27 00:17:29
|
Revision: 26 http://patchanim.svn.sourceforge.net/patchanim/?rev=26&view=rev Author: dbrosius Date: 2008-01-26 16:17:33 -0800 (Sat, 26 Jan 2008) Log Message: ----------- break out surface routines to a separate class Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-26 07:16:38 UTC (rev 25) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-27 00:17:33 UTC (rev 26) @@ -22,12 +22,10 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; -import java.awt.image.IndexColorModel; import javax.swing.BorderFactory; import javax.swing.JPanel; @@ -35,11 +33,10 @@ import com.mebigfatguy.patchanim.PatchColor; import com.mebigfatguy.patchanim.surface.CombinedPatch; -import com.mebigfatguy.patchanim.surface.PatchCoords; +import com.mebigfatguy.patchanim.surface.PatchGenerator; public class JPatchSamplePanel extends JPanel { private static final int SAMPLE_SIZE = 200; - private static final int ORDER = 4; private PatchColor color; private Color rgb; private BufferedImage image; @@ -67,7 +64,7 @@ } private void initComponents() { - buildImage(); + image = PatchGenerator.buildImage(rgb, SAMPLE_SIZE, SAMPLE_SIZE); setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); Dimension d = new Dimension(SAMPLE_SIZE, SAMPLE_SIZE); setMinimumSize(d); @@ -100,9 +97,9 @@ Thread t = new Thread(new Runnable() { public void run() { if (color == PatchColor.Combined) { - recalcCombinedImage(patch); + PatchGenerator.recalcCombinedImage(patch, image); } else { - recalcIndexedImage(color, patch); + PatchGenerator.recalcIndexedImage(color, patch, image); } SwingUtilities.invokeLater(new Runnable() { @@ -117,150 +114,6 @@ t.start(); } - private void recalcCombinedImage(CombinedPatch patch) { - PatchCoords[] coords = new PatchCoords[3]; - - coords[0] = patch.getPatch(PatchColor.Red); - coords[1] = patch.getPatch(PatchColor.Green); - coords[2] = patch.getPatch(PatchColor.Blue); - - double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3; - double v, v2, v3, oneMinusV, oneMinusV2, oneMinusV3; - double[] uCoeffs = new double[ORDER]; - double[] vCoeffs = new double[ORDER]; - double[] value = new double[3]; - int[] iValue = new int[3]; - - for (int iu = 0; iu < SAMPLE_SIZE; iu++) { - u = (double)iu / (double)SAMPLE_SIZE; - u2 = u * u; - u3 = u2 * u; - oneMinusU = 1.0 - u; - oneMinusU2 = oneMinusU * oneMinusU; - oneMinusU3 = oneMinusU2 * oneMinusU; - - uCoeffs[0] = oneMinusU3; - uCoeffs[1] = 3.0 * u * oneMinusU2; - uCoeffs[2] = 3.0 * u2 * oneMinusU; - uCoeffs[3] = u3; - - for (int iv = 0; iv < SAMPLE_SIZE; iv++) { - v = (double)iv / (double)SAMPLE_SIZE; - v2 = v * v; - v3 = v2 * v; - oneMinusV = 1.0 - v; - oneMinusV2 = oneMinusV * oneMinusV; - oneMinusV3 = oneMinusV2 * oneMinusV; - - vCoeffs[0] = oneMinusV3; - vCoeffs[1] = 3.0 * v * oneMinusV2; - vCoeffs[2] = 3.0 * v2 * oneMinusV; - vCoeffs[3] = v3; - - value[0] = value[1] = value[2] = 0.0; - - for (int i = 0; i < ORDER; i++) { - for (int j = 0; j < ORDER; j++) { - double coeff = uCoeffs[i] * vCoeffs[j]; - for (int k = 0; k < 3; k++) { - value[k] += coords[k].getCoordinate(i, j).getColor() * coeff; - } - } - } - - 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; - } - int compValue = 0xFF000000 | (iValue[0] << 16) | (iValue[1] << 8) | iValue[2]; - image.setRGB(iu, iv, compValue); - } - } - } - - private void recalcIndexedImage(PatchColor color, CombinedPatch patch) { - PatchCoords coords = patch.getPatch(color); - - double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3; - double v, v2, v3, oneMinusV, oneMinusV2, oneMinusV3; - double[] uCoeffs = new double[ORDER]; - double[] vCoeffs = new double[ORDER]; - - for (int iu = 0; iu < SAMPLE_SIZE; iu++) { - u = (double)iu / (double)SAMPLE_SIZE; - u2 = u * u; - u3 = u2 * u; - oneMinusU = 1.0 - u; - oneMinusU2 = oneMinusU * oneMinusU; - oneMinusU3 = oneMinusU2 * oneMinusU; - - uCoeffs[0] = oneMinusU3; - uCoeffs[1] = 3.0 * u * oneMinusU2; - uCoeffs[2] = 3.0 * u2 * oneMinusU; - uCoeffs[3] = u3; - - for (int iv = 0; iv < SAMPLE_SIZE; iv++) { - v = (double)iv / (double)SAMPLE_SIZE; - v2 = v * v; - v3 = v2 * v; - oneMinusV = 1.0 - v; - oneMinusV2 = oneMinusV * oneMinusV; - oneMinusV3 = oneMinusV2 * oneMinusV; - - vCoeffs[0] = oneMinusV3; - vCoeffs[1] = 3.0 * v * oneMinusV2; - vCoeffs[2] = 3.0 * v2 * oneMinusV; - vCoeffs[3] = v3; - - double value = 0.0; - for (int i = 0; i < ORDER; i++) { - for (int j = 0; j < ORDER; j++) { - value += coords.getCoordinate(i, j).getColor() * uCoeffs[i] * vCoeffs[j]; - } - } - - int iValue = (int)value; - if (iValue > 255) - iValue = 255; - else if (iValue < 0) - iValue = 0; - if (color == PatchColor.Red) - iValue <<= 16; - else if (color == PatchColor.Green) - iValue <<= 8; - iValue |= 0xFF000000; - - image.setRGB(iu, iv, iValue); - } - } - } - - private void buildImage() { - if (rgb == null) { - image = new BufferedImage(SAMPLE_SIZE, SAMPLE_SIZE, BufferedImage.TYPE_3BYTE_BGR); - } else { - byte[] r = new byte[256]; - byte[] g = new byte[256]; - byte[] b = new byte[256]; - - for (int i = 0; i < 256; i++) { - r[i] = (byte)((i * rgb.getRed()) / 255); - g[i] = (byte)((i * rgb.getGreen()) / 255); - b[i] = (byte)((i * rgb.getBlue()) / 255); - } - IndexColorModel icm = new IndexColorModel(8, 256, r, g, b); - - image = new BufferedImage(SAMPLE_SIZE, SAMPLE_SIZE, BufferedImage.TYPE_BYTE_INDEXED, icm); - } - - Graphics graphics = image.getGraphics(); - graphics.setColor(rgb); - graphics.fillRect(0, 0, SAMPLE_SIZE, SAMPLE_SIZE); - } - @Override public void paintComponent(Graphics g) { Rectangle bounds = getBounds(); Added: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-01-27 00:17:33 UTC (rev 26) @@ -0,0 +1,187 @@ +/* + * 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.surface; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.image.IndexColorModel; + +import com.mebigfatguy.patchanim.PatchColor; + +public class PatchGenerator { + private static final int ORDER = 4; + + private PatchGenerator() { + } + + public static void recalcCombinedImage(CombinedPatch patch, BufferedImage image) { + PatchCoords[] coords = new PatchCoords[3]; + + coords[0] = patch.getPatch(PatchColor.Red); + coords[1] = patch.getPatch(PatchColor.Green); + coords[2] = patch.getPatch(PatchColor.Blue); + + double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3; + double v, v2, v3, oneMinusV, oneMinusV2, oneMinusV3; + double[] uCoeffs = new double[ORDER]; + double[] vCoeffs = new double[ORDER]; + double[] value = new double[3]; + int[] iValue = new int[3]; + + int sampleSizeX = image.getWidth(); + int sampleSizeY = image.getHeight(); + + for (int iu = 0; iu < sampleSizeX; iu++) { + u = (double)iu / (double)sampleSizeX; + u2 = u * u; + u3 = u2 * u; + oneMinusU = 1.0 - u; + oneMinusU2 = oneMinusU * oneMinusU; + oneMinusU3 = oneMinusU2 * oneMinusU; + + uCoeffs[0] = oneMinusU3; + uCoeffs[1] = 3.0 * u * oneMinusU2; + uCoeffs[2] = 3.0 * u2 * oneMinusU; + uCoeffs[3] = u3; + + for (int iv = 0; iv < sampleSizeY; iv++) { + v = (double)iv / (double)sampleSizeY; + v2 = v * v; + v3 = v2 * v; + oneMinusV = 1.0 - v; + oneMinusV2 = oneMinusV * oneMinusV; + oneMinusV3 = oneMinusV2 * oneMinusV; + + vCoeffs[0] = oneMinusV3; + vCoeffs[1] = 3.0 * v * oneMinusV2; + vCoeffs[2] = 3.0 * v2 * oneMinusV; + vCoeffs[3] = v3; + + value[0] = value[1] = value[2] = 0.0; + + for (int i = 0; i < ORDER; i++) { + for (int j = 0; j < ORDER; j++) { + double coeff = uCoeffs[i] * vCoeffs[j]; + for (int k = 0; k < 3; k++) { + value[k] += coords[k].getCoordinate(i, j).getColor() * coeff; + } + } + } + + 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; + } + int compValue = 0xFF000000 | (iValue[0] << 16) | (iValue[1] << 8) | iValue[2]; + image.setRGB(iu, iv, compValue); + } + } + } + + public static void recalcIndexedImage(PatchColor color, CombinedPatch patch, BufferedImage image) { + PatchCoords coords = patch.getPatch(color); + + double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3; + double v, v2, v3, oneMinusV, oneMinusV2, oneMinusV3; + double[] uCoeffs = new double[ORDER]; + double[] vCoeffs = new double[ORDER]; + + int sampleSizeX = image.getWidth(); + int sampleSizeY = image.getHeight(); + + for (int iu = 0; iu < sampleSizeX; iu++) { + u = (double)iu / (double)sampleSizeX; + u2 = u * u; + u3 = u2 * u; + oneMinusU = 1.0 - u; + oneMinusU2 = oneMinusU * oneMinusU; + oneMinusU3 = oneMinusU2 * oneMinusU; + + uCoeffs[0] = oneMinusU3; + uCoeffs[1] = 3.0 * u * oneMinusU2; + uCoeffs[2] = 3.0 * u2 * oneMinusU; + uCoeffs[3] = u3; + + for (int iv = 0; iv < sampleSizeY; iv++) { + v = (double)iv / (double)sampleSizeY; + v2 = v * v; + v3 = v2 * v; + oneMinusV = 1.0 - v; + oneMinusV2 = oneMinusV * oneMinusV; + oneMinusV3 = oneMinusV2 * oneMinusV; + + vCoeffs[0] = oneMinusV3; + vCoeffs[1] = 3.0 * v * oneMinusV2; + vCoeffs[2] = 3.0 * v2 * oneMinusV; + vCoeffs[3] = v3; + + double value = 0.0; + for (int i = 0; i < ORDER; i++) { + for (int j = 0; j < ORDER; j++) { + value += coords.getCoordinate(i, j).getColor() * uCoeffs[i] * vCoeffs[j]; + } + } + + int iValue = (int)value; + if (iValue > 255) + iValue = 255; + else if (iValue < 0) + iValue = 0; + if (color == PatchColor.Red) + iValue <<= 16; + else if (color == PatchColor.Green) + iValue <<= 8; + iValue |= 0xFF000000; + + image.setRGB(iu, iv, iValue); + } + } + } + + public static BufferedImage buildImage(Color color, int sampleSizeX, int sampleSizeY) { + BufferedImage image = null; + + if (color == null) { + image = new BufferedImage(sampleSizeX, sampleSizeY, BufferedImage.TYPE_3BYTE_BGR); + } else { + byte[] r = new byte[256]; + byte[] g = new byte[256]; + byte[] b = new byte[256]; + + for (int i = 0; i < 256; i++) { + r[i] = (byte)((i * color.getRed()) / 255); + g[i] = (byte)((i * color.getGreen()) / 255); + b[i] = (byte)((i * color.getBlue()) / 255); + } + IndexColorModel icm = new IndexColorModel(8, 256, r, g, b); + + image = new BufferedImage(sampleSizeX, sampleSizeY, BufferedImage.TYPE_BYTE_INDEXED, icm); + } + + Graphics graphics = image.getGraphics(); + graphics.setColor(color); + graphics.fillRect(0, 0, sampleSizeX, sampleSizeY); + return image; + } + +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.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. |
From: <dbr...@us...> - 2008-01-27 01:42:12
|
Revision: 28 http://patchanim.svn.sourceforge.net/patchanim/?rev=28&view=rev Author: dbrosius Date: 2008-01-26 17:42:18 -0800 (Sat, 26 Jan 2008) Log Message: ----------- patch animation is starting to work. Shift coordinates to be doubles. Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-27 01:42:18 UTC (rev 28) @@ -36,10 +36,10 @@ public PatchAnimDocument() { patches = new ArrayList<CombinedPatch>(); - CombinedPatch patch = new CombinedPatch(); + CombinedPatch patch = new CombinedPatch(true); patches.add(patch); - width = 100; - height = 100; + width = 200; + height = 200; animationType = AnimationType.Wave; outOfBoundsColor = OutOfBoundsColor.Clip; tweenCount = 10; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-27 01:42:18 UTC (rev 28) @@ -66,7 +66,7 @@ sample.setDecorator(this); colorLabel = new JLabel(rb.getString(PatchAnimBundle.COLOR)); - colorField = new JTextField(new IntegerDocument(), "", 4); + colorField = new JTextField(new DoubleDocument(), "", 4); add(Box.createVerticalGlue()); JPanel p = new JPanel(); @@ -109,11 +109,20 @@ SwingUtilities.invokeLater(new Runnable() { public void run() { Coordinate coord = coords.getCoordinate(selectedXPt, selectedYPt); - if (!fireEvents) - colorField.getDocument().removeDocumentListener(docListener); - colorField.setText(String.valueOf(coord.getColor())); - if (!fireEvents) - colorField.getDocument().addDocumentListener(docListener); + double newColor = coord.getColor(); + double oldColor; + try { + oldColor = Double.parseDouble(colorField.getText()); + } catch (NumberFormatException nfe) { + oldColor = 0.0; + } + if (newColor != oldColor) { + if (!fireEvents) + colorField.getDocument().removeDocumentListener(docListener); + colorField.setText(String.valueOf(coord.getColor())); + if (!fireEvents) + colorField.getDocument().addDocumentListener(docListener); + } } }); } @@ -127,9 +136,11 @@ for (int v = 0; v < 4; v++) { Coordinate c = coords.getCoordinate(u, v); if ((selectedXPt == u) && (selectedYPt == v)) { - g.fillOval(((c.getX() * (bounds.width - 5)) / 100) + bounds.x, ((c.getY() * (bounds.height - 5)) / 100) + bounds.y, 5, 5); + g.fillOval((int)(((c.getX() * (bounds.width - 5)) / 100.0) + bounds.x), + (int)(((c.getY() * (bounds.height - 5)) / 100.0) + bounds.y), 5, 5); } else { - g.drawOval(((c.getX() * (bounds.width - 5)) / 100) + bounds.x, ((c.getY() * (bounds.height - 5)) / 100) + bounds.y, 5, 5); + g.drawOval((int)(((c.getX() * (bounds.width - 5)) / 100.0) + bounds.x), + (int)(((c.getY() * (bounds.height - 5)) / 100.0) + bounds.y), 5, 5); } } } @@ -163,13 +174,13 @@ } private void processChange() { - int value; - String color = colorField.getText().trim(); - if ((color.length() == 0) || ("-".equals(color))) - return; - else - value = Integer.parseInt(colorField.getText()); - + double value; + + try { + value = Double.parseDouble(colorField.getText()); + } catch (NumberFormatException nfe) { + value = 0.0; + } Coordinate coord = coords.getCoordinate(selectedXPt, selectedYPt); coord.setColor(value); coords.setCoordinate(selectedXPt, selectedYPt, coord); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 01:42:18 UTC (rev 28) @@ -31,7 +31,6 @@ import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.main.PatchAnimBundle; -import com.mebigfatguy.patchanim.main.PatchMain; public class JPatchAnimFrame extends JFrame { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-01-27 01:42:18 UTC (rev 28) @@ -19,19 +19,13 @@ package com.mebigfatguy.patchanim.gui; import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; -import javax.swing.JList; import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; import com.mebigfatguy.patchanim.PatchColor; -import com.mebigfatguy.patchanim.surface.CombinedPatch; public class JPatchAnimPanel extends JPanel { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 01:42:18 UTC (rev 28) @@ -19,6 +19,8 @@ package com.mebigfatguy.patchanim.gui; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.ResourceBundle; import javax.swing.BorderFactory; @@ -143,5 +145,14 @@ }); } }); + + testButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + JTestFrame tf = new JTestFrame(); + tf.setLocationRelativeTo(null); + tf.setVisible(true); + tf.beginAnimation(); + } + }); } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-27 01:42:18 UTC (rev 28) @@ -96,7 +96,7 @@ if (selIndex < 0) selIndex = patchListModel.getSize() - 1; - CombinedPatch newPatch = new CombinedPatch(); + CombinedPatch newPatch = new CombinedPatch(true); patchListModel.add(selIndex, newPatch); PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setNewActivePatch(newPatch); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-27 01:42:18 UTC (rev 28) @@ -50,6 +50,10 @@ } } + public PatchAnimDocument getDocument() { + return document; + } + public void addActivePatchChangedListener(ActivePatchChangedListener apcl) { apclisteners.add(apcl); } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-01-27 01:42:18 UTC (rev 28) @@ -20,7 +20,6 @@ import java.io.Serializable; import java.util.EnumMap; -import java.util.Random; import com.mebigfatguy.patchanim.PatchColor; @@ -29,10 +28,16 @@ private EnumMap<PatchColor, PatchCoords> patches = new EnumMap<PatchColor, PatchCoords>(PatchColor.class); - public CombinedPatch() { - patches.put(PatchColor.Red, PatchCoords.buildRandomPatch()); - patches.put(PatchColor.Green, PatchCoords.buildRandomPatch()); - patches.put(PatchColor.Blue, PatchCoords.buildRandomPatch()); + public CombinedPatch(boolean init) { + if (init) { + patches.put(PatchColor.Red, PatchCoords.buildRandomPatch()); + patches.put(PatchColor.Green, PatchCoords.buildRandomPatch()); + patches.put(PatchColor.Blue, PatchCoords.buildRandomPatch()); + } else { + patches.put(PatchColor.Red, new PatchCoords()); + patches.put(PatchColor.Green, new PatchCoords()); + patches.put(PatchColor.Blue, new PatchCoords()); + } } public CombinedPatch(PatchCoords redPatch, PatchCoords greenPatch, PatchCoords bluePatch) { @@ -41,6 +46,26 @@ patches.put(PatchColor.Blue, bluePatch); } + public static CombinedPatch tween(CombinedPatch startPatch, CombinedPatch endPatch, double frac) { + CombinedPatch tweenPatch = new CombinedPatch(false); + { + PatchCoords sRedCoords = startPatch.getPatch(PatchColor.Red); + PatchCoords eRedCoords = endPatch.getPatch(PatchColor.Red); + tweenPatch.setPatch(PatchColor.Red, PatchCoords.tween(sRedCoords, eRedCoords, frac)); + } + { + PatchCoords sGreenCoords = startPatch.getPatch(PatchColor.Green); + PatchCoords eGreenCoords = endPatch.getPatch(PatchColor.Green); + tweenPatch.setPatch(PatchColor.Green, PatchCoords.tween(sGreenCoords, eGreenCoords, frac)); + } + { + PatchCoords sBlueCoords = startPatch.getPatch(PatchColor.Blue); + PatchCoords eBlueCoords = endPatch.getPatch(PatchColor.Blue); + tweenPatch.setPatch(PatchColor.Blue, PatchCoords.tween(sBlueCoords, eBlueCoords, frac)); + } + return tweenPatch; + } + public PatchCoords getPatch(PatchColor color) { return patches.get(color); } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java 2008-01-27 01:42:18 UTC (rev 28) @@ -22,35 +22,35 @@ public class Coordinate implements Serializable { - private int x, y, color; + private double x, y, color; - public Coordinate(int xPos, int yPos, int colorVal) { + public Coordinate(double xPos, double yPos, double colorVal) { x = xPos; y = yPos; color = colorVal; } - public int getX() { + public double getX() { return x; } - public void setX(int xPos) { + public void setX(double xPos) { x = xPos; } - public int getY() { + public double getY() { return y; } - public void sety(int yPos) { + public void sety(double yPos) { y = yPos; } - public int getColor() { + public double getColor() { return color; } - public void setColor(int colorVal) { + public void setColor(double colorVal) { color = colorVal; } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-01-27 00:24:02 UTC (rev 27) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-01-27 01:42:18 UTC (rev 28) @@ -34,16 +34,35 @@ Random r = new Random(); for (int u = 0; u < PatchCoords.ORDER; u++) { for (int v = 0; v < PatchCoords.ORDER; v++) { - coords[u][v] = new Coordinate((u * 100) / (PatchCoords.ORDER - 1), (v * 100) / (PatchCoords.ORDER - 1), r.nextInt(256)); + coords[u][v] = new Coordinate((u * 100.0) / (PatchCoords.ORDER - 1), (v * 100.0) / (PatchCoords.ORDER - 1), r.nextInt(256)); } } return new PatchCoords(coords); } + public PatchCoords() { + coords = new Coordinate[ORDER][ORDER]; + } + public PatchCoords(Coordinate[][] coordinates) { coords = coordinates; } + public static PatchCoords tween(PatchCoords startCoords, PatchCoords endCoords, double frac) { + + PatchCoords tweenCoords = new PatchCoords(); + for (int x = 0; x < ORDER; x++) { + for (int y = 0; y < ORDER; y++) { + Coordinate startC = startCoords.getCoordinate(x,y); + Coordinate endC = endCoords.getCoordinate(x,y); + int tweenColor = (int)(startC.getColor() + (endC.getColor() - startC.getColor()) * frac); + Coordinate tweenC = new Coordinate(startC.getX(), endC.getY(), tweenColor); + tweenCoords.setCoordinate(x, y, tweenC); + } + } + return tweenCoords; + } + public Coordinate getCoordinate(int i, int j) { return coords[i][j]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
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. |
From: <dbr...@us...> - 2008-01-27 04:31:50
|
Revision: 38 http://patchanim.svn.sourceforge.net/patchanim/?rev=38&view=rev Author: dbrosius Date: 2008-01-26 20:31:55 -0800 (Sat, 26 Jan 2008) Log Message: ----------- findbugs fixes Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.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/surface/Coordinate.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-27 04:31:55 UTC (rev 38) @@ -26,6 +26,8 @@ public class PatchAnimDocument implements Serializable { + private static final long serialVersionUID = -587863884486252874L; + private boolean dirty; private List<CombinedPatch> patches; private int width; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java 2008-01-27 04:31:55 UTC (rev 38) @@ -23,6 +23,8 @@ import com.mebigfatguy.patchanim.surface.CombinedPatch; public class ActivePatchChangedEvent extends EventObject { + private static final long serialVersionUID = -6329025951907079541L; + private CombinedPatch patch; public ActivePatchChangedEvent(Object src, CombinedPatch activePatch) { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java 2008-01-27 04:31:55 UTC (rev 38) @@ -23,6 +23,8 @@ import com.mebigfatguy.patchanim.PatchAnimDocument; public class DocumentChangedEvent extends EventObject { + private static final long serialVersionUID = 7694516648407911200L; + private PatchAnimDocument document; public DocumentChangedEvent(Object src, PatchAnimDocument d) { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-27 04:31:55 UTC (rev 38) @@ -42,6 +42,8 @@ public class JColorControlPatchPanel extends JPanel implements PatchDecorator { + private static final long serialVersionUID = -2524694507912574529L; + private PatchCoords coords; private PatchColor color; private JPatchSamplePanel sample; @@ -67,6 +69,7 @@ colorLabel = new JLabel(rb.getString(PatchAnimBundle.COLOR)); colorField = new JTextField(new DoubleDocument(), "", 4); + colorLabel.setLabelFor(colorField); add(Box.createVerticalGlue()); JPanel p = new JPanel(); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 04:31:55 UTC (rev 38) @@ -20,6 +20,8 @@ import java.awt.BorderLayout; import java.awt.Container; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ResourceBundle; @@ -34,6 +36,8 @@ public class JPatchAnimFrame extends JFrame { + private static final long serialVersionUID = -4610407923936772733L; + private JMenuItem newItem; private JMenuItem openItem; private JMenuItem closeItem; @@ -64,7 +68,7 @@ pack(); } - public void initMenus() { + private void initMenus() { ResourceBundle rb = PatchAnimBundle.getBundle(); JMenuBar mb = new JMenuBar(); JMenu fileMenu = new JMenu(rb.getString(PatchAnimBundle.FILE)); @@ -96,5 +100,12 @@ System.exit(0); } }); + + quitItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + dispose(); + System.exit(0); + } + }); } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-01-27 04:31:55 UTC (rev 38) @@ -29,11 +29,9 @@ public class JPatchAnimPanel extends JPanel { + private static final long serialVersionUID = 7719900566976553103L; private JPatchControlPanel ctrl; private JPatchSamplePanel sample; - private JColorControlPatchPanel redPatch; - private JColorControlPatchPanel greenPatch; - private JColorControlPatchPanel bluePatch; public JPatchAnimPanel() { initComponents(); @@ -63,9 +61,9 @@ q = new JPanel(); { q.setLayout(new BoxLayout(q, BoxLayout.X_AXIS)); - redPatch = new JColorControlPatchPanel(PatchColor.Red); - greenPatch = new JColorControlPatchPanel(PatchColor.Green); - bluePatch = new JColorControlPatchPanel(PatchColor.Blue); + JColorControlPatchPanel redPatch = new JColorControlPatchPanel(PatchColor.Red); + JColorControlPatchPanel greenPatch = new JColorControlPatchPanel(PatchColor.Green); + JColorControlPatchPanel bluePatch = new JColorControlPatchPanel(PatchColor.Blue); q.add(Box.createHorizontalGlue()); q.add(redPatch); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-27 04:31:55 UTC (rev 38) @@ -37,8 +37,6 @@ 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; @@ -47,6 +45,8 @@ public class JPatchControlPanel extends JPanel { + private static final long serialVersionUID = -5968231995166721151L; + private PatchAnimDocument document; private JTextField widthField; private JTextField heightField; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-27 04:31:55 UTC (rev 38) @@ -40,6 +40,8 @@ import com.mebigfatguy.patchanim.surface.CombinedPatch; public class JPatchListPanel extends JPanel { + private static final long serialVersionUID = -6673383252840039387L; + private JList patchList; private PatchListModel patchListModel; private JButton addButton; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-27 04:31:55 UTC (rev 38) @@ -38,6 +38,8 @@ import com.mebigfatguy.patchanim.surface.PatchGenerator; public class JPatchSamplePanel extends JPanel { + private static final long serialVersionUID = 8057501623261814175L; + private static final int SAMPLE_SIZE = 200; private PatchColor color; private Color rgb; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 04:31:55 UTC (rev 38) @@ -41,6 +41,8 @@ public class JTestFrame extends JFrame { + private static final long serialVersionUID = -7975149184522257748L; + private Thread animThread = null; private TestPanel testPanel = null; private int tweenCount; @@ -163,6 +165,8 @@ } class TestPanel extends JPanel { + private static final long serialVersionUID = 6268304008663415749L; + public TestPanel() { Dimension d = new Dimension(width, height); setMinimumSize(d); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java 2008-01-27 04:21:18 UTC (rev 37) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/Coordinate.java 2008-01-27 04:31:55 UTC (rev 38) @@ -22,6 +22,8 @@ public class Coordinate implements Serializable { + private static final long serialVersionUID = 5211344767856486552L; + private double x, y, color; public Coordinate(double xPos, double yPos, double colorVal) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-27 22:29:20
|
Revision: 39 http://patchanim.svn.sourceforge.net/patchanim/?rev=39&view=rev Author: dbrosius Date: 2008-01-27 14:29:19 -0800 (Sun, 27 Jan 2008) Log Message: ----------- start adding io routines Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/io/ trunk/patchanim/src/com/mebigfatguy/patchanim/io/Closer.java trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java Added: trunk/patchanim/src/com/mebigfatguy/patchanim/io/Closer.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/Closer.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/Closer.java 2008-01-27 22:29:19 UTC (rev 39) @@ -0,0 +1,18 @@ +package com.mebigfatguy.patchanim.io; + +import java.io.Closeable; +import java.io.IOException; + +public class Closer { + + private Closer() { + } + + public static void close(Closeable c) { + try { + if (c != null) + c.close(); + } catch (IOException ioe) { + } + } +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/io/Closer.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java 2008-01-27 22:29:19 UTC (rev 39) @@ -0,0 +1,46 @@ +package com.mebigfatguy.patchanim.io; + +import java.beans.XMLDecoder; +import java.beans.XMLEncoder; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import com.mebigfatguy.patchanim.PatchAnimDocument; + +public class PatchAnimIO { + + private PatchAnimIO() { + + } + + public static void saveFile(File f, PatchAnimDocument document) throws IOException { + OutputStream os = null; + try { + os = new BufferedOutputStream(new FileOutputStream(f)); + XMLEncoder encoder = new XMLEncoder(os); + encoder.writeObject(document); + encoder.flush(); + } finally { + Closer.close(os); + } + } + + public static PatchAnimDocument loadFile(File f) throws IOException { + InputStream is = null; + try { + is = new BufferedInputStream(new FileInputStream(f)); + XMLDecoder decoder = new XMLDecoder(is); + return (PatchAnimDocument)decoder.readObject(); + } finally { + Closer.close(is); + } + } + + +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.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. |
From: <dbr...@us...> - 2008-01-27 23:19:25
|
Revision: 40 http://patchanim.svn.sourceforge.net/patchanim/?rev=40&view=rev Author: dbrosius Date: 2008-01-27 15:19:28 -0800 (Sun, 27 Jan 2008) Log Message: ----------- add basic file io Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 22:29:19 UTC (rev 39) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 23:19:28 UTC (rev 40) @@ -24,14 +24,20 @@ import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; import java.util.ResourceBundle; +import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileFilter; import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.io.PatchAnimIO; import com.mebigfatguy.patchanim.main.PatchAnimBundle; public class JPatchAnimFrame extends JFrame { @@ -45,6 +51,7 @@ private JMenuItem saveAsItem; private JMenuItem quitItem; private PatchAnimDocument document; + private File documentLocation; public JPatchAnimFrame() { @@ -60,6 +67,7 @@ JPatchAnimPanel patchPanel = new JPatchAnimPanel(); document = new PatchAnimDocument(); + documentLocation = null; PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setDocument(document); @@ -101,6 +109,29 @@ } }); + openItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + //Ask save + load(); + } + }); + + saveItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + if (documentLocation == null) { + saveAs(); + } else { + save(); + } + } + }); + + saveAsItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + saveAs(); + } + }); + quitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); @@ -108,4 +139,71 @@ } }); } + + private void load() { + try { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setFileFilter(new FileFilter() { + + @Override + public boolean accept(File f) { + if (f.isDirectory()) + return true; + return (f.getPath().endsWith("paf")); + } + + @Override + public String getDescription() { + return "PatchAnim Files (*.paf)"; + } + }); + chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); + int option = chooser.showOpenDialog(JPatchAnimFrame.this); + if (option == JFileChooser.APPROVE_OPTION) { + documentLocation = chooser.getSelectedFile(); + document = PatchAnimIO.loadFile(documentLocation); + } + } catch (Exception e) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + documentLocation = null; + document = new PatchAnimDocument(); + } finally { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.setDocument(document); + } + } + + private void saveAs() { + try { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + File defLocation; + if (documentLocation == null) + defLocation = new File(System.getProperty("user.dir")); + else + defLocation = documentLocation.getParentFile(); + + chooser.setCurrentDirectory(defLocation); + int option = chooser.showSaveDialog(JPatchAnimFrame.this); + if (option == JFileChooser.APPROVE_OPTION) { + String path = chooser.getSelectedFile().getPath(); + if (!path.toLowerCase().endsWith(".paf")) + path += ".paf"; + documentLocation = new File(path); + PatchAnimIO.saveFile(documentLocation, document); + documentLocation = chooser.getSelectedFile(); + } + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + } + } + + private void save() { + try { + PatchAnimIO.saveFile(documentLocation, document); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + } + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java 2008-01-27 22:29:19 UTC (rev 39) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java 2008-01-27 23:19:28 UTC (rev 40) @@ -1,15 +1,14 @@ package com.mebigfatguy.patchanim.io; import java.beans.XMLDecoder; -import java.beans.XMLEncoder; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import com.mebigfatguy.patchanim.PatchAnimDocument; @@ -20,23 +19,22 @@ } public static void saveFile(File f, PatchAnimDocument document) throws IOException { - OutputStream os = null; + ObjectOutputStream os = null; try { - os = new BufferedOutputStream(new FileOutputStream(f)); - XMLEncoder encoder = new XMLEncoder(os); - encoder.writeObject(document); - encoder.flush(); + document.setDirty(false); + os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f))); + os.writeObject(document); + os.flush(); } finally { Closer.close(os); } } - public static PatchAnimDocument loadFile(File f) throws IOException { - InputStream is = null; + public static PatchAnimDocument loadFile(File f) throws IOException, ClassNotFoundException { + ObjectInputStream is = null; try { - is = new BufferedInputStream(new FileInputStream(f)); - XMLDecoder decoder = new XMLDecoder(is); - return (PatchAnimDocument)decoder.readObject(); + is = new ObjectInputStream(new BufferedInputStream(new FileInputStream(f))); + return (PatchAnimDocument)is.readObject(); } finally { Closer.close(is); } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 22:29:19 UTC (rev 39) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 23:19:28 UTC (rev 40) @@ -47,6 +47,7 @@ public static final String ADD = "patchanim.add"; public static final String REMOVE = "patchanim.remove"; public static final String COLOR = "patchanim.color"; + public static final String SAVEFAILED = "patchanim.err.savefailed"; private static ResourceBundle rb = ResourceBundle.getBundle("com/mebigfatguy/patchanim/resources"); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-27 22:29:19 UTC (rev 39) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-27 23:19:28 UTC (rev 40) @@ -40,3 +40,4 @@ patchanim.add = Add patchanim.remove = Remove patchanim.color = Color +patchanim.err.savefailed = Failed saving Patch Animation File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-28 01:21:42
|
Revision: 41 http://patchanim.svn.sourceforge.net/patchanim/?rev=41&view=rev Author: dbrosius Date: 2008-01-27 17:21:47 -0800 (Sun, 27 Jan 2008) Log Message: ----------- get file io working (dirty flag still not set, tho) Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-27 23:19:28 UTC (rev 40) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-28 01:21:47 UTC (rev 41) @@ -47,7 +47,7 @@ tweenCount = 10; } - public boolean getDirty() { + public boolean isDirty() { return dirty; } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 23:19:28 UTC (rev 40) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-28 01:21:47 UTC (rev 41) @@ -109,33 +109,84 @@ } }); + newItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + try { + if (document.isDirty()) { + int choice = askSave(); + if (choice == JFileChooser.CANCEL_OPTION) + return; + if (choice == JFileChooser.APPROVE_OPTION) { + save(); + } + } + + document = new PatchAnimDocument(); + documentLocation = null; + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + } + } + }); + openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - //Ask save - load(); + try { + if (document.isDirty()) { + int choice = askSave(); + if (choice == JFileChooser.CANCEL_OPTION) + return; + if (choice == JFileChooser.APPROVE_OPTION) { + save(); + } + } + load(); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.LOADFAILED); + } } }); saveItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - if (documentLocation == null) { - saveAs(); - } else { - save(); + try { + if (documentLocation == null) { + saveAs(); + } else { + save(); + } + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); } } }); saveAsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - saveAs(); + try { + saveAs(); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + } } }); quitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - dispose(); - System.exit(0); + try { + if (document.isDirty()) { + int choice = askSave(); + if (choice == JFileChooser.CANCEL_OPTION) + return; + if (choice == JFileChooser.APPROVE_OPTION) { + save(); + } + } + dispose(); + System.exit(0); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + } } }); } @@ -174,36 +225,32 @@ } } - private void saveAs() { - try { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - File defLocation; - if (documentLocation == null) - defLocation = new File(System.getProperty("user.dir")); - else - defLocation = documentLocation.getParentFile(); + private void saveAs() throws IOException { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + File defLocation; + if (documentLocation == null) + defLocation = new File(System.getProperty("user.dir")); + else + defLocation = documentLocation.getParentFile(); - chooser.setCurrentDirectory(defLocation); - int option = chooser.showSaveDialog(JPatchAnimFrame.this); - if (option == JFileChooser.APPROVE_OPTION) { - String path = chooser.getSelectedFile().getPath(); - if (!path.toLowerCase().endsWith(".paf")) - path += ".paf"; - documentLocation = new File(path); - PatchAnimIO.saveFile(documentLocation, document); - documentLocation = chooser.getSelectedFile(); - } - } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + chooser.setCurrentDirectory(defLocation); + int option = chooser.showSaveDialog(JPatchAnimFrame.this); + if (option == JFileChooser.APPROVE_OPTION) { + String path = chooser.getSelectedFile().getPath(); + if (!path.toLowerCase().endsWith(".paf")) + path += ".paf"; + documentLocation = new File(path); + PatchAnimIO.saveFile(documentLocation, document); + documentLocation = chooser.getSelectedFile(); } } - private void save() { - try { - PatchAnimIO.saveFile(documentLocation, document); - } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); - } + private void save() throws IOException { + PatchAnimIO.saveFile(documentLocation, document); } + + private int askSave() { + return JFileChooser.APPROVE_OPTION; + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 23:19:28 UTC (rev 40) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 01:21:47 UTC (rev 41) @@ -47,6 +47,7 @@ public static final String ADD = "patchanim.add"; public static final String REMOVE = "patchanim.remove"; public static final String COLOR = "patchanim.color"; + public static final String LOADFAILED = "patchanim.err.loadfailed"; public static final String SAVEFAILED = "patchanim.err.savefailed"; private static ResourceBundle rb = ResourceBundle.getBundle("com/mebigfatguy/patchanim/resources"); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-27 23:19:28 UTC (rev 40) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 01:21:47 UTC (rev 41) @@ -41,3 +41,4 @@ patchanim.remove = Remove patchanim.color = Color patchanim.err.savefailed = Failed saving Patch Animation File +patchanim.err.loadfailed = Failed loading Patch Animation File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-28 01:45:24
|
Revision: 43 http://patchanim.svn.sourceforge.net/patchanim/?rev=43&view=rev Author: dbrosius Date: 2008-01-27 17:45:28 -0800 (Sun, 27 Jan 2008) Log Message: ----------- add asking for save before doing destroy actions. Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-28 01:22:32 UTC (rev 42) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-28 01:45:28 UTC (rev 43) @@ -84,10 +84,9 @@ fileMenu.add(newItem); openItem = new JMenuItem(rb.getString(PatchAnimBundle.OPEN)); fileMenu.add(openItem); - closeItem = new JMenuItem(rb.getString(PatchAnimBundle.CLOSE)); - fileMenu.add(closeItem); fileMenu.addSeparator(); saveItem = new JMenuItem(rb.getString(PatchAnimBundle.SAVE)); + saveItem.setEnabled(false); fileMenu.add(saveItem); saveAsItem = new JMenuItem(rb.getString(PatchAnimBundle.SAVEAS)); fileMenu.add(saveAsItem); @@ -104,8 +103,20 @@ addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { - dispose(); - System.exit(0); + try { + if (document.isDirty()) { + int choice = askSave(); + if (choice == JOptionPane.CANCEL_OPTION) + return; + if (choice == JOptionPane.YES_OPTION) { + save(); + } + } + dispose(); + System.exit(0); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + } } }); @@ -114,15 +125,16 @@ try { if (document.isDirty()) { int choice = askSave(); - if (choice == JFileChooser.CANCEL_OPTION) + if (choice == JOptionPane.CANCEL_OPTION) return; - if (choice == JFileChooser.APPROVE_OPTION) { + if (choice == JOptionPane.YES_OPTION) { save(); } } document = new PatchAnimDocument(); documentLocation = null; + saveItem.setEnabled(false); } catch (IOException ioe) { JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); } @@ -134,9 +146,9 @@ try { if (document.isDirty()) { int choice = askSave(); - if (choice == JFileChooser.CANCEL_OPTION) + if (choice == JOptionPane.CANCEL_OPTION) return; - if (choice == JFileChooser.APPROVE_OPTION) { + if (choice == JOptionPane.YES_OPTION) { save(); } } @@ -176,9 +188,9 @@ try { if (document.isDirty()) { int choice = askSave(); - if (choice == JFileChooser.CANCEL_OPTION) + if (choice == JOptionPane.CANCEL_OPTION) return; - if (choice == JFileChooser.APPROVE_OPTION) { + if (choice == JOptionPane.YES_OPTION) { save(); } } @@ -189,6 +201,21 @@ } } }); + + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.addActivePatchChangedListener(new ActivePatchChangedListener () { + public void activePatchChanged(ActivePatchChangedEvent apce) { + document.setDirty(true); + saveItem.setEnabled(true); + } + }); + + mediator.addSettingsChangedListener(new SettingsChangedListener() { + public void settingsChanged(SettingsChangedEvent sce) { + document.setDirty(true); + saveItem.setEnabled(true); + } + }); } private void load() { @@ -222,6 +249,7 @@ } finally { PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setDocument(document); + saveItem.setEnabled(false); } } @@ -243,14 +271,19 @@ documentLocation = new File(path); PatchAnimIO.saveFile(documentLocation, document); documentLocation = chooser.getSelectedFile(); + document.setDirty(false); + saveItem.setEnabled(false); } } private void save() throws IOException { PatchAnimIO.saveFile(documentLocation, document); + document.setDirty(false); + saveItem.setEnabled(false); } private int askSave() { - return JFileChooser.APPROVE_OPTION; + ResourceBundle rb = PatchAnimBundle.getBundle(); + return JOptionPane.showConfirmDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.ASKSAVE), rb.getString(PatchAnimBundle.TITLE), JOptionPane.YES_NO_CANCEL_OPTION); } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 01:22:32 UTC (rev 42) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 01:45:28 UTC (rev 43) @@ -27,7 +27,6 @@ public static final String FILE = "patchanim.file"; public static final String NEW = "patchanim.new"; public static final String OPEN = "patchanim.open"; - public static final String CLOSE = "patchanim.close"; public static final String SAVE = "patchanim.save"; public static final String SAVEAS = "patchanim.saveas"; public static final String QUIT = "patchanim.quit"; @@ -47,6 +46,7 @@ public static final String ADD = "patchanim.add"; public static final String REMOVE = "patchanim.remove"; public static final String COLOR = "patchanim.color"; + public static final String ASKSAVE = "patchanim.asksave"; public static final String LOADFAILED = "patchanim.err.loadfailed"; public static final String SAVEFAILED = "patchanim.err.savefailed"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 01:22:32 UTC (rev 42) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 01:45:28 UTC (rev 43) @@ -20,7 +20,6 @@ patchanim.file = File patchanim.new = New patchanim.open = Open... -patchanim.close = Close patchanim.save = Save patchanim.saveas = Save As... patchanim.quit = Quit @@ -40,5 +39,6 @@ patchanim.add = Add patchanim.remove = Remove patchanim.color = Color +patchanim.asksave = Do you want to save your changes? patchanim.err.savefailed = Failed saving Patch Animation File patchanim.err.loadfailed = Failed loading Patch Animation File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-28 07:48:25
|
Revision: 51 http://patchanim.svn.sourceforge.net/patchanim/?rev=51&view=rev Author: dbrosius Date: 2008-01-27 23:48:31 -0800 (Sun, 27 Jan 2008) Log Message: ----------- add context menu to patches to bulk set all ctrl points to either black, fullcolor or custom value Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-28 02:45:47 UTC (rev 50) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-28 07:48:31 UTC (rev 51) @@ -23,18 +23,28 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import java.util.ResourceBundle; import javax.swing.BorderFactory; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import com.mebigfatguy.patchanim.OutOfBoundsColor; import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.PatchColor; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; import com.mebigfatguy.patchanim.surface.CombinedPatch; +import com.mebigfatguy.patchanim.surface.Coordinate; +import com.mebigfatguy.patchanim.surface.PatchCoords; import com.mebigfatguy.patchanim.surface.PatchGenerator; public class JPatchSamplePanel extends JPanel { @@ -81,10 +91,21 @@ addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { - if (decorator != null) { + if (decorator != null) decorator.click(me.getPoint(), JPatchSamplePanel.this.getBounds()); - } } + + @Override + public void mousePressed(MouseEvent me) { + if ((color != PatchColor.Combined) && me.isPopupTrigger()) + showPatchContentMenu(me); + } + + @Override + public void mouseReleased(MouseEvent me) { + if ((color != PatchColor.Combined) && me.isPopupTrigger()) + showPatchContentMenu(me); + } }); PatchPanelMediator mediator = PatchPanelMediator.getMediator(); @@ -142,6 +163,54 @@ } } + private void showPatchContentMenu(MouseEvent me) { + final ResourceBundle rb = PatchAnimBundle.getBundle(); + JPopupMenu menu = new JPopupMenu(); + JMenu setAllItem = new JMenu(rb.getString(PatchAnimBundle.SETALLPOINTS)); + menu.add(setAllItem); + JMenuItem blackItem = new JMenuItem(rb.getString(PatchAnimBundle.BLACK)); + blackItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + setAllPts(0.0); + } + }); + setAllItem.add(blackItem); + JMenuItem fullColorItem = new JMenuItem(rb.getString(PatchAnimBundle.FULLCOLOR)); + fullColorItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + setAllPts(255.0); + } + }); + + setAllItem.add(fullColorItem); + JMenuItem valueItem = new JMenuItem(rb.getString(PatchAnimBundle.VALUE)); + valueItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + String value = JOptionPane.showInputDialog(JPatchSamplePanel.this, rb.getString(PatchAnimBundle.VALUE), "128"); + try { + setAllPts(Double.parseDouble(value)); + } catch (NumberFormatException nfe) { + } + } + }); + setAllItem.add(valueItem); + menu.show(JPatchSamplePanel.this, me.getX(), me.getY()); + } + + private void setAllPts(double d) { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + CombinedPatch patch = mediator.getActivePatch(); + PatchCoords coords = patch.getPatch(color); + for (int i = 0; i < PatchCoords.ORDER; i++) { + for (int j = 0; j < PatchCoords.ORDER; j++) { + Coordinate c = coords.getCoordinate(i, j); + c.setColor(d); + coords.setCoordinate(i, j, c); + } + } + mediator.setNewActivePatch(patch); + } + @Override public void paintComponent(Graphics g) { Rectangle bounds = getBounds(); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 02:45:47 UTC (rev 50) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 07:48:31 UTC (rev 51) @@ -46,6 +46,10 @@ public static final String ADD = "patchanim.add"; public static final String REMOVE = "patchanim.remove"; public static final String COLOR = "patchanim.color"; + public static final String SETALLPOINTS = "patchanim.setallpoints"; + public static final String BLACK = "patchanim.black"; + public static final String FULLCOLOR="patchanim.fullcolor"; + public static final String VALUE="patchanim.value"; public static final String ASKSAVE = "patchanim.asksave"; public static final String LOADFAILED = "patchanim.err.loadfailed"; public static final String SAVEFAILED = "patchanim.err.savefailed"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 02:45:47 UTC (rev 50) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 07:48:31 UTC (rev 51) @@ -39,6 +39,10 @@ patchanim.add = Add patchanim.remove = Remove patchanim.color = Color +patchanim.setallpoints = Set all control points to... +patchanim.black = Black +patchanim.fullcolor = Full Color +patchanim.value = Value... patchanim.asksave = Do you want to save your changes? patchanim.err.savefailed = Failed saving Patch Animation File patchanim.err.loadfailed = Failed loading Patch Animation File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-29 05:54:57
|
Revision: 53 http://patchanim.svn.sourceforge.net/patchanim/?rev=53&view=rev Author: dbrosius Date: 2008-01-28 21:55:02 -0800 (Mon, 28 Jan 2008) Log Message: ----------- add export to list of jpgs or pngs Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-28 07:50:54 UTC (rev 52) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-29 05:55:02 UTC (rev 53) @@ -24,10 +24,14 @@ import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.text.NumberFormat; +import java.util.List; import java.util.ResourceBundle; +import javax.imageio.ImageIO; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu; @@ -36,9 +40,14 @@ import javax.swing.JOptionPane; import javax.swing.filechooser.FileFilter; +import com.mebigfatguy.patchanim.AnimationType; +import com.mebigfatguy.patchanim.ExportType; +import com.mebigfatguy.patchanim.OutOfBoundsColor; import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.io.PatchAnimIO; import com.mebigfatguy.patchanim.main.PatchAnimBundle; +import com.mebigfatguy.patchanim.surface.CombinedPatch; +import com.mebigfatguy.patchanim.surface.PatchGenerator; public class JPatchAnimFrame extends JFrame { @@ -46,9 +55,11 @@ private JMenuItem newItem; private JMenuItem openItem; - private JMenuItem closeItem; private JMenuItem saveItem; private JMenuItem saveAsItem; + private JMenu exportMenu; + private JMenuItem exportJpgsItem; + private JMenuItem exportPngsItem; private JMenuItem quitItem; private PatchAnimDocument document; private File documentLocation; @@ -91,6 +102,13 @@ saveAsItem = new JMenuItem(rb.getString(PatchAnimBundle.SAVEAS)); fileMenu.add(saveAsItem); fileMenu.addSeparator(); + exportMenu = new JMenu(rb.getString(PatchAnimBundle.EXPORT)); + exportJpgsItem = new JMenuItem(rb.getString(PatchAnimBundle.JPGSERIES)); + exportPngsItem = new JMenuItem(rb.getString(PatchAnimBundle.PNGSERIES)); + exportMenu.add(exportJpgsItem); + exportMenu.add(exportPngsItem); + fileMenu.add(exportMenu); + fileMenu.addSeparator(); quitItem = new JMenuItem(rb.getString(PatchAnimBundle.QUIT)); fileMenu.add(quitItem); @@ -183,6 +201,26 @@ } }); + exportJpgsItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + try { + exportFiles(ExportType.JPegs); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); + } + } + }); + + exportPngsItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + try { + exportFiles(ExportType.Pngs); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); + } + } + }); + quitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { @@ -286,4 +324,67 @@ ResourceBundle rb = PatchAnimBundle.getBundle(); return JOptionPane.showConfirmDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.ASKSAVE), rb.getString(PatchAnimBundle.TITLE), JOptionPane.YES_NO_CANCEL_OPTION); } + + private void exportFiles(ExportType type) throws IOException { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + File defLocation; + if (documentLocation == null) + defLocation = new File(System.getProperty("user.dir")); + else + defLocation = documentLocation.getParentFile(); + + chooser.setCurrentDirectory(defLocation); + int option = chooser.showSaveDialog(JPatchAnimFrame.this); + if (option != JFileChooser.APPROVE_OPTION) + return; + + File dir = chooser.getSelectedFile(); + dir.mkdir(); + String baseName = dir.getName(); + + BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight()); + + List<CombinedPatch> patches = document.getPatches(); + int lastPatch = patches.size() - 1; + int tweenCount = document.getTweenCount(); + OutOfBoundsColor oob = document.getOutOfBoundsColor(); + int imageIndex = 1; + AnimationType atype = document.getAnimationType(); + + for(int p = 0; p < lastPatch; p++) { + CombinedPatch startPatch = patches.get(p); + 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, oob); + writeSingleFile(image, imageIndex++, dir, baseName, type); + } + } + + if (atype == AnimationType.None) + return; + + if (atype == AnimationType.Wave) { + for (int p = lastPatch; p > 0; p--) { + CombinedPatch startPatch = patches.get(p-1); + 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, oob); + writeSingleFile(image, imageIndex++, dir, baseName, type); + } + } + } + } + + private void writeSingleFile(BufferedImage image, int index, File dir, String baseName, ExportType type) throws IOException { + NumberFormat nf = NumberFormat.getIntegerInstance(); + nf.setMinimumIntegerDigits(6); + String name = baseName + "_" + nf.format(index) + "." + type.getExtension(); + + File imageFile = new File(dir, name); + ImageIO.write(image, type.getExtension(), imageFile); + } } + Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 07:50:54 UTC (rev 52) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-29 05:55:02 UTC (rev 53) @@ -29,6 +29,9 @@ public static final String OPEN = "patchanim.open"; public static final String SAVE = "patchanim.save"; public static final String SAVEAS = "patchanim.saveas"; + public static final String EXPORT = "patchanim.export"; + public static final String JPGSERIES = "patchanim.jpgs"; + public static final String PNGSERIES = "patchanim.pngs"; public static final String QUIT = "patchanim.quit"; public static final String CONTROLS = "patchanim.control"; public static final String WIDTH = "patchanim.width"; @@ -53,6 +56,7 @@ public static final String ASKSAVE = "patchanim.asksave"; public static final String LOADFAILED = "patchanim.err.loadfailed"; public static final String SAVEFAILED = "patchanim.err.savefailed"; + public static final String EXPORTFAILED = "patchanim.err.exportfailed"; private static ResourceBundle rb = ResourceBundle.getBundle("com/mebigfatguy/patchanim/resources"); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 07:50:54 UTC (rev 52) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-29 05:55:02 UTC (rev 53) @@ -22,6 +22,9 @@ patchanim.open = Open... patchanim.save = Save patchanim.saveas = Save As... +patchanim.export = Export As... +patchanim.jpgs = a series of JPGs +patchanim.pngs = a series of PNGs patchanim.quit = Quit patchanim.control = Controls patchanim.width = Width @@ -46,3 +49,4 @@ patchanim.asksave = Do you want to save your changes? patchanim.err.savefailed = Failed saving Patch Animation File patchanim.err.loadfailed = Failed loading Patch Animation File +patchanim.err.exportfailed = Failed exporting PatchAnimations This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-18 18:36:38
|
Revision: 215 http://patchanim.svn.sourceforge.net/patchanim/?rev=215&view=rev Author: dbrosius Date: 2008-02-18 10:36:45 -0800 (Mon, 18 Feb 2008) Log Message: ----------- add shift menu to patch context menu Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-18 18:16:41 UTC (rev 214) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-18 18:36:45 UTC (rev 215) @@ -44,6 +44,7 @@ import com.mebigfatguy.patchanim.OutOfBoundsColor; import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.PatchColor; +import com.mebigfatguy.patchanim.ShiftDirection; import com.mebigfatguy.patchanim.gui.events.ActivePatchChangedEvent; import com.mebigfatguy.patchanim.gui.events.ActivePatchChangedListener; import com.mebigfatguy.patchanim.gui.events.DocumentChangedEvent; @@ -305,7 +306,42 @@ radialGradient.add(outward); radialGradient.add(inward); menu.add(radialGradient); + + JMenu shift = new JMenu(rb.getString(PatchAnimBundle.SHIFT)); + JMenuItem left = new JMenuItem(rb.getString(PatchAnimBundle.LEFT)); + left.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + shiftPatch(ShiftDirection.Left); + } + }); + JMenuItem down = new JMenuItem(rb.getString(PatchAnimBundle.DOWN)); + down.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + shiftPatch(ShiftDirection.Down); + } + }); + + JMenuItem right = new JMenuItem(rb.getString(PatchAnimBundle.RIGHT)); + right.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + shiftPatch(ShiftDirection.Right); + } + }); + + JMenuItem up = new JMenuItem(rb.getString(PatchAnimBundle.UP)); + up.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + shiftPatch(ShiftDirection.Up); + } + }); + + shift.add(left); + shift.add(down); + shift.add(right); + shift.add(up); + menu.add(shift); + JMenuItem invert = new JMenuItem(rb.getString(PatchAnimBundle.INVERT)); invert.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { @@ -474,6 +510,43 @@ mediator.setNewActivePatch(patch); } + private void shiftPatch(ShiftDirection dir) { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + CombinedPatch patch = mediator.getActivePatch(); + PatchCoords coords = patch.getPatch(color); + int order = coords.getOrder(); + + PatchCoords srcCoords = (PatchCoords)coords.clone(); + + for (int i = 0; i < order; i++) { + for (int j = 0; j < order; j++) { + Coordinate c = coords.getCoordinate(i, j); + Coordinate srcC = null; + switch (dir) { + case Left: + srcC = srcCoords.getCoordinate((i + 1) % order, j); + break; + + case Down: + srcC = srcCoords.getCoordinate(i, (j - 1 + order) % order); + break; + + case Right: + srcC = srcCoords.getCoordinate((i - 1 + order) % order, j); + break; + + case Up: + srcC = srcCoords.getCoordinate(i, (j + 1) % order); + break; + } + + c.setColor(srcC.getColor()); + coords.setCoordinate(i, j, c); + } + } + mediator.setNewActivePatch(patch); + } + @Override public void paintComponent(Graphics g) { Shape clip = g.getClip(); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-18 18:16:41 UTC (rev 214) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-18 18:36:45 UTC (rev 215) @@ -89,6 +89,11 @@ public static final String RADIALGRADIENT = "patchanim.radialgradient"; public static final String OUTWARD = "patchanim.outward"; public static final String INWARD = "patchanim.inward"; + public static final String SHIFT = "patchanim.shift"; + public static final String LEFT = "patchanim.left"; + public static final String DOWN = "patchanim.down"; + public static final String RIGHT = "patchanim.right"; + public static final String UP = "patchanim.up"; public static final String INVERT = "patchanim.invert"; public static final String COPYPATCHFROM = "patchanim.copypatchfrom"; public static final String REDPATCH = "patchanim.redpatch"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-18 18:16:41 UTC (rev 214) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-18 18:36:45 UTC (rev 215) @@ -82,6 +82,11 @@ patchanim.radialgradient = Radial Gradient patchanim.outward = Outward patchanim.inward = Inward +patchanim.shift = Shift +patchanim.left = Left +patchanim.down = Down +patchanim.right = Right +patchanim.up = Up patchanim.invert = Invert patchanim.copypatchfrom = Copy patch from... patchanim.redpatch = Red Patch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-30 01:34:30
|
Revision: 57 http://patchanim.svn.sourceforge.net/patchanim/?rev=57&view=rev Author: dbrosius Date: 2008-01-29 17:34:35 -0800 (Tue, 29 Jan 2008) Log Message: ----------- break out export routines to another class, fix the add scroll button Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java 2008-01-30 00:59:16 UTC (rev 56) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java 2008-01-30 01:34:35 UTC (rev 57) @@ -1,18 +1,22 @@ package com.mebigfatguy.patchanim; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; + public enum ExportType { - JPegs("jpg", true), - Pngs("png", true), - Gifs("gif", true), - AnimatedGif("gif", false), - MPeg("mpg", false); + JPegs("jpg", true, PatchAnimBundle.JPGSERIESFILTER), + Pngs("png", true, PatchAnimBundle.PNGSERIESFILTER), + Gifs("gif", true, PatchAnimBundle.GIFSERIESFILTER), + AnimatedGif("gif", false, PatchAnimBundle.ANIMATEDGIFFILTER), + MPeg("mpeg", false, PatchAnimBundle.MPEGFILTER); private String ext; private boolean multi; + private String key; - private ExportType(String extension, boolean multipleFiles) { + private ExportType(String extension, boolean multipleFiles, String descriptionKey) { ext = extension; multi = multipleFiles; + key = descriptionKey; } public String getExtension() { @@ -22,4 +26,8 @@ public boolean isMultipleFiles() { return multi; } + + public String getDescriptionKey() { + return key; + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-30 00:59:16 UTC (rev 56) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-30 01:34:35 UTC (rev 57) @@ -46,6 +46,7 @@ import com.mebigfatguy.patchanim.OutOfBoundsColor; import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.io.PatchAnimIO; +import com.mebigfatguy.patchanim.io.PatchExporter; import com.mebigfatguy.patchanim.main.PatchAnimBundle; import com.mebigfatguy.patchanim.surface.CombinedPatch; import com.mebigfatguy.patchanim.surface.PatchGenerator; @@ -66,9 +67,7 @@ private JMenuItem quitItem; private PatchAnimDocument document; private File documentLocation; - private AnimatedGifEncoder agEncoder = null; - public JPatchAnimFrame() { initComponents(); initMenus(); @@ -213,7 +212,11 @@ exportJpgsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { - exportFiles(ExportType.JPegs); + File f = getExportLocation(ExportType.JPegs); + if (f != null) { + PatchExporter exporter = new PatchExporter(ExportType.JPegs, f); + exporter.export(document); + } } catch (IOException ioe) { JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); } @@ -223,7 +226,11 @@ exportPngsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { - exportFiles(ExportType.Pngs); + File f = getExportLocation(ExportType.Pngs); + if (f != null) { + PatchExporter exporter = new PatchExporter(ExportType.Pngs, f); + exporter.export(document); + } } catch (IOException ioe) { JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); } @@ -233,7 +240,11 @@ exportGifsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { - exportFiles(ExportType.Gifs); + File f = getExportLocation(ExportType.Gifs); + if (f != null) { + PatchExporter exporter = new PatchExporter(ExportType.Gifs, f); + exporter.export(document); + } } catch (IOException ioe) { JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); } @@ -243,7 +254,11 @@ exportAnimatedGifItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { - exportFiles(ExportType.AnimatedGif); + File f = getExportLocation(ExportType.AnimatedGif); + if (f != null) { + PatchExporter exporter = new PatchExporter(ExportType.AnimatedGif, f); + exporter.export(document); + } } catch (IOException ioe) { JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); } @@ -354,7 +369,8 @@ return JOptionPane.showConfirmDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.ASKSAVE), rb.getString(PatchAnimBundle.TITLE), JOptionPane.YES_NO_CANCEL_OPTION); } - private void exportFiles(ExportType type) throws IOException { + private File getExportLocation(final ExportType type) { + final ResourceBundle rb = PatchAnimBundle.getBundle(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); File defLocation; @@ -362,85 +378,28 @@ defLocation = new File(System.getProperty("user.dir")); else defLocation = documentLocation.getParentFile(); - chooser.setCurrentDirectory(defLocation); - int option = chooser.showSaveDialog(JPatchAnimFrame.this); - if (option != JFileChooser.APPROVE_OPTION) - return; - File dir = chooser.getSelectedFile(); - String baseName = dir.getName(); - if (type.isMultipleFiles()) { - dir.mkdir(); - } else { - dir = dir.getParentFile(); - String dotExt = "." + type.getExtension(); - if (!baseName.endsWith(dotExt)) - baseName = baseName + dotExt; - if (type == ExportType.AnimatedGif) { - agEncoder = new AnimatedGifEncoder(); - agEncoder.start(new File(dir, baseName).getPath()); - } - } + if (!type.isMultipleFiles()) { + chooser.setFileFilter(new FileFilter() { - BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight()); - - List<CombinedPatch> patches = document.getPatches(); - int lastPatch = patches.size() - 1; - int tweenCount = document.getTweenCount(); - OutOfBoundsColor oob = document.getOutOfBoundsColor(); - int imageIndex = 1; - AnimationType atype = document.getAnimationType(); - - for(int p = 0; p < lastPatch; p++) { - CombinedPatch startPatch = patches.get(p); - 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, oob); - writeSingleFile(image, imageIndex++, dir, baseName, type); - } - } - - if (atype == AnimationType.None) - return; - - if (atype == AnimationType.Wave) { - for (int p = lastPatch; p > 0; p--) { - CombinedPatch startPatch = patches.get(p-1); - 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, oob); - writeSingleFile(image, imageIndex++, dir, baseName, type); + @Override + public boolean accept(File f) { + return (f.isDirectory() || f.getPath().toLowerCase().endsWith("." + type.getExtension())); } - } + + @Override + public String getDescription() { + return rb.getString(type.getDescriptionKey()); + } + }); } - if (type == ExportType.AnimatedGif) { - agEncoder.finish(); - agEncoder = null; - } + int option = chooser.showSaveDialog(JPatchAnimFrame.this); + if (option != JFileChooser.APPROVE_OPTION) + return null; + + return chooser.getSelectedFile(); } - - private void writeSingleFile(BufferedImage image, int index, File dir, String baseName, ExportType type) throws IOException { - NumberFormat nf = NumberFormat.getIntegerInstance(); - nf.setMinimumIntegerDigits(6); - String name = baseName + "_" + nf.format(index) + "." + type.getExtension(); - - File imageFile = new File(dir, name); - - if (type == ExportType.Gifs) { - AnimatedGifEncoder encoder = new AnimatedGifEncoder(); - encoder.start(imageFile.getPath()); - encoder.addFrame(image); - encoder.finish(); - } else if (type == ExportType.AnimatedGif) { - agEncoder.addFrame(image); - agEncoder.setDelay(100); - } - else - ImageIO.write(image, type.getExtension(), imageFile); - } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-30 00:59:16 UTC (rev 56) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-30 01:34:35 UTC (rev 57) @@ -96,14 +96,14 @@ public void actionPerformed(ActionEvent ae) { int selIndex = patchList.getSelectedIndex(); if (selIndex < 0) - selIndex = patchListModel.getSize() - 1; + selIndex = patchListModel.getSize(); + else + selIndex++; CombinedPatch newPatch = new CombinedPatch(true); patchListModel.add(selIndex, newPatch); - PatchPanelMediator mediator = PatchPanelMediator.getMediator(); - mediator.setNewActivePatch(newPatch); + patchList.setSelectedIndex(selIndex); removeButton.setEnabled(patchListModel.getSize() > 1); - patchList.setSelectedIndex(selIndex); } }); Added: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-01-30 01:34:35 UTC (rev 57) @@ -0,0 +1,125 @@ +/* + * 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.io; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.text.NumberFormat; +import java.util.List; + +import javax.imageio.ImageIO; + +import com.fmsware.gif.AnimatedGifEncoder; +import com.mebigfatguy.patchanim.AnimationType; +import com.mebigfatguy.patchanim.ExportType; +import com.mebigfatguy.patchanim.OutOfBoundsColor; +import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.surface.CombinedPatch; +import com.mebigfatguy.patchanim.surface.PatchGenerator; + +public class PatchExporter { + private ExportType type; + private File loc; + private AnimatedGifEncoder agEncoder; + + public PatchExporter(ExportType exportType, File location) { + type = exportType; + loc = location; + if (type == ExportType.AnimatedGif) + agEncoder = new AnimatedGifEncoder(); + else + agEncoder = null; + } + + public void export(PatchAnimDocument document) throws IOException { + try { + String baseName = loc.getName(); + if (type.isMultipleFiles()) { + loc.mkdir(); + } else { + loc = loc.getParentFile(); + String dotExt = "." + type.getExtension(); + if (!baseName.toLowerCase().endsWith(dotExt)) + baseName = baseName + dotExt; + if (type == ExportType.AnimatedGif) + agEncoder.start(new File(loc, baseName).getPath()); + } + + BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight()); + + List<CombinedPatch> patches = document.getPatches(); + int lastPatch = patches.size() - 1; + int tweenCount = document.getTweenCount(); + OutOfBoundsColor oob = document.getOutOfBoundsColor(); + int imageIndex = 1; + AnimationType atype = document.getAnimationType(); + + for(int p = 0; p < lastPatch; p++) { + CombinedPatch startPatch = patches.get(p); + 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, oob); + writeSingleFile(image, imageIndex++, loc, baseName, type); + } + } + + if (atype == AnimationType.None) + return; + + if (atype == AnimationType.Wave) { + for (int p = lastPatch; p > 0; p--) { + CombinedPatch startPatch = patches.get(p-1); + 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, oob); + writeSingleFile(image, imageIndex++, loc, baseName, type); + } + } + } + } finally { + if (type == ExportType.AnimatedGif) { + agEncoder.finish(); + } + } + } + + private void writeSingleFile(BufferedImage image, int index, File dir, String baseName, ExportType type) throws IOException { + NumberFormat nf = NumberFormat.getIntegerInstance(); + nf.setMinimumIntegerDigits(6); + String name = baseName + "_" + nf.format(index) + "." + type.getExtension(); + + File imageFile = new File(dir, name); + + if (type == ExportType.Gifs) { + AnimatedGifEncoder encoder = new AnimatedGifEncoder(); + encoder.start(imageFile.getPath()); + encoder.addFrame(image); + encoder.finish(); + } else if (type == ExportType.AnimatedGif) { + agEncoder.addFrame(image); + agEncoder.setDelay(100); + } + else + ImageIO.write(image, type.getExtension(), imageFile); + } + +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.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-30 00:59:16 UTC (rev 56) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-30 01:34:35 UTC (rev 57) @@ -31,9 +31,15 @@ public static final String SAVEAS = "patchanim.saveas"; public static final String EXPORT = "patchanim.export"; public static final String JPGSERIES = "patchanim.jpgs"; + public static final String JPGSERIESFILTER = "patchanim.filter.jpgs"; public static final String PNGSERIES = "patchanim.pngs"; + public static final String PNGSERIESFILTER = "patchanim.filter.pngs"; public static final String GIFSERIES = "patchanim.gifs"; + public static final String GIFSERIESFILTER = "patchanim.filter.gifs"; public static final String ANIMATEDGIF = "patchanim.animatedgif"; + public static final String ANIMATEDGIFFILTER = "patchanim.filter.animatedgif"; + public static final String MPEG = "patchanim.mpeg"; + public static final String MPEGFILTER = "patchanim.filter.mpeg"; public static final String QUIT = "patchanim.quit"; public static final String CONTROLS = "patchanim.control"; public static final String WIDTH = "patchanim.width"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-30 00:59:16 UTC (rev 56) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-30 01:34:35 UTC (rev 57) @@ -24,9 +24,15 @@ patchanim.saveas = Save As... patchanim.export = Export As... patchanim.jpgs = a series of JPGs +patchanim.filter.jpgs = Files (*.jpg) patchanim.pngs = a series of PNGs +patchanim.filter.pnga = Png Files (*.png) patchanim.gifs = a series of GIFs +patchanim.filter.gifs = Gif Files (*.gif) patchanim.animatedgif = an Animated Gif +patchanim.filter.animatedgif = Gif Files (*.gif) +patchanim.mpeg = an MPEG +patchanim.filter.mpeg = MPEG Files (*.mpg) patchanim.quit = Quit patchanim.control = Controls patchanim.width = Width This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-30 02:04:38
|
Revision: 66 http://patchanim.svn.sourceforge.net/patchanim/?rev=66&view=rev Author: dbrosius Date: 2008-01-29 18:04:43 -0800 (Tue, 29 Jan 2008) Log Message: ----------- add an export listener so that a gui can show progress Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java 2008-01-30 02:04:43 UTC (rev 66) @@ -0,0 +1,25 @@ +package com.mebigfatguy.patchanim.gui.events; + +import java.util.EventObject; + +public class ExportEvent extends EventObject { + private static final long serialVersionUID = 2626267094073359857L; + + private int index; + private int total; + + public ExportEvent(Object src, int curImage, int totalImages) { + super(src); + index = curImage; + total = totalImages; + } + + public int getCurrentImage() { + return index; + } + + public int getTotalImages() { + return total; + } + +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java 2008-01-30 02:04:43 UTC (rev 66) @@ -0,0 +1,5 @@ +package com.mebigfatguy.patchanim.gui.events; + +public interface ExportListener { + public void imageExported(ExportEvent ee); +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-01-30 01:49:46 UTC (rev 65) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-01-30 02:04:43 UTC (rev 66) @@ -22,7 +22,9 @@ import java.io.File; import java.io.IOException; import java.text.NumberFormat; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.imageio.ImageIO; @@ -31,6 +33,8 @@ import com.mebigfatguy.patchanim.ExportType; import com.mebigfatguy.patchanim.OutOfBoundsColor; import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.gui.events.ExportEvent; +import com.mebigfatguy.patchanim.gui.events.ExportListener; import com.mebigfatguy.patchanim.surface.CombinedPatch; import com.mebigfatguy.patchanim.surface.PatchGenerator; @@ -38,6 +42,8 @@ private ExportType type; private File loc; private AnimatedGifEncoder agEncoder; + private int totalImages; + private Set<ExportListener> elisteners = new HashSet<ExportListener>(); public PatchExporter(ExportType exportType, File location) { type = exportType; @@ -48,6 +54,10 @@ agEncoder = null; } + public void addExportListener(ExportListener el) { + elisteners.add(el); + } + public void export(PatchAnimDocument document) throws IOException { try { String baseName = loc.getName(); @@ -62,8 +72,9 @@ agEncoder.start(new File(loc, baseName).getPath()); } + totalImages = calcImageCount(document); + BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight()); - List<CombinedPatch> patches = document.getPatches(); int lastPatch = patches.size() - 1; int tweenCount = document.getTweenCount(); @@ -71,6 +82,10 @@ int imageIndex = 1; AnimationType atype = document.getAnimationType(); + if (type == ExportType.AnimatedGif) { + agEncoder.setRepeat((atype != AnimationType.None) ? 0 : -1); + } + for(int p = 0; p < lastPatch; p++) { CombinedPatch startPatch = patches.get(p); CombinedPatch endPatch = patches.get(p+1); @@ -120,6 +135,23 @@ } else ImageIO.write(image, type.getExtension(), imageFile); + + fireExportEvent(index); } - + + private void fireExportEvent(int index) { + ExportEvent ee = new ExportEvent(this, index, totalImages); + for (ExportListener el : elisteners) { + el.imageExported(ee); + } + } + + private int calcImageCount(PatchAnimDocument document) { + int total = (document.getPatches().size() - 1) * document.getTweenCount() + 1; + + if (document.getAnimationType() == AnimationType.Wave) + total *= 2; + + return total; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-30 02:35:20
|
Revision: 67 http://patchanim.svn.sourceforge.net/patchanim/?rev=67&view=rev Author: dbrosius Date: 2008-01-29 18:35:25 -0800 (Tue, 29 Jan 2008) Log Message: ----------- add a progress bar on export Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ExportFrame.java Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ExportFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ExportFrame.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ExportFrame.java 2008-01-30 02:35:25 UTC (rev 67) @@ -0,0 +1,46 @@ +package com.mebigfatguy.patchanim.gui; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.util.ResourceBundle; + +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JProgressBar; +import javax.swing.SwingUtilities; + +import com.mebigfatguy.patchanim.gui.events.ExportEvent; +import com.mebigfatguy.patchanim.gui.events.ExportListener; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; + +public class ExportFrame extends JDialog implements ExportListener { + private static final long serialVersionUID = 3111097499092146056L; + private JProgressBar bar; + + public ExportFrame() { + initComponents(); + } + + private void initComponents() { + ResourceBundle rb = PatchAnimBundle.getBundle(); + Container cp = getContentPane(); + cp.setLayout(new BorderLayout(4, 4)); + bar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); + bar.setBorder(BorderFactory.createEmptyBorder(10, 50, 10, 50)); + cp.add(bar, BorderLayout.CENTER); + pack(); + setTitle(rb.getString(PatchAnimBundle.EXPORTINGFILE)); + Dimension d = getPreferredSize(); + } + + public void imageExported(final ExportEvent ee) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + bar.setMaximum(ee.getTotalImages()); + bar.setValue(ee.getCurrentImage()); + } + }); + } + +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ExportFrame.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-30 02:04:43 UTC (rev 66) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-30 02:35:25 UTC (rev 67) @@ -34,6 +34,7 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; import com.mebigfatguy.patchanim.ExportType; @@ -206,57 +207,25 @@ exportJpgsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - try { - File f = getExportLocation(ExportType.JPegs); - if (f != null) { - PatchExporter exporter = new PatchExporter(ExportType.JPegs, f); - exporter.export(document); - } - } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); - } + export(ExportType.JPegs); } }); exportPngsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - try { - File f = getExportLocation(ExportType.Pngs); - if (f != null) { - PatchExporter exporter = new PatchExporter(ExportType.Pngs, f); - exporter.export(document); - } - } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); - } + export(ExportType.Pngs); } }); exportGifsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - try { - File f = getExportLocation(ExportType.Gifs); - if (f != null) { - PatchExporter exporter = new PatchExporter(ExportType.Gifs, f); - exporter.export(document); - } - } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); - } + export(ExportType.Gifs); } }); exportAnimatedGifItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - try { - File f = getExportLocation(ExportType.AnimatedGif); - if (f != null) { - PatchExporter exporter = new PatchExporter(ExportType.AnimatedGif, f); - exporter.export(document); - } - } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); - } + export(ExportType.AnimatedGif); } }); @@ -396,5 +365,31 @@ return chooser.getSelectedFile(); } + + private void export(ExportType type) { + File f = getExportLocation(type); + if (f != null) { + final PatchExporter exporter = new PatchExporter(type, f); + final ExportFrame ed = new ExportFrame(); + ed.setLocationRelativeTo(JPatchAnimFrame.this); + ed.setVisible(true); + Thread t = new Thread(new Runnable() { + public void run() { + try { + exporter.addExportListener(ed); + exporter.export(document); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + ed.dispose(); + } + }); + } catch (IOException ioe) { + JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); + } + } + }); + t.start(); + } + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-30 02:04:43 UTC (rev 66) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-30 02:35:25 UTC (rev 67) @@ -40,6 +40,7 @@ public static final String ANIMATEDGIFFILTER = "patchanim.filter.animatedgif"; public static final String MPEG = "patchanim.mpeg"; public static final String MPEGFILTER = "patchanim.filter.mpeg"; + public static final String EXPORTINGFILE = "patchanim.exportfile"; public static final String QUIT = "patchanim.quit"; public static final String CONTROLS = "patchanim.control"; public static final String WIDTH = "patchanim.width"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-30 02:04:43 UTC (rev 66) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-30 02:35:25 UTC (rev 67) @@ -26,13 +26,14 @@ patchanim.jpgs = a series of JPGs patchanim.filter.jpgs = Files (*.jpg) patchanim.pngs = a series of PNGs -patchanim.filter.pnga = Png Files (*.png) +patchanim.filter.pngs = Png Files (*.png) patchanim.gifs = a series of GIFs patchanim.filter.gifs = Gif Files (*.gif) patchanim.animatedgif = an Animated Gif patchanim.filter.animatedgif = Gif Files (*.gif) patchanim.mpeg = an MPEG patchanim.filter.mpeg = MPEG Files (*.mpg) +patchanim.exportfile = Exporting Animation patchanim.quit = Quit patchanim.control = Controls patchanim.width = Width This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-01 07:43:46
|
Revision: 81 http://patchanim.svn.sourceforge.net/patchanim/?rev=81&view=rev Author: dbrosius Date: 2008-01-31 23:43:51 -0800 (Thu, 31 Jan 2008) Log Message: ----------- add lighten patch and darken patch commands to the context menu Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-31 22:45:25 UTC (rev 80) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-01 07:43:51 UTC (rev 81) @@ -217,10 +217,41 @@ } } }); + setAllItem.add(valueItem); + JMenuItem lightenPatch = new JMenuItem(rb.getString(PatchAnimBundle.LIGHTENPATCH)); + lightenPatch.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + deltaAllPts(10.0); + } + }); + + menu.add(lightenPatch); + JMenuItem darkenPatch = new JMenuItem(rb.getString(PatchAnimBundle.DARKENPATCH)); + darkenPatch.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + deltaAllPts(-10.0); + } + }); + + menu.add(darkenPatch); menu.show(JPatchSamplePanel.this, me.getX(), me.getY()); } + private void deltaAllPts(double d) { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + CombinedPatch patch = mediator.getActivePatch(); + PatchCoords coords = patch.getPatch(color); + for (int i = 0; i < PatchCoords.ORDER; i++) { + for (int j = 0; j < PatchCoords.ORDER; j++) { + Coordinate c = coords.getCoordinate(i, j); + c.setColor(c.getColor() + d); + coords.setCoordinate(i, j, c); + } + } + mediator.setNewActivePatch(patch); + } + private void setAllPts(double d) { PatchPanelMediator mediator = PatchPanelMediator.getMediator(); CombinedPatch patch = mediator.getActivePatch(); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-31 22:45:25 UTC (rev 80) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-01 07:43:51 UTC (rev 81) @@ -62,6 +62,8 @@ public static final String BLACK = "patchanim.black"; public static final String FULLCOLOR="patchanim.fullcolor"; public static final String VALUE="patchanim.value"; + public static final String LIGHTENPATCH = "patchanim.lightenpatch"; + public static final String DARKENPATCH = "patchanim.darkenpatch"; public static final String ASKSAVE = "patchanim.asksave"; public static final String LOADFAILED = "patchanim.err.loadfailed"; public static final String SAVEFAILED = "patchanim.err.savefailed"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-31 22:45:25 UTC (rev 80) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-01 07:43:51 UTC (rev 81) @@ -55,6 +55,8 @@ patchanim.black = Black patchanim.fullcolor = Full Color patchanim.value = Value... +patchanim.lightenpatch = Lighten Patch +patchanim.darkenpatch = Darken Patch patchanim.asksave = Do you want to save your changes? patchanim.err.savefailed = Failed saving Patch Animation File patchanim.err.loadfailed = Failed loading Patch Animation File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-01 08:02:13
|
Revision: 82 http://patchanim.svn.sourceforge.net/patchanim/?rev=82&view=rev Author: dbrosius Date: 2008-02-01 00:02:15 -0800 (Fri, 01 Feb 2008) Log Message: ----------- add copy patch from to patch context menu Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-01 07:43:51 UTC (rev 81) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-01 08:02:15 UTC (rev 82) @@ -224,20 +224,67 @@ public void actionPerformed(ActionEvent ae) { deltaAllPts(10.0); } - }); - + }); menu.add(lightenPatch); + JMenuItem darkenPatch = new JMenuItem(rb.getString(PatchAnimBundle.DARKENPATCH)); darkenPatch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { deltaAllPts(-10.0); } }); + menu.add(darkenPatch); + + JMenu copy = new JMenu(rb.getString(PatchAnimBundle.COPYPATCHFROM)); + if (color != PatchColor.Red) { + JMenuItem copyRed = new JMenuItem(rb.getString(PatchAnimBundle.REDPATCH)); + copyRed.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + copyPatch(PatchColor.Red); + } + }); + copy.add(copyRed); + } + if (color != PatchColor.Green) { + JMenuItem copyGreen = new JMenuItem(rb.getString(PatchAnimBundle.GREENPATCH)); + copyGreen.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + copyPatch(PatchColor.Green); + } + }); + copy.add(copyGreen); + } + if (color != PatchColor.Blue) { + JMenuItem copyBlue = new JMenuItem(rb.getString(PatchAnimBundle.BLUEPATCH)); + copyBlue.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + copyPatch(PatchColor.Blue); + } + }); + copy.add(copyBlue); + } - menu.add(darkenPatch); + menu.add(copy); menu.show(JPatchSamplePanel.this, me.getX(), me.getY()); } + private void copyPatch(PatchColor copyColor) { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + CombinedPatch patch = mediator.getActivePatch(); + PatchCoords srcCoords = patch.getPatch(copyColor); + PatchCoords dstCoords = patch.getPatch(color); + for (int i = 0; i < PatchCoords.ORDER; i++) { + for (int j = 0; j < PatchCoords.ORDER; j++) { + Coordinate srcCoord = srcCoords.getCoordinate(i, j); + double value = srcCoord.getColor(); + Coordinate dstCoord = dstCoords.getCoordinate(i, j); + dstCoord.setColor(value); + } + } + mediator.setNewActivePatch(patch); + + } + private void deltaAllPts(double d) { PatchPanelMediator mediator = PatchPanelMediator.getMediator(); CombinedPatch patch = mediator.getActivePatch(); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-01 07:43:51 UTC (rev 81) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-01 08:02:15 UTC (rev 82) @@ -64,6 +64,10 @@ public static final String VALUE="patchanim.value"; public static final String LIGHTENPATCH = "patchanim.lightenpatch"; public static final String DARKENPATCH = "patchanim.darkenpatch"; + public static final String COPYPATCHFROM = "patchanim.copypatchfrom"; + public static final String REDPATCH = "patchanim.redpatch"; + public static final String GREENPATCH = "patchanim.greenpatch"; + public static final String BLUEPATCH = "patchanim.bluepatch"; public static final String ASKSAVE = "patchanim.asksave"; public static final String LOADFAILED = "patchanim.err.loadfailed"; public static final String SAVEFAILED = "patchanim.err.savefailed"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-01 07:43:51 UTC (rev 81) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-01 08:02:15 UTC (rev 82) @@ -57,6 +57,10 @@ patchanim.value = Value... patchanim.lightenpatch = Lighten Patch patchanim.darkenpatch = Darken Patch +patchanim.copypatchfrom = Copy patch from... +patchanim.redpatch = Red Patch +patchanim.greenpatch = Green Patch +patchanim.bluepatch = Blue Patch patchanim.asksave = Do you want to save your changes? patchanim.err.savefailed = Failed saving Patch Animation File patchanim.err.loadfailed = Failed loading Patch Animation File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-01 08:14:30
|
Revision: 83 http://patchanim.svn.sourceforge.net/patchanim/?rev=83&view=rev Author: dbrosius Date: 2008-02-01 00:14:28 -0800 (Fri, 01 Feb 2008) Log Message: ----------- javadoc Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java 2008-02-01 08:02:15 UTC (rev 82) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java 2008-02-01 08:14:28 UTC (rev 83) @@ -22,11 +22,22 @@ import com.mebigfatguy.patchanim.main.PatchAnimBundle; +/** + * denotes the way animations progress through the series of images. + * <ul> + * <li><b>None</b> Animation progress from start to finish and then stops</li> + * <li><b>Cycle</b> Animation progress from start to finish and then from finish to start, and repeats</li> + * <li><b>None</b> Animation progress from start to finish and then repeats</li> + * </ul> + */ public enum AnimationType { None, Cycle, Wave; + /** + * returns the localized value of the type + */ @Override public String toString() { ResourceBundle rb = PatchAnimBundle.getBundle(); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java 2008-02-01 08:02:15 UTC (rev 82) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/ExportType.java 2008-02-01 08:14:28 UTC (rev 83) @@ -2,6 +2,16 @@ import com.mebigfatguy.patchanim.main.PatchAnimBundle; +/** + * denotes the type of file to export to + * <ul> + * <li><b>JPegs</b> a series of jpeg files in a directory</li> + * <li><b>Pngs</b> a series of Png files in a directory</li> + * <li><b>Gifs</b> a series of Gif files in a directory</li> + * <li><b>AnimatedGif</b> an animated gif file</li> + * <li><b>Mpeg</b> an animated mpeg file</li> + * </ul> + */ public enum ExportType { JPegs("jpg", true, PatchAnimBundle.JPGSERIESFILTER), Pngs("png", true, PatchAnimBundle.PNGSERIESFILTER), @@ -13,20 +23,38 @@ private boolean multi; private String key; + /** + * constructs an ExportType enum + * @param extension the file extension used for this type + * @param multipleFiles whether or not this file type generates multiple files + * @param descriptionKey the resource bundle key for the display value + */ private ExportType(String extension, boolean multipleFiles, String descriptionKey) { ext = extension; multi = multipleFiles; key = descriptionKey; } + /** + * returns the file extension for this export type + * @return the file extension + */ public String getExtension() { return ext; } + /** + * returns whether or not this file type generates multiple files + * @return whether the export generates multiple files + */ public boolean isMultipleFiles() { return multi; } + /** + * returns the resource bundle key for the localized value + * @return the resource key + */ public String getDescriptionKey() { return key; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-03 00:28:46
|
Revision: 88 http://patchanim.svn.sourceforge.net/patchanim/?rev=88&view=rev Author: dbrosius Date: 2008-02-02 16:28:51 -0800 (Sat, 02 Feb 2008) Log Message: ----------- title the list panel, and size the ctrl and list panels width the same Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-02-03 00:10:34 UTC (rev 87) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-02-03 00:28:51 UTC (rev 88) @@ -23,6 +23,7 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.JComponent; import javax.swing.JPanel; import com.mebigfatguy.patchanim.PatchColor; @@ -55,8 +56,11 @@ p = new JPanel(); p.setLayout(new BorderLayout(4, 4)); - p.add(new JPatchListPanel(), BorderLayout.WEST); + JPanel listPanel = new JPatchListPanel(); + p.add(listPanel, BorderLayout.WEST); + Utils.sizeUniformly(new JComponent[] { ctrl, listPanel }, Utils.Sizing.Width); + q = new JPanel(); { q.setLayout(new BoxLayout(q, BoxLayout.X_AXIS)); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 00:10:34 UTC (rev 87) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 00:28:51 UTC (rev 88) @@ -24,6 +24,7 @@ import java.awt.event.ActionListener; import java.util.ResourceBundle; +import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.ImageIcon; @@ -96,6 +97,8 @@ moveCtrls.add(downButton); moveCtrls.add(Box.createVerticalGlue()); add(moveCtrls, BorderLayout.EAST); + + setBorder(BorderFactory.createTitledBorder(rb.getString(PatchAnimBundle.PATCHES))); } private void initListeners() { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-03 00:10:34 UTC (rev 87) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-03 00:28:51 UTC (rev 88) @@ -43,6 +43,7 @@ public static final String EXPORTINGFILE = "patchanim.exportfile"; public static final String QUIT = "patchanim.quit"; public static final String CONTROLS = "patchanim.control"; + public static final String PATCHES = "patchanim.patches"; public static final String WIDTH = "patchanim.width"; public static final String HEIGHT = "patchanim.height"; public static final String ANIMATION = "patchanim.animation"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-03 00:10:34 UTC (rev 87) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-03 00:28:51 UTC (rev 88) @@ -36,6 +36,7 @@ patchanim.exportfile = Exporting Animation patchanim.quit = Quit patchanim.control = Controls +patchanim.patches = Patches patchanim.width = Width patchanim.height = Height patchanim.animation = Animation Repeat This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-03 00:52:41
|
Revision: 89 http://patchanim.svn.sourceforge.net/patchanim/?rev=89&view=rev Author: dbrosius Date: 2008-02-02 16:52:44 -0800 (Sat, 02 Feb 2008) Log Message: ----------- allow for named patches, and fix error messages Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-02-03 00:28:51 UTC (rev 88) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-02-03 00:52:44 UTC (rev 89) @@ -137,7 +137,8 @@ dispose(); System.exit(0); } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); } } }); @@ -158,7 +159,8 @@ documentLocation = null; saveItem.setEnabled(false); } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); } } }); @@ -176,7 +178,8 @@ } load(); } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.LOADFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.LOADFAILED)); } } }); @@ -190,7 +193,8 @@ save(); } } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); } } }); @@ -200,7 +204,8 @@ try { saveAs(); } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); } } }); @@ -243,7 +248,8 @@ dispose(); System.exit(0); } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); } } }); @@ -289,7 +295,8 @@ document = PatchAnimIO.loadFile(documentLocation); } } catch (Exception e) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); documentLocation = null; document = new PatchAnimDocument(); } finally { @@ -384,7 +391,8 @@ } }); } catch (IOException ioe) { - JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED); + ResourceBundle rb = PatchAnimBundle.getBundle(); + JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.EXPORTFAILED)); } } }); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 00:28:51 UTC (rev 88) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 00:52:44 UTC (rev 89) @@ -22,6 +22,8 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ResourceBundle; import javax.swing.BorderFactory; @@ -31,6 +33,7 @@ import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JList; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; @@ -192,6 +195,27 @@ } } }); + + patchList.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent me) { + ResourceBundle rb = PatchAnimBundle.getBundle(); + if (me.getClickCount() == 2) { + CombinedPatch patch = (CombinedPatch)patchList.getSelectedValue(); + if (patch != null) { + String newName = JOptionPane.showInputDialog(JPatchListPanel.this, rb.getString(PatchAnimBundle.ENTERNEWPATCHNAME), patch.getName()); + if (newName != null) { + patch.setName(newName); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.getDocument().setDirty(true); + patchList.invalidate(); + patchList.revalidate(); + patchList.repaint(); + } + } + } + } + }); } private void enabledMovementCtrls() { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-03 00:28:51 UTC (rev 88) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-03 00:52:44 UTC (rev 89) @@ -56,6 +56,8 @@ public static final String TWEENFRAMES = "patchanim.tween"; public static final String TEST = "patchanim.test"; public static final String STOP = "patchanim.stop"; + public static final String DEFAULTPATCHNAME = "patchanim.defaultpatchname"; + public static final String ENTERNEWPATCHNAME = "patchanim.enternewpatchname"; public static final String ADD = "patchanim.add"; public static final String REMOVE = "patchanim.remove"; public static final String COLOR = "patchanim.color"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-03 00:28:51 UTC (rev 88) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-03 00:52:44 UTC (rev 89) @@ -49,6 +49,8 @@ patchanim.tween = In-between frames patchanim.test = Test patchanim.stop = Stop +patchanim.defaultpatchname = Patch Coordinates +patchanim.enternewpatchname = Rename Patch to patchanim.add = Add patchanim.remove = Remove patchanim.color = Color Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-02-03 00:28:51 UTC (rev 88) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-02-03 00:52:44 UTC (rev 89) @@ -20,13 +20,16 @@ import java.io.Serializable; import java.util.EnumMap; +import java.util.ResourceBundle; import com.mebigfatguy.patchanim.PatchColor; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; public class CombinedPatch implements Serializable { - private static final long serialVersionUID = 8732763987020552187L; + private static final long serialVersionUID = 3521025714125245036L; private EnumMap<PatchColor, PatchCoords> patches = new EnumMap<PatchColor, PatchCoords>(PatchColor.class); + private String name; public CombinedPatch(boolean init) { if (init) { @@ -38,6 +41,8 @@ patches.put(PatchColor.Green, new PatchCoords()); patches.put(PatchColor.Blue, new PatchCoords()); } + ResourceBundle rb = PatchAnimBundle.getBundle(); + name = rb.getString(PatchAnimBundle.DEFAULTPATCHNAME); } public CombinedPatch(PatchCoords redPatch, PatchCoords greenPatch, PatchCoords bluePatch) { @@ -74,8 +79,15 @@ patches.put(color, coords); } + public String getName() { + return name; + } + + public void setName(String patchName) { + name = patchName; + } @Override public String toString() { - return "Patch Coordinates"; + return name; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-03 01:32:08
|
Revision: 93 http://patchanim.svn.sourceforge.net/patchanim/?rev=93&view=rev Author: dbrosius Date: 2008-02-02 17:32:12 -0800 (Sat, 02 Feb 2008) Log Message: ----------- add clone to the list context menu Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 01:11:24 UTC (rev 92) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 01:32:12 UTC (rev 93) @@ -33,8 +33,10 @@ import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JList; +import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; @@ -215,9 +217,40 @@ } } } + + @Override + public void mousePressed(MouseEvent me) { + if (me.isPopupTrigger()) { + showPatchListMenu(me); + } + } + + @Override + public void mouseReleased(MouseEvent me) { + if (me.isPopupTrigger()) { + showPatchListMenu(me); + } + } }); } + private void showPatchListMenu(MouseEvent me) { + ResourceBundle rb = PatchAnimBundle.getBundle(); + JPopupMenu patchMenu = new JPopupMenu(); + JMenuItem cloneItem = new JMenuItem(rb.getString(PatchAnimBundle.CLONE)); + cloneItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + int selIndex = patchList.getSelectedIndex(); + CombinedPatch patch = (CombinedPatch)patchListModel.getElementAt(selIndex); + CombinedPatch newPatch = (CombinedPatch)patch.clone(); + patchListModel.add(selIndex + 1, newPatch); + patchList.setSelectedIndex(selIndex + 1); + } + }); + patchMenu.add(cloneItem); + patchMenu.show(JPatchListPanel.this, me.getX(), me.getY()); + } + private void enabledMovementCtrls() { int selIndex = patchList.getSelectedIndex(); int lastIndex = patchListModel.getSize() - 1; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-03 01:11:24 UTC (rev 92) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-03 01:32:12 UTC (rev 93) @@ -60,6 +60,7 @@ public static final String ENTERNEWPATCHNAME = "patchanim.enternewpatchname"; public static final String ADD = "patchanim.add"; public static final String REMOVE = "patchanim.remove"; + public static final String CLONE = "patchanim.clone"; public static final String COLOR = "patchanim.color"; public static final String SETALLPOINTS = "patchanim.setallpoints"; public static final String BLACK = "patchanim.black"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-03 01:11:24 UTC (rev 92) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-03 01:32:12 UTC (rev 93) @@ -53,6 +53,7 @@ patchanim.enternewpatchname = Rename Patch to patchanim.add = Add patchanim.remove = Remove +patchanim.clone = Clone patchanim.color = Color patchanim.setallpoints = Set all control points to... patchanim.black = Black Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-02-03 01:11:24 UTC (rev 92) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-02-03 01:32:12 UTC (rev 93) @@ -20,12 +20,13 @@ import java.io.Serializable; import java.util.EnumMap; +import java.util.Map; import java.util.ResourceBundle; import com.mebigfatguy.patchanim.PatchColor; import com.mebigfatguy.patchanim.main.PatchAnimBundle; -public class CombinedPatch implements Serializable { +public class CombinedPatch implements Serializable, Cloneable { private static final long serialVersionUID = 3521025714125245036L; private EnumMap<PatchColor, PatchCoords> patches = new EnumMap<PatchColor, PatchCoords>(PatchColor.class); @@ -51,6 +52,18 @@ patches.put(PatchColor.Blue, bluePatch); } + @Override + public Object clone() { + try { + CombinedPatch clonedPatch = (CombinedPatch)super.clone(); + for (Map.Entry<PatchColor, PatchCoords> entry : patches.entrySet()) { + entry.setValue((PatchCoords)entry.getValue().clone()); + } + return clonedPatch; + } catch (CloneNotSupportedException cnse) { + return new CombinedPatch(true); + } + } public static CombinedPatch tween(CombinedPatch startPatch, CombinedPatch endPatch, double frac) { CombinedPatch tweenPatch = new CombinedPatch(false); { Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-02-03 01:11:24 UTC (rev 92) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-02-03 01:32:12 UTC (rev 93) @@ -22,7 +22,7 @@ import java.util.Arrays; import java.util.Random; -public class PatchCoords implements Serializable { +public class PatchCoords implements Serializable, Cloneable { private static final long serialVersionUID = -4052789167154764908L; public static final int ORDER = 4; @@ -48,6 +48,14 @@ coords = coordinates; } + @Override + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException cnse) { + return buildRandomPatch(); + } + } public static PatchCoords tween(PatchCoords startCoords, PatchCoords endCoords, double frac) { PatchCoords tweenCoords = new PatchCoords(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-12 04:24:14
|
Revision: 168 http://patchanim.svn.sourceforge.net/patchanim/?rev=168&view=rev Author: dbrosius Date: 2008-02-11 20:24:08 -0800 (Mon, 11 Feb 2008) Log Message: ----------- add some tooltips Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-02-11 04:16:56 UTC (rev 167) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-02-12 04:24:08 UTC (rev 168) @@ -77,6 +77,8 @@ widthLabel = new JLabel(rb.getString(PatchAnimBundle.WIDTH)); widthField = new JTextField(new IntegerDocument(), "", 8); widthLabel.setLabelFor(widthField); + widthField.setToolTipText(rb.getString(PatchAnimBundle.WIDTH_TT)); + JPanel p = Utils.createFormPanel(widthLabel, widthField); Utils.limitPanelHeight(p, widthField); @@ -87,6 +89,7 @@ heightLabel = new JLabel(rb.getString(PatchAnimBundle.HEIGHT)); heightField = new JTextField(new IntegerDocument(), "", 8); heightLabel.setLabelFor(heightField); + heightField.setToolTipText(rb.getString(PatchAnimBundle.HEIGHT_TT)); JPanel p = Utils.createFormPanel(heightLabel, heightField); Utils.limitPanelHeight(p, heightField); @@ -99,6 +102,7 @@ AnimationType.Cycle, AnimationType.Wave }); animationLabel.setLabelFor(animationCB); + animationCB.setToolTipText(rb.getString(PatchAnimBundle.ANIMATION_TT)); JPanel p = Utils.createFormPanel(animationLabel, animationCB); Utils.limitPanelHeight(p, animationCB); @@ -109,6 +113,7 @@ outOfBoundsLabel = new JLabel(rb.getString(PatchAnimBundle.OUTOFBOUNDSCOLOR)); outOfBoundsColorCB = new JComboBox(new Object[] { OutOfBoundsColor.Clip, OutOfBoundsColor.Roll }); + outOfBoundsColorCB.setToolTipText(rb.getString(PatchAnimBundle.OUTOFBOUNDSCOLOR_TT)); outOfBoundsLabel.setLabelFor(outOfBoundsColorCB); JPanel p = Utils.createFormPanel(outOfBoundsLabel, outOfBoundsColorCB); Utils.limitPanelHeight(p, outOfBoundsColorCB); @@ -119,6 +124,7 @@ tweenFramesLabel = new JLabel(rb.getString(PatchAnimBundle.TWEENFRAMES)); tweenFramesField = new JTextField(new IntegerDocument(), "", 8); tweenFramesLabel.setLabelFor(tweenFramesField); + tweenFramesField.setToolTipText(rb.getString(PatchAnimBundle.TWEENFRAMES_TT)); JPanel p = Utils.createFormPanel(tweenFramesLabel, tweenFramesField); Utils.limitPanelHeight(p, tweenFramesField); add(p); @@ -126,6 +132,7 @@ add(Box.createVerticalStrut(5)); testButton = new JButton(rb.getString(PatchAnimBundle.TEST)); + testButton.setToolTipText(rb.getString(PatchAnimBundle.TEST_TT)); add(testButton); Utils.sizeUniformly(new JComponent[] { widthLabel, heightLabel, animationLabel, outOfBoundsLabel, tweenFramesLabel }, Utils.Sizing.Both); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-11 04:16:56 UTC (rev 167) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-12 04:24:08 UTC (rev 168) @@ -47,16 +47,22 @@ public static final String CONTROLS = "patchanim.control"; public static final String PATCHES = "patchanim.patches"; public static final String WIDTH = "patchanim.width"; + public static final String WIDTH_TT = "patchanim.tooltip.width"; public static final String HEIGHT = "patchanim.height"; + public static final String HEIGHT_TT = "patchanim.tooltip.height"; public static final String ANIMATION = "patchanim.animation"; + public static final String ANIMATION_TT = "patchanim.tooltip.animation"; public static final String NONE = "patchanim.none"; public static final String CYCLE = "patchanim.cycle"; public static final String WAVE = "patchanim.wave"; public static final String OUTOFBOUNDSCOLOR = "patchanim.outofboundscolor"; + public static final String OUTOFBOUNDSCOLOR_TT = "patchanim.tooltip.outofboundscolor"; public static final String CLIP = "patchanim.clip"; public static final String ROLL = "patchanim.roll"; public static final String TWEENFRAMES = "patchanim.tween"; + public static final String TWEENFRAMES_TT = "patchanim.tooltip.tween"; public static final String TEST = "patchanim.test"; + public static final String TEST_TT = "patchanim.tooltip.test"; public static final String STOP = "patchanim.stop"; public static final String DEFAULTPATCHNAME = "patchanim.defaultpatchname"; public static final String ENTERNEWPATCHNAME = "patchanim.enternewpatchname"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-11 04:16:56 UTC (rev 167) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-12 04:24:08 UTC (rev 168) @@ -40,16 +40,22 @@ patchanim.control = Controls patchanim.patches = Patches patchanim.width = Width +patchanim.tooltip.width = The width of the exported animation patchanim.height = Height +patchanim.tooltip.height = The height of the exported animation patchanim.animation = Animation Repeat +patchanim.tooltip.animation = The type of repetition that the animation uses patchanim.none = None patchanim.cycle = Cycle patchanim.wave = Wave patchanim.outofboundscolor = Out Of Bounds Color +patchanim.tooltip.outofboundscolor = How colors that are out of the range of 0 - 255 are handled patchanim.clip = Clip patchanim.roll = Roll patchanim.tween = In-between frames +patchanim.tooltip.tween = How many frames are generated as transitions from one patch to the next patchanim.test = Test +patchanim.tooltip.test = Test the animation using the export settings patchanim.stop = Stop patchanim.defaultpatchname = Patch Coordinates patchanim.enternewpatchname = Rename Patch to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-12 04:56:47
|
Revision: 172 http://patchanim.svn.sourceforge.net/patchanim/?rev=172&view=rev Author: dbrosius Date: 2008-02-11 20:56:52 -0800 (Mon, 11 Feb 2008) Log Message: ----------- rearrange package for encoders Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/APngEncoder.java trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/Chunk.java trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/MngEncoder.java trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/PngStream.java trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/APngEncoder.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/APngEncoder.java 2008-02-12 04:55:36 UTC (rev 171) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/APngEncoder.java 2008-02-12 04:56:52 UTC (rev 172) @@ -16,7 +16,7 @@ * 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.encoders; +package com.mebigfatguy.patchanim.encoders; import java.awt.image.BufferedImage; import java.io.BufferedOutputStream; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/Chunk.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/Chunk.java 2008-02-12 04:55:36 UTC (rev 171) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/Chunk.java 2008-02-12 04:56:52 UTC (rev 172) @@ -16,7 +16,7 @@ * 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.encoders; +package com.mebigfatguy.patchanim.encoders; import java.io.DataOutputStream; import java.io.IOException; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/MngEncoder.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/MngEncoder.java 2008-02-12 04:55:36 UTC (rev 171) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/MngEncoder.java 2008-02-12 04:56:52 UTC (rev 172) @@ -16,7 +16,7 @@ * 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.encoders; +package com.mebigfatguy.patchanim.encoders; import java.awt.image.BufferedImage; import java.io.BufferedOutputStream; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/PngStream.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/PngStream.java 2008-02-12 04:55:36 UTC (rev 171) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/encoders/PngStream.java 2008-02-12 04:56:52 UTC (rev 172) @@ -16,7 +16,7 @@ * 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.encoders; +package com.mebigfatguy.patchanim.encoders; public class PngStream { private static final int HEADERLENGTH = 8; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-02-12 04:55:36 UTC (rev 171) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-02-12 04:56:52 UTC (rev 172) @@ -29,8 +29,8 @@ import javax.imageio.ImageIO; import com.fmsware.gif.AnimatedGifEncoder; -import com.mebigfatguy.encoders.APngEncoder; -import com.mebigfatguy.encoders.MngEncoder; +import com.mebigfatguy.patchanim.encoders.APngEncoder; +import com.mebigfatguy.patchanim.encoders.MngEncoder; import com.mebigfatguy.patchanim.AnimationType; import com.mebigfatguy.patchanim.ExportType; import com.mebigfatguy.patchanim.OutOfBoundsColor; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-14 07:18:40
|
Revision: 185 http://patchanim.svn.sourceforge.net/patchanim/?rev=185&view=rev Author: dbrosius Date: 2008-02-13 23:18:45 -0800 (Wed, 13 Feb 2008) Log Message: ----------- allow for documents with user specified patch order Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsd trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsl trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimExtension.java trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-02-14 07:18:45 UTC (rev 185) @@ -29,9 +29,10 @@ */ public class PatchAnimDocument implements Serializable { - private static final long serialVersionUID = -587863884486252874L; + private static final long serialVersionUID = -7412254429829665944L; private boolean dirty; + private int order; private List<CombinedPatch> patches; private int width; private int height; @@ -42,9 +43,10 @@ /** * constructs a new document for the New menu item */ - public PatchAnimDocument() { + public PatchAnimDocument(int patchOrder) { + order = patchOrder; patches = new ArrayList<CombinedPatch>(); - CombinedPatch patch = new CombinedPatch(true); + CombinedPatch patch = new CombinedPatch(order, true); patches.add(patch); width = 200; height = 200; @@ -70,6 +72,14 @@ } /** + * returns the order of the bezier patch used for this document + * @return the order of the patch + */ + public int getOrder() { + return order; + } + + /** * retrieves a list of all the bezier patches * @return the list of all the bezier patches */ Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-02-14 07:18:45 UTC (rev 185) @@ -143,8 +143,9 @@ return; g.setColor(Color.yellow); - for (int u = 0; u < PatchCoords.ORDER; u++) { - for (int v = 0; v < PatchCoords.ORDER; v++) { + int order = coords.getOrder(); + for (int u = 0; u < order; u++) { + for (int v = 0; v < order; v++) { Coordinate c = coords.getCoordinate(u, v); if ((selectedXPt == u) && (selectedYPt == v)) { g.fillOval((int)(((c.getX() * (bounds.width - 5)) / 100.0) + bounds.x), @@ -210,8 +211,9 @@ int minU = 0; int minV = 0; - for (int u = 0; u < PatchCoords.ORDER; u++) { - for (int v = 0; v < PatchCoords.ORDER; v++) { + int order = coords.getOrder(); + for (int u = 0; u < order; u++) { + for (int v = 0; v < order; v++) { Coordinate c = coords.getCoordinate(u, v); double xSq = c.getX() - inputX; xSq *= xSq; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-02-14 07:18:45 UTC (rev 185) @@ -82,7 +82,7 @@ cp.setLayout(new BorderLayout(4, 4)); JPatchAnimPanel patchPanel = new JPatchAnimPanel(); - document = new PatchAnimDocument(); + document = new PatchAnimDocument(4); documentLocation = null; PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setDocument(document); @@ -171,6 +171,7 @@ newItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { + ResourceBundle rb = PatchAnimBundle.getBundle(); try { if (document.isDirty()) { int choice = askSave(); @@ -181,13 +182,28 @@ } } - document = new PatchAnimDocument(); + Integer choice = (Integer)JOptionPane.showInputDialog(JPatchAnimFrame.this, + rb.getString(PatchAnimBundle.SETORDER), + rb.getString(PatchAnimBundle.TITLE), + JOptionPane.QUESTION_MESSAGE, + new ImageIcon(JPatchAnimFrame.this.getIconImage()), + new Object[] { Integer.valueOf(3), + Integer.valueOf(4), + Integer.valueOf(5), + Integer.valueOf(6), + Integer.valueOf(7), + Integer.valueOf(8), + Integer.valueOf(9) }, + Integer.valueOf(4)); + if (choice == null) + choice = Integer.valueOf(4); + + document = new PatchAnimDocument(choice.intValue()); documentLocation = null; saveItem.setEnabled(false); PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setDocument(document); } catch (IOException ioe) { - ResourceBundle rb = PatchAnimBundle.getBundle(); JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.SAVEFAILED)); } } @@ -338,7 +354,7 @@ ResourceBundle rb = PatchAnimBundle.getBundle(); JOptionPane.showMessageDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.LOADFAILED)); documentLocation = null; - document = new PatchAnimDocument(); + document = new PatchAnimDocument(4); } finally { PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setDocument(document); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-14 07:18:45 UTC (rev 185) @@ -130,7 +130,8 @@ else selIndex++; - CombinedPatch newPatch = new CombinedPatch(true); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + CombinedPatch newPatch = new CombinedPatch(mediator.getDocument().getOrder(), true); patchListModel.add(selIndex, newPatch); patchList.setSelectedIndex(selIndex); removeButton.setEnabled(patchListModel.getSize() > 1); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-14 07:18:45 UTC (rev 185) @@ -286,8 +286,9 @@ CombinedPatch patch = mediator.getActivePatch(); PatchCoords srcCoords = patch.getPatch(copyColor); PatchCoords dstCoords = patch.getPatch(color); - for (int i = 0; i < PatchCoords.ORDER; i++) { - for (int j = 0; j < PatchCoords.ORDER; j++) { + int order = srcCoords.getOrder(); + for (int i = 0; i < order; i++) { + for (int j = 0; j < order; j++) { Coordinate srcCoord = srcCoords.getCoordinate(i, j); double value = srcCoord.getColor(); Coordinate dstCoord = dstCoords.getCoordinate(i, j); @@ -302,8 +303,9 @@ PatchPanelMediator mediator = PatchPanelMediator.getMediator(); CombinedPatch patch = mediator.getActivePatch(); PatchCoords coords = patch.getPatch(color); - for (int i = 0; i < PatchCoords.ORDER; i++) { - for (int j = 0; j < PatchCoords.ORDER; j++) { + int order = coords.getOrder(); + for (int i = 0; i < order; i++) { + for (int j = 0; j < order; j++) { Coordinate c = coords.getCoordinate(i, j); c.setColor(c.getColor() + d); coords.setCoordinate(i, j, c); @@ -316,8 +318,9 @@ PatchPanelMediator mediator = PatchPanelMediator.getMediator(); CombinedPatch patch = mediator.getActivePatch(); PatchCoords coords = patch.getPatch(color); - for (int i = 0; i < PatchCoords.ORDER; i++) { - for (int j = 0; j < PatchCoords.ORDER; j++) { + int order = coords.getOrder(); + for (int i = 0; i < order; i++) { + for (int j = 0; j < order; j++) { Coordinate c = coords.getCoordinate(i, j); c.setColor(d); coords.setCoordinate(i, j, c); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsd =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsd 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsd 2008-02-14 07:18:45 UTC (rev 185) @@ -29,6 +29,7 @@ <xsd:complexType name="SettingsClass"> <xsd:attribute name="animationType" type="AnimationTypeClass" use="required"/> <xsd:attribute name="height" type="xsd:integer" use="required"/> + <xsd:attribute name="order" type="xsd:positiveInteger" default="4"/> <xsd:attribute name="outOfBoundsColor" type="OutOfBoundsColorClass" use="required"/> <xsd:attribute name="tweenCount" type="xsd:integer" use="required"/> <xsd:attribute name="width" type="xsd:integer" use="required"/> @@ -77,7 +78,7 @@ </xsd:simpleType> <xsd:complexType name="PatchesClass"> <xsd:sequence> - <xsd:element maxOccurs="4" minOccurs="4" name="CombinedPatch" type="CombinedPatchClass"/> + <xsd:element maxOccurs="unbounded" minOccurs="1" name="CombinedPatch" type="CombinedPatchClass"/> </xsd:sequence> </xsd:complexType> <xsd:element name="PatchAnimDoc" type="PatchAnimDocClass"/> Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsl =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsl 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimDoc.xsl 2008-02-14 07:18:45 UTC (rev 185) @@ -37,6 +37,9 @@ <xsl:value-of select="pae:getVersion($ext)"/> </xsl:attribute> <Settings> + <xsl:attribute name="order"> + <xsl:value-of select="pae:getOrder($ext)"/> + </xsl:attribute> <xsl:attribute name="width"> <xsl:value-of select="pae:getWidth($ext)"/> </xsl:attribute> Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimExtension.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimExtension.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimExtension.java 2008-02-14 07:18:45 UTC (rev 185) @@ -34,7 +34,6 @@ import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.PatchColor; import com.mebigfatguy.patchanim.surface.Coordinate; -import com.mebigfatguy.patchanim.surface.PatchCoords; public class PatchAnimExtension { private static final String VERSION_URL = "/com/mebigfatguy/patchanim/io/Version.txt"; @@ -60,6 +59,10 @@ } } + public String getOrder(@SuppressWarnings("unused") ExpressionContext context) { + return String.valueOf(paDoc.getOrder()); + } + public String getWidth(@SuppressWarnings("unused") ExpressionContext context) { return String.valueOf(paDoc.getWidth()); } @@ -104,11 +107,11 @@ NodeList nl = new NodeList() { public int getLength() { - return PatchCoords.ORDER * PatchCoords.ORDER; + int order = paDoc.getOrder(); + return order * order; } public Node item(int index) { - // TODO Auto-generated method stub return d.createTextNode(String.valueOf(index)); } }; @@ -117,30 +120,24 @@ } public String getX(@SuppressWarnings("unused") ExpressionContext context, String color, Node patchIndexNode, Node coordIndexNode) { - PatchColor patchColor = PatchColor.valueOf(PatchColor.class, color); - int patchIndex = Integer.parseInt(patchIndexNode.getNodeValue()); - int coordIndex = Integer.parseInt(coordIndexNode.getNodeValue()); - - Coordinate coord = paDoc.getPatches().get(patchIndex).getPatch(patchColor).getCoordinate(coordIndex % PatchCoords.ORDER, coordIndex / PatchCoords.ORDER); - return String.valueOf(coord.getX()); + return String.valueOf(getCoordinate(color, patchIndexNode, coordIndexNode).getX()); } public String getY(@SuppressWarnings("unused") ExpressionContext context, String color, Node patchIndexNode, Node coordIndexNode) { - PatchColor patchColor = PatchColor.valueOf(PatchColor.class, color); - int patchIndex = Integer.parseInt(patchIndexNode.getNodeValue()); - int coordIndex = Integer.parseInt(coordIndexNode.getNodeValue()); - - Coordinate coord = paDoc.getPatches().get(patchIndex).getPatch(patchColor).getCoordinate(coordIndex % PatchCoords.ORDER, coordIndex / PatchCoords.ORDER); - return String.valueOf(coord.getY()); + return String.valueOf(getCoordinate(color, patchIndexNode, coordIndexNode).getY()); } public String getColor(@SuppressWarnings("unused") ExpressionContext context, String color, Node patchIndexNode, Node coordIndexNode) { + return String.valueOf(getCoordinate(color, patchIndexNode, coordIndexNode).getColor()); + } + + private Coordinate getCoordinate(String color, Node patchIndexNode, Node coordIndexNode) { PatchColor patchColor = PatchColor.valueOf(PatchColor.class, color); int patchIndex = Integer.parseInt(patchIndexNode.getNodeValue()); int coordIndex = Integer.parseInt(coordIndexNode.getNodeValue()); + int order = paDoc.getOrder(); - Coordinate coord = paDoc.getPatches().get(patchIndex).getPatch(patchColor).getCoordinate(coordIndex % PatchCoords.ORDER, coordIndex / PatchCoords.ORDER); - return String.valueOf(coord.getColor()); + return paDoc.getPatches().get(patchIndex).getPatch(patchColor).getCoordinate(coordIndex % order, coordIndex / order); } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchAnimIO.java 2008-02-14 07:18:45 UTC (rev 185) @@ -86,73 +86,18 @@ public static PatchAnimDocument loadFile(File f) throws IOException { InputStream xmlIs = null; - final PatchAnimDocument doc = new PatchAnimDocument(); - doc.getPatches().clear(); try { XMLReader reader = XMLReaderFactory.createXMLReader(); - reader.setContentHandler(new DefaultHandler() { - private static final String SETTINGS = "Settings"; - private static final String WIDTH = "width"; - private static final String HEIGHT = "height"; - private static final String ANIMATIONTYPE = "animationType"; - private static final String OUTOFBOUNDSCOLOR = "outOfBoundsColor"; - private static final String TWEENCOUNT = "tweenCount"; - private static final String COMBINEDPATCH = "CombinedPatch"; - private static final String PATCH = "Patch"; - private static final String COLOR = "color"; - private static final String COORDINATE = "Coordinate"; - private static final String X = "x"; - private static final String Y = "y"; - - private CombinedPatch cPatch = null; - private PatchCoords patchCoords = null; - private PatchColor patchColor = null; - private int coordIndex = 0; - - @Override - public void startElement(String uri, String localName, String qName, Attributes atts) { - if (SETTINGS.equals(localName)) { - doc.setWidth(Integer.parseInt(atts.getValue(WIDTH))); - doc.setHeight(Integer.parseInt(atts.getValue(HEIGHT))); - doc.setAnimationType(AnimationType.valueOf(AnimationType.class, atts.getValue(ANIMATIONTYPE))); - doc.setOutOfBoundsColor(OutOfBoundsColor.valueOf(OutOfBoundsColor.class, atts.getValue(OUTOFBOUNDSCOLOR))); - doc.setTweenCount(Integer.parseInt(atts.getValue(TWEENCOUNT))); - } else if (COMBINEDPATCH.equals(localName)) { - cPatch = new CombinedPatch(false); - } else if (PATCH.equals(localName)) { - patchCoords = new PatchCoords(); - patchColor = PatchColor.valueOf(PatchColor.class, atts.getValue(COLOR)); - } else if (COORDINATE.equals(localName)) { - Coordinate c = new Coordinate(Double.parseDouble(atts.getValue(X)), - Double.parseDouble(atts.getValue(Y)), - Double.parseDouble(atts.getValue(COLOR))); - patchCoords.setCoordinate(coordIndex / PatchCoords.ORDER, coordIndex % PatchCoords.ORDER, c); - coordIndex++; - c = null; - } - } - - @Override - public void endElement(String uri, String localName, String qName) { - if (COMBINEDPATCH.equals(localName)) { - doc.getPatches().add(cPatch); - cPatch = null; - } else if (PATCH.equals(localName)) { - cPatch.setPatch(patchColor, patchCoords); - patchColor = null; - patchCoords = null; - coordIndex = 0; - } - } - }); + PatchAnimDocContentHandler handler = new PatchAnimDocContentHandler(); + reader.setContentHandler(handler); xmlIs = new BufferedInputStream(new FileInputStream(f)); reader.setFeature("http://apache.org/xml/features/validation/schema", true); reader.setFeature("http://xml.org/sax/features/validation", true); reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", PatchAnimDocument.class.getResource(PATCHANIMDOC_SCHEMA).toString()); reader.parse(new InputSource(xmlIs)); - return doc; + return handler.getDocument(); } catch (IOException ioe) { throw ioe; } catch (Exception e) { @@ -163,4 +108,71 @@ Closer.close(xmlIs); } } + + static class PatchAnimDocContentHandler extends DefaultHandler { + private static final String SETTINGS = "Settings"; + private static final String ORDER = "order"; + private static final String WIDTH = "width"; + private static final String HEIGHT = "height"; + private static final String ANIMATIONTYPE = "animationType"; + private static final String OUTOFBOUNDSCOLOR = "outOfBoundsColor"; + private static final String TWEENCOUNT = "tweenCount"; + private static final String COMBINEDPATCH = "CombinedPatch"; + private static final String PATCH = "Patch"; + private static final String COLOR = "color"; + private static final String COORDINATE = "Coordinate"; + private static final String X = "x"; + private static final String Y = "y"; + + PatchAnimDocument doc = null; + + private CombinedPatch cPatch = null; + private PatchCoords patchCoords = null; + private PatchColor patchColor = null; + private int coordIndex = 0; + + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) { + if (SETTINGS.equals(localName)) { + int order = Integer.parseInt(atts.getValue(ORDER)); + doc = new PatchAnimDocument(order); + doc.getPatches().clear(); + doc.setWidth(Integer.parseInt(atts.getValue(WIDTH))); + doc.setHeight(Integer.parseInt(atts.getValue(HEIGHT))); + doc.setAnimationType(AnimationType.valueOf(AnimationType.class, atts.getValue(ANIMATIONTYPE))); + doc.setOutOfBoundsColor(OutOfBoundsColor.valueOf(OutOfBoundsColor.class, atts.getValue(OUTOFBOUNDSCOLOR))); + doc.setTweenCount(Integer.parseInt(atts.getValue(TWEENCOUNT))); + } else if (COMBINEDPATCH.equals(localName)) { + cPatch = new CombinedPatch(doc.getOrder(), false); + } else if (PATCH.equals(localName)) { + patchCoords = new PatchCoords(doc.getOrder()); + patchColor = PatchColor.valueOf(PatchColor.class, atts.getValue(COLOR)); + } else if (COORDINATE.equals(localName)) { + Coordinate c = new Coordinate(Double.parseDouble(atts.getValue(X)), + Double.parseDouble(atts.getValue(Y)), + Double.parseDouble(atts.getValue(COLOR))); + int order = doc.getOrder(); + patchCoords.setCoordinate(coordIndex % order, coordIndex / order, c); + coordIndex++; + c = null; + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (COMBINEDPATCH.equals(localName)) { + doc.getPatches().add(cPatch); + cPatch = null; + } else if (PATCH.equals(localName)) { + cPatch.setPatch(patchColor, patchCoords); + patchColor = null; + patchCoords = null; + coordIndex = 0; + } + } + + public PatchAnimDocument getDocument() { + return doc; + } + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-02-14 07:18:45 UTC (rev 185) @@ -45,6 +45,7 @@ public static final String EXPORTINGFILE = "patchanim.exportfile"; public static final String QUIT = "patchanim.quit"; public static final String CONTROLS = "patchanim.control"; + public static final String SETORDER = "patchanim.setorder"; public static final String PATCHES = "patchanim.patches"; public static final String WIDTH = "patchanim.width"; public static final String WIDTH_TT = "patchanim.tooltip.width"; Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-02-14 07:18:45 UTC (rev 185) @@ -38,6 +38,7 @@ patchanim.exportfile = Exporting Animation patchanim.quit = Quit patchanim.control = Controls +patchanim.setorder = Set the order of the patches to patchanim.patches = Patches patchanim.width = Width patchanim.tooltip.width = The width of the exported animation Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-02-14 07:18:45 UTC (rev 185) @@ -32,15 +32,15 @@ private EnumMap<PatchColor, PatchCoords> patches = new EnumMap<PatchColor, PatchCoords>(PatchColor.class); private String name; - public CombinedPatch(boolean init) { + public CombinedPatch(int order, boolean init) { if (init) { - patches.put(PatchColor.Red, PatchCoords.buildRandomPatch()); - patches.put(PatchColor.Green, PatchCoords.buildRandomPatch()); - patches.put(PatchColor.Blue, PatchCoords.buildRandomPatch()); + patches.put(PatchColor.Red, PatchCoords.buildRandomPatch(order)); + patches.put(PatchColor.Green, PatchCoords.buildRandomPatch(order)); + patches.put(PatchColor.Blue, PatchCoords.buildRandomPatch(order)); } else { - patches.put(PatchColor.Red, new PatchCoords()); - patches.put(PatchColor.Green, new PatchCoords()); - patches.put(PatchColor.Blue, new PatchCoords()); + patches.put(PatchColor.Red, new PatchCoords(order)); + patches.put(PatchColor.Green, new PatchCoords(order)); + patches.put(PatchColor.Blue, new PatchCoords(order)); } ResourceBundle rb = PatchAnimBundle.getBundle(); name = rb.getString(PatchAnimBundle.DEFAULTPATCHNAME); @@ -62,11 +62,11 @@ } return clonedPatch; } catch (CloneNotSupportedException cnse) { - return new CombinedPatch(true); + return new CombinedPatch(getPatch(PatchColor.Red).getOrder(), true); } } public static CombinedPatch tween(CombinedPatch startPatch, CombinedPatch endPatch, double frac) { - CombinedPatch tweenPatch = new CombinedPatch(false); + CombinedPatch tweenPatch = new CombinedPatch(startPatch.getPatch(PatchColor.Red).getOrder(), false); { PatchCoords sRedCoords = startPatch.getPatch(PatchColor.Red); PatchCoords eRedCoords = endPatch.getPatch(PatchColor.Red); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-02-14 07:18:45 UTC (rev 185) @@ -25,26 +25,27 @@ public class PatchCoords implements Serializable, Cloneable { private static final long serialVersionUID = -4052789167154764908L; - public static final int ORDER = 4; - + private int order; private Coordinate[][] coords; - public static PatchCoords buildRandomPatch() { - Coordinate[][] coords = new Coordinate[PatchCoords.ORDER][PatchCoords.ORDER]; + public static PatchCoords buildRandomPatch(int patchOrder) { + Coordinate[][] coords = new Coordinate[patchOrder][patchOrder]; Random r = new Random(); - for (int u = 0; u < PatchCoords.ORDER; u++) { - for (int v = 0; v < PatchCoords.ORDER; v++) { - coords[u][v] = new Coordinate((u * 100.0) / (PatchCoords.ORDER - 1), (v * 100.0) / (PatchCoords.ORDER - 1), r.nextInt(400) - 50); + for (int u = 0; u < patchOrder; u++) { + for (int v = 0; v < patchOrder; v++) { + coords[u][v] = new Coordinate((u * 100.0) / (patchOrder - 1), (v * 100.0) / (patchOrder - 1), r.nextInt(400) - 50); } } - return new PatchCoords(coords); + return new PatchCoords(patchOrder, coords); } - public PatchCoords() { - coords = new Coordinate[ORDER][ORDER]; + public PatchCoords(int patchOrder) { + order = patchOrder; + coords = new Coordinate[patchOrder][patchOrder]; } - public PatchCoords(Coordinate[][] coordinates) { + public PatchCoords(int patchOrder, Coordinate[][] coordinates) { + order = patchOrder; coords = coordinates; } @@ -52,22 +53,27 @@ public Object clone() { try { PatchCoords clonedCoords = (PatchCoords)super.clone(); - clonedCoords.coords = new Coordinate[ORDER][ORDER]; - for (int u = 0; u < PatchCoords.ORDER; u++) { - for (int v = 0; v < PatchCoords.ORDER; v++) { + clonedCoords.coords = new Coordinate[order][order]; + for (int u = 0; u < order; u++) { + for (int v = 0; v < order; v++) { clonedCoords.coords[u][v] = (Coordinate)coords[u][v].clone(); } } return clonedCoords; } catch (CloneNotSupportedException cnse) { - return buildRandomPatch(); + return buildRandomPatch(order); } } + + public int getOrder() { + return order; + } + public static PatchCoords tween(PatchCoords startCoords, PatchCoords endCoords, double frac) { - PatchCoords tweenCoords = new PatchCoords(); - for (int x = 0; x < ORDER; x++) { - for (int y = 0; y < ORDER; y++) { + PatchCoords tweenCoords = new PatchCoords(startCoords.getOrder()); + for (int x = 0; x < tweenCoords.order; x++) { + for (int y = 0; y < tweenCoords.order; y++) { Coordinate startC = startCoords.getCoordinate(x,y); Coordinate endC = endCoords.getCoordinate(x,y); int tweenColor = (int)(startC.getColor() + (endC.getColor() - startC.getColor()) * frac); Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-02-14 05:14:11 UTC (rev 184) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-02-14 07:18:45 UTC (rev 185) @@ -46,11 +46,12 @@ coords[0] = patch.getPatch(PatchColor.Red); coords[1] = patch.getPatch(PatchColor.Green); coords[2] = patch.getPatch(PatchColor.Blue); + int order = coords[0].getOrder(); double u; double v; - double[] uCoeffs = new double[PatchCoords.ORDER]; - double[] vCoeffs = new double[PatchCoords.ORDER]; + double[] uCoeffs = new double[order]; + double[] vCoeffs = new double[order]; double[] value = new double[3]; int[] iValue = new int[3]; @@ -67,8 +68,8 @@ value[0] = value[1] = value[2] = 0.0; - for (int i = 0; i < PatchCoords.ORDER; i++) { - for (int j = 0; j < PatchCoords.ORDER; j++) { + for (int j = 0; j < order; j++) { + for (int i = 0; i < order; i++) { double coeff = uCoeffs[i] * vCoeffs[j]; for (int k = 0; k < 3; k++) { value[k] += coords[k].getCoordinate(i, j).getColor() * coeff; @@ -108,11 +109,12 @@ int pixel = 0; PatchCoords coords = patch.getPatch(color); + int order = coords.getOrder(); double u; double v; - double[] uCoeffs = new double[PatchCoords.ORDER]; - double[] vCoeffs = new double[PatchCoords.ORDER]; + double[] uCoeffs = new double[order]; + double[] vCoeffs = new double[order]; int sampleSizeX = image.getWidth(); int sampleSizeY = image.getHeight(); @@ -126,8 +128,8 @@ buildCoefficients(u, uCoeffs); double value = 0.0; - for (int i = 0; i < PatchCoords.ORDER; i++) { - for (int j = 0; j < PatchCoords.ORDER; j++) { + for (int j = 0; j < order; j++) { + for (int i = 0; i < order; i++) { value += coords.getCoordinate(i, j).getColor() * uCoeffs[i] * vCoeffs[j]; } } @@ -178,16 +180,29 @@ } private static void buildCoefficients(double t, double[] coeffs) { - double t2 = t * t; - double t3 = t2 * t; + double tt = 1.0; + for (int i = 0; i < coeffs.length; i++) { + coeffs[i] = tt; + tt = tt * t; + } + double oneMinusT = 1.0 - t; - double oneMinusT2 = oneMinusT * oneMinusT; - double oneMinusT3 = oneMinusT2 * oneMinusT; + double oneMinusTT = 1.0; + for (int i = coeffs.length - 1; i >= 0; i--) { + coeffs[i] *= oneMinusTT; + oneMinusTT = oneMinusTT * oneMinusT; + } - coeffs[0] = oneMinusT3; - coeffs[1] = 3.0 * t * oneMinusT2; - coeffs[2] = 3.0 * t2 * oneMinusT; - coeffs[3] = t3; + for (int i = 0; i < coeffs.length; i++) { + coeffs[i] *= NChooseI.nChooseI(coeffs.length-1, i); + } } + static class NChooseI { + private static double[] factorial = { 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0 }; + + public static double nChooseI(int n, int i) { + return factorial[n]/(factorial[i] * factorial[n-i]); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |