64 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
65 |
|
|
66 |
/** |
/** |
67 |
* A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains |
* A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). |
68 |
* two types of buttons. A group of <i>tools</i> for the mouse actions on the |
* This contains two types of buttons. A group of <i>tools</i> for the mouse |
69 |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
* actions on the map represented by {@link JToggleButton JToggleButtons}, where |
70 |
* can be activated every time. And some (general) <i>actions</i>, represented |
* only one tool can be activated every time. And some (general) <i>actions</i>, |
71 |
* by normal {@link JButton JButtons}. |
* represented by normal {@link JButton JButtons}. |
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) |
168 |
} |
} |
169 |
|
|
170 |
}; |
}; |
171 |
|
private CrsLabel crsViewer; |
172 |
|
|
173 |
/** |
/** |
174 |
* Creates a new toolbar. Notice: This toolbar does nothing until |
* Creates a new toolbar. Notice: This toolbar does nothing until |
205 |
// Create a Listener to listen to the zooms on the JMapPane |
// Create a Listener to listen to the zooms on the JMapPane |
206 |
this.mapPaneListener = new JMapPaneListener() { |
this.mapPaneListener = new JMapPaneListener() { |
207 |
public void performMapPaneEvent(XMapPaneEvent e) { |
public void performMapPaneEvent(XMapPaneEvent e) { |
208 |
|
|
209 |
if (!(e instanceof MapAreaChangedEvent)) |
if (!(e instanceof MapAreaChangedEvent)) |
210 |
return; |
return; |
211 |
|
|
256 |
setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1); |
setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1); |
257 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
258 |
} |
} |
259 |
|
|
260 |
}; |
}; |
261 |
|
|
262 |
setMapPane(mapPane); |
setMapPane(mapPane); |
266 |
init(); |
init(); |
267 |
} |
} |
268 |
|
|
269 |
|
private CrsLabel getCrsComponent() { |
270 |
|
if (crsViewer == null) { |
271 |
|
crsViewer = new CrsLabel(this.mapPane); |
272 |
|
} |
273 |
|
return crsViewer; |
274 |
|
} |
275 |
|
|
276 |
/** |
/** |
277 |
* Sets the {@link SelectableXMapPane} controlled by this tool bar. |
* Sets the {@link SelectableXMapPane} controlled by this tool bar. |
278 |
* |
* |
279 |
* @param mapPane |
* @param mapPane |
280 |
* {@link SelectableXMapPane} to control (if {@code null} this tool bar |
* {@link SelectableXMapPane} to control (if {@code null} this |
281 |
* controls NOTHING!) |
* tool bar controls NOTHING!) |
282 |
*/ |
*/ |
283 |
public void setMapPane(SelectableXMapPane mapPane) { |
public void setMapPane(SelectableXMapPane mapPane) { |
284 |
// Remove listener from old MapPane |
// Remove listener from old MapPane |
307 |
* Creates the tool buttons and action buttons and seperators, adds them to |
* Creates the tool buttons and action buttons and seperators, adds them to |
308 |
* {@link #toolAndActionButtons} and finally creates a button group for all |
* {@link #toolAndActionButtons} and finally creates a button group for all |
309 |
* tools. So sub-classes which override this method should FIRST add their |
* tools. So sub-classes which override this method should FIRST add their |
310 |
* new tool buttons to {@link #toolAndActionButtons} before calling {@code |
* new tool buttons to {@link #toolAndActionButtons} before calling |
311 |
* super.initTools()}. |
* {@code super.initTools()}. |
312 |
*/ |
*/ |
313 |
protected void initToolsAndActions() { |
protected void initToolsAndActions() { |
314 |
// Pan |
// Pan |
315 |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false); |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), |
316 |
|
false); |
317 |
|
|
318 |
// Info |
// Info |
319 |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false); |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), |
320 |
|
false); |
321 |
|
|
322 |
// Zoom in |
// Zoom in |
323 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false); |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, |
324 |
|
XMapPaneTool.ZOOM_IN), false); |
325 |
|
|
326 |
// Zoom out |
// Zoom out |
327 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false); |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, |
328 |
|
XMapPaneTool.ZOOM_OUT), false); |
329 |
|
|
330 |
// Action button to revert the last zoom |
// Action button to revert the last zoom |
331 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
addAction( |
332 |
new ImageIcon(MapView.class |
new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
333 |
.getResource("resource/icons/zoom_back.png")), |
new ImageIcon(MapView.class |
334 |
R("MapPaneButtons.LastZoom.TT")), false); |
.getResource("resource/icons/zoom_back.png")), |
335 |
|
R("MapPaneButtons.LastZoom.TT")), false); |
336 |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
337 |
|
|
338 |
// Action button to redo the last zoom |
// Action button to redo the last zoom |
339 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
addAction( |
340 |
new ImageIcon(MapView.class |
new MapPaneToolBarAction( |
341 |
.getResource("resource/icons/zoom_forward.png")), |
ACTION_ZOOM_FORWARD, |
342 |
R("MapPaneButtons.NextZoom.TT")), false); |
this, |
343 |
|
"", |
344 |
|
new ImageIcon(MapView.class |
345 |
|
.getResource("resource/icons/zoom_forward.png")), |
346 |
|
R("MapPaneButtons.NextZoom.TT")), false); |
347 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
348 |
|
|
349 |
// set the selected tool enabled |
// set the selected tool enabled |
350 |
setSelectedTool(selectedTool); |
setSelectedTool(selectedTool); |
351 |
|
|
352 |
|
add(getCrsComponent()); |
353 |
|
|
354 |
} |
} |
355 |
|
|
356 |
@Override |
@Override |
456 |
protected void performActionButton(int action, ActionEvent e) { |
protected void performActionButton(int action, ActionEvent e) { |
457 |
if (mapPane == null) |
if (mapPane == null) |
458 |
return; |
return; |
459 |
|
|
460 |
// Perform the action "Zoom back": Revert the last zoom |
// Perform the action "Zoom back": Revert the last zoom |
461 |
if (action == ACTION_ZOOM_BACK) { |
if (action == ACTION_ZOOM_BACK) { |
462 |
if (zoomBackIndex <= 1) |
if (zoomBackIndex <= 1) |
499 |
*/ |
*/ |
500 |
public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) { |
public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) { |
501 |
if (isButtonIDUsed(buttonAction.getID())) { |
if (isButtonIDUsed(buttonAction.getID())) { |
502 |
LOGGER |
LOGGER.warn("addTool(.) ignored because ID already used for tool or action: " |
503 |
.warn("addTool(.) ignored because ID already used for tool or action: " |
+ buttonAction.getID()); |
|
+ buttonAction.getID()); |
|
504 |
return; |
return; |
505 |
} |
} |
506 |
JToggleButton button = new SmallToggleButton(buttonAction); |
JToggleButton button = new SmallToggleButton(buttonAction); |
507 |
|
|
508 |
toolButtonGroup.add(button); |
toolButtonGroup.add(button); |
509 |
toolAndActionButtons.put(buttonAction.getID(), button); |
toolAndActionButtons.put(buttonAction.getID(), button); |
510 |
if (resetToolBar) |
if (resetToolBar) |
535 |
public void addAction(MapPaneToolBarAction buttonAction, |
public void addAction(MapPaneToolBarAction buttonAction, |
536 |
boolean resetToolBar) { |
boolean resetToolBar) { |
537 |
if (isButtonIDUsed(buttonAction.getID())) { |
if (isButtonIDUsed(buttonAction.getID())) { |
538 |
LOGGER |
LOGGER.warn("addAction(.) ignored because ID already used for tool or action: " |
539 |
.warn("addAction(.) ignored because ID already used for tool or action: " |
+ buttonAction.getID()); |
|
+ buttonAction.getID()); |
|
540 |
return; |
return; |
541 |
} |
} |
542 |
JButton button = new SmallButton(buttonAction); |
JButton button = new SmallButton(buttonAction); |
561 |
public void addJComponent(JComponent component, int id, boolean resetToolBar) { |
public void addJComponent(JComponent component, int id, boolean resetToolBar) { |
562 |
|
|
563 |
if (isButtonIDUsed(id)) { |
if (isButtonIDUsed(id)) { |
564 |
LOGGER |
LOGGER.warn("addAction(.) ignored because ID already used for tool or action: " |
565 |
.warn("addAction(.) ignored because ID already used for tool or action: " |
+ id); |
|
+ id); |
|
566 |
return; |
return; |
567 |
} |
} |
568 |
|
|
573 |
|
|
574 |
public void addSeparator(int id, Separator separator) { |
public void addSeparator(int id, Separator separator) { |
575 |
if (isButtonIDUsed(id)) { |
if (isButtonIDUsed(id)) { |
576 |
LOGGER |
LOGGER.warn("addSeparator(.) ignored because ID already used for tool or action. "); |
|
.warn("addSeparator(.) ignored because ID already used for tool or action. "); |
|
577 |
return; |
return; |
578 |
} |
} |
579 |
toolAndActionButtons.put(id, separator); |
toolAndActionButtons.put(id, separator); |
600 |
* {@linkplain #getToolButton(int) tool button} |
* {@linkplain #getToolButton(int) tool button} |
601 |
*/ |
*/ |
602 |
public AbstractButton getButton(int id) { |
public AbstractButton getButton(int id) { |
603 |
|
|
604 |
//ACHUTNG: Das ist ein SK QUICK FIX! TODO |
// ACHUTNG: Das ist ein SK QUICK FIX! TODO |
605 |
if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null; |
if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) |
606 |
|
return null; |
607 |
|
|
608 |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
609 |
if (button == null) |
if (button == null) |
610 |
LOGGER.warn("Unknown tool or action ID: " + id); |
LOGGER.warn("Unknown tool or action ID: " + id); |
671 |
return -1; |
return -1; |
672 |
return selectedTool; |
return selectedTool; |
673 |
} |
} |
674 |
|
|
675 |
/** |
/** |
676 |
* 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 |
677 |
* of the button is not affected. |
* of the button is not affected. |
748 |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
749 |
for (int id : toolAndActionButtons.keySet()) { |
for (int id : toolAndActionButtons.keySet()) { |
750 |
if (toolAndActionButtons.get(id) instanceof JToggleButton) { |
if (toolAndActionButtons.get(id) instanceof JToggleButton) { |
751 |
setButtonEnabled(id, enabled, hideOnDisable); |
setButtonEnabled(id, enabled, hideOnDisable); |
752 |
} |
} |
753 |
} |
} |
754 |
} |
} |
755 |
|
|
756 |
/** |
/** |
757 |
* Sets the activation for all actions. |
* Sets the activation for all actions. |
758 |
* |
* |
873 |
this.toolBar = toolBar; |
this.toolBar = toolBar; |
874 |
} |
} |
875 |
|
|
876 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) { |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
877 |
|
XMapPaneTool tool) { |
878 |
this(id, toolBar, "", tool.getIcon(), tool.getToolTip()); |
this(id, toolBar, "", tool.getIcon(), tool.getToolTip()); |
879 |
} |
} |
880 |
|
|
906 |
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht |
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht |
907 |
* wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
* wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
908 |
* |
* |
909 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
|
* Tzeggai</a> |
|
910 |
*/ |
*/ |
911 |
@Override |
@Override |
912 |
public void print(Graphics g) { |
public void print(Graphics g) { |
920 |
} |
} |
921 |
} |
} |
922 |
|
|
923 |
|
@Override |
924 |
|
protected void finalize() throws Throwable { |
925 |
|
super.finalize(); |
926 |
|
|
927 |
|
if (mapPane != null && mapPaneListener != null) |
928 |
|
mapPane.removeMapPaneListener(mapPaneListener); |
929 |
|
} |
930 |
|
|
931 |
} |
} |