/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java

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

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26