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
56 @Override
57 public void actionPerformed(final ActionEvent actionEvent)
58 {
59 String actionCommand = actionEvent.getActionCommand();
60 try
61 {
62 if (actionCommand.equals("Home"))
63 {
64 this.animationPanel.home();
65 }
66 if (actionCommand.equals("ZoomAll"))
67 {
68 this.animationPanel.zoomAll();
69 }
70 if (actionCommand.equals("Grid"))
71 {
72 this.animationPanel.showGrid(!this.animationPanel.isShowGrid());
73 }
74 }
75 catch (Exception exception)
76 {
77 CategoryLogger.always().warn(exception);
78 }
79 }
80 }