View Javadoc

    1   /*
    2    * @(#) NavigationToolbar.java 20-jul-2004
    3    *
    4    * Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5, 2628 BX
    5    * Delft, the Netherlands. All rights reserved.
    6    *
    7    * This software is proprietary information of Delft University of Technology
    8    * The code is published under the Lesser 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 2002-2005 <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/lesser.html">Lesser
    28   * General Public License (LGPL) </a>, no warranty.
    29   *
    30   * @version $Revision$ $Date$
    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 Target grid panel
    67  	 */
    68  	public NavigationToolbar(final GridPanel target)
    69  	{
    70  		super();
    71  		this.setFloatable(true);
    72  		this.setOrientation(SwingConstants.HORIZONTAL);
    73  		this.setRollover(true);
    74
    75  		// Initialize actions
    76  		this.actions = new NavigationToolbarActions(this, target);
    77
    78  		// Buttons
    79  		this.panLeft = createButton("", "Pan left",
    80  				"/toolbarButtonGraphics/navigation/Back16.gif");
    81
    82  		this.panRight = createButton("", "Pan right",
    83  				"/toolbarButtonGraphics/navigation/Forward16.gif");
    84
    85  		this.panUp = createButton("", "Pan up",
    86  				"/toolbarButtonGraphics/navigation/Up16.gif");
    87
    88  		this.panDown = createButton("", "Pan down",
    89  				"/toolbarButtonGraphics/navigation/Down16.gif");
    90
    91  		this.zoomIn = createButton("", "Zoom in",
    92  				"/toolbarButtonGraphics/general/ZoomIn16.gif");
    93
    94  		this.zoomOut = createButton("", "Zoom out",
    95  				"/toolbarButtonGraphics/general/ZoomOut16.gif");
    96
    97  		this.home = createButton("", "Home",
    98  				"/toolbarButtonGraphics/navigation/Home16.gif");
    99
    100 		this.troggleGrid = createButton("", "Troggle grid",
    101 				"/editorToolbarButtons/grid.GIF");
    102
    103 		this.add(this.panLeft);
    104 		this.add(this.panRight);
    105 		this.add(this.panUp);
    106 		this.add(this.panDown);
    107 		this.add(this.zoomIn);
    108 		this.add(this.zoomOut);
    109 		this.add(this.home);
    110 		this.add(this.troggleGrid);
    111
    112 	}
    113
    114 	/***
    115 	 * Create a toolbar button
    116 	 *
    117 	 * @param text Text on the button
    118 	 * @param tooltip Tooltip text
    119 	 * @param icon Location of icon
    120 	 * @return Button
    121 	 */
    122 	private JButton createButton(final String text, final String tooltip,
    123 			final String icon)
    124 	{
    125 		JButton button = new JButton(text, new ImageIcon(URLResource
    126 				.getResource(icon)));
    127 		button.setToolTipText(tooltip);
    128 		button.addActionListener(this.actions);
    129 		return button;
    130 	}
    131
    132 	/***
    133 	 * @return Returns the panDown.
    134 	 */
    135 	public JButton getPanDown()
    136 	{
    137 		return this.panDown;
    138 	}
    139
    140 	/***
    141 	 * @return Returns the panLeft.
    142 	 */
    143 	public JButton getPanLeft()
    144 	{
    145 		return this.panLeft;
    146 	}
    147
    148 	/***
    149 	 * @return Returns the panRight.
    150 	 */
    151 	public JButton getPanRight()
    152 	{
    153 		return this.panRight;
    154 	}
    155
    156 	/***
    157 	 * @return Returns the panUp.
    158 	 */
    159 	public JButton getPanUp()
    160 	{
    161 		return this.panUp;
    162 	}
    163
    164 	/***
    165 	 * @return Returns the zoomIn.
    166 	 */
    167 	public JButton getZoomIn()
    168 	{
    169 		return this.zoomIn;
    170 	}
    171
    172 	/***
    173 	 * @return Returns the zoomOut.
    174 	 */
    175 	public JButton getZoomOut()
    176 	{
    177 		return this.zoomOut;
    178 	}
    179
    180 	/***
    181 	 * @return Returns the home.
    182 	 */
    183 	public JButton getHome()
    184 	{
    185 		return this.home;
    186 	}
    187
    188 	/***
    189 	 * @return Returns the troggleGrid.
    190 	 */
    191 	public JButton getTroggleGrid()
    192 	{
    193 		return this.troggleGrid;
    194 	}
    195 }