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; |
import java.awt.event.ActionListener; |
36 |
import java.util.ArrayList; |
import java.util.ArrayList; |
37 |
import java.util.HashSet; |
import java.util.HashSet; |
|
import java.util.Locale; |
|
38 |
import java.util.Set; |
import java.util.Set; |
39 |
import java.util.SortedMap; |
import java.util.SortedMap; |
40 |
import java.util.TreeMap; |
import java.util.TreeMap; |
42 |
import javax.swing.AbstractAction; |
import javax.swing.AbstractAction; |
43 |
import javax.swing.AbstractButton; |
import javax.swing.AbstractButton; |
44 |
import javax.swing.Action; |
import javax.swing.Action; |
|
import javax.swing.BorderFactory; |
|
45 |
import javax.swing.Icon; |
import javax.swing.Icon; |
46 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
47 |
import javax.swing.JButton; |
import javax.swing.JButton; |
51 |
|
|
52 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
53 |
|
|
54 |
import schmitzm.geotools.gui.JMapPane; |
import schmitzm.geotools.gui.GeotoolsGUIUtil; |
55 |
import schmitzm.geotools.map.event.JMapPaneEvent; |
import schmitzm.geotools.gui.SelectableXMapPane; |
56 |
|
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; |
|
import schmitzm.lang.LangUtil; |
|
|
import schmitzm.lang.ResourceProvider; |
|
60 |
import schmitzm.swing.ButtonGroup; |
import schmitzm.swing.ButtonGroup; |
61 |
import schmitzm.swing.SwingUtil; |
import skrueger.swing.SmallButton; |
62 |
|
import skrueger.swing.SmallToggleButton; |
63 |
|
|
64 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
65 |
|
|
66 |
/** |
/** |
67 |
* A toolbar to control an {@link JMapPane} (Atlas visualization). This contains |
* A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains |
68 |
* 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 |
69 |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
70 |
* can be activated every time. And some (general) <i>actions</i>, represented |
* can be activated every time. And some (general) <i>actions</i>, represented |
72 |
* |
* |
73 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
74 |
* (University of Bonn/Germany) |
* (University of Bonn/Germany) |
75 |
* @version 1.2 Stefan Krüger |
* @version 1.2 Stefan Tzeggai |
76 |
*/ |
*/ |
77 |
public class MapPaneToolBar extends JToolBar { |
public class MapPaneToolBar extends JToolBar { |
78 |
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class |
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class |
79 |
.getName()); |
.getName()); |
80 |
|
|
|
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
|
|
.extendPackagePath(MapPaneToolBar.class, |
|
|
"resource.locales.mapPaneToolbar"), Locale.ENGLISH); |
|
|
|
|
81 |
public static String R(String key, Object... values) { |
public static String R(String key, Object... values) { |
82 |
return RESOURCE.getString(key, values); |
return GeotoolsGUIUtil.R(key, values); |
83 |
} |
} |
84 |
|
|
85 |
/** Constant for the tool "Panning" (10). */ |
/** Constant for the tool "Panning" (10). */ |
90 |
|
|
91 |
/** Constant for the tool "Zoom In" (110). */ |
/** Constant for the tool "Zoom In" (110). */ |
92 |
public static final int TOOL_ZOOMIN = 110; |
public static final int TOOL_ZOOMIN = 110; |
93 |
|
public static final int ACTION_ZOOM_DEFAULT = 150; |
94 |
/** Constant for the tool "Zoom Out" (120). */ |
/** Constant for the tool "Zoom Out" (120). */ |
95 |
public static final int TOOL_ZOOMOUT = 120; |
public static final int TOOL_ZOOMOUT = 120; |
96 |
/** Constant for the action "Zoom back" (130). */ |
/** Constant for the action "Zoom back" (130). */ |
135 |
// /** Holds the action buttons of the bar. */ |
// /** Holds the action buttons of the bar. */ |
136 |
// protected SortedMap<Integer, JButton> actionButtons = null; |
// protected SortedMap<Integer, JButton> actionButtons = null; |
137 |
|
|
138 |
/** Holds the {@link JMapPane} this tool bar controls. */ |
/** Holds the {@link SelectableXMapPane} this tool bar controls. */ |
139 |
protected JMapPane mapPane = null; |
protected SelectableXMapPane mapPane = null; |
140 |
|
|
141 |
/** |
/** |
142 |
* 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 |
154 |
/** Listeners what want to be informed about a change of the selected tool **/ |
/** Listeners what want to be informed about a change of the selected tool **/ |
155 |
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>(); |
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>(); |
156 |
|
|
157 |
/** This listener is added to all {@link JToggleButton} **/ |
/** This listener is added to all {@link JToggleButton} **/ |
158 |
private final ActionListener toolSelectedListener = new ActionListener(){ |
private final ActionListener toolSelectedListener = new ActionListener() { |
159 |
|
|
160 |
@Override |
@Override |
161 |
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
162 |
JToggleButton tb = (JToggleButton) e.getSource(); |
JToggleButton tb = (JToggleButton) e.getSource(); |
163 |
|
|
164 |
// Inform the listeners about a newly selected tool |
// Inform the listeners about a newly selected tool |
165 |
for (MapPaneToolSelectedListener l : toolSelectionListeners) { |
for (MapPaneToolSelectedListener l : toolSelectionListeners) { |
166 |
l.toolSelected(Integer.valueOf( tb.getName() ) ) ; |
l.toolSelected(Integer.valueOf(tb.getName())); |
167 |
} |
} |
168 |
} |
} |
169 |
|
|
170 |
}; |
}; |
171 |
|
|
172 |
/** |
/** |
173 |
* Creates a new toolbar. Notice: This toolbar does nothing until |
* Creates a new toolbar. Notice: This toolbar does nothing until |
174 |
* {@link #setMapPane(JMapPane)} is called! |
* {@link #setMapPane(SelectableXMapPane)} is called! |
175 |
*/ |
*/ |
176 |
public MapPaneToolBar() { |
public MapPaneToolBar() { |
177 |
this(null); |
this(null); |
178 |
} |
} |
179 |
|
|
180 |
public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) { |
public void addButtonSelectedListener(MapPaneToolSelectedListener listener) { |
181 |
toolSelectionListeners.add(listener); |
toolSelectionListeners.add(listener); |
182 |
} |
} |
183 |
|
|
184 |
public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) { |
public void removeButtonSelectedListener( |
185 |
toolSelectionListeners .remove(listener); |
MapPaneToolSelectedListener listener) { |
186 |
|
toolSelectionListeners.remove(listener); |
187 |
} |
} |
188 |
|
|
189 |
/** |
/** |
190 |
* Creates a new tool bar. |
* Creates a new tool bar. |
191 |
* |
* |
192 |
* @param mapPane |
* @param mapPane |
193 |
* {@link JMapPane} the tool bar controls |
* {@link SelectableXMapPane} the tool bar controls |
194 |
*/ |
*/ |
195 |
public MapPaneToolBar(JMapPane mapPane) { |
public MapPaneToolBar(SelectableXMapPane mapPane) { |
196 |
super("Control the map", JToolBar.HORIZONTAL); |
super("Control the map", JToolBar.HORIZONTAL); |
197 |
|
|
198 |
|
// I want to see nothing on the background |
199 |
|
setOpaque(false); |
200 |
|
setBorder(null); |
201 |
|
|
202 |
this.toolButtonGroup = new ButtonGroup(); |
this.toolButtonGroup = new ButtonGroup(); |
203 |
|
|
204 |
// Create a Listener to listen to the zooms on the JMapPane |
// Create a Listener to listen to the zooms on the JMapPane |
205 |
this.mapPaneListener = new JMapPaneListener() { |
this.mapPaneListener = new JMapPaneListener() { |
206 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(XMapPaneEvent e) { |
207 |
if (!(e instanceof MapAreaChangedEvent)) |
if (!(e instanceof MapAreaChangedEvent)) |
208 |
return; |
return; |
209 |
|
|
214 |
|
|
215 |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
216 |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
217 |
|
|
218 |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
219 |
if (mapArea == null || mapArea.equals(oldMapArea) ) { |
if (mapArea == null || mapArea.equals(oldMapArea) |
220 |
// If the MapArea didn't change... we don't want to register it as a zoom action. |
|| Double.isNaN(mapArea.getMinX()) |
221 |
|
|| Double.isNaN(mapArea.getMaxX()) |
222 |
|
|| Double.isNaN(mapArea.getMinY()) |
223 |
|
|| Double.isNaN(mapArea.getMaxY())) { |
224 |
|
// If the MapArea didn't change... we don't want to register |
225 |
|
// it as a zoom action. |
226 |
return; |
return; |
227 |
} |
} |
228 |
|
|
229 |
if (lastZooms.size() == 0 && oldMapArea != null) { |
if (lastZooms.size() == 0 |
230 |
|
&& oldMapArea != null |
231 |
|
&& !oldMapArea.isNull() |
232 |
|
&& !(Double.isNaN(oldMapArea.getMinX()) |
233 |
|
|| Double.isNaN(oldMapArea.getMaxX()) |
234 |
|
|| Double.isNaN(oldMapArea.getMinY()) || Double |
235 |
|
.isNaN(oldMapArea.getMaxY()))) { |
236 |
lastZooms.add(oldMapArea); |
lastZooms.add(oldMapArea); |
237 |
zoomBackIndex = 1; |
zoomBackIndex = 1; |
238 |
} |
} |
264 |
} |
} |
265 |
|
|
266 |
/** |
/** |
267 |
* Sets the {@link JMapPane} controlled by this tool bar. |
* Sets the {@link SelectableXMapPane} controlled by this tool bar. |
268 |
* |
* |
269 |
* @param mapPane |
* @param mapPane |
270 |
* {@link JMapPane} to control (if {@code null} this tool bar |
* {@link SelectableXMapPane} to control (if {@code null} this tool bar |
271 |
* controls NOTHING!) |
* controls NOTHING!) |
272 |
*/ |
*/ |
273 |
public void setMapPane(JMapPane mapPane) { |
public void setMapPane(SelectableXMapPane mapPane) { |
274 |
// Remove listener from old MapPane |
// Remove listener from old MapPane |
275 |
if (this.mapPane != null) |
if (this.mapPane != null) |
276 |
this.mapPane.removeMapPaneListener(mapPaneListener); |
this.mapPane.removeMapPaneListener(mapPaneListener); |
284 |
* puts all tool buttons and all actions buttons to the tool bar. |
* puts all tool buttons and all actions buttons to the tool bar. |
285 |
*/ |
*/ |
286 |
protected void init() { |
protected void init() { |
287 |
|
|
288 |
initToolsAndActions(); |
initToolsAndActions(); |
289 |
|
|
290 |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
302 |
*/ |
*/ |
303 |
protected void initToolsAndActions() { |
protected void initToolsAndActions() { |
304 |
// Panning |
// Panning |
305 |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
// addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
306 |
MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false); |
// MapView.class.getResource("resource/icons/pan.png")), |
307 |
|
// R("MapPaneButtons.Pan.TT")), false); |
308 |
|
|
309 |
|
addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false); |
310 |
|
|
311 |
// Info |
// Info |
312 |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
// addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
313 |
MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false); |
// MapView.class.getResource("resource/icons/info.png")), |
314 |
|
// R("MapPaneButtons.Info.TT")), false); |
315 |
|
addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false); |
316 |
|
|
317 |
// Zoom in |
// Zoom in |
318 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false); |
319 |
MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")), |
|
|
false); |
|
320 |
// Zoom out |
// Zoom out |
321 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false); |
322 |
MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")), |
|
323 |
false); |
|
324 |
|
// // Zoom in |
325 |
|
// addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
326 |
|
// MapView.class.getResource("resource/icons/zoom_in.png")), |
327 |
|
// R("MapPaneButtons.ZoomIn.TT")), false); |
328 |
|
// |
329 |
|
// // Zoom out |
330 |
|
// addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
331 |
|
// MapView.class.getResource("resource/icons/zoom_out.png")), |
332 |
|
// R("MapPaneButtons.ZoomOut.TT")), false); |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
// Action button to revert the last zoom |
// Action button to revert the last zoom |
337 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
338 |
new ImageIcon(MapView.class |
new ImageIcon(MapView.class |
339 |
.getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false); |
.getResource("resource/icons/zoom_back.png")), |
340 |
|
R("MapPaneButtons.LastZoom.TT")), false); |
341 |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
342 |
|
|
343 |
// Action button to redo the last zoom |
// Action button to redo the last zoom |
344 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
345 |
new ImageIcon(MapView.class |
new ImageIcon(MapView.class |
346 |
.getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")), |
.getResource("resource/icons/zoom_forward.png")), |
347 |
false); |
R("MapPaneButtons.NextZoom.TT")), false); |
348 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
349 |
|
|
350 |
// set the selected tool enabled |
// set the selected tool enabled |
352 |
|
|
353 |
} |
} |
354 |
|
|
355 |
|
@Override |
356 |
|
public void paint(Graphics g) { |
357 |
|
super.paint(g); |
358 |
|
} |
359 |
|
|
360 |
/** |
/** |
361 |
* 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 |
362 |
* the tool bar. |
* the tool bar. |
363 |
*/ |
*/ |
364 |
public void initToolBar() { |
public void initToolBar() { |
365 |
setAlignmentY(1f); |
// setOpaque(true); |
366 |
|
// |
367 |
|
// setAlignmentY(1f); |
368 |
|
// setAlignmentX(0.5f); |
369 |
removeAll(); |
removeAll(); |
370 |
// Separator to the left of the tool actions to start |
|
371 |
// the tool buttons with the map (not with the coordinate grid) |
// // Separator to the left of the tool actions to start |
372 |
Dimension dimension = new Dimension(49, 10); |
// // the tool buttons with the map (not with the coordinate grid) |
373 |
addSeparator(dimension); |
// Dimension dimension = new Dimension(49, 10); |
374 |
|
// addSeparator(dimension); |
375 |
|
|
376 |
// Tool buttons |
// Tool buttons |
377 |
for (Integer bKey : toolAndActionButtons.keySet()) { |
for (Integer bKey : toolAndActionButtons.keySet()) { |
378 |
|
|
379 |
JComponent b = toolAndActionButtons.get(bKey); |
JComponent b = toolAndActionButtons.get(bKey); |
380 |
|
|
381 |
if (b instanceof JToggleButton) { |
if (b instanceof JToggleButton) { |
382 |
JToggleButton tb = (JToggleButton) b; |
JToggleButton tb = (JToggleButton) b; |
383 |
tb.setName(bKey.toString()); |
tb.setName(bKey.toString()); |
384 |
tb.addActionListener( toolSelectedListener ); |
tb.addActionListener(toolSelectedListener); |
385 |
} |
} |
386 |
|
|
387 |
add(b); |
add(b); |
388 |
} |
} |
389 |
|
|
403 |
} |
} |
404 |
|
|
405 |
} |
} |
406 |
|
|
407 |
revalidate(); |
revalidate(); |
408 |
repaint(); |
repaint(); |
409 |
} |
} |
435 |
switch (tool) { |
switch (tool) { |
436 |
case TOOL_PAN: |
case TOOL_PAN: |
437 |
// Set the mouse tool to "Panning" |
// Set the mouse tool to "Panning" |
438 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
// mapPane.setState(SelectableXMapPane.PAN); |
439 |
mapPane.setState(JMapPane.PAN); |
mapPane.setTool(XMapPaneTool.PAN); |
440 |
mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
// mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
441 |
break; |
break; |
442 |
case TOOL_INFO: |
case TOOL_INFO: |
443 |
// Set the mouse tool to "Info" |
// Set the mouse tool to "Info" |
444 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setTool(XMapPaneTool.INFO); |
445 |
mapPane.setState(JMapPane.SELECT_TOP); // Why not: |
// mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP); |
446 |
// JMapPane.SELECT_TOP_ONEONLY |
// mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
|
// properly removed it to save |
|
|
// performance |
|
|
mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
|
447 |
break; |
break; |
448 |
case TOOL_ZOOMIN: |
case TOOL_ZOOMIN: |
449 |
// Set the mouse tool to "Zoom in" |
// Set the mouse tool to "Zoom in" |
450 |
mapPane.setWindowSelectionState(JMapPane.ZOOM_IN); |
mapPane.setTool(XMapPaneTool.ZOOM_IN); |
451 |
mapPane.setState(JMapPane.ZOOM_IN); |
// mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
|
mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
|
452 |
break; |
break; |
453 |
case TOOL_ZOOMOUT: |
case TOOL_ZOOMOUT: |
454 |
// Set the mouse tool to "Zoom out" |
// Set the mouse tool to "Zoom out" |
455 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setTool(XMapPaneTool.ZOOM_OUT); |
456 |
mapPane.setState(JMapPane.ZOOM_OUT); |
// mapPane.setState(SelectableXMapPane.ZOOM_OUT); |
457 |
mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
// mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
458 |
break; |
break; |
459 |
default: |
// default: |
460 |
// Set map actions to default |
// Set map actions to default |
461 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
// mapPane.setState(SelectableXMapPane.NONE); |
462 |
mapPane.setState(JMapPane.NONE); |
// mapPane.setNormalCursor(null); |
463 |
mapPane.setNormalCursor(null); |
// break; |
|
break; |
|
464 |
} |
} |
465 |
mapPane.updateCursor(); |
// mapPane.updateCursorAndRepaintTimer(); |
466 |
} |
} |
467 |
|
|
468 |
/** |
/** |
486 |
protected void performActionButton(int action, ActionEvent e) { |
protected void performActionButton(int action, ActionEvent e) { |
487 |
if (mapPane == null) |
if (mapPane == null) |
488 |
return; |
return; |
489 |
|
|
490 |
// Perform the action "Zoom back": Revert the last zoom |
// Perform the action "Zoom back": Revert the last zoom |
491 |
if (action == ACTION_ZOOM_BACK) { |
if (action == ACTION_ZOOM_BACK) { |
492 |
if (zoomBackIndex <= 1) |
if (zoomBackIndex <= 1) |
534 |
+ buttonAction.getID()); |
+ buttonAction.getID()); |
535 |
return; |
return; |
536 |
} |
} |
537 |
JToggleButton button = new JToggleButton(buttonAction); |
JToggleButton button = new SmallToggleButton(buttonAction); |
538 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
|
539 |
|
// button.setBorder(BorderFactory.createRaisedBevelBorder()); |
540 |
toolButtonGroup.add(button); |
toolButtonGroup.add(button); |
541 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
542 |
if (resetToolBar) |
if (resetToolBar) |
543 |
initToolBar(); |
initToolBar(); |
544 |
} |
} |
545 |
|
|
|
|
|
|
|
|
546 |
/** |
/** |
547 |
* Adds a tool to the tool bar and resets the toolbar GUI. |
* Adds a tool to the tool bar and resets the toolbar GUI. |
548 |
* |
* |
572 |
+ buttonAction.getID()); |
+ buttonAction.getID()); |
573 |
return; |
return; |
574 |
} |
} |
575 |
JButton button = new JButton(buttonAction); |
JButton button = new SmallButton(buttonAction); |
576 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
// button.setBorder(BorderFactory.createRaisedBevelBorder()); |
577 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
578 |
if (resetToolBar) |
if (resetToolBar) |
579 |
initToolBar(); |
initToolBar(); |
580 |
} |
} |
581 |
|
|
582 |
/** |
/** |
583 |
* Adds any JComponent to the tool bar. Does nothing if a tool or action with the |
* Adds any JComponent to the tool bar. Does nothing if a tool or action |
584 |
* specified ID already exists! |
* with the specified ID already exists! |
585 |
* |
* |
586 |
* @param component A {@link JComponent} that shall be added |
* @param component |
587 |
* @param id The ID associaded with the {@link JComponent} |
* A {@link JComponent} that shall be added |
588 |
|
* @param id |
589 |
|
* The ID associaded with the {@link JComponent} |
590 |
* @param resetToolBar |
* @param resetToolBar |
591 |
* indicates whether the toolbar GUI is reset after adding the |
* indicates whether the toolbar GUI is reset after adding the |
592 |
* button (if adding several actions it useful only to reset the |
* button (if adding several actions it useful only to reset the |
593 |
* GUI for the last added tool) |
* GUI for the last added tool) |
594 |
*/ |
*/ |
595 |
public void addJComponent(JComponent component, int id, |
public void addJComponent(JComponent component, int id, boolean resetToolBar) { |
|
boolean resetToolBar) { |
|
596 |
|
|
597 |
if (isButtonIDUsed(id)) { |
if (isButtonIDUsed(id)) { |
598 |
LOGGER |
LOGGER |
599 |
.warn("addAction(.) ignored because ID already used for tool or action: " |
.warn("addAction(.) ignored because ID already used for tool or action: " |
600 |
+ id); |
+ id); |
601 |
return; |
return; |
602 |
} |
} |
603 |
|
|
604 |
toolAndActionButtons.put(id, component); |
toolAndActionButtons.put(id, component); |
605 |
if (resetToolBar) |
if (resetToolBar) |
606 |
initToolBar(); |
initToolBar(); |
636 |
* {@linkplain #getToolButton(int) tool button} |
* {@linkplain #getToolButton(int) tool button} |
637 |
*/ |
*/ |
638 |
public AbstractButton getButton(int id) { |
public AbstractButton getButton(int id) { |
639 |
|
|
640 |
|
//ACHUTNG: Das ist ein SK QUICK FIX! TODO |
641 |
|
if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null; |
642 |
|
|
643 |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
644 |
if (button == null) |
if (button == null) |
645 |
LOGGER.warn("Unknown tool or action ID: " + id); |
LOGGER.warn("Unknown tool or action ID: " + id); |
706 |
return -1; |
return -1; |
707 |
return selectedTool; |
return selectedTool; |
708 |
} |
} |
709 |
|
|
710 |
/** |
/** |
711 |
* 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 |
712 |
* of the button is not affected. |
* of the button is not affected. |
781 |
* is {@code false} |
* is {@code false} |
782 |
*/ |
*/ |
783 |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
784 |
for (int tool : toolAndActionButtons.keySet()) |
for (int id : toolAndActionButtons.keySet()) { |
785 |
setButtonEnabled(tool, enabled, hideOnDisable); |
if (toolAndActionButtons.get(id) instanceof JToggleButton) { |
786 |
|
setButtonEnabled(id, enabled, hideOnDisable); |
787 |
|
} |
788 |
|
} |
789 |
} |
} |
790 |
|
|
791 |
/** |
/** |
792 |
* Sets the activation for all actions. |
* Sets the activation for all actions. |
793 |
* |
* |
879 |
*/ |
*/ |
880 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
881 |
String name, Icon icon) { |
String name, Icon icon) { |
882 |
this (id, toolBar, name, icon, null); |
this(id, toolBar, name, icon, null); |
883 |
} |
} |
884 |
|
|
885 |
/** |
/** |
886 |
* Creates a new action. |
* Creates a new action. |
887 |
* |
* |
899 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
900 |
String name, Icon icon, String toolTip) { |
String name, Icon icon, String toolTip) { |
901 |
super(name, icon); |
super(name, icon); |
902 |
|
|
903 |
if (toolTip != null && !toolTip.trim().isEmpty()){ |
if (toolTip != null && !toolTip.trim().isEmpty()) { |
904 |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
905 |
} |
} |
906 |
|
|
907 |
this.id = id; |
this.id = id; |
908 |
this.toolBar = toolBar; |
this.toolBar = toolBar; |
909 |
} |
} |
910 |
|
|
911 |
|
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) { |
912 |
|
this(id, toolBar, "", tool.getIcon(), tool.getToolTip()); |
913 |
|
} |
914 |
|
|
915 |
/** |
/** |
916 |
* Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
* Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
917 |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} |
935 |
return id; |
return id; |
936 |
} |
} |
937 |
} |
} |
938 |
|
|
939 |
/** |
/** |
940 |
* 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 |
941 |
* Hintergrund auf WEISS gesetzt. |
* wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
942 |
* |
* |
943 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
944 |
* Krüger</a> |
* Krüger</a> |
945 |
*/ |
*/ |
946 |
@Override |
@Override |
947 |
public void print(Graphics g) { |
public void print(Graphics g) { |
948 |
Color orig = getBackground(); |
Color orig = getBackground(); |
949 |
setBackground(Color.WHITE); |
setBackground(Color.WHITE); |
950 |
// wrap in try/finally so that we always restore the state |
// wrap in try/finally so that we always restore the state |
951 |
try { |
try { |
952 |
super.print(g); |
super.print(g); |
953 |
} finally { |
} finally { |
954 |
setBackground(orig); |
setBackground(orig); |
955 |
} |
} |
956 |
} |
} |
957 |
|
|
958 |
} |
} |