/[schmitzm]/trunk/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/XMapPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/1.0-gt2-2.6/src/org/geotools/gui/swing/JMapPane.java revision 320 by mojays, Wed Aug 26 13:49:19 2009 UTC branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java revision 493 by mojays, Fri Oct 23 14:09:27 2009 UTC
# Line 13  Line 13 
13   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *    Lesser General Public License for more details.   *    Lesser General Public License for more details.
15   */   */
16  package org.geotools.gui.swing;  package gtmig.org.geotools.swing;
17    
18  /**  /**
19   * <b>Xulu:<br>   * <b>Xulu:<br>
# Line 58  import java.util.Map; Line 58  import java.util.Map;
58  import javax.swing.JPanel;  import javax.swing.JPanel;
59    
60  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
 import org.geotools.feature.FeatureCollection;  
 import org.geotools.filter.IllegalFilterException;  
 import org.geotools.map.DefaultMapContext;  
61  import org.geotools.map.MapContext;  import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;  
62  import org.geotools.map.event.MapLayerListEvent;  import org.geotools.map.event.MapLayerListEvent;
63  import org.geotools.map.event.MapLayerListListener;  import org.geotools.map.event.MapLayerListListener;
 import org.geotools.referencing.crs.DefaultGeographicCRS;  
64  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
65    import org.geotools.renderer.label.LabelCacheImpl;
66  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
 import org.geotools.renderer.lite.LabelCacheDefault;  
67  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
 import org.geotools.renderer.shape.TransitionShapefileRenderer;  
 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.Style;  
 import org.geotools.styling.StyleBuilder;  
 import org.geotools.styling.StyleFactory;  
 import org.opengis.filter.Filter;  
68  import org.opengis.filter.FilterFactory2;  import org.opengis.filter.FilterFactory2;
69  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
70    
71    import schmitzm.geotools.JTSUtil;
72  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
73    
 import com.sun.jini.jeri.internal.runtime.SelectionManager;  
74  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
75  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;  
76  import com.vividsolutions.jts.geom.GeometryFactory;  import com.vividsolutions.jts.geom.GeometryFactory;
77    
78  public class JMapPane extends JPanel implements MouseListener,  public class JMapPane extends JPanel implements MouseListener,
79                  MouseMotionListener, HighlightChangeListener, SelectionChangeListener,                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {
80                  PropertyChangeListener, MapLayerListListener {          private static Logger LOGGER = Logger.getLogger(JMapPane.class);
         private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());  
81    
82          private static final long serialVersionUID = -8647971481359690499L;          private static final long serialVersionUID = -8647971481359690499L;
83    
# Line 108  public class JMapPane extends JPanel imp Line 91  public class JMapPane extends JPanel imp
91    
92          public static final int Select = 4;          public static final int Select = 4;
93    
         private static final int POLYGON = 0;  
   
         private static final int LINE = 1;  
   
         private static final int POINT = 2;  
   
94          /**          /**
95           * what renders the map           * what renders the map
96           */           */
97          GTRenderer renderer;          GTRenderer renderer;
98    
         private GTRenderer highlightRenderer, selectionRenderer;  
   
99          /**          /**
100           * the map context to render           * the map context to render
101           */           */
102          MapContext context;          MapContext context;
103    
         private MapContext selectionContext;  
   
104          /**          /**
105           * the area of the map to draw           * the area of the map to draw
106           */           */
         // xulu.sc  
         // Envelope mapArea;  
107          protected Envelope mapArea;          protected Envelope mapArea;
         // xulu.ec  
108    
109          /**          /**
110           * the size of the pane last time we drew           * the size of the pane last time we drew
111           */           */
         // xulu.sc  
         // private Rectangle oldRect = null;  
112          protected Rectangle oldRect = null;          protected Rectangle oldRect = null;
         // xulu.ec  
113    
114          /**          /**
115           * the last map area drawn.           * the last map area drawn.
116           */           */
         // xulu.sc  
         // private Envelope oldMapArea = null;  
117          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
         // xulu.ec  
118    
119          /**          /**
120           * the base image of the map           * the base image of the map
121           */           */
122          protected BufferedImage baseImage, panningImage;          protected BufferedImage baseImage, panningImage;
         // SK: private BufferedImage baseImage, panningImage;  
   
         /**  
          * image of selection  
          */  
         private BufferedImage selectImage;  
   
         /**  
          * style for selected items  
          */  
         private Style selectionStyle;  
   
         /**  
          * layer that selection works on  
          */  
         private MapLayer selectionLayer;  
   
         /**  
          * layer that highlight works on  
          */  
         private MapLayer highlightLayer;  
   
         /**  
          * the object which manages highlighting  
          */  
         private HighlightManager highlightManager;  
   
         /**  
          * is highlighting on or off  
          */  
         private boolean highlight = true;  
