summaryrefslogtreecommitdiff
path: root/src/tesseract/newmenu
diff options
context:
space:
mode:
authorPhillip <pacardon@u.washington.edu>2011-02-20 21:53:53 +0000
committerPhillip <pacardon@u.washington.edu>2011-02-20 21:53:53 +0000
commit1a68dca420fc432b2267ef786c040759d2ca50e2 (patch)
tree467a3d4e8936f732e4cc0fc6563d79848d409001 /src/tesseract/newmenu
parent5d737c42197d7f7c0e4d7a088bd99141481b5145 (diff)
Spelling corrections, added NewToroidMenuItem
Diffstat (limited to 'src/tesseract/newmenu')
-rw-r--r--src/tesseract/newmenu/MenuItem.java49
-rw-r--r--src/tesseract/newmenu/NewIcosahedronMenuItem.java37
-rw-r--r--src/tesseract/newmenu/NewToroidMenuItem.java108
3 files changed, 161 insertions, 33 deletions
diff --git a/src/tesseract/newmenu/MenuItem.java b/src/tesseract/newmenu/MenuItem.java
index 9f65958..1be137f 100644
--- a/src/tesseract/newmenu/MenuItem.java
+++ b/src/tesseract/newmenu/MenuItem.java
@@ -3,13 +3,10 @@ package tesseract.newmenu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
-import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
-import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -42,6 +39,11 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
* default position.
*/
protected static final Vector3f DEFAULT_POSITION = new Vector3f(0, 0, 0);
+
+ /**
+ *
+ */
+ protected static final float DEFAULT_MASS = 2f;
/**
* Jframe to hold panel.
*/
@@ -50,10 +52,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
* Jpanel for variable text boxes.
*/
private JPanel myPanel;
- /**
- * JTextFields.
- */
- private JTextField[] myFields;
+
/**
* Variable name/type mapping.
*/
@@ -88,17 +87,16 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
/**
* Constructor.
* @param theWorld world parameter.
+ * @param theLabel for menu item.
*/
- public MenuItem(final World theWorld, String theLabel) {
+ public MenuItem(final World theWorld, final String theLabel) {
super(theLabel);
myFrame = new JFrame();
myParameters = new HashMap<String, Object>();
myPanel = new JPanel();
-
- myFields = new JTextField[myParameters.keySet().size()];
myReadData = new HashMap <String, JTextField>();
myWorld = theWorld;
- myParameters.put("Positon", new Vector3f());
+ myParameters.put("Position", new Vector3f());
myParameters.put("Mass", new Float(0f));
addActionListener(this);
}
@@ -108,17 +106,17 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
*/
protected void makePanel() {
Set<String> varNames = myParameters.keySet();
- myFields = new JTextField[myParameters.keySet().size()];
myPanel.setLayout(new GridLayout(myParameters.size(), 2));
- int i = 0;
for (String s : varNames) {
- myFields[i] = new JTextField();
myPanel.add(new JLabel(s));
- myPanel.add(myFields[i]);
- myReadData.put(s, myFields[i]);
- i++;
+ myReadData.put(s, new JTextField());
+ myPanel.add(myReadData.get(s));
}
- //myPanel = new JPanel(new GridLayout(myParameters.keySet().size(), 2));
+ myReadData.get("Position").setText(
+ MenuItem.DEFAULT_POSITION.toString().substring(1,
+ MenuItem.DEFAULT_POSITION.toString().length() - 1));
+ myReadData.get("Mass").setText(((Float)
+ MenuItem.DEFAULT_MASS).toString());
}
/**
@@ -164,7 +162,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
/**
*
- * @return
+ * @return Default Button
*/
public JCheckBox getDefaultButton() {
return myDefaultButton;
@@ -172,7 +170,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
/**
*
- * @return
+ * @return enter button
*/
public JButton getEnterButton() {
return myEnterButton;
@@ -180,7 +178,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
/**
*
- * @return
+ * @return parameter frame
*/
public JFrame getParamFrame() {
return myParamFrame;
@@ -194,6 +192,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
* @author Jesse Morgan, Steve Bradshaw
*/
protected Vector3f parseVector(final String input) {
+
String[] split = input.split(",");
float x = Float.parseFloat(split[0]);
@@ -203,10 +202,18 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
return new Vector3f(x, y, z);
}
+ /**
+ *
+ * @return position from vector.
+ */
protected Vector3f getPosition() {
return (Vector3f) myParameters.get("Position");
}
+ /**
+ *
+ * @return mass.
+ */
protected float getMass() {
return ((Float) myParameters.get("Mass")).floatValue();
}
diff --git a/src/tesseract/newmenu/NewIcosahedronMenuItem.java b/src/tesseract/newmenu/NewIcosahedronMenuItem.java
index 910b834..4123486 100644
--- a/src/tesseract/newmenu/NewIcosahedronMenuItem.java
+++ b/src/tesseract/newmenu/NewIcosahedronMenuItem.java
@@ -2,10 +2,6 @@ package tesseract.newmenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
import javax.swing.JButton;
@@ -25,30 +21,42 @@ import tesseract.objects.Icosahedron;
* @author Phillip Cardon
*/
public class NewIcosahedronMenuItem extends MenuItem {
- private static final float DEFAULT_MASS = 2f;
+
+ /**
+ *
+ */
private static final long serialVersionUID = 1936364496102891064L;
//private static Map <String, Object> myParams;
-
- public NewIcosahedronMenuItem (World theWorld) {
+ /**
+ * Constructor.
+ * @param theWorld to add objects to.
+ */
+ public NewIcosahedronMenuItem(final World theWorld) {
super(theWorld, "Icosahedron(NEW)");
buildParams();
- this.makePanel();
+
}
+ /**
+ * Adds Parameters for user input.
+ * Sets default text box text.
+ */
private void buildParams() {
myParameters.put("Scale", new Float(0f));
-
+ this.makePanel();
+ myReadData.get("Scale").setText(((Float)
+ Icosahedron.DEFAULT_SCALE).toString());
}
@Override
- public void actionPerformed(ActionEvent e) {
+ 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()) {
@@ -72,7 +80,8 @@ public class NewIcosahedronMenuItem extends MenuItem {
}
if (event.getSource() == enterButton) {
- myWorld.addObject(new Icosahedron(getPosition(), getMass(), getScale()));
+ myWorld.addObject(new Icosahedron(
+ getPosition(), getMass(), getScale()));
params.dispose();
}
}
@@ -80,6 +89,10 @@ public class NewIcosahedronMenuItem extends MenuItem {
}
+ /**
+ * Gets the Scale for Icosahedron.
+ * @return the scale.
+ */
private float getScale() {
return ((Float) myParameters.get("Scale")).floatValue();
}
diff --git a/src/tesseract/newmenu/NewToroidMenuItem.java b/src/tesseract/newmenu/NewToroidMenuItem.java
new file mode 100644
index 0000000..89b5000
--- /dev/null
+++ b/src/tesseract/newmenu/NewToroidMenuItem.java
@@ -0,0 +1,108 @@
+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.Icosahedron;
+import tesseract.objects.Toroid;
+
+/**
+ * NewToroidMenuItem
+ *
+ * Defines a menu item to add an Icosahedron to the world.
+ * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan
+ *
+ * @author Phillip Cardon
+ */
+public class NewToroidMenuItem extends MenuItem {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1936364496102891064L;
+ //private static Map <String, Object> myParams;
+
+ /**
+ * Constructor.
+ * @param theWorld to add objects to.
+ */
+ public NewToroidMenuItem(final World theWorld) {
+ super(theWorld, "Toroid(NEW)");
+ buildParams();
+
+
+ }
+
+ /**
+ * Adds Parameters for user input.
+ * Sets default text box text.
+ */
+ private void buildParams() {
+ myParameters.put("Tube Radius", new Float(0f));
+ myParameters.put("Tube Resolution", new Integer(0));
+ myParameters.put("Toroid Radius", new Float(0f));
+ myParameters.put("Toroid Resolution", new Integer(0));
+ this.makePanel();
+ myReadData.get("Position").setText(
+ MenuItem.DEFAULT_POSITION.toString());
+ myReadData.get("Mass").setText(((Float)
+ MenuItem.DEFAULT_MASS).toString());
+ myReadData.get("Tube Radius").setText(".06");
+ myReadData.get("Tube Resolution").setText("25");
+ myReadData.get("Toroid Radius").setText(".08");
+ myReadData.get("Toroid Resolution").setText("30");
+ }
+
+ @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 Toroid(MenuItem.DEFAULT_POSITION,
+ MenuItem.DEFAULT_MASS, 0f, .06f, 25, .08f, 30));
+ 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));
+ } else if (o.getClass().equals(new Integer(0).getClass())) {
+ myParameters.put(s, new Integer(Integer.parseInt(p)));
+ }
+
+ }
+ if (event.getSource() == enterButton) {
+ myWorld.addObject(new Toroid(getPosition(), getMass(), 0f,
+ ((Float) myParameters.get("Tube Radius")).floatValue(),
+ ((Integer) myParameters.get("Tube Resolution")
+ ).intValue(),
+ ((Float) myParameters.get("Toroid Radius")
+ ).floatValue(),
+ ((Integer) myParameters.get("Toroid Resolution")
+ ).intValue()));
+ params.dispose();
+ }
+ }
+ });
+ }
+}