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

Legend:
Removed from v.177  
changed lines
  Added in v.417

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26