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

Legend:
Removed from v.139  
changed lines
  Added in v.297

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26