1 package nl.tudelft.simulation.dsol.swing.gui.animation.panel;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5
6 import javax.swing.BoxLayout;
7 import javax.swing.JPanel;
8
9 import org.djutils.logger.CategoryLogger;
10
11 import nl.tudelft.simulation.dsol.swing.ButtonUtil;
12 import nl.tudelft.simulation.dsol.swing.animation.d2.AnimationPanel;
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class ButtonPanel extends JPanel implements ActionListener
27 {
28
29 private static final long serialVersionUID = 20210214L;
30
31
32 private final AnimationPanel animationPanel;
33
34
35
36
37
38 public ButtonPanel(final AnimationPanel animationPanel)
39 {
40 this.animationPanel = animationPanel;
41 init();
42 }
43
44
45
46
47 public void init()
48 {
49 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
50 add(ButtonUtil.makeButton(this, "allButton", "/resources/Expand.png", "ZoomAll", "Zoom whole network", true));
51 add(ButtonUtil.makeButton(this, "homeButton", "/resources/Home.png", "Home", "Zoom to original extent", true));
52 add(ButtonUtil.makeButton(this, "gridButton", "/resources/Grid.png", "Grid", "Toggle grid on/off", true));
53 }
54
55 @Override
56 public void actionPerformed(final ActionEvent actionEvent)
57 {
58 String actionCommand = actionEvent.getActionCommand();
59 try
60 {
61 if (actionCommand.equals("Home"))
62 {
63 this.animationPanel.home();
64 }
65 if (actionCommand.equals("ZoomAll"))
66 {
67 this.animationPanel.zoomAll();
68 }
69 if (actionCommand.equals("Grid"))
70 {
71 this.animationPanel.showGrid(!this.animationPanel.isShowGrid());
72 }
73 }
74 catch (Exception exception)
75 {
76 CategoryLogger.always().warn(exception);
77 }
78 }
79 }