[Schmitzm-commits] r445 - in branches/1.0-gt2-2.6/src: gtmig/org/geotools/swing skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Oct 7 15:17:04 CEST 2009
Author: alfonx
Date: 2009-10-07 15:17:02 +0200 (Wed, 07 Oct 2009)
New Revision: 445
Modified:
branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java
Log:
* GP: * Do not allow NaN values in zoom back/forward Envelopes
* Extra check against unlimited while loop in JMapPane.bestAllowedMapArea
Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java 2009-10-07 12:31:27 UTC (rev 444)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java 2009-10-07 13:17:02 UTC (rev 445)
@@ -956,7 +956,7 @@
}
Envelope maxAllowedExtend = getMaxExtend();
- while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) {
+ while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) && newArea != null && !newArea.isNull() && !Double.isNaN(newArea.getMinX()) && !Double.isNaN(newArea.getMaxX()) && !Double.isNaN(newArea.getMinY()) && !Double.isNaN(newArea.getMaxY()) ) {
/*
* If a maxExtend is set, we have to honour that...
*/
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java 2009-10-07 12:31:27 UTC (rev 444)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java 2009-10-07 13:17:02 UTC (rev 445)
@@ -78,11 +78,11 @@
public class MapPaneToolBar extends JToolBar {
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
.getName());
-
+
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
.extendPackagePath(MapPaneToolBar.class,
"resource.locales.mapPaneToolbar"), Locale.ENGLISH);
-
+
public static String R(String key, Object... values) {
return RESOURCE.getString(key, values);
}
@@ -158,19 +158,19 @@
/** Listeners what want to be informed about a change of the selected tool **/
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
- /** This listener is added to all {@link JToggleButton} **/
- private final ActionListener toolSelectedListener = new ActionListener(){
+ /** This listener is added to all {@link JToggleButton} **/
+ private final ActionListener toolSelectedListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JToggleButton tb = (JToggleButton) e.getSource();
-
+
// Inform the listeners about a newly selected tool
for (MapPaneToolSelectedListener l : toolSelectionListeners) {
- l.toolSelected(Integer.valueOf( tb.getName() ) ) ;
+ l.toolSelected(Integer.valueOf(tb.getName()));
}
}
-
+
};
/**
@@ -180,13 +180,14 @@
public MapPaneToolBar() {
this(null);
}
-
- public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) {
+
+ public void addButtonSelectedListener(MapPaneToolSelectedListener listener) {
toolSelectionListeners.add(listener);
}
- public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) {
- toolSelectionListeners .remove(listener);
+ public void removeButtonSelectedListener(
+ MapPaneToolSelectedListener listener) {
+ toolSelectionListeners.remove(listener);
}
/**
@@ -197,13 +198,13 @@
*/
public MapPaneToolBar(JMapPane mapPane) {
super("Control the map", JToolBar.HORIZONTAL);
-
- // I want to see nothing on the background
+
+ // I want to see nothing on the background
setOpaque(false);
setBorder(null);
-
+
this.toolButtonGroup = new ButtonGroup();
-
+
// Create a Listener to listen to the zooms on the JMapPane
this.mapPaneListener = new JMapPaneListener() {
public void performMapPaneEvent(JMapPaneEvent e) {
@@ -217,14 +218,25 @@
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
-
+
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
- if (mapArea == null || mapArea.equals(oldMapArea) ) {
- // If the MapArea didn't change... we don't want to register it as a zoom action.
+ if (mapArea == null || mapArea.equals(oldMapArea)
+ || Double.isNaN(mapArea.getMinX())
+ || Double.isNaN(mapArea.getMaxX())
+ || Double.isNaN(mapArea.getMinY())
+ || Double.isNaN(mapArea.getMaxY())) {
+ // If the MapArea didn't change... we don't want to register
+ // it as a zoom action.
return;
}
-
- if (lastZooms.size() == 0 && oldMapArea != null) {
+
+ if (lastZooms.size() == 0
+ && oldMapArea != null
+ && !oldMapArea.isNull()
+ && !(Double.isNaN(oldMapArea.getMinX())
+ || Double.isNaN(oldMapArea.getMaxX())
+ || Double.isNaN(oldMapArea.getMinY()) || Double
+ .isNaN(oldMapArea.getMaxY()))) {
lastZooms.add(oldMapArea);
zoomBackIndex = 1;
}
@@ -276,7 +288,7 @@
* puts all tool buttons and all actions buttons to the tool bar.
*/
protected void init() {
-
+
initToolsAndActions();
addSeparator(SEPERATOR0, new JToolBar.Separator());
@@ -295,38 +307,41 @@
protected void initToolsAndActions() {
// Panning
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
- MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);
+ MapView.class.getResource("resource/icons/pan.png")),
+ R("MapPaneButtons.Pan.TT")), false);
// Info
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
- MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);
+ MapView.class.getResource("resource/icons/info.png")),
+ R("MapPaneButtons.Info.TT")), false);
// Zoom in
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
- MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),
- false);
+ MapView.class.getResource("resource/icons/zoom_in.png")),
+ R("MapPaneButtons.ZoomIn.TT")), false);
// Zoom out
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
- MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),
- false);
+ MapView.class.getResource("resource/icons/zoom_out.png")),
+ R("MapPaneButtons.ZoomOut.TT")), false);
// Action button to revert the last zoom
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
new ImageIcon(MapView.class
- .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);
+ .getResource("resource/icons/zoom_back.png")),
+ R("MapPaneButtons.LastZoom.TT")), false);
setButtonEnabled(ACTION_ZOOM_BACK, false);
// Action button to redo the last zoom
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
new ImageIcon(MapView.class
- .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),
- false);
+ .getResource("resource/icons/zoom_forward.png")),
+ R("MapPaneButtons.NextZoom.TT")), false);
setButtonEnabled(ACTION_ZOOM_FORWARD, false);
// set the selected tool enabled
setSelectedTool(selectedTool);
}
-
+
@Override
public void paint(Graphics g) {
super.paint(g);
@@ -337,29 +352,28 @@
* the tool bar.
*/
public void initToolBar() {
-// setOpaque(true);
-//
-// setAlignmentY(1f);
-// setAlignmentX(0.5f);
+ // setOpaque(true);
+ //
+ // setAlignmentY(1f);
+ // setAlignmentX(0.5f);
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);
-
-
+
+ // // 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 (Integer bKey : toolAndActionButtons.keySet()) {
-
+
JComponent b = toolAndActionButtons.get(bKey);
-
+
if (b instanceof JToggleButton) {
JToggleButton tb = (JToggleButton) b;
tb.setName(bKey.toString());
- tb.addActionListener( toolSelectedListener );
+ tb.addActionListener(toolSelectedListener);
}
-
+
add(b);
}
@@ -379,7 +393,7 @@
}
}
-
+
revalidate();
repaint();
}
@@ -523,8 +537,6 @@
initToolBar();
}
-
-
/**
* Adds a tool to the tool bar and resets the toolbar GUI.
*
@@ -560,28 +572,29 @@
if (resetToolBar)
initToolBar();
}
-
+
/**
- * Adds any JComponent to the tool bar. Does nothing if a tool or action with the
- * specified ID already exists!
+ * Adds any JComponent to the tool bar. Does nothing if a tool or action
+ * with the specified ID already exists!
*
- * @param component A {@link JComponent} that shall be added
- * @param id The ID associaded with the {@link JComponent}
+ * @param component
+ * A {@link JComponent} that shall be added
+ * @param id
+ * The ID associaded with the {@link JComponent}
* @param resetToolBar
* indicates whether the toolbar GUI is reset after adding the
* button (if adding several actions it useful only to reset the
* GUI for the last added tool)
*/
- public void addJComponent(JComponent component, int id,
- boolean resetToolBar) {
+ public void addJComponent(JComponent component, int id, boolean resetToolBar) {
if (isButtonIDUsed(id)) {
LOGGER
- .warn("addAction(.) ignored because ID already used for tool or action: "
- + id);
+ .warn("addAction(.) ignored because ID already used for tool or action: "
+ + id);
return;
}
-
+
toolAndActionButtons.put(id, component);
if (resetToolBar)
initToolBar();
@@ -853,9 +866,9 @@
*/
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
String name, Icon icon) {
- this (id, toolBar, name, icon, null);
+ this(id, toolBar, name, icon, null);
}
-
+
/**
* Creates a new action.
*
@@ -873,11 +886,11 @@
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
String name, Icon icon, String toolTip) {
super(name, icon);
-
- if (toolTip != null && !toolTip.trim().isEmpty()){
+
+ if (toolTip != null && !toolTip.trim().isEmpty()) {
putValue(Action.SHORT_DESCRIPTION, toolTip);
}
-
+
this.id = id;
this.toolBar = toolBar;
}
@@ -905,24 +918,24 @@
return id;
}
}
-
- /**
- * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der
- * Hintergrund auf WEISS gesetzt.
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Krüger</a>
- */
- @Override
- public void print(Graphics g) {
- Color orig = getBackground();
- setBackground(Color.WHITE);
- // wrap in try/finally so that we always restore the state
- try {
- super.print(g);
- } finally {
- setBackground(orig);
- }
- }
+ /**
+ * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
+ * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
+ */
+ @Override
+ public void print(Graphics g) {
+ Color orig = getBackground();
+ setBackground(Color.WHITE);
+ // wrap in try/finally so that we always restore the state
+ try {
+ super.print(g);
+ } finally {
+ setBackground(orig);
+ }
+ }
+
}
More information about the Schmitzm-commits
mailing list