123    
124          /**          /**
125           * a factory for filters           * a factory for filters
# Line 198  public class JMapPane extends JPanel imp Line 131  public class JMapPane extends JPanel imp
131           */           */
132          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
133    
         /**  
          * the collections of features to be selected or highlighted  
          */  
         FeatureCollection selection;  
   
         /**  
          * the collections of features to be selected or highlighted  
          */  
         FeatureCollection highlightFeature;  
   
134          private int state = ZoomIn;          private int state = ZoomIn;
135    
136          /**          /**
# Line 215  public class JMapPane extends JPanel imp Line 138  public class JMapPane extends JPanel imp
138           */           */
139          private double zoomFactor = 2.0;          private double zoomFactor = 2.0;
140    
         Style lineHighlightStyle;  
   
         Style pointHighlightStyle;  
   
         Style polygonHighlightStyle;  
   
         Style polygonSelectionStyle;  
   
         Style pointSelectionStyle;  
   
         Style lineSelectionStyle;  
   
141          boolean changed = true;          boolean changed = true;
142    
143          LabelCache labelCache = new LabelCacheDefault();          LabelCache labelCache = new LabelCacheImpl();
144    
         // xulu.sc  
         // private boolean reset = false;  
145          protected boolean reset = false;          protected boolean reset = false;
         // xulu.ec  
146    
147          int startX;          int startX;
148    
149          int startY;          int startY;
150    
151            /**
152             * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
153             * out of that area
154             **/
155            private Envelope maxExtend = null;
156    
157            // /**
158            // * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If
159            // * <code>true</code> the extends has to be fully inside maxExtend
160            // **/
161            // boolean maxExtendForceMode = true;
162    
163          private boolean clickable;          private boolean clickable;
164    
165          int lastX;          int lastX;
166    
167          int lastY;          int lastY;
168    
         private SelectionManager selectionManager;  
         // xulu.sn  
169          private Double maxZoomScale = Double.MIN_VALUE;          private Double maxZoomScale = Double.MIN_VALUE;
170          private Double minZoomScale = Double.MAX_VALUE;          private Double minZoomScale = Double.MAX_VALUE;
         // xulu.en  
171    
         // sk.sn  
172          /**          /**
173           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
174           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
# Line 260  public class JMapPane extends JPanel imp Line 176  public class JMapPane extends JPanel imp
176           */           */
177          private boolean panning_started = false;          private boolean panning_started = false;
178    
         // sk.en  
   
179          public JMapPane() {          public JMapPane() {
180                  this(null, true, null, null);                  this(null, true, null, null);
181          }          }
# Line 302  public class JMapPane extends JPanel imp Line 216  public class JMapPane extends JPanel imp
216    
217                  this.addMouseListener(this);                  this.addMouseListener(this);
218                  this.addMouseMotionListener(this);                  this.addMouseMotionListener(this);
                 setHighlightManager(new HighlightManager(highlightLayer));  
                 setSelectionManager(new SelectionManager(selectionLayer));  
                 lineHighlightStyle = setupStyle(LINE, Color.red);  
   
                 pointHighlightStyle = setupStyle(POINT, Color.red);  
   
                 polygonHighlightStyle = setupStyle(POLYGON, Color.red);  
   
                 polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);  
   
                 pointSelectionStyle = setupStyle(POINT, Color.cyan);  
   
                 lineSelectionStyle = setupStyle(LINE, Color.cyan);  
219                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
220          }          }
221    
# Line 326  public class JMapPane extends JPanel imp Line 227  public class JMapPane extends JPanel imp
227          }          }
228    
229          public void setRenderer(final GTRenderer renderer) {          public void setRenderer(final GTRenderer renderer) {
230                  Map hints = new HashMap();                  Map<Object, Object> hints = new HashMap<Object, Object>();
231                    
232                  this.renderer = renderer;                  this.renderer = renderer;
233                    //MS: Apply hint also for ShapeFileRenderer
234                  if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) {  //              if (renderer instanceof StreamingRenderer) {
235                          hints = renderer.getRendererHints();                          hints = renderer.getRendererHints();
236                          if (hints == null) {                          if (hints == null) {
237                                  hints = new HashMap();                                  hints = new HashMap<Object, Object>();
238                          }                          }
239                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
240                                  labelCache = (LabelCache) hints                                  labelCache = (LabelCache) hints
# Line 343  public class JMapPane extends JPanel imp Line 244  public class JMapPane extends JPanel imp
244                          }                          }
245    
246                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);
                           
                         renderer.setRendererHints(hints);  
                 }  
   
 //              this.highlightRenderer = new StreamingRenderer();  
 //              this.selectionRenderer = new StreamingRenderer();  
