summaryrefslogtreecommitdiff
path: root/src/tesseract/newmenu/NewChainLinkMenuItem.java
diff options
context:
space:
mode:
authorPhillip <pacardon@u.washington.edu>2011-02-20 22:57:16 +0000
committerPhillip <pacardon@u.washington.edu>2011-02-20 22:57:16 +0000
commit3c7f3b099198d4ea36d498c349cad80f2a6937de (patch)
treee33275370ba5cf181a86ecd894046504c368064c /src/tesseract/newmenu/NewChainLinkMenuItem.java
parent972b0a6922d66ef28f048101e8026227a93eee36 (diff)
Fixed some checkstyle errors (added java doc)
Added new constructor to Ellipsoid.java to feed in a Mass, Radius and Position.
Diffstat (limited to 'src/tesseract/newmenu/NewChainLinkMenuItem.java')
-rw-r--r--src/tesseract/newmenu/NewChainLinkMenuItem.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/tesseract/newmenu/NewChainLinkMenuItem.java b/src/tesseract/newmenu/NewChainLinkMenuItem.java
new file mode 100644
index 0000000..59d0f53
--- /dev/null
+++ b/src/tesseract/newmenu/NewChainLinkMenuItem.java
@@ -0,0 +1,100 @@
+package tesseract.newmenu;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Set;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.vecmath.Vector3f;
+
+import tesseract.World;
+import tesseract.objects.ChainLink2;
+import tesseract.objects.Icosahedron;
+
+/**
+ * NewIcosahedronMenutItem
+ *
+ * Defines a menu item to add an ChainLink to the world.
+ * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan
+ *
+ * @author Phillip Cardon
+ */
+public class NewChainLinkMenuItem extends MenuItem {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1936364496102891064L;
+ //private static Map <String, Object> myParams;
+
+ /**
+ * Constructor.
+ * @param theWorld to add objects to.
+ */
+ public NewChainLinkMenuItem(final World theWorld) {
+ super(theWorld, "ChainLink(NEW)");
+ buildParams();
+ }
+
+ /**
+ * Adds Parameters for user input.
+ * Sets default text box text.
+ */
+ private void buildParams() {
+ myParameters.put("Diameter", new Float(0f));
+ myParameters.put("Length", new Float(0f));
+ myParameters.put("Width", new Float(0f));
+ this.makePanel();
+ myReadData.get("Diameter").setText(((Float)
+ ChainLink2.DEFAULT_DIAMETER_RATIO).toString());
+ myReadData.get("Length").setText(((Float)
+ ChainLink2.DEFAULT_LENGTH).toString());
+ myReadData.get("Width").setText(((Float)
+ ChainLink2.DEFAULT_WIDTH_RATIO).toString());
+ }
+
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ createParameterMenu();
+ final JCheckBox defaultButton = getDefaultButton();
+ final JFrame params = getParamFrame();
+ final JButton enterButton = getEnterButton();
+
+ defaultButton.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent e) {
+ if (defaultButton.isSelected()) {
+ myWorld.addObject(new ChainLink2(MenuItem.DEFAULT_POSITION,
+ MenuItem.DEFAULT_MASS));
+ params.dispose();
+ }
+ }
+ });
+ enterButton.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent event) {
+ Set<String> itr = myParameters.keySet();
+ for (String s : itr) {
+ Object o = myParameters.get(s);
+ String p = myReadData.get(s).getText();
+ if (o.getClass().equals(new Float(0f).getClass())) {
+ myParameters.put(s, new Float(Float.parseFloat(p)));
+ } else if (o.getClass().equals(new Vector3f().getClass())) {
+ myParameters.put(s, parseVector(p));
+ }
+
+ }
+ if (event.getSource() == enterButton) {
+ myWorld.addObject(
+ new ChainLink2((Vector3f) myParameters.get("Position"),
+ ((Float) myParameters.get("Mass")).floatValue(),
+ ((Float) myParameters.get("Diameter")).floatValue(),
+ ((Float) myParameters.get("Length")).floatValue(),
+ ((Float) myParameters.get("Width")).floatValue()));
+ params.dispose();
+ }
+ }
+ });
+
+ }
+}