25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.geotools; |
package skrueger.geotools; |
31 |
|
|
32 |
import java.awt.Color; |
import java.awt.Color; |
|
import java.awt.Dimension; |
|
33 |
import java.awt.Graphics; |
import java.awt.Graphics; |
34 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
35 |
|
import java.awt.event.ActionListener; |
36 |
import java.util.ArrayList; |
import java.util.ArrayList; |
37 |
|
import java.util.HashSet; |
38 |
import java.util.Locale; |
import java.util.Locale; |
39 |
|
import java.util.Set; |
40 |
import java.util.SortedMap; |
import java.util.SortedMap; |
41 |
import java.util.TreeMap; |
import java.util.TreeMap; |
42 |
|
|
43 |
import javax.swing.AbstractAction; |
import javax.swing.AbstractAction; |
44 |
import javax.swing.AbstractButton; |
import javax.swing.AbstractButton; |
45 |
import javax.swing.Action; |
import javax.swing.Action; |
|
import javax.swing.BorderFactory; |
|
46 |
import javax.swing.Icon; |
import javax.swing.Icon; |
47 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
48 |
import javax.swing.JButton; |
import javax.swing.JButton; |
52 |
|
|
53 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
54 |
|
|
55 |
import schmitzm.geotools.gui.JMapPane; |
import schmitzm.geotools.gui.SelectableXMapPane; |
56 |
import schmitzm.geotools.map.event.JMapPaneEvent; |
import schmitzm.geotools.gui.XMapPaneEvent; |
57 |
|
import schmitzm.geotools.gui.XMapPaneTool; |
58 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
59 |
import schmitzm.geotools.map.event.MapAreaChangedEvent; |
import schmitzm.geotools.map.event.MapAreaChangedEvent; |
60 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
61 |
import schmitzm.lang.ResourceProvider; |
import schmitzm.lang.ResourceProvider; |
62 |
import schmitzm.swing.ButtonGroup; |
import schmitzm.swing.ButtonGroup; |
63 |
import schmitzm.swing.SwingUtil; |
import skrueger.swing.SmallButton; |
64 |
|
import skrueger.swing.SmallToggleButton; |
65 |
|
|
66 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
67 |
|
|
68 |
/** |
/** |
69 |
* A toolbar to control an {@link JMapPane} (Atlas visualization). This contains |
* A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains |
70 |
* two types of buttons. A group of <i>tools</i> for the mouse actions on the |
* two types of buttons. A group of <i>tools</i> for the mouse actions on the |
71 |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
72 |
* can be activated every time. And some (general) <i>actions</i>, represented |
* can be activated every time. And some (general) <i>actions</i>, represented |
74 |
* |
* |
75 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
76 |
* (University of Bonn/Germany) |
* (University of Bonn/Germany) |
77 |
* @version 1.2 Stefan Krüger |
* @version 1.2 Stefan Tzeggai |
78 |
*/ |
*/ |
79 |
public class MapPaneToolBar extends JToolBar { |
public class MapPaneToolBar extends JToolBar { |
80 |
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class |
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class |
81 |
.getName()); |
.getName()); |
82 |
|
|
83 |
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
public static ResourceProvider RESOURCE = ResourceProvider.newInstance(LangUtil |
84 |
.extendPackagePath(MapPaneToolBar.class, |
.extendPackagePath(MapPaneToolBar.class, |
85 |
"resource.locales.mapPaneToolbar"), Locale.ENGLISH); |
"resource.locales.mapPaneToolbar"), Locale.ENGLISH); |
86 |
|
|
87 |
public static String R(String key, Object... values) { |
public static String R(String key, Object... values) { |
88 |
return RESOURCE.getString(key, values); |
return RESOURCE.getString(key, values); |
89 |
} |
} |
96 |
|
|
97 |
/** Constant for the tool "Zoom In" (110). */ |
/** Constant for the tool "Zoom In" (110). */ |
98 |
public static final int TOOL_ZOOMIN = 110; |
public static final int TOOL_ZOOMIN = 110; |
99 |
|
public static final int ACTION_ZOOM_DEFAULT = 150; |
100 |
/** Constant for the tool "Zoom Out" (120). */ |
/** Constant for the tool "Zoom Out" (120). */ |
101 |
public static final int TOOL_ZOOMOUT = 120; |
public static final int TOOL_ZOOMOUT = 120; |
102 |
/** Constant for the action "Zoom back" (130). */ |
/** Constant for the action "Zoom back" (130). */ |
126 |
*/ |
*/ |
127 |
public static final int TOOL_SELECTION_REMOVE = 230; |
public static final int TOOL_SELECTION_REMOVE = 230; |
128 |
|
|
129 |
|
public static final int ACTION_CHARTS = 401; |
130 |
|
|
131 |
/** Tool currently selected */ |
/** Tool currently selected */ |
132 |
protected int selectedTool = TOOL_ZOOMIN; |
protected int selectedTool = TOOL_ZOOMIN; |
133 |
|
|
134 |
/** Holds the tool buttons of the tool bar. */ |
/** Holds the tool buttons of the tool bar. */ |
135 |
protected SortedMap<Integer, JComponent> toolAndActionButtons = null; |
final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>(); |
136 |
/** Controls that only one tool button is activated. */ |
/** Controls that only one tool button is activated. */ |
137 |
protected ButtonGroup toolButtonGroup = null; |
protected ButtonGroup toolButtonGroup = null; |
138 |
|
|
141 |
// /** Holds the action buttons of the bar. */ |
// /** Holds the action buttons of the bar. */ |
142 |
// protected SortedMap<Integer, JButton> actionButtons = null; |
// protected SortedMap<Integer, JButton> actionButtons = null; |
143 |
|
|
144 |
/** Holds the {@link JMapPane} this tool bar controls. */ |
/** Holds the {@link SelectableXMapPane} this tool bar controls. */ |
145 |
protected JMapPane mapPane = null; |
protected SelectableXMapPane mapPane = null; |
146 |
|
|
147 |
/** |
/** |
148 |
* A List to remember the last Envelopes that have been watched. Used for |
* A List to remember the last Envelopes that have been watched. Used for |
157 |
|
|
158 |
protected boolean zoomBackForwardButtonInAction; |
protected boolean zoomBackForwardButtonInAction; |
159 |
|
|
160 |
|
/** Listeners what want to be informed about a change of the selected tool **/ |
161 |
|
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>(); |
162 |
|
|
163 |
|
/** This listener is added to all {@link JToggleButton} **/ |
164 |
|
private final ActionListener toolSelectedListener = new ActionListener() { |
165 |
|
|
166 |
|
@Override |
167 |
|
public void actionPerformed(ActionEvent e) { |
168 |
|
JToggleButton tb = (JToggleButton) e.getSource(); |
169 |
|
|
170 |
|
// Inform the listeners about a newly selected tool |
171 |
|
for (MapPaneToolSelectedListener l : toolSelectionListeners) { |
172 |
|
l.toolSelected(Integer.valueOf(tb.getName())); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
|
}; |
177 |
|
|
178 |
/** |
/** |
179 |
* Creates a new toolbar. Notice: This toolbar does nothing until |
* Creates a new toolbar. Notice: This toolbar does nothing until |
180 |
* {@link #setMapPane(JMapPane)} is called! |
* {@link #setMapPane(SelectableXMapPane)} is called! |
181 |
*/ |
*/ |
182 |
public MapPaneToolBar() { |
public MapPaneToolBar() { |
183 |
this(null); |
this(null); |
184 |
} |
} |
185 |
|
|
186 |
|
public void addButtonSelectedListener(MapPaneToolSelectedListener listener) { |
187 |
|
toolSelectionListeners.add(listener); |
188 |
|
} |
189 |
|
|
190 |
|
public void removeButtonSelectedListener( |
191 |
|
MapPaneToolSelectedListener listener) { |
192 |
|
toolSelectionListeners.remove(listener); |
193 |
|
} |
194 |
|
|
195 |
/** |
/** |
196 |
* Creates a new tool bar. |
* Creates a new tool bar. |
197 |
* |
* |
198 |
* @param mapPane |
* @param mapPane |
199 |
* {@link JMapPane} the tool bar controls |
* {@link SelectableXMapPane} the tool bar controls |
200 |
*/ |
*/ |
201 |
public MapPaneToolBar(JMapPane mapPane) { |
public MapPaneToolBar(SelectableXMapPane mapPane) { |
202 |
super("Control the map", JToolBar.HORIZONTAL); |
super("Control the map", JToolBar.HORIZONTAL); |
203 |
this.toolAndActionButtons = new TreeMap<Integer, JComponent>(); |
|
204 |
|
// I want to see nothing on the background |
205 |
|
setOpaque(false); |
206 |
|
setBorder(null); |
207 |
|
|
208 |
this.toolButtonGroup = new ButtonGroup(); |
this.toolButtonGroup = new ButtonGroup(); |
209 |
|
|
210 |
// Create a Listener to listen to the zooms on the JMapPane |
// Create a Listener to listen to the zooms on the JMapPane |
211 |
this.mapPaneListener = new JMapPaneListener() { |
this.mapPaneListener = new JMapPaneListener() { |
212 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(XMapPaneEvent e) { |
213 |
if (!(e instanceof MapAreaChangedEvent)) |
if (!(e instanceof MapAreaChangedEvent)) |
214 |
return; |
return; |
215 |
|
|
220 |
|
|
221 |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
222 |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
223 |
|
|
224 |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
225 |
if (mapArea == null || mapArea.equals(oldMapArea) ) { |
if (mapArea == null || mapArea.equals(oldMapArea) |
226 |
// If the MapArea didn't change... we don't want to register it as a zoom action. |
|| Double.isNaN(mapArea.getMinX()) |
227 |
|
|| Double.isNaN(mapArea.getMaxX()) |
228 |
|
|| Double.isNaN(mapArea.getMinY()) |
229 |
|
|| Double.isNaN(mapArea.getMaxY())) { |
230 |
|
// If the MapArea didn't change... we don't want to register |
231 |
|
// it as a zoom action. |
232 |
return; |
return; |
233 |
} |
} |
234 |
|
|
235 |
if (lastZooms.size() == 0 && oldMapArea != null) { |
if (lastZooms.size() == 0 |
236 |
|
&& oldMapArea != null |
237 |
|
&& !oldMapArea.isNull() |
238 |
|
&& !(Double.isNaN(oldMapArea.getMinX()) |
239 |
|
|| Double.isNaN(oldMapArea.getMaxX()) |
240 |
|
|| Double.isNaN(oldMapArea.getMinY()) || Double |
241 |
|
.isNaN(oldMapArea.getMaxY()))) { |
242 |
lastZooms.add(oldMapArea); |
lastZooms.add(oldMapArea); |
243 |
zoomBackIndex = 1; |
zoomBackIndex = 1; |
244 |
} |
} |
270 |
} |
} |
271 |
|
|
272 |
/** |
/** |
273 |
* Sets the {@link JMapPane} controlled by this tool bar. |
* Sets the {@link SelectableXMapPane} controlled by this tool bar. |
274 |
* |
* |
275 |
* @param mapPane |
* @param mapPane |
276 |
* {@link JMapPane} to control (if {@code null} this tool bar |
* {@link SelectableXMapPane} to control (if {@code null} this tool bar |
277 |
* controls NOTHING!) |
* controls NOTHING!) |
278 |
*/ |
*/ |
279 |
public void setMapPane(JMapPane mapPane) { |
public void setMapPane(SelectableXMapPane mapPane) { |
280 |
// Remove listener from old MapPane |
// Remove listener from old MapPane |
281 |
if (this.mapPane != null) |
if (this.mapPane != null) |
282 |
this.mapPane.removeMapPaneListener(mapPaneListener); |
this.mapPane.removeMapPaneListener(mapPaneListener); |
290 |
* puts all tool buttons and all actions buttons to the tool bar. |
* puts all tool buttons and all actions buttons to the tool bar. |
291 |
*/ |
*/ |
292 |
protected void init() { |
protected void init() { |
293 |
|
|
294 |
initToolsAndActions(); |
initToolsAndActions(); |
295 |
|
|
296 |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
308 |
*/ |
*/ |
309 |
protected void initToolsAndActions() { |
protected void initToolsAndActions() { |
310 |
// Panning |
// Panning |
311 |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
// addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
312 |
MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false); |
// MapView.class.getResource("resource/icons/pan.png")), |
313 |
|
// R("MapPaneButtons.Pan.TT")), false); |
314 |
|
|
315 |
|
addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false); |
316 |
|
|
317 |
// Info |
// Info |
318 |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
// addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
319 |
MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false); |
// MapView.class.getResource("resource/icons/info.png")), |
320 |
|
// R("MapPaneButtons.Info.TT")), false); |
321 |
|
addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false); |
322 |
|
|
323 |
// Zoom in |
// Zoom in |
324 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false); |
325 |
MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")), |
|
|
false); |
|
326 |
// Zoom out |
// Zoom out |
327 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false); |
328 |
MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")), |
|
329 |
false); |
|
330 |
|
// // Zoom in |
331 |
|
// addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
332 |
|
// MapView.class.getResource("resource/icons/zoom_in.png")), |
333 |
|
// R("MapPaneButtons.ZoomIn.TT")), false); |
334 |
|
// |
335 |
|
// // Zoom out |
336 |
|
// addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
337 |
|
// MapView.class.getResource("resource/icons/zoom_out.png")), |
338 |
|
// R("MapPaneButtons.ZoomOut.TT")), false); |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
// Action button to revert the last zoom |
// Action button to revert the last zoom |
343 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
344 |
new ImageIcon(MapView.class |
new ImageIcon(MapView.class |
345 |
.getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false); |
.getResource("resource/icons/zoom_back.png")), |
346 |
|
R("MapPaneButtons.LastZoom.TT")), false); |
347 |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
348 |
|
|
349 |
// Action button to redo the last zoom |
// Action button to redo the last zoom |
350 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
351 |
new ImageIcon(MapView.class |
new ImageIcon(MapView.class |
352 |
.getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")), |
.getResource("resource/icons/zoom_forward.png")), |
353 |
false); |
R("MapPaneButtons.NextZoom.TT")), false); |
354 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
355 |
|
|
356 |
// set the selected tool enabled |
// set the selected tool enabled |
358 |
|
|
359 |
} |
} |
360 |
|
|
361 |
|
@Override |
362 |
|
public void paint(Graphics g) { |
363 |
|
super.paint(g); |
364 |
|
} |
365 |
|
|
366 |
/** |
/** |
367 |
* Clears the GUI of all components and adds all tool and action buttons to |
* Clears the GUI of all components and adds all tool and action buttons to |
368 |
* the tool bar. |
* the tool bar. |
369 |
*/ |
*/ |
370 |
public void initToolBar() { |
public void initToolBar() { |
371 |
setAlignmentY(1f); |
// setOpaque(true); |
372 |
|
// |
373 |
|
// setAlignmentY(1f); |
374 |
|
// setAlignmentX(0.5f); |
375 |
removeAll(); |
removeAll(); |
376 |
// Separator to the left of the tool actions to start |
|
377 |
// the tool buttons with the map (not with the coordinate grid) |
// // Separator to the left of the tool actions to start |
378 |
Dimension dimension = new Dimension(49, 10); |
// // the tool buttons with the map (not with the coordinate grid) |
379 |
addSeparator(dimension); |
// Dimension dimension = new Dimension(49, 10); |
380 |
|
// addSeparator(dimension); |
381 |
|
|
382 |
// Tool buttons |
// Tool buttons |
383 |
for (JComponent b : toolAndActionButtons.values()) |
for (Integer bKey : toolAndActionButtons.keySet()) { |
384 |
|
|
385 |
|
JComponent b = toolAndActionButtons.get(bKey); |
386 |
|
|
387 |
|
if (b instanceof JToggleButton) { |
388 |
|
JToggleButton tb = (JToggleButton) b; |
389 |
|
tb.setName(bKey.toString()); |
390 |
|
tb.addActionListener(toolSelectedListener); |
391 |
|
} |
392 |
|
|
393 |
add(b); |
add(b); |
394 |
|
} |
395 |
|
|
396 |
if (!toolAndActionButtons.containsKey(selectedTool)) { |
if (!toolAndActionButtons.containsKey(selectedTool)) { |
397 |
/** |
/** |
409 |
} |
} |
410 |
|
|
411 |
} |
} |
412 |
|
|
413 |
revalidate(); |
revalidate(); |
414 |
repaint(); |
repaint(); |
415 |
} |
} |
441 |
switch (tool) { |
switch (tool) { |
442 |
case TOOL_PAN: |
case TOOL_PAN: |
443 |
// Set the mouse tool to "Panning" |
// Set the mouse tool to "Panning" |
444 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
// mapPane.setState(SelectableXMapPane.PAN); |
445 |
mapPane.setState(JMapPane.PAN); |
mapPane.setTool(XMapPaneTool.PAN); |
446 |
mapPane.setHighlight(false); |
// mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
|
mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
|
447 |
break; |
break; |
448 |
case TOOL_INFO: |
case TOOL_INFO: |
449 |
// Set the mouse tool to "Info" |
// Set the mouse tool to "Info" |
450 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setTool(XMapPaneTool.INFO); |
451 |
mapPane.setState(JMapPane.SELECT_TOP); // Why not: |
// mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP); |
452 |
// JMapPane.SELECT_TOP_ONEONLY |
// mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
|
mapPane.setHighlight(false);// SK: Was true, but since it not works |
|
|
// properly removed it to save |
|
|
// performance |
|
|
mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
|
453 |
break; |
break; |
454 |
case TOOL_ZOOMIN: |
case TOOL_ZOOMIN: |
455 |
// Set the mouse tool to "Zoom in" |
// Set the mouse tool to "Zoom in" |
456 |
mapPane.setWindowSelectionState(JMapPane.ZOOM_IN); |
mapPane.setTool(XMapPaneTool.ZOOM_IN); |
457 |
mapPane.setState(JMapPane.ZOOM_IN); |
// mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
|
mapPane.setHighlight(false); |
|
|
mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
|
458 |
break; |
break; |
459 |
case TOOL_ZOOMOUT: |
case TOOL_ZOOMOUT: |
460 |
// Set the mouse tool to "Zoom out" |
// Set the mouse tool to "Zoom out" |
461 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setTool(XMapPaneTool.ZOOM_OUT); |
462 |
mapPane.setState(JMapPane.ZOOM_OUT); |
// mapPane.setState(SelectableXMapPane.ZOOM_OUT); |
463 |
mapPane.setHighlight(false); |
// mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
|
mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
|
464 |
break; |
break; |
465 |
default: |
// default: |
466 |
// Set map actions to default |
// Set map actions to default |
467 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
// mapPane.setState(SelectableXMapPane.NONE); |
468 |
mapPane.setState(JMapPane.NONE); |
// mapPane.setNormalCursor(null); |
469 |
mapPane.setHighlight(false); |
// break; |
|
mapPane.setNormalCursor(null); |
|
|
break; |
|
470 |
} |
} |
471 |
mapPane.updateCursor(); |
// mapPane.updateCursorAndRepaintTimer(); |
472 |
} |
} |
473 |
|
|
474 |
/** |
/** |
492 |
protected void performActionButton(int action, ActionEvent e) { |
protected void performActionButton(int action, ActionEvent e) { |
493 |
if (mapPane == null) |
if (mapPane == null) |
494 |
return; |
return; |
495 |
|
|
496 |
// Perform the action "Zoom back": Revert the last zoom |
// Perform the action "Zoom back": Revert the last zoom |
497 |
if (action == ACTION_ZOOM_BACK) { |
if (action == ACTION_ZOOM_BACK) { |
498 |
if (zoomBackIndex <= 1) |
if (zoomBackIndex <= 1) |
540 |
+ buttonAction.getID()); |
+ buttonAction.getID()); |
541 |
return; |
return; |
542 |
} |
} |
543 |
JToggleButton button = new JToggleButton(buttonAction); |
JToggleButton button = new SmallToggleButton(buttonAction); |
544 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
|
545 |
|
// button.setBorder(BorderFactory.createRaisedBevelBorder()); |
546 |
toolButtonGroup.add(button); |
toolButtonGroup.add(button); |
547 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
548 |
if (resetToolBar) |
if (resetToolBar) |
578 |
+ buttonAction.getID()); |
+ buttonAction.getID()); |
579 |
return; |
return; |
580 |
} |
} |
581 |
JButton button = new JButton(buttonAction); |
JButton button = new SmallButton(buttonAction); |
582 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
// button.setBorder(BorderFactory.createRaisedBevelBorder()); |
583 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
584 |
if (resetToolBar) |
if (resetToolBar) |
585 |
initToolBar(); |
initToolBar(); |
586 |
} |
} |
587 |
|
|
588 |
|
/** |
589 |
|
* Adds any JComponent to the tool bar. Does nothing if a tool or action |
590 |
|
* with the specified ID already exists! |
591 |
|
* |
592 |
|
* @param component |
593 |
|
* A {@link JComponent} that shall be added |
594 |
|
* @param id |
595 |
|
* The ID associaded with the {@link JComponent} |
596 |
|
* @param resetToolBar |
597 |
|
* indicates whether the toolbar GUI is reset after adding the |
598 |
|
* button (if adding several actions it useful only to reset the |
599 |
|
* GUI for the last added tool) |
600 |
|
*/ |
601 |
|
public void addJComponent(JComponent component, int id, boolean resetToolBar) { |
602 |
|
|
603 |
|
if (isButtonIDUsed(id)) { |
604 |
|
LOGGER |
605 |
|
.warn("addAction(.) ignored because ID already used for tool or action: " |
606 |
|
+ id); |
607 |
|
return; |
608 |
|
} |
609 |
|
|
610 |
|
toolAndActionButtons.put(id, component); |
611 |
|
if (resetToolBar) |
612 |
|
initToolBar(); |
613 |
|
} |
614 |
|
|
615 |
public void addSeparator(int id, Separator separator) { |
public void addSeparator(int id, Separator separator) { |
616 |
if (isButtonIDUsed(id)) { |
if (isButtonIDUsed(id)) { |
617 |
LOGGER |
LOGGER |
642 |
* {@linkplain #getToolButton(int) tool button} |
* {@linkplain #getToolButton(int) tool button} |
643 |
*/ |
*/ |
644 |
public AbstractButton getButton(int id) { |
public AbstractButton getButton(int id) { |
645 |
|
|
646 |
|
//ACHUTNG: Das ist ein SK QUICK FIX! TODO |
647 |
|
if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null; |
648 |
|
|
649 |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
650 |
if (button == null) |
if (button == null) |
651 |
LOGGER.warn("Unknown tool or action ID: " + id); |
LOGGER.warn("Unknown tool or action ID: " + id); |
712 |
return -1; |
return -1; |
713 |
return selectedTool; |
return selectedTool; |
714 |
} |
} |
715 |
|
|
716 |
/** |
/** |
717 |
* 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 |
718 |
* of the button is not affected. |
* of the button is not affected. |
787 |
* is {@code false} |
* is {@code false} |
788 |
*/ |
*/ |
789 |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
790 |
for (int tool : toolAndActionButtons.keySet()) |
for (int id : toolAndActionButtons.keySet()) { |
791 |
setButtonEnabled(tool, enabled, hideOnDisable); |
if (toolAndActionButtons.get(id) instanceof JToggleButton) { |
792 |
|
setButtonEnabled(id, enabled, hideOnDisable); |
793 |
|
} |
794 |
|
} |
795 |
} |
} |
796 |
|
|
797 |
/** |
/** |
798 |
* Sets the activation for all actions. |
* Sets the activation for all actions. |
799 |
* |
* |
885 |
*/ |
*/ |
886 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
887 |
String name, Icon icon) { |
String name, Icon icon) { |
888 |
this (id, toolBar, name, icon, null); |
this(id, toolBar, name, icon, null); |
889 |
} |
} |
890 |
|
|
891 |
/** |
/** |
892 |
* Creates a new action. |
* Creates a new action. |
893 |
* |
* |
905 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
906 |
String name, Icon icon, String toolTip) { |
String name, Icon icon, String toolTip) { |
907 |
super(name, icon); |
super(name, icon); |
908 |
|
|
909 |
if (toolTip != null && !toolTip.trim().isEmpty()){ |
if (toolTip != null && !toolTip.trim().isEmpty()) { |
910 |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
911 |
} |
} |
912 |
|
|
913 |
this.id = id; |
this.id = id; |
914 |
this.toolBar = toolBar; |
this.toolBar = toolBar; |
915 |
} |
} |
916 |
|
|
917 |
|
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) { |
918 |
|
this(id, toolBar, "", tool.getIcon(), tool.getToolTip()); |
919 |
|
} |
920 |
|
|
921 |
/** |
/** |
922 |
* Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
* Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
923 |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} |
941 |
return id; |
return id; |
942 |
} |
} |
943 |
} |
} |
944 |
|
|
945 |
/** |
/** |
946 |
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der |
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht |
947 |
* Hintergrund auf WEISS gesetzt. |
* wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
948 |
* |
* |
949 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
950 |
* Krüger</a> |
* Krüger</a> |
951 |
*/ |
*/ |
952 |
@Override |
@Override |
953 |
public void print(Graphics g) { |
public void print(Graphics g) { |
954 |
Color orig = getBackground(); |
Color orig = getBackground(); |
955 |
setBackground(Color.WHITE); |
setBackground(Color.WHITE); |
956 |
// wrap in try/finally so that we always restore the state |
// wrap in try/finally so that we always restore the state |
957 |
try { |
try { |
958 |
super.print(g); |
super.print(g); |
959 |
} finally { |
} finally { |
960 |
setBackground(orig); |
setBackground(orig); |
961 |
} |
} |
962 |
} |
} |
963 |
|
|
964 |
} |
} |