/[schmitzm]/branches/2.0-RC1/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /branches/2.0-RC1/src/skrueger/geotools/MapPaneToolBar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.2  
changed lines
  Added in v.414

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26