[Patchanim-commit] SF.net SVN: patchanim: [2] trunk
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-01-25 03:57:31
|
Revision: 2 http://patchanim.svn.sourceforge.net/patchanim/?rev=2&view=rev Author: dbrosius Date: 2008-01-24 19:57:36 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Initial Import to svn Added Paths: ----------- trunk/patchanim/ trunk/patchanim/.classpath trunk/patchanim/.project trunk/patchanim/src/ trunk/patchanim/src/com/ trunk/patchanim/src/com/mebigfatguy/ trunk/patchanim/src/com/mebigfatguy/patchanim/ trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java trunk/patchanim/src/com/mebigfatguy/patchanim/PatchColor.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedListener.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedListener.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JCoordControl.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/PatchDecorator.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/Utils.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchMain.java trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties trunk/patchanim/src/com/mebigfatguy/patchanim/surface/ 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 Added: trunk/patchanim/.classpath =================================================================== --- trunk/patchanim/.classpath (rev 0) +++ trunk/patchanim/.classpath 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="classes"/> +</classpath> Added: trunk/patchanim/.project =================================================================== --- trunk/patchanim/.project (rev 0) +++ trunk/patchanim/.project 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>PatchAnim</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/AnimationType.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,25 @@ +/* + * 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; + +public enum AnimationType { + None, + Cycle, + Wave; +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/OutOfBoundsColor.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,24 @@ +/* + * 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; + +public enum OutOfBoundsColor { + Clip, + Roll; +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,103 @@ +/* + * 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; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import com.mebigfatguy.patchanim.surface.CombinedPatch; + +public class PatchAnimDocument implements Serializable { + + private boolean dirty; + private List<CombinedPatch> patches; + private int width; + private int height; + private AnimationType animationType; + private OutOfBoundsColor outOfBoundsColor; + private int tweenCount; + + public PatchAnimDocument() { + patches = new ArrayList<CombinedPatch>(); + CombinedPatch patch = new CombinedPatch(); + patches.add(patch); + width = 100; + height = 100; + animationType = AnimationType.Wave; + outOfBoundsColor = OutOfBoundsColor.Clip; + tweenCount = 10; + } + + public boolean getDirty() { + return dirty; + } + + public void setDirty(boolean isDirty) { + dirty = isDirty; + } + + public List<CombinedPatch> getPatches() { + return patches; + } + + public void setPatches(List<CombinedPatch> patches) { + this.patches = patches; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public AnimationType getAnimationType() { + return animationType; + } + + public void setAnimationType(AnimationType animationType) { + this.animationType = animationType; + } + + public OutOfBoundsColor getOutOfBoundsColor() { + return outOfBoundsColor; + } + + public void setOutOfBoundsColor(OutOfBoundsColor outOfBoundsColor) { + this.outOfBoundsColor = outOfBoundsColor; + } + + public int getTweenCount() { + return tweenCount; + } + + public void setTweenCount(int tweenCount) { + this.tweenCount = tweenCount; + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchColor.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchColor.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchColor.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,26 @@ +/* + * 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; + +public enum PatchColor { + Red, + Green, + Blue, + Combined; +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedEvent.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,36 @@ +/* + * 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.surface.CombinedPatch; + +public class ActivePatchChangedEvent extends EventObject { + private CombinedPatch patch; + + public ActivePatchChangedEvent(Object src, CombinedPatch activePatch) { + super(src); + patch = activePatch; + } + + public CombinedPatch getActivePatch() { + return patch; + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedListener.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedListener.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/ActivePatchChangedListener.java 2008-01-25 03:57:36 UTC (rev 2) @@ -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 ActivePatchChangedListener { + void activePatchChanged(ActivePatchChangedEvent apce); +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedEvent.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,36 @@ +/* + * 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 DocumentChangedEvent extends EventObject { + private PatchAnimDocument document; + + public DocumentChangedEvent(Object src, PatchAnimDocument d) { + super(src); + document = d; + } + + public PatchAnimDocument getDocument() { + return document; + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedListener.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedListener.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/DocumentChangedListener.java 2008-01-25 03:57:36 UTC (rev 2) @@ -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 DocumentChangedListener { + void documentChanged(DocumentChangedEvent dce); +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,144 @@ +/* + * 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.awt.BorderLayout; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.ResourceBundle; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +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; + +public class JColorControlPatchPanel extends JPanel implements PatchDecorator { + + private PatchCoords coords; + private PatchColor color; + private JPatchSamplePanel sample; + private JLabel colorLabel; + private JTextField colorField; + private int selectedU; + private int selectedV; + + public JColorControlPatchPanel(PatchColor c) { + color = c; + selectedU = 0; + selectedV = 0; + initComponents(); + initListeners(); + } + + private void initComponents() { + ResourceBundle rb = PatchAnimBundle.getBundle(); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + sample = new JPatchSamplePanel(color); + sample.setDecorator(this); + + colorLabel = new JLabel(rb.getString(PatchAnimBundle.COLOR)); + colorField = new JTextField(4); + + add(Box.createVerticalGlue()); + JPanel p = new JPanel(); + { + p.setLayout(new BorderLayout(4, 4)); + p.add(sample, BorderLayout.CENTER); + + JPanel south = new JPanel(); + south.setLayout(new BoxLayout(south, BoxLayout.X_AXIS)); + south.add(Box.createHorizontalGlue()); + south.add(colorLabel); + south.add(Box.createHorizontalStrut(5)); + south.add(colorField); + south.add(Box.createHorizontalGlue()); + p.add(south, BorderLayout.SOUTH); + } + add(p); + add(Box.createVerticalGlue()); + + setMaximumSize(getPreferredSize()); + } + + private void initListeners() { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + 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(); + } + }); + } + + private void setColorField() { + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + Coordinate coord = coords.getCoordinate(selectedU, selectedV); + colorField.setText(String.valueOf(coord.getColor())); + } + }); + } + + public void drawDecoration(Graphics2D g, Rectangle bounds) { + if (coords == null) + return; + + g.setColor(Color.black); + for (int u = 0; u < 4; u++) { + for (int v = 0; v < 4; v++) { + Coordinate c = coords.getCoordinate(u, v); + if ((selectedU == u) && (selectedV == v)) { + g.fillOval(((c.getX() * (bounds.width - 5)) / 100) + bounds.x, ((c.getY() * (bounds.height - 5)) / 100) + 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); + } + } + } + } + + public void click(Point p, Rectangle bounds) { + int newSelectedU = ((((p.x - bounds.x) * 100) / bounds.width) + 16) / 33; + int newSelectedV = ((((p.y - bounds.y) * 100) / bounds.height) + 16) / 33; + if ((newSelectedU != selectedU) || (newSelectedV != selectedV)) { + selectedU = newSelectedU; + selectedV = newSelectedV; + sample.repaint(); + setColorField(); + } + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JCoordControl.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JCoordControl.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JCoordControl.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,154 @@ +/* + * 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.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.awt.image.DataBuffer; +import java.awt.image.IndexColorModel; +import java.awt.image.WritableRaster; + +import javax.swing.JComponent; + +public class JCoordControl extends JComponent { + + private Color color; + private BufferedImage image; + private int lowVal; + private int hiVal; + private int firstCurVal; + private int secondCurVal; + private int[] xs = new int[3]; + private int[] ys = new int[3]; + + public JCoordControl(Color c) + { + color = c; + + 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(256, 1, BufferedImage.TYPE_BYTE_INDEXED, icm); + WritableRaster raster = image.getRaster(); + DataBuffer db = raster.getDataBuffer(); + for (int i = 0; i < 256; i++) { + db.setElem(i, i); + } + + Dimension d = new Dimension(100, 5); + setMinimumSize(d); + d = new Dimension(256, 20); + setPreferredSize(d); + lowVal = 0; + hiVal = 255; + firstCurVal = 255; + secondCurVal = 255; + + initListeners(); + setEnabled(true); + } + + public void initListeners() { + addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent me) { + if (inThumb()) { + + } else { + + } + } + }); + } + + public boolean inThumb() { + return false; + } + + public void setMinValue(int min) { + lowVal = min; + } + + public void setMaxValue(int max) { + hiVal = max; + } + + public void setFirstCurValue(int cur) { + firstCurVal = cur; + } + public void setSecondCurValue(int cur) { + secondCurVal = cur; + } + + @Override + public void paint(Graphics g) { + Color saveColor = g.getColor(); + try { + Rectangle bounds = getBounds(); + + g.drawImage(image, 0, 0, bounds.width, bounds.height, 0, 0, 256, 1, null); + g.setColor(Color.BLACK); + g.drawRect(0, 0, bounds.width, bounds.height); + + int pt = calcPt(firstCurVal, bounds); + xs[0] = Math.max(pt - 10, 1); + xs[1] = pt; + xs[2] = Math.min(pt + 10, bounds.width - 1); + + ys[0] = 0; + ys[1] = (bounds.height >> 1) - 2; + ys[2] = ys[0]; + g.setColor(Color.YELLOW); + g.fillPolygon(xs, ys, 3); + g.setColor(Color.BLACK); + g.drawPolygon(xs, ys, 3); + + pt = calcPt(secondCurVal, bounds); + ys[0] = bounds.height; + ys[1] = (bounds.height >> 1) + 2; + ys[2] = ys[0]; + g.setColor(Color.YELLOW); + g.fillPolygon(xs, ys, 3); + g.setColor(Color.BLACK); + g.drawPolygon(xs, ys, 3); + + + } finally { + g.setColor(saveColor); + } + } + + private int calcPt(int val, Rectangle bounds) { + double frac = ((double)(val - lowVal)) / ((double)(hiVal - lowVal)); + return (int)(bounds.width * frac + 0.49); + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,101 @@ +/* + * 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.awt.BorderLayout; +import java.awt.Container; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.ResourceBundle; + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; + +import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; +import com.mebigfatguy.patchanim.main.PatchMain; + +public class JPatchAnimFrame extends JFrame { + + private JMenuItem newItem; + private JMenuItem openItem; + private JMenuItem closeItem; + private JMenuItem saveItem; + private JMenuItem saveAsItem; + private JMenuItem quitItem; + private PatchAnimDocument document; + + + public JPatchAnimFrame() { + initComponents(); + initMenus(); + initListeners(); + } + + private void initComponents() { + ResourceBundle rb = PatchAnimBundle.getBundle(); + Container cp = getContentPane(); + cp.setLayout(new BorderLayout(4, 4)); + + JPatchAnimPanel patchPanel = new JPatchAnimPanel(); + document = new PatchAnimDocument(); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.setDocument(document); + + cp.add(patchPanel, BorderLayout.CENTER); + setTitle(rb.getString(PatchAnimBundle.TITLE)); + pack(); + } + + public void initMenus() { + ResourceBundle rb = PatchAnimBundle.getBundle(); + JMenuBar mb = new JMenuBar(); + JMenu fileMenu = new JMenu(rb.getString(PatchAnimBundle.FILE)); + newItem = new JMenuItem(rb.getString(PatchAnimBundle.NEW)); + 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)); + fileMenu.add(saveItem); + saveAsItem = new JMenuItem(rb.getString(PatchAnimBundle.SAVEAS)); + fileMenu.add(saveAsItem); + fileMenu.addSeparator(); + quitItem = new JMenuItem(rb.getString(PatchAnimBundle.QUIT)); + fileMenu.add(quitItem); + + mb.add(fileMenu); + + setJMenuBar(mb); + } + + private void initListeners() { + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + dispose(); + System.exit(0); + } + }); + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimPanel.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,92 @@ +/* + * 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.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 { + + private JPatchControlPanel ctrl; + private JPatchSamplePanel sample; + private JColorControlPatchPanel redPatch; + private JColorControlPatchPanel greenPatch; + private JColorControlPatchPanel bluePatch; + + public JPatchAnimPanel() { + initComponents(); + } + + private void initComponents() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + JPanel p = new JPanel(); + p.setLayout(new BorderLayout(4, 4)); + ctrl = new JPatchControlPanel(); + p.add(ctrl, BorderLayout.WEST); + sample = new JPatchSamplePanel(PatchColor.Combined); + JPanel q = new JPanel(); + q.setLayout(new BoxLayout(q, BoxLayout.X_AXIS)); + q.add(Box.createHorizontalGlue()); + q.add(sample); + q.add(Box.createHorizontalGlue()); + q.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); + p.add(q, BorderLayout.CENTER); + add(p); + + + p = new JPanel(); + p.setLayout(new BorderLayout(4, 4)); + p.add(new JPatchListPanel(), BorderLayout.WEST); + + 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); + + q.add(Box.createHorizontalGlue()); + q.add(redPatch); + q.add(Box.createHorizontalStrut(10)); + q.add(greenPatch); + q.add(Box.createHorizontalStrut(10)); + q.add(bluePatch); + q.add(Box.createHorizontalGlue()); + } + + p.add(q, BorderLayout.CENTER); + + p.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); + + add(p); + setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchControlPanel.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,142 @@ +/* + * 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.awt.Dimension; +import java.util.ResourceBundle; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.main.PatchAnimBundle; + +public class JPatchControlPanel extends JPanel { + + private PatchAnimDocument document; + private JTextField widthField; + private JTextField heightField; + private JComboBox animationCB; + private JComboBox outOfBoundsColorCB; + private JTextField tweenFramesField; + private JButton testButton; + + public JPatchControlPanel() { + initComponents(); + initListeners(); + } + + private void initComponents() { + ResourceBundle rb = PatchAnimBundle.getBundle(); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + setBorder(BorderFactory.createTitledBorder(rb.getString(PatchAnimBundle.CONTROLS))); + + JLabel widthLabel; + JLabel heightLabel; + JLabel animationLabel; + JLabel outOfBoundsLabel; + JLabel tweenFramesLabel; + + { + widthLabel = new JLabel(rb.getString(PatchAnimBundle.WIDTH)); + widthField = new JTextField(8); + JPanel p = Utils.createFormPanel(widthLabel, widthField); + + Utils.limitPanelHeight(p, widthField); + add(p); + } + add(Box.createVerticalStrut(5)); + { + heightLabel = new JLabel(rb.getString(PatchAnimBundle.HEIGHT)); + heightField = new JTextField(8); + JPanel p = Utils.createFormPanel(heightLabel, heightField); + + Utils.limitPanelHeight(p, heightField); + add(p); + } + 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) }); + JPanel p = Utils.createFormPanel(animationLabel, animationCB); + + Utils.limitPanelHeight(p, animationCB); + add(p); + } + add(Box.createVerticalStrut(5)); + { + outOfBoundsLabel = new JLabel(rb.getString(PatchAnimBundle.OUTOFBOUNDSCOLOR)); + outOfBoundsColorCB = new JComboBox(new Object[] { rb.getString(PatchAnimBundle.CLIP), + rb.getString(PatchAnimBundle.ROLL) }); + JPanel p = Utils.createFormPanel(outOfBoundsLabel, outOfBoundsColorCB); + Utils.limitPanelHeight(p, outOfBoundsColorCB); + add(p); + } + add(Box.createVerticalStrut(5)); + { + tweenFramesLabel = new JLabel(rb.getString(PatchAnimBundle.TWEENFRAMES)); + tweenFramesField = new JTextField(8); + JPanel p = Utils.createFormPanel(tweenFramesLabel, tweenFramesField); + Utils.limitPanelHeight(p, tweenFramesField); + add(p); + } + add(Box.createVerticalStrut(5)); + + testButton = new JButton(rb.getString(PatchAnimBundle.TEST)); + add(testButton); + + Utils.sizeUniformly(new JComponent[] { widthLabel, heightLabel, animationLabel, outOfBoundsLabel, tweenFramesLabel }, Utils.Sizing.Both); + Utils.sizeUniformly(new JComponent[] { widthField, heightField, animationCB, outOfBoundsColorCB, tweenFramesField }, Utils.Sizing.Width); + + add(Box.createVerticalGlue()); + + Dimension d = getPreferredSize(); + if (d.width < 200) + d.width = 200; + setPreferredSize(d); + } + + private void initListeners() { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.addDocumentChangedListener(new DocumentChangedListener() { + public void documentChanged(DocumentChangedEvent dce) { + document = dce.getDocument(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + widthField.setText(String.valueOf(document.getWidth())); + heightField.setText(String.valueOf(document.getHeight())); + animationCB.setSelectedIndex(document.getAnimationType().ordinal()); + outOfBoundsColorCB.setSelectedIndex(document.getOutOfBoundsColor().ordinal()); + tweenFramesField.setText(String.valueOf(document.getTweenCount())); + } + }); + } + }); + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,137 @@ +/* + * 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.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ResourceBundle; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import com.mebigfatguy.patchanim.main.PatchAnimBundle; +import com.mebigfatguy.patchanim.surface.CombinedPatch; + +public class JPatchListPanel extends JPanel { + private JList patchList; + private PatchListModel patchListModel; + private JButton addButton; + private JButton removeButton; + + public JPatchListPanel() { + initComponents(); + initListeners(); + } + + private void initComponents() { + ResourceBundle rb = PatchAnimBundle.getBundle(); + setLayout(new BorderLayout(4, 4)); + + patchListModel = new PatchListModel(); + patchList = new JList(patchListModel); + patchList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); + patchList.setPreferredSize(new Dimension(200, 300)); + add(new JScrollPane(patchList), BorderLayout.CENTER); + + JPanel modCtrls = new JPanel(); + modCtrls.setLayout(new BoxLayout(modCtrls, BoxLayout.X_AXIS)); + modCtrls.add(Box.createHorizontalGlue()); + + addButton = new JButton(rb.getString(PatchAnimBundle.ADD)); + removeButton = new JButton(rb.getString(PatchAnimBundle.REMOVE)); + removeButton.setEnabled(false); + Utils.sizeUniformly(new JComponent[] {addButton, removeButton}, Utils.Sizing.Both); + modCtrls.add(addButton); + modCtrls.add(Box.createHorizontalStrut(10)); + modCtrls.add(removeButton); + modCtrls.add(Box.createHorizontalGlue()); + add(modCtrls, BorderLayout.SOUTH); + } + + private void initListeners() { + final PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.addDocumentChangedListener(new DocumentChangedListener() { + public void documentChanged(final DocumentChangedEvent dce) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + patchList.setSelectedIndex(0); + patchListModel = new PatchListModel(dce.getDocument()); + patchList.setModel(patchListModel); + mediator.setNewActivePatch((CombinedPatch)patchListModel.getElementAt(0)); + } + }); + } + }); + + addButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + int selIndex = patchList.getSelectedIndex(); + if (selIndex < 0) + selIndex = patchListModel.getSize() - 1; + + CombinedPatch newPatch = new CombinedPatch(); + patchListModel.add(selIndex, newPatch); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.setNewActivePatch(newPatch); + removeButton.setEnabled(patchListModel.getSize() > 1); + patchList.setSelectedIndex(selIndex); + } + }); + + removeButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + int selIndex = patchList.getSelectedIndex(); + if (selIndex >= 0) { + patchListModel.remove(selIndex); + if (selIndex >= patchListModel.getSize()) { + selIndex--; + } + patchList.setSelectedIndex(selIndex); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.setNewActivePatch((CombinedPatch)patchListModel.getElementAt(selIndex)); + removeButton.setEnabled(patchListModel.getSize() > 1); + } + } + }); + + patchList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + int selIndex = patchList.getSelectedIndex(); + if (selIndex >= 0) { + CombinedPatch newPatch = (CombinedPatch)patchListModel.getElementAt(selIndex); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.setNewActivePatch(newPatch); + } + } + } + }); + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,122 @@ +/* + * 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.awt.Color; +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; + +import com.mebigfatguy.patchanim.PatchColor; + +public class JPatchSamplePanel extends JPanel { + private static final int SAMPLE_SIZE = 200; + private PatchColor color; + private Color rgb; + private BufferedImage image; + private PatchDecorator decorator; + + public JPatchSamplePanel(PatchColor c) { + color = c; + if (c == PatchColor.Red) + rgb = Color.red; + else if (c == PatchColor.Green) + rgb = Color.green; + else if (c == PatchColor.Blue) + rgb = Color.blue; + else + rgb = null; + + initComponents(); + initListeners(); + decorator = null; + } + + public void setDecorator(PatchDecorator patchDecorator) { + decorator = patchDecorator; + setEnabled(true); + } + + private void initComponents() { + buildImage(); + setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + Dimension d = new Dimension(SAMPLE_SIZE, SAMPLE_SIZE); + setMinimumSize(d); + setMaximumSize(d); + setPreferredSize(d); + } + + private void initListeners() { + addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent me) { + if (decorator != null) { + decorator.click(me.getPoint(), JPatchSamplePanel.this.getBounds()); + } + } + }); + } + + 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(); + g.drawImage(image, 0, 0, (int)bounds.getWidth(), (int)bounds.getHeight(), 0, 0, SAMPLE_SIZE, SAMPLE_SIZE, null); + Insets insets = getInsets(); + bounds.x += insets.left; + bounds.y += insets.top; + bounds.width -= (insets.left + insets.right) + 1; + bounds.height -= (insets.top + insets.bottom) + 1; + g.setColor(rgb); + g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); + if (decorator != null) + decorator.drawDecoration(((Graphics2D) g), g.getClipBounds()); + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,29 @@ +/* + * 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.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; + +public interface PatchDecorator { + void drawDecoration(Graphics2D g, Rectangle bounds); + + void click(Point p, Rectangle bounds); +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,78 @@ +/* + * 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.List; + +import javax.swing.AbstractListModel; + +import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.surface.CombinedPatch; + +public class PatchListModel extends AbstractListModel { + + private static final long serialVersionUID = -4980398874234658317L; + + private PatchAnimDocument doc; + + public PatchListModel() { + doc = null; + } + + public PatchListModel(PatchAnimDocument document) { + doc = document; + } + + public void add(int pos, CombinedPatch patch) { + if (doc == null) + return; + + List<CombinedPatch> patches = doc.getPatches(); + patches.add(patch); + doc.setDirty(true); + fireIntervalAdded(this, pos, pos); + } + + public void remove(int pos) { + if (doc == null) + return; + + List<CombinedPatch> patches = doc.getPatches(); + patches.remove(pos); + doc.setDirty(true); + fireIntervalRemoved(this, pos, pos); + } + + public Object getElementAt(int index) { + if (doc == null) + return null; + + List<CombinedPatch> patches = doc.getPatches(); + return patches.get(index); + } + + public int getSize() { + if (doc == null) + return 0; + + List<CombinedPatch> patches = doc.getPatches(); + return patches.size(); + } + +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,65 @@ +/* + * 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.HashSet; +import java.util.Set; + +import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.surface.CombinedPatch; + +public class PatchPanelMediator { + private static final PatchPanelMediator mediator = new PatchPanelMediator(); + + private PatchAnimDocument document; + private Set<DocumentChangedListener> dclisteners = new HashSet<DocumentChangedListener>(); + private Set<ActivePatchChangedListener> apclisteners = new HashSet<ActivePatchChangedListener>(); + + private PatchPanelMediator() { + } + + public static PatchPanelMediator getMediator() { + return mediator; + } + public void addDocumentChangedListener(DocumentChangedListener dcl) { + dclisteners.add(dcl); + } + + public void setDocument(PatchAnimDocument doc) { + document = doc; + DocumentChangedEvent dce = new DocumentChangedEvent(this, doc); + for (DocumentChangedListener dcl : dclisteners) { + dcl.documentChanged(dce); + } + } + + public void addActivePatchChangedListener(ActivePatchChangedListener apcl) { + apclisteners.add(apcl); + } + + public void setNewActivePatch(CombinedPatch patch) { + ActivePatchChangedEvent apce = new ActivePatchChangedEvent(this, patch); + for (ActivePatchChangedListener apcl : apclisteners) { + apcl.activePatchChanged(apce); + } + } + + + +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/Utils.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/Utils.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/Utils.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,85 @@ +/* + * 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.awt.BorderLayout; +import java.awt.Dimension; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class Utils { + public enum Sizing {Width, Height, Both}; + + private Utils() {} + + public static JPanel createFormPanel(JLabel label, JComponent component) { + JPanel p = new JPanel(); + p.setLayout(new BorderLayout(4, 4)); + label.setLabelFor(component); + p.add(label, BorderLayout.WEST); + p.add(component, BorderLayout.CENTER); + return p; + + } + + public static void limitPanelHeight(JPanel p, JComponent limitingComponent) { + Dimension ps = limitingComponent.getPreferredSize(); + Dimension ms = p.getMaximumSize(); + ms.height = ps.height; + p.setMaximumSize(ms); + } + + public static void sizeUniformly(JComponent[] components, Sizing sizing) { + int width = 0; + int height = 0; + + for (JComponent comp : components) { + Dimension d = comp.getPreferredSize(); + if (d.width > width) + width = d.width; + if (d.height > height) + height = d.height; + } + + for (JComponent comp : components) { + Dimension minD = comp.getMinimumSize(); + if (sizing != Sizing.Height) + minD.width = width; + if (sizing != Sizing.Width) + minD.height = height; + comp.setMinimumSize(minD); + + Dimension maxD = comp.getMaximumSize(); + if (sizing != Sizing.Height) + maxD.width = width; + if (sizing != Sizing.Width) + maxD.height = height; + comp.setMaximumSize(maxD); + + Dimension prefD = comp.getPreferredSize(); + if (sizing != Sizing.Height) + prefD.width = width; + if (sizing != Sizing.Width) + prefD.height = height; + comp.setPreferredSize(prefD); + } + } +} Added: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-25 03:57:36 UTC (rev 2) @@ -0,0 +1,60 @@ +/* + * 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.main; + +import java.util.ResourceBundle; + +public class PatchAnimBundle { + + public static final String TITLE = "patchanim.title"; + 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"; + public static final String CONTROLS = "patchanim.control"; + public static final String WIDTH = "patchanim.width"; + public static final String HEIGHT = "patchanim.height"; + public static final String ANIMATION = "patchanim.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 CLIP = "patchanim.clip"; + public static final String ROLL = "patchanim.roll"; + 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 ADD = "patchanim.add"; + public static final String REMOVE = "patchanim.remove"; + public static final String COLOR = "patchanim.color"; + + + ... [truncated message content] |