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

Legend:
Removed from v.117  
changed lines
  Added in v.891

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26