|
@@ -1,7 +1,6 @@
|
|
package ui.view;
|
|
package ui.view;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.BorderLayout;
|
|
-import java.awt.Color;
|
|
|
|
import java.awt.FlowLayout;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.Image;
|
|
import java.awt.Image;
|
|
import java.awt.Point;
|
|
import java.awt.Point;
|
|
@@ -16,15 +15,10 @@ import javax.swing.JButton;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JSlider;
|
|
import javax.swing.JSlider;
|
|
-import javax.swing.JTextField;
|
|
|
|
import javax.swing.Timer;
|
|
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.ChangeEvent;
|
|
import javax.swing.event.ChangeListener;
|
|
import javax.swing.event.ChangeListener;
|
|
import javax.swing.plaf.basic.BasicSliderUI;
|
|
import javax.swing.plaf.basic.BasicSliderUI;
|
|
-import javax.swing.plaf.synth.SynthSliderUI;
|
|
|
|
|
|
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
@@ -41,31 +35,38 @@ public class TimePanel extends JPanel {
|
|
private Model model;
|
|
private Model model;
|
|
private Control controller;
|
|
private Control controller;
|
|
|
|
|
|
- JLabel simSpeedLabel = new JLabel(Languages.getLanguage()[84]);
|
|
|
|
- private JTextField simSpeedText = new JTextField("1000");
|
|
|
|
- JSlider timeSlider = new JSlider(){
|
|
|
|
- {
|
|
|
|
- // Make the slider jump to mouse position on left click
|
|
|
|
- MouseListener[] listeners = getMouseListeners();
|
|
|
|
- for (MouseListener l : listeners)
|
|
|
|
- removeMouseListener(l); // remove UI-installed TrackListener
|
|
|
|
- final BasicSliderUI ui = (BasicSliderUI) getUI();
|
|
|
|
- BasicSliderUI.TrackListener tl = ui.new TrackListener() {
|
|
|
|
- // this is where we jump to absolute value of click
|
|
|
|
- @Override public void mouseClicked(MouseEvent e) {
|
|
|
|
- Point p = e.getPoint();
|
|
|
|
- int value = ui.valueForXPosition(p.x);
|
|
|
|
-
|
|
|
|
- setValue(value);
|
|
|
|
- }
|
|
|
|
- // disable check that will invoke scrollDueToClickInTrack
|
|
|
|
- @Override public boolean shouldScroll(int dir) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- addMouseListener(tl);
|
|
|
|
- }
|
|
|
|
|
|
+ JSlider timeSlider = new JSlider() {
|
|
|
|
+ {
|
|
|
|
+ // Make the slider jump to mouse position on left click
|
|
|
|
+ MouseListener[] listeners = getMouseListeners();
|
|
|
|
+ for (MouseListener l : listeners)
|
|
|
|
+ removeMouseListener(l); // remove UI-installed TrackListener
|
|
|
|
+ final BasicSliderUI ui = (BasicSliderUI) getUI();
|
|
|
|
+ BasicSliderUI.TrackListener tl = ui.new TrackListener() {
|
|
|
|
+ // this is where we jump to absolute value of click
|
|
|
|
+ @Override
|
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
|
+ Point p = e.getPoint();
|
|
|
|
+ int value = ui.valueForXPosition(p.x);
|
|
|
|
+
|
|
|
|
+ setValue(value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // disable check that will invoke scrollDueToClickInTrack
|
|
|
|
+ @Override
|
|
|
|
+ public boolean shouldScroll(int dir) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ addMouseListener(tl);
|
|
|
|
+ }
|
|
};;
|
|
};;
|
|
|
|
+
|
|
|
|
+ private JLabel simSpeedLabel = new JLabel("Speed:");
|
|
|
|
+ private JSlider speedSlider = new JSlider();
|
|
|
|
+
|
|
|
|
+ private final JPanel btnAndSpeedPanel = new JPanel();
|
|
|
|
+ private final JPanel speedPanel = new JPanel();
|
|
private final JPanel timeBtnPanel = new JPanel();
|
|
private final JPanel timeBtnPanel = new JPanel();
|
|
final JButton playBtn = new JButton();
|
|
final JButton playBtn = new JButton();
|
|
final JButton timeResetBtn = new JButton();
|
|
final JButton timeResetBtn = new JButton();
|
|
@@ -129,7 +130,7 @@ public class TimePanel extends JPanel {
|
|
controller.resetSimulation();
|
|
controller.resetSimulation();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
timeSlider.addMouseMotionListener(new MouseAdapter() {
|
|
timeSlider.addMouseMotionListener(new MouseAdapter() {
|
|
@Override
|
|
@Override
|
|
public void mouseDragged(MouseEvent e) {
|
|
public void mouseDragged(MouseEvent e) {
|
|
@@ -181,7 +182,6 @@ public class TimePanel extends JPanel {
|
|
});
|
|
});
|
|
timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
|
|
timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
|
|
|
|
|
|
-
|
|
|
|
timeForwardBtn.setContentAreaFilled(false);
|
|
timeForwardBtn.setContentAreaFilled(false);
|
|
timeForwardBtn.setBorder(null);
|
|
timeForwardBtn.setBorder(null);
|
|
timeForwardBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/forward.png"))
|
|
timeForwardBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/forward.png"))
|
|
@@ -204,21 +204,7 @@ 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(simSpeedText);
|
|
timeBtnPanel.add(playBtn);
|
|
timeBtnPanel.add(playBtn);
|
|
timeBtnPanel.add(timeResetBtn);
|
|
timeBtnPanel.add(timeResetBtn);
|
|
/*
|
|
/*
|
|
@@ -227,7 +213,31 @@ public class TimePanel extends JPanel {
|
|
// timeBtnPanel.add(timeBackwardBtn);
|
|
// timeBtnPanel.add(timeBackwardBtn);
|
|
timeBtnPanel.add(timeForwardBtn);
|
|
timeBtnPanel.add(timeForwardBtn);
|
|
|
|
|
|
- this.add(timeBtnPanel, BorderLayout.WEST);
|
|
|
|
|
|
+ // Speed Panel
|
|
|
|
+ speedPanel.add(simSpeedLabel);
|
|
|
|
+ speedPanel.add(speedSlider);
|
|
|
|
+ speedSlider.setPaintTicks(true);
|
|
|
|
+ speedSlider.setPaintLabels(true);
|
|
|
|
+ speedSlider.setToolTipText("Speed: 1000");
|
|
|
|
+ speedSlider.setMaximum(10000);
|
|
|
|
+ speedSlider.setMinimum(0);
|
|
|
|
+ speedSlider.setValue(1000);
|
|
|
|
+ speedSlider.setMajorTickSpacing(2000);
|
|
|
|
+ speedSlider.addChangeListener(new ChangeListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void stateChanged(ChangeEvent e) {
|
|
|
|
+ controller.setTimerSpeed(speedSlider.getValue());
|
|
|
|
+ speedSlider.setToolTipText("Speed: "+speedSlider.getValue());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // Buttons and Speed Panel
|
|
|
|
+ btnAndSpeedPanel.setLayout(new BorderLayout(0,0));
|
|
|
|
+ btnAndSpeedPanel.setBorder(null);
|
|
|
|
+ btnAndSpeedPanel.add(timeBtnPanel, BorderLayout.NORTH);
|
|
|
|
+ btnAndSpeedPanel.add(speedPanel, BorderLayout.CENTER);
|
|
|
|
+
|
|
|
|
+ this.add(btnAndSpeedPanel, BorderLayout.WEST);
|
|
this.add(timeSlider);
|
|
this.add(timeSlider);
|
|
}
|
|
}
|
|
|
|
|