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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26