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