[Patchanim-commit] SF.net SVN: patchanim: [28] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
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. |