View Javadoc

1   /*
2    * @(#) NavigationToolbar.java 20-jul-2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.gui.editor2D;
11  
12  import javax.swing.ImageIcon;
13  import javax.swing.JButton;
14  import javax.swing.JToolBar;
15  import javax.swing.SwingConstants;
16  
17  import nl.tudelft.simulation.dsol.gui.animation2D.GridPanel;
18  import nl.tudelft.simulation.dsol.gui.editor2D.actions.NavigationToolbarActions;
19  import nl.tudelft.simulation.language.io.URLResource;
20  
21  /***
22   * NavigationToolbar.java <br>
23   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
24   * University of Technology </a>, the Netherlands. <br>
25   * See for project information <a
26   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
27   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
28   * License (GPL) </a>, no warranty <br>
29   * 
30   * @version 1.0 <br>
31   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
32   *         </a>
33   */
34  public class NavigationToolbar extends JToolBar
35  {
36      /*** Pan left button */
37      private JButton panLeft = null;
38  
39      /*** Pan right button */
40      private JButton panRight = null;
41  
42      /*** Pan uo button */
43      private JButton panUp = null;
44  
45      /*** Pan down button */
46      private JButton panDown = null;
47  
48      /*** Zoom in button */
49      private JButton zoomIn = null;
50  
51      /*** Zoom out button */
52      private JButton zoomOut = null;
53  
54      /*** Home button */
55      private JButton home = null;
56  
57      /*** Troggle grid button */
58      private JButton troggleGrid = null;
59  
60      /*** Action listener */
61      private NavigationToolbarActions actions = null;
62  
63      /***
64       * Constructs the toolbar
65       * 
66       * @param target
67       *            Target grid panel
68       */
69      public NavigationToolbar(final GridPanel target)
70      {
71          super();
72          this.setFloatable(true);
73          this.setOrientation(SwingConstants.HORIZONTAL);
74          this.setRollover(true);
75  
76          // Initialize actions
77          this.actions = new NavigationToolbarActions(this, target);
78  
79          // Buttons
80          this.panLeft = createButton("", "Pan left",
81                  "/toolbarButtonGraphics/navigation/Back16.gif");
82  
83          this.panRight = createButton("", "Pan right",
84                  "/toolbarButtonGraphics/navigation/Forward16.gif");
85  
86          this.panUp = createButton("", "Pan up",
87                  "/toolbarButtonGraphics/navigation/Up16.gif");
88  
89          this.panDown = createButton("", "Pan down",
90                  "/toolbarButtonGraphics/navigation/Down16.gif");
91  
92          this.zoomIn = createButton("", "Zoom in",
93                  "/toolbarButtonGraphics/general/ZoomIn16.gif");
94  
95          this.zoomOut = createButton("", "Zoom out",
96                  "/toolbarButtonGraphics/general/ZoomOut16.gif");
97  
98          this.home = createButton("", "Home",
99                  "/toolbarButtonGraphics/navigation/Home16.gif");
100 
101         this.troggleGrid = createButton("", "Troggle grid",
102                 "/editorToolbarButtons/grid.GIF");
103 
104         this.add(this.panLeft);
105         this.add(this.panRight);
106         this.add(this.panUp);
107         this.add(this.panDown);
108         this.add(this.zoomIn);
109         this.add(this.zoomOut);
110         this.add(this.home);
111         this.add(this.troggleGrid);
112 
113     }
114 
115     /***
116      * Create a toolbar button
117      * 
118      * @param text
119      *            Text on the button
120      * @param tooltip
121      *            Tooltip text
122      * @param icon
123      *            Location of icon
124      * @return Button
125      */
126     private JButton createButton(final String text, final String tooltip,
127             final String icon)
128     {
129         JButton button = new JButton(text, new ImageIcon(URLResource
130                 .getResource(icon)));
131         button.setToolTipText(tooltip);
132         button.addActionListener(this.actions);
133         return button;
134     }
135 
136     /***
137      * @return Returns the panDown.
138      */
139     public JButton getPanDown()
140     {
141         return this.panDown;
142     }
143 
144     /***
145      * @return Returns the panLeft.
146      */
147     public JButton getPanLeft()
148     {
149         return this.panLeft;
150     }
151 
152     /***
153      * @return Returns the panRight.
154      */
155     public JButton getPanRight()
156     {
157         return this.panRight;
158     }
159 
160     /***
161      * @return Returns the panUp.
162      */
163     public JButton getPanUp()
164     {
165         return this.panUp;
166     }
167 
168     /***
169      * @return Returns the zoomIn.
170      */
171     public JButton getZoomIn()
172     {
173         return this.zoomIn;
174     }
175 
176     /***
177      * @return Returns the zoomOut.
178      */
179     public JButton getZoomOut()
180     {
181         return this.zoomOut;
182     }
183 
184     /***
185      * @return Returns the home.
186      */
187     public JButton getHome()
188     {
189         return this.home;
190     }
191 
192     /***
193      * @return Returns the troggleGrid.
194      */
195     public JButton getTroggleGrid()
196     {
197         return this.troggleGrid;
198     }
199 }