/[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 886 by alfonx, Thu Jun 3 10:16:07 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);                  // Panning
305          // this.addSeparator(dimension2);  //              addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
306    //                              MapView.class.getResource("resource/icons/pan.png")),
307          // // Action buttons  //                              R("MapPaneButtons.Pan.TT")), false);
308          // for (JButton b : actionButtons.values())  
309          // add(b);                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
310          // }                  
311                    // Info
312          /**  //              addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
313           * Performs the activation of a tool.  //                              MapView.class.getResource("resource/icons/info.png")),
314           *  //                              R("MapPaneButtons.Info.TT")), false);
315           * @param tool                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
316           *            the tool to activate  
317           * @param e                  // Zoom in
318           *            the event of the button                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
319           */                  
320          public void performToolButton(int tool, ActionEvent e) {                  // Zoom out
321                  if (mapPane == null)                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
322                          return;                  
323                    
324                  selectedTool = tool;  //              // Zoom in
325    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
326                  switch (tool) {  //                              MapView.class.getResource("resource/icons/zoom_in.png")),
327                  case TOOL_PAN:  //                              R("MapPaneButtons.ZoomIn.TT")), false);
328                          // Set the mouse tool to "Panning"  //              
329                          mapPane.setWindowSelectionState(JMapPane.NONE);  //              // Zoom out
330                          mapPane.setState(JMapPane.PAN);  //              addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
331                          mapPane.setHighlight(false);  //                              MapView.class.getResource("resource/icons/zoom_out.png")),
332                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  //                              R("MapPaneButtons.ZoomOut.TT")), false);
333                          break;                  
334                  case TOOL_INFO:                  
335                          // Set the mouse tool to "Info"  
336                          mapPane.setWindowSelectionState(JMapPane.NONE);                  // Action button to revert the last zoom
337                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
338                          // JMapPane.SELECT_TOP_ONEONLY                                  new ImageIcon(MapView.class
339                          mapPane.setHighlight(false);// SK: Was true, but since it not works                                                  .getResource("resource/icons/zoom_back.png")),
340                          // properly removed it to save                                  R("MapPaneButtons.LastZoom.TT")), false);
341                          // performance                  setButtonEnabled(ACTION_ZOOM_BACK, false);
342                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
343                          break;                  // Action button to redo the last zoom
344                  case TOOL_ZOOMIN:                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
345                          // Set the mouse tool to "Zoom in"                                  new ImageIcon(MapView.class
346                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);                                                  .getResource("resource/icons/zoom_forward.png")),
347                          mapPane.setState(JMapPane.ZOOM_IN);                                  R("MapPaneButtons.NextZoom.TT")), false);
348                          mapPane.setHighlight(false);                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
349                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
350                          break;                  // set the selected tool enabled
351                  case TOOL_ZOOMOUT:                  setSelectedTool(selectedTool);
352                          // Set the mouse tool to "Zoom out"  
353                          mapPane.setWindowSelectionState(JMapPane.NONE);          }
354                          mapPane.setState(JMapPane.ZOOM_OUT);  
355                          mapPane.setHighlight(false);          @Override
356                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);          public void paint(Graphics g) {
357                          break;                  super.paint(g);
358                  default:          }
359                          // Set map actions to default  
360                          mapPane.setWindowSelectionState(JMapPane.NONE);          /**
361                          mapPane.setState(JMapPane.NONE);           * Clears the GUI of all components and adds all tool and action buttons to
362                          mapPane.setHighlight(false);           * the tool bar.
363                          mapPane.setNormalCursor(null);           */
364                          break;          public void initToolBar() {
365                  }                  // setOpaque(true);
366                  mapPane.updateCursor();                  //              
367          }                  // setAlignmentY(1f);
368                    // setAlignmentX(0.5f);
369          /**                  removeAll();
370           * @param id  
371           *            The ID of the Component to remove. The change will not be                  // // Separator to the left of the tool actions to start
372           *            visible until {@link #initToolBar()} is called.                  // // the tool buttons with the map (not with the coordinate grid)
373           * @return <code>null</code> or the component that has been removed.                  // Dimension dimension = new Dimension(49, 10);
374           */                  // addSeparator(dimension);
375          public JComponent removeId(int id) {  
376                  return toolAndActionButtons.remove(id);                  // Tool buttons
377          }                  for (Integer bKey : toolAndActionButtons.keySet()) {
378    
379          /**                          JComponent b = toolAndActionButtons.get(bKey);
380           * Performs the action of an action button.  
381           *                          if (b instanceof JToggleButton) {
382           * @param tool                                  JToggleButton tb = (JToggleButton) b;
383           *            the action                                  tb.setName(bKey.toString());
384           * @param e                                  tb.addActionListener(toolSelectedListener);
385           *            the event of the button                          }
386           */  
387          protected void performActionButton(int action, ActionEvent e) {                          add(b);
388                  if (mapPane == null)                  }
389                          return;  
390                    if (!toolAndActionButtons.containsKey(selectedTool)) {
391                  // Perform the action "Zoom back": Revert the last zoom                          /**
392                  if (action == ACTION_ZOOM_BACK) {                           * This might be a bit specific, but IF selection buttons are
393                          if (zoomBackIndex <= 1)                           * available, select one of them.. if not, select the INFO tool.
394                                  return;                           */
395    
396                          zoomBackForwardButtonInAction = true;                          if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
397                          zoomBackIndex--;                                  setSelectedTool(TOOL_SELECTION_SET);
398                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);                          } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
399                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);                                  setSelectedTool(TOOL_INFO);
400                            } else {
401                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));                                  // TODO What to do now?!
402                          mapPane.refresh();                                  setSelectedTool(null);
403                  }                          }
404    
405                  // Perform the action "Zoom forward": Re-do the last zoom                  }
406                  if (action == ACTION_ZOOM_FORWARD) {  
407                          if (zoomBackIndex < lastZooms.size()) {                  revalidate();
408                                  zoomBackForwardButtonInAction = true;                  repaint();
409                                  zoomBackIndex++;          }
410                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);  
411                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(          // Space between tool buttons and action buttons
412                                                  zoomBackIndex < lastZooms.size());          // SK: Seperators are now als manages like actions and tools
413            // Dimension dimension2 = new Dimension( 10,10);
414                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));          // this.addSeparator(dimension2);
415                                  mapPane.refresh();  
416                          }          // // Action buttons
417                  }          // for (JButton b : actionButtons.values())
418          }          // add(b);
419            // }
420          /**  
421           * Adds a tool to the tool bar. Does nothing if a tool or action with the          /**
422           * specified ID already exists!           * Performs the activation of a tool.
423           *           *
424           * @param buttonAction           * @param tool
425           *            action for the toggle button           *            the tool to activate
426           * @param resetToolBar           * @param e
427           *            indicates whether the toolbar GUI is reset after adding the           *            the event of the button
428           *            button (if adding several actions it useful only to reset the           */
429           *            GUI for the last added tool)          public void performToolButton(int tool, ActionEvent e) {
430           */                  if (mapPane == null)
431          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {                          return;
432                  if (isButtonIDUsed(buttonAction.getID())) {  
433                          LOGGER                  selectedTool = tool;
434                                          .warn("addTool(.) ignored because ID already used for tool or action: "  
435                                                          + buttonAction.getID());                  switch (tool) {
436                          return;                  case TOOL_PAN:
437                  }                          // Set the mouse tool to "Panning"
438                  JToggleButton button = new JToggleButton(buttonAction);  //                      mapPane.setState(SelectableXMapPane.PAN);
439                  button.setBorder(BorderFactory.createRaisedBevelBorder());                          mapPane.setTool(XMapPaneTool.PAN);
440                  toolButtonGroup.add(button);  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
441                  toolAndActionButtons.put(buttonAction.getID(), button);                          break;
442                  if (resetToolBar)                  case TOOL_INFO:
443                          initToolBar();                          // Set the mouse tool to "Info"
444          }                          mapPane.setTool(XMapPaneTool.INFO);
445    //                      mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);
446          /**  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
447           * Adds a tool to the tool bar and resets the toolbar GUI.                          break;
448           *                  case TOOL_ZOOMIN:
449           * @param buttonAction                          // Set the mouse tool to "Zoom in"
450           *            action for the toggle button                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
451           */  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
452          public void addTool(MapPaneToolBarAction buttonAction) {                          break;
453                  addTool(buttonAction, true);                  case TOOL_ZOOMOUT:
454          }                          // Set the mouse tool to "Zoom out"
455                            mapPane.setTool(XMapPaneTool.ZOOM_OUT);
456          /**  //                      mapPane.setState(SelectableXMapPane.ZOOM_OUT);
457           * Adds an action to the tool bar. Does nothing if a tool or action with the  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
458           * specified ID already exists!                          break;
459           *  //              default:
460           * @param buttonAction                          // Set map actions to default
461           *            action for the button  //                      mapPane.setState(SelectableXMapPane.NONE);
462           * @param resetToolBar  //                      mapPane.setNormalCursor(null);
463           *            indicates whether the toolbar GUI is reset after adding the  //                      break;
464           *            button (if adding several actions it useful only to reset the                  }
465           *            GUI for the last added tool)  //              mapPane.updateCursorAndRepaintTimer();
466           */          }
467          public void addAction(MapPaneToolBarAction buttonAction,  
468                          boolean resetToolBar) {          /**
469                  if (isButtonIDUsed(buttonAction.getID())) {           * @param id
470                          LOGGER           *            The ID of the Component to remove. The change will not be
471                                          .warn("addAction(.) ignored because ID already used for tool or action: "           *            visible until {@link #initToolBar()} is called.
472                                                          + buttonAction.getID());           * @return <code>null</code> or the component that has been removed.
473                          return;           */
474                  }          public JComponent removeId(int id) {
475                  JButton button = new JButton(buttonAction);                  return toolAndActionButtons.remove(id);
476                  button.setBorder(BorderFactory.createRaisedBevelBorder());          }
477                  toolAndActionButtons.put(buttonAction.getID(), button);  
478                  if (resetToolBar)          /**
479                          initToolBar();           * Performs the action of an action button.
480          }           *
481             * @param tool
482          public void addSeparator(int id, Separator separator) {           *            the action
483                  if (isButtonIDUsed(id)) {           * @param e
484                          LOGGER           *            the event of the button
485                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");           */
486                          return;          protected void performActionButton(int action, ActionEvent e) {
487                  }                  if (mapPane == null)
488                  toolAndActionButtons.put(id, separator);                          return;
489          }                  
490                    // Perform the action "Zoom back": Revert the last zoom
491          /**                  if (action == ACTION_ZOOM_BACK) {
492           * Adds an action to the tool bar and resets the toolbar GUI.                          if (zoomBackIndex <= 1)
493           *                                  return;
494           * @param buttonAction  
495           *            action for the toggle button                          zoomBackForwardButtonInAction = true;
496           */                          zoomBackIndex--;
497          public void addAction(MapPaneToolBarAction buttonAction) {                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);
498                  addAction(buttonAction, true);                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);
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                  // Perform the action "Zoom forward": Re-do the last zoom
505           *            the constant for any button in the {@link MapPaneToolBar}                  if (action == ACTION_ZOOM_FORWARD) {
506           * @return a {@link JButton} if {@code id} specifies an                          if (zoomBackIndex < lastZooms.size()) {
507           *         {@linkplain #getActionButton(int) action button} or                                  zoomBackForwardButtonInAction = true;
508           *         {@link JToogleButton} if {@code id} specifies a                                  zoomBackIndex++;
509           *         {@linkplain #getToolButton(int) tool button}                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);
510           */                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(
511          public AbstractButton getButton(int id) {                                                  zoomBackIndex < lastZooms.size());
512                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);  
513                  if (button == null)                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
514                          LOGGER.warn("Unknown tool or action ID: " + id);                                  mapPane.refresh();
515                  return button;                          }
516          }                  }
517            }
518          /**  
519           * Returns the button for a specific tool.          /**
520           *           * Adds a tool to the tool bar. Does nothing if a tool or action with the
521           * @param tool           * specified ID already exists!
522           *            the constant for a tool           *
523           */           * @param buttonAction
524          public JToggleButton getToolButton(int tool) {           *            action for the toggle button
525                  AbstractButton button = getButton(tool);           * @param resetToolBar
526                  if (button != null && !(button instanceof JToggleButton)) {           *            indicates whether the toolbar GUI is reset after adding the
527                          LOGGER.warn("ID specifies no tool: " + tool);           *            button (if adding several actions it useful only to reset the
528                          button = null;           *            GUI for the last added tool)
529                  }           */
530                  return (JToggleButton) button;          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
531          }                  if (isButtonIDUsed(buttonAction.getID())) {
532                            LOGGER
533          /**                                          .warn("addTool(.) ignored because ID already used for tool or action: "
534           * Returns the button for a specific action.                                                          + buttonAction.getID());
535           *                          return;
536           * @param action                  }
537           *            the constant an action                  JToggleButton button = new SmallToggleButton(buttonAction);
538           */                  
539          public JButton getActionButton(int action) {  //              button.setBorder(BorderFactory.createRaisedBevelBorder());
540                  AbstractButton button = getButton(action);                  toolButtonGroup.add(button);
541                  if (button != null && !(button instanceof JButton)) {                  toolAndActionButtons.put(buttonAction.getID(), button);
542                          LOGGER.warn("ID specifies no action: " + action);                  if (resetToolBar)
543                          button = null;                          initToolBar();
544                  }          }
545                  return (JButton) button;  
546            /**
547          }           * Adds a tool to the tool bar and resets the toolbar GUI.
548             *
549          /**           * @param buttonAction
550           * Sets the selected tool.           *            action for the toggle button
551           *           */
552           * @param tool          public void addTool(MapPaneToolBarAction buttonAction) {
553           *            ID of the tool                  addTool(buttonAction, true);
554           */          }
555          public void setSelectedTool(Integer tool) {  
556                  if (tool == null)          /**
557                          toolButtonGroup.setUnselected();           * Adds an action to the tool bar. Does nothing if a tool or action with the
558             * specified ID already exists!
559                  JToggleButton button = getToolButton(tool);           *
560                  if (button == null)           * @param buttonAction
561                          return;           *            action for the button
562                  button.setSelected(true);           * @param resetToolBar
563                  button.getAction().actionPerformed(null);           *            indicates whether the toolbar GUI is reset after adding the
564             *            button (if adding several actions it useful only to reset the
565                  selectedTool = tool;           *            GUI for the last added tool)
566          }           */
567            public void addAction(MapPaneToolBarAction buttonAction,
568          /**                          boolean resetToolBar) {
569           * Returns the selected tool.                  if (isButtonIDUsed(buttonAction.getID())) {
570           *                          LOGGER
571           * @return -1 if no tool is active                                          .warn("addAction(.) ignored because ID already used for tool or action: "
572           */                                                          + buttonAction.getID());
573          public int getSelectedTool() {                          return;
574                  if (toolButtonGroup.getSelectedButton() == null)                  }
575                          return -1;                  JButton button = new SmallButton(buttonAction);
576                  return selectedTool;  //              button.setBorder(BorderFactory.createRaisedBevelBorder());
577          }                  toolAndActionButtons.put(buttonAction.getID(), button);
578                    if (resetToolBar)
579          /**                          initToolBar();
580           * Sets whether a tool or action is activated or not. The visible property          }
581           * of the button is not affected.  
582           *          /**
583           * @param id           * Adds any JComponent to the tool bar. Does nothing if a tool or action
584           *            tool or actionID           * with the specified ID already exists!
585           * @param enabled           *
586           *            if {@code true} the tool becomes available           * @param component
587           */           *            A {@link JComponent} that shall be added
588          public void setButtonEnabled(int id, boolean enabled) {           * @param id
589                  AbstractButton button = getButton(id);           *            The ID associaded with the {@link JComponent}
590                  if (button == null)           * @param resetToolBar
591                          return;           *            indicates whether the toolbar GUI is reset after adding the
592                  button.setEnabled(enabled);           *            button (if adding several actions it useful only to reset the
593          }           *            GUI for the last added tool)
594             */
595          /**          public void addJComponent(JComponent component, int id, boolean resetToolBar) {
596           * Sets whether a tool or action is activated or not.  
597           *                  if (isButtonIDUsed(id)) {
598           * @param id                          LOGGER
599           *            tool or actionID                                          .warn("addAction(.) ignored because ID already used for tool or action: "
600           * @param enabled                                                          + id);
601           *            if {@code true} the tool becomes available                          return;
602           * @param hideOnDisable                  }
603           *            if {@code true} the button is also hidden if {@code enabled}  
604           *            is {@code false}                  toolAndActionButtons.put(id, component);
605           */                  if (resetToolBar)
606          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {                          initToolBar();
607                  AbstractButton button = getButton(id);          }
608                  if (button == null)  
609                          return;          public void addSeparator(int id, Separator separator) {
610                  button.setEnabled(enabled);                  if (isButtonIDUsed(id)) {
611                  // if button is enabled, it becomes visible anyway                          LOGGER
612                  // if button is disabled and the "hide" option is set, it is also hidden                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");
613                  if (enabled)                          return;
614                          button.setVisible(true);                  }
615                  else                  toolAndActionButtons.put(id, separator);
616                          button.setVisible(!hideOnDisable);          }
617          }  
618            /**
619          /**           * Adds an action to the tool bar and resets the toolbar GUI.
620           * Checks whether a ID is already used for a tool or action.           *
621           *           * @param buttonAction
622           * @param tool           *            action for the toggle button
623           *            tool ID           */
624           */          public void addAction(MapPaneToolBarAction buttonAction) {
625          public boolean isButtonIDUsed(int id) {                  addAction(buttonAction, true);
626                  return toolAndActionButtons.get(id) != null;          }
627          }  
628            /**
629          /**           * Returns the button for a specific tool or action.
630           * Checks whether a tool is activated.           *
631           *           * @param id
632           * @param tool           *            the constant for any button in the {@link MapPaneToolBar}
633           *            tool ID           * @return a {@link JButton} if {@code id} specifies an
634           * @return {@code false} if an unknown ID is specified           *         {@linkplain #getActionButton(int) action button} or
635           */           *         {@link JToogleButton} if {@code id} specifies a
636          public boolean isButtonEnabled(int id) {           *         {@linkplain #getToolButton(int) tool button}
637                  AbstractButton button = getButton(id);           */
638                  if (button != null)          public AbstractButton getButton(int id) {
639                          return button.isEnabled();                  
640                  return false;                  //ACHUTNG: Das ist ein SK QUICK FIX! TODO
641          }                  if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
642                    
643          /**                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
644           * Sets the activation for all tools.                  if (button == null)
645           *                          LOGGER.warn("Unknown tool or action ID: " + id);
646           * @param enabled                  return button;
647           *            if {@code true} all tools becomes available          }
648           * @param hideOnDisable  
649           *            if {@code true} the buttons are also hidden if {@code enabled}          /**
650           *            is {@code false}           * Returns the button for a specific tool.
651           */           *
652          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {           * @param tool
653                  for (int tool : toolAndActionButtons.keySet())           *            the constant for a tool
654                          setButtonEnabled(tool, enabled, hideOnDisable);           */
655          }          public JToggleButton getToolButton(int tool) {
656                    AbstractButton button = getButton(tool);
657          /**                  if (button != null && !(button instanceof JToggleButton)) {
658           * Sets the activation for all actions.                          LOGGER.warn("ID specifies no tool: " + tool);
659           *                          button = null;
660           * @param enabled                  }
661           *            if {@code true} all actions becomes available                  return (JToggleButton) button;
662           * @param hideOnDisable          }
663           *            if {@code true} the buttons are also hidden if {@code enabled}  
664           *            is {@code false}          /**
665           */           * Returns the button for a specific action.
666          public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {           *
667                  for (int id : toolAndActionButtons.keySet()) {           * @param action
668                          if (toolAndActionButtons.get(id) instanceof JButton) {           *            the constant an action
669                                  setButtonEnabled(id, enabled, hideOnDisable);           */
670                          }          public JButton getActionButton(int action) {
671                  }                  AbstractButton button = getButton(action);
672                    if (button != null && !(button instanceof JButton)) {
673          }                          LOGGER.warn("ID specifies no action: " + action);
674                            button = null;
675          /**                  }
676           * Returns the maximum ID of tools.                  return (JButton) button;
677           */  
678          public int getMaxToolID() {          }
679                  return toolAndActionButtons.lastKey();  
680          }          /**
681             * Sets the selected tool.
682          /**           *
683           * Returns the minimum ID of tools.           * @param tool
684           */           *            ID of the tool
685          public int getMinToolID() {           */
686                  return toolAndActionButtons.firstKey();          public void setSelectedTool(Integer tool) {
687          }                  if (tool == null)
688                            toolButtonGroup.setUnselected();
689          /**  
690           * Extends the {@link AbstractAction} with maintaining an ID and the                  JToggleButton button = getToolButton(tool);
691           * {@link MapPaneToolBar} the actions controls. Additionally this class                  if (button == null)
692           * automatically calls                          return;
693           * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                  button.setSelected(true);
694           * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on                  button.getAction().actionPerformed(null);
695           * whether the action is added via  
696           * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or                  selectedTool = tool;
697           * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.          }
698           *  
699           * @author <a href="mailto:[email protected]">Martin Schmitz</a>          /**
700           *         (University of Bonn/Germany)           * Returns the selected tool.
701           */           *
702          public static class MapPaneToolBarAction extends AbstractAction {           * @return -1 if no tool is active
703                  /** The ID of the action */           */
704                  protected int id = -1;          public int getSelectedTool() {
705                  /** The tool bar, this action is made for. */                  if (toolButtonGroup.getSelectedButton() == null)
706                  protected MapPaneToolBar toolBar = null;                          return -1;
707                    return selectedTool;
708                  /**          }
709                   * Creates a new action with a dummy description and no icon.          
710                   *          /**
711                   * @param id           * Sets whether a tool or action is activated or not. The visible property
712                   *            unique ID for the action           * of the button is not affected.
713                   * @param toolBar           *
714                   *            toolbar this action is made for           * @param id
715                   */           *            tool or actionID
716                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {           * @param enabled
717                          this(id, toolBar, "" + id);           *            if {@code true} the tool becomes available
718                  }           */
719            public void setButtonEnabled(int id, boolean enabled) {
720                  /**                  AbstractButton button = getButton(id);
721                   * Creates a new action without an icon.                  if (button == null)
722                   *                          return;
723                   * @param id                  button.setEnabled(enabled);
724                   *            unique ID for the action          }
725                   * @param toolBar  
726                   *            toolbar this action is made for          /**
727                   * @param name           * Sets whether a tool or action is activated or not.
728                   *            description used for buttons or menus           *
729                   */           * @param id
730                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {           *            tool or actionID
731                          this(id, toolBar, name, null);           * @param enabled
732                  }           *            if {@code true} the tool becomes available
733             * @param hideOnDisable
734                  /**           *            if {@code true} the button is also hidden if {@code enabled}
735                   * Creates a new action.           *            is {@code false}
736                   *           */
737                   * @param id          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
738                   *            unique ID for the action                  AbstractButton button = getButton(id);
739                   * @param toolBar                  if (button == null)
740                   *            toolbar this action is made for                          return;
741                   * @param name                  button.setEnabled(enabled);
742                   *            description used for buttons or menus                  // if button is enabled, it becomes visible anyway
743                   * @param icon                  // if button is disabled and the "hide" option is set, it is also hidden
744                   *            icon used for buttons or menus                  if (enabled)
745                   */                          button.setVisible(true);
746                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  else
747                                  String name, Icon icon) {                          button.setVisible(!hideOnDisable);
748                          this (id, toolBar, name, icon, null);          }
749                  }  
750                            /**
751                  /**           * Checks whether a ID is already used for a tool or action.
752                   * Creates a new action.           *
753                   *           * @param tool
754                   * @param id           *            tool ID
755                   *            unique ID for the action           */
756                   * @param toolBar          public boolean isButtonIDUsed(int id) {
757                   *            The {@link MapPaneToolBar} this action is made for                  return toolAndActionButtons.get(id) != null;
758                   * @param name          }
759                   *            description used for buttons or menus  
760                   * @param icon          /**
761                   *            icon used for buttons or menus           * Checks whether a tool is activated.
762                   * @param toolTip           *
763                   *            Tooltip to use for the button or menu           * @param tool
764                   */           *            tool ID
765                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,           * @return {@code false} if an unknown ID is specified
766                                  String name, Icon icon, String toolTip) {           */
767                          super(name, icon);          public boolean isButtonEnabled(int id) {
768                                            AbstractButton button = getButton(id);
769                          if (toolTip != null && !toolTip.trim().isEmpty()){                  if (button != null)
770                                  putValue(Action.SHORT_DESCRIPTION, toolTip);                          return button.isEnabled();
771                          }                  return false;
772                                    }
773                          this.id = id;  
774                          this.toolBar = toolBar;          /**
775                  }           * Sets the activation for all tools.
776             *
777                  /**           * @param enabled
778                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or           *            if {@code true} all tools becomes available
779                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}           * @param hideOnDisable
780                   * depending on whether the action is added to the toolbar via           *            if {@code true} the buttons are also hidden if {@code enabled}
781                   * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or           *            is {@code false}
782                   * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.           */
783                   */          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
784                  public void actionPerformed(ActionEvent e) {                  for (int id : toolAndActionButtons.keySet()) {
785                          if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
786                                  toolBar.performToolButton(id, e);                          setButtonEnabled(id, enabled, hideOnDisable);
787                          else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)                          }
788                                  toolBar.performActionButton(id, e);                  }
789                  }          }
790            
791                  /**          /**
792                   * Returns the (unique) id of this action.           * Sets the activation for all actions.
793                   *           *
794                   * @return           * @param enabled
795                   */           *            if {@code true} all actions becomes available
796                  public int getID() {           * @param hideOnDisable
797                          return id;           *            if {@code true} the buttons are also hidden if {@code enabled}
798                  }           *            is {@code false}
799          }           */
800                    public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
801            /**                  for (int id : toolAndActionButtons.keySet()) {
802             * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der                          if (toolAndActionButtons.get(id) instanceof JButton) {
803             * Hintergrund auf WEISS gesetzt.                                  setButtonEnabled(id, enabled, hideOnDisable);
804             *                          }
805             * @author <a href="mailto:[email protected]">Stefan Alfons                  }
806             *         Kr&uuml;ger</a>  
807             */          }
808            @Override  
809            public void print(Graphics g) {          /**
810                Color orig = getBackground();           * Returns the maximum ID of tools.
811                setBackground(Color.WHITE);           */
812                // wrap in try/finally so that we always restore the state          public int getMaxToolID() {
813                try {                  return toolAndActionButtons.lastKey();
814                    super.print(g);          }
815                } finally {  
816                    setBackground(orig);          /**
817                }           * Returns the minimum ID of tools.
818            }           */
819  }          public int getMinToolID() {
820                    return toolAndActionButtons.firstKey();
821            }
822    
823            /**
824             * Extends the {@link AbstractAction} with maintaining an ID and the
825             * {@link MapPaneToolBar} the actions controls. Additionally this class
826             * automatically calls
827             * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
828             * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on
829             * whether the action is added via
830             * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
831             * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
832             *
833             * @author <a href="mailto:[email protected]">Martin Schmitz</a>
834             *         (University of Bonn/Germany)
835             */
836            public static class MapPaneToolBarAction extends AbstractAction {
837                    /** The ID of the action */
838                    protected int id = -1;
839                    /** The tool bar, this action is made for. */
840                    protected MapPaneToolBar toolBar = null;
841    
842                    /**
843                     * Creates a new action with a dummy description and no icon.
844                     *
845                     * @param id
846                     *            unique ID for the action
847                     * @param toolBar
848                     *            toolbar this action is made for
849                     */
850                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {
851                            this(id, toolBar, "" + id);
852                    }
853    
854                    /**
855                     * Creates a new action without an icon.
856                     *
857                     * @param id
858                     *            unique ID for the action
859                     * @param toolBar
860                     *            toolbar this action is made for
861                     * @param name
862                     *            description used for buttons or menus
863                     */
864                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {
865                            this(id, toolBar, name, null);
866                    }
867    
868                    /**
869                     * Creates a new action.
870                     *
871                     * @param id
872                     *            unique ID for the action
873                     * @param toolBar
874                     *            toolbar this action is made for
875                     * @param name
876                     *            description used for buttons or menus
877                     * @param icon
878                     *            icon used for buttons or menus
879                     */
880                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
881                                    String name, Icon icon) {
882                            this(id, toolBar, name, icon, null);
883                    }
884    
885                    /**
886                     * Creates a new action.
887                     *
888                     * @param id
889                     *            unique ID for the action
890                     * @param toolBar
891                     *            The {@link MapPaneToolBar} this action is made for
892                     * @param name
893                     *            description used for buttons or menus
894                     * @param icon
895                     *            icon used for buttons or menus
896                     * @param toolTip
897                     *            Tooltip to use for the button or menu
898                     */
899                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
900                                    String name, Icon icon, String toolTip) {
901                            super(name, icon);
902    
903                            if (toolTip != null && !toolTip.trim().isEmpty()) {
904                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
905                            }
906    
907                            this.id = id;
908                            this.toolBar = toolBar;
909                    }
910    
911                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
912                            this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
913                    }
914    
915                    /**
916                     * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
917                     * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
918                     * depending on whether the action is added to the toolbar via
919                     * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
920                     * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
921                     */
922                    public void actionPerformed(ActionEvent e) {
923                            if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)
924                                    toolBar.performToolButton(id, e);
925                            else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)
926                                    toolBar.performActionButton(id, e);
927                    }
928    
929                    /**
930                     * Returns the (unique) id of this action.
931                     *
932                     * @return
933                     */
934                    public int getID() {
935                            return id;
936                    }
937            }
938    
939            /**
940             * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
941             * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
942             *
943             * @author <a href="mailto:[email protected]">Stefan Alfons
944             *         Kr&uuml;ger</a>
945             */
946            @Override
947            public void print(Graphics g) {
948                    Color orig = getBackground();
949                    setBackground(Color.WHITE);
950                    // wrap in try/finally so that we always restore the state
951                    try {
952                            super.print(g);
953                    } finally {
954                            setBackground(orig);
955                    }
956            }
957    
958    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26