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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26