[Schmitzm-commits] r539 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/gui skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 20 20:10:06 CET 2009
Author: alfonx
Date: 2009-11-20 20:10:05 +0100 (Fri, 20 Nov 2009)
New Revision: 539
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java
branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java
Log:
Last commit before i crack the selection mechanism
* RenderingExceutor will also report Exceptions that crash the Thread
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java 2009-11-20 15:39:55 UTC (rev 538)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java 2009-11-20 19:10:05 UTC (rev 539)
@@ -170,7 +170,7 @@
public SelectableXMapPane(MapContext context) {
this(context, null);
}
-
+
/**
* Erzeugt ein neues MapPane.
*
@@ -191,11 +191,12 @@
public SelectableXMapPane() {
this(null, null);
}
-
+
/**
* This {@link MouseListener} is managing all selection related tasks
*/
- protected final SelectXMapPaneMouseListener selectMapPaneMouseListener = new SelectXMapPaneMouseListener(this);
+ protected final SelectXMapPaneMouseListener selectMapPaneMouseListener = new SelectXMapPaneMouseListener(
+ this);
/**
* Erzeugt ein neues MapPane.
@@ -289,7 +290,7 @@
// }
// });
/**
- * Adding the #selectionMapPaneMouseListener
+ * Adding the #selectionMapPaneMouseListener
*/
this.addMouseListener(selectMapPaneMouseListener);
this.addMouseMotionListener(selectMapPaneMouseListener);
@@ -596,7 +597,8 @@
* Modus fuer Window-Selektion
*/
public void setState(final int state) {
- selectMapPaneMouseListener.setEnabled((state == SELECT_ALL || state == SELECT_ONE_FROM_TOP || state == SELECT_TOP));
+ selectMapPaneMouseListener.setEnabled((state == SELECT_ALL
+ || state == SELECT_ONE_FROM_TOP || state == SELECT_TOP));
super.setState(state);
}
@@ -622,8 +624,7 @@
* @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
* Krüger</a>
*/
- public boolean findGridCoverageValuesAndFireEvents(Point2D point,
- int mode) {
+ public boolean findGridCoverageValuesAndFireEvents(Point2D point, int mode) {
Hashtable<MapLayer, double[]> result = findGridCoverageValues(point,
mode);
@@ -923,11 +924,10 @@
* Y-Koordinate der BIS-Position
*/
public void performSelectionEvent(int ox, int oy, int px, int py) {
-
+
if (getContext().getLayerCount() == 0)
return;
-
// Fenster-Koordinaten in Map-Koordinaten umwandeln
Envelope env = tranformWindowToGeo(ox, oy, px, py);
@@ -936,14 +936,16 @@
int selectState = getState();
switch (selectState) {
- case ZOOM_IN: // Karte neu setzen
- this.setMapArea(env);
- refresh(); // WICHTIG!! Damit die veraenderte Form beruecksichtigt
- // wird!?
- break;
+ // case ZOOM_IN: // Karte neu setzen
+ // LOGGER.error("WHEN IS THIS CALLED?!");
+ // this.setMapArea(env);
+ // refresh(); // WICHTIG!! Damit die veraenderte Form beruecksichtigt
+ // // wird!?
+ // break;
case SELECT_TOP:
case SELECT_ONE_FROM_TOP:
case SELECT_ALL: // Features selektieren
+
boolean featuresFound = findFeaturesAndFireEvents(
new BoundingBoxFilterGenerator(env, getContext()
.getCoordinateReferenceSystem()), selectState, env);
@@ -1093,7 +1095,8 @@
GeomFilterGenerator filterGenerator, int mode, Envelope env) {
Hashtable<MapLayer, FeatureCollection<SimpleFeatureType, SimpleFeature>> result = new Hashtable<MapLayer, FeatureCollection<SimpleFeatureType, SimpleFeature>>();
if (filterGenerator == null)
- throw new IllegalArgumentException("filterGenerator may not be null");
+ throw new IllegalArgumentException(
+ "filterGenerator may not be null");
// Je nach Modus: Alle oder nur das oberste Layer
MapContext context = getContext();
@@ -1178,7 +1181,7 @@
}
return result;
}
-
+
@Override
public void mouseDragged(Point startPos, Point lastPos, MouseEvent event) {
super.mouseDragged(startPos, lastPos, event);
@@ -1214,7 +1217,8 @@
}
/**
- * Prueft, ob es sich bei einem Layer um ein Raster-Layer handelt. VOn SK an eine GT Methode abgegeben.
+ * Prueft, ob es sich bei einem Layer um ein Raster-Layer handelt. VOn SK an
+ * eine GT Methode abgegeben.
*
* @param layer
* zu ueberpruefendes Layer
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java 2009-11-20 15:39:55 UTC (rev 538)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java 2009-11-20 19:10:05 UTC (rev 539)
@@ -77,7 +77,8 @@
public RenderThread(final Rectangle paintArea,
final Graphics2D graphics, GTRenderer renderer,
AffineTransform worldToScreen, ReferencedEnvelope mapEnv) {
- super(new RenderRun(paintArea, graphics, renderer, mapEnv, worldToScreen));
+ super(new RenderRun(paintArea, graphics, renderer, mapEnv,
+ worldToScreen));
this.renderer = renderer;
setName("Render" + getName());
@@ -102,7 +103,8 @@
private final ReferencedEnvelope mapEnv;
public RenderRun(Rectangle paintArea, Graphics2D graphics,
- GTRenderer renderer, ReferencedEnvelope mapEnv, AffineTransform worldToScreen) {
+ GTRenderer renderer, ReferencedEnvelope mapEnv,
+ AffineTransform worldToScreen) {
this.paintArea = paintArea;
this.graphics = graphics;
this.renderer = renderer;
@@ -126,12 +128,14 @@
graphics.clearRect(paintArea.x, paintArea.y, paintArea.width,
paintArea.height);
- renderer.paint(graphics, paintArea, mapEnv, worldToScreen);
+ renderer.paint(graphics, paintArea, worldToScreen);
- // Kill the reference to this Thread to #isRunning will def. say false
+ // Kill the reference to this Thread so #isRunning will say
+ // false directly
renderThread = null;
mapPane.onRenderingCompleted();
-
+ } catch (Exception e) {
+ mapPane.onRenderingFailed(e);
} finally {
renderer.removeRenderListener(this);
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java 2009-11-20 15:39:55 UTC (rev 538)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java 2009-11-20 19:10:05 UTC (rev 539)
@@ -13,6 +13,7 @@
import org.geotools.data.memory.MemoryFeatureCollection;
import org.geotools.feature.FeatureCollection;
import org.geotools.map.MapLayer;
+import org.geotools.swing.tool.VectorLayerHelper;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
@@ -76,6 +77,9 @@
Point2D geoCoord = xMapPane.getScreenToWorld().transform(e.getPoint(),
null);
+
+// new VectorLayerHelper(layer, geomAttributeName, geomClass)
+
com.vividsolutions.jts.geom.Point mousePoint = new GeometryFactory()
.createPoint(new Coordinate(geoCoord.getX(), geoCoord.getY()));
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java 2009-11-20 15:39:55 UTC (rev 538)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java 2009-11-20 19:10:05 UTC (rev 539)
@@ -44,6 +44,7 @@
import org.geotools.renderer.GTRenderer;
import org.geotools.renderer.label.LabelCacheImpl;
import org.geotools.renderer.lite.LabelCache;
+import org.geotools.renderer.lite.RendererUtilities;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.swing.JMapPane;
import org.geotools.swing.event.MapMouseEvent;
@@ -146,7 +147,7 @@
* Default delay (milliseconds) before the map will be redrawn when resizing
* the pane. This is to avoid flickering while drag-resizing.
*/
- public static final int DEFAULT_RESIZING_PAINT_DELAY = 500;
+ public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
public static final int NONE = -123;
@@ -386,6 +387,7 @@
localRenderer.setContext(getContext());
if (localContext.getLayers().length == 1) { // the first one
+
// if the Area of Interest is unset, the LayerBounds are used
if (!setMapArea(localContext.getAreaOfInterest()))
repaint();
@@ -538,8 +540,6 @@
private final Timer resizeTimer;
- private final int resizingPaintDelay;
-
/**
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
* (lat/lon)
@@ -620,8 +620,7 @@
* Using a ComponentListener doesn't work because, unlike a JFrame, the
* pane receives a stream of events during drag-resizing.
*/
- resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY;
- resizeTimer = new Timer(resizingPaintDelay, new ActionListener() {
+ resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() {
public void actionPerformed(final ActionEvent e) {
paneResized = true;
@@ -714,6 +713,7 @@
* Krüger</a>
*/
public Envelope bestAllowedMapArea(Envelope env) {
+ // return env;
if (getWidth() == 0)
return env;
if (env == null)
@@ -921,29 +921,7 @@
}
localExecuter.dispose();
}
- //
- // if (bgImage != null) {
- // bgImage = dispose(bgImage);
- // bgImage = null;
- // // LangUtil.gcTotal();
- // }
- //
- // if (localImage != null) {
- // localImage = dispose(localImage);
- // localImage = null;
- // // LangUtil.gcTotal();
- // }
- //
- // if (finalImage != null) {
- // finalImage = dispose(finalImage);
- // finalImage = null;
- // // LangUtil.gcTotal();
- // }
- //
- // if (preFinalImage != null) {
- // preFinalImage = dispose(preFinalImage);
- // preFinalImage = null;
- // }
+
disposeImages();
// LangUtil.gcTotal();
@@ -1001,6 +979,8 @@
*/
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
+ if (1 == 1)return false;
+
if (quickPreviewHint == 0)
return false;
@@ -1019,7 +999,7 @@
// Calculate the oldMapArea in the current WindowCoordinates:
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea
- .getMaxY(), null);
+ .getMaxY());
final int xx1 = (int) Math.round(oldMapWindow.getMinX());
final int yy1 = (int) Math.round(oldMapWindow.getMinY());
@@ -1124,16 +1104,13 @@
if (mapArea == null)
return null;
+ // TODO is needed at all, this should go to setMapArea maybe
if (localContext.getCoordinateReferenceSystem() == null)
try {
localContext.setCoordinateReferenceSystem(GeoImportUtil
.getDefaultCRS());
- } catch (TransformException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FactoryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (Exception e) {
+ throw new RuntimeException("setting context CRS:", e);
}
return new ReferencedEnvelope(mapArea, localContext
@@ -1610,81 +1587,89 @@
requestStartRendering = true;
}
-//
-// /**
-// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
-// * neu.
-// */
-// protected void resetTransforms() {
-// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
-// return;
-//
-// // We store the last Transform
-// oldScreenToWorld = screenToWorld;
-//
-// this.screenToWorld = new AffineTransform(
-// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
-// // nach rechts (Osten) hin groesser
-// // --> positive Verschiebung
-// getMapArea().getWidth() / getWidth(),
-// // keine Verzerrung
-// 0.0, 0.0,
-// // Waehrend die Fenster-Koordinaten nach unten hin groesser
-// // werden,
-// // werden Latitude-Koordinaten nach Sueden hin keiner
-// // --> negative Verschiebung
-// -getMapArea().getHeight() / getHeight(),
-// // Die Longitude-Koordinaten werden nach Osten hin groesser
-// // --> obere linke Ecke des Fensters hat also den Minimalwert
-// getMapArea().getMinX(),
-// // Die Latitude-Koordinaten werden nach Norden hin groesser
-// // --> obere linke Ecke des Fensters hat also den Maximalwert
-// getMapArea().getMaxY());
-//
-// try {
-// this.worldToScreen = screenToWorld.createInverse();
-// } catch (final NoninvertibleTransformException e) {
-// LOGGER.error(e);
-// }
-// }
-
-
- /**
- * Calculate the affine transforms used to convert between
- * world and pixel coordinates. The calculations here are very
- * basic and assume a cartesian reference system.
- * <p>
- * Tne transform is calculated such that {@code envelope} will
- * be centred in the display
- *
- * @param envelope the current map extent (world coordinates)
- * @param paintArea the current map pane extent (screen units)
- */
- private void resetTransforms() {
- ReferencedEnvelope refEnv = new ReferencedEnvelope(mapArea, getContext().getCoordinateReferenceSystem());
+ //
+ // /**
+ // * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
+ // * neu.
+ // */
+ // protected void resetTransforms() {
+ // if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
+ // return;
+ //
+ // // We store the last Transform
+ // oldScreenToWorld = screenToWorld;
+ //
+ // this.screenToWorld = new AffineTransform(
+ // // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
+ // // nach rechts (Osten) hin groesser
+ // // --> positive Verschiebung
+ // getMapArea().getWidth() / getWidth(),
+ // // keine Verzerrung
+ // 0.0, 0.0,
+ // // Waehrend die Fenster-Koordinaten nach unten hin groesser
+ // // werden,
+ // // werden Latitude-Koordinaten nach Sueden hin keiner
+ // // --> negative Verschiebung
+ // -getMapArea().getHeight() / getHeight(),
+ // // Die Longitude-Koordinaten werden nach Osten hin groesser
+ // // --> obere linke Ecke des Fensters hat also den Minimalwert
+ // getMapArea().getMinX(),
+ // // Die Latitude-Koordinaten werden nach Norden hin groesser
+ // // --> obere linke Ecke des Fensters hat also den Maximalwert
+ // getMapArea().getMaxY());
+ //
+ // try {
+ // this.worldToScreen = screenToWorld.createInverse();
+ // } catch (final NoninvertibleTransformException e) {
+ // LOGGER.error(e);
+ // }
+ // }
- Rectangle paintArea = getBounds();
-
- double xscale = paintArea.getWidth() / refEnv.getWidth();
- double yscale = paintArea.getHeight() / refEnv.getHeight();
+ /**
+ * Calculate the affine transforms used to convert between world and pixel
+ * coordinates. The calculations here are very basic and assume a cartesian
+ * reference system.
+ * <p>
+ * Tne transform is calculated such that {@code envelope} will be centred in
+ * the display
+ *
+ * @param envelope
+ * the current map extent (world coordinates)
+ * @param paintArea
+ * the current map pane extent (screen units)
+ */
+ private void resetTransforms() {
+ ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
+ getContext().getCoordinateReferenceSystem());
+ //
+ Rectangle paintArea = getBounds();
+
+ if (!getBounds().equals(getVisibleRect())) {
+ System.out.println("did we expect that?");
+ }
+ //
+ // double xscale = paintArea.getWidth() / refEnv.getWidth();
+ // double yscale = paintArea.getHeight() / refEnv.getHeight();
+ //
+ // double scale = Math.min(xscale, yscale);
+ //
+ // double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
+ // double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
- double scale = Math.min(xscale, yscale);
+ worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
+ paintArea);
- double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
- double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
+ // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,
+ // yoff);
+ try {
+ screenToWorld = worldToScreen.createInverse();
- worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff);
- try {
- screenToWorld = worldToScreen.createInverse();
+ } catch (NoninvertibleTransformException ex) {
+ ex.printStackTrace();
+ }
+ }
- } catch (NoninvertibleTransformException ex) {
- ex.printStackTrace();
- }
- }
-
-
-
public void setBgContext(final MapContext context) {
// Remove the default listener from the old context
@@ -1776,9 +1761,10 @@
return false;
}
+ final Envelope candNew = bestAllowedMapArea(newMapArea);
+
// Testing, whether the difference if just minimal
if (mapArea != null) {
- final Envelope candNew = bestAllowedMapArea(newMapArea);
final double tolX = mapArea.getWidth() / 1000.;
final double tolY = mapArea.getHeight() / 1000.;
if ((candNew.getMinX() - tolX < mapArea.getMinX())
@@ -1798,10 +1784,11 @@
}
}
+ // New map are is accepted:
oldMapArea = mapArea;
+ mapArea = candNew;
+ resetTransforms();
- this.mapArea = bestAllowedMapArea(newMapArea);
-
if (localContext != null) {
localContext.setAreaOfInterest(mapArea, localContext
.getCoordinateReferenceSystem());
@@ -1810,12 +1797,11 @@
bgContext.setAreaOfInterest(mapArea, localContext
.getCoordinateReferenceSystem());
}
- resetTransforms();
mapImageInvalid = true;
mapAreaChanged = true;
repaint();
- // LOGGER.debug("New maparea = " + mapArea);
+ LOGGER.debug("New maparea = " + mapArea);
return true;
}
@@ -2035,21 +2021,17 @@
* {@link #getScreenToWorld()} is used.
*/
public Envelope tranformGeoToWindow(final double ox, final double oy,
- final double px, final double py,
- final AffineTransform winToGeotransform) {
- final AffineTransform at = winToGeotransform == null ? getScreenToWorld()
- : winToGeotransform;
+ final double px, final double py) {
+ final AffineTransform at = getWorldToScreenTransform();
Point2D geoO;
- try {
- geoO = at.inverseTransform(new Point2D.Double(ox, oy), null);
- final Point2D geoP = at.inverseTransform(
- new Point2D.Double(px, py), null);
- return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP
- .getY());
- } catch (final NoninvertibleTransformException e) {
- LOGGER.error(e);
- return new Envelope(ox, oy, px, py);
- }
+ // try {
+ geoO = at.transform(new Point2D.Double(ox, oy), null);
+ final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
+ return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
+ // } catch (final NoninvertibleTransformException e) {
+ // LOGGER.error(e);
+ // return new Envelope(ox, oy, px, py);
+ // }
}
/**
@@ -2069,7 +2051,10 @@
final AffineTransform at = getScreenToWorld();
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
- return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
+
+ // Mmmmm... don't really understand why its x,x,y,y
+// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
+ return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY()));
}
/**
@@ -2189,29 +2174,27 @@
- mapImage.getWidth() - 10, getBounds().height
- mapImage.getHeight() - 10, null);
}
-
-
+
int y = 17;
// If the rendering process is still running, indicate this is the image
if (forceWait || bgExecuter != null && bgExecuter.isRunning()
|| localExecuter != null && localExecuter.isRunning()) {
-
- y+=8;
+ y += 8;
+
final Color c = graphics.getColor();
graphics.setFont(waitFont);
-// String waitStr = "Wait..."; // i8n
graphics.setColor(getMapBackgroundColor());
graphics.drawString(waitMsg, 5, y);
graphics.setColor(getMapBackgroundColor());
- graphics.drawString(waitMsg, 7, y+2);
+ graphics.drawString(waitMsg, 7, y + 2);
graphics.setColor(Color.BLACK);
- graphics.drawString(waitMsg, 6, y+1);
+ graphics.drawString(waitMsg, 6, y + 1);
graphics.setColor(c);
-
+
y += 24;
}
@@ -2367,12 +2350,13 @@
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
.getHeight()) / 2.);
+
+// TODO we actually want that
+// // Move the newMapArea above the new center
+// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
+// .getY()
+// - mapArea.centre().y);
- // Move the newMapArea above the new center
- newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
- .getY()
- - mapArea.centre().y);
-
setMapArea(newMapArea);
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java 2009-11-20 15:39:55 UTC (rev 538)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java 2009-11-20 19:10:05 UTC (rev 539)
@@ -97,7 +97,6 @@
drawRectangle(xMapPane.getGraphics(), e.getPoint());
-
// Don't zoom too small areas. Handle it like a click then
if ((Math.abs(startPos.x - e.getPoint().x) * Math.abs(e.getPoint().y - startPos.y)) < 160) {
xMapPane.zoomTo(e.getPoint(), .5);
More information about the Schmitzm-commits
mailing list