247    
248  //              highlightRenderer.setRendererHints(hints);                          renderer.setRendererHints(hints);
249  //              selectionRenderer.setRendererHints(hints);  //              }
                   
 //              renderer.setRendererHints(hints);  
250    
251                  if (this.context != null) {                  if (this.context != null) {
252                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
# Line 406  public class JMapPane extends JPanel imp Line 299  public class JMapPane extends JPanel imp
299                  this.zoomFactor = zoomFactor;                  this.zoomFactor = zoomFactor;
300          }          }
301    
         public MapLayer getSelectionLayer() {  
                 return selectionLayer;  
         }  
   
         public void setSelectionLayer(final MapLayer selectionLayer) {  
                 this.selectionLayer = selectionLayer;  
                 if (selectionManager != null) {  
                         selectionManager.setSelectionLayer(selectionLayer);  
                 }  
         }  
   
         public boolean isHighlight() {  
                 return highlight;  
         }  
   
         public void setHighlight(final boolean highlight) {  
                 this.highlight = highlight;  
         }  
   
         public MapLayer getHighlightLayer() {  
                 return highlightLayer;  
         }  
   
         public void setHighlightLayer(final MapLayer highlightLayer) {  
                 this.highlightLayer = highlightLayer;  
   
                 if (highlightManager != null) {  
                         highlightManager.setHighlightLayer(highlightLayer);  
                 }  
         }  
   
         public HighlightManager getHighlightManager() {  
                 return highlightManager;  
         }  
   
         public void setHighlightManager(final HighlightManager highlightManager) {  
                 this.highlightManager = highlightManager;  
                 this.highlightManager.addHighlightChangeListener(this);  
                 this.addMouseMotionListener(this.highlightManager);  
         }  
   
         public Style getLineHighlightStyle() {  
                 return lineHighlightStyle;  
         }  
   
         public void setLineHighlightStyle(final Style lineHighlightStyle) {  
                 this.lineHighlightStyle = lineHighlightStyle;  
         }  
   
         public Style getLineSelectionStyle() {  
                 return lineSelectionStyle;  
         }  
   
         public void setLineSelectionStyle(final Style lineSelectionStyle) {  
                 this.lineSelectionStyle = lineSelectionStyle;  
         }  
   
         public Style getPointHighlightStyle() {  
                 return pointHighlightStyle;  
         }  
   
         public void setPointHighlightStyle(final Style pointHighlightStyle) {  
                 this.pointHighlightStyle = pointHighlightStyle;  
         }  
   
         public Style getPointSelectionStyle() {  
                 return pointSelectionStyle;  
         }  
   
         public void setPointSelectionStyle(final Style pointSelectionStyle) {  
                 this.pointSelectionStyle = pointSelectionStyle;  
         }  
   
         public Style getPolygonHighlightStyle() {  
                 return polygonHighlightStyle;  
         }  
   
         public void setPolygonHighlightStyle(final Style polygonHighlightStyle) {  
                 this.polygonHighlightStyle = polygonHighlightStyle;  
         }  
   
         public Style getPolygonSelectionStyle() {  
                 return polygonSelectionStyle;  
         }  
   
         public void setPolygonSelectionStyle(final Style polygonSelectionStyle) {  
                 this.polygonSelectionStyle = polygonSelectionStyle;  
         }  
   
