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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26