/[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

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26