302          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
303                  super.paintComponent(g);                  super.paintComponent(g);
304    
# Line 510  public class JMapPane extends JPanel imp Line 314  public class JMapPane extends JPanel imp
314                                  try {                                  try {
315                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
316                                  } catch (final IOException e) {                                  } catch (final IOException e) {
317                                          // TODO Auto-generated catch block                                          LOGGER.warn("context.getLayerBounds()", e);
                                         e.printStackTrace();  
318                                  }                                  }
319                          }                          }
320    
# Line 521  public class JMapPane extends JPanel imp Line 324  public class JMapPane extends JPanel imp
324                                  reset = false; /* forget about the reset */                                  reset = false; /* forget about the reset */
325                                  oldRect = r; /* store what the current size is */                                  oldRect = r; /* store what the current size is */
326    
327                                  mapArea = fixAspectRatio(r, mapArea);                                  mapArea = fixAspectRatio(r, mapArea, false);
328                          }                          }
329                  }                  }
330    
# Line 534  public class JMapPane extends JPanel imp Line 337  public class JMapPane extends JPanel imp
337                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
338                  }                  }
339    
340                  if (changed ) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
341                          changed = false;                          changed = false;
342                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
343                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_ARGB);
344    
345                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
346                          /* System.out.println("rendering"); */                          /* System.out.println("rendering"); */
347                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
348                                  renderer.setContext(context);                                  renderer.setContext(context);
349                          labelCache.clear(); // work around anoying labelcache bug                          labelCache.clear(); // work around anoying labelcache bug
350    
# Line 555  public class JMapPane extends JPanel imp Line 358  public class JMapPane extends JPanel imp
358                  }                  }
359    
360                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
   
                 if ((selection != null) && (selection.size() > 0)) {  
                         // paint selection  
   
                         String type = selectionLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getType().getName();  
                         /* String type = selection.getDefaultGeometry().getGeometryType(); */  
                         /* System.out.println(type); */  
                         if (type == null)  
                                 type = "polygon";  
   
                         /* String type = "point"; */  
   
                         if (type.toLowerCase().endsWith("polygon")) {  
                                 selectionStyle = polygonSelectionStyle;  
                         } else if (type.toLowerCase().endsWith("point")) {  
                                 selectionStyle = pointSelectionStyle;  
                         } else if (type.toLowerCase().endsWith("line")) {  
                                 selectionStyle = lineSelectionStyle;  
                         }  
   
                         selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);  
   
                         selectionContext.addLayer(selection, selectionStyle);  
                         selectionRenderer.setContext(selectionContext);  
   
                         selectImage = new BufferedImage(dr.width, dr.height,  
                                         BufferedImage.TYPE_INT_ARGB);  
   
                         final Graphics2D ig = selectImage.createGraphics();  
                         /* System.out.println("rendering selection"); */  
                         selectionRenderer.paint((Graphics2D) ig, dr, mapArea);  
   
                         ((Graphics2D) g).drawImage(selectImage, 0, 0, this);  
                 }  
   
                 if (highlight && (highlightFeature != null)  
                                 && (highlightFeature.size() > 0)) {  
                         /*  
                          * String type = selection.getDefaultGeometry().getGeometryType();  
                          * System.out.println(type); if(type==null) type="polygon";  
                          */  
                         String type = highlightLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getType().getName();  
                         /* String type = selection.getDefaultGeometry().getGeometryType(); */  
                         // System.out.println(type);  
                         if (type == null)  
                                 type = "polygon";  
   
                         /* String type = "point"; */  
                         Style highlightStyle = null;  
                         if (type.toLowerCase().endsWith("polygon")) {  
                                 highlightStyle = polygonHighlightStyle;  
                         } else if (type.toLowerCase().endsWith("point")) {  
                                 highlightStyle = pointHighlightStyle;  
                         } else if (type.toLowerCase().endsWith("line")) {  
                                 highlightStyle = lineHighlightStyle;  
                         }  
   
                         final MapContext highlightContext = new DefaultMapContext(  
                                         DefaultGeographicCRS.WGS84);  
   
                         highlightContext.addLayer(highlightFeature, highlightStyle);  
                         highlightRenderer.setContext(highlightContext);  
   
                         /* System.out.println("rendering highlight"); */  
                         highlightRenderer.paint((Graphics2D) g, dr, mapArea);  
                 }  
361          }          }
362    
363          private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) {          /**
364             * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle
365             * @param grow
366             *            If <code>true</code>, than the area will be enlarged to match
367             *            the aspect ratio. If <code>false</code>, it will only shrink.
368             */
369            private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,
370                            boolean grow) {
371                    
372                    if (mapArea == null) {
373                            LOGGER.warn("mapArea has been null in method fixAspectRatio, returning also NULL");
374                            return null;
375                    }
376                    if ( r == null || r.width == 0 || r.height == 0 ) {
377              LOGGER.warn("Empty rectangle in method fixAspectRatio, returning an unmodified mapArea!");
378              return mapArea;
379                    }
380    
381                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
382                  final double mapHeight = mapArea.getHeight();                  final double mapHeight = mapArea.getHeight();
383                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*
384                                                                                                                           * calculate the new                                                                                                                                   * calculate the
385                                                                                                                           * scale                                                                                                                                   * new scale
386                                                                                                                           */                                                                                                                                   */
387    
388                  final double scaleY = r.getHeight() / mapArea.getHeight();                  final double scaleY = r.getHeight() / mapArea.getHeight();
389                  double scale = 1.0; // stupid compiler!                  double scale = 1.0; // stupid compiler!
390    
391                  if (scaleX < scaleY) { /* pick the smaller scale */                  if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
392                          scale = scaleX;                          scale = scaleX;
393                  } else {                  } else {
394                          scale = scaleY;                          scale = scaleY;
# Line 653  public class JMapPane extends JPanel imp Line 404  public class JMapPane extends JPanel imp
404                   */                   */
405    
406                  /* create the new extent */                  /* create the new extent */
407                  final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),                  final Coordinate ll = new Coordinate(
408                                  mapArea.getMinY() - (deltaY / 2.0));                                  mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
409                  final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),                                                  - (deltaY / 2.0));
410                                  mapArea.getMaxY() + (deltaY / 2.0));                  final Coordinate ur = new Coordinate(
411                                    mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
412                                                    + (deltaY / 2.0));
413    
414                  return new Envelope(ll, ur);                  return new Envelope(ll, ur);
415          }          }
416    
         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;  
         }  
   
