summaryrefslogtreecommitdiff
path: root/src/tesseract/newmenu/NewParticleEmitterMenuItem.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/NewParticleEmitterMenuItem.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/NewParticleEmitterMenuItem.java')
-rw-r--r--src/tesseract/newmenu/NewParticleEmitterMenuItem.java104
1 files changed, 104 insertions, 0 deletions
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)));
+
+ }
+ }
+ });
+ }
+}