diff --git a/LIQUID/bin/liquid/core/DesktopLauncher.class b/LIQUID/bin/liquid/core/DesktopLauncher.class index 68f9d2c..aa61e62 100644 Binary files a/LIQUID/bin/liquid/core/DesktopLauncher.class and b/LIQUID/bin/liquid/core/DesktopLauncher.class differ diff --git a/LIQUID/bin/liquid/core/LiquidApplication.class b/LIQUID/bin/liquid/core/LiquidApplication.class index 925857c..4ea8ce3 100644 Binary files a/LIQUID/bin/liquid/core/LiquidApplication.class and b/LIQUID/bin/liquid/core/LiquidApplication.class differ diff --git a/LIQUID/bin/liquid/engine/LiquidEngine.class b/LIQUID/bin/liquid/engine/LiquidEngine.class index dbf8dab..5e816c2 100644 Binary files a/LIQUID/bin/liquid/engine/LiquidEngine.class and b/LIQUID/bin/liquid/engine/LiquidEngine.class differ diff --git a/LIQUID/bin/liquid/gui/ConsolePanel.class b/LIQUID/bin/liquid/gui/ConsolePanel.class index a04abcc..6de89b9 100644 Binary files a/LIQUID/bin/liquid/gui/ConsolePanel.class and b/LIQUID/bin/liquid/gui/ConsolePanel.class differ diff --git a/LIQUID/bin/liquid/gui/LiquidFrame.class b/LIQUID/bin/liquid/gui/LiquidFrame.class index febd4a6..8a9fc03 100644 Binary files a/LIQUID/bin/liquid/gui/LiquidFrame.class and b/LIQUID/bin/liquid/gui/LiquidFrame.class differ diff --git a/LIQUID/bin/liquid/gui/LiquidGUI.class b/LIQUID/bin/liquid/gui/LiquidGUI.class index e8bead0..5e7bede 100644 Binary files a/LIQUID/bin/liquid/gui/LiquidGUI.class and b/LIQUID/bin/liquid/gui/LiquidGUI.class differ diff --git a/LIQUID/bin/liquid/gui/LiquidMenuBar$1.class b/LIQUID/bin/liquid/gui/LiquidMenuBar$1.class index f800d85..652cdf7 100644 Binary files a/LIQUID/bin/liquid/gui/LiquidMenuBar$1.class and b/LIQUID/bin/liquid/gui/LiquidMenuBar$1.class differ diff --git a/LIQUID/bin/liquid/gui/LiquidMenuBar$2.class b/LIQUID/bin/liquid/gui/LiquidMenuBar$2.class index 24da5d2..29fd6cb 100644 Binary files a/LIQUID/bin/liquid/gui/LiquidMenuBar$2.class and b/LIQUID/bin/liquid/gui/LiquidMenuBar$2.class differ diff --git a/LIQUID/bin/liquid/gui/LiquidMenuBar.class b/LIQUID/bin/liquid/gui/LiquidMenuBar.class index 86fdc64..3242360 100644 Binary files a/LIQUID/bin/liquid/gui/LiquidMenuBar.class and b/LIQUID/bin/liquid/gui/LiquidMenuBar.class differ diff --git a/LIQUID/bin/liquid/gui/ParameterPanel.class b/LIQUID/bin/liquid/gui/ParameterPanel.class index 75b28e0..9d21d1a 100644 Binary files a/LIQUID/bin/liquid/gui/ParameterPanel.class and b/LIQUID/bin/liquid/gui/ParameterPanel.class differ diff --git a/LIQUID/src/liquid/core/DesktopLauncher.java b/LIQUID/src/liquid/core/DesktopLauncher.java index daadc69..9155a70 100644 --- a/LIQUID/src/liquid/core/DesktopLauncher.java +++ b/LIQUID/src/liquid/core/DesktopLauncher.java @@ -1,3 +1,4 @@ +// DONE! package liquid.core; /** diff --git a/LIQUID/src/liquid/core/Interfaceable.java b/LIQUID/src/liquid/core/Interfaceable.java index 229ef55..4b3de6d 100644 --- a/LIQUID/src/liquid/core/Interfaceable.java +++ b/LIQUID/src/liquid/core/Interfaceable.java @@ -1,3 +1,4 @@ +// DONE! package liquid.core; /** diff --git a/LIQUID/src/liquid/core/LiquidApplication.java b/LIQUID/src/liquid/core/LiquidApplication.java index 95c0532..995704c 100644 --- a/LIQUID/src/liquid/core/LiquidApplication.java +++ b/LIQUID/src/liquid/core/LiquidApplication.java @@ -1,3 +1,4 @@ +// DONE! package liquid.core; import liquid.engine.LiquidEngine; diff --git a/LIQUID/src/liquid/engine/Flowmeter.java b/LIQUID/src/liquid/engine/Flowmeter.java index 31cbd51..cef93dd 100644 --- a/LIQUID/src/liquid/engine/Flowmeter.java +++ b/LIQUID/src/liquid/engine/Flowmeter.java @@ -3,6 +3,7 @@ */ package liquid.engine; +import java.text.DecimalFormat; import java.util.ArrayList; import org.jbox2d.common.Vec2; @@ -15,24 +16,32 @@ public class Flowmeter { private World myWorld; private Vec2 myLoc; - private float timer; + private int myID; /** * * @param imHere the world this flow meter is monitoring * @param loc the location this flow meter monitors */ - public Flowmeter(World imHere, Vec2 loc){ + public Flowmeter(World imHere, Vec2 loc, int ID){ myWorld = imHere; myLoc = loc; - timer = 0; + myID = ID; } + + public String update(){ + DecimalFormat adj = new DecimalFormat(); + Vec2 curVel = pollVelocity(); + adj.setMaximumFractionDigits(4); + String send = "" + myID + ": " + "X-Velocity " + adj.format(curVel.x) + " Y-Velocity " + adj.format(curVel.y); + return send; + } + /** * Gets the average x and y velocities of particles within 2.0 units of this flowmeter's position * @return Vec2 object containing the average x and y velocities of nearby particles */ - public Vec2 pollVelocity(float delta){ - timer += delta; + private Vec2 pollVelocity(){ ArrayList vel = new ArrayList(); Vec2[] pos = myWorld.getParticlePositionBuffer(); Vec2 bounds = new Vec2(10.0f, 10.0f); //To change boundaries to check, simply change parameters of constructor diff --git a/LIQUID/src/liquid/engine/FluidEnvironment.java b/LIQUID/src/liquid/engine/FluidEnvironment.java index 401fe85..84d189f 100644 --- a/LIQUID/src/liquid/engine/FluidEnvironment.java +++ b/LIQUID/src/liquid/engine/FluidEnvironment.java @@ -80,7 +80,7 @@ public void update(float delta){ if(timer >= 10){ timer = 0; for (Flowmeter f: meters){ - System.out.println(f.pollVelocity(delta)); + System.out.println(f.update()); } } } @@ -96,8 +96,8 @@ public void addObstacle(Shape s,float x, float y){ b.createFixture(fd); } - public void addSource(float x, float y, float velx, float vely){ - sources.add(new Source(this, x, y, velx, vely)); + public void addSource(float x, float y, float velx, float vely, float flow){ + sources.add(new Source(this, x, y, velx, vely, flow)); } /** @@ -105,8 +105,8 @@ public void addSource(float x, float y, float velx, float vely){ * @param x x-position of the new flow meter * @param y y-position of the new flow meter */ - public void addFlowmeter(float x, float y){ - meters.add(new Flowmeter(world, new Vec2(x, y))); + public void addFlowmeter(float x, float y, int ID){ + meters.add(new Flowmeter(world, new Vec2(x, y), ID)); } public void addParticle(float x, float y, float velx, float vely){ diff --git a/LIQUID/src/liquid/engine/LiquidEngine.java b/LIQUID/src/liquid/engine/LiquidEngine.java index be810ff..d8cc374 100644 --- a/LIQUID/src/liquid/engine/LiquidEngine.java +++ b/LIQUID/src/liquid/engine/LiquidEngine.java @@ -135,7 +135,10 @@ public void initiateSim(String[] args) { String[] tokens = args[6].split(" "); enviro = new FluidEnvironment(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1])); - float x, y, l, w; + + int ID = 1; + float x, y, l, w, r; + for (int i = 7; i < args.length; i++) { tokens = args[i].split(" "); if (tokens[0].equals("Rectangular")) { @@ -165,12 +168,13 @@ public void initiateSim(String[] args) { y = Float.parseFloat(tokens[2]); l = Float.parseFloat(tokens[3]); w = Float.parseFloat(tokens[4]); - enviro.addSource(x, y, l, w); + r = Float.parseFloat(tokens[5]); + enviro.addSource(x, y, l, w, r); } if (tokens[0].equals("Flowmeter")) { x = Float.parseFloat(tokens[1]); y = Float.parseFloat(tokens[2]); - enviro.addFlowmeter(x, y); + enviro.addFlowmeter(x, y, ID++); } } enviro.init(); diff --git a/LIQUID/src/liquid/engine/Source.java b/LIQUID/src/liquid/engine/Source.java index 66345e9..7f1c3e3 100644 --- a/LIQUID/src/liquid/engine/Source.java +++ b/LIQUID/src/liquid/engine/Source.java @@ -5,6 +5,8 @@ import org.jbox2d.common.Vec2; +import liquid.core.LiquidApplication; + /** * @author Rafael Zamora * @@ -17,11 +19,11 @@ public class Source { private float flowspeed; private float timer; - public Source(FluidEnvironment enviro, float x, float y, float velx, float vely){ + public Source(FluidEnvironment enviro, float x, float y, float velx, float vely, float flow){ this.enviro = enviro; pos = new Vec2(x, y); force = new Vec2(velx,vely); - flowspeed = force.length(); + flowspeed = flow; timer = 0; } diff --git a/LIQUID/src/liquid/gui/ConsolePanel.java b/LIQUID/src/liquid/gui/ConsolePanel.java index 5f6bec7..9b1a411 100644 --- a/LIQUID/src/liquid/gui/ConsolePanel.java +++ b/LIQUID/src/liquid/gui/ConsolePanel.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import java.awt.Color; diff --git a/LIQUID/src/liquid/gui/EnviroAddiParamPanel.java b/LIQUID/src/liquid/gui/EnviroAddiParamPanel.java new file mode 100644 index 0000000..7db531e --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroAddiParamPanel.java @@ -0,0 +1,119 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class creates the additional parameters of the EnvironmentEditorPanel. This is currently + * located at the bottom of the panel, where it is shared by all drop-down options. + */ +public class EnviroAddiParamPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // defines variables of the additional parameters + JButton selectNext; + JButton selectPrev; + JButton selectUpdate; + JButton delete; + + /** + * Constructor adds the additional parameters of the EnvironmentEditorPanel. + */ + public EnviroAddiParamPanel() { + initComponents(); + } + + /** + * Initializes the buttons of the additional parameters. + */ + public void initComponents() { + setBounds(5,240,240,65); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + //selectNext = new JButton("Next Item"); + //selectNext.setBounds(35,5,(this.getWidth()/2),25); + //add(selectNext); + + selectNext = new JButton("Next Item"); + selectPrev = new JButton("Prev Item"); + selectUpdate = new JButton("Update Item"); + delete = new JButton("Delete"); + nextParam(); + prevParam(); + updateParam(); + deleteParam(); + } + + public void nextParam() { + selectNext.setBounds(5,4,(int)(this.getWidth()/2.2),25); + ActionListener next = new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + if (LiquidApplication.getGUI().variables.selectedObject < LiquidApplication.getGUI().variables.objects.size()-1){ + LiquidApplication.getGUI().variables.selectedObject += 1; + } else { + LiquidApplication.getGUI().variables.selectedObject = 0; + } + LiquidApplication.getGUI().enviroeditor.update(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + }; + selectNext.addActionListener(next); + add(selectNext); + } + + public void prevParam() { + selectPrev.setBounds(125,4,(int)(this.getWidth()/2.2),25); + ActionListener prev = new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + if( LiquidApplication.getGUI().variables.selectedObject > 0) { + LiquidApplication.getGUI().variables.selectedObject -= 1; + } else { + LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; + } + LiquidApplication.getGUI().enviroeditor.update(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + }; + selectPrev.addActionListener(prev); + add(selectPrev); + } + + public void updateParam() { + selectUpdate.setBounds(5,34,(int)(this.getWidth()/2.2),25); + selectUpdate.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent actionEvent) { + if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Obstacles")) { + LiquidApplication.getGUI().enviroeditor.obstacles.createObstacle(true); + } else if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Initial Forces")) { + LiquidApplication.getGUI().enviroeditor.forces.createForce(true); + } else if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Flow Sensors")) { + LiquidApplication.getGUI().enviroeditor.sensors.createSensor(true); + } + } + }); + add(selectUpdate); + } + + public void deleteParam() { + delete.setBounds(125,34,(int)(this.getWidth()/2.2),25); + delete.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent actionEvent) { + LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); + LiquidApplication.getGUI().variables.selectedObject = 0; + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + }); + add(delete); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroForcesPanel.java b/LIQUID/src/liquid/gui/EnviroForcesPanel.java new file mode 100644 index 0000000..3e79db1 --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroForcesPanel.java @@ -0,0 +1,187 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked + * to creating a force are present, such as the force in the X/Y directions. + */ +public class EnviroForcesPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // list of components needed to create a force + JComboBox forceType; + JComboBox forceSpeed; + JComboBox forceX; + JComboBox forceY; + JComboBox forceXComp; + JComboBox forceYComp; + + String[] foType = {"Source"}; + ArrayList params; + + /** + * Constructor creates the Force (or Initial Force) section of the EnvironmentEditorPanel. + */ + public EnviroForcesPanel() { + initComponents(); + } + + /** + * Method creates the labels and drop-downs associated with creating forces. + */ + public void initComponents() { + setBounds(5,30,240,205); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + // makes labels specific to creating forces + JLabel l = new JLabel("Object Type:"); + l.setBounds(5,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Flow Speed:"); + l.setBounds(125,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Coordinate:"); + l.setBounds(5,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Coordinate:"); + l.setBounds(125,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Force:"); + l.setBounds(5,110,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Force:"); + l.setBounds(125,110,(this.getWidth()/2),25); + add(l); + + // makes the drop-downs needed to create forces + forceType = new JComboBox(foType); + forceType.setBounds(5,30,(int)(this.getWidth()/2.2),25); + add(forceType); + + forceSpeed = new JComboBox(); + forceX = new JComboBox(); + forceY = new JComboBox(); + forceXComp = new JComboBox(); + forceYComp = new JComboBox(); + forcesParam(); // populates the drop-down information + createButton(); // makes a Create button + } + + /** + * Method adjusts the force's settings to be within the limit of the environment's size. It also provides + * a real-time update of the force parameters to prevent them from exceeding the environment's boundaries. + */ + public void forcesParam() { + // each drop-down first gets all items removed from it, then gets + // populated with items all dependent on the environment boundaries + forceSpeed.removeAllItems(); + for (int i = 0; i <= 100; i++) { + forceSpeed.addItem(Float.valueOf(i));} + forceSpeed.setBounds(125,30,(int)(this.getWidth()/2.2),25); + add(forceSpeed); + + forceX.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + forceX.addItem(Float.valueOf(i));} + forceX.setBounds(5,85,(int)(this.getWidth()/2.2),25); + add(forceX); + + forceY.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + forceY.addItem(Float.valueOf(i));} + forceY.setBounds(125,85,(int)(this.getWidth()/2.2),25); + add(forceY); + + forceXComp.removeAllItems(); + for (int i = -100; i <= 100; i++) { + forceXComp.addItem(Float.valueOf(i));} + forceXComp.setBounds(5,135,(int)(this.getWidth()/2.2),25); + add(forceXComp); + + forceYComp.removeAllItems(); + for (int i = -100; i <= 100; i++) { + forceYComp.addItem(Float.valueOf(i));} + forceYComp.setBounds(125,135,(int)(this.getWidth()/2.2),25); + add(forceYComp); + + // sets the default parameters even after an environment size change + resetForces(); + } + + /** + * Method used to call the editor panel to make a Create button for Forces. + */ + public void createButton() { + // button creates the obstacle according to the parameters set + JButton create = new JButton("Create"); + create.setBounds(65,170,(int)(this.getWidth()/2.2),25); + create.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + createForce(false); + } + }); + add(create); + } + + /** + * Method packages data and sends it to editor to check if valid and + * to be added into object list. + */ + public void createForce(boolean update){ + params = new ArrayList(); + params.add((Float) forceX.getSelectedItem()); + params.add((Float) forceY.getSelectedItem()); + params.add((Float) forceXComp.getSelectedItem()); + params.add((Float) forceYComp.getSelectedItem()); + params.add((Float) forceSpeed.getSelectedItem()); + LiquidApplication.getGUI().enviroeditor.checkBoundaries(forceType, params, update); + } + + /** + * Method splits up the String[] of the log file in order to correctly set the + * parameters of the Forces (or Initial Forces) section of the EnvironmentEditorPanel. + * + * @param tokens - String[] of the log file to split + */ + public void updateForces(String[] tokens) { + try { + forceType.setSelectedItem(tokens[0]); + forceX.setSelectedItem(Float.parseFloat(tokens[1])); + forceY.setSelectedItem(Float.parseFloat(tokens[2])); + forceXComp.setSelectedItem(Float.parseFloat(tokens[3])); + forceYComp.setSelectedItem(Float.parseFloat(tokens[4])); + forceSpeed.setSelectedItem(Float.parseFloat(tokens[5])); + } catch (Exception e) { + e.printStackTrace();} + } + + /** + * Method resets the parameters of the Forces section. + */ + public void resetForces() { + forceType.setSelectedIndex(0); + forceSpeed.setSelectedIndex(20); + forceX.setSelectedIndex(0); + forceY.setSelectedIndex(0); + forceXComp.setSelectedIndex(150); + forceYComp.setSelectedIndex(150); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroObstacles.java b/LIQUID/src/liquid/gui/EnviroObstacles.java deleted file mode 100644 index 93b70bb..0000000 --- a/LIQUID/src/liquid/gui/EnviroObstacles.java +++ /dev/null @@ -1,189 +0,0 @@ -package liquid.gui; - -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - -import liquid.core.LiquidApplication; - -/** - * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked - * to creating an obstacle are present, such as the X-/Y-Coordinates. - */ -public class EnviroObstacles extends JPanel { - - private static final long serialVersionUID = 1L; - - // list of components needed to create an obstacle - JComboBox obstacleType; - JComboBox obstacleX; - JComboBox obstacleY; - JComboBox obstacleL; - JComboBox obstacleW; - String[] obstype = {"Rectangular", "Circular"}; - - /** - * Constructor creates the Obstacles section of the EnvironmentEditorPanel. - */ - public EnviroObstacles() { - initComponents(); - } - - /** - * Method creates the labels and drop-downs associated with creating obstacles. - */ - public void initComponents() { - setBounds(5,30,240,175); - setBackground(Color.LIGHT_GRAY); - setLayout(null); - - // makes labels specific to creating obstacles - JLabel l = new JLabel("Object Type:"); - l.setBounds(35,5,(this.getWidth()/2),25); - add(l); - - l = new JLabel("X-Coordinate:"); - l.setBounds(5,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Y-Coordinate:"); - l.setBounds(125,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Length:"); - l.setBounds(5,80,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Width:"); - l.setBounds(125,80,(this.getWidth()/2),25); - add(l); - - // makes the drop-downs needed to create obstacles - obstacleType = new JComboBox(obstype); - obstacleType.setBounds(115,5,(this.getWidth()/2),25); - add(obstacleType); - - // makes drop-downs to represent the parameters of an obstacle - obstacleX = new JComboBox(); - obstacleY = new JComboBox(); - obstacleL = new JComboBox(); - obstacleW = new JComboBox(); - adjustSettings(); // populates the drop-down information - createButton(); // creates the Create button - } - - /** - * Method adjusts the obstacles settings to be within the limit of the environment's size. It also provides - * a real-time update of the obstacle parameters to prevent them from exceeding the environment's boundaries. - */ - public void adjustSettings() { - // each drop-down first gets all items removed from it, then gets - // populated with items all dependent on the environment boundaries - obstacleX.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { - obstacleX.addItem(Float.valueOf(i));} - obstacleX.setBounds(5,55,(int)(this.getWidth()/2.2),25); - add(obstacleX); - - obstacleY.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { - obstacleY.addItem(Float.valueOf(i));} - obstacleY.setBounds(125,55,(int)(this.getWidth()/2.2),25); - add(obstacleY); - - // sets the default settings to be always 50, unless restricted by the environment - obstacleL.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { - obstacleL.addItem(Float.valueOf(i));} - obstacleL.setBounds(5,105,(int)(this.getWidth()/2.2),25); - add(obstacleL); - - obstacleW.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { - obstacleW.addItem(Float.valueOf(i));} - obstacleW.setBounds(125,105,(int)(this.getWidth()/2.2),25); - add(obstacleW); - - // sets what the default parameters should be - resetObstacles(); - } - - /** - * Method creates the Create button and throws error messages when - * the obstacle will go out of the predefined environment size. - */ - public void createButton() { - // button creates the obstacle according to the parameters set - JButton create = new JButton("Create"); - create.setBounds(65,140,(int)(this.getWidth()/2.2),25); - create.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - // throws error messages when the obstacle will go beyond the environment (determined - // by the X-/Y-Coordinates and the Length/Width of the obstacle, respectively) - if ((obstacleX.getSelectedIndex() + obstacleL.getSelectedIndex()) > EnvironmentEditorPanel.enviroLenLimit) { - JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, - "Warning!! Your X-Coordinate must be from 0.0 - " + (EnvironmentEditorPanel.enviroLenLimit - obstacleL.getSelectedIndex()) + - ",\n or your Length must be from 0.0 - " + (EnvironmentEditorPanel.enviroLenLimit - obstacleX.getSelectedIndex()) + - "\n to be in the boundaries of your desired environment size.", - "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); - } else if ((obstacleY.getSelectedIndex() + obstacleW.getSelectedIndex() > EnvironmentEditorPanel.enviroWidLimit)) { - JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, - "Warning!! Your Y-Coordinate must be from 0.0 - " + (EnvironmentEditorPanel.enviroWidLimit - obstacleW.getSelectedIndex()) + - ",\n or your Width must be from 0.0 - " + (EnvironmentEditorPanel.enviroWidLimit - obstacleY.getSelectedIndex()) + - "\n to be in the boundaries of your desired environment size.", - "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); - - // else sends the obstacle's information to the ArrayList of objects to store - } else { - String arg = obstacleType.getSelectedItem() + " " + - obstacleX.getSelectedItem() + " " + obstacleY.getSelectedItem() + " " + - obstacleL.getSelectedItem() + " " + obstacleW.getSelectedItem(); - LiquidApplication.getGUI().variables.objects.add(arg); - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size() - 1; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - } - }); - add(create); - } - - /** - * Method splits up the String[] of the log file in order to correctly set - * the parameters of the Obstacles section of the EnvironmentEditorPanel. - * - * @param tokens - String[] of the log file to split - */ - public void updateObstacles(String[] tokens) { - try { - obstacleType.setSelectedItem(tokens[0]); - obstacleX.setSelectedItem(tokens[1]); - obstacleY.setSelectedItem(tokens[2]); - obstacleL.setSelectedItem(tokens[3]); - obstacleW.setSelectedItem(tokens[4]); - } catch (Exception e) { - e.printStackTrace();} - } - - /** - * Method resets the parameters of the Obstacles section. - */ - public void resetObstacles() { - obstacleType.setSelectedIndex(0); - obstacleX.setSelectedIndex(0); - obstacleY.setSelectedIndex(0); - - // sets the default settings to be always 50, unless restricted by the environment - if (EnvironmentEditorPanel.enviroLenLimit >= 50) obstacleL.setSelectedIndex(50); - else obstacleL.setSelectedIndex((int) (EnvironmentEditorPanel.enviroLenLimit/10)); - - if (EnvironmentEditorPanel.enviroLenLimit >= 50) obstacleW.setSelectedIndex(50); - else obstacleW.setSelectedIndex((int) (EnvironmentEditorPanel.enviroLenLimit/10)); - } -} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroObstaclesPanel.java b/LIQUID/src/liquid/gui/EnviroObstaclesPanel.java new file mode 100644 index 0000000..5a4a2da --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroObstaclesPanel.java @@ -0,0 +1,191 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked + * to creating an obstacle are present, such as the X-/Y-Coordinates. + */ +public class EnviroObstaclesPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // list of components needed to create an obstacle + JComboBox obstacleType; + JComboBox obstacleRotation; + JComboBox obstacleX; + JComboBox obstacleY; + JComboBox obstacleL; + JComboBox obstacleW; + JButton create; + + String[] obsType = {"Rectangular", "Circular"}; + ArrayList params; + + /** + * Constructor creates the Obstacles section of the EnvironmentEditorPanel. + */ + public EnviroObstaclesPanel() { + initComponents(); + } + + /** + * Method creates the labels and drop-downs associated with creating obstacles. + */ + public void initComponents() { + setBounds(5,30,240,205); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + // makes labels specific to creating obstacles + JLabel l = new JLabel("Object Type:"); + l.setBounds(5,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Rotation (Degrees):"); + l.setBounds(125,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Coordinate:"); + l.setBounds(5,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Coordinate:"); + l.setBounds(125,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Length:"); + l.setBounds(5,110,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Width:"); + l.setBounds(125,110,(this.getWidth()/2),25); + add(l); + + // makes the drop-downs needed to creating obstacles + obstacleType = new JComboBox(obsType); + obstacleType.setBounds(5,30,(int)(this.getWidth()/2.2),25); + add(obstacleType); + + obstacleRotation = new JComboBox(); + obstacleX = new JComboBox(); + obstacleY = new JComboBox(); + obstacleL = new JComboBox(); + obstacleW = new JComboBox(); + create = new JButton("Create"); + obstaclesParam(); // populates the drop-down information + createButton(); // makes a Create button + + //EnviroAddiParamPanel test = new EnviroAddiParamPanel(); + //add(test); + } + + /** + * Method adjusts the obstacle's settings to be within the limit of the environment's size. It also provides + * a real-time update of the obstacle parameters to prevent them from exceeding the environment's boundaries. + */ + public void obstaclesParam() { + // each drop-down first gets all items removed from it, then gets + // populated with items all dependent on the environment boundaries + obstacleRotation.removeAllItems(); + for (int i = 0; i <= 360; i++) { + obstacleRotation.addItem(Float.valueOf(i));} + obstacleRotation.setBounds(125,30,(int)(this.getWidth()/2.2),25); + add(obstacleRotation); + + obstacleX.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + obstacleX.addItem(Float.valueOf(i));} + obstacleX.setBounds(5,85,(int)(this.getWidth()/2.2),25); + add(obstacleX); + + obstacleY.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + obstacleY.addItem(Float.valueOf(i));} + obstacleY.setBounds(125,85,(int)(this.getWidth()/2.2),25); + add(obstacleY); + + obstacleL.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + obstacleL.addItem(Float.valueOf(i));} + obstacleL.setBounds(5,135,(int)(this.getWidth()/2.2),25); + add(obstacleL); + + obstacleW.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + obstacleW.addItem(Float.valueOf(i));} + obstacleW.setBounds(125,135,(int)(this.getWidth()/2.2),25); + add(obstacleW); + + // sets the default parameters even after an environment size change + resetObstacles(); + } + + /** + * Method used to call the editor panel to make a Create button for Obstacles. + */ + public void createButton() { + // button creates the obstacle according to the parameters set + create.setBounds(65,170,(int)(this.getWidth()/2.2),25); + create.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + createObstacle(false); + } + }); + add(create); + } + + /** + * Method packages data and sends it to editor to check if valid and + * to be added into obstacle list. + */ + public void createObstacle(boolean update){ + params = new ArrayList(); + params.add((Float) obstacleX.getSelectedItem()); + params.add((Float) obstacleY.getSelectedItem()); + params.add((Float) obstacleL.getSelectedItem()); + params.add((Float) obstacleW.getSelectedItem()); + params.add((Float) obstacleRotation.getSelectedItem()); + LiquidApplication.getGUI().enviroeditor.checkBoundaries(obstacleType, params, update); + } + + /** + * Method splits up the String[] of the log file in order to correctly set + * the parameters of the Obstacles section of the EnvironmentEditorPanel. + * + * @param tokens - String[] of the log file to split + */ + public void updateObstacles(String[] tokens) { + try { + obstacleType.setSelectedItem(tokens[0]); + obstacleX.setSelectedItem(Float.parseFloat(tokens[1])); + obstacleY.setSelectedItem(Float.parseFloat(tokens[2])); + obstacleL.setSelectedItem(Float.parseFloat(tokens[3])); + obstacleW.setSelectedItem(Float.parseFloat(tokens[4])); + obstacleRotation.setSelectedItem(Float.parseFloat(tokens[5])); + } catch (Exception e) { + e.printStackTrace();} + } + + /** + * Method resets the parameters of the Obstacles section. + */ + public void resetObstacles() { + obstacleType.setSelectedIndex(0); + obstacleRotation.setSelectedIndex(0); + obstacleX.setSelectedIndex(0); + obstacleY.setSelectedIndex(0); + obstacleL.setSelectedIndex((int) (EnvironmentEditorPanel.enviroLenLimit/10)); + obstacleW.setSelectedIndex((int) (EnvironmentEditorPanel.enviroWidLimit/8)); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroSensorsPanel.java b/LIQUID/src/liquid/gui/EnviroSensorsPanel.java new file mode 100644 index 0000000..89f3295 --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroSensorsPanel.java @@ -0,0 +1,141 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class is a branch of the EnvironmentEditorPanel. Here, all elements + * linked to creating a sensor are present, such as the X-/Y-Coordinates. + */ +public class EnviroSensorsPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // list of components needed to create a source + JComboBox sensorType; + JComboBox sensorX; + JComboBox sensorY; + String[] senType = {"Flowmeter"}; // changed to "Flowmeter" without space to fix "flowmeters" not being rendered + ArrayList params; + + /** + * Constructor creates the Sensors (or Flow Sensors) section of the EnvironmentEditorPanel. + */ + public EnviroSensorsPanel() { + initComponents(); + } + + /** + * Method creates the labels and drop-downs associated with creating sensors. + */ + public void initComponents() { + setBounds(5,30,240,205); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + // makes labels specific to creating sensors + JLabel l = new JLabel("Object Type:"); + l.setBounds(35,5,(int)(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Coordinate:"); + l.setBounds(5,30,(int)(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Coordinate:"); + l.setBounds(125, 30, 110, 25); + add(l); + + // makes the drop-downs needed to creating sensors + sensorType = new JComboBox(senType); + sensorType.setBounds(115,5,(int)(this.getWidth()/2),25); + add(sensorType); + + sensorX = new JComboBox(); + sensorY = new JComboBox(); + sensorsParam(); // populates the drop-down information + createButton(); // creates the Create button + } + + /** + * Method adjusts the sensor's settings to be within the limit of the environment's size. It also provides + * a real-time update of the sensor parameters to prevent them from exceeding the environment's boundaries. + */ + public void sensorsParam() { + // each drop-down first gets all items removed from it, then gets + // populated with items all dependent on the environment boundaries + sensorX.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + sensorX.addItem(Float.valueOf(i));} + sensorX.setBounds(5,55,(int)(this.getWidth()/2.2),25); + add(sensorX); + + sensorY.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + sensorY.addItem(Float.valueOf(i));} + sensorY.setBounds(125,55,(int)(this.getWidth()/2.2),25); + add(sensorY); + + // sets the default parameters even after an environment size change + resetSensors(); + } + + /** + * Method creates the Create button to add in a sensor. + */ + public void createButton() { + // button creates the obstacle according to the parameters set + JButton create = new JButton("Create"); + create.setBounds(65,90,(int)(this.getWidth()/2.2),25); + create.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + createSensor(false); + } + }); + add(create); + } + + /** + * Method packages data and sends it to editor to check if valid and + * to be added into object list. + */ + public void createSensor(boolean update){ + params = new ArrayList(); + params.add((Float) sensorX.getSelectedItem()); + params.add((Float) sensorY.getSelectedItem()); + LiquidApplication.getGUI().enviroeditor.checkBoundaries(sensorType, params, update); + } + + /** + * Method splits up the String[] of the log file in order to correctly set + * the parameters of the Sensors section of the EnvironmentEditorPanel. + * + * @param tokens - String[] of the log file to split + */ + public void updateSensors(String[] tokens) { + try { + sensorType.setSelectedItem(tokens[0]); + sensorX.setSelectedItem(Float.parseFloat(tokens[1])); + sensorY.setSelectedItem(Float.parseFloat(tokens[2])); + } catch (Exception e) { + e.printStackTrace();} + } + + /** + * Method resets the parameters of the Sensors section. + */ + public void resetSensors() { + sensorType.setSelectedIndex(0); + sensorX.setSelectedIndex(0); + sensorY.setSelectedIndex(0); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroSources.java b/LIQUID/src/liquid/gui/EnviroSources.java deleted file mode 100644 index 1de03d0..0000000 --- a/LIQUID/src/liquid/gui/EnviroSources.java +++ /dev/null @@ -1,137 +0,0 @@ -package liquid.gui; - -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import liquid.core.LiquidApplication; - -/** - * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked - * to creating a source are present, such as the force in the X-/Y-Coordinates. - */ -public class EnviroSources extends JPanel { - - private static final long serialVersionUID = 1L; - - // list of components needed to create a source - JComboBox forceType; - JTextField forceX; - JTextField forceY; - JTextField forceXComp; - JTextField forceYComp; - String[] fotype = {"Source"}; - - /** - * Constructor creates the Source (or Initial Force) section of the EnvironmentEditorPanel. - */ - public EnviroSources() { - initComponents(); - } - - /** - * Method creates the labels and drop-downs associated with creating sources. - */ - public void initComponents() { - setBounds(5,30,240,175); - setBackground(Color.LIGHT_GRAY); - setLayout(null); - setVisible(false); - - // makes labels specific to creating sources - JLabel l = new JLabel("Object Type:"); - l.setBounds(35,5,(this.getWidth()/2),25); - add(l); - - l = new JLabel("X-Coordinate:"); - l.setBounds(5,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Y-Coordinate:"); - l.setBounds(125,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Force-X:"); - l.setBounds(5,80,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Force-Y:"); - l.setBounds(125,80,(this.getWidth()/2),25); - add(l); - - // makes the drop-downs needed to create sources - forceType = new JComboBox(fotype); - forceType.setSelectedIndex(0); - forceType.setBounds(115, 5, 110, 25); - add(forceType); - - forceX = new JTextField("0"); - forceX.setBounds(5, 55, 110, 25); - add(forceX); - - forceY = new JTextField("0"); - forceY.setBounds(125, 55, 110, 25); - add(forceY); - - forceXComp = new JTextField("10"); - forceXComp.setBounds(5, 105, 110, 25); - add(forceXComp); - - forceYComp = new JTextField("10"); - forceYComp.setBounds(125, 105, 110, 25); - add(forceYComp); - - JButton create = new JButton("Create"); - create.setBounds(65, 140, 110, 25); - create.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - try { - String arg = forceType.getSelectedItem() + " " + - Float.parseFloat(forceX.getText()) + " " + Float.parseFloat(forceY.getText()) + " " + - Float.parseFloat(forceXComp.getText()) + " " + Float.parseFloat(forceYComp.getText()); - LiquidApplication.getGUI().variables.objects.add(arg); - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } catch (Exception e) { - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - add(create); - } - - /** - * Method splits up the String[] of the log file in order to correctly set - * the parameters of the Sources section of the EnvironmentEditorPanel. - * - * @param tokens - String[] of the log file to split - */ - public void updateSources(String[] tokens) { - try { - forceType.setSelectedItem(tokens[0]); - forceX.setText(tokens[1]); - forceY.setText(tokens[2]); - forceXComp.setText(tokens[3]); - forceYComp.setText(tokens[4]); - } catch (Exception e) { - e.printStackTrace();} - } - - /** - * Method resets the parameters of the Sources section. - */ - public void resetSources() { - forceType.setSelectedIndex(0); - forceX.setText("0"); - forceY.setText("0"); - forceXComp.setText("10"); - forceYComp.setText("10"); - } -} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java b/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java index a3b52fb..6df79b3 100644 --- a/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java +++ b/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java @@ -8,75 +8,60 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JTextField; import liquid.core.LiquidApplication; +/** + * Class stores the details of the EnvironmentEditorPanel section of the ParameterPanel + * class. Here, users will be able to create obstacles, liquid sources, or flow meters. + */ public class EnvironmentEditorPanel extends JPanel { private static final long serialVersionUID = 1L; String[] options = {"Environment", "Obstacles", "Initial Forces", "Flow Sensors"}; - JComboBox select; + + // defines parameters needed to adjust the environment size JPanel enviro; JComboBox enviroLen; JComboBox enviroWid; static float enviroLenLimit = 500; static float enviroWidLimit = 400; - EnviroObstacles obstacles; - EnviroSources forces; - - JPanel sensors; - JComboBox sensorType; - JTextField sensorX; - JTextField sensorY; + // creates the Obstacles, Forces, and Sensors parts of the panel + EnviroObstaclesPanel obstacles; + EnviroForcesPanel forces; + EnviroSensorsPanel sensors; + EnviroAddiParamPanel addiParam; + /** + * Constructor sets up the EnvironmentEditorPanel part of the ParameterPanel. It + * is currently located around the center part of the right side of the simulator. + */ public EnvironmentEditorPanel() { super(); initComponents(); setLayout(null); setBackground(Color.GRAY); - setBounds(25, 150, 250, 310); + setBounds(25,150,250,310); setVisible(true); } + /** + * Sets up some of the components of the EnvironmentEditorPanel. + */ public void initComponents() { Font font = new Font("Verdana", Font.BOLD, 12); setFont(font); - ActionListener snext = new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (LiquidApplication.getGUI().variables.selectedObject < LiquidApplication.getGUI().variables.objects.size()-1){ - LiquidApplication.getGUI().variables.selectedObject += 1; - } else { - LiquidApplication.getGUI().variables.selectedObject = 0; - } - update(); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }; - - ActionListener sprev = new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if( LiquidApplication.getGUI().variables.selectedObject > 0) { - LiquidApplication.getGUI().variables.selectedObject -= 1; - } else { - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; - } - update(); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }; - // sets the overall drop-down options for the EnvironmentEditorPanel select = new JComboBox(options); select.setBounds(5,5,240,25); @@ -96,21 +81,50 @@ public void itemStateChanged(ItemEvent arg0) { }); add(select); + // creates the Environment section + createEnvironment(); + + // creates the Obstacle section, which represents the EnviroObstacles class + obstacles = new EnviroObstaclesPanel(); + obstacles.setVisible(false); + add(obstacles); + + // creates the Initial Forces section, which represents the EnviroForces class + forces = new EnviroForcesPanel(); + forces.setVisible(false); + add(forces); + + // creates the Flow Sensors section, which represents the EnviroSensors class + sensors = new EnviroSensorsPanel(); + sensors.setVisible(false); + add(sensors); + + // creates the additional set of parameters + addiParam = new EnviroAddiParamPanel(); + addiParam.setVisible(true); + add(addiParam); + } + + /** + * Method creates the parameters to set the length/width of the simulating environment + * itself. A new method is created to provide flexibility in where it is created. + */ + public void createEnvironment() { // creates the Environment section, which sets the length/width of the environment enviro = new JPanel(); - enviro.setBounds(5,30,240,275); + enviro.setBounds(5,30,240,205); enviro.setBackground(Color.LIGHT_GRAY); enviro.setLayout(null); - + // makes labels for creating an environment JLabel l = new JLabel("Length:"); l.setBounds(5,0,110,25); enviro.add(l); - + l = new JLabel("Width:"); l.setBounds(5,50,110,25); enviro.add(l); - + // makes drop-downs for creating an environment enviroLen = new JComboBox(); for (int i = 0; i <= enviroLenLimit; i++) { @@ -118,285 +132,140 @@ public void itemStateChanged(ItemEvent arg0) { enviroLen.setSelectedIndex((int) enviroLenLimit); enviroLen.setBounds(5,25,110,25); enviro.add(enviroLen); - + enviroWid = new JComboBox(); for (int i = 0; i <= enviroWidLimit; i++) { enviroWid.addItem(Float.valueOf(i));} enviroWid.setSelectedIndex((int) enviroWidLimit); enviroWid.setBounds(5,75,110,25); enviro.add(enviroWid); - + // draws the size of the environment based on the parameters set JButton draw = new JButton("Draw"); draw.setBounds(5,125,110,25); draw.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - // sets the length/width according to the drop-downs - LiquidApplication.getGUI().variables.enviroLength = (float) enviroLen.getSelectedItem(); - LiquidApplication.getGUI().variables.enviroWidth = (float) enviroWid.getSelectedItem(); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - - // resets the limits to adjust the boundaries of creating various objects - enviroLenLimit = (float) enviroLen.getSelectedItem(); - enviroWidLimit = (float) enviroWid.getSelectedItem(); - obstacles.adjustSettings(); + public void actionPerformed(ActionEvent actionEvent) { + // sets the length/width according to the drop-downs + LiquidApplication.getGUI().variables.enviroLength = (float) enviroLen.getSelectedItem(); + LiquidApplication.getGUI().variables.enviroWidth = (float) enviroWid.getSelectedItem(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + + // resets the limits to adjust the boundaries of creating various objects + enviroLenLimit = (float) enviroLen.getSelectedItem(); + enviroWidLimit = (float) enviroWid.getSelectedItem(); + obstacles.obstaclesParam(); + forces.forcesParam(); + sensors.sensorsParam(); } - }); + }); enviro.add(draw); add(enviro); - - // creates the Obstacle section, which represents the EnviroObstacle class - obstacles = new EnviroObstacles(); - obstacles.setVisible(false); - add(obstacles); - - // creates the Initial Forces section, which represents the EnviroSource class - forces = new EnviroSources(); - add(forces); - - /**JButton selectNext = new JButton("Next Object"); - selectNext.setBounds(5, 200, 110, 25); - selectNext.addActionListener(snext); - obstacles.add(selectNext); - - JButton selectPrev = new JButton("Prev Object"); - selectPrev.setBounds(125, 200, 110, 25); - selectPrev.addActionListener(sprev); - obstacles.add(selectPrev); - - JButton selectUpdate = new JButton("Update Obj"); - selectUpdate.setBounds(5, 240, 110, 25); - selectUpdate.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = obstacleType.getSelectedItem() + " "; - arg += Float.parseFloat(obstacleX.getText()) + " "; - arg += Float.parseFloat(obstacleY.getText()) + " "; - arg += Float.parseFloat(obstacleL.getText()) + " "; - arg += Float.parseFloat(obstacleW.getText()); - LiquidApplication.getGUI().variables.objects.add(LiquidApplication.getGUI().variables.selectedObject, arg); - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject+1); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - obstacles.add(selectUpdate); - - JButton delete = new JButton("Delete"); - delete.setBounds(125, 240, 110, 25); - delete.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); - LiquidApplication.getGUI().variables.selectedObject = 0; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }); - obstacles.add(delete); - obstacles.setVisible(false); - add(obstacles); */ - - - - /**JButton selectNext = new JButton("Next Force"); - selectNext.setBounds(5, 200, 110, 25); - selectNext.addActionListener(snext); - forces.add(selectNext); - - JButton selectPrev = new JButton("Prev Force"); - selectPrev.setBounds(125, 200, 110, 25); - selectPrev.addActionListener(sprev); - forces.add(selectPrev); - - JButton selectUpdate = new JButton("Update For"); - selectUpdate.setBounds(5, 240, 110, 25); - selectUpdate.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = forceType.getSelectedItem() + " "; - arg += Float.parseFloat(forceX.getText()) + " "; - arg += Float.parseFloat(forceY.getText()) + " "; - arg += Float.parseFloat(forceXComp.getText()) + " "; - arg += Float.parseFloat(forceYComp.getText()); - LiquidApplication.getGUI().variables.objects.add(LiquidApplication.getGUI().variables.selectedObject, arg); - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject+1); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - forces.add(selectUpdate); - - JButton delete = new JButton("Delete"); - delete.setBounds(125, 240, 110, 25); - delete.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); - LiquidApplication.getGUI().variables.selectedObject = 0; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }); - forces.add(delete); - add(forces);*/ - - sensors = new JPanel(); - sensors.setBounds(5, 30, 240, 275); - sensors.setLayout(null); - sensors.setBackground(Color.LIGHT_GRAY); - - l = new JLabel("Object Type:"); - l.setBounds(35, 5, 110, 25); - sensors.add(l); - - l = new JLabel("X:"); - l.setBounds(5, 30, 110, 25); - sensors.add(l); - - l = new JLabel("Y:"); - l.setBounds(125, 30, 110, 25); - sensors.add(l); - - String[] sentype = {"Flowmeter"}; //changed to "Flowmeter" without space to fix flowmeters not being rendered - sensorType = new JComboBox(sentype); - sensorType.setBounds(115, 5, 110, 25); - sensors.add(sensorType); - - sensorX = new JTextField("0"); - sensorX.setBounds(5, 55, 110, 25); - sensors.add(sensorX); - - sensorY = new JTextField("0"); - sensorY.setBounds(125, 55, 110, 25); - sensors.add(sensorY); - - JButton create = new JButton("Create"); - create.setBounds(65, 90, 110, 25); - create.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = sensorType.getSelectedItem() + " "; - arg += Float.parseFloat(sensorX.getText()) + " "; - arg += Float.parseFloat(sensorY.getText()); - LiquidApplication.getGUI().variables.objects.add(arg); - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - sensors.add(create); - - - JButton selectNext = new JButton("Next Sensor"); - selectNext.setBounds(5, 200, 110, 25); - selectNext.addActionListener(snext); - sensors.add(selectNext); - - JButton selectPrev = new JButton("Prev Sensor"); - selectPrev.setBounds(125, 200, 110, 25); - selectPrev.addActionListener(sprev); - sensors.add(selectPrev); - - JButton selectUpdate = new JButton("Update Sen"); - selectUpdate.setBounds(5, 240, 110, 25); - selectUpdate.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = sensorType.getSelectedItem() + " "; - arg += Float.parseFloat(sensorX.getText()) + " "; - arg += Float.parseFloat(sensorY.getText()); - LiquidApplication.getGUI().variables.objects.add(LiquidApplication.getGUI().variables.selectedObject, arg); - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject+1); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } + } + + /** + * Method checks the boundaries of the environment and throws error messages + * when the obstacle will go out of the predefined environment size. + * + * For the ArrayList: + * - 1 - X-Coordinate of Obstacle/Force + * - 2 - Y-Coordinate of Obstacle/Force + * - 3 - Length of Obstacle/X-Force of Force + * - 4 - Width of Obstacle/Y-Force of Force + * - 5 - Rotation of Obstacle/Flow Speed of Force + */ + public void checkBoundaries(JComboBox type, ArrayList params, boolean update) { + // throws error messages when the obstacle will go beyond the environment (determined + // by the X-/Y-Coordinates and the Length/Width of the obstacle, respectively) + if ((type.getSelectedItem().equals("Rectangular") || type.getSelectedItem().equals("Circular")) + &&(params.get(0) + params.get(2) > enviroLenLimit)) { + JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, + "Warning!! Your X-Coordinate must be from 0.0 - " + (enviroLenLimit - params.get(2)) + + ",\n or our Length must be from 0.0 - " + (enviroLenLimit - params.get(0)) + + "\n to be in the boundaries of your desired environment size.", + "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); + } else if ((type.getSelectedItem().equals("Rectangular") || type.getSelectedItem().equals("Circular")) + &&(params.get(1) + params.get(3) > enviroWidLimit)) { + JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, + "Warning!! Your Y-Coordinate must be from 0.0 - " + (enviroWidLimit - params.get(3)) + + ",\n or your Width must be from 0.0 - " + (enviroWidLimit - params.get(1)) + + "\n to be in the boundaries of your desired environment size.", + "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); + + // else sends the obstacle's information to the ArrayList of objects to store + } else { + String arg = type.getSelectedItem() + ""; + for(int i = 0; i < params.size(); i++) arg += " " + params.get(i); + if(update){ + LiquidApplication.getGUI().variables.objects.set(LiquidApplication.getGUI().variables.selectedObject, arg); + }else{ + LiquidApplication.getGUI().variables.objects.add(arg); + LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size() - 1; } - }); - sensors.add(selectUpdate); - - JButton delete = new JButton("Delete"); - delete.setBounds(125, 240, 110, 25); - delete.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); - LiquidApplication.getGUI().variables.selectedObject = 0; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + } + + /** + * Method enables/disables the components of the EnvironmentEditorPanel. + */ + public void setEnabled(boolean enable) { + for (Component x : getComponents()) { + x.setEnabled(enable); + if (x instanceof Container) { + for (Component y : ((Container) x).getComponents()) { + y.setEnabled(enable);} } - }); - sensors.add(delete); - sensors.setVisible(false); - add(sensors); + } } - public void update(){ + /** + * Method updates the simulation with the information presented in the log file. + */ + public void update() { enviroLen.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroLength)); enviroWid.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroWidth)); - try{ + try { + // obtains the line of parameters associated with a EnvironmentEditorPanel item String[] tokens = LiquidApplication.getGUI().variables.objects.get(LiquidApplication.getGUI().variables.selectedObject).split(" "); - if(tokens[0].equals("Rectangular") || tokens[0].equals("Circular")){ + // creates obstacle items, if any present + if (tokens[0].equals("Rectangular") || tokens[0].equals("Circular")) { select.setSelectedItem("Obstacles"); + obstacles.setVisible(true); forces.setVisible(false); sensors.setVisible(false); - obstacles.setVisible(true); - obstacles.updateObstacles(tokens); - } - if(tokens[0].equals("Source")){ + + // creates source items, if any present + } else if (tokens[0].equals("Source")) { select.setSelectedItem("Initial Forces"); + obstacles.setVisible(false); forces.setVisible(true); sensors.setVisible(false); + forces.updateForces(tokens); + + // creates flow meter items, if any present + } else if (tokens[0].equals("Flowmeter")) { + select.setSelectedItem("Flow Sensors"); obstacles.setVisible(false); - - forces.updateSources(tokens); - - } - if(tokens[0].equals("Flowmeter")){ - select.setSelectedItem("Sensors"); sensors.setVisible(true); forces.setVisible(false); - obstacles.setVisible(false); - sensorType.setSelectedItem(tokens[0]); - sensorX.setText(tokens[1]); - sensorY.setText(tokens[2]); + sensors.updateSensors(tokens); } - }catch(Exception e){ - e.printStackTrace(); - } + } catch(Exception e) { + e.printStackTrace();} } - public void reset(){ - enviroLen.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroLength)); - enviroWid.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroWidth)); + /** + * Resets all parts of the EnvironmentEditorPanel to its default settings. + */ + public void reset() { select.setSelectedItem("Environment"); - + enviroLen.setSelectedItem(enviroLenLimit); + enviroWid.setSelectedItem(enviroWidLimit); obstacles.resetObstacles(); - forces.resetSources(); - - sensorType.setSelectedIndex(0); - sensorX.setText("0"); - sensorY.setText("0"); - } - - public void setEnabled(boolean enable){ - for(Component x : getComponents()){ - x.setEnabled(enable); - if(x instanceof Container){ - for(Component y : ((Container) x).getComponents()){ - y.setEnabled(enable); - } - } - } + forces.resetForces(); + sensors.resetSensors(); } } \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/LiquidFrame.java b/LIQUID/src/liquid/gui/LiquidFrame.java index 3788495..9c91439 100644 --- a/LIQUID/src/liquid/gui/LiquidFrame.java +++ b/LIQUID/src/liquid/gui/LiquidFrame.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import javax.swing.JFrame; @@ -35,7 +36,6 @@ public void dispose() { JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (exitSim == JOptionPane.YES_OPTION) { super.dispose(); - LiquidApplication.dispose(); - } + LiquidApplication.dispose();} } } \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/LiquidGUI.java b/LIQUID/src/liquid/gui/LiquidGUI.java index 11e7b2c..4476970 100644 --- a/LIQUID/src/liquid/gui/LiquidGUI.java +++ b/LIQUID/src/liquid/gui/LiquidGUI.java @@ -159,7 +159,8 @@ public void reset() { param.reset(); } - public void dispose() { - - } + /** + * Represents a placeholder method for when necessary to dispose something. + */ + public void dispose() {} } \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/LiquidGuiVariables.java b/LIQUID/src/liquid/gui/LiquidGuiVariables.java index 77e4f31..1d6897b 100644 --- a/LIQUID/src/liquid/gui/LiquidGuiVariables.java +++ b/LIQUID/src/liquid/gui/LiquidGuiVariables.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import java.util.ArrayList; @@ -115,7 +116,7 @@ public void saveState() { } /** - * Un-does the lastest change made by the user. + * Un-does the latest change made by the user. */ public void undo() { // if there are unsaved changes, the latest changes will get be popped @@ -126,7 +127,7 @@ public void undo() { } /** - * Re-does the lastest change made by the user. + * Re-does the latest change made by the user. */ public void redo() { // if a set of un-did changes is present, then those set of parameters diff --git a/LIQUID/src/liquid/gui/LiquidMenuBar.java b/LIQUID/src/liquid/gui/LiquidMenuBar.java index 046fcf3..6c88452 100644 --- a/LIQUID/src/liquid/gui/LiquidMenuBar.java +++ b/LIQUID/src/liquid/gui/LiquidMenuBar.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import java.awt.Font; diff --git a/LIQUID/src/liquid/gui/ParameterPanel.java b/LIQUID/src/liquid/gui/ParameterPanel.java index a2fbdbf..7e124d8 100644 --- a/LIQUID/src/liquid/gui/ParameterPanel.java +++ b/LIQUID/src/liquid/gui/ParameterPanel.java @@ -256,7 +256,6 @@ public void update() { time.setSelectedItem(LiquidApplication.getGUI().variables.runtime); temp.setSelectedItem(LiquidApplication.getGUI().variables.temperature); visc.setSelectedItem(LiquidApplication.getGUI().variables.viscosity); - System.out.println(LiquidApplication.getGUI().variables.runtime); } /** diff --git a/LIQUID/src/liquid/logger/LiquidFileWriter.java b/LIQUID/src/liquid/logger/LiquidFileWriter.java index 07ec99d..22bb61e 100644 --- a/LIQUID/src/liquid/logger/LiquidFileWriter.java +++ b/LIQUID/src/liquid/logger/LiquidFileWriter.java @@ -20,7 +20,7 @@ public class LiquidFileWriter { * represent the log file, which stores all parameter information. * * @param fileName - the file's name to store in - * @param args - the String[] of parameters + * @param args - the String[] of parameters */ public void writetoLogFile(String fileName, String args[]) { try { @@ -53,8 +53,8 @@ public void appendtoLogFile(String fileName, String arg){ * is saved in the correct directory and whether or not it will override an existing file. * * @param fileDialog - uses same JFileChooser to keep consistency - * @param frame - the frame with which to display - * @return - String name of the file + * @param frame - the frame with which to display + * @return - String name of the file */ public String setUpFileToSave(JFileChooser fileDialog, Component frame) { File origFile = fileDialog.getCurrentDirectory(); diff --git a/logs/test.log b/logs/test.log index 3134f6d..33dd54e 100644 --- a/logs/test.log +++ b/logs/test.log @@ -1,9 +1,11 @@ C:\Users\Lauren\Documents\GitHub\AtlasSoft\logs\test.log Water -0 +2 70.0 1.0 300 -460.0 400.0 -Rectangular 0.0 0.0 50.0 50.0 +500.0 400.0 +Rectangular 75.0 0.0 50.0 89.0 0.0 +Source 270.0 276.0 172.0 2.0 20.0 +Source 67.0 46.0 99.0 149.0 50.0 break diff --git a/logs/test1.log b/logs/test1.log index 35d1518..7b725c5 100644 --- a/logs/test1.log +++ b/logs/test1.log @@ -1,15 +1,16 @@ C:\Users\GameDesign\Documents\GitHub\AtlasSoft\logs\test1.log Glycerin 6 -50.0 +53.0 2.0 15 400.0 300.0 -Rectangular 0 0 400 50 -Rectangular 0 250 400 50 -Rectangular 0 100 50 150 -Rectangular 350 50 50 150 -Rectangular 150.0 100.0 100.0 100.0 -Source 375.0 225.0 -100.0 0.0 -Source 25.0 75.0 100.0 0.0 +Rectangular 0 0 400 50 0.0 +Rectangular 0 250 400 50 0.0 +Rectangular 0 100 50 150 0.0 +Rectangular 350 50 50 150 0.0 +Rectangular 150.0 100.0 100.0 100.0 0.0 +Source 375.0 225.0 -100.0 0.0 10.0 +Source 25.0 75.0 100.0 0.0 10.0 +Circular 150.0 60.0 100.0 100.0 0.0 break diff --git a/logs/test2.log b/logs/test2.log index 53cbbad..2169028 100644 --- a/logs/test2.log +++ b/logs/test2.log @@ -1,10 +1,9 @@ C:\Users\GameDesign\Documents\GitHub\AtlasSoft\logs\test2.log Water -1 +0 70.0 1.0 -300 -300.0 300.0 -Rectangular 0.0 0.0 50.0 50.0 -Source 299.0 299.0 -100.0 -100.0 +15 +500.0 400.0 +Source 50.0 50.0 1.0 1.0 100.0 break diff --git a/logs/test3.log b/logs/test3.log index db9fc58..2becdf2 100644 --- a/logs/test3.log +++ b/logs/test3.log @@ -1,8 +1,17 @@ -C:\Users\Lauren\Documents\GitHub\AtlasSoft\logs\test3.log -Water -0 -70.0 -1.0 -300 -500.0 400.0 +C:\Users\Will\Documents\GitHub\AtlasSoft\logs\test3.log +Glycerin +8 +53.0 +2.0 +15 +400.0 300.0 +Rectangular 0 0 400 50 0.0 +Rectangular 0 250 400 50 0.0 +Rectangular 0 100 50 150 0.0 +Rectangular 350 50 50 150 0.0 +Rectangular 150.0 100.0 100.0 100.0 0.0 +Source 375.0 225.0 -100.0 0.0 10.0 +Source 25.0 75.0 100.0 0.0 10.0 +Circular 150.0 60.0 100.0 100.0 0.0 +Flowmeter 246.0 60.0 break diff --git a/logs/test4.log b/logs/test4.log deleted file mode 100644 index 89c1e3a..0000000 --- a/logs/test4.log +++ /dev/null @@ -1,16 +0,0 @@ -C:\Users\billi\Documents\GitHub\AtlasSoft\logs\test4.log -Glycerin -1 -50.0 -2.0 -15 -400.0 300.0 -Rectangular 0 0 400 50 -Rectangular 0 250 400 50 -Rectangular 0 100 50 150 -Rectangular 350 50 50 150 -Rectangular 150.0 100.0 100.0 100.0 -Source 375.0 225.0 -100.0 0.0 -Source 25.0 75.0 100.0 0.0 -Flowmeter 260.0 148.0 -break