/[schmitzm]/trunk/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/MapPaneToolBar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/skrueger/geotools/MapPaneToolBar.java revision 48 by alfonx, Fri Apr 17 12:49:33 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java revision 414 by alfonx, Thu Sep 24 13:23:08 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.awt.Dimension;   *
4  import java.awt.event.ActionEvent;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.util.ArrayList;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import java.util.SortedMap;   * and the Geotools library.
7  import java.util.TreeMap;   *
8     * The SCHMITZM project is hosted at:
9  import javax.swing.AbstractAction;   * http://wald.intevation.org/projects/schmitzm/
10  import javax.swing.AbstractButton;   *
11  import javax.swing.BorderFactory;   * This program is free software; you can redistribute it and/or
12  import javax.swing.Icon;   * modify it under the terms of the GNU Lesser General Public License
13  import javax.swing.ImageIcon;   * as published by the Free Software Foundation; either version 3
14  import javax.swing.JButton;   * of the License, or (at your option) any later version.
15  import javax.swing.JToggleButton;   *
16  import javax.swing.JToolBar;   * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  import org.apache.log4j.Logger;   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     * GNU General Public License for more details.
20  import schmitzm.geotools.gui.JMapPane;   *
21  import schmitzm.geotools.map.event.JMapPaneEvent;   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22  import schmitzm.geotools.map.event.JMapPaneListener;   * along with this program; if not, write to the Free Software
23  import schmitzm.geotools.map.event.MapAreaChangedEvent;   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  import schmitzm.swing.ButtonGroup;   * or try this link: http://www.gnu.org/licenses/lgpl.html
25  import schmitzm.swing.SwingUtil;   *
26     * Contributors:
27  import com.vividsolutions.jts.geom.Envelope;   *     Martin O. J. Schmitz - initial API and implementation
28     *     Stefan A. Krüger - additional utility classes
29  /**   ******************************************************************************/
30   * A toolbar to controll a {@link JMapPane} (Atlas visualization). This contains two types  package skrueger.geotools;
31   * of buttons. A group of <i>tools</i> for the mouse actions on the map represented  
32   * by {@link JToggleButton JToggleButtons}, where only one tool can be activated  import java.awt.Color;
33   * every time. And some (general) <i>actions</i>, represented by normal  import java.awt.Dimension;
34   * {@link JButton JButtons}.  import java.awt.Graphics;
35   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)  import java.awt.event.ActionEvent;
36   */  import java.awt.event.ActionListener;
37  public class MapPaneToolBar extends JToolBar {  import java.util.ArrayList;
38          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class.getName());  import java.util.HashSet;
39          /** Constant for the tool "Panning" (10). */  import java.util.Locale;
40          public static final int TOOL_PAN = 10;  import java.util.Set;
41          /** Constant for the tool "Zoom In" (30). */  import java.util.SortedMap;
42          public static final int TOOL_ZOOMIN = 30;  import java.util.TreeMap;
43          /** Constant for the tool "Zoom Out" (40). */  
44          public static final int TOOL_ZOOMOUT = 40;  import javax.swing.AbstractAction;
45          /** Constant for the tool "Info" (20). */  import javax.swing.AbstractButton;
46          public static final int TOOL_INFO = 20;  import javax.swing.Action;
47    import javax.swing.BorderFactory;
48          /** Tool currently selected */  import javax.swing.Icon;
49      protected int selectedTool = TOOL_ZOOMIN;  import javax.swing.ImageIcon;
50      /** Holds the tool buttons of the tool bar. */  import javax.swing.JButton;
51      protected SortedMap<Integer, JToggleButton> toolButtons = null;  import javax.swing.JComponent;
52      /** Controls that only one tool button is activated. */  import javax.swing.JToggleButton;
53      protected ButtonGroup toolButtonGroup = null;  import javax.swing.JToolBar;
54      /** Constant for the action "Zoom back" (100). */  
55      public static final int ACTION_ZOOM_BACK = 100;  import org.apache.log4j.Logger;
56      /** Constant for the action "Zoom forward" (110). */  
57      public static final int ACTION_ZOOM_FORWARD = 110;  import schmitzm.geotools.gui.JMapPane;
58      /** Constant for the action "Search Labels" (120). */  import schmitzm.geotools.map.event.JMapPaneEvent;
59      public static final int ACTION_SEARCH = 120;  import schmitzm.geotools.map.event.JMapPaneListener;
60    import schmitzm.geotools.map.event.MapAreaChangedEvent;
61      /** Holds the action buttons of the bar. */  import schmitzm.lang.LangUtil;
62      protected SortedMap<Integer, JButton> actionButtons = null;  import schmitzm.lang.ResourceProvider;
63    import schmitzm.swing.ButtonGroup;
64          /** Holds the {@link JMapPane} this tool bar controls. */  import schmitzm.swing.SwingUtil;
65          protected JMapPane mapPane = null;  
66    import com.vividsolutions.jts.geom.Envelope;
67          /**  
68           * A List to remember the last Envelopes that have been watched. Used for  /**
69           * the zoomBack- and zoomForwardButtons *   * A toolbar to control an {@link JMapPane} (Atlas visualization). This contains
70           */   * two types of buttons. A group of <i>tools</i> for the mouse actions on the
71          protected ArrayList<Envelope> lastZooms = new ArrayList<Envelope>();   * map represented by {@link JToggleButton JToggleButtons}, where only one tool
72          /** Holds the index to the current element in {@link #lastZooms}. */   * can be activated every time. And some (general) <i>actions</i>, represented
73          protected int zoomBackIndex = 0;   * by normal {@link JButton JButtons}.
74     *
75          /** Listener to sniff the zoom actions on the map. */   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
76          protected JMapPaneListener mapPaneListener = null;   *         (University of Bonn/Germany)
77             * @version 1.2 Stefan Krüger
78          protected boolean zoomBackForwardButtonInAction;   */
79    public class MapPaneToolBar extends JToolBar {
80      /**          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
81       * Creates a new toolbar. Notice: This toolbar does nothing                          .getName());
82       * until {@link #setMapPane(JMapPane)} is called!          
83       */          public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
84      public MapPaneToolBar() {                          .extendPackagePath(MapPaneToolBar.class,
85        this(null);                                          "resource.locales.mapPaneToolbar"), Locale.ENGLISH);
86      }          
87                public static String R(String key, Object... values) {
88      /**                  return RESOURCE.getString(key, values);
89           * Creates a new tool bar.          }
90           * @param mapPane {@link JMapPane} the tool bar controls  
91           */          /** Constant for the tool "Panning" (10). */
92          public MapPaneToolBar(JMapPane mapPane) {          public static final int TOOL_PAN = 10;
93            super("Control the map", JToolBar.HORIZONTAL);          /** Constant for the tool "Info" (20). */
94        this.toolButtons     = new TreeMap<Integer,JToggleButton>();          public static final int TOOL_INFO = 20;
95        this.toolButtonGroup = new ButtonGroup();          public static final int SEPERATOR0 = 99;
96        this.actionButtons   = new TreeMap<Integer,JButton>();  
97        // Create a Listener to sniff the zooms on the JMapPane          /** Constant for the tool "Zoom In" (110). */
98        this.mapPaneListener = new JMapPaneListener() {          public static final int TOOL_ZOOMIN = 110;
99            public void performMapPaneEvent(JMapPaneEvent e) {          /** Constant for the tool "Zoom Out" (120). */
100                if ( !(e instanceof MapAreaChangedEvent) )          public static final int TOOL_ZOOMOUT = 120;
101                  return;          /** Constant for the action "Zoom back" (130). */
102                            public static final int ACTION_ZOOM_BACK = 130;
103                if ( zoomBackForwardButtonInAction ) {          /** Constant for the action "Zoom forward" (140). */
104                  zoomBackForwardButtonInAction = false;          public static final int ACTION_ZOOM_FORWARD = 140;
105                  return;          public static final int SEPERATOR1 = 199;
106                }  
107                        /**
108                Envelope oldMapArea = ((MapAreaChangedEvent)e).getOldMapArea();           * Constant for the tool "Selection Reset" which clears the selection (240).
109                if (lastZooms.size() == 0 && oldMapArea != null ) {           */
110                  lastZooms.add(oldMapArea);          public static final int TOOL_SELECTION_CLEAR = 240;
111                  zoomBackIndex = 1;  
112                }          /**
113             * Constant for the tool "Select" which sets the Selection to the selected
114                final Envelope mapArea = ((MapAreaChangedEvent)e).getNewMapArea();           * features (210).
115                if (mapArea == null)           */
116                  return;          public static final int TOOL_SELECTION_SET = 210;
117                          /**
118                if (lastZooms.size() > 0 && mapArea.equals(lastZooms.get(lastZooms.size() - 1))) {           * Constant for the tool "Selection add" which adds the features to the
119                  // LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch");           * Selection (220).
120                  return;           */
121                }          public static final int TOOL_SELECTION_ADD = 220;
122            /**
123                if (lastZooms.size() > 0)           * Constant for the tool "Selection subtract" which removes the selected
124                  while (zoomBackIndex < lastZooms.size())           * features from the selection (230).
125                    lastZooms.remove(lastZooms.size() - 1);           */
126            public static final int TOOL_SELECTION_REMOVE = 230;
127                lastZooms.add(mapArea);  
128                zoomBackIndex = lastZooms.size();          public static final int ACTION_CHARTS = 401;
129                setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);  
130                setButtonEnabled(ACTION_ZOOM_FORWARD, false);          /** Tool currently selected */
131            }          protected int selectedTool = TOOL_ZOOMIN;
132        };      
133                /** Holds the tool buttons of the tool bar. */
134        setMapPane(mapPane);          final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
135            setFloatable(false);          /** Controls that only one tool button is activated. */
136            setRollover(true);          protected ButtonGroup toolButtonGroup = null;
137              
138            init();          // SK: Musste ich ändern damit man Tools und Actions in der Reihenfolge
139          }          // mischen kann.
140                    // /** Holds the action buttons of the bar. */
141          /**          // protected SortedMap<Integer, JButton> actionButtons = null;
142           * Sets the {@link JMapPane} controlled by this tool bar.  
143           * @param mapPane {@link JMapPane} to control (if {@code null} this          /** Holds the {@link JMapPane} this tool bar controls. */
144           *                tool bar controls NOTHING!)          protected JMapPane mapPane = null;
145           */  
146          public void setMapPane(JMapPane mapPane) {          /**
147            // Remove listener from old MapPane           * A List to remember the last Envelopes that have been watched. Used for
148            if ( this.mapPane != null )           * the zoomBack- and zoomForwardButtons *
149              this.mapPane.removeMapPaneListener( mapPaneListener );           */
150        this.mapPane = mapPane;          protected ArrayList<Envelope> lastZooms = new ArrayList<Envelope>();
151        if ( this.mapPane != null && mapPaneListener != null )          /** Holds the index to the current element in {@link #lastZooms}. */
152          this.mapPane.addMapPaneListener( mapPaneListener );          protected int zoomBackIndex = 0;
153          }  
154                    /** Listener to sniff the zoom actions on the map. */
155          /**          protected JMapPaneListener mapPaneListener = null;
156           * Calls {@link #initTools()} and {@link #initActions()} and then puts  
157           * all tool buttons and all actions buttons to the tool bar.          protected boolean zoomBackForwardButtonInAction;
158           */  
159          protected void init() {          /** Listeners what want to be informed about a change of the selected tool **/
160            initTools();          protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
161            initActions();  
162            initToolBar();          /** This listener is added to all {@link JToggleButton}  **/
163          }          private final ActionListener toolSelectedListener = new ActionListener(){
164    
165                    @Override
166          /**                  public void actionPerformed(ActionEvent e) {
167           * Creates the tool buttons, adds them to {@link #toolButtons} and finally                          JToggleButton tb = (JToggleButton) e.getSource();
168           * creates a button group for all tools. So sub-classes which override this                          
169           * method should FIRST add their new tool buttons to {@link #toolButtons}                          // Inform the listeners about a newly selected tool
170           * before calling {@code super.initTools()}.                          for (MapPaneToolSelectedListener l : toolSelectionListeners) {
171           */                                  l.toolSelected(Integer.valueOf( tb.getName() ) ) ;
172          protected void initTools() {                          }
173        // Panning                  }
174        addTool( new MapPaneToolBarAction(                  
175            TOOL_PAN,          };
176            this,  
177            "",          /**
178            new ImageIcon(MapView.class.getResource("pan.png"))           * Creates a new toolbar. Notice: This toolbar does nothing until
179        ), false );           * {@link #setMapPane(JMapPane)} is called!
180        // Info           */
181        addTool( new MapPaneToolBarAction(          public MapPaneToolBar() {
182            TOOL_INFO,                  this(null);
183            this,          }
184            "",          
185            new ImageIcon(MapView.class.getResource("info.png"))          public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) {
186        ), false );                  toolSelectionListeners.add(listener);
187        // Zoom in          }
188        addTool( new MapPaneToolBarAction(  
189            TOOL_ZOOMIN,          public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) {
190            this,                  toolSelectionListeners .remove(listener);
191            "",          }
192            new ImageIcon(MapView.class.getResource("zoom_in.png"))  
193        ), false );          /**
194        // Zoom out           * Creates a new tool bar.
195        addTool( new MapPaneToolBarAction(           *
196            TOOL_ZOOMOUT,           * @param mapPane
197            this,           *            {@link JMapPane} the tool bar controls
198            "",           */
199            new ImageIcon(MapView.class.getResource("zoom_out.png"))          public MapPaneToolBar(JMapPane mapPane) {
200        ), false );                  super("Control the map", JToolBar.HORIZONTAL);
201                          this.toolButtonGroup = new ButtonGroup();
202            // set the selected tool enabled                  
203        setSelectedTool(selectedTool);                  // Create a Listener to listen to the zooms on the JMapPane
204                          this.mapPaneListener = new JMapPaneListener() {
205          }                          public void performMapPaneEvent(JMapPaneEvent e) {
206                                    if (!(e instanceof MapAreaChangedEvent))
207      /**                                          return;
208       * Creates the action buttons and adds them to {@link #actionButtons}.  
209       */                                  if (zoomBackForwardButtonInAction) {
210      protected void initActions() {                                          zoomBackForwardButtonInAction = false;
211        // Action button to revert the last zoom                                          return;
212        addAction( new MapPaneToolBarAction(                                  }
213            ACTION_ZOOM_BACK,  
214            this,                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
215            "",                                  Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
216            new ImageIcon(MapView.class.getResource("zoom_back.png"))                                  
217        ), false);                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
218        setButtonEnabled( ACTION_ZOOM_BACK, false );                                  if (mapArea == null || mapArea.equals(oldMapArea) ) {
219                                            // If the MapArea didn't change... we don't want to register it as a zoom action.
220        // Action button to redo the last zoom                                          return;
221        addAction( new MapPaneToolBarAction(                                  }
222            ACTION_ZOOM_FORWARD,                                  
223            this,                                  if (lastZooms.size() == 0 && oldMapArea != null) {
224            "",                                          lastZooms.add(oldMapArea);
225            new ImageIcon(MapView.class.getResource("zoom_forward.png"))                                          zoomBackIndex = 1;
226        ), false);                                  }
227        setButtonEnabled( ACTION_ZOOM_FORWARD, false );                                  if (mapArea == null)
228                                            return;
229      }  
230                                        if (lastZooms.size() > 0
231      /**                                                  && mapArea.equals(lastZooms.get(lastZooms.size() - 1))) {
232       * Clears the GUI of all components and adds all tool and action buttons to the                                          // LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch");
233       * tool bar.                                          return;
234       */                                  }
235      protected void initToolBar() {  
236        setAlignmentY( 1f );                                  if (lastZooms.size() > 0)
237        removeAll();                                          while (zoomBackIndex < lastZooms.size())
238        // Separator to the left of the tool actions to start                                                  lastZooms.remove(lastZooms.size() - 1);
239        // the tool buttons with the map (not with the coordinate grid)  
240        Dimension dimension = new Dimension( 49,10);                                  lastZooms.add(mapArea);
241        addSeparator(dimension);                                  zoomBackIndex = lastZooms.size();
242        // Tool buttons                                  setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);
243        for (JToggleButton b : toolButtons.values())                                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
244          add(b);                          }
245        // Space between tool buttons and action buttons                  };
246        Dimension dimension2 = new Dimension( 10,10);  
247        this.addSeparator(dimension2);                  setMapPane(mapPane);
248        // Action buttons                  setFloatable(false);
249        for (JButton b : actionButtons.values())                  setRollover(true);
250          add(b);  
251      }                  init();
252                }
253          /**  
254           * Performs the activation of a tool.          /**
255           * @param tool the tool to activate           * Sets the {@link JMapPane} controlled by this tool bar.
256           * @param e    the event of the button           *
257           */           * @param mapPane
258          public void performToolButton(int tool, ActionEvent e) {           *            {@link JMapPane} to control (if {@code null} this tool bar
259            if ( mapPane == null )           *            controls NOTHING!)
260              return;           */
261                      public void setMapPane(JMapPane mapPane) {
262            selectedTool = tool;                  // Remove listener from old MapPane
263                              if (this.mapPane != null)
264        switch( tool ) {                          this.mapPane.removeMapPaneListener(mapPaneListener);
265          case TOOL_PAN:                  this.mapPane = mapPane;
266            // Set the mouse tool to "Panning"                  if (this.mapPane != null && mapPaneListener != null)
267            mapPane.setWindowSelectionState(JMapPane.NONE);                          this.mapPane.addMapPaneListener(mapPaneListener);
268            mapPane.setState(JMapPane.PAN);          }
269            mapPane.setHighlight(false);  
270            mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);          /**
271            break;           * Calls {@link #initToolsAndActions()} and {@link #initActions()} and then
272          case TOOL_INFO:           * puts all tool buttons and all actions buttons to the tool bar.
273            // Set the mouse tool to "Info"           */
274            mapPane.setWindowSelectionState(JMapPane.NONE);          protected void init() {
275            mapPane.setState(JMapPane.SELECT_TOP);                  initToolsAndActions();
276            mapPane.setHighlight(true);  
277            mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);                  addSeparator(SEPERATOR0, new JToolBar.Separator());
278            break;                  addSeparator(SEPERATOR1, new JToolBar.Separator());
279          case TOOL_ZOOMIN:  
280            // Set the mouse tool to "Zoom in"                  initToolBar();
281            mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);          }
282            mapPane.setState(JMapPane.ZOOM_IN);  
283            mapPane.setHighlight(false);          /**
284            mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);           * Creates the tool buttons and action buttons and seperators, adds them to
285            break;           * {@link #toolAndActionButtons} and finally creates a button group for all
286          case TOOL_ZOOMOUT:           * tools. So sub-classes which override this method should FIRST add their
287            // Set the mouse tool to "Zoom out"           * new tool buttons to {@link #toolAndActionButtons} before calling {@code
288            mapPane.setWindowSelectionState(JMapPane.NONE);           * super.initTools()}.
289            mapPane.setState(JMapPane.ZOOM_OUT);           */
290            mapPane.setHighlight(false);          protected void initToolsAndActions() {
291            mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                  // Panning
292            break;                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
293          default:                                  MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);
294            // Set map actions to default                  // Info
295            mapPane.setWindowSelectionState(JMapPane.NONE);                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
296            mapPane.setState(JMapPane.NONE);                                  MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);
297            mapPane.setHighlight(false);  
298            mapPane.setNormalCursor(null);                  // Zoom in
299            break;                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
300        }                                  MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),
301        mapPane.updateCursor();                                  false);
302          }                  // Zoom out
303                            addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
304      /**                                  MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),
305       * Performs the action of an action button.                                  false);
306       * @param tool the action  
307       * @param e    the event of the button                  // Action button to revert the last zoom
308       */                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
309          protected void performActionButton(int action, ActionEvent e) {                                  new ImageIcon(MapView.class
310        if ( mapPane == null )                                                  .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);
311          return;                  setButtonEnabled(ACTION_ZOOM_BACK, false);
312    
313        // Perform the action "Zoom back": Revert the last zoom                  // Action button to redo the last zoom
314        if ( action == ACTION_ZOOM_BACK ) {                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
315              if (zoomBackIndex <= 1)                                  new ImageIcon(MapView.class
316            return;                                                  .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),
317                                      false);
318          zoomBackForwardButtonInAction = true;                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
319          zoomBackIndex--;  
320          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);                  // set the selected tool enabled
321          getButton(ACTION_ZOOM_BACK).setEnabled( zoomBackIndex > 1 );                  setSelectedTool(selectedTool);
322      
323          mapPane.setMapArea( lastZooms.get(zoomBackIndex-1) );          }
324          mapPane.refresh();  
325        }          /**
326             * Clears the GUI of all components and adds all tool and action buttons to
327        // Perform the action "Zoom forward": Redo the last zoom           * the tool bar.
328        if ( action == ACTION_ZOOM_FORWARD ) {           */
329          if (zoomBackIndex < lastZooms.size()) {          public void initToolBar() {
330            zoomBackForwardButtonInAction = true;                  setAlignmentY(1f);
331            zoomBackIndex++;                  removeAll();
332            getButton(ACTION_ZOOM_BACK).setEnabled(true);                  // Separator to the left of the tool actions to start
333            getButton(ACTION_ZOOM_FORWARD).setEnabled(zoomBackIndex < lastZooms.size());                  // the tool buttons with the map (not with the coordinate grid)
334                    Dimension dimension = new Dimension(49, 10);
335            mapPane.setMapArea( lastZooms.get(zoomBackIndex-1) );                  addSeparator(dimension);
336            mapPane.refresh();                  // Tool buttons
337          }                  for (Integer bKey : toolAndActionButtons.keySet()) {
338        }                          
339          }                          JComponent b = toolAndActionButtons.get(bKey);
340                                    
341                                    if (b instanceof JToggleButton) {
342          /**                                  JToggleButton tb = (JToggleButton) b;
343           * Adds a tool to the tool bar. Does nothing if a tool or action with the                                  tb.setName(bKey.toString());
344           * specified ID already exists!                                  tb.addActionListener( toolSelectedListener );
345           * @param buttonAction action for the toggle button                          }
346           * @param resetToolBar indicates whether the toolbar GUI is reset after adding                          
347           *                     the button (if adding several actions it useful only to                          add(b);
348           *                     reset the GUI for the last added tool)                  }
349           */  
350          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {                  if (!toolAndActionButtons.containsKey(selectedTool)) {
351            if ( isButtonIDUsed(buttonAction.getID()) ) {                          /**
352              LOGGER.warn("addTool(.) ignored because ID already used for tool or action: "+buttonAction.getID());                           * This might be a bit specific, but IF selection buttons are
353              return;                           * available, select one of them.. if not, select the INFO tool.
354            }                           */
355            JToggleButton button = new JToggleButton(buttonAction);  
356            button.setBorder( BorderFactory.createRaisedBevelBorder() );                          if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
357            toolButtonGroup.add(button);                                  setSelectedTool(TOOL_SELECTION_SET);
358            toolButtons.put(buttonAction.getID(), button);                          } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
359            if ( resetToolBar )                                  setSelectedTool(TOOL_INFO);
360              initToolBar();                          } else {
361          }                                  // TODO What to do now?!
362                                    setSelectedTool(null);
363      /**                          }
364       * Adds a tool to the tool bar and resets the toolbar GUI.  
365       * @param buttonAction action for the toggle button                  }
366       */                  
367      public void addTool(MapPaneToolBarAction buttonAction) {                  revalidate();
368        addTool(buttonAction, true);                  repaint();
369      }          }
370    
371      /**          // Space between tool buttons and action buttons
372       * Adds an action to the tool bar. Does nothing if a tool or action with the          // SK: Seperators are now als manages like actions and tools
373       * specified ID already exists!          // Dimension dimension2 = new Dimension( 10,10);
374       * @param buttonAction action for the button          // this.addSeparator(dimension2);
375       * @param resetToolBar indicates whether the toolbar GUI is reset after adding  
376       *                     the button (if adding several actions it useful only to          // // Action buttons
377       *                     reset the GUI for the last added tool)          // for (JButton b : actionButtons.values())
378       */          // add(b);
379      public void addAction(MapPaneToolBarAction buttonAction, boolean resetToolBar) {          // }
380        if ( isButtonIDUsed(buttonAction.getID()) ) {  
381          LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "+buttonAction.getID());          /**
382          return;           * Performs the activation of a tool.
383        }           *
384        JButton button = new JButton(buttonAction);           * @param tool
385        actionButtons.put( buttonAction.getID(), button );           *            the tool to activate
386        if ( resetToolBar )           * @param e
387          initToolBar();           *            the event of the button
388      }           */
389            public void performToolButton(int tool, ActionEvent e) {
390      /**                  if (mapPane == null)
391       * Adds an action to the tool bar and resets the toolbar GUI.                          return;
392       * @param buttonAction action for the toggle button  
393       */                  selectedTool = tool;
394      public void addAction(MapPaneToolBarAction buttonAction) {  
395        addAction(buttonAction, true);                  switch (tool) {
396      }                  case TOOL_PAN:
397                                // Set the mouse tool to "Panning"
398      /**                          mapPane.setWindowSelectionState(JMapPane.NONE);
399       * Returns the button for a specific tool or action.                          mapPane.setState(JMapPane.PAN);
400       * @param id the constant for a tool                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
401       * @return a {@link JButton} if {@code id} specifies an {@linkplain #getActionButton(int) action button}                          break;
402       *         or {@link JToogleButton} if {@code id} specifies a {@linkplain #getToolButton(int) tool button}                  case TOOL_INFO:
403       */                          // Set the mouse tool to "Info"
404      public AbstractButton getButton(int id) {                          mapPane.setWindowSelectionState(JMapPane.NONE);
405        AbstractButton button = toolButtons.get(id);                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:
406        if ( button == null )                          // JMapPane.SELECT_TOP_ONEONLY
407          button = actionButtons.get(id);                          // properly removed it to save
408        if ( button == null )                          // performance
409          LOGGER.warn("Unknown tool or action ID: "+id);                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
410        return button;                          break;
411      }                  case TOOL_ZOOMIN:
412                            // Set the mouse tool to "Zoom in"
413      /**                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);
414       * Returns the button for a specific tool.                          mapPane.setState(JMapPane.ZOOM_IN);
415       * @param tool the constant for a tool                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
416       */                          break;
417          public JToggleButton getToolButton(int tool) {                  case TOOL_ZOOMOUT:
418        AbstractButton button = getButton(tool);                          // Set the mouse tool to "Zoom out"
419        if ( button != null && !(button instanceof JToggleButton) ) {                          mapPane.setWindowSelectionState(JMapPane.NONE);
420          LOGGER.warn("ID specifies no tool: "+tool);                          mapPane.setState(JMapPane.ZOOM_OUT);
421          button = null;                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
422        }                          break;
423        return (JToggleButton)button;                  default:
424      }                          // Set map actions to default
425                            mapPane.setWindowSelectionState(JMapPane.NONE);
426      /**                          mapPane.setState(JMapPane.NONE);
427       * Returns the button for a specific action.                          mapPane.setNormalCursor(null);
428       * @param action the constant an action                          break;
429       */                  }
430      public JButton getActionButton(int action) {                  mapPane.updateCursor();
431        AbstractButton button = getButton(action);          }
432        if ( button != null && !(button instanceof JButton) ) {  
433          LOGGER.warn("ID specifies no action: "+action);          /**
434          button = null;           * @param id
435        }           *            The ID of the Component to remove. The change will not be
436        return (JButton)button;           *            visible until {@link #initToolBar()} is called.
437             * @return <code>null</code> or the component that has been removed.
438      }           */
439            public JComponent removeId(int id) {
440          /**                  return toolAndActionButtons.remove(id);
441           * Sets the selected tool.          }
442           * @param tool ID of the tool  
443           */          /**
444          public void setSelectedTool(Integer tool) {           * Performs the action of an action button.
445            if ( tool == null )           *
446              toolButtonGroup.setUnselected();           * @param tool
447                       *            the action
448            JToggleButton button = getToolButton(tool);           * @param e
449            if ( button == null )           *            the event of the button
450              return;           */
451            button.setSelected( true );          protected void performActionButton(int action, ActionEvent e) {
452            button.getAction().actionPerformed(null);                  if (mapPane == null)
453          }                          return;
454            
455          /**                  // Perform the action "Zoom back": Revert the last zoom
456           * Returns the selected tool.                  if (action == ACTION_ZOOM_BACK) {
457           * @return -1 if no tool is active                          if (zoomBackIndex <= 1)
458           */                                  return;
459          public int getSelectedTool() {  
460            if ( toolButtonGroup.getSelectedButton() == null )                          zoomBackForwardButtonInAction = true;
461              return -1;                          zoomBackIndex--;
462            return selectedTool;                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);
463          }                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);
464            
465      /**                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
466       * Sets whether a tool or action is activated or not. The visible property                          mapPane.refresh();
467       * of the button is not affected.                  }
468       * @param id tool or actionID  
469       * @param enabled if {@code true} the tool becomes available                  // Perform the action "Zoom forward": Re-do the last zoom
470       */                  if (action == ACTION_ZOOM_FORWARD) {
471      public void setButtonEnabled(int id, boolean enabled) {                          if (zoomBackIndex < lastZooms.size()) {
472        AbstractButton button = getButton(id);                                  zoomBackForwardButtonInAction = true;
473        if ( button == null )                                  zoomBackIndex++;
474          return;                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);
475        button.setEnabled( enabled );                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(
476      }                                                  zoomBackIndex < lastZooms.size());
477    
478      /**                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
479       * Sets whether a tool or action is activated or not.                                  mapPane.refresh();
480       * @param id tool or actionID                          }
481       * @param enabled if {@code true} the tool becomes available                  }
482       * @param hideOnDisable if {@code true} the button is also hidden if          }
483       *                      {@code enabled} is {@code false}  
484       */          /**
485          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {           * Adds a tool to the tool bar. Does nothing if a tool or action with the
486            AbstractButton button = getButton(id);           * specified ID already exists!
487            if ( button == null )           *
488              return;           * @param buttonAction
489            button.setEnabled( enabled );           *            action for the toggle button
490            // if button is enabled, it becomes visible anyway           * @param resetToolBar
491            // if button is disabled and the "hide" option is set, it is also hidden           *            indicates whether the toolbar GUI is reset after adding the
492            if ( enabled )           *            button (if adding several actions it useful only to reset the
493              button.setVisible( true );           *            GUI for the last added tool)
494            else           */
495              button.setVisible( !hideOnDisable );          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
496          }                  if (isButtonIDUsed(buttonAction.getID())) {
497                            LOGGER
498      /**                                          .warn("addTool(.) ignored because ID already used for tool or action: "
499       * Checks whether a ID is already used for a tool or action.                                                          + buttonAction.getID());
500       * @param tool tool ID                          return;
501       */                  }
502      public boolean isButtonIDUsed(int id) {                  JToggleButton button = new JToggleButton(buttonAction);
503        return toolButtons.get(id) != null || actionButtons.get(id) != null;                  button.setBorder(BorderFactory.createRaisedBevelBorder());
504      }                  toolButtonGroup.add(button);
505                    toolAndActionButtons.put(buttonAction.getID(), button);
506      /**                  if (resetToolBar)
507       * Checks whether a tool is activated.                          initToolBar();
508       * @param tool tool ID          }
509       * @return {@code false} if an unknown ID is specified  
510       */  
511      public boolean isButtonEnabled(int id) {  
512        AbstractButton button = getButton(id);          /**
513        if ( button != null )           * Adds a tool to the tool bar and resets the toolbar GUI.
514          return button.isEnabled();           *
515        return false;           * @param buttonAction
516      }           *            action for the toggle button
517             */
518      /**          public void addTool(MapPaneToolBarAction buttonAction) {
519       * Sets the activation for all tools.                  addTool(buttonAction, true);
520       * @param enabled if {@code true} all tools becomes available          }
521       * @param hideOnDisable if {@code true} the buttons are also hidden if  
522       *                      {@code enabled} is {@code false}          /**
523       */           * Adds an action to the tool bar. Does nothing if a tool or action with the
524      public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {           * specified ID already exists!
525        for (int tool : toolButtons.keySet())           *
526          setButtonEnabled(tool,enabled,hideOnDisable);           * @param buttonAction
527      }             *            action for the button
528             * @param resetToolBar
529      /**           *            indicates whether the toolbar GUI is reset after adding the
530       * Sets the activation for all actions.           *            button (if adding several actions it useful only to reset the
531       * @param enabled if {@code true} all actions becomes available           *            GUI for the last added tool)
532       * @param hideOnDisable if {@code true} the buttons are also hidden if           */
533       *                      {@code enabled} is {@code false}          public void addAction(MapPaneToolBarAction buttonAction,
534       */                          boolean resetToolBar) {
535      public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {                  if (isButtonIDUsed(buttonAction.getID())) {
536        for (int tool : actionButtons.keySet())                          LOGGER
537          setButtonEnabled(tool,enabled,hideOnDisable);                                          .warn("addAction(.) ignored because ID already used for tool or action: "
538      }                                                            + buttonAction.getID());
539                                return;
540      /**                  }
541       * Returns the maximum ID of tools.                  JButton button = new JButton(buttonAction);
542       */                  button.setBorder(BorderFactory.createRaisedBevelBorder());
543      public int getMaxToolID() {                  toolAndActionButtons.put(buttonAction.getID(), button);
544        return toolButtons.lastKey();                  if (resetToolBar)
545      }                          initToolBar();
546            }
547      /**          
548       * Returns the minimum ID of tools.          /**
549       */           * Adds any JComponent to the tool bar. Does nothing if a tool or action with the
550      public int getMinToolID() {           * specified ID already exists!
551        return toolButtons.firstKey();           *
552      }           * @param component A {@link JComponent} that shall be added
553             * @param id The ID associaded with the {@link JComponent}
554      /**           * @param resetToolBar
555       * Returns the maximum ID of actions.           *            indicates whether the toolbar GUI is reset after adding the
556       */           *            button (if adding several actions it useful only to reset the
557      public int getMaxActionID() {           *            GUI for the last added tool)
558        return actionButtons.lastKey();           */
559      }          public void addJComponent(JComponent component, int id,
560                            boolean resetToolBar) {
561      /**  
562       * Returns the minimum ID of actions.                  if (isButtonIDUsed(id)) {
563       */                          LOGGER
564      public int getMinActionID() {                          .warn("addAction(.) ignored because ID already used for tool or action: "
565        return actionButtons.firstKey();                                          + id);
566      }                          return;
567                        }
568      /**                  
569       * Extends the {@link AbstractAction} with maintaining an ID and                  toolAndActionButtons.put(id, component);
570       * the {@link MapPaneToolBar} the actions controls.                  if (resetToolBar)
571       * Additionally this class automatically calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)}                          initToolBar();
572       * or {@link MapPaneToolBar#performActionButton(int, ActionEvent)}          }
573       * depending on whether the action is added via {@link MapPaneToolBar#addTool(MapPaneToolBarAction)}  
574       * or {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.          public void addSeparator(int id, Separator separator) {
575       * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)                  if (isButtonIDUsed(id)) {
576       */                          LOGGER
577      public static class MapPaneToolBarAction extends AbstractAction {                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");
578        /** The ID of the action */                          return;
579        protected int id = -1;                  }
580        /** The tool bar, this action is made for. */                  toolAndActionButtons.put(id, separator);
581        protected MapPaneToolBar toolBar = null;          }
582    
583        /**          /**
584         * Creates a new action with a dummy description and no icon.           * Adds an action to the tool bar and resets the toolbar GUI.
585         * @param id      unique ID for the action           *
586         * @param toolBar toolbar this action is made for           * @param buttonAction
587         */           *            action for the toggle button
588        public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {           */
589          this(id,toolBar,""+id);          public void addAction(MapPaneToolBarAction buttonAction) {
590        }                  addAction(buttonAction, true);
591            }
592        /**  
593         * Creates a new action without an icon.          /**
594         * @param id      unique ID for the action           * Returns the button for a specific tool or action.
595         * @param toolBar toolbar this action is made for           *
596         * @param name    description used for buttons or menus           * @param id
597         */           *            the constant for any button in the {@link MapPaneToolBar}
598        public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {           * @return a {@link JButton} if {@code id} specifies an
599          this(id,toolBar,name,null);           *         {@linkplain #getActionButton(int) action button} or
600        }           *         {@link JToogleButton} if {@code id} specifies a
601             *         {@linkplain #getToolButton(int) tool button}
602        /**           */
603         * Creates a new action.          public AbstractButton getButton(int id) {
604         * @param id      unique ID for the action                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
605         * @param toolBar toolbar this action is made for                  if (button == null)
606         * @param name    description used for buttons or menus                          LOGGER.warn("Unknown tool or action ID: " + id);
607         * @param icon    icon used for buttons or menus                  return button;
608         */          }
609        public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name, Icon icon) {  
610          super(name,icon);          /**
611          this.id      = id;           * Returns the button for a specific tool.
612          this.toolBar = toolBar;           *
613        }           * @param tool
614                   *            the constant for a tool
615        /**           */
616         * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)}          public JToggleButton getToolButton(int tool) {
617         * or {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                  AbstractButton button = getButton(tool);
618         * depending on whether the action is added to the toolbar via                  if (button != null && !(button instanceof JToggleButton)) {
619         * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)}                          LOGGER.warn("ID specifies no tool: " + tool);
620         * or {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.                          button = null;
621         */                  }
622        public void actionPerformed(ActionEvent e) {                  return (JToggleButton) button;
623          if ( toolBar.toolButtons.get(id) != null )          }
624            toolBar.performToolButton(id, e);  
625          if ( toolBar.actionButtons.get(id) != null )          /**
626            toolBar.performActionButton(id, e);           * Returns the button for a specific action.
627        }           *
628                   * @param action
629        /**           *            the constant an action
630         * Returns the (unique) id of this action.           */
631         * @return          public JButton getActionButton(int action) {
632         */                  AbstractButton button = getButton(action);
633        public int getID() {                  if (button != null && !(button instanceof JButton)) {
634          return id;                          LOGGER.warn("ID specifies no action: " + action);
635        }                          button = null;
636      }                  }
637  }                  return (JButton) button;
638    
639            }
640    
641            /**
642             * Sets the selected tool.
643             *
644             * @param tool
645             *            ID of the tool
646             */
647            public void setSelectedTool(Integer tool) {
648                    if (tool == null)
649                            toolButtonGroup.setUnselected();
650    
651                    JToggleButton button = getToolButton(tool);
652                    if (button == null)
653                            return;
654                    button.setSelected(true);
655                    button.getAction().actionPerformed(null);
656    
657                    selectedTool = tool;
658            }
659    
660            /**
661             * Returns the selected tool.
662             *
663             * @return -1 if no tool is active
664             */
665            public int getSelectedTool() {
666                    if (toolButtonGroup.getSelectedButton() == null)
667                            return -1;
668                    return selectedTool;
669            }
670    
671            /**
672             * Sets whether a tool or action is activated or not. The visible property
673             * of the button is not affected.
674             *
675             * @param id
676             *            tool or actionID
677             * @param enabled
678             *            if {@code true} the tool becomes available
679             */
680            public void setButtonEnabled(int id, boolean enabled) {
681                    AbstractButton button = getButton(id);
682                    if (button == null)
683                            return;
684                    button.setEnabled(enabled);
685            }
686    
687            /**
688             * Sets whether a tool or action is activated or not.
689             *
690             * @param id
691             *            tool or actionID
692             * @param enabled
693             *            if {@code true} the tool becomes available
694             * @param hideOnDisable
695             *            if {@code true} the button is also hidden if {@code enabled}
696             *            is {@code false}
697             */
698            public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
699                    AbstractButton button = getButton(id);
700                    if (button == null)
701                            return;
702                    button.setEnabled(enabled);
703                    // if button is enabled, it becomes visible anyway
704                    // if button is disabled and the "hide" option is set, it is also hidden
705                    if (enabled)
706                            button.setVisible(true);
707                    else
708                            button.setVisible(!hideOnDisable);
709            }
710    
711            /**
712             * Checks whether a ID is already used for a tool or action.
713             *
714             * @param tool
715             *            tool ID
716             */
717            public boolean isButtonIDUsed(int id) {
718                    return toolAndActionButtons.get(id) != null;
719            }
720    
721            /**
722             * Checks whether a tool is activated.
723             *
724             * @param tool
725             *            tool ID
726             * @return {@code false} if an unknown ID is specified
727             */
728            public boolean isButtonEnabled(int id) {
729                    AbstractButton button = getButton(id);
730                    if (button != null)
731                            return button.isEnabled();
732                    return false;
733            }
734    
735            /**
736             * Sets the activation for all tools.
737             *
738             * @param enabled
739             *            if {@code true} all tools becomes available
740             * @param hideOnDisable
741             *            if {@code true} the buttons are also hidden if {@code enabled}
742             *            is {@code false}
743             */
744            public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
745                    for (int tool : toolAndActionButtons.keySet())
746                            setButtonEnabled(tool, enabled, hideOnDisable);
747            }
748    
749            /**
750             * Sets the activation for all actions.
751             *
752             * @param enabled
753             *            if {@code true} all actions becomes available
754             * @param hideOnDisable
755             *            if {@code true} the buttons are also hidden if {@code enabled}
756             *            is {@code false}
757             */
758            public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
759                    for (int id : toolAndActionButtons.keySet()) {
760                            if (toolAndActionButtons.get(id) instanceof JButton) {
761                                    setButtonEnabled(id, enabled, hideOnDisable);
762                            }
763                    }
764    
765            }
766    
767            /**
768             * Returns the maximum ID of tools.
769             */
770            public int getMaxToolID() {
771                    return toolAndActionButtons.lastKey();
772            }
773    
774            /**
775             * Returns the minimum ID of tools.
776             */
777            public int getMinToolID() {
778                    return toolAndActionButtons.firstKey();
779            }
780    
781            /**
782             * Extends the {@link AbstractAction} with maintaining an ID and the
783             * {@link MapPaneToolBar} the actions controls. Additionally this class
784             * automatically calls
785             * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
786             * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on
787             * whether the action is added via
788             * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
789             * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
790             *
791             * @author <a href="mailto:[email protected]">Martin Schmitz</a>
792             *         (University of Bonn/Germany)
793             */
794            public static class MapPaneToolBarAction extends AbstractAction {
795                    /** The ID of the action */
796                    protected int id = -1;
797                    /** The tool bar, this action is made for. */
798                    protected MapPaneToolBar toolBar = null;
799    
800                    /**
801                     * Creates a new action with a dummy description and no icon.
802                     *
803                     * @param id
804                     *            unique ID for the action
805                     * @param toolBar
806                     *            toolbar this action is made for
807                     */
808                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {
809                            this(id, toolBar, "" + id);
810                    }
811    
812                    /**
813                     * Creates a new action without an icon.
814                     *
815                     * @param id
816                     *            unique ID for the action
817                     * @param toolBar
818                     *            toolbar this action is made for
819                     * @param name
820                     *            description used for buttons or menus
821                     */
822                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {
823                            this(id, toolBar, name, null);
824                    }
825    
826                    /**
827                     * Creates a new action.
828                     *
829                     * @param id
830                     *            unique ID for the action
831                     * @param toolBar
832                     *            toolbar this action is made for
833                     * @param name
834                     *            description used for buttons or menus
835                     * @param icon
836                     *            icon used for buttons or menus
837                     */
838                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
839                                    String name, Icon icon) {
840                            this (id, toolBar, name, icon, null);
841                    }
842                    
843                    /**
844                     * Creates a new action.
845                     *
846                     * @param id
847                     *            unique ID for the action
848                     * @param toolBar
849                     *            The {@link MapPaneToolBar} this action is made for
850                     * @param name
851                     *            description used for buttons or menus
852                     * @param icon
853                     *            icon used for buttons or menus
854                     * @param toolTip
855                     *            Tooltip to use for the button or menu
856                     */
857                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
858                                    String name, Icon icon, String toolTip) {
859                            super(name, icon);
860                            
861                            if (toolTip != null && !toolTip.trim().isEmpty()){
862                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
863                            }
864                            
865                            this.id = id;
866                            this.toolBar = toolBar;
867                    }
868    
869                    /**
870                     * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
871                     * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
872                     * depending on whether the action is added to the toolbar via
873                     * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
874                     * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
875                     */
876                    public void actionPerformed(ActionEvent e) {
877                            if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)
878                                    toolBar.performToolButton(id, e);
879                            else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)
880                                    toolBar.performActionButton(id, e);
881                    }
882    
883                    /**
884                     * Returns the (unique) id of this action.
885                     *
886                     * @return
887                     */
888                    public int getID() {
889                            return id;
890                    }
891            }
892            
893              /**
894               * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der
895               * Hintergrund auf WEISS gesetzt.
896               *
897               * @author <a href="mailto:[email protected]">Stefan Alfons
898               *         Kr&uuml;ger</a>
899               */
900              @Override
901              public void print(Graphics g) {
902                  Color orig = getBackground();
903                  setBackground(Color.WHITE);
904                  // wrap in try/finally so that we always restore the state
905                  try {
906                      super.print(g);
907                  } finally {
908                      setBackground(orig);
909                  }
910              }
911    
912    }

Legend:
Removed from v.48  
changed lines
  Added in v.414

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26