summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/tesseract/TesseractUI.java23
-rw-r--r--src/tesseract/newmenu/MenuItem.java18
-rw-r--r--src/tesseract/newmenu/NewChainLinkMenuItem.java4
-rw-r--r--src/tesseract/newmenu/NewEllipsoidMenuItem.java4
-rw-r--r--src/tesseract/newmenu/NewIcosahedronMenuItem.java4
-rw-r--r--src/tesseract/newmenu/NewParticleEmitterMenuItem.java104
-rw-r--r--src/tesseract/newmenu/NewParticleMenuItem.java104
-rw-r--r--src/tesseract/newmenu/NewPlanarPolygonMenuItem.java98
-rw-r--r--src/tesseract/newmenu/NewToroidMenuItem.java4
-rw-r--r--src/tesseract/objects/PlanarPolygon.java11
10 files changed, 343 insertions, 31 deletions
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java
index 79bb8e6..1ad6cbb 100644
--- a/src/tesseract/TesseractUI.java
+++ b/src/tesseract/TesseractUI.java
@@ -42,7 +42,13 @@ import tesseract.menuitems.ParticleEmitterMenuItem;
import tesseract.menuitems.ParticleMenuItem;
import tesseract.menuitems.PlanarPolygonMenuItem;
import tesseract.menuitems.SurfBoardMenuItem;
+import tesseract.newmenu.NewChainLinkMenuItem;
+import tesseract.newmenu.NewEllipsoidMenuItem;
import tesseract.newmenu.NewIcosahedronMenuItem;
+import tesseract.newmenu.NewParticleEmitterMenuItem;
+import tesseract.newmenu.NewParticleMenuItem;
+import tesseract.newmenu.NewPlanarPolygonMenuItem;
+import tesseract.newmenu.NewToroidMenuItem;
import tesseract.objects.Box;
import tesseract.objects.ChainLink2;
import tesseract.objects.PhysicalObject;
@@ -129,15 +135,14 @@ public class TesseractUI extends JFrame {
myCurrentObject = null;
myObjectMenuItems = new JMenuItem[] {
- new ParticleEmitterMenuItem(myWorld),
- new ParticleMenuItem(myWorld),
- new PlanarPolygonMenuItem(myWorld),
- new EllipsoidMenuItem(myWorld),
- new IcosahedronMenuItem(myWorld),
- new ChainLinkMenuItem(myWorld),
- new DonutMenuItem(myWorld),
- new SurfBoardMenuItem(myWorld),
- new NewIcosahedronMenuItem(myWorld)
+ new NewParticleEmitterMenuItem(myWorld),
+ new NewParticleMenuItem(myWorld),
+ new NewPlanarPolygonMenuItem(myWorld),
+ new NewEllipsoidMenuItem(myWorld),
+ new NewIcosahedronMenuItem(myWorld),
+ new NewChainLinkMenuItem(myWorld),
+ new NewToroidMenuItem(myWorld),
+ new SurfBoardMenuItem(myWorld)
};
createMenu();
setupCanvas();
diff --git a/src/tesseract/newmenu/MenuItem.java b/src/tesseract/newmenu/MenuItem.java
index 1be137f..e4f689e 100644
--- a/src/tesseract/newmenu/MenuItem.java
+++ b/src/tesseract/newmenu/MenuItem.java
@@ -77,7 +77,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
/**
* The default button.
*/
- private JCheckBox myDefaultButton;
+ private JButton myDefaultButton;
/**
* Default constructor.
@@ -96,9 +96,12 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
myPanel = new JPanel();
myReadData = new HashMap <String, JTextField>();
myWorld = theWorld;
- myParameters.put("Position", new Vector3f());
- myParameters.put("Mass", new Float(0f));
+ myParameters.put("Position", DEFAULT_POSITION);
+ myParameters.put("Mass", new Float(DEFAULT_MASS));
addActionListener(this);
+ myParamFrame = new JFrame("Parameters");
+ myParamFrame.setBackground(Color.GRAY);
+ myParamFrame.setLayout(new BorderLayout());
}
/**
@@ -124,9 +127,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
*/
protected void createParameterMenu() {
- myParamFrame = new JFrame("Parameters");
- myParamFrame.setBackground(Color.GRAY);
- myParamFrame.setLayout(new BorderLayout());
+
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
@@ -149,7 +150,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
myEnterButton = new JButton("ENTER");
- myDefaultButton = new JCheckBox("Default Shape ");
+ myDefaultButton = new JButton("Default Shape");
myParamFrame.add(myDefaultButton, BorderLayout.NORTH);
myParamFrame.add(myPanel, BorderLayout.CENTER);
@@ -164,7 +165,7 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
*
* @return Default Button
*/
- public JCheckBox getDefaultButton() {
+ public JButton getDefaultButton() {
return myDefaultButton;
}
@@ -217,5 +218,4 @@ public abstract class MenuItem extends JMenuItem implements ActionListener {
protected float getMass() {
return ((Float) myParameters.get("Mass")).floatValue();
}
-
}
diff --git a/src/tesseract/newmenu/NewChainLinkMenuItem.java b/src/tesseract/newmenu/NewChainLinkMenuItem.java
index 59d0f53..65e7395 100644
--- a/src/tesseract/newmenu/NewChainLinkMenuItem.java
+++ b/src/tesseract/newmenu/NewChainLinkMenuItem.java
@@ -58,13 +58,13 @@ public class NewChainLinkMenuItem extends MenuItem {
@Override
public void actionPerformed(final ActionEvent e) {
createParameterMenu();
- final JCheckBox defaultButton = getDefaultButton();
+ final JButton defaultButton = getDefaultButton();
final JFrame params = getParamFrame();
final JButton enterButton = getEnterButton();
defaultButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
- if (defaultButton.isSelected()) {
+ if (e.getSource() == defaultButton) {
myWorld.addObject(new ChainLink2(MenuItem.DEFAULT_POSITION,
MenuItem.DEFAULT_MASS));
params.dispose();
diff --git a/src/tesseract/newmenu/NewEllipsoidMenuItem.java b/src/tesseract/newmenu/NewEllipsoidMenuItem.java
index dddf3d6..ae5885a 100644
--- a/src/tesseract/newmenu/NewEllipsoidMenuItem.java
+++ b/src/tesseract/newmenu/NewEllipsoidMenuItem.java
@@ -55,13 +55,13 @@ public class NewEllipsoidMenuItem extends MenuItem {
@Override
public void actionPerformed(final ActionEvent e) {
createParameterMenu();
- final JCheckBox defaultButton = getDefaultButton();
+ final JButton defaultButton = getDefaultButton();
final JFrame params = getParamFrame();
final JButton enterButton = getEnterButton();
defaultButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
- if (defaultButton.isSelected()) {
+ if (e.getSource() == defaultButton) {
myWorld.addObject(new Ellipsoid(getPosition(),
DEFAULT_RADIUS));
params.dispose();
diff --git a/src/tesseract/newmenu/NewIcosahedronMenuItem.java b/src/tesseract/newmenu/NewIcosahedronMenuItem.java
index 4123486..8a96ee0 100644
--- a/src/tesseract/newmenu/NewIcosahedronMenuItem.java
+++ b/src/tesseract/newmenu/NewIcosahedronMenuItem.java
@@ -53,13 +53,13 @@ public class NewIcosahedronMenuItem extends MenuItem {
@Override
public void actionPerformed(final ActionEvent e) {
createParameterMenu();
- final JCheckBox defaultButton = getDefaultButton();
+ final JButton defaultButton = getDefaultButton();
final JFrame params = getParamFrame();
final JButton enterButton = getEnterButton();
defaultButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
- if (defaultButton.isSelected()) {
+ if (e.getSource() == defaultButton) {
myWorld.addObject(new Icosahedron(MenuItem.DEFAULT_POSITION,
DEFAULT_MASS, Icosahedron.DEFAULT_SCALE));
params.dispose();
diff --git a/src/tesseract/newmenu/NewParticleEmitterMenuItem.java b/src/tesseract/newmenu/NewParticleEmitterMenuItem.java
new file mode 100644
index 0000000..9f67ba8
--- /dev/null
+++ b/src/tesseract/newmenu/NewParticleEmitterMenuItem.java
@@ -0,0 +1,104 @@
+package tesseract.newmenu;
+
+import java.awt.Color;
+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.JColorChooser;
+import javax.swing.JFrame;
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import tesseract.World;
+import tesseract.objects.Icosahedron;
+import tesseract.objects.emitters.ParticleEmitter;
+
+/**
+ * NewIcosahedronMenutItem
+ *
+ * Defines a menu item to add an Particle emitter to the world.
+ * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan
+ *
+ * @author Phillip Cardon
+ */
+public class NewParticleEmitterMenuItem extends MenuItem {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1936364496102891064L;
+
+ /**
+ * Default frequency.
+ */
+ private static final float DEFAULT_FREQUENCY = 0.5f;
+
+ /**
+ * Constructor.
+ * @param theWorld to add objects to.
+ */
+ public NewParticleEmitterMenuItem(final World theWorld) {
+ super(theWorld, "Particle Emitter(NEW)");
+ buildParams();
+
+
+ }
+
+ /**
+ * Adds Parameters for user input.
+ * Sets default text box text.
+ */
+ private void buildParams() {
+ myParameters.put("Frequency", new Float(0f));
+ this.makePanel();
+ myReadData.get("Frequency").setText(((Float)
+ Icosahedron.DEFAULT_SCALE).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 ParticleEmitter(getPosition(),
+ DEFAULT_FREQUENCY, new Color3f(1f, 0f, 0f)));
+ 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) {
+ params.dispose();
+ Color c = JColorChooser.showDialog(null, "Particle Color",
+ Color.RED);
+ myWorld.addObject(new ParticleEmitter(getPosition(),
+ ((Float) myParameters.get("Frequency")).floatValue(),
+ new Color3f(c)));
+
+ }
+ }
+ });
+ }
+}
diff --git a/src/tesseract/newmenu/NewParticleMenuItem.java b/src/tesseract/newmenu/NewParticleMenuItem.java
new file mode 100644
index 0000000..36bf502
--- /dev/null
+++ b/src/tesseract/newmenu/NewParticleMenuItem.java
@@ -0,0 +1,104 @@
+package tesseract.newmenu;
+
+import java.awt.Color;
+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.JColorChooser;
+import javax.swing.JFrame;
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import tesseract.World;
+import tesseract.objects.Icosahedron;
+import tesseract.objects.Particle;
+import tesseract.objects.emitters.ParticleEmitter;
+
+/**
+ * NewIcosahedronMenutItem
+ *
+ * Defines a menu item to add an Particle to the world.
+ * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan
+ *
+ * @author Phillip Cardon
+ */
+public class NewParticleMenuItem extends MenuItem {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1936364496102891064L;
+
+ /**
+ * Default frequency.
+ */
+ private static final float DEFAULT_FREQUENCY = 0.5f;
+
+ /**
+ * Constructor.
+ * @param theWorld to add objects to.
+ */
+ public NewParticleMenuItem(final World theWorld) {
+ super(theWorld, "Particle(NEW)");
+ this.makePanel();
+
+
+ }
+
+ /**
+ * Adds Parameters for user input.
+ * Sets default text box text.
+ */
+ /*private void buildParams() {
+ myParameters.put("Frequency", new Float(0f));
+ this.makePanel();
+ myReadData.get("Frequency").setText(((Float)
+ Icosahedron.DEFAULT_SCALE).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 Particle(getPosition(),
+ getMass(), new Color3f(1f, 0f, 0f)));
+ 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) {
+ params.dispose();
+ Color c = JColorChooser.showDialog(null, "Particle Color",
+ Color.RED);
+ myWorld.addObject(new Particle(getPosition(), getMass(),
+ new Color3f(c)));
+
+ }
+ }
+ });
+ }
+}
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();
+ }
+ }
+ });
+
+ }
+
+
+}
diff --git a/src/tesseract/newmenu/NewToroidMenuItem.java b/src/tesseract/newmenu/NewToroidMenuItem.java
index 8d98595..7bfde78 100644
--- a/src/tesseract/newmenu/NewToroidMenuItem.java
+++ b/src/tesseract/newmenu/NewToroidMenuItem.java
@@ -63,13 +63,13 @@ public class NewToroidMenuItem extends MenuItem {
@Override
public void actionPerformed(final ActionEvent e) {
createParameterMenu();
- final JCheckBox defaultButton = getDefaultButton();
+ final JButton defaultButton = getDefaultButton();
final JFrame params = getParamFrame();
final JButton enterButton = getEnterButton();
defaultButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
- if (defaultButton.isSelected()) {
+ if (e.getSource() == defaultButton) {
myWorld.addObject(new Toroid(MenuItem.DEFAULT_POSITION,
MenuItem.DEFAULT_MASS, 0f, .06f, 25, .08f, 30));
params.dispose();
diff --git a/src/tesseract/objects/PlanarPolygon.java b/src/tesseract/objects/PlanarPolygon.java
index 0521062..30eac77 100644
--- a/src/tesseract/objects/PlanarPolygon.java
+++ b/src/tesseract/objects/PlanarPolygon.java
@@ -54,7 +54,12 @@ public class PlanarPolygon extends PhysicalObject {
/**
* Number of divisions in the sphere.
*/
- private static final int DEFAULT_DIVISIONS = 6;
+ public static final int DEFAULT_DIVISIONS = 6;
+
+ /**
+ * A Default radius.
+ */
+ public static final float DEFAULT_RADIUS = 0.1f;
/**
* Create a new Ellipsoid.
@@ -62,11 +67,7 @@ public class PlanarPolygon extends PhysicalObject {
* @param position Initial position.
* @param mass Initial mass.
* @param radius the radius of the base sphere.
- * @param primflags an int for the base spere primflags.
* @param divisions an in for the shape divisions.
- * @param appearance an Appearance object.
- * @param b a float for the b portion of the ellipsoid formula.
- * @param c a float for the c portion of the ellipsoid formula.
*/
public PlanarPolygon(final Vector3f position, final float mass,
final float radius, final int divisions) {