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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26