Ver Fonte

simulation speed is now in the timePanel

Kevin Trometer há 7 anos atrás
pai
commit
f45d88561e
3 ficheiros alterados com 34 adições e 16 exclusões
  1. 0 1
      src/ui/view/GUI.java
  2. 8 8
      src/ui/view/SimulationMenu.java
  3. 26 7
      src/ui/view/TimePanel.java

+ 0 - 1
src/ui/view/GUI.java

@@ -1942,7 +1942,6 @@ public class GUI<E> implements CategoryListener {
 		eraseCategory = tempArray[29];
 		selectObjBeforeErase = tempArray[30];
 		// SimMenu
-		simMenu.simSpeedLabel.setText(Languages.getLanguage()[84]);
 		simMenu.algoFolderButton.setText(Languages.getLanguage()[85]);
 		// TimePanel
 		timePanel.playBtn.setToolTipText(Languages.getLanguage()[89]);

+ 8 - 8
src/ui/view/SimulationMenu.java

@@ -40,8 +40,8 @@ public class SimulationMenu extends JMenuBar {
 	private static final long serialVersionUID = 1L;
 
 	private JPanel menuPanel = new JPanel();
-	JLabel simSpeedLabel = new JLabel(Languages.getLanguage()[84]);
-	private JTextField simSpeedText = new JTextField("1000");
+	//JLabel simSpeedLabel = new JLabel(Languages.getLanguage()[84]);
+	//private JTextField simSpeedText = new JTextField("1000");
 	private JComboBox<Object> algoCombo = new JComboBox<>();
 	JButton algoFolderButton = new JButton(Languages.getLanguage()[85]);
 	private HashMap<String, File> algosHash = new HashMap<>();
@@ -66,8 +66,8 @@ public class SimulationMenu extends JMenuBar {
 		this.model = mod;
 		this.controller = cont;
 		
-		simSpeedLabel.setMaximumSize(simSpeedLabel.getPreferredSize());
-		simSpeedLabel.setMinimumSize(simSpeedLabel.getPreferredSize());
+		//simSpeedLabel.setMaximumSize(simSpeedLabel.getPreferredSize());
+		//simSpeedLabel.setMinimumSize(simSpeedLabel.getPreferredSize());
 		algoCombo.addItem("None");
 
 		// Algorithm ComboBox Action
@@ -136,10 +136,10 @@ public class SimulationMenu extends JMenuBar {
 		gbcsimSpeedLabel.insets = new Insets(0, 0, 0, 5);
 		gbcsimSpeedLabel.gridx = 1;
 		gbcsimSpeedLabel.gridy = 0;
-		menuPanel.add(simSpeedLabel, gbcsimSpeedLabel);
+		//menuPanel.add(simSpeedLabel, gbcsimSpeedLabel);
 
 		// timerSpeed
-		simSpeedText.setMaximumSize(new Dimension(300, 300));
+		/*simSpeedText.setMaximumSize(new Dimension(300, 300));
 		// simSpeedText.setMinimumSize(new Dimension(300, 300));
 		simSpeedText.addCaretListener(new CaretListener() {
 			@Override
@@ -151,13 +151,13 @@ public class SimulationMenu extends JMenuBar {
 				}
 
 			}
-		});
+		});*/
 		GridBagConstraints gbcSimSpeedText = new GridBagConstraints();
 		gbcSimSpeedText.anchor = GridBagConstraints.WEST;
 		gbcSimSpeedText.insets = new Insets(0, 0, 0, 5);
 		gbcSimSpeedText.gridx = 2;
 		gbcSimSpeedText.gridy = 0;
-		menuPanel.add(simSpeedText, gbcSimSpeedText);
+		//menuPanel.add(simSpeedText, gbcSimSpeedText);
 		GridBagConstraints gbcAlgoFolderButton = new GridBagConstraints();
 		gbcAlgoFolderButton.anchor = GridBagConstraints.WEST;
 		gbcAlgoFolderButton.insets = new Insets(0, 0, 0, 5);

+ 26 - 7
src/ui/view/TimePanel.java

@@ -2,6 +2,8 @@ package ui.view;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
 import java.awt.Image;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -10,20 +12,20 @@ import java.awt.event.MouseEvent;
 
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JSeparator;
 import javax.swing.JSlider;
+import javax.swing.JTextField;
 import javax.swing.Timer;
 import javax.swing.border.LineBorder;
+import javax.swing.event.CaretEvent;
+import javax.swing.event.CaretListener;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
-import classes.HolonElement;
-import classes.HolonObject;
-import classes.HolonSwitch;
-import classes.SubNet;
 import ui.controller.Control;
 import ui.model.Model;
-import javax.swing.BoxLayout;
 
 /**
  * This Class represents a Panel where the User can start and stop the
@@ -37,6 +39,8 @@ public class TimePanel extends JPanel {
 	private Model model;
 	private Control controller;
 
+	JLabel simSpeedLabel = new JLabel(Languages.getLanguage()[84]);
+	private JTextField simSpeedText = new JTextField("1000");
 	JSlider timeSlider = new JSlider();
 	private final JPanel timeBtnPanel = new JPanel();
 	final JButton playBtn = new JButton();
@@ -62,7 +66,7 @@ public class TimePanel extends JPanel {
 		this.controller = cont;
 
 		// One Iteration
-		timer = new Timer(model.getTimerSpeed(), new ActionListener() {
+		timer = new Timer(0, new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() + 1);
@@ -106,7 +110,7 @@ public class TimePanel extends JPanel {
 		// Panel
 		timeBtnPanel.setBorder(null);
 		timeBtnPanel.setBackground(Color.WHITE);
-		timeBtnPanel.setLayout(new BoxLayout(timeBtnPanel, BoxLayout.X_AXIS));
+		timeBtnPanel.setLayout(new FlowLayout());
 
 		// Buttons
 		playBtn.setToolTipText(Languages.getLanguage()[89]);
@@ -174,6 +178,21 @@ public class TimePanel extends JPanel {
 			}
 		});
 
+		// timerSpeed
+		simSpeedText.addCaretListener(new CaretListener() {
+			@Override
+			public void caretUpdate(CaretEvent e) {
+				try {
+					controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
+				} catch (Exception ex) {
+					// TODO: handle exception
+				}
+
+			}
+		});
+
+		timeBtnPanel.add(simSpeedLabel);
+		timeBtnPanel.add(simSpeedText);
 		timeBtnPanel.add(playBtn);
 		timeBtnPanel.add(timeResetBtn);
 		/*