417          public void mouseClicked(final MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
418                  if (mapArea == null) return;                  if (mapArea == null)
419                            return;
420                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
421                  // h:"+mapArea.getHeight());                  // h:"+mapArea.getHeight());
422                  final Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
# Line 752  public class JMapPane extends JPanel imp Line 430  public class JMapPane extends JPanel imp
430                  final double width2 = width / 2.0;                  final double width2 = width / 2.0;
431                  final double height2 = height / 2.0;                  final double height2 = height / 2.0;
432                  // xulu.ec                  // xulu.ec
433                  final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();                  final double mapX = ((x * width) / (double) bounds.width)
434                                    + mapArea.getMinX();
435                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
436                                  + mapArea.getMinY();                                  + mapArea.getMinY();
437    
# Line 783  public class JMapPane extends JPanel imp Line 462  public class JMapPane extends JPanel imp
462                          zlevel = 1.0 / zoomFactor;                          zlevel = 1.0 / zoomFactor;
463    
464                          break;                          break;
465                    //
466                  case Select:                  // case Select:
467                          doSelection(mapX, mapY, selectionLayer);                  // doSelection(mapX, mapY, selectionLayer);
468                    //
469                          return;                  // return;
470    
471                  default:                  default:
472                          return;                          return;
# Line 859  public class JMapPane extends JPanel imp Line 538  public class JMapPane extends JPanel imp
538                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
539                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
540                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige
541                                                                                                                          // farbe? am besten                                  // farbe? am besten
542                                                                                                                          // vom L&F die                                  // vom L&F die
543                                                                                                                          // hintergrundfarbe                                  // hintergrundfarbe
544                                                                                                                          // auslesen...                                  // auslesen...
545                                    
546                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
547                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
548                                  graphics.drawImage(panningImage, 0, 0, this);                                  graphics.drawImage(panningImage, 0, 0, this);
# Line 885  public class JMapPane extends JPanel imp Line 564  public class JMapPane extends JPanel imp
564                          lastX = x;                          lastX = x;
565                          lastY = y;                          lastY = y;
566                          drawRectangle(graphics);                          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);  
567                  }                  }
568                    // else if (state == JMapPane.Select && selectionLayer != null) {
569                    //
570                    // // construct a new bbox filter
571                    // final Rectangle bounds = this.getBounds();
572                    //
573                    // final double mapWidth = mapArea.getWidth();
574                    // final double mapHeight = mapArea.getHeight();
575                    //
576                    // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
577                    // + mapArea.getMinX();
578                    // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
579                    // (double) bounds.height)
580                    // + mapArea.getMinY();
581                    // final double x2 = ((x * mapWidth) / (double) bounds.width)
582                    // + mapArea.getMinX();
583                    // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
584                    // bounds.height)
585                    // + mapArea.getMinY();
586                    // final double left = Math.min(x1, x2);
587                    // final double right = Math.max(x1, x2);
588                    // final double bottom = Math.min(y1, y2);
589                    // final double top = Math.max(y1, y2);
590                    //
591                    // String name = selectionLayer.getFeatureSource().getSchema()
592                    // .getDefaultGeometry().getName();
593                    //
594                    // if (name == "") {
595                    // name = "the_geom";
596                    // }
597                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
598                    // top,
599                    // getContext().getCoordinateReferenceSystem().toString());
600                    // if (selectionManager != null) {
601                    // selectionManager.selectionChanged(this, bb);
602                    // }
603                    //
604                    // graphics.setXORMode(Color.green);
605                    //
606                    // /*
607                    // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
608                    // */
609                    //
610                    // // draw new box
611                    // lastX = x;
612                    // lastY = y;
613                    // drawRectangle(graphics);
614                    // }
615    
616          }          }
617    
# Line 938  public class JMapPane extends JPanel imp Line 621  public class JMapPane extends JPanel imp
621          protected void processDrag(final int x1, final int y1, final int x2,          protected void processDrag(final int x1, final int y1, final int x2,
622                          final int y2, final MouseEvent e) {                          final int y2, final MouseEvent e) {
623    
624    
625                  /****                  /****
626                   * If no layer is availabe we dont want a NullPointerException                   * If no layers exist, we ignore the drag.
627                   */                   */
628                  if (mapArea == null)                  if (context.getLayerCount() <= 0) {
629                          return;                          return;
630                    }
631                    
632                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
633                  // + x2 + "," + y2);                  // + x2 + "," + y2);
634                  if ((x1 == x2) && (y1 == y2)) {                  if ((x1 == x2) && (y1 == y2)) {
# Line 989  public class JMapPane extends JPanel imp Line 674  public class JMapPane extends JPanel imp
674                          final Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
675                          // xulu.sc                          // xulu.sc
676                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
677                          setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));                          
678    
679                            setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
680                          // xulu.ec                          // xulu.ec
681                  } else if (state == JMapPane.ZoomIn) {                  } else if (state == JMapPane.ZoomIn) {
682    
# Line 1013  public class JMapPane extends JPanel imp Line 700  public class JMapPane extends JPanel imp
700                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
701    
702                          // sk.sc                          // sk.sc
703  //                      {                          // {
704  //                      // SK tries to paint a preview of the zoom ;-9 aha.... well                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
705  //                      Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
706  //                      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
707  //                                      RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
708  //                      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
709  //                                      RenderingHints.VALUE_ANTIALIAS_OFF);                          // RenderingHints.VALUE_ANTIALIAS_OFF);
710  //                      graphics.setRenderingHint(RenderingHints.KEY_RENDERING,                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
711  //                                      RenderingHints.VALUE_RENDER_SPEED);                          // RenderingHints.VALUE_RENDER_SPEED);
712  //                      graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
713  //                                      JMapPane.this.getHeight(), x1, y1, x2, y2, null);                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
714  //                      }                          // }
715                          // xulu.ec                          // xulu.ec
716                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
717                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
# Line 1053  public class JMapPane extends JPanel imp Line 740  public class JMapPane extends JPanel imp
740                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
741    
742                          // xulu.ec                          // 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(); }  
                          */  
743                  }                  }
744                    // else if (state == JMapPane.Select && selectionLayer != null) {
745                    // final double left = Math.min(startX, endX);
746                    // final double right = Math.max(startX, endX);
747                    // final double bottom = Math.min(startY, endY);
748                    // final double top = Math.max(startY, endY);
749                    //
750                    // String name = selectionLayer.getFeatureSource().getSchema()
751                    // .getDefaultGeometry().getLocalName();
752                    //
753                    // if (name == "") {
754                    // name = "the_geom";
755                    // }
756                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
757                    // top,
758                    // getContext().getCoordinateReferenceSystem().toString());
759                    // // System.out.println(bb.toString());
760                    // if (selectionManager != null) {
761                    // selectionManager.selectionChanged(this, bb);
762                    // }
763                    // /*
764                    // * FeatureCollection fc; selection = null; try { fc =
765                    // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
766                    // * fc; } catch (IOException e) { e.printStackTrace(); }
767                    // */
768                    // }
769    
770                  // xulu.so                  // xulu.so
771                  // setMapArea(mapArea);                  // setMapArea(mapArea);
# Line 1088  public class JMapPane extends JPanel imp Line 777  public class JMapPane extends JPanel imp
777                  return clickable;                  return clickable;
778          }          }
779    
780          private org.geotools.styling.Style setupStyle(final int type, final Color color) {          //
781                  final StyleFactory sf = org.geotools.factory.CommonFactoryFinder          // private org.geotools.styling.Style setupStyle(final int type, final Color
782                                  .getStyleFactory(null);          // color) {
783                  final StyleBuilder sb = new StyleBuilder();          // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
784            // .getStyleFactory(null);
785                  org.geotools.styling.Style s = sf.createStyle();          // final StyleBuilder sb = new StyleBuilder();
786                  s.setTitle("selection");          //
787            // org.geotools.styling.Style s = sf.createStyle();
788                  // TODO parameterise the color          // s.setTitle("selection");
789                  final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);          //
790                  ps.setStroke(sb.createStroke(color));          // // TODO parameterise the color
791            // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
792                  final LineSymbolizer ls = sb.createLineSymbolizer(color);          // ps.setStroke(sb.createStroke(color));
793                  final Graphic h = sb.createGraphic();          //
794                  h.setMarks(new Mark[] { sb.createMark("square", color) });          // final LineSymbolizer ls = sb.createLineSymbolizer(color);
795            // final Graphic h = sb.createGraphic();
796                  final PointSymbolizer pts = sb.createPointSymbolizer(h);          // h.setMarks(new Mark[] { sb.createMark("square", color) });
797            //
798                  // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});          // final PointSymbolizer pts = sb.createPointSymbolizer(h);
799                  switch (type) {          //
800                  case POLYGON:          // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
801                          s = sb.createStyle(ps);          // switch (type) {
802            // case POLYGON:
803                          break;          // s = sb.createStyle(ps);
804            //
805                  case POINT:          // break;
806                          s = sb.createStyle(pts);          //
807            // case POINT:
808                          break;          // s = sb.createStyle(pts);
809            //
810                  case LINE:          // break;
811                          s = sb.createStyle(ls);          //
812                  }          // case LINE:
813            // s = sb.createStyle(ls);
814                  return s;          // }
815          }          //
816            // return s;
817          public void highlightChanged(final HighlightChangedEvent e) {          // }
                 final org.opengis.filter.Filter f = e.getFilter();  
   
                 try {  
                         highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);  
                 } catch (final IOException e1) {  
                         // TODO Auto-generated catch block  
                         e1.printStackTrace();  
                 }  
   
                 repaint();  
         }  
