[Schmitzm-commits] r414 - in branches/1.0-gt2-2.6/src: gtmig/org/geotools/swing schmitzm/geotools/gui skrueger/geotools skrueger/geotools/selection
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Sep 24 15:23:09 CEST 2009
Author: alfonx
Date: 2009-09-24 15:23:08 +0200 (Thu, 24 Sep 2009)
New Revision: 414
Modified:
branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java
branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java
branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java
branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
JMapPane can optionally be given an envelope. When zooming/panning it will never show anything outside this envelope.
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-09-23 11:36:45 UTC (rev 413)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java 2009-09-24 13:23:08 UTC (rev 414)
@@ -58,6 +58,7 @@
import javax.swing.JPanel;
import org.apache.log4j.Logger;
+import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.MapContext;
import org.geotools.map.event.MapLayerListEvent;
import org.geotools.map.event.MapLayerListListener;
@@ -66,13 +67,6 @@
import org.geotools.renderer.lite.LabelCache;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.renderer.shape.ShapefileRenderer;
-import org.geotools.styling.Graphic;
-import org.geotools.styling.LineSymbolizer;
-import org.geotools.styling.Mark;
-import org.geotools.styling.PointSymbolizer;
-import org.geotools.styling.PolygonSymbolizer;
-import org.geotools.styling.StyleBuilder;
-import org.geotools.styling.StyleFactory;
import org.opengis.filter.FilterFactory2;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -98,55 +92,35 @@
public static final int Select = 4;
- private static final int POLYGON = 0;
-
- private static final int LINE = 1;
-
- private static final int POINT = 2;
-
/**
* what renders the map
*/
GTRenderer renderer;
- private GTRenderer highlightRenderer, selectionRenderer;
-
/**
* the map context to render
*/
MapContext context;
- private MapContext selectionContext;
-
/**
* the area of the map to draw
*/
- // xulu.sc
- // Envelope mapArea;
protected Envelope mapArea;
- // xulu.ec
/**
* the size of the pane last time we drew
*/
- // xulu.sc
- // private Rectangle oldRect = null;
protected Rectangle oldRect = null;
- // xulu.ec
/**
* the last map area drawn.
*/
- // xulu.sc
- // private Envelope oldMapArea = null;
protected Envelope oldMapArea = null;
- // xulu.ec
/**
* the base image of the map
*/
protected BufferedImage baseImage, panningImage;
- // SK: private BufferedImage baseImage, panningImage;
/**
* a factory for filters
@@ -169,27 +143,33 @@
LabelCache labelCache = new LabelCacheImpl();
- // xulu.sc
- // private boolean reset = false;
protected boolean reset = false;
- // xulu.ec
int startX;
int startY;
+ /**
+ * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
+ * out of that area
+ **/
+ private Envelope maxExtend = null;
+
+ // /**
+ // * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If
+ // * <code>true</code> the extends has to be fully inside maxExtend
+ // **/
+ // boolean maxExtendForceMode = true;
+
private boolean clickable;
int lastX;
int lastY;
- // xulu.sn
private Double maxZoomScale = Double.MIN_VALUE;
private Double minZoomScale = Double.MAX_VALUE;
- // xulu.en
- // sk.sn
/**
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
@@ -197,8 +177,6 @@
*/
private boolean panning_started = false;
- // sk.en
-
public JMapPane() {
this(null, true, null, null);
}
@@ -250,14 +228,15 @@
}
public void setRenderer(final GTRenderer renderer) {
- Map<Object,Object> hints = new HashMap<Object,Object>();
-
+ Map<Object, Object> hints = new HashMap<Object, Object>();
+
this.renderer = renderer;
-
- if (renderer instanceof StreamingRenderer || renderer instanceof ShapefileRenderer) {
+
+ if (renderer instanceof StreamingRenderer
+ || renderer instanceof ShapefileRenderer) {
hints = renderer.getRendererHints();
if (hints == null) {
- hints = new HashMap<Object,Object>();
+ hints = new HashMap<Object, Object>();
}
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
labelCache = (LabelCache) hints
@@ -267,18 +246,18 @@
}
hints.put("memoryPreloadingEnabled", Boolean.TRUE);
-
+
renderer.setRendererHints(hints);
}
-// this.highlightRenderer = new StreamingRenderer();
-// this.selectionRenderer = new StreamingRenderer();
+ // this.highlightRenderer = new StreamingRenderer();
+ // this.selectionRenderer = new StreamingRenderer();
-// highlightRenderer.setRendererHints(hints);
-// selectionRenderer.setRendererHints(hints);
-
-// renderer.setRendererHints(hints);
+ // highlightRenderer.setRendererHints(hints);
+ // selectionRenderer.setRendererHints(hints);
+ // renderer.setRendererHints(hints);
+
if (this.context != null) {
this.renderer.setContext(this.context);
}
@@ -330,7 +309,6 @@
this.zoomFactor = zoomFactor;
}
-
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
@@ -369,14 +347,14 @@
.getCoordinateReferenceSystem());
}
- if (changed ) { /* if the map changed then redraw */
+ if (changed) { /* if the map changed then redraw */
changed = false;
baseImage = new BufferedImage(dr.width, dr.height,
BufferedImage.TYPE_INT_ARGB);
final Graphics2D ig = baseImage.createGraphics();
/* System.out.println("rendering"); */
- if (renderer.getContext() != null)
+ if (renderer.getContext() != null)
renderer.setContext(context);
labelCache.clear(); // work around anoying labelcache bug
@@ -397,14 +375,14 @@
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
final double mapHeight = mapArea.getHeight();
final double scaleX = r.getWidth() / mapArea.getWidth(); /*
- * calculate the new
- * scale
- */
+ * calculate the
+ * new scale
+ */
final double scaleY = r.getHeight() / mapArea.getHeight();
double scale = 1.0; // stupid compiler!
- if (scaleX < scaleY) { /* pick the smaller scale */
+ if (scaleX > scaleY) { /* pick the smaller scale */
scale = scaleX;
} else {
scale = scaleY;
@@ -420,92 +398,19 @@
*/
/* create the new extent */
- final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),
- mapArea.getMinY() - (deltaY / 2.0));
- final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),
- mapArea.getMaxY() + (deltaY / 2.0));
+ final Coordinate ll = new Coordinate(
+ mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
+ - (deltaY / 2.0));
+ final Coordinate ur = new Coordinate(
+ mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
+ + (deltaY / 2.0));
return new Envelope(ll, ur);
}
-// public void doSelection(final double x, final double y, final MapLayer layer) {
-//
-// final Geometry geometry = gf.createPoint(new Coordinate(x, y));
-//
-// // org.opengis.geometry.Geometry geometry = new Point();
-//
-// findFeature(geometry, layer);
-//
-// }
-//
-// /**
-// * @param geometry
-// * - a geometry to construct the filter with
-// * @param i
-// * - the index of the layer to search
-// * @throws IndexOutOfBoundsException
-// */
-// private void findFeature(final Geometry geometry, final MapLayer layer)
-// throws IndexOutOfBoundsException {
-// org.opengis.filter.spatial.BinarySpatialOperator f = null;
-//
-// if ((context == null) || (layer == null)) {
-// return;
-// }
-//
-// try {
-// String name = layer.getFeatureSource().getSchema()
-// .getDefaultGeometry().getLocalName();
-//
-// if (name == "") {
-// name = "the_geom";
-// }
-//
-// try {
-// f = ff.contains(ff.property(name), ff.literal(geometry));
-// if (selectionManager != null) {
-//// System.out.println("selection changed");
-// selectionManager.selectionChanged(this, f);
-//
-// }
-// } catch (final IllegalFilterException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-//
-// /*
-// * // f.addLeftGeometry(ff.property(name)); //
-// * System.out.println("looking with " + f); FeatureCollection fc =
-// * layer.getFeatureSource().getFeatures(f);
-// *
-// *
-// *
-// * if (fcol == null) { fcol = fc;
-// *
-// * // here we should set the defaultgeom type } else {
-// * fcol.addAll(fc); }
-// */
-//
-// /*
-// * GeometryAttributeType gat =
-// * layer.getFeatureSource().getSchema().getDefaultGeometry();
-// * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());
-// */
-//
-// /*
-// * Iterator fi = fc.iterator(); while (fi.hasNext()) { SimpleFeature feat
-// * = (SimpleFeature) fi.next(); System.out.println("selected " +
-// * feat.getAttribute("STATE_NAME")); }
-// */
-// } catch (final IllegalFilterException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// return;
-// }
-
public void mouseClicked(final MouseEvent e) {
- if (mapArea == null) return;
+ if (mapArea == null)
+ return;
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
// h:"+mapArea.getHeight());
final Rectangle bounds = this.getBounds();
@@ -519,7 +424,8 @@
final double width2 = width / 2.0;
final double height2 = height / 2.0;
// xulu.ec
- final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();
+ final double mapX = ((x * width) / (double) bounds.width)
+ + mapArea.getMinX();
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
+ mapArea.getMinY();
@@ -550,11 +456,11 @@
zlevel = 1.0 / zoomFactor;
break;
-//
-// case Select:
-// doSelection(mapX, mapY, selectionLayer);
-//
-// return;
+ //
+ // case Select:
+ // doSelection(mapX, mapY, selectionLayer);
+ //
+ // return;
default:
return;
@@ -626,11 +532,11 @@
// System.out.println("translate "+dx+","+dy);
final Graphics2D g2 = panningImage.createGraphics();
g2.setBackground(new Color(240, 240, 240)); // TODO richtige
- // farbe? am besten
- // vom L&F die
- // hintergrundfarbe
- // auslesen...
-
+ // farbe? am besten
+ // vom L&F die
+ // hintergrundfarbe
+ // auslesen...
+
g2.clearRect(0, 0, this.getWidth(), this.getHeight());
g2.drawImage(baseImage, dx, dy, this);
graphics.drawImage(panningImage, 0, 0, this);
@@ -652,51 +558,54 @@
lastX = x;
lastY = y;
drawRectangle(graphics);
- }
-// else if (state == JMapPane.Select && selectionLayer != null) {
-//
-// // construct a new bbox filter
-// final Rectangle bounds = this.getBounds();
-//
-// final double mapWidth = mapArea.getWidth();
-// final double mapHeight = mapArea.getHeight();
-//
-// final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
-// + mapArea.getMinX();
-// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)
-// + mapArea.getMinY();
-// final double x2 = ((x * mapWidth) / (double) bounds.width)
-// + mapArea.getMinX();
-// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)
-// + mapArea.getMinY();
-// final double left = Math.min(x1, x2);
-// final double right = Math.max(x1, x2);
-// final double bottom = Math.min(y1, y2);
-// final double top = Math.max(y1, y2);
-//
-// String name = selectionLayer.getFeatureSource().getSchema()
-// .getDefaultGeometry().getName();
-//
-// if (name == "") {
-// name = "the_geom";
-// }
-// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
-// getContext().getCoordinateReferenceSystem().toString());
-// if (selectionManager != null) {
-// selectionManager.selectionChanged(this, bb);
-// }
-//
-// graphics.setXORMode(Color.green);
-//
-// /*
-// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
-// */
-//
-// // draw new box
-// lastX = x;
-// lastY = y;
-// drawRectangle(graphics);
-// }
+ }
+ // else if (state == JMapPane.Select && selectionLayer != null) {
+ //
+ // // construct a new bbox filter
+ // final Rectangle bounds = this.getBounds();
+ //
+ // final double mapWidth = mapArea.getWidth();
+ // final double mapHeight = mapArea.getHeight();
+ //
+ // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
+ // + mapArea.getMinX();
+ // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
+ // (double) bounds.height)
+ // + mapArea.getMinY();
+ // final double x2 = ((x * mapWidth) / (double) bounds.width)
+ // + mapArea.getMinX();
+ // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
+ // bounds.height)
+ // + mapArea.getMinY();
+ // final double left = Math.min(x1, x2);
+ // final double right = Math.max(x1, x2);
+ // final double bottom = Math.min(y1, y2);
+ // final double top = Math.max(y1, y2);
+ //
+ // String name = selectionLayer.getFeatureSource().getSchema()
+ // .getDefaultGeometry().getName();
+ //
+ // if (name == "") {
+ // name = "the_geom";
+ // }
+ // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
+ // top,
+ // getContext().getCoordinateReferenceSystem().toString());
+ // if (selectionManager != null) {
+ // selectionManager.selectionChanged(this, bb);
+ // }
+ //
+ // graphics.setXORMode(Color.green);
+ //
+ // /*
+ // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
+ // */
+ //
+ // // draw new box
+ // lastX = x;
+ // lastY = y;
+ // drawRectangle(graphics);
+ // }
}
@@ -781,18 +690,18 @@
setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
// sk.sc
-// {
-// // SK tries to paint a preview of the zoom ;-9 aha.... well
-// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
-// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-// RenderingHints.VALUE_ANTIALIAS_OFF);
-// graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
-// RenderingHints.VALUE_RENDER_SPEED);
-// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
-// JMapPane.this.getHeight(), x1, y1, x2, y2, null);
-// }
+ // {
+ // // SK tries to paint a preview of the zoom ;-9 aha.... well
+ // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
+ // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+ // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+ // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ // RenderingHints.VALUE_ANTIALIAS_OFF);
+ // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+ // RenderingHints.VALUE_RENDER_SPEED);
+ // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
+ // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
+ // }
// xulu.ec
} else if (state == JMapPane.ZoomOut) {
drawRectangle(this.getGraphics());
@@ -821,31 +730,32 @@
setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
// xulu.ec
- }
-// else if (state == JMapPane.Select && selectionLayer != null) {
-// final double left = Math.min(startX, endX);
-// final double right = Math.max(startX, endX);
-// final double bottom = Math.min(startY, endY);
-// final double top = Math.max(startY, endY);
-//
-// String name = selectionLayer.getFeatureSource().getSchema()
-// .getDefaultGeometry().getLocalName();
-//
-// if (name == "") {
-// name = "the_geom";
-// }
-// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
-// getContext().getCoordinateReferenceSystem().toString());
-// // System.out.println(bb.toString());
-// if (selectionManager != null) {
-// selectionManager.selectionChanged(this, bb);
-// }
-// /*
-// * FeatureCollection fc; selection = null; try { fc =
-// * selectionLayer.getFeatureSource().getFeatures(bb); selection =
-// * fc; } catch (IOException e) { e.printStackTrace(); }
-// */
-// }
+ }
+ // else if (state == JMapPane.Select && selectionLayer != null) {
+ // final double left = Math.min(startX, endX);
+ // final double right = Math.max(startX, endX);
+ // final double bottom = Math.min(startY, endY);
+ // final double top = Math.max(startY, endY);
+ //
+ // String name = selectionLayer.getFeatureSource().getSchema()
+ // .getDefaultGeometry().getLocalName();
+ //
+ // if (name == "") {
+ // name = "the_geom";
+ // }
+ // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
+ // top,
+ // getContext().getCoordinateReferenceSystem().toString());
+ // // System.out.println(bb.toString());
+ // if (selectionManager != null) {
+ // selectionManager.selectionChanged(this, bb);
+ // }
+ // /*
+ // * FeatureCollection fc; selection = null; try { fc =
+ // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
+ // * fc; } catch (IOException e) { e.printStackTrace(); }
+ // */
+ // }
// xulu.so
// setMapArea(mapArea);
@@ -857,44 +767,45 @@
return clickable;
}
- private org.geotools.styling.Style setupStyle(final int type, final Color color) {
- final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
- .getStyleFactory(null);
- final StyleBuilder sb = new StyleBuilder();
+ //
+ // private org.geotools.styling.Style setupStyle(final int type, final Color
+ // color) {
+ // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
+ // .getStyleFactory(null);
+ // final StyleBuilder sb = new StyleBuilder();
+ //
+ // org.geotools.styling.Style s = sf.createStyle();
+ // s.setTitle("selection");
+ //
+ // // TODO parameterise the color
+ // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
+ // ps.setStroke(sb.createStroke(color));
+ //
+ // final LineSymbolizer ls = sb.createLineSymbolizer(color);
+ // final Graphic h = sb.createGraphic();
+ // h.setMarks(new Mark[] { sb.createMark("square", color) });
+ //
+ // final PointSymbolizer pts = sb.createPointSymbolizer(h);
+ //
+ // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
+ // switch (type) {
+ // case POLYGON:
+ // s = sb.createStyle(ps);
+ //
+ // break;
+ //
+ // case POINT:
+ // s = sb.createStyle(pts);
+ //
+ // break;
+ //
+ // case LINE:
+ // s = sb.createStyle(ls);
+ // }
+ //
+ // return s;
+ // }
- org.geotools.styling.Style s = sf.createStyle();
- s.setTitle("selection");
-
- // TODO parameterise the color
- final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
- ps.setStroke(sb.createStroke(color));
-
- final LineSymbolizer ls = sb.createLineSymbolizer(color);
- final Graphic h = sb.createGraphic();
- h.setMarks(new Mark[] { sb.createMark("square", color) });
-
- final PointSymbolizer pts = sb.createPointSymbolizer(h);
-
- // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
- switch (type) {
- case POLYGON:
- s = sb.createStyle(ps);
-
- break;
-
- case POINT:
- s = sb.createStyle(pts);
-
- break;
-
- case LINE:
- s = sb.createStyle(ls);
- }
-
- return s;
- }
-
-
public void propertyChange(final PropertyChangeEvent evt) {
final String prop = evt.getPropertyName();
@@ -977,8 +888,6 @@
public void mouseMoved(final MouseEvent e) {
}
-
-
// xulu.sn
/**
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
@@ -997,6 +906,8 @@
if (env == null)
return env;
+ Envelope newArea = null;
+
/**
* Correct the aspect Ratio before we check the rest. Otherwise we might
* easily fail.
@@ -1006,8 +917,8 @@
final double scale = env.getWidth() / getWidth();
final double centerX = env.getMinX() + env.getWidth() / 2.;
final double centerY = env.getMinY() + env.getHeight() / 2.;
- double newWidth2;
- double newHeight2;
+ double newWidth2 = 0;
+ double newHeight2 = 0;
if (scale < getMaxZoomScale()) {
// ****************************************************************************
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope
@@ -1024,15 +935,128 @@
// ****************************************************************************
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
// ****************************************************************************
- return env;
+ newArea = env;
}
- final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
- - newHeight2);
- final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
- + newHeight2);
+ if (newArea == null) {
- return new Envelope(ll, ur);
+ final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
+ - newHeight2);
+ final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
+ + newHeight2);
+
+ newArea = new Envelope(ll, ur);
+ }
+
+ if (getMaxExtend() != null) {
+
+ while (!getMaxExtend().contains(newArea)) {
+ /*
+ * If a maxExtend is set, we have to honour that...
+ */
+
+ // Exceeds top? Move down and maybe cut
+ if (newArea.getMaxY() > maxExtend.getMaxY()) {
+ double divY = newArea.getMaxY() - maxExtend.getMaxY();
+ LOGGER.debug("Moving area down by " + divY);
+
+ newArea = new Envelope(new Coordinate(newArea.getMinX(),
+ newArea.getMinY() - divY), new Coordinate(newArea
+ .getMaxX(), newArea.getMaxY() - divY));
+
+ if (newArea.getMinY() < maxExtend.getMinY()) {
+ LOGGER.debug("Now it exeeds the bottom border.. cut!");
+ // And cut the bottom if it moved out of the area
+ newArea = new Envelope(new Coordinate(
+ newArea.getMinX(), maxExtend.getMinY()),
+ new Coordinate(newArea.getMaxX(), newArea
+ .getMaxY()));
+
+ LOGGER.debug("and fix aspect ratio");
+
+ newArea = fixAspectRatio(this.getBounds(), newArea);
+ }
+ }
+
+ // Exceeds bottom? Move up and maybe cut
+ if (newArea.getMinY() < maxExtend.getMinY()) {
+ double divY = newArea.getMinY() - maxExtend.getMinY();
+ LOGGER.debug("Moving area up by " + divY);
+
+ newArea = new Envelope(new Coordinate(newArea.getMinX(),
+ newArea.getMinY() - divY), new Coordinate(newArea
+ .getMaxX(), newArea.getMaxY() - divY));
+
+ if (newArea.getMaxY() > maxExtend.getMaxY()) {
+ LOGGER.debug("Now it exeeds the top border.. cut!");
+ // And cut the bottom if it moved out of the area
+ newArea = new Envelope(new Coordinate(
+ newArea.getMinX(), newArea.getMinY()),
+ new Coordinate(newArea.getMaxX(), maxExtend
+ .getMaxY()));
+
+ LOGGER.debug("and fix aspect ratio");
+
+ newArea = fixAspectRatio(this.getBounds(), newArea);
+ }
+ }
+
+ // Exceeds to the right? move and maybe cut
+ if (newArea.getMaxX() > maxExtend.getMaxX()) {
+
+ // Move left..
+ double divX = newArea.getMaxX() - maxExtend.getMaxX();
+ LOGGER.debug("Moving area left by " + divX);
+
+ newArea = new Envelope(new Coordinate(newArea.getMinX()
+ - divX, newArea.getMinY()), new Coordinate(newArea
+ .getMaxX()
+ - divX, newArea.getMaxY()));
+
+ if (newArea.getMinX() < maxExtend.getMinX()) {
+ LOGGER.debug("Now it exeeds the left border.. cut!");
+ // And cut the left if it moved out of the area
+ newArea = new Envelope(new Coordinate(maxExtend
+ .getMinX(), newArea.getMinY()), new Coordinate(
+ newArea.getMaxX(), newArea.getMaxY()));
+
+ LOGGER.debug("and fix aspect ratio");
+
+ newArea = fixAspectRatio(this.getBounds(), newArea);
+ }
+ }
+
+ // Exceeds to the left? move and maybe cut
+ if (newArea.getMinX() < maxExtend.getMinX()) {
+
+ // Move right..
+ double divX = newArea.getMinX() - maxExtend.getMinX();
+ LOGGER.debug("Moving area right by " + divX);
+
+ newArea = new Envelope(new Coordinate(newArea.getMinX()
+ - divX, newArea.getMinY()), new Coordinate(newArea
+ .getMaxX()
+ - divX, newArea.getMaxY()));
+
+ if (newArea.getMaxX() > maxExtend.getMaxX()) {
+ LOGGER.debug("Now it exeeds the right border.. cut!");
+ // And cut the left if it moved out of the area
+ newArea = new Envelope(new Coordinate(
+ newArea.getMinX(), newArea.getMinY()),
+ new Coordinate(maxExtend.getMaxX(), newArea
+ .getMaxY()));
+
+ LOGGER.debug("and fix aspect ratio");
+
+ newArea = fixAspectRatio(this.getBounds(), newArea);
+ }
+ }
+
+ }
+
+ }
+
+ return newArea;
}
/**
@@ -1065,7 +1089,6 @@
* Krüger</a>
*/
public void setMaxZoomScale(final Double maxZoomScale) {
- // System.out.println("setting max scale to "+maxZoomScale);
this.maxZoomScale = maxZoomScale;
}
@@ -1079,6 +1102,28 @@
public void setMinZoomScale(final Double minZoomScale) {
this.minZoomScale = minZoomScale;
}
- // xulu.en
+ /**
+ * Defines an evelope of the viwable area. The JMapPane will never show
+ * anything outside of this extend.
+ *
+ * @param maxExtend
+ * <code>null</code> to not have this restriction.
+ */
+ public void setMaxExtend(Envelope maxExtend) {
+ this.maxExtend = maxExtend;
+ }
+
+ /**
+ * Returns the evelope of the viewable area. The JMapPane will never show
+ * anything outside of this extend.
+ *
+ * @param maxExtend
+ * <code>null</code> to not have this restriction.
+ */
+
+ public Envelope getMaxExtend() {
+ return maxExtend;
+ }
+
}
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java 2009-09-23 11:36:45 UTC (rev 413)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java 2009-09-24 13:23:08 UTC (rev 414)
@@ -284,7 +284,7 @@
*/
protected Vector<JMapPaneListener> mapPaneListeners = new Vector<JMapPaneListener>();
- protected gtmig.org.geotools.swing.MouseSelectionTracker selTracker = new gtmig.org.geotools.swing.MouseSelectionTracker() {
+ final protected gtmig.org.geotools.swing.MouseSelectionTracker selTracker = new gtmig.org.geotools.swing.MouseSelectionTracker() {
public void mouseDragged(final MouseEvent event) {
// Wenn Fenster-Selektions-Modus auf NICHTS steht (z.B. Info-Tool),
// keinen Rahmen beim Draggen zeichnen
@@ -357,7 +357,7 @@
/** Holds a flag for each layer, whether it is regarded or ignored on
* {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
* actions. */
- protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
+ final protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
/**
* Erzeugt ein neues MapPane.
@@ -562,20 +562,22 @@
}
});
- // The default is to regard a layer on selection
- // actions
- getContext().addMapLayerListListener(
- new MapLayerListAdapter() {
- @Override
- public void layerAdded(MapLayerListEvent e) {
- setMapLayerSelectable(e.getLayer(),true);
- }
- @Override
- public void layerRemoved(MapLayerListEvent e) {
- // remove reference to layer
- mapLayerSelectable.remove(e.getLayer());
- }
- });
+
+// Solved without just with the access methods
+// // The default is to regard a layer on selection
+// // actions
+// getContext().addMapLayerListListener(
+// new MapLayerListAdapter() {
+// @Override
+// public void layerAdded(MapLayerListEvent e) {
+// setMapLayerSelectable(e.getLayer(),true);
+// }
+// @Override
+// public void layerRemoved(MapLayerListEvent e) {
+// // remove reference to layer
+// mapLayerSelectable.remove(e.getLayer());
+// }
+// });
}
public JMapPane(LayoutManager layout, boolean isDoubleBuffered,
@@ -1570,7 +1572,7 @@
continue;
}
- LOGGER.debug("mode = " + mode);
+// LOGGER.debug("mode = " + mode);
// Bei einem Raster-Layer, das die BB schneidet, abbrechen, wenn nur
// im obersten (sichtbaren) Layer gesucht wird.
@@ -1618,21 +1620,6 @@
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = featureSource
.getFeatures(filter);
-// LOGGER.info("Crazy finsvisible features position reached");
-
- // Liefert eine FeatureCollection zurück, in welcher nur
- // Features enthalten sind, welche bei der aktuellen
- // Anzeigeskala aufgrund des Styles gerendert werden.
- if (layer.getTitle().equals(
- "vector_afrikan_countries_00040984322")) {
- LOGGER
- .warn("Cancelling here to avoid infinite loop in ShapefileReader.ensureCapacity(ByteBuffer, int, boolean) line: 203.");
- LOGGER
- .warn("Calling isEmpty() or getSize() in GT2.4.5 the ShapefileReader-Class enters infinite loop here for the here for layer vector_afrikan_countries_00040984322. It seems to be specific for this special ShapeFile. Canelling the operation here is a very ugly and very static work-arround. Hopefully this problem vanishes with GT 2.5");
- continue;
- }
-
- // @Martin Using size() produces the same problem
if (!fc.isEmpty()) {
fc = filterSLDVisibleOnly(fc, layer.getStyle());
@@ -2728,20 +2715,23 @@
* actions.
* @param layer a layer
* @param selectable if {@code false} the layer is ignored during the
- * upper mentioned actions
+ * upper mentioned actions. If <code>null</code>, the default (true) will be used.
*/
- public void setMapLayerSelectable(MapLayer layer, boolean selectable) {
- mapLayerSelectable.put(layer, selectable);
+ public void setMapLayerSelectable(MapLayer layer, Boolean selectable) {
+ if (selectable == null)
+ mapLayerSelectable.remove(layer);
+ else
+ mapLayerSelectable.put(layer, selectable);
}
/**
* Returns whether a layer is regarded or ignored on
* {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
- * actions.
+ * actions. Returns <code>true</code> if the selectability has not been defined.
* @param layer a layer
*/
public boolean isMapLayerSelectable(MapLayer layer) {
Boolean selectable = mapLayerSelectable.get(layer);
- return selectable != null && selectable;
+ return selectable == null ? true : selectable;
}
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java 2009-09-23 11:36:45 UTC (rev 413)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java 2009-09-24 13:23:08 UTC (rev 414)
@@ -33,8 +33,11 @@
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Locale;
+import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -128,7 +131,7 @@
protected int selectedTool = TOOL_ZOOMIN;
/** Holds the tool buttons of the tool bar. */
- protected SortedMap<Integer, JComponent> toolAndActionButtons = null;
+ final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
/** Controls that only one tool button is activated. */
protected ButtonGroup toolButtonGroup = null;
@@ -153,6 +156,24 @@
protected boolean zoomBackForwardButtonInAction;
+ /** 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(){
+
+ @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() ) ) ;
+ }
+ }
+
+ };
+
/**
* Creates a new toolbar. Notice: This toolbar does nothing until
* {@link #setMapPane(JMapPane)} is called!
@@ -160,7 +181,15 @@
public MapPaneToolBar() {
this(null);
}
+
+ public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) {
+ toolSelectionListeners.add(listener);
+ }
+ public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) {
+ toolSelectionListeners .remove(listener);
+ }
+
/**
* Creates a new tool bar.
*
@@ -169,7 +198,6 @@
*/
public MapPaneToolBar(JMapPane mapPane) {
super("Control the map", JToolBar.HORIZONTAL);
- this.toolAndActionButtons = new TreeMap<Integer, JComponent>();
this.toolButtonGroup = new ButtonGroup();
// Create a Listener to listen to the zooms on the JMapPane
@@ -306,8 +334,18 @@
Dimension dimension = new Dimension(49, 10);
addSeparator(dimension);
// Tool buttons
- for (JComponent b : toolAndActionButtons.values())
+ 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 );
+ }
+
add(b);
+ }
if (!toolAndActionButtons.containsKey(selectedTool)) {
/**
@@ -870,4 +908,5 @@
setBackground(orig);
}
}
+
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java 2009-09-23 11:36:45 UTC (rev 413)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java 2009-09-24 13:23:08 UTC (rev 414)
@@ -77,8 +77,6 @@
// Needed because variables for the overwritten methods
// are not yet set.
getGeoMapPane().getMapPane().setWaitCursorComponent(parentGui);
- if (toolBar == null)
- toolBar = new MapPaneToolBar(getMapPane());
jToolBar = toolBar;
}
@@ -136,9 +134,12 @@
/**
* Returns the tool bar which controls the active mouse actions on the map.
*
- * @return
+ * @return never <code>null</code>, will rather create a default
*/
public MapPaneToolBar getToolBar() {
+ if (jToolBar == null) {
+ jToolBar = new MapPaneToolBar(getMapPane());
+ }
return jToolBar;
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-09-23 11:36:45 UTC (rev 413)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-09-24 13:23:08 UTC (rev 414)
@@ -44,7 +44,6 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -54,7 +53,6 @@
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionListener;
-import org.geotools.feature.FeatureIterator;
import org.geotools.map.MapLayer;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.Style;
@@ -62,13 +60,11 @@
import org.opengis.filter.identity.FeatureId;
import schmitzm.geotools.FilterUtil;
-import schmitzm.geotools.feature.PipedFeatureIterator;
import schmitzm.geotools.gui.JMapPane;
import schmitzm.geotools.map.event.FeatureSelectedEvent;
import schmitzm.geotools.map.event.JMapPaneEvent;
import schmitzm.geotools.map.event.JMapPaneListener;
import schmitzm.geotools.styling.StylingUtil;
-import schmitzm.lang.LangUtil;
import skrueger.geotools.MapPaneToolBar;
import skrueger.geotools.StyledLayerInterface;
More information about the Schmitzm-commits
mailing list