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