Преглед изворни кода

fully function menubar (except choosing the algorithms)

Kevin Trometer пре 7 година
родитељ
комит
77cf76d4b0

+ 15 - 0
src/ui/controller/Control.java

@@ -319,4 +319,19 @@ public class Control {
 	public void clearConsole() {
 		consoleController.clearConsole();
 	}
+	
+	/**
+	 * @return sets the timerSpeed
+	 */
+	public void setTimerSpeed(int t) {
+		globalController.setTimerSpeed(t);
+	}
+	
+	/**
+	 * @param isSimulation
+	 *            boolean for for isSimulation
+	 */
+	public void setIsSimulation(boolean b) {
+		globalController.setIsSimulation(b);
+	}
 }

+ 33 - 14
src/ui/controller/GlobalController.java

@@ -15,53 +15,72 @@ public class GlobalController {
 	 * 
 	 * @return SCALE
 	 */
-	public int getScale(){
+	public int getScale() {
 		return MODEL.getScale();
 	}
-	
+
 	/**
 	 * Returns SCALE Divided by 2
 	 * 
 	 * @return SCALE Divided by 2
 	 */
-	public int getScaleDiv2(){
+	public int getScaleDiv2() {
 		return MODEL.getScaleDiv2();
 	}
-	
+
 	/**
 	 * Changes the value of SCALE and SCALEDIV2
 	 * 
-	 * @param int Scale
+	 * @param int
+	 *            Scale
 	 */
-	public void setScale(int s){
+	public void setScale(int s) {
 		MODEL.setScale(s);
 	}
-	
+
 	/**
 	 * sets the current Iteration
 	 * 
-	 * @param cur_it, the current Iteration
+	 * @param cur_it,
+	 *            the current Iteration
 	 */
 	public void setCurIteration(int cur_it) {
 		MODEL.setCurIteration(cur_it);
 	}
-	
+
 	/**
 	 * Returns numberOfSaves
 	 * 
 	 * @return numberOfSaves
 	 */
-	public int getNumbersOfSaves(){
+	public int getNumbersOfSaves() {
 		return MODEL.getNumberOfSaves();
 	}
-	
+
 	/**
 	 * sets the max number of autosaves
 	 * 
-	 * @param numberOfSaves, the max number of autosaves
+	 * @param numberOfSaves,
+	 *            the max number of autosaves
+	 */
+	public void setNumberOfSaves(int numberOfSaves) {
+		MODEL.setNumberOfSaves(numberOfSaves);
+		;
+	}
+
+	/**
+	 * @return sets the timerSpeed
+	 */
+	public void setTimerSpeed(int t) {
+		MODEL.setTimerSpeed(t);
+	}
+	
+	/**
+	 * @param isSimulation
+	 *            boolean for for isSimulation
 	 */
-	public void setNumberOfSaves(int numberOfSaves){
-		MODEL.setNumberOfSaves(numberOfSaves);;
+	public void setIsSimulation(boolean b) {
+		MODEL.setIsSimulation(b);
 	}
 
 }

+ 81 - 26
src/ui/model/Model.java

@@ -30,10 +30,16 @@ public class Model {
 	private ArrayList<CpsObject> clipboardObjects = new ArrayList<CpsObject>();
 	private Console console;
 
+	// Iteration Speed
+	private int timerSpeed = 1000;
+
+	// Simulation boolean
+	private boolean isSimulation = false;
+
 	private int selectedID = 0;
 	// number of the current autosave
 	private int autoSaveNr = -1;
-	// number of max simultaneous autosaves 
+	// number of max simultaneous autosaves
 	private int numberOfSaves = 35;
 	// eventuell wenn Canvasgröße gewählt werden kann
 	private int HEIGHT;
@@ -44,13 +50,12 @@ public class Model {
 	 */
 	private ArrayList<Category> categories;
 
-
 	/*
 	 * Array of all CpsObjects in our canvas. It is set by default as an empty
 	 * list.
 	 */
 	private ArrayList<CpsObject> objectsOnCanvas;
-	
+
 	private HashMap<String, Integer> cgIdx;
 	private HashMap<Integer, Integer> cvsObjIdx;
 
@@ -72,14 +77,14 @@ public class Model {
 	 * default values.
 	 */
 	public Model() {
-		
+
 		setCategories(new ArrayList<Category>());
 		setObjectsOnCanvas(new ArrayList<CpsObject>());
 		setEdgesOnCanvas(new ArrayList<CpsEdge>());
 		setCategoryListeners(new LinkedList<CategoryListener>());
 		setObjectListeners(new LinkedList<ObjectListener>());
-		setCgIdx(new HashMap<String,Integer>());
-		setCvsObjIdx(new HashMap<Integer,Integer>());
+		setCgIdx(new HashMap<String, Integer>());
+		setCvsObjIdx(new HashMap<Integer, Integer>());
 		setClipboradObjects(new ArrayList<CpsObject>());
 	}
 
@@ -218,7 +223,7 @@ public class Model {
 	public void setSelectedCpsObject(CpsObject selectedCpsObject) {
 		this.selectedCpsObject = selectedCpsObject;
 	}
-	
+
 	public ArrayList<CpsObject> getSelectedCpsObjects() {
 		return selectedObjects;
 	}
@@ -262,11 +267,12 @@ public class Model {
 	public int getIterations() {
 		return ITERATIONS;
 	}
-	
+
 	/**
 	 * sets the current Iteration
 	 * 
-	 * @param cur_it, the current Iteration
+	 * @param cur_it,
+	 *            the current Iteration
 	 */
 	public void setCurIteration(int cur_it) {
 		this.CUR_ITERATION = cur_it;
@@ -290,13 +296,13 @@ public class Model {
 	public void setSelectedEdge(CpsEdge edge) {
 		this.selectedEdge = edge;
 	}
-	
+
 	/**
 	 * Returns the selected Edge
 	 * 
 	 * @return selectedEdge
 	 */
-	public CpsEdge getSelectedEdge(){
+	public CpsEdge getSelectedEdge() {
 		return selectedEdge;
 	}
 
@@ -308,13 +314,13 @@ public class Model {
 	}
 
 	/**
-	 * @param cgIdx the cgIdx to set
+	 * @param cgIdx
+	 *            the cgIdx to set
 	 */
 	public void setCgIdx(HashMap<String, Integer> cgIdx) {
 		this.cgIdx = cgIdx;
 	}
 
-
 	/**
 	 * @return the cvsObjIdx
 	 */
@@ -323,17 +329,18 @@ public class Model {
 	}
 
 	/**
-	 * @param cvsObjIdx the cvsObjIdx to set
+	 * @param cvsObjIdx
+	 *            the cvsObjIdx to set
 	 */
 	public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
 		this.cvsObjIdx = cvsObjIdx;
 	}
-	
-	public void setAutoSaveNr(int autoSaveNr){
+
+	public void setAutoSaveNr(int autoSaveNr) {
 		this.autoSaveNr = autoSaveNr;
 	}
-	
-	public int getAutoSaveNr(){
+
+	public int getAutoSaveNr() {
 		return autoSaveNr;
 	}
 
@@ -345,25 +352,73 @@ public class Model {
 	}
 
 	/**
-	 * @param numberOfSaves the numberOfSaves to set
+	 * @param numberOfSaves
+	 *            the numberOfSaves to set
 	 */
 	public void setNumberOfSaves(int numberOfSaves) {
 		this.numberOfSaves = numberOfSaves;
 	}
 
-	public void setClipboradObjects(ArrayList<CpsObject> c){
+	/**
+	 * @param Objects
+	 *            Array of Objects
+	 */
+	public void setClipboradObjects(ArrayList<CpsObject> c) {
 		this.clipboardObjects = c;
 	}
-	
-	public ArrayList<CpsObject> getClipboradObjects(){
+
+	/**
+	 * 
+	 * @return Objects in the Clipboard
+	 */
+	public ArrayList<CpsObject> getClipboradObjects() {
 		return clipboardObjects;
 	}
-	
-	public void setConsole(Console console){
+
+	/**
+	 * 
+	 * @param console
+	 *            the console
+	 */
+	public void setConsole(Console console) {
 		this.console = console;
 	}
-	
-	public Console getConsole(){
+
+	/**
+	 * 
+	 * @return console the console
+	 */
+	public Console getConsole() {
 		return console;
 	}
+
+	/**
+	 * @param timerSpeed
+	 *            speed for the Iterations
+	 */
+	public void setTimerSpeed(int t) {
+		this.timerSpeed = t;
+	}
+
+	/**
+	 * @return timerSpeed speed for the Iterations
+	 */
+	public int getTimerSpeed() {
+		return this.timerSpeed;
+	}
+
+	/**
+	 * @param isSimulation
+	 *            boolean for for isSimulation
+	 */
+	public void setIsSimulation(boolean b) {
+		this.isSimulation = b;
+	}
+
+	/**
+	 * @return isSimulation boolean for for isSimulation
+	 */
+	public boolean getIsSimulation() {
+		return this.isSimulation;
+	}
 }

+ 2 - 2
src/ui/view/GUI.java

@@ -1465,11 +1465,11 @@ public class GUI<E> implements CategoryListener {
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
 
-		simulationSpeedField.setText(Integer.toString(timePanel.getTimerSpeed()));
+		simulationSpeedField.setText(Integer.toString(model.getTimerSpeed()));
 		btnApply.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
 				int speed = Integer.parseInt(simulationSpeedField.getText());
-				timePanel.setTimerSpeed(speed);
+				controller.setTimerSpeed(speed);
 				mnSimulationSpeed.setPopupMenuVisible(false);
 			}
 		});

+ 30 - 12
src/ui/view/SimulationMenu.java

@@ -8,14 +8,15 @@ import javax.swing.JRadioButton;
 import javax.swing.JTextField;
 import javax.swing.event.CaretEvent;
 import javax.swing.event.CaretListener;
-
-import com.sun.org.apache.regexp.internal.recompile;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 
 import ui.controller.Control;
 import ui.model.Model;
 import java.util.ArrayList;
 
 import java.awt.GridBagLayout;
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.Insets;
@@ -28,35 +29,52 @@ public class SimulationMenu extends JMenuBar {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	private Model model;
-	private Control controller;
-
 	// Components
 	private JPanel simMenuPanel = new JPanel();
 	private JRadioButton simButton = new JRadioButton("Simulate");
-	private JLabel simSpeedLabel = new JLabel("Simulation Speed: ");
-	private JTextField simSpeedText = new JTextField("10000000");
-	private JLabel algoLabel = new JLabel("Algorithm: ");
+	private JLabel simSpeedLabel = new JLabel("Simulation Speed:");
+	private JTextField simSpeedText = new JTextField("1000");
+	private JLabel algoLabel = new JLabel("Algorithm:");
 	private JComboBox algoCombo;
 	private ArrayList<String> algos = new ArrayList<>();
 
+	Model model;
+	Control controller;
+	
 	public SimulationMenu(Model mod, Control cont) {
 		super();
+		// Init Stuff
 		this.model = mod;
 		this.controller = cont;
-
-		// Init Stuff
+		
+		//AlgoCombobox Items
 		algos.add("algorithm1");
 		algos.add("algorithm2");
 		algos.add("algorithm3");
+		
+		//timerSpeed
 		simSpeedText.setMaximumSize(new Dimension(300, 300));
 		simSpeedText.addCaretListener(new CaretListener() {
-			
 			@Override
 			public void caretUpdate(CaretEvent e) {
-				System.out.println("test");
+				try {
+					controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
+				} catch (Exception e2) {
+					// TODO: handle exception
+				}
+				
+			}
+		});
+		
+		//isSimulation
+		simButton.addPropertyChangeListener(new PropertyChangeListener() {
+			
+			@Override
+			public void propertyChange(PropertyChangeEvent evt) {
+				controller.setIsSimulation(simButton.isSelected());
 			}
 		});
+		
 		// Add to Panel
 		JPanel menuPanel = new JPanel();
 		GridBagLayout gbl_t = new GridBagLayout();

+ 3 - 12
src/ui/view/TimePanel.java

@@ -33,7 +33,6 @@ public class TimePanel extends JPanel {
 	private final JButton timeBackwardBtn = new JButton();
 	private Timer timer;
 	private boolean running = false;
-	private int timerSpeed;
 
 	/**
 	 * 
@@ -44,14 +43,14 @@ public class TimePanel extends JPanel {
 		super();
 		this.model = mod;
 		this.controller = cont;
-		timerSpeed = 1000;
 
 		// One Iteration
-		timer = new Timer(timerSpeed, new ActionListener() {
+		timer = new Timer(model.getTimerSpeed(), new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() + 1);
 				controller.setCurIteration(timeSlider.getValue());
+				timer.setDelay(model.getTimerSpeed());
 				if (timeSlider.getValue() == model.getIterations() - 1) {
 					running = false;
 					playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/play.png"))
@@ -99,6 +98,7 @@ public class TimePanel extends JPanel {
 				running = !running;
 				if (running) {
 					timer.start();
+					timer.setDelay(model.getTimerSpeed());
 					playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/pause.png"))
 							.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
 				} else {
@@ -156,13 +156,4 @@ public class TimePanel extends JPanel {
 		this.add(timeBtnPanel, BorderLayout.WEST);
 		this.add(timeSlider);
 	}
-	
-	public int getTimerSpeed(){
-		return timerSpeed;
-	}
-	
-	public void setTimerSpeed(int toSet){
-		timerSpeed = toSet;
-		timer.setDelay(timerSpeed);
-	}
 }