818    
819          public void propertyChange(final PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
820                  final String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
# Line 1220  public class JMapPane extends JPanel imp Line 898  public class JMapPane extends JPanel imp
898          public void mouseMoved(final MouseEvent e) {          public void mouseMoved(final MouseEvent e) {
899          }          }
900    
         public FeatureCollection getSelection() {  
                 return selection;  
         }  
   
         public void setSelection(final FeatureCollection selection) {  
                 this.selection = selection;  
                 repaint();  
         }  
   
         /*  
          * (non-Javadoc)  
          *  
          * @see  
          * org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged  
          * (org.geotools.gui.swing.event.SelectionChangedEvent)  
          */  
         public void selectionChanged(final SelectionChangedEvent e) {  
   
                 try {  
                         selection = selectionLayer.getFeatureSource().getFeatures(  
                                         e.getFilter());  
                         repaint();  
                 } catch (final IOException e1) {  
                         e1.printStackTrace();  
                 }  
         }  
   
         public SelectionManager getSelectionManager() {  
                 return selectionManager;  
         }  
   
         public void setSelectionManager(final SelectionManager selectionManager) {  
                 this.selectionManager = selectionManager;  
                 this.selectionManager.addSelectionChangeListener(this);  
   
         }  
   
901          // xulu.sn          // xulu.sn
902          /**          /**
903           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
# Line 1275  public class JMapPane extends JPanel imp Line 916  public class JMapPane extends JPanel imp
916                  if (env == null)                  if (env == null)
917                          return env;                          return env;
918    
919                    Envelope newArea = null;
920    
921                  /**                  /**
922                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
923                   * easily fail.                   * easily fail.
924                   */                   */
925                  env = fixAspectRatio(this.getBounds(), env);                  env = fixAspectRatio(this.getBounds(), env, false);
926    
927                  final double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
928                  final double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
929                  final double centerY = env.getMinY() + env.getHeight() / 2.;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
930                  double newWidth2;                  double newWidth2 = 0;
931                  double newHeight2;                  double newHeight2 = 0;
932                  if (scale < getMaxZoomScale()) {                  if (scale < getMaxZoomScale()) {
933                          // ****************************************************************************                          // ****************************************************************************
934                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
# Line 1302  public class JMapPane extends JPanel imp Line 945  public class JMapPane extends JPanel imp
945                          // ****************************************************************************                          // ****************************************************************************
946                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
947                          // ****************************************************************************                          // ****************************************************************************
948                          return env;                          newArea = env;
949                  }                  }
950    
951                  final Coordinate ll = new Coordinate(centerX - newWidth2, centerY                  if (newArea == null) {
                                 - newHeight2);  
                 final Coordinate ur = new Coordinate(centerX + newWidth2, centerY  
                                 + newHeight2);  
952    
953                  return new Envelope(ll, ur);                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
954                                            - newHeight2);
955                            final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
956                                            + newHeight2);
957    
958                            newArea = new Envelope(ll, ur);
959                    }
960    
961                    Envelope maxAllowedExtend = getMaxExtend();
962                    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()) ) {
963                            /*
964                             * If a maxExtend is set, we have to honour that...
965                             */
966    
967                            // Exceeds top? Move down and maybe cut
968                            if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
969                                    double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
970    //                              LOGGER.debug("Moving area down by " + divY);
971    
972                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
973                                                    newArea.getMinY() - divY), new Coordinate(newArea
974                                                    .getMaxX(), newArea.getMaxY() - divY));
975    
976                                    if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
977    //                                      LOGGER.debug("Now it exeeds the bottom border.. cut!");
978                                            // And cut the bottom if it moved out of the area
979                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
980                                                            maxAllowedExtend.getMinY()), new Coordinate(newArea
981                                                            .getMaxX(), newArea.getMaxY()));
982    
983    //                                      LOGGER.debug("and fix aspect ratio");
984    
985                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
986                                    }
987                            }
988    
989                            // Exceeds bottom? Move up and maybe cut
990                            if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
991                                    double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
992    //                              LOGGER.debug("Moving area up by " + divY);
993    
994                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
995                                                    newArea.getMinY() - divY), new Coordinate(newArea
996                                                    .getMaxX(), newArea.getMaxY() - divY));
997    
998                                    if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
999    //                                      LOGGER.debug("Now it exeeds the top border.. cut!");
1000                                            // And cut the bottom if it moved out of the area
1001                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1002                                                            newArea.getMinY()), new Coordinate(newArea
1003                                                            .getMaxX(), maxAllowedExtend.getMaxY()));
1004    
1005    //                                      LOGGER.debug("and fix aspect ratio");
1006    
1007                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1008                                    }
1009                            }
1010    
1011                            // Exceeds to the right? move and maybe cut
1012                            if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1013    
1014                                    // Move left..
1015                                    double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
1016    //                              LOGGER.debug("Moving area left by " + divX);
1017    
1018                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1019                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1020                                                    - divX, newArea.getMaxY()));
1021    
1022                                    if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1023    //                                      LOGGER.debug("Now it exeeds the left border.. cut!");
1024                                            // And cut the left if it moved out of the area
1025                                            newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(),
1026                                                            newArea.getMinY()), new Coordinate(newArea
1027                                                            .getMaxX(), newArea.getMaxY()));
1028    
1029    //                                      LOGGER.debug("and fix aspect ratio");
1030    
1031                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1032                                    }
1033                            }
1034    
1035                            // Exceeds to the left? move and maybe cut
1036                            if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1037    
1038                                    // Move right..
1039                                    double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
1040    //                              LOGGER.debug("Moving area right by " + divX);
1041    
1042                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1043                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1044                                                    - divX, newArea.getMaxY()));
1045    
1046                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1047    //                                      LOGGER.debug("Now it exeeds the right border.. cut!");
1048                                            // And cut the left if it moved out of the area
1049                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1050                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
1051                                                            .getMaxX(), newArea.getMaxY()));
1052    
1053    //                                      LOGGER.debug("and fix aspect ratio");
1054    
1055                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1056                                    }
1057                            }
1058    
1059                    }
1060    
1061                    return newArea;
1062          }          }
1063    
1064          /**          /**
# Line 1343  public class JMapPane extends JPanel imp Line 1091  public class JMapPane extends JPanel imp
1091           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1092           */           */
1093          public void setMaxZoomScale(final Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
                 // System.out.println("setting max scale to "+maxZoomScale);  
1094                  this.maxZoomScale = maxZoomScale;                  this.maxZoomScale = maxZoomScale;
1095          }          }
1096    
# Line 1357  public class JMapPane extends JPanel imp Line 1104  public class JMapPane extends JPanel imp
1104          public void setMinZoomScale(final Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1105                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale;
1106          }          }
1107          // xulu.en  
1108            /**
1109             * Defines an evelope of the viwable area. The JMapPane will never show
1110             * anything outside of this extend.
1111             *
1112             * @param maxExtend
1113             *            <code>null</code> to not have this restriction.
1114             */
1115            public void setMaxExtend(Envelope maxExtend) {
1116                    this.maxExtend = maxExtend;
1117            }
1118    
1119            /**
1120             * Returns the evelope of the viewable area. The JMapPane will never show
1121             * anything outside of this extend. If this has been set to
1122             * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1123             * quickly the context's bounds. It it takes to long to determine the
1124             * context bounds, <code>null</code> is returned.
1125             *
1126             * @param maxExtend
1127             *            <code>null</code> to not have this restriction.
1128             */
1129    
1130            public Envelope getMaxExtend() {
1131                    if (maxExtend == null) {
1132                            try {
1133                                    return fixAspectRatio(
1134                                        this.getBounds(),
1135                            // Kartenbereich um 10% vergroessern
1136                                        JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1137                                        true
1138                                    );
1139                            } catch (IOException e) {
1140                                    LOGGER.warn(
1141                                                                    "maxExtend == null; failed to getLayerBounds of context",
1142                                                                    e);
1143                            }
1144                    }
1145                    return maxExtend;
1146            }
1147    
1148  }  }

Legend:
Removed from v.320  
changed lines
  Added in v.493

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26