|
@@ -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();
|
|
@@ -116,7 +117,6 @@ public class TimePanel extends JPanel {
|
|
timeSlider.setToolTipText(Languages.getLanguage()[93]);
|
|
timeSlider.setToolTipText(Languages.getLanguage()[93]);
|
|
timeSlider.setMaximum(model.getIterations() - 1);
|
|
timeSlider.setMaximum(model.getIterations() - 1);
|
|
timeSlider.setValue(0);
|
|
timeSlider.setValue(0);
|
|
- timeSlider.setBackground(Color.WHITE);
|
|
|
|
timeSlider.addChangeListener(new ChangeListener() {
|
|
timeSlider.addChangeListener(new ChangeListener() {
|
|
@Override
|
|
@Override
|
|
public void stateChanged(ChangeEvent e) {
|
|
public void stateChanged(ChangeEvent e) {
|
|
@@ -130,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) {
|
|
@@ -140,15 +140,14 @@ public class TimePanel extends JPanel {
|
|
|
|
|
|
// Panel
|
|
// Panel
|
|
timeBtnPanel.setBorder(null);
|
|
timeBtnPanel.setBorder(null);
|
|
- timeBtnPanel.setBackground(Color.WHITE);
|
|
|
|
- timeBtnPanel.setLayout(new FlowLayout());
|
|
|
|
|
|
+ timeBtnPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
|
|
|
|
|
// Buttons
|
|
// Buttons
|
|
playBtn.setToolTipText(Languages.getLanguage()[89]);
|
|
playBtn.setToolTipText(Languages.getLanguage()[89]);
|
|
|
|
|
|
- playBtn.setBackground(Color.WHITE);
|
|
|
|
|
|
+ playBtn.setContentAreaFilled(false);
|
|
playBtn.setBorderPainted(false);
|
|
playBtn.setBorderPainted(false);
|
|
- playBtn.setBorder(new LineBorder(Color.WHITE, 4));
|
|
|
|
|
|
+ playBtn.setBorder(null);
|
|
playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/play.png")).getImage()
|
|
playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/play.png")).getImage()
|
|
.getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
.getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
playBtn.addActionListener(new ActionListener() {
|
|
playBtn.addActionListener(new ActionListener() {
|
|
@@ -169,9 +168,8 @@ public class TimePanel extends JPanel {
|
|
});
|
|
});
|
|
timeResetBtn.setToolTipText(Languages.getLanguage()[90]);
|
|
timeResetBtn.setToolTipText(Languages.getLanguage()[90]);
|
|
|
|
|
|
- timeResetBtn.setBorderPainted(false);
|
|
|
|
- timeResetBtn.setBackground(Color.WHITE);
|
|
|
|
- timeResetBtn.setBorder(new LineBorder(Color.WHITE, 4));
|
|
|
|
|
|
+ timeResetBtn.setContentAreaFilled(false);
|
|
|
|
+ timeResetBtn.setBorder(null);
|
|
timeResetBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/reset.png"))
|
|
timeResetBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/reset.png"))
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
timeResetBtn.addActionListener(new ActionListener() {
|
|
timeResetBtn.addActionListener(new ActionListener() {
|
|
@@ -184,9 +182,8 @@ public class TimePanel extends JPanel {
|
|
});
|
|
});
|
|
timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
|
|
timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
|
|
|
|
|
|
- timeForwardBtn.setBorderPainted(false);
|
|
|
|
timeForwardBtn.setContentAreaFilled(false);
|
|
timeForwardBtn.setContentAreaFilled(false);
|
|
- timeForwardBtn.setBorder(new LineBorder(Color.WHITE, 4));
|
|
|
|
|
|
+ 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"))
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
timeForwardBtn.addActionListener(new ActionListener() {
|
|
timeForwardBtn.addActionListener(new ActionListener() {
|
|
@@ -197,9 +194,7 @@ public class TimePanel extends JPanel {
|
|
});
|
|
});
|
|
timeBackwardBtn.setToolTipText(Languages.getLanguage()[92]);
|
|
timeBackwardBtn.setToolTipText(Languages.getLanguage()[92]);
|
|
|
|
|
|
- timeBackwardBtn.setBackground(Color.WHITE);
|
|
|
|
- timeBackwardBtn.setBorderPainted(false);
|
|
|
|
- timeBackwardBtn.setBorder(new LineBorder(Color.WHITE, 4));
|
|
|
|
|
|
+ timeBackwardBtn.setBorder(null);
|
|
timeBackwardBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/backward.png"))
|
|
timeBackwardBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/backward.png"))
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
|
|
timeBackwardBtn.addActionListener(new ActionListener() {
|
|
timeBackwardBtn.addActionListener(new ActionListener() {
|
|
@@ -209,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);
|
|
/*
|
|
/*
|
|
@@ -232,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);
|
|
}
|
|
}
|
|
|
|
|