From 354a7aa455a016ac179d7f027014e6b9c2a2433a Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 12 Feb 2011 13:04:41 +0000 Subject: Added parameter box for adding objects. The chainlink is not implemented yet as its params are very different. --- src/tesseract/menuitems/EllipsoidMenuItem.java | 38 ++++-- src/tesseract/menuitems/IcosahedronMenuItem.java | 29 +++- .../menuitems/ParticleEmitterMenuItem.java | 31 +++-- src/tesseract/menuitems/PlanarPolygonMenuItem.java | 39 ++++-- src/tesseract/menuitems/TesseractMenuItem.java | 146 ++++++++++++++++++++- 5 files changed, 239 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/tesseract/menuitems/EllipsoidMenuItem.java b/src/tesseract/menuitems/EllipsoidMenuItem.java index 71b302f..d7217e6 100644 --- a/src/tesseract/menuitems/EllipsoidMenuItem.java +++ b/src/tesseract/menuitems/EllipsoidMenuItem.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JFrame; @@ -42,14 +43,16 @@ public class EllipsoidMenuItem extends TesseractMenuItem { * @param arg0 Unused event info. */ public void actionPerformed(final ActionEvent arg0) { + createParameterMenu(); //If the default button is checked, the frame will close. final JCheckBox defaultButton = getDefaultButton(); final JFrame params = getParamFrame(); - + final JButton enterButton = getEnterButton(); + defaultButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(final ActionEvent ev) { if (defaultButton.isSelected()) { myWorld.addObject(new Ellipsoid(getDefaultPosition(), getDefaultRadius())); params.dispose(); @@ -57,15 +60,26 @@ public class EllipsoidMenuItem extends TesseractMenuItem { } }); - - - - - /*Vector3f pos = - parseVector(JOptionPane.showInputDialog("Enter the position")); - float radius = - Float.parseFloat(JOptionPane.showInputDialog("Enter the radius")); - - myWorld.addObject(new Ellipsoid(pos, radius));*/ + enterButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + String string = getPositionField().getText(); + Vector3f pos = parseVector(string); + setPosition(pos); + + String string2 = getRadiusField().getText(); + float radius = Float.parseFloat(string2); + setRadius(radius); + + String string3 = getMassField().getText(); + float mass = Float.parseFloat(string3); + setMass(mass); + + if (event.getSource() == enterButton) { + myWorld.addObject(new Ellipsoid(getPosition(), getRadius())); + params.dispose(); + } + } + }); + } } diff --git a/src/tesseract/menuitems/IcosahedronMenuItem.java b/src/tesseract/menuitems/IcosahedronMenuItem.java index b2cdc33..c6b5bf1 100644 --- a/src/tesseract/menuitems/IcosahedronMenuItem.java +++ b/src/tesseract/menuitems/IcosahedronMenuItem.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JFrame; @@ -12,6 +13,7 @@ import javax.vecmath.Color3f; import javax.vecmath.Vector3f; import tesseract.World; +import tesseract.objects.Ellipsoid; import tesseract.objects.Icosahedron; import tesseract.objects.PlanarPolygon; @@ -47,6 +49,7 @@ public class IcosahedronMenuItem extends TesseractMenuItem { //If the default button is checked, the frame will close. final JCheckBox defaultButton = getDefaultButton(); final JFrame params = getParamFrame(); + final JButton enterButton = getEnterButton(); defaultButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { @@ -56,12 +59,26 @@ public class IcosahedronMenuItem extends TesseractMenuItem { } } }); - /*Vector3f pos = - parseVector(JOptionPane.showInputDialog("Enter the position")); - float radius = - Float.parseFloat(JOptionPane.showInputDialog("Enter the radius")); - - myWorld.addObject(new Icosahedron(pos, radius));*/ + enterButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + String string = getPositionField().getText(); + Vector3f pos = parseVector(string); + setPosition(pos); + + String string2 = getRadiusField().getText(); + float radius = Float.parseFloat(string2); + setRadius(radius); + + String string3 = getMassField().getText(); + float mass = Float.parseFloat(string3); + setMass(mass); + + if (event.getSource() == enterButton) { + myWorld.addObject(new Icosahedron(getPosition(), getMass(), getRadius())); + params.dispose(); + } + } + }); } } diff --git a/src/tesseract/menuitems/ParticleEmitterMenuItem.java b/src/tesseract/menuitems/ParticleEmitterMenuItem.java index 1c69def..9373e57 100644 --- a/src/tesseract/menuitems/ParticleEmitterMenuItem.java +++ b/src/tesseract/menuitems/ParticleEmitterMenuItem.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -11,6 +12,7 @@ import javax.vecmath.Color3f; import javax.vecmath.Vector3f; import tesseract.World; +import tesseract.objects.Ellipsoid; import tesseract.objects.PlanarPolygon; import tesseract.objects.emitters.ParticleEmitter; @@ -46,6 +48,7 @@ public class ParticleEmitterMenuItem extends TesseractMenuItem { //If the default button is checked, the frame will close. final JCheckBox defaultButton = getDefaultButton(); final JFrame params = getParamFrame(); + final JButton enterButton = getEnterButton(); defaultButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { @@ -57,14 +60,26 @@ public class ParticleEmitterMenuItem extends TesseractMenuItem { } }); - /*Vector3f pos = - parseVector(JOptionPane.showInputDialog("Enter the position")); - - float freq = Float.parseFloat( - JOptionPane.showInputDialog( - "Emission Frequency (seconds)", "1")); - - myWorld.addObject(new ParticleEmitter(pos, freq, null));*/ + enterButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + String string = getPositionField().getText(); + Vector3f pos = parseVector(string); + setPosition(pos); + + String string2 = getRadiusField().getText(); + float radius = Float.parseFloat(string2); + setRadius(radius); + + String string3 = getMassField().getText(); + float mass = Float.parseFloat(string3); + setMass(mass); + + if (event.getSource() == enterButton) { + myWorld.addObject(new ParticleEmitter(getPosition(), .5f, new Color3f(1f,0f,0f))); + params.dispose(); + } + } + }); } } diff --git a/src/tesseract/menuitems/PlanarPolygonMenuItem.java b/src/tesseract/menuitems/PlanarPolygonMenuItem.java index a41dabb..6759f19 100644 --- a/src/tesseract/menuitems/PlanarPolygonMenuItem.java +++ b/src/tesseract/menuitems/PlanarPolygonMenuItem.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; @@ -14,6 +15,7 @@ import javax.vecmath.Color3f; import javax.vecmath.Vector3f; import tesseract.World; +import tesseract.objects.Ellipsoid; import tesseract.objects.PlanarPolygon; /** @@ -48,27 +50,36 @@ public class PlanarPolygonMenuItem extends TesseractMenuItem { //If the default button is checked, the frame will close. final JCheckBox defaultButton = getDefaultButton(); final JFrame params = getParamFrame(); + final JButton enterButton = getEnterButton(); defaultButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(final ActionEvent ev) { if (defaultButton.isSelected()) { - myWorld.addObject(new PlanarPolygon(new Vector3f(0f,-.3f, 0f), getDefaultRadius())); + myWorld.addObject(new PlanarPolygon(getDefaultPosition(), getDefaultRadius())); params.dispose(); } } }); - - /*if(arg0. == true) { - myWorld.addObject(new PlanarPolygon(new Vector3f(0,0,0), DEFAULT_RADIUS)); - params.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - }*/ - - /*Vector3f pos = - parseVector(JOptionPane.showInputDialog("Enter the position")); - float radius = - Float.parseFloat(JOptionPane.showInputDialog("Enter the radius")); - - myWorld.addObject(new PlanarPolygon(pos, radius));*/ + enterButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + String string = getPositionField().getText(); + Vector3f pos = parseVector(string); + setPosition(pos); + + String string2 = getRadiusField().getText(); + float radius = Float.parseFloat(string2); + setRadius(radius); + + String string3 = getMassField().getText(); + float mass = Float.parseFloat(string3); + setMass(mass); + + if (event.getSource() == enterButton) { + myWorld.addObject(new Ellipsoid(getPosition(), getRadius())); + params.dispose(); + } + } + }); } } diff --git a/src/tesseract/menuitems/TesseractMenuItem.java b/src/tesseract/menuitems/TesseractMenuItem.java index cd3bf03..606f487 100644 --- a/src/tesseract/menuitems/TesseractMenuItem.java +++ b/src/tesseract/menuitems/TesseractMenuItem.java @@ -1,12 +1,18 @@ package tesseract.menuitems; +import java.awt.Color; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Toolkit; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JMenuItem; +import javax.swing.JTextField; import javax.vecmath.Vector3f; import tesseract.World; @@ -45,10 +51,45 @@ public abstract class TesseractMenuItem private JCheckBox my_default_button; /** - * A Parameter setting Jframe + * A Parameter setting JFrame */ private JFrame my_param_frame; + /** + * A position. + */ + private Vector3f my_position; + + /** + * A radius field. + */ + private float my_radius; + + /** + * A mass field. + */ + private float my_mass; + + /** + * A position input. + */ + private JTextField my_position_input; + + /** + * A radius input. + */ + private JTextField my_radius_input; + + /** + * A mass input. + */ + private JTextField my_mass_input; + + /** + * The button that get all inputs for shape + */ + private JButton my_enter_button; + /** * Constructor. * @@ -60,6 +101,10 @@ public abstract class TesseractMenuItem myWorld = theWorld; + my_position = new Vector3f(0,0,0); + my_radius = 0f; + my_mass = 1; + addActionListener(this); } @@ -80,15 +125,40 @@ public abstract class TesseractMenuItem } protected void createParameterMenu() { - my_param_frame= new JFrame("Parameters"); + + my_param_frame = new JFrame("Parameters"); + my_param_frame.setBackground(Color.GRAY); + my_param_frame.setLayout(new FlowLayout()); + Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; - my_param_frame.setSize(screenWidth / 2, screenHeight / 2); + my_param_frame.setSize(screenWidth / 4, screenHeight / 4); my_param_frame.setLocation(screenWidth / 4, screenHeight / 4); - my_default_button = new JCheckBox("Default Shape"); + + my_position_input = new JTextField(10); + my_radius_input = new JTextField(10); + my_mass_input = new JTextField(10); + + JLabel position_label = new JLabel("Enter Position: "); + JLabel radius_label = new JLabel("Enter Radius: "); + JLabel mass_label = new JLabel("Enter Mass: "); + + my_enter_button = new JButton("ENTER"); + + my_default_button = new JCheckBox("Default Shape "); + my_param_frame.add(my_default_button); + my_param_frame.add(position_label); + my_param_frame.add(my_position_input); + my_param_frame.add(radius_label); + my_param_frame.add(my_radius_input); + my_param_frame.add(mass_label); + my_param_frame.add(my_mass_input); + my_param_frame.add(my_enter_button); + + my_param_frame.setAlwaysOnTop(true); my_param_frame.pack(); my_param_frame.setVisible(isVisible()); @@ -101,6 +171,10 @@ public abstract class TesseractMenuItem protected JFrame getParamFrame() { return my_param_frame; } + + protected JButton getEnterButton() { + return my_enter_button; + } /** * @return the defaultRadius @@ -115,4 +189,68 @@ public abstract class TesseractMenuItem public static Vector3f getDefaultPosition() { return DEFAULT_POSITION; } + + /** + * @return the input position. + */ + public Vector3f getPosition() { + return my_position; + } + + /** + * @return the radius. + */ + public float getRadius() { + return my_radius; + } + + /** + * @return the mass. + */ + public float getMass() { + return my_mass; + } + + /** + * + * @param the_position the new position + */ + public void setPosition(final Vector3f the_position) { + my_position = the_position; + } + + /** + * @param the_radius float sets the radius. + */ + public void setRadius(final float the_radius) { + my_radius = the_radius; + } + + /** + * @param the_mass float sets the mass. + */ + public void setMass(final float the_mass) { + my_mass = the_mass; + } + + /** + * @return the input position input + */ + public JTextField getPositionField() { + return my_position_input; + } + + /** + * @return the radius input. + */ + public JTextField getRadiusField() { + return my_radius_input; + } + + /** + * @return the mass input. + */ + public JTextField getMassField() { + return my_mass_input; + } } -- cgit v1.2.3