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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26