Browse Source

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

jess 8 years ago
parent
commit
ceb9e23d97
2 changed files with 37 additions and 5 deletions
  1. 25 4
      src/ui/view/GUI.java
  2. 12 1
      src/ui/view/TimePanel.java

+ 25 - 4
src/ui/view/GUI.java

@@ -63,6 +63,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;
@@ -94,7 +96,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;
@@ -198,6 +200,9 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
 	private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
 	private final JMenuItem mntmSetFolder = new JMenuItem("Set Folder");
+	private final JMenu mnSimulationSpeed = new JMenu("Simulation Speed");
+	private final JTextField simulationSpeedField = new JTextField();
+	private final JButton btnApply = new JButton("Apply");
 
 	/**
 	 * Create the application.
@@ -218,6 +223,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);
@@ -442,6 +448,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
@@ -518,10 +528,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)
@@ -1436,12 +1446,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.setPopupMenuVisible(false);
+			}
+		});
+		
+		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);
+	}
 }