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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26