summaryrefslogtreecommitdiff
path: root/src/tesseract/newmenu/NewPlanarPolygonMenuItem.java
diff options
context:
space:
mode:
authorPhillip <pacardon@u.washington.edu>2011-02-21 00:08:11 +0000
committerPhillip <pacardon@u.washington.edu>2011-02-21 00:08:11 +0000
commit88510c4f90193b59c366901536c933b3176c20c2 (patch)
tree3e068b35c9ebdb667671c45cc47d587a43d8ff21 /src/tesseract/newmenu/NewPlanarPolygonMenuItem.java
parent3c7f3b099198d4ea36d498c349cad80f2a6937de (diff)
Added lots of NewMenuItem Classes. Changed Default Shape from JCheckBox to JButton.
Added new Constructor to PlanarPolygon. Changed the sequence of events building JPanel/Frame in MenuItem.
Diffstat (limited to 'src/tesseract/newmenu/NewPlanarPolygonMenuItem.java')
-rw-r--r--src/tesseract/newmenu/NewPlanarPolygonMenuItem.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/tesseract/newmenu/NewPlanarPolygonMenuItem.java b/src/tesseract/newmenu/NewPlanarPolygonMenuItem.java
new file mode 100644
index 0000000..95a4b92
--- /dev/null
+++ b/src/tesseract/newmenu/NewPlanarPolygonMenuItem.java
@@ -0,0 +1,98 @@
+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.PlanarPolygon;
+
+/**
+ * NewIcosahedronMenutItem
+ *
+ * Defines a menu item to add a Planar Polygon to the world.
+ * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan
+ *
+ * @author Phillip Cardon
+ */
+public class NewPlanarPolygonMenuItem extends MenuItem {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1936364496102891064L;
+ //private static Map <String, Object> myParams;
+
+ /**
+ * Constructor.
+ * @param theWorld to add objects to.
+ */
+ public NewPlanarPolygonMenuItem(final World theWorld) {
+ super(theWorld, "Planar Polygon(NEW)");
+ buildParams();
+
+
+ }
+
+ /**
+ * Adds Parameters for user input.
+ * Sets default text box text.
+ */
+ private void buildParams() {
+ myParameters.put("Radius", new Float(PlanarPolygon.DEFAULT_RADIUS));
+ myParameters.put("Divisions", new Integer(0));
+ this.makePanel();
+ myReadData.get("Radius").setText(
+ ((Float) PlanarPolygon.DEFAULT_RADIUS).toString());
+ myReadData.get("Divisions").setText(
+ ((Integer) PlanarPolygon.DEFAULT_DIVISIONS).toString());
+ }
+
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ createParameterMenu();
+ final JButton defaultButton = getDefaultButton();
+ final JFrame params = getParamFrame();
+ final JButton enterButton = getEnterButton();
+
+ defaultButton.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent e) {
+ if (e.getSource() == defaultButton) {
+ myWorld.addObject(new PlanarPolygon(getPosition(),
+ PlanarPolygon.DEFAULT_RADIUS));
+ 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 PlanarPolygon(getPosition(),
+ getMass(),
+ ((Float) myParameters.get("Radius")).floatValue(),
+ ((Integer) myParameters.get("Divisions")).intValue()));
+ params.dispose();
+ }
+ }
+ });
+
+ }
+
+
+}