/[schmitzm]/branches/2.3.x/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Annotation of /branches/2.3.x/src/skrueger/geotools/MapPaneToolBar.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 111 - (hide annotations)
Tue May 12 23:33:14 2009 UTC (15 years, 9 months ago) by alfonx
Original Path: trunk/src/skrueger/geotools/MapPaneToolBar.java
File size: 25476 byte(s)
* Fixed some bugs with the SelectionListeners and the JMapPane. To make this work,  StyledFeatureLayerSelectionModel now extends StyledLayerSelectionModel<String>. So the selection is remembered as a Set of Feature-IDs. This change was needed, because Feature.java doesn't overwrite the equals method, and therefore the HashSet didn't function as expected.
* Added new Tools and BUttons to MapPaneToolBar.java to select features
* Changed a lot in MapPaneToolBar.java. It now allows to position Spaces, Actions and Tools via the ID field. (the new feature is to mix them)
* Fixed a bug in AV's ClickInfoPanel that would suddenly pop up an AtlasViewer if started from Geopublisher under special circumstances.
* Moving layers in the legend is using MapContext's move method instead of remove and insert.
* LayerPanel's remember* Maps now all have the MapLayer's ID as a key. 

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26