/[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/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java revision 621 by alfonx, Thu Jan 28 10:06:05 2010 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.Icon;
47  public class MapPaneToolBar extends JToolBar {  import javax.swing.ImageIcon;
48          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class  import javax.swing.JButton;
49                          .getName());  import javax.swing.JComponent;
50            import javax.swing.JToggleButton;
51          public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil  import javax.swing.JToolBar;
52                          .extendPackagePath(MapPaneToolBar.class,  
53                                          "resource.locales.mapPaneToolbar"), Locale.ENGLISH);  import org.apache.log4j.Logger;
54            
55          public static String R(String key, Object... values) {  import schmitzm.geotools.gui.SelectableXMapPane;
56                  return RESOURCE.getString(key, values);  import schmitzm.geotools.map.event.JMapPaneListener;
57          }  import schmitzm.geotools.map.event.MapAreaChangedEvent;
58    import schmitzm.geotools.map.event.MapPaneEvent;
59          /** Constant for the tool "Panning" (10). */  import schmitzm.lang.LangUtil;
60          public static final int TOOL_PAN = 10;  import schmitzm.lang.ResourceProvider;
61          /** Constant for the tool "Info" (20). */  import schmitzm.swing.ButtonGroup;
62          public static final int TOOL_INFO = 20;  import skrueger.swing.SmallButton;
63          public static final int SEPERATOR0 = 99;  import skrueger.swing.SmallToggleButton;
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 SelectableXMapPane} (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 SelectableXMapPane} this tool bar controls. */
143                            protected SelectableXMapPane 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(SelectableXMapPane)} 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(
189                  setFloatable(false);                          MapPaneToolSelectedListener listener) {
190                  setRollover(true);                  toolSelectionListeners.remove(listener);
191            }
192                  init();  
193          }          /**
194             * Creates a new tool bar.
195          /**           *
196           * Sets the {@link JMapPane} controlled by this tool bar.           * @param mapPane
197           *           *            {@link SelectableXMapPane} the tool bar controls
198           * @param mapPane           */
199           *            {@link JMapPane} to control (if {@code null} this tool bar          public MapPaneToolBar(SelectableXMapPane mapPane) {
200           *            controls NOTHING!)                  super("Control the map", JToolBar.HORIZONTAL);
201           */  
202          public void setMapPane(JMapPane mapPane) {                  // I want to see nothing on the background
203                  // Remove listener from old MapPane                  setOpaque(false);
204                  if (this.mapPane != null)                  setBorder(null);
205                          this.mapPane.removeMapPaneListener(mapPaneListener);  
206                  this.mapPane = mapPane;                  this.toolButtonGroup = new ButtonGroup();
207                  if (this.mapPane != null && mapPaneListener != null)  
208                          this.mapPane.addMapPaneListener(mapPaneListener);                  // Create a Listener to listen to the zooms on the JMapPane
209          }                  this.mapPaneListener = new JMapPaneListener() {
210                            public void performMapPaneEvent(MapPaneEvent e) {
211          /**                                  if (!(e instanceof MapAreaChangedEvent))
212           * Calls {@link #initToolsAndActions()} and {@link #initActions()} and then                                          return;
213           * puts all tool buttons and all actions buttons to the tool bar.  
214           */                                  if (zoomBackForwardButtonInAction) {
215          protected void init() {                                          zoomBackForwardButtonInAction = false;
216                  initToolsAndActions();                                          return;
217                                    }
218                  addSeparator(SEPERATOR0, new JToolBar.Separator());  
219                  addSeparator(SEPERATOR1, new JToolBar.Separator());                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
220                                    Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
221                  initToolBar();  
222          }                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
223                                    if (mapArea == null || mapArea.equals(oldMapArea)
224          /**                                                  || Double.isNaN(mapArea.getMinX())
225           * Creates the tool buttons and action buttons and seperators, adds them to                                                  || Double.isNaN(mapArea.getMaxX())
226           * {@link #toolAndActionButtons} and finally creates a button group for all                                                  || Double.isNaN(mapArea.getMinY())
227           * tools. So sub-classes which override this method should FIRST add their                                                  || Double.isNaN(mapArea.getMaxY())) {
228           * new tool buttons to {@link #toolAndActionButtons} before calling {@code                                          // If the MapArea didn't change... we don't want to register
229           * super.initTools()}.                                          // it as a zoom action.
230           */                                          return;
231          protected void initToolsAndActions() {                                  }
232                  // Panning  
233                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(                                  if (lastZooms.size() == 0
234                                  MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);                                                  && oldMapArea != null
235                  // Info                                                  && !oldMapArea.isNull()
236                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(                                                  && !(Double.isNaN(oldMapArea.getMinX())
237                                  MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);                                                                  || Double.isNaN(oldMapArea.getMaxX())
238                                                                    || Double.isNaN(oldMapArea.getMinY()) || Double
239                  // Zoom in                                                                  .isNaN(oldMapArea.getMaxY()))) {
240                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                                          lastZooms.add(oldMapArea);
241                                  MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),                                          zoomBackIndex = 1;
242                                  false);                                  }
243                  // Zoom out                                  if (mapArea == null)
244                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                                          return;
245                                  MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),  
246                                  false);                                  if (lastZooms.size() > 0
247                                                    && mapArea.equals(lastZooms.get(lastZooms.size() - 1))) {
248                  // Action button to revert the last zoom                                          // LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch");
249                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                                          return;
250                                  new ImageIcon(MapView.class                                  }
251                                                  .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);  
252                  setButtonEnabled(ACTION_ZOOM_BACK, false);                                  if (lastZooms.size() > 0)
253                                            while (zoomBackIndex < lastZooms.size())
254                  // Action button to redo the last zoom                                                  lastZooms.remove(lastZooms.size() - 1);
255                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",  
256                                  new ImageIcon(MapView.class                                  lastZooms.add(mapArea);
257                                                  .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),                                  zoomBackIndex = lastZooms.size();
258                                  false);                                  setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);
259                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
260                            }
261                  // set the selected tool enabled                  };
262                  setSelectedTool(selectedTool);  
263                    setMapPane(mapPane);
264          }                  setFloatable(false);
265                    setRollover(true);
266          /**  
267           * Clears the GUI of all components and adds all tool and action buttons to                  init();
268           * the tool bar.          }
269           */  
270          public void initToolBar() {          /**
271                  setAlignmentY(1f);           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
272                  removeAll();           *
273                  // Separator to the left of the tool actions to start           * @param mapPane
274                  // the tool buttons with the map (not with the coordinate grid)           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
275                  Dimension dimension = new Dimension(49, 10);           *            controls NOTHING!)
276                  addSeparator(dimension);           */
277                  // Tool buttons          public void setMapPane(SelectableXMapPane mapPane) {
278                  for (JComponent b : toolAndActionButtons.values())                  // Remove listener from old MapPane
279                          add(b);                  if (this.mapPane != null)
280                            this.mapPane.removeMapPaneListener(mapPaneListener);
281                  if (!toolAndActionButtons.containsKey(selectedTool)) {                  this.mapPane = mapPane;
282                          /**                  if (this.mapPane != null && mapPaneListener != null)
283                           * This might be a bit specific, but IF selection buttons are                          this.mapPane.addMapPaneListener(mapPaneListener);
284                           * available, select one of them.. if not, select the INFO tool.          }
285                           */  
286            /**
287                          if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {           * Calls {@link #initToolsAndActions()} and {@link #initActions()} and then
288                                  setSelectedTool(TOOL_SELECTION_SET);           * puts all tool buttons and all actions buttons to the tool bar.
289                          } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {           */
290                                  setSelectedTool(TOOL_INFO);          protected void init() {
291                          } else {  
292                                  // TODO What to do now?!                  initToolsAndActions();
293                                  setSelectedTool(null);  
294                          }                  addSeparator(SEPERATOR0, new JToolBar.Separator());
295                    addSeparator(SEPERATOR1, new JToolBar.Separator());
296                  }  
297                                    initToolBar();
298                  revalidate();          }
299                  repaint();  
300          }          /**
301             * Creates the tool buttons and action buttons and seperators, adds them to
302          // Space between tool buttons and action buttons           * {@link #toolAndActionButtons} and finally creates a button group for all
303          // SK: Seperators are now als manages like actions and tools           * tools. So sub-classes which override this method should FIRST add their
304          // Dimension dimension2 = new Dimension( 10,10);           * new tool buttons to {@link #toolAndActionButtons} before calling {@code
305          // this.addSeparator(dimension2);           * super.initTools()}.
306             */
307          // // Action buttons          protected void initToolsAndActions() {
308          // for (JButton b : actionButtons.values())                  // Panning
309          // add(b);                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
310          // }                                  MapView.class.getResource("resource/icons/pan.png")),
311                                    R("MapPaneButtons.Pan.TT")), false);
312          /**                  // Info
313           * Performs the activation of a tool.                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
314           *                                  MapView.class.getResource("resource/icons/info.png")),
315           * @param tool                                  R("MapPaneButtons.Info.TT")), false);
316           *            the tool to activate  
317           * @param e                  // Zoom in
318           *            the event of the button                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
319           */                                  MapView.class.getResource("resource/icons/zoom_in.png")),
320          public void performToolButton(int tool, ActionEvent e) {                                  R("MapPaneButtons.ZoomIn.TT")), false);
321                  if (mapPane == null)                  // Zoom out
322                          return;                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
323                                    MapView.class.getResource("resource/icons/zoom_out.png")),
324                  selectedTool = tool;                                  R("MapPaneButtons.ZoomOut.TT")), false);
325    
326                  switch (tool) {                  // Action button to revert the last zoom
327                  case TOOL_PAN:                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
328                          // Set the mouse tool to "Panning"                                  new ImageIcon(MapView.class
329                          mapPane.setWindowSelectionState(JMapPane.NONE);                                                  .getResource("resource/icons/zoom_back.png")),
330                          mapPane.setState(JMapPane.PAN);                                  R("MapPaneButtons.LastZoom.TT")), false);
331                          mapPane.setHighlight(false);                  setButtonEnabled(ACTION_ZOOM_BACK, false);
332                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  
333                          break;                  // Action button to redo the last zoom
334                  case TOOL_INFO:                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
335                          // Set the mouse tool to "Info"                                  new ImageIcon(MapView.class
336                          mapPane.setWindowSelectionState(JMapPane.NONE);                                                  .getResource("resource/icons/zoom_forward.png")),
337                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:                                  R("MapPaneButtons.NextZoom.TT")), false);
338                          // JMapPane.SELECT_TOP_ONEONLY                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
339                          mapPane.setHighlight(false);// SK: Was true, but since it not works  
340                          // properly removed it to save                  // set the selected tool enabled
341                          // performance                  setSelectedTool(selectedTool);
342                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
343                          break;          }
344                  case TOOL_ZOOMIN:  
345                          // Set the mouse tool to "Zoom in"          @Override
346                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);          public void paint(Graphics g) {
347                          mapPane.setState(JMapPane.ZOOM_IN);                  super.paint(g);
348                          mapPane.setHighlight(false);          }
349                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
350                          break;          /**
351                  case TOOL_ZOOMOUT:           * Clears the GUI of all components and adds all tool and action buttons to
352                          // Set the mouse tool to "Zoom out"           * the tool bar.
353                          mapPane.setWindowSelectionState(JMapPane.NONE);           */
354                          mapPane.setState(JMapPane.ZOOM_OUT);          public void initToolBar() {
355                          mapPane.setHighlight(false);                  // setOpaque(true);
356                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                  //              
357                          break;                  // setAlignmentY(1f);
358                  default:                  // setAlignmentX(0.5f);
359                          // Set map actions to default                  removeAll();
360                          mapPane.setWindowSelectionState(JMapPane.NONE);  
361                          mapPane.setState(JMapPane.NONE);                  // // Separator to the left of the tool actions to start
362                          mapPane.setHighlight(false);                  // // the tool buttons with the map (not with the coordinate grid)
363                          mapPane.setNormalCursor(null);                  // Dimension dimension = new Dimension(49, 10);
364                          break;                  // addSeparator(dimension);
365                  }  
366                  mapPane.updateCursor();                  // Tool buttons
367          }                  for (Integer bKey : toolAndActionButtons.keySet()) {
368    
369          /**                          JComponent b = toolAndActionButtons.get(bKey);
370           * @param id  
371           *            The ID of the Component to remove. The change will not be                          if (b instanceof JToggleButton) {
372           *            visible until {@link #initToolBar()} is called.                                  JToggleButton tb = (JToggleButton) b;
373           * @return <code>null</code> or the component that has been removed.                                  tb.setName(bKey.toString());
374           */                                  tb.addActionListener(toolSelectedListener);
375          public JComponent removeId(int id) {                          }
376                  return toolAndActionButtons.remove(id);  
377          }                          add(b);
378                    }
379          /**  
380           * Performs the action of an action button.                  if (!toolAndActionButtons.containsKey(selectedTool)) {
381           *                          /**
382           * @param tool                           * This might be a bit specific, but IF selection buttons are
383           *            the action                           * available, select one of them.. if not, select the INFO tool.
384           * @param e                           */
385           *            the event of the button  
386           */                          if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
387          protected void performActionButton(int action, ActionEvent e) {                                  setSelectedTool(TOOL_SELECTION_SET);
388                  if (mapPane == null)                          } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
389                          return;                                  setSelectedTool(TOOL_INFO);
390                            } else {
391                  // Perform the action "Zoom back": Revert the last zoom                                  // TODO What to do now?!
392                  if (action == ACTION_ZOOM_BACK) {                                  setSelectedTool(null);
393                          if (zoomBackIndex <= 1)                          }
394                                  return;  
395                    }
396                          zoomBackForwardButtonInAction = true;  
397                          zoomBackIndex--;                  revalidate();
398                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);                  repaint();
399                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);          }
400    
401                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));          // Space between tool buttons and action buttons
402                          mapPane.refresh();          // SK: Seperators are now als manages like actions and tools
403                  }          // Dimension dimension2 = new Dimension( 10,10);
404            // this.addSeparator(dimension2);
405                  // Perform the action "Zoom forward": Re-do the last zoom  
406                  if (action == ACTION_ZOOM_FORWARD) {          // // Action buttons
407                          if (zoomBackIndex < lastZooms.size()) {          // for (JButton b : actionButtons.values())
408                                  zoomBackForwardButtonInAction = true;          // add(b);
409                                  zoomBackIndex++;          // }
410                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);  
411                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(          /**
412                                                  zoomBackIndex < lastZooms.size());           * Performs the activation of a tool.
413             *
414                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));           * @param tool
415                                  mapPane.refresh();           *            the tool to activate
416                          }           * @param e
417                  }           *            the event of the button
418          }           */
419            public void performToolButton(int tool, ActionEvent e) {
420          /**                  if (mapPane == null)
421           * Adds a tool to the tool bar. Does nothing if a tool or action with the                          return;
422           * specified ID already exists!  
423           *                  selectedTool = tool;
424           * @param buttonAction  
425           *            action for the toggle button                  switch (tool) {
426           * @param resetToolBar                  case TOOL_PAN:
427           *            indicates whether the toolbar GUI is reset after adding the                          // Set the mouse tool to "Panning"
428           *            button (if adding several actions it useful only to reset the                          mapPane.setState(SelectableXMapPane.PAN);
429           *            GUI for the last added tool)  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
430           */                          break;
431          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {                  case TOOL_INFO:
432                  if (isButtonIDUsed(buttonAction.getID())) {                          // Set the mouse tool to "Info"
433                          LOGGER                          mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);
434                                          .warn("addTool(.) ignored because ID already used for tool or action: "  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
435                                                          + buttonAction.getID());                          break;
436                          return;                  case TOOL_ZOOMIN:
437                  }                          // Set the mouse tool to "Zoom in"
438                  JToggleButton button = new JToggleButton(buttonAction);                          mapPane.setState(SelectableXMapPane.ZOOM_IN);
439                  button.setBorder(BorderFactory.createRaisedBevelBorder());  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
440                  toolButtonGroup.add(button);                          break;
441                  toolAndActionButtons.put(buttonAction.getID(), button);                  case TOOL_ZOOMOUT:
442                  if (resetToolBar)                          // Set the mouse tool to "Zoom out"
443                          initToolBar();                          mapPane.setState(SelectableXMapPane.ZOOM_OUT);
444          }  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
445                            break;
446          /**                  default:
447           * Adds a tool to the tool bar and resets the toolbar GUI.                          // Set map actions to default
448           *                          mapPane.setState(SelectableXMapPane.NONE);
449           * @param buttonAction  //                      mapPane.setNormalCursor(null);
450           *            action for the toggle button                          break;
451           */                  }
452          public void addTool(MapPaneToolBarAction buttonAction) {  //              mapPane.updateCursorAndRepaintTimer();
453                  addTool(buttonAction, true);          }
454          }  
455            /**
456          /**           * @param id
457           * Adds an action to the tool bar. Does nothing if a tool or action with the           *            The ID of the Component to remove. The change will not be
458           * specified ID already exists!           *            visible until {@link #initToolBar()} is called.
459           *           * @return <code>null</code> or the component that has been removed.
460           * @param buttonAction           */
461           *            action for the button          public JComponent removeId(int id) {
462           * @param resetToolBar                  return toolAndActionButtons.remove(id);
463           *            indicates whether the toolbar GUI is reset after adding the          }
464           *            button (if adding several actions it useful only to reset the  
465           *            GUI for the last added tool)          /**
466           */           * Performs the action of an action button.
467          public void addAction(MapPaneToolBarAction buttonAction,           *
468                          boolean resetToolBar) {           * @param tool
469                  if (isButtonIDUsed(buttonAction.getID())) {           *            the action
470                          LOGGER           * @param e
471                                          .warn("addAction(.) ignored because ID already used for tool or action: "           *            the event of the button
472                                                          + buttonAction.getID());           */
473                          return;          protected void performActionButton(int action, ActionEvent e) {
474                  }                  if (mapPane == null)
475                  JButton button = new JButton(buttonAction);                          return;
476                  button.setBorder(BorderFactory.createRaisedBevelBorder());  
477                  toolAndActionButtons.put(buttonAction.getID(), button);                  // Perform the action "Zoom back": Revert the last zoom
478                  if (resetToolBar)                  if (action == ACTION_ZOOM_BACK) {
479                          initToolBar();                          if (zoomBackIndex <= 1)
480          }                                  return;
481    
482          public void addSeparator(int id, Separator separator) {                          zoomBackForwardButtonInAction = true;
483                  if (isButtonIDUsed(id)) {                          zoomBackIndex--;
484                          LOGGER                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);
485                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);
486                          return;  
487                  }                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
488                  toolAndActionButtons.put(id, separator);                          mapPane.refresh();
489          }                  }
490    
491          /**                  // Perform the action "Zoom forward": Re-do the last zoom
492           * Adds an action to the tool bar and resets the toolbar GUI.                  if (action == ACTION_ZOOM_FORWARD) {
493           *                          if (zoomBackIndex < lastZooms.size()) {
494           * @param buttonAction                                  zoomBackForwardButtonInAction = true;
495           *            action for the toggle button                                  zoomBackIndex++;
496           */                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);
497          public void addAction(MapPaneToolBarAction buttonAction) {                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(
498                  addAction(buttonAction, true);                                                  zoomBackIndex < lastZooms.size());
499          }  
500                                    mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
501          /**                                  mapPane.refresh();
502           * Returns the button for a specific tool or action.                          }
503           *                  }
504           * @param id          }
505           *            the constant for any button in the {@link MapPaneToolBar}  
506           * @return a {@link JButton} if {@code id} specifies an          /**
507           *         {@linkplain #getActionButton(int) action button} or           * Adds a tool to the tool bar. Does nothing if a tool or action with the
508           *         {@link JToogleButton} if {@code id} specifies a           * specified ID already exists!
509           *         {@linkplain #getToolButton(int) tool button}           *
510           */           * @param buttonAction
511          public AbstractButton getButton(int id) {           *            action for the toggle button
512                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);           * @param resetToolBar
513                  if (button == null)           *            indicates whether the toolbar GUI is reset after adding the
514                          LOGGER.warn("Unknown tool or action ID: " + id);           *            button (if adding several actions it useful only to reset the
515                  return button;           *            GUI for the last added tool)
516          }           */
517            public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
518          /**                  if (isButtonIDUsed(buttonAction.getID())) {
519           * Returns the button for a specific tool.                          LOGGER
520           *                                          .warn("addTool(.) ignored because ID already used for tool or action: "
521           * @param tool                                                          + buttonAction.getID());
522           *            the constant for a tool                          return;
523           */                  }
524          public JToggleButton getToolButton(int tool) {                  JToggleButton button = new SmallToggleButton(buttonAction);
525                  AbstractButton button = getButton(tool);                  
526                  if (button != null && !(button instanceof JToggleButton)) {  //              button.setBorder(BorderFactory.createRaisedBevelBorder());
527                          LOGGER.warn("ID specifies no tool: " + tool);                  toolButtonGroup.add(button);
528                          button = null;                  toolAndActionButtons.put(buttonAction.getID(), button);
529                  }                  if (resetToolBar)
530                  return (JToggleButton) button;                          initToolBar();
531          }          }
532    
533          /**          /**
534           * Returns the button for a specific action.           * Adds a tool to the tool bar and resets the toolbar GUI.
535           *           *
536           * @param action           * @param buttonAction
537           *            the constant an action           *            action for the toggle button
538           */           */
539          public JButton getActionButton(int action) {          public void addTool(MapPaneToolBarAction buttonAction) {
540                  AbstractButton button = getButton(action);                  addTool(buttonAction, true);
541                  if (button != null && !(button instanceof JButton)) {          }
542                          LOGGER.warn("ID specifies no action: " + action);  
543                          button = null;          /**
544                  }           * Adds an action to the tool bar. Does nothing if a tool or action with the
545                  return (JButton) button;           * specified ID already exists!
546             *
547          }           * @param buttonAction
548             *            action for the button
549          /**           * @param resetToolBar
550           * Sets the selected tool.           *            indicates whether the toolbar GUI is reset after adding the
551           *           *            button (if adding several actions it useful only to reset the
552           * @param tool           *            GUI for the last added tool)
553           *            ID of the tool           */
554           */          public void addAction(MapPaneToolBarAction buttonAction,
555          public void setSelectedTool(Integer tool) {                          boolean resetToolBar) {
556                  if (tool == null)                  if (isButtonIDUsed(buttonAction.getID())) {
557                          toolButtonGroup.setUnselected();                          LOGGER
558                                            .warn("addAction(.) ignored because ID already used for tool or action: "
559                  JToggleButton button = getToolButton(tool);                                                          + buttonAction.getID());
560                  if (button == null)                          return;
561                          return;                  }
562                  button.setSelected(true);                  JButton button = new SmallButton(buttonAction);
563                  button.getAction().actionPerformed(null);  //              button.setBorder(BorderFactory.createRaisedBevelBorder());
564                    toolAndActionButtons.put(buttonAction.getID(), button);
565                  selectedTool = tool;                  if (resetToolBar)
566          }                          initToolBar();
567            }
568          /**  
569           * Returns the selected tool.          /**
570           *           * Adds any JComponent to the tool bar. Does nothing if a tool or action
571           * @return -1 if no tool is active           * with the specified ID already exists!
572           */           *
573          public int getSelectedTool() {           * @param component
574                  if (toolButtonGroup.getSelectedButton() == null)           *            A {@link JComponent} that shall be added
575                          return -1;           * @param id
576                  return selectedTool;           *            The ID associaded with the {@link JComponent}
577          }           * @param resetToolBar
578             *            indicates whether the toolbar GUI is reset after adding the
579          /**           *            button (if adding several actions it useful only to reset the
580           * Sets whether a tool or action is activated or not. The visible property           *            GUI for the last added tool)
581           * of the button is not affected.           */
582           *          public void addJComponent(JComponent component, int id, boolean resetToolBar) {
583           * @param id  
584           *            tool or actionID                  if (isButtonIDUsed(id)) {
585           * @param enabled                          LOGGER
586           *            if {@code true} the tool becomes available                                          .warn("addAction(.) ignored because ID already used for tool or action: "
587           */                                                          + id);
588          public void setButtonEnabled(int id, boolean enabled) {                          return;
589                  AbstractButton button = getButton(id);                  }
590                  if (button == null)  
591                          return;                  toolAndActionButtons.put(id, component);
592                  button.setEnabled(enabled);                  if (resetToolBar)
593          }                          initToolBar();
594            }
595          /**  
596           * Sets whether a tool or action is activated or not.          public void addSeparator(int id, Separator separator) {
597           *                  if (isButtonIDUsed(id)) {
598           * @param id                          LOGGER
599           *            tool or actionID                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");
600           * @param enabled                          return;
601           *            if {@code true} the tool becomes available                  }
602           * @param hideOnDisable                  toolAndActionButtons.put(id, separator);
603           *            if {@code true} the button is also hidden if {@code enabled}          }
604           *            is {@code false}  
605           */          /**
606          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {           * Adds an action to the tool bar and resets the toolbar GUI.
607                  AbstractButton button = getButton(id);           *
608                  if (button == null)           * @param buttonAction
609                          return;           *            action for the toggle button
610                  button.setEnabled(enabled);           */
611                  // if button is enabled, it becomes visible anyway          public void addAction(MapPaneToolBarAction buttonAction) {
612                  // if button is disabled and the "hide" option is set, it is also hidden                  addAction(buttonAction, true);
613                  if (enabled)          }
614                          button.setVisible(true);  
615                  else          /**
616                          button.setVisible(!hideOnDisable);           * Returns the button for a specific tool or action.
617          }           *
618             * @param id
619          /**           *            the constant for any button in the {@link MapPaneToolBar}
620           * Checks whether a ID is already used for a tool or action.           * @return a {@link JButton} if {@code id} specifies an
621           *           *         {@linkplain #getActionButton(int) action button} or
622           * @param tool           *         {@link JToogleButton} if {@code id} specifies a
623           *            tool ID           *         {@linkplain #getToolButton(int) tool button}
624           */           */
625          public boolean isButtonIDUsed(int id) {          public AbstractButton getButton(int id) {
626                  return toolAndActionButtons.get(id) != null;                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
627          }                  if (button == null)
628                            LOGGER.warn("Unknown tool or action ID: " + id);
629          /**                  return button;
630           * Checks whether a tool is activated.          }
631           *  
632           * @param tool          /**
633           *            tool ID           * Returns the button for a specific tool.
634           * @return {@code false} if an unknown ID is specified           *
635           */           * @param tool
636          public boolean isButtonEnabled(int id) {           *            the constant for a tool
637                  AbstractButton button = getButton(id);           */
638                  if (button != null)          public JToggleButton getToolButton(int tool) {
639                          return button.isEnabled();                  AbstractButton button = getButton(tool);
640                  return false;                  if (button != null && !(button instanceof JToggleButton)) {
641          }                          LOGGER.warn("ID specifies no tool: " + tool);
642                            button = null;
643          /**                  }
644           * Sets the activation for all tools.                  return (JToggleButton) button;
645           *          }
646           * @param enabled  
647           *            if {@code true} all tools becomes available          /**
648           * @param hideOnDisable           * Returns the button for a specific action.
649           *            if {@code true} the buttons are also hidden if {@code enabled}           *
650           *            is {@code false}           * @param action
651           */           *            the constant an action
652          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {           */
653                  for (int tool : toolAndActionButtons.keySet())          public JButton getActionButton(int action) {
654                          setButtonEnabled(tool, enabled, hideOnDisable);                  AbstractButton button = getButton(action);
655          }                  if (button != null && !(button instanceof JButton)) {
656                            LOGGER.warn("ID specifies no action: " + action);
657          /**                          button = null;
658           * Sets the activation for all actions.                  }
659           *                  return (JButton) button;
660           * @param enabled  
661           *            if {@code true} all actions becomes available          }
662           * @param hideOnDisable  
663           *            if {@code true} the buttons are also hidden if {@code enabled}          /**
664           *            is {@code false}           * Sets the selected tool.
665           */           *
666          public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {           * @param tool
667                  for (int id : toolAndActionButtons.keySet()) {           *            ID of the tool
668                          if (toolAndActionButtons.get(id) instanceof JButton) {           */
669                                  setButtonEnabled(id, enabled, hideOnDisable);          public void setSelectedTool(Integer tool) {
670                          }                  if (tool == null)
671                  }                          toolButtonGroup.setUnselected();
672    
673          }                  JToggleButton button = getToolButton(tool);
674                    if (button == null)
675          /**                          return;
676           * Returns the maximum ID of tools.                  button.setSelected(true);
677           */                  button.getAction().actionPerformed(null);
678          public int getMaxToolID() {  
679                  return toolAndActionButtons.lastKey();                  selectedTool = tool;
680          }          }
681    
682          /**          /**
683           * Returns the minimum ID of tools.           * Returns the selected tool.
684           */           *
685          public int getMinToolID() {           * @return -1 if no tool is active
686                  return toolAndActionButtons.firstKey();           */
687          }          public int getSelectedTool() {
688                    if (toolButtonGroup.getSelectedButton() == null)
689          /**                          return -1;
690           * Extends the {@link AbstractAction} with maintaining an ID and the                  return selectedTool;
691           * {@link MapPaneToolBar} the actions controls. Additionally this class          }
692           * automatically calls  
693           * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or          /**
694           * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on           * Sets whether a tool or action is activated or not. The visible property
695           * whether the action is added via           * of the button is not affected.
696           * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or           *
697           * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.           * @param id
698           *           *            tool or actionID
699           * @author <a href="mailto:[email protected]">Martin Schmitz</a>           * @param enabled
700           *         (University of Bonn/Germany)           *            if {@code true} the tool becomes available
701           */           */
702          public static class MapPaneToolBarAction extends AbstractAction {          public void setButtonEnabled(int id, boolean enabled) {
703                  /** The ID of the action */                  AbstractButton button = getButton(id);
704                  protected int id = -1;                  if (button == null)
705                  /** The tool bar, this action is made for. */                          return;
706                  protected MapPaneToolBar toolBar = null;                  button.setEnabled(enabled);
707            }
708                  /**  
709                   * Creates a new action with a dummy description and no icon.          /**
710                   *           * Sets whether a tool or action is activated or not.
711                   * @param id           *
712                   *            unique ID for the action           * @param id
713                   * @param toolBar           *            tool or actionID
714                   *            toolbar this action is made for           * @param enabled
715                   */           *            if {@code true} the tool becomes available
716                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {           * @param hideOnDisable
717                          this(id, toolBar, "" + id);           *            if {@code true} the button is also hidden if {@code enabled}
718                  }           *            is {@code false}
719             */
720                  /**          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
721                   * Creates a new action without an icon.                  AbstractButton button = getButton(id);
722                   *                  if (button == null)
723                   * @param id                          return;
724                   *            unique ID for the action                  button.setEnabled(enabled);
725                   * @param toolBar                  // if button is enabled, it becomes visible anyway
726                   *            toolbar this action is made for                  // if button is disabled and the "hide" option is set, it is also hidden
727                   * @param name                  if (enabled)
728                   *            description used for buttons or menus                          button.setVisible(true);
729                   */                  else
730                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {                          button.setVisible(!hideOnDisable);
731                          this(id, toolBar, name, null);          }
732                  }  
733            /**
734                  /**           * Checks whether a ID is already used for a tool or action.
735                   * Creates a new action.           *
736                   *           * @param tool
737                   * @param id           *            tool ID
738                   *            unique ID for the action           */
739                   * @param toolBar          public boolean isButtonIDUsed(int id) {
740                   *            toolbar this action is made for                  return toolAndActionButtons.get(id) != null;
741                   * @param name          }
742                   *            description used for buttons or menus  
743                   * @param icon          /**
744                   *            icon used for buttons or menus           * Checks whether a tool is activated.
745                   */           *
746                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,           * @param tool
747                                  String name, Icon icon) {           *            tool ID
748                          this (id, toolBar, name, icon, null);           * @return {@code false} if an unknown ID is specified
749                  }           */
750                            public boolean isButtonEnabled(int id) {
751                  /**                  AbstractButton button = getButton(id);
752                   * Creates a new action.                  if (button != null)
753                   *                          return button.isEnabled();
754                   * @param id                  return false;
755                   *            unique ID for the action          }
756                   * @param toolBar  
757                   *            The {@link MapPaneToolBar} this action is made for          /**
758                   * @param name           * Sets the activation for all tools.
759                   *            description used for buttons or menus           *
760                   * @param icon           * @param enabled
761                   *            icon used for buttons or menus           *            if {@code true} all tools becomes available
762                   * @param toolTip           * @param hideOnDisable
763                   *            Tooltip to use for the button or menu           *            if {@code true} the buttons are also hidden if {@code enabled}
764                   */           *            is {@code false}
765                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,           */
766                                  String name, Icon icon, String toolTip) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
767                          super(name, icon);                  for (int tool : toolAndActionButtons.keySet())
768                                                    setButtonEnabled(tool, enabled, hideOnDisable);
769                          if (toolTip != null && !toolTip.trim().isEmpty()){          }
770                                  putValue(Action.SHORT_DESCRIPTION, toolTip);  
771                          }          /**
772                                     * Sets the activation for all actions.
773                          this.id = id;           *
774                          this.toolBar = toolBar;           * @param enabled
775                  }           *            if {@code true} all actions becomes available
776             * @param hideOnDisable
777                  /**           *            if {@code true} the buttons are also hidden if {@code enabled}
778                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or           *            is {@code false}
779                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}           */
780                   * depending on whether the action is added to the toolbar via          public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
781                   * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or                  for (int id : toolAndActionButtons.keySet()) {
782                   * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.                          if (toolAndActionButtons.get(id) instanceof JButton) {
783                   */                                  setButtonEnabled(id, enabled, hideOnDisable);
784                  public void actionPerformed(ActionEvent e) {                          }
785                          if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)                  }
786                                  toolBar.performToolButton(id, e);  
787                          else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)          }
788                                  toolBar.performActionButton(id, e);  
789                  }          /**
790             * Returns the maximum ID of tools.
791                  /**           */
792                   * Returns the (unique) id of this action.          public int getMaxToolID() {
793                   *                  return toolAndActionButtons.lastKey();
794                   * @return          }
795                   */  
796                  public int getID() {          /**
797                          return id;           * Returns the minimum ID of tools.
798                  }           */
799          }          public int getMinToolID() {
800                            return toolAndActionButtons.firstKey();
801            /**          }
802             * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der  
803             * Hintergrund auf WEISS gesetzt.          /**
804             *           * Extends the {@link AbstractAction} with maintaining an ID and the
805             * @author <a href="mailto:[email protected]">Stefan Alfons           * {@link MapPaneToolBar} the actions controls. Additionally this class
806             *         Kr&uuml;ger</a>           * automatically calls
807             */           * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
808            @Override           * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on
809            public void print(Graphics g) {           * whether the action is added via
810                Color orig = getBackground();           * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
811                setBackground(Color.WHITE);           * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
812                // wrap in try/finally so that we always restore the state           *
813                try {           * @author <a href="mailto:[email protected]">Martin Schmitz</a>
814                    super.print(g);           *         (University of Bonn/Germany)
815                } finally {           */
816                    setBackground(orig);          public static class MapPaneToolBarAction extends AbstractAction {
817                }                  /** The ID of the action */
818            }                  protected int id = -1;
819  }                  /** The tool bar, this action is made for. */
820                    protected MapPaneToolBar toolBar = null;
821    
822                    /**
823                     * Creates a new action with a dummy description and no icon.
824                     *
825                     * @param id
826                     *            unique ID for the action
827                     * @param toolBar
828                     *            toolbar this action is made for
829                     */
830                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {
831                            this(id, toolBar, "" + id);
832                    }
833    
834                    /**
835                     * Creates a new action without an icon.
836                     *
837                     * @param id
838                     *            unique ID for the action
839                     * @param toolBar
840                     *            toolbar this action is made for
841                     * @param name
842                     *            description used for buttons or menus
843                     */
844                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {
845                            this(id, toolBar, name, null);
846                    }
847    
848                    /**
849                     * Creates a new action.
850                     *
851                     * @param id
852                     *            unique ID for the action
853                     * @param toolBar
854                     *            toolbar this action is made for
855                     * @param name
856                     *            description used for buttons or menus
857                     * @param icon
858                     *            icon used for buttons or menus
859                     */
860                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
861                                    String name, Icon icon) {
862                            this(id, toolBar, name, icon, null);
863                    }
864    
865                    /**
866                     * Creates a new action.
867                     *
868                     * @param id
869                     *            unique ID for the action
870                     * @param toolBar
871                     *            The {@link MapPaneToolBar} this action is made for
872                     * @param name
873                     *            description used for buttons or menus
874                     * @param icon
875                     *            icon used for buttons or menus
876                     * @param toolTip
877                     *            Tooltip to use for the button or menu
878                     */
879                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
880                                    String name, Icon icon, String toolTip) {
881                            super(name, icon);
882    
883                            if (toolTip != null && !toolTip.trim().isEmpty()) {
884                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
885                            }
886    
887                            this.id = id;
888                            this.toolBar = toolBar;
889                    }
890    
891                    /**
892                     * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
893                     * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
894                     * depending on whether the action is added to the toolbar via
895                     * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
896                     * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
897                     */
898                    public void actionPerformed(ActionEvent e) {
899                            if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)
900                                    toolBar.performToolButton(id, e);
901                            else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)
902                                    toolBar.performActionButton(id, e);
903                    }
904    
905                    /**
906                     * Returns the (unique) id of this action.
907                     *
908                     * @return
909                     */
910                    public int getID() {
911                            return id;
912                    }
913            }
914    
915            /**
916             * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
917             * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
918             *
919             * @author <a href="mailto:[email protected]">Stefan Alfons
920             *         Kr&uuml;ger</a>
921             */
922            @Override
923            public void print(Graphics g) {
924                    Color orig = getBackground();
925                    setBackground(Color.WHITE);
926                    // wrap in try/finally so that we always restore the state
927                    try {
928                            super.print(g);
929                    } finally {
930                            setBackground(orig);
931                    }
932            }
933    
934    }

Legend:
Removed from v.180  
changed lines
  Added in v.621

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26