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.map.event.MapPaneEvent; |
57 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
58 |
import schmitzm.geotools.map.event.MapAreaChangedEvent; |
import schmitzm.geotools.map.event.MapAreaChangedEvent; |
59 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
60 |
import schmitzm.lang.ResourceProvider; |
import schmitzm.lang.ResourceProvider; |
61 |
import schmitzm.swing.ButtonGroup; |
import schmitzm.swing.ButtonGroup; |
62 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
63 |
|
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 |
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 = new ResourceProvider(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 |
} |
} |
140 |
// /** Holds the action buttons of the bar. */ |
// /** Holds the action buttons of the bar. */ |
141 |
// protected SortedMap<Integer, JButton> actionButtons = null; |
// protected SortedMap<Integer, JButton> actionButtons = null; |
142 |
|
|
143 |
/** Holds the {@link JMapPane} this tool bar controls. */ |
/** Holds the {@link SelectableXMapPane} this tool bar controls. */ |
144 |
protected JMapPane mapPane = null; |
protected SelectableXMapPane mapPane = null; |
145 |
|
|
146 |
/** |
/** |
147 |
* 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 |
159 |
/** 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 **/ |
160 |
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>(); |
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>(); |
161 |
|
|
162 |
/** This listener is added to all {@link JToggleButton} **/ |
/** This listener is added to all {@link JToggleButton} **/ |
163 |
private final ActionListener toolSelectedListener = new ActionListener(){ |
private final ActionListener toolSelectedListener = new ActionListener() { |
164 |
|
|
165 |
@Override |
@Override |
166 |
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
167 |
JToggleButton tb = (JToggleButton) e.getSource(); |
JToggleButton tb = (JToggleButton) e.getSource(); |
168 |
|
|
169 |
// Inform the listeners about a newly selected tool |
// Inform the listeners about a newly selected tool |
170 |
for (MapPaneToolSelectedListener l : toolSelectionListeners) { |
for (MapPaneToolSelectedListener l : toolSelectionListeners) { |
171 |
l.toolSelected(Integer.valueOf( tb.getName() ) ) ; |
l.toolSelected(Integer.valueOf(tb.getName())); |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
175 |
}; |
}; |
176 |
|
|
177 |
/** |
/** |
178 |
* Creates a new toolbar. Notice: This toolbar does nothing until |
* Creates a new toolbar. Notice: This toolbar does nothing until |
179 |
* {@link #setMapPane(JMapPane)} is called! |
* {@link #setMapPane(SelectableXMapPane)} is called! |
180 |
*/ |
*/ |
181 |
public MapPaneToolBar() { |
public MapPaneToolBar() { |
182 |
this(null); |
this(null); |
183 |
} |
} |
184 |
|
|
185 |
public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) { |
public void addButtonSelectedListener(MapPaneToolSelectedListener listener) { |
186 |
toolSelectionListeners.add(listener); |
toolSelectionListeners.add(listener); |
187 |
} |
} |
188 |
|
|
189 |
public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) { |
public void removeButtonSelectedListener( |
190 |
toolSelectionListeners .remove(listener); |
MapPaneToolSelectedListener listener) { |
191 |
|
toolSelectionListeners.remove(listener); |
192 |
} |
} |
193 |
|
|
194 |
/** |
/** |
195 |
* Creates a new tool bar. |
* Creates a new tool bar. |
196 |
* |
* |
197 |
* @param mapPane |
* @param mapPane |
198 |
* {@link JMapPane} the tool bar controls |
* {@link SelectableXMapPane} the tool bar controls |
199 |
*/ |
*/ |
200 |
public MapPaneToolBar(JMapPane mapPane) { |
public MapPaneToolBar(SelectableXMapPane mapPane) { |
201 |
super("Control the map", JToolBar.HORIZONTAL); |
super("Control the map", JToolBar.HORIZONTAL); |
202 |
|
|
203 |
// I want to see nothing on the background |
// I want to see nothing on the background |
204 |
setOpaque(false); |
setOpaque(false); |
205 |
setBorder(null); |
setBorder(null); |
206 |
|
|
207 |
this.toolButtonGroup = new ButtonGroup(); |
this.toolButtonGroup = new ButtonGroup(); |
208 |
|
|
209 |
// Create a Listener to listen to the zooms on the JMapPane |
// Create a Listener to listen to the zooms on the JMapPane |
210 |
this.mapPaneListener = new JMapPaneListener() { |
this.mapPaneListener = new JMapPaneListener() { |
211 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(MapPaneEvent e) { |
212 |
if (!(e instanceof MapAreaChangedEvent)) |
if (!(e instanceof MapAreaChangedEvent)) |
213 |
return; |
return; |
214 |
|
|
219 |
|
|
220 |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
221 |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
222 |
|
|
223 |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
224 |
if (mapArea == null || mapArea.equals(oldMapArea) ) { |
if (mapArea == null || mapArea.equals(oldMapArea) |
225 |
// If the MapArea didn't change... we don't want to register it as a zoom action. |
|| Double.isNaN(mapArea.getMinX()) |
226 |
|
|| Double.isNaN(mapArea.getMaxX()) |
227 |
|
|| Double.isNaN(mapArea.getMinY()) |
228 |
|
|| Double.isNaN(mapArea.getMaxY())) { |
229 |
|
// If the MapArea didn't change... we don't want to register |
230 |
|
// it as a zoom action. |
231 |
return; |
return; |
232 |
} |
} |
233 |
|
|
234 |
if (lastZooms.size() == 0 && oldMapArea != null) { |
if (lastZooms.size() == 0 |
235 |
|
&& oldMapArea != null |
236 |
|
&& !oldMapArea.isNull() |
237 |
|
&& !(Double.isNaN(oldMapArea.getMinX()) |
238 |
|
|| Double.isNaN(oldMapArea.getMaxX()) |
239 |
|
|| Double.isNaN(oldMapArea.getMinY()) || Double |
240 |
|
.isNaN(oldMapArea.getMaxY()))) { |
241 |
lastZooms.add(oldMapArea); |
lastZooms.add(oldMapArea); |
242 |
zoomBackIndex = 1; |
zoomBackIndex = 1; |
243 |
} |
} |
269 |
} |
} |
270 |
|
|
271 |
/** |
/** |
272 |
* Sets the {@link JMapPane} controlled by this tool bar. |
* Sets the {@link SelectableXMapPane} controlled by this tool bar. |
273 |
* |
* |
274 |
* @param mapPane |
* @param mapPane |
275 |
* {@link JMapPane} to control (if {@code null} this tool bar |
* {@link SelectableXMapPane} to control (if {@code null} this tool bar |
276 |
* controls NOTHING!) |
* controls NOTHING!) |
277 |
*/ |
*/ |
278 |
public void setMapPane(JMapPane mapPane) { |
public void setMapPane(SelectableXMapPane mapPane) { |
279 |
// Remove listener from old MapPane |
// Remove listener from old MapPane |
280 |
if (this.mapPane != null) |
if (this.mapPane != null) |
281 |
this.mapPane.removeMapPaneListener(mapPaneListener); |
this.mapPane.removeMapPaneListener(mapPaneListener); |
289 |
* puts all tool buttons and all actions buttons to the tool bar. |
* puts all tool buttons and all actions buttons to the tool bar. |
290 |
*/ |
*/ |
291 |
protected void init() { |
protected void init() { |
292 |
|
|
293 |
initToolsAndActions(); |
initToolsAndActions(); |
294 |
|
|
295 |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
308 |
protected void initToolsAndActions() { |
protected void initToolsAndActions() { |
309 |
// Panning |
// Panning |
310 |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
311 |
MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false); |
MapView.class.getResource("resource/icons/pan.png")), |
312 |
|
R("MapPaneButtons.Pan.TT")), false); |
313 |
// Info |
// Info |
314 |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
315 |
MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false); |
MapView.class.getResource("resource/icons/info.png")), |
316 |
|
R("MapPaneButtons.Info.TT")), false); |
317 |
|
|
318 |
// Zoom in |
// Zoom in |
319 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
320 |
MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")), |
MapView.class.getResource("resource/icons/zoom_in.png")), |
321 |
false); |
R("MapPaneButtons.ZoomIn.TT")), false); |
322 |
// Zoom out |
// Zoom out |
323 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
324 |
MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")), |
MapView.class.getResource("resource/icons/zoom_out.png")), |
325 |
false); |
R("MapPaneButtons.ZoomOut.TT")), false); |
326 |
|
|
327 |
// Action button to revert the last zoom |
// Action button to revert the last zoom |
328 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
329 |
new ImageIcon(MapView.class |
new ImageIcon(MapView.class |
330 |
.getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false); |
.getResource("resource/icons/zoom_back.png")), |
331 |
|
R("MapPaneButtons.LastZoom.TT")), false); |
332 |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
333 |
|
|
334 |
// Action button to redo the last zoom |
// Action button to redo the last zoom |
335 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
336 |
new ImageIcon(MapView.class |
new ImageIcon(MapView.class |
337 |
.getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")), |
.getResource("resource/icons/zoom_forward.png")), |
338 |
false); |
R("MapPaneButtons.NextZoom.TT")), false); |
339 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
340 |
|
|
341 |
// set the selected tool enabled |
// set the selected tool enabled |
342 |
setSelectedTool(selectedTool); |
setSelectedTool(selectedTool); |
343 |
|
|
344 |
} |
} |
345 |
|
|
346 |
@Override |
@Override |
347 |
public void paint(Graphics g) { |
public void paint(Graphics g) { |
348 |
super.paint(g); |
super.paint(g); |
353 |
* the tool bar. |
* the tool bar. |
354 |
*/ |
*/ |
355 |
public void initToolBar() { |
public void initToolBar() { |
356 |
// setOpaque(true); |
// setOpaque(true); |
357 |
// |
// |
358 |
// setAlignmentY(1f); |
// setAlignmentY(1f); |
359 |
// setAlignmentX(0.5f); |
// setAlignmentX(0.5f); |
360 |
removeAll(); |
removeAll(); |
361 |
|
|
362 |
// // Separator to the left of the tool actions to start |
// // Separator to the left of the tool actions to start |
363 |
// // the tool buttons with the map (not with the coordinate grid) |
// // the tool buttons with the map (not with the coordinate grid) |
364 |
// Dimension dimension = new Dimension(49, 10); |
// Dimension dimension = new Dimension(49, 10); |
365 |
// addSeparator(dimension); |
// addSeparator(dimension); |
366 |
|
|
|
|
|
367 |
// Tool buttons |
// Tool buttons |
368 |
for (Integer bKey : toolAndActionButtons.keySet()) { |
for (Integer bKey : toolAndActionButtons.keySet()) { |
369 |
|
|
370 |
JComponent b = toolAndActionButtons.get(bKey); |
JComponent b = toolAndActionButtons.get(bKey); |
371 |
|
|
372 |
if (b instanceof JToggleButton) { |
if (b instanceof JToggleButton) { |
373 |
JToggleButton tb = (JToggleButton) b; |
JToggleButton tb = (JToggleButton) b; |
374 |
tb.setName(bKey.toString()); |
tb.setName(bKey.toString()); |
375 |
tb.addActionListener( toolSelectedListener ); |
tb.addActionListener(toolSelectedListener); |
376 |
} |
} |
377 |
|
|
378 |
add(b); |
add(b); |
379 |
} |
} |
380 |
|
|
394 |
} |
} |
395 |
|
|
396 |
} |
} |
397 |
|
|
398 |
revalidate(); |
revalidate(); |
399 |
repaint(); |
repaint(); |
400 |
} |
} |
426 |
switch (tool) { |
switch (tool) { |
427 |
case TOOL_PAN: |
case TOOL_PAN: |
428 |
// Set the mouse tool to "Panning" |
// Set the mouse tool to "Panning" |
429 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setState(SelectableXMapPane.PAN); |
430 |
mapPane.setState(JMapPane.PAN); |
// mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
|
mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
|
431 |
break; |
break; |
432 |
case TOOL_INFO: |
case TOOL_INFO: |
433 |
// Set the mouse tool to "Info" |
// Set the mouse tool to "Info" |
434 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP); |
435 |
mapPane.setState(JMapPane.SELECT_TOP); // Why not: |
// mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
|
// JMapPane.SELECT_TOP_ONEONLY |
|
|
// properly removed it to save |
|
|
// performance |
|
|
mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
|
436 |
break; |
break; |
437 |
case TOOL_ZOOMIN: |
case TOOL_ZOOMIN: |
438 |
// Set the mouse tool to "Zoom in" |
// Set the mouse tool to "Zoom in" |
439 |
mapPane.setWindowSelectionState(JMapPane.ZOOM_IN); |
mapPane.setState(SelectableXMapPane.ZOOM_IN); |
440 |
mapPane.setState(JMapPane.ZOOM_IN); |
// mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
|
mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
|
441 |
break; |
break; |
442 |
case TOOL_ZOOMOUT: |
case TOOL_ZOOMOUT: |
443 |
// Set the mouse tool to "Zoom out" |
// Set the mouse tool to "Zoom out" |
444 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setState(SelectableXMapPane.ZOOM_OUT); |
445 |
mapPane.setState(JMapPane.ZOOM_OUT); |
// mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
|
mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
|
446 |
break; |
break; |
447 |
default: |
default: |
448 |
// Set map actions to default |
// Set map actions to default |
449 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setState(SelectableXMapPane.NONE); |
450 |
mapPane.setState(JMapPane.NONE); |
// mapPane.setNormalCursor(null); |
|
mapPane.setNormalCursor(null); |
|
451 |
break; |
break; |
452 |
} |
} |
453 |
mapPane.updateCursor(); |
// mapPane.updateCursorAndRepaintTimer(); |
454 |
} |
} |
455 |
|
|
456 |
/** |
/** |
522 |
+ buttonAction.getID()); |
+ buttonAction.getID()); |
523 |
return; |
return; |
524 |
} |
} |
525 |
JToggleButton button = new JToggleButton(buttonAction); |
JToggleButton button = new SmallToggleButton(buttonAction); |
526 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
|
527 |
|
// button.setBorder(BorderFactory.createRaisedBevelBorder()); |
528 |
toolButtonGroup.add(button); |
toolButtonGroup.add(button); |
529 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
530 |
if (resetToolBar) |
if (resetToolBar) |
531 |
initToolBar(); |
initToolBar(); |
532 |
} |
} |
533 |
|
|
|
|
|
|
|
|
534 |
/** |
/** |
535 |
* Adds a tool to the tool bar and resets the toolbar GUI. |
* Adds a tool to the tool bar and resets the toolbar GUI. |
536 |
* |
* |
560 |
+ buttonAction.getID()); |
+ buttonAction.getID()); |
561 |
return; |
return; |
562 |
} |
} |
563 |
JButton button = new JButton(buttonAction); |
JButton button = new SmallButton(buttonAction); |
564 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
// button.setBorder(BorderFactory.createRaisedBevelBorder()); |
565 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
566 |
if (resetToolBar) |
if (resetToolBar) |
567 |
initToolBar(); |
initToolBar(); |
568 |
} |
} |
569 |
|
|
570 |
/** |
/** |
571 |
* 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 |
572 |
* specified ID already exists! |
* with the specified ID already exists! |
573 |
* |
* |
574 |
* @param component A {@link JComponent} that shall be added |
* @param component |
575 |
* @param id The ID associaded with the {@link JComponent} |
* A {@link JComponent} that shall be added |
576 |
|
* @param id |
577 |
|
* The ID associaded with the {@link JComponent} |
578 |
* @param resetToolBar |
* @param resetToolBar |
579 |
* indicates whether the toolbar GUI is reset after adding the |
* indicates whether the toolbar GUI is reset after adding the |
580 |
* button (if adding several actions it useful only to reset the |
* button (if adding several actions it useful only to reset the |
581 |
* GUI for the last added tool) |
* GUI for the last added tool) |
582 |
*/ |
*/ |
583 |
public void addJComponent(JComponent component, int id, |
public void addJComponent(JComponent component, int id, boolean resetToolBar) { |
|
boolean resetToolBar) { |
|
584 |
|
|
585 |
if (isButtonIDUsed(id)) { |
if (isButtonIDUsed(id)) { |
586 |
LOGGER |
LOGGER |
587 |
.warn("addAction(.) ignored because ID already used for tool or action: " |
.warn("addAction(.) ignored because ID already used for tool or action: " |
588 |
+ id); |
+ id); |
589 |
return; |
return; |
590 |
} |
} |
591 |
|
|
592 |
toolAndActionButtons.put(id, component); |
toolAndActionButtons.put(id, component); |
593 |
if (resetToolBar) |
if (resetToolBar) |
594 |
initToolBar(); |
initToolBar(); |
860 |
*/ |
*/ |
861 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
862 |
String name, Icon icon) { |
String name, Icon icon) { |
863 |
this (id, toolBar, name, icon, null); |
this(id, toolBar, name, icon, null); |
864 |
} |
} |
865 |
|
|
866 |
/** |
/** |
867 |
* Creates a new action. |
* Creates a new action. |
868 |
* |
* |
880 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
881 |
String name, Icon icon, String toolTip) { |
String name, Icon icon, String toolTip) { |
882 |
super(name, icon); |
super(name, icon); |
883 |
|
|
884 |
if (toolTip != null && !toolTip.trim().isEmpty()){ |
if (toolTip != null && !toolTip.trim().isEmpty()) { |
885 |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
886 |
} |
} |
887 |
|
|
888 |
this.id = id; |
this.id = id; |
889 |
this.toolBar = toolBar; |
this.toolBar = toolBar; |
890 |
} |
} |
912 |
return id; |
return id; |
913 |
} |
} |
914 |
} |
} |
915 |
|
|
916 |
/** |
/** |
917 |
* 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 |
918 |
* Hintergrund auf WEISS gesetzt. |
* wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
919 |
* |
* |
920 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
921 |
* Krüger</a> |
* Krüger</a> |
922 |
*/ |
*/ |
923 |
@Override |
@Override |
924 |
public void print(Graphics g) { |
public void print(Graphics g) { |
925 |
Color orig = getBackground(); |
Color orig = getBackground(); |
926 |
setBackground(Color.WHITE); |
setBackground(Color.WHITE); |
927 |
// wrap in try/finally so that we always restore the state |
// wrap in try/finally so that we always restore the state |
928 |
try { |
try { |
929 |
super.print(g); |
super.print(g); |
930 |
} finally { |
} finally { |
931 |
setBackground(orig); |
setBackground(orig); |
932 |
} |
} |
933 |
} |
} |
934 |
|
|
935 |
} |
} |