dominik.rieder 8 лет назад
Родитель
Сommit
af1f629412
2 измененных файлов с 39 добавлено и 7 удалено
  1. 27 6
      src/ui/view/GUI.java
  2. 12 1
      src/ui/view/TimePanel.java

+ 27 - 6
src/ui/view/GUI.java

@@ -62,6 +62,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreeCellRenderer;
 
+import com.sun.corba.se.spi.orbutil.fsm.Action;
+
 import Interfaces.CategoryListener;
 import classes.Category;
 import classes.CpsEdge;
@@ -93,7 +95,7 @@ public class GUI<E> implements CategoryListener {
 	private final JSplitPane splitPane_1 = new JSplitPane();
 	private final JScrollPane scrollPane_1 = new JScrollPane();
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
-	private final JScrollPane scrollPane_2 = new JScrollPane();
+	private final JScrollPane SimulationPane = new JScrollPane();
 	private JPopupMenu popmenuEdit = new JPopupMenu();
 	private JMenuItem editItem = new JMenuItem("Edit Object");
 	private String catOfObjToBeEdited;
@@ -196,6 +198,9 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
 	private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
 	private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
+	private final JMenu mnSimulationSpeed = new JMenu("Simulation Speed");
+	private final JTextField simulationSpeedField = new JTextField();
+	private final JButton btnApply = new JButton("Apply");
 
 	/**
 	 * Create the application.
@@ -203,8 +208,8 @@ public class GUI<E> implements CategoryListener {
 	public GUI(Control control) {
 		this.controller = control;
 		this.model = control.getModel();
-		this.canvas = new MyCanvas(model, control);
-		this.unitGraph = new UnitGraph(model, control);
+		//this.canvas = new MyCanvas(model, control);
+		//this.unitGraph = new UnitGraph(model, control);
 		control.initListener(this);
 		initialize();
 		updateCategories(model.getCategories());
@@ -216,6 +221,7 @@ public class GUI<E> implements CategoryListener {
 	 */
 	@SuppressWarnings({ "serial", "unchecked" })
 	private void initialize() {
+		simulationSpeedField.setColumns(10);
 		frmCyberPhysical = new JFrame();
 		frmCyberPhysical.setTitle("Cyber Physical Systems Model");
 		frmCyberPhysical.setBounds(100, 100, 1000, 800);
@@ -440,6 +446,10 @@ public class GUI<E> implements CategoryListener {
 		mnNewMenu_2.add(mntmEditEdges);
 
 		mnNewMenu_2.add(mntmResetCategory);
+		
+		mnNewMenu_2.add(mnSimulationSpeed);
+		
+		mnSimulationSpeed.add(simulationSpeedField);
 		mntmResetCategory.addActionListener(new ActionListener() {
 
 			@Override
@@ -514,10 +524,10 @@ public class GUI<E> implements CategoryListener {
 		tabbedPane.addTab("Simulation",
 				new ImageIcon(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
 						.getScaledInstance(30, 30, Image.SCALE_SMOOTH)),
-				scrollPane_2, "Simulate the CPS");
+				SimulationPane, "Simulate the CPS");
 		dtrpnHereWillBe.setText("Here will be the Simulation");
 
-		scrollPane_2.setViewportView(dtrpnHereWillBe);
+		SimulationPane.setViewportView(dtrpnHereWillBe);
 
 		/********************
 		 * RIGHT CONTAINER (INFORMATION)
@@ -1407,12 +1417,23 @@ public class GUI<E> implements CategoryListener {
 		splitPane_1.setBorder(null);
 		split_HolonEl_Pro.setBorder(null);
 		split_Graph_HolonEl.setBorder(null);
-		scrollPane_2.setBorder(null);
+		SimulationPane.setBorder(null);
 		panel_HolonEl.setBorder(null);
 
 		tableHolonElementScrollPane.setBorder(null);
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
+		
+		simulationSpeedField.setText(Integer.toString(timePanel.getTimerSpeed()));
+		btnApply.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				int speed = Integer.parseInt(simulationSpeedField.getText());
+				timePanel.setTimerSpeed(speed);
+				mnSimulationSpeed.
+			}
+		});
+		
+		mnSimulationSpeed.add(btnApply);
 	}
 
 	/*

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

@@ -33,6 +33,7 @@ public class TimePanel extends JPanel {
 	private final JButton timeBackwardBtn = new JButton();
 	private Timer timer;
 	private boolean running = false;
+	private int timerSpeed;
 
 	/**
 	 * 
@@ -43,9 +44,10 @@ public class TimePanel extends JPanel {
 		super();
 		this.model = mod;
 		this.controller = cont;
+		timerSpeed = 1000;
 
 		// One Iteration
-		timer = new Timer(1000, new ActionListener() {
+		timer = new Timer(timerSpeed, new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() + 1);
@@ -154,4 +156,13 @@ 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);
+	}
 }