/[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

trunk/src/org/geotools/gui/swing/JMapPane.java revision 2 by mojays, Tue Feb 24 22:43:52 2009 UTC branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java revision 431 by alfonx, Sun Oct 4 16:55:52 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>
20   *    Code taken from gt-2.4.2 to make some changes (marked with {@code xulu}),   *    Code taken from gt-2.4.5 to make some changes (marked with {@code xulu}),
21   *    which can not be realized in a subclass:</b>   *    which can not be realized in a subclass:</b>
22   *    <ul>   *    <ul>
23   *       <li>{@link #getMapArea()} declared as {@code final}<li>   *       <li>{@link #getMapArea()} declared as {@code final}<li>
# 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.gui.swing.event.HighlightChangeListener;  
 import org.geotools.gui.swing.event.HighlightChangedEvent;  
 import org.geotools.gui.swing.event.SelectionChangeListener;  
 import org.geotools.gui.swing.event.SelectionChangedEvent;  
 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;
68  import org.geotools.styling.Graphic;  import org.geotools.renderer.shape.ShapefileRenderer;
 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;  
69  import org.opengis.filter.FilterFactory2;  import org.opengis.filter.FilterFactory2;
70  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
71    
# Line 90  import schmitzm.swing.SwingUtil; Line 73  import schmitzm.swing.SwingUtil;
73    
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, PropertyChangeListener,                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {
80          MapLayerListListener {          private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());
     private static Logger LOGGER = Logger.getLogger( JMapPane.class.getName() );  
    /**  
      *  
      */  
     private static final long serialVersionUID = -8647971481359690499L;  
81    
82      public static final int Reset = 0;          private static final long serialVersionUID = -8647971481359690499L;
83    
84      public static final int ZoomIn = 1;          public static final int Reset = 0;
85    
86      public static final int ZoomOut = 2;          public static final int ZoomIn = 1;
87    
88      public static final int Pan = 3;          public static final int ZoomOut = 2;
89    
90      public static final int Select = 4;          public static final int Pan = 3;
91    
92      private static final int POLYGON = 0;          public static final int Select = 4;
93    
94      private static final int LINE = 1;          /**
95             * what renders the map
96             */
97            GTRenderer renderer;
98    
99      private static final int POINT = 2;          /**
100             * the map context to render
101             */
102            MapContext context;
103    
104      /**          /**
105       * what renders the map           * the area of the map to draw
106       */           */
107      GTRenderer renderer;          protected Envelope mapArea;
108    
109      private GTRenderer highlightRenderer, selectionRenderer;          /**
110             * the size of the pane last time we drew
111             */
112            protected Rectangle oldRect = null;
113    
114      /**          /**
115       * the map context to render           * the last map area drawn.
116       */           */
117      MapContext context;          protected Envelope oldMapArea = null;
118    
119      private MapContext selectionContext;          /**
120             * the base image of the map
121             */
122            protected BufferedImage baseImage, panningImage;
123    
124      /**          /**
125       * the area of the map to draw           * a factory for filters
126       */           */
127  //xulu.sc          FilterFactory2 ff;
 //    Envelope mapArea;  
     protected Envelope mapArea;  
 //xulu.ec  
128    
129      /**          /**
130       * the size of the pane last time we drew           * a factory for geometries
131       */           */
132  //xulu.sc          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
 //    private Rectangle oldRect = null;  
     protected Rectangle oldRect = null;  
 //xulu.ec  
133    
134      /**          private int state = ZoomIn;
      * the last map area drawn.  
      */  
 //xulu.sc  
 //    private Envelope oldMapArea = null;  
     protected Envelope oldMapArea = null;  
 //xulu.ec  
135    
136      /**          /**
137       * the base image of the map           * how far to zoom in or out
138       */           */
139      protected  BufferedImage baseImage, panningImage;          private double zoomFactor = 2.0;
     // SK: private BufferedImage baseImage, panningImage;  
140    
141      /**          boolean changed = true;
      * image of selection  
      */  
     private BufferedImage selectImage;  
142    
143      /**          LabelCache labelCache = new LabelCacheImpl();
      * style for selected items  
      */  
     private Style selectionStyle;  
144    
145      /**          protected boolean reset = false;
      * layer that selection works on  
      */  
     private MapLayer selectionLayer;  
146    
147      /**          int startX;
      * layer that highlight works on  
      */  
     private MapLayer highlightLayer;  
148    
149      /**          int startY;
      * the object which manages highlighting  
      */  
     private HighlightManager highlightManager;  
150    
151      /**          /**
152       * is highlighting on or off           * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
153       */           * out of that area
154      private boolean highlight = true;           **/
155            private Envelope maxExtend = null;
156    
157      /**          // /**
158       * a factory for filters          // * 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      FilterFactory2 ff;          // **/
161            // boolean maxExtendForceMode = true;
162    
163      /**          private boolean clickable;
      * a factory for geometries  
      */  
     GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);  
164    
165      /**          int lastX;
      * the collections of features to be selected or highlighted  
      */  
     FeatureCollection selection;  
166    
167      /**          int lastY;
      * the collections of features to be selected or highlighted  
      */  
     FeatureCollection highlightFeature;  
168    
169      private int state = ZoomIn;          private Double maxZoomScale = Double.MIN_VALUE;
170            private Double minZoomScale = Double.MAX_VALUE;
171    
172      /**          /**
173       * how far to zoom in or out           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
174       */           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
175      private double zoomFactor = 2.0;           * setzen.
176             */
     Style lineHighlightStyle;  
   
     Style pointHighlightStyle;  
   
     Style polygonHighlightStyle;  
   
     Style polygonSelectionStyle;  
   
     Style pointSelectionStyle;  
   
     Style lineSelectionStyle;  
   
     boolean changed = true;  
   
     LabelCache labelCache = new LabelCacheDefault();  
   
 //xulu.sc  
 //    private boolean reset = false;  
     protected boolean reset = false;  
 //xulu.ec  
   
     int startX;  
   
     int startY;  
   
     private boolean clickable;  
   
     int lastX;  
   
     int lastY;  
   
     private SelectionManager selectionManager;  
 //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 setzen.  
      */  
177          private boolean panning_started = false;          private boolean panning_started = false;
 // sk.en          
178    
179      public JMapPane() {          public JMapPane() {
180          this(null, true, null, null);                  this(null, true, null, null);
181      }          }
182    
183      /**          /**
184       * create a basic JMapPane           * create a basic JMapPane
185       *           *
186       * @param render -           * @param render
187       *            how to draw the map           *            - how to draw the map
188       * @param context -           * @param context
189       *            the map context to display           *            - the map context to display
190       */           */
191      public JMapPane(GTRenderer render, MapContext context) {          public JMapPane(final GTRenderer render, final MapContext context) {
192          this(null, true, render, context);                  this(null, true, render, context);
193      }          }
194    
195      /**          /**
196       * full constructor extending JPanel           * full constructor extending JPanel
197       *           *
198       * @param layout -           * @param layout
199       *            layout (probably shouldn't be set)           *            - layout (probably shouldn't be set)
200       * @param isDoubleBuffered -           * @param isDoubleBuffered
201       *            a Swing thing I don't really understand           *            - a Swing thing I don't really understand
202       * @param render -           * @param render
203       *            what to draw the map with           *            - what to draw the map with
204       * @param context -           * @param context
205       *            what to draw           *            - what to draw
206       */           */
207      public JMapPane(LayoutManager layout, boolean isDoubleBuffered,          public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered,
208              GTRenderer render, MapContext context) {                          final GTRenderer render, final MapContext context) {
209          super(layout, isDoubleBuffered);                  super(layout, isDoubleBuffered);
210    
211          ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder                  ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
212                  .getFilterFactory(null);                                  .getFilterFactory(null);
213          setRenderer(render);                  setRenderer(render);
214    
215          setContext(context);                  setContext(context);
216    
217          this.addMouseListener(this);                  this.addMouseListener(this);
218          this.addMouseMotionListener(this);                  this.addMouseMotionListener(this);
219          setHighlightManager(new HighlightManager(highlightLayer));                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
220          setSelectionManager(new SelectionManager(selectionLayer));          }
221          lineHighlightStyle = setupStyle(LINE, Color.red);  
222            /**
223          pointHighlightStyle = setupStyle(POINT, Color.red);           * get the renderer
224             */
225          polygonHighlightStyle = setupStyle(POLYGON, Color.red);          public GTRenderer getRenderer() {
226                    return renderer;
227          polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);          }
228    
229          pointSelectionStyle = setupStyle(POINT, Color.cyan);          public void setRenderer(final GTRenderer renderer) {
230                    Map<Object, Object> hints = new HashMap<Object, Object>();
231          lineSelectionStyle = setupStyle(LINE, Color.cyan);  
232          setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));                  this.renderer = renderer;
233      }  
234                    if (renderer instanceof StreamingRenderer
235      /**                                  || renderer instanceof ShapefileRenderer) {
236       * get the renderer                          hints = renderer.getRendererHints();
237       */                          if (hints == null) {
238      public GTRenderer getRenderer() {                                  hints = new HashMap<Object, Object>();
239          return renderer;                          }
240      }                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
241                                    labelCache = (LabelCache) hints
242      public void setRenderer(GTRenderer renderer) {                                                  .get(StreamingRenderer.LABEL_CACHE_KEY);
243          Map hints = new HashMap();                          } else {
244          if (renderer instanceof StreamingRenderer) {                                  hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
245              hints = renderer.getRendererHints();                          }
246              if (hints == null) {  
247                  hints = new HashMap();                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);
248              }  
249              if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {                          renderer.setRendererHints(hints);
250                  labelCache = (LabelCache) hints                  }
251                          .get(StreamingRenderer.LABEL_CACHE_KEY);  
252              } else {                  // this.highlightRenderer = new StreamingRenderer();
253                  hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);                  // this.selectionRenderer = new StreamingRenderer();
254              }  
255              renderer.setRendererHints(hints);                  // highlightRenderer.setRendererHints(hints);
256          }                  // selectionRenderer.setRendererHints(hints);
257    
258          this.renderer = renderer;                  // renderer.setRendererHints(hints);
259          this.highlightRenderer = new StreamingRenderer();  
260          this.selectionRenderer = new StreamingRenderer();                  if (this.context != null) {
261                            this.renderer.setContext(this.context);
262          hints.put("memoryPreloadingEnabled", Boolean.FALSE);                  }
263          highlightRenderer.setRendererHints(hints);          }
264          selectionRenderer.setRendererHints(hints);  
265            public MapContext getContext() {
266          if (this.context != null) {                  return context;
267              this.renderer.setContext(this.context);          }
268          }  
269      }          public void setContext(final MapContext context) {
270                    if (this.context != null) {
271      public MapContext getContext() {                          this.context.removeMapLayerListListener(this);
272          return context;                  }
273      }  
274                    this.context = context;
275      public void setContext(MapContext context) {  
276          if (this.context != null) {                  if (context != null) {
277              this.context.removeMapLayerListListener(this);                          this.context.addMapLayerListListener(this);
278          }                  }
279    
280          this.context = context;                  if (renderer != null) {
281                            renderer.setContext(this.context);
282          if (context != null) {                  }
283              this.context.addMapLayerListListener(this);          }
284          }  
285            public Envelope getMapArea() {
286          if (renderer != null) {                  return mapArea;
287              renderer.setContext(this.context);          }
288          }  
289      }          public void setMapArea(final Envelope mapArea) {
290                    this.mapArea = mapArea;
291      public Envelope getMapArea() {          }
292          return mapArea;  
293      }          public int getState() {
294                    return state;
295      public void setMapArea(Envelope mapArea) {          }
296          this.mapArea = mapArea;  
297      }          public void setState(final int state) {
298                    this.state = state;
299      public int getState() {  
300          return state;                  // System.out.println("State: " + state);
301      }          }
302    
303      public void setState(int state) {          public double getZoomFactor() {
304          this.state = state;                  return zoomFactor;
305            }
306          // System.out.println("State: " + state);  
307      }          public void setZoomFactor(final double zoomFactor) {
308                    this.zoomFactor = zoomFactor;
309      public double getZoomFactor() {          }
310          return zoomFactor;  
311      }          protected void paintComponent(final Graphics g) {
312                    super.paintComponent(g);
313      public void setZoomFactor(double zoomFactor) {  
314          this.zoomFactor = zoomFactor;                  if ((renderer == null) || (mapArea == null)) {
315      }                          return;
316                    }
317      public MapLayer getSelectionLayer() {  
318          return selectionLayer;                  final Rectangle r = getBounds();
319      }                  final Rectangle dr = new Rectangle(r.width, r.height);
320    
321      public void setSelectionLayer(MapLayer selectionLayer) {                  if (!r.equals(oldRect) || reset) {
322          this.selectionLayer = selectionLayer;                          if (!r.equals(oldRect) && (mapArea == null)) {
323          if(selectionManager!=null) {                                  try {
324              selectionManager.setSelectionLayer(selectionLayer);                                          mapArea = context.getLayerBounds();
325          }                                  } catch (final IOException e) {
326      }                                          LOGGER.warn("context.getLayerBounds()", e);
327                                    }
328      public boolean isHighlight() {                          }
329          return highlight;  
330      }                          if (mapArea != null) {
331                                    /* either the viewer size has changed or we've done a reset */
332      public void setHighlight(boolean highlight) {                                  changed = true; /* note we need to redraw */
333          this.highlight = highlight;                                  reset = false; /* forget about the reset */
334      }                                  oldRect = r; /* store what the current size is */
335    
336      public MapLayer getHighlightLayer() {                                  mapArea = fixAspectRatio(r, mapArea, false);
337          return highlightLayer;                          }
338      }                  }
339    
340      public void setHighlightLayer(MapLayer highlightLayer) {                  if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */
341          this.highlightLayer = highlightLayer;                          changed = true;
342                            oldMapArea = mapArea;
343          if (highlightManager != null) {                          // when we tell the context that the bounds have changed WMSLayers
344              highlightManager.setHighlightLayer(highlightLayer);                          // can refresh them selves
345          }                          context.setAreaOfInterest(mapArea, context
346      }                                          .getCoordinateReferenceSystem());
347                    }
348      public HighlightManager getHighlightManager() {  
349          return highlightManager;                  if (changed) { /* if the map changed then redraw */
350      }                          changed = false;
351                            baseImage = new BufferedImage(dr.width, dr.height,
352      public void setHighlightManager(HighlightManager highlightManager) {                                          BufferedImage.TYPE_INT_ARGB);
353          this.highlightManager = highlightManager;  
354          this.highlightManager.addHighlightChangeListener(this);                          final Graphics2D ig = baseImage.createGraphics();
355          this.addMouseMotionListener(this.highlightManager);                          /* System.out.println("rendering"); */
356      }                          if (renderer.getContext() != null)
357                                    renderer.setContext(context);
358      public Style getLineHighlightStyle() {                          labelCache.clear(); // work around anoying labelcache bug
359          return lineHighlightStyle;  
360      }                          // draw the map
361                            renderer.paint((Graphics2D) ig, dr, mapArea);
362      public void setLineHighlightStyle(Style lineHighlightStyle) {  
363          this.lineHighlightStyle = lineHighlightStyle;                          // TODO nur machen, wenn panning beginnt
364      }                          panningImage = new BufferedImage(dr.width, dr.height,
365                                            BufferedImage.TYPE_INT_RGB);
366      public Style getLineSelectionStyle() {  
367          return lineSelectionStyle;                  }
368      }  
369                    ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
370      public void setLineSelectionStyle(Style lineSelectionStyle) {          }
371          this.lineSelectionStyle = lineSelectionStyle;  
372      }          /**
373             * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle
374      public Style getPointHighlightStyle() {           * @param grow
375          return pointHighlightStyle;           *            If <code>true</code>, than the area will be enlarged to match
376      }           *            the aspect ratio. If <code>false</code>, it will only shrink.
377             */
378      public void setPointHighlightStyle(Style pointHighlightStyle) {          private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,
379          this.pointHighlightStyle = pointHighlightStyle;                          boolean grow) {
380      }                  
381                    if (mapArea == null) {
382      public Style getPointSelectionStyle() {                          LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified ");
383          return pointSelectionStyle;                  }
384      }  
385                    final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
386      public void setPointSelectionStyle(Style pointSelectionStyle) {                  final double mapHeight = mapArea.getHeight();
387          this.pointSelectionStyle = pointSelectionStyle;                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*
388      }                                                                                                                                   * calculate the
389                                                                                                                                     * new scale
390      public Style getPolygonHighlightStyle() {                                                                                                                                   */
391          return polygonHighlightStyle;  
392      }                  final double scaleY = r.getHeight() / mapArea.getHeight();
393                    double scale = 1.0; // stupid compiler!
394      public void setPolygonHighlightStyle(Style polygonHighlightStyle) {  
395          this.polygonHighlightStyle = polygonHighlightStyle;                  if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
396      }                          scale = scaleX;
397                    } else {
398      public Style getPolygonSelectionStyle() {                          scale = scaleY;
399          return polygonSelectionStyle;                  }
400      }  
401                    /* calculate the difference in width and height of the new extent */
402      public void setPolygonSelectionStyle(Style polygonSelectionStyle) {                  final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);
403          this.polygonSelectionStyle = polygonSelectionStyle;                  final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);
404      }  
405                    /*
406      protected void paintComponent(Graphics g) {                   * System.out.println("delta x " + deltaX);
407          super.paintComponent(g);                   * System.out.println("delta y " + deltaY);
408                     */
409          if ((renderer == null) || (mapArea == null)  ) {  
410              return;                  /* create the new extent */
411          }                  final Coordinate ll = new Coordinate(
412                                    mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
413          Rectangle r = getBounds();                                                  - (deltaY / 2.0));
414          Rectangle dr = new Rectangle(r.width, r.height);                  final Coordinate ur = new Coordinate(
415                                    mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
416          if (!r.equals(oldRect) || reset) {                                                  + (deltaY / 2.0));
417                  if(!r.equals(oldRect) && (mapArea == null)) {  
418                          try {                  return new Envelope(ll, ur);
419                                          mapArea=context.getLayerBounds();          }
420                                  } catch (IOException e) {  
421                                          // TODO Auto-generated catch block          public void mouseClicked(final MouseEvent e) {
422                                          e.printStackTrace();                  if (mapArea == null)
423                                  }                          return;
424                  }                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
425                                    // h:"+mapArea.getHeight());
426                  if (mapArea != null){                  final Rectangle bounds = this.getBounds();
427                          /* either the viewer size has changed or we've done a reset */                  final double x = (double) (e.getX());
428                          changed = true; /* note we need to redraw */                  final double y = (double) (e.getY());
429                          reset = false; /* forget about the reset */                  final double width = mapArea.getWidth();
430                          oldRect = r; /* store what the current size is */                  final double height = mapArea.getHeight();
431                                            // xulu.sc
432                          mapArea = fixAspectRatio(r, mapArea);                  // double width2 = mapArea.getWidth() / 2.0;
433                  }                  // double height2 = mapArea.getHeight() / 2.0;
434          }                  final double width2 = width / 2.0;
435                    final double height2 = height / 2.0;
436          if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */                  // xulu.ec
437              changed = true;                  final double mapX = ((x * width) / (double) bounds.width)
438              oldMapArea = mapArea;                                  + mapArea.getMinX();
439  //          when we tell the context that the bounds have changed WMSLayers                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
440              // can refresh them selves                                  + mapArea.getMinY();
441              context.setAreaOfInterest(mapArea, context  
442                      .getCoordinateReferenceSystem());                  /*
443          }                   * System.out.println(""+x+"->"+mapX);
444                     * System.out.println(""+y+"->"+mapY);
445          if (changed) { /* if the map changed then redraw */                   */
446              changed = false;  
447              baseImage = new BufferedImage(dr.width, dr.height,                  /*
448                      BufferedImage.TYPE_INT_ARGB);                   * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());
449                     * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());
450              Graphics2D ig = baseImage.createGraphics();                   */
451              /* System.out.println("rendering"); */                  double zlevel = 1.0;
452              renderer.setContext(context);  
453              labelCache.clear(); // work around anoying labelcache bug                  switch (state) {
454                    case Pan:
455                            zlevel = 1.0;
456              // draw the map                          // xulu.sc SK: return here.. a mouselistener is managing the PANNING
457              renderer.paint((Graphics2D) ig, dr, mapArea);                          // break;
458                            return;
459              // TODO , nur machen, wenn panning beginnt                          // xulu.ec
460              panningImage = new BufferedImage(dr.width, dr.height,                  case ZoomIn:
461                          BufferedImage.TYPE_INT_RGB);                          zlevel = zoomFactor;
462                
463          }                          break;
464    
465          ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  case ZoomOut:
466                            zlevel = 1.0 / zoomFactor;
467          if ((selection != null) && (selection.size() > 0)) {  
468              // paint selection                          break;
469                    //
470              String type = selectionLayer.getFeatureSource().getSchema()                  // case Select:
471              .getDefaultGeometry().getType().getName();                  // doSelection(mapX, mapY, selectionLayer);
472              /*String type = selection.getDefaultGeometry().getGeometryType();*/                  //
473              /*System.out.println(type);*/                  // return;
474              if (type == null)  
475                  type = "polygon";                  default:
476                            return;
477              /* String type = "point"; */                  }
478    
479              if (type.toLowerCase().endsWith("polygon")) {                  final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY
480                  selectionStyle = polygonSelectionStyle;                                  - (height2 / zlevel));
481              } else if (type.toLowerCase().endsWith("point")) {                  final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY
482                  selectionStyle = pointSelectionStyle;                                  + (height2 / zlevel));
483              } else if (type.toLowerCase().endsWith("line")) {                  // xulu.sc SK: Check for min/max scale
484                  selectionStyle = lineSelectionStyle;                  // mapArea = new Envelope(ll, ur);
485              }                  final Envelope newMapArea = new Envelope(ll, ur);
486                    setMapArea(bestAllowedMapArea(newMapArea));
487              selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);                  // xulu.ec
488    
489              selectionContext.addLayer(selection, selectionStyle);                  // sk.ec
490              selectionRenderer.setContext(selectionContext);  
491                    // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"
492              selectImage = new BufferedImage(dr.width, dr.height,                  // h:"+mapArea.getHeight());
493                      BufferedImage.TYPE_INT_ARGB);                  repaint();
494            }
495              Graphics2D ig = selectImage.createGraphics();  
496              /* System.out.println("rendering selection"); */          public void mouseEntered(final MouseEvent e) {
497              selectionRenderer.paint((Graphics2D) ig, dr, mapArea);          }
498    
499              ((Graphics2D) g).drawImage(selectImage, 0, 0, this);          public void mouseExited(final MouseEvent e) {
500          }          }
501    
502          if (highlight && (highlightFeature != null)          public void mousePressed(final MouseEvent e) {
503                  && (highlightFeature.size() > 0)) {                  startX = e.getX();
504              /*                  startY = e.getY();
505               * String type = selection.getDefaultGeometry().getGeometryType();                  lastX = 0;
506               * System.out.println(type); if(type==null) type="polygon";                  lastY = 0;
507               */          }
508              String type = highlightLayer.getFeatureSource().getSchema()  
509              .getDefaultGeometry().getType().getName();          public void mouseReleased(final MouseEvent e) {
510              /*String type = selection.getDefaultGeometry().getGeometryType();*/                  final int endX = e.getX();
511              //System.out.println(type);                  final int endY = e.getY();
512              if (type == null)  
513                  type = "polygon";                  processDrag(startX, startY, endX, endY, e);
514                    lastX = 0;
515              /* String type = "point"; */                  lastY = 0;
516              Style highlightStyle = null;  
517              if (type.toLowerCase().endsWith("polygon")) {                  /**
518                  highlightStyle = polygonHighlightStyle;                   * Es wird nicht (mehr) gepannt!
519              } else if (type.toLowerCase().endsWith("point")) {                   */
520                  highlightStyle = pointHighlightStyle;                  panning_started = false;
521              } else if (type.toLowerCase().endsWith("line")) {          }
522                  highlightStyle = lineHighlightStyle;  
523              }          public void mouseDragged(final MouseEvent e) {
524                    final Graphics graphics = this.getGraphics();
525                    final int x = e.getX();
526                    final int y = e.getY();
527    
528              MapContext highlightContext = new DefaultMapContext(                  if ((state == JMapPane.Pan)
529                      DefaultGeographicCRS.WGS84);                                  || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
530                            /**
531              highlightContext.addLayer(highlightFeature, highlightStyle);                           * SK: Der Cursor wird auf PANNING gesetzt.
532              highlightRenderer.setContext(highlightContext);                           */
533                            if (panning_started == false) {
534              /* System.out.println("rendering highlight"); */                                  panning_started = true;
535              highlightRenderer.paint((Graphics2D) g, dr, mapArea);                                  setCursor(SwingUtil.PANNING_CURSOR);
536          }                          }
537      }  
538                            // move the image with the mouse
539      private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {                          if ((lastX > 0) && (lastY > 0)) {
540                                            final int dx = lastX - startX;
541          double mapWidth = mapArea.getWidth(); /* get the extent of the map */                                  final int dy = lastY - startY;
542          double mapHeight = mapArea.getHeight();                                  // System.out.println("translate "+dx+","+dy);
543          double scaleX = r.getWidth() / mapArea.getWidth(); /*                                  final Graphics2D g2 = panningImage.createGraphics();
544                                                               * calculate the new                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige
545                                                               * scale                                  // farbe? am besten
546                                                               */                                  // vom L&F die
547                                    // hintergrundfarbe
548          double scaleY = r.getHeight() / mapArea.getHeight();                                  // auslesen...
549          double scale = 1.0; // stupid compiler!  
   
         if (scaleX < scaleY) { /* pick the smaller scale */  
             scale = scaleX;  
         } else {  
             scale = scaleY;  
         }  
   
         /* calculate the difference in width and height of the new extent */  
         double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);  
         double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);  
   
         /*  
          * System.out.println("delta x " + deltaX); System.out.println("delta y " +  
          * deltaY);  
          */  
   
         /* create the new extent */  
         Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),  
                 mapArea.getMinY() - (deltaY / 2.0));  
         Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),  
                 mapArea.getMaxY() + (deltaY / 2.0));  
   
         return new Envelope(ll, ur);  
     }  
   
     public void doSelection(double x, double y, MapLayer layer) {  
   
         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(Geometry geometry, MapLayer layer)  
             throws IndexOutOfBoundsException {  
         org.opengis.filter.spatial.BinarySpatialOperator f = null;  
   
   
         if ((context == null) || (layer==null)) {  
             return ;  
         }  
   
   
   
         try {  
             String name = layer.getFeatureSource().getSchema()  
                     .getDefaultGeometry().getName();  
   
             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 (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()) { Feature feat =  
              * (Feature) fi.next(); System.out.println("selected " +  
              * feat.getAttribute("STATE_NAME")); }  
              */  
         } catch (IllegalFilterException e) {  
             // TODO Auto-generated catch block  
             e.printStackTrace();  
         }  
         return ;  
     }  
   
     public void mouseClicked(MouseEvent e) {  
         // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"  
         // h:"+mapArea.getHeight());  
         Rectangle bounds = this.getBounds();  
         double x = (double) (e.getX());  
         double y = (double) (e.getY());  
         double width = mapArea.getWidth();  
         double height = mapArea.getHeight();  
 //xulu.sc  
 //        double width2 = mapArea.getWidth() / 2.0;  
 //        double height2 = mapArea.getHeight() / 2.0;  
         double width2 = width / 2.0;  
         double height2 = height / 2.0;  
 //xulu.ec  
         double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();  
         double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)  
                 + mapArea.getMinY();  
   
         /*  
          * System.out.println(""+x+"->"+mapX);  
          * System.out.println(""+y+"->"+mapY);  
          */  
   
         /*  
          * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());  
          * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());  
          */  
         double zlevel = 1.0;  
   
         switch (state) {  
         case Pan:  
             zlevel = 1.0;  
 //xulu.sc SK: return here.. a mouselistener is maanaging the PANNING  
 //            break;  
             return;  
 //xulu.ec  
         case ZoomIn:  
             zlevel = zoomFactor;  
   
             break;  
   
         case ZoomOut:  
             zlevel = 1.0 / zoomFactor;  
   
             break;  
   
         case Select:  
             doSelection(mapX, mapY, selectionLayer);  
   
   
             return;  
   
         default:  
             return;  
         }  
   
         Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY  
                 - (height2 / zlevel));  
         Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY  
                 + (height2 / zlevel));  
 //xulu.sc SK: Check for min/max scale  
 //        mapArea = new Envelope(ll, ur);  
         final Envelope newMapArea = new Envelope(ll, ur);  
         setMapArea( bestAllowedMapArea( newMapArea ) );  
 //xulu.ec  
   
         // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"  
         // h:"+mapArea.getHeight());  
         repaint();  
     }  
   
     public void mouseEntered(MouseEvent e) {  
     }  
   
     public void mouseExited(MouseEvent e) {  
     }  
   
     public void mousePressed(MouseEvent e) {  
         startX = e.getX();  
         startY = e.getY();  
         lastX = 0;  
         lastY = 0;  
     }  
       
     public void mouseReleased(MouseEvent e) {  
         int endX = e.getX();  
         int endY = e.getY();  
           
         processDrag(startX, startY, endX, endY, e);  
         lastX = 0;  
         lastY = 0;  
           
         /**  
          * Es wird nicht (mehr) gepannt!  
          */  
         panning_started = false;  
     }  
   
     public void mouseDragged(MouseEvent e) {  
         Graphics graphics = this.getGraphics();  
         int x = e.getX();  
         int y = e.getY();  
           
   
         if ( (state == JMapPane.Pan) || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0))  {  
             /**  
              * SK:  
              * Der Cursor wird auf PANNING gesetzt.  
              */  
                 if (panning_started == false){  
                         panning_started = true;  
                         setCursor( SwingUtil.PANNING_CURSOR );  
                 }  
                   
                   
             // move the image with the mouse  
             if ((lastX > 0) && (lastY > 0)) {  
                 int dx = lastX - startX;  
                 int dy = lastY - startY;  
                 // 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...  
550                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
551                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
552                  graphics.drawImage(panningImage, 0, 0, this);                                  graphics.drawImage(panningImage, 0, 0, this);
553              }                          }
554    
555              lastX = x;                          lastX = x;
556              lastY = y;                          lastY = y;
557          } else                  } else
558                    
559          if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {                  if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {
560            
561                                    graphics.setXORMode(Color.WHITE);
562              graphics.setXORMode(Color.WHITE);  
563                            if ((lastX > 0) && (lastY > 0)) {
564              if ((lastX > 0) && (lastY > 0)) {                                  drawRectangle(graphics);
565                  drawRectangle(graphics);                          }
566              }  
567                            // draw new box
568              // draw new box                          lastX = x;
569              lastX = x;                          lastY = y;
570              lastY = y;                          drawRectangle(graphics);
571              drawRectangle(graphics);                  }
572          } else if (state == JMapPane.Select && selectionLayer != null) {                  // else if (state == JMapPane.Select && selectionLayer != null) {
573                    //
574              // construct a new bbox filter                  // // construct a new bbox filter
575              Rectangle bounds = this.getBounds();                  // final Rectangle bounds = this.getBounds();
576                    //
577              double mapWidth = mapArea.getWidth();                  // final double mapWidth = mapArea.getWidth();
578              double mapHeight = mapArea.getHeight();                  // final double mapHeight = mapArea.getHeight();
579                    //
580              double x1 = ((this.startX * mapWidth) / (double) bounds.width)                  // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
581                      + mapArea.getMinX();                  // + mapArea.getMinX();
582              double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)                  // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
583                      + mapArea.getMinY();                  // (double) bounds.height)
584              double x2 = ((x * mapWidth) / (double) bounds.width)                  // + mapArea.getMinY();
585                      + mapArea.getMinX();                  // final double x2 = ((x * mapWidth) / (double) bounds.width)
586              double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)                  // + mapArea.getMinX();
587                      + mapArea.getMinY();                  // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
588              double left = Math.min(x1, x2);                  // bounds.height)
589              double right = Math.max(x1, x2);                  // + mapArea.getMinY();
590              double bottom = Math.min(y1, y2);                  // final double left = Math.min(x1, x2);
591              double top = Math.max(y1, y2);                  // final double right = Math.max(x1, x2);
592                    // final double bottom = Math.min(y1, y2);
593                    // final double top = Math.max(y1, y2);
594              String name = selectionLayer.getFeatureSource().getSchema()                  //
595                      .getDefaultGeometry().getName();                  // String name = selectionLayer.getFeatureSource().getSchema()
596                    // .getDefaultGeometry().getName();
597              if (name == "") {                  //
598                  name = "the_geom";                  // if (name == "") {
599              }                  // name = "the_geom";
600              Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                  // }
601                      getContext().getCoordinateReferenceSystem().toString());                  // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
602              if(selectionManager!=null) {                  // top,
603                  selectionManager.selectionChanged(this, bb);                  // getContext().getCoordinateReferenceSystem().toString());
604              }                  // if (selectionManager != null) {
605                    // selectionManager.selectionChanged(this, bb);
606              graphics.setXORMode(Color.green);                  // }
607                    //
608              /*                  // graphics.setXORMode(Color.green);
609               * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }                  //
610               */                  // /*
611                    // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
612              // draw new box                  // */
613              lastX = x;                  //
614              lastY = y;                  // // draw new box
615              drawRectangle(graphics);                  // lastX = x;
616         }                  // lastY = y;
617                        // drawRectangle(graphics);
618      }                  // }
619    
620      // sk.cs          }
621  //    private void processDrag(int x1, int y1, int x2, int y2) {  
622      // sk.ce          // sk.cs
623      protected void processDrag(int x1, int y1, int x2, int y2, MouseEvent e) {          // private void processDrag(int x1, int y1, int x2, int y2) {
624                    // sk.ce
625          /****          protected void processDrag(final int x1, final int y1, final int x2,
626           * If no layer is availabe we dont want a NullPointerException                          final int y2, final MouseEvent e) {
627           */  
628          if (mapArea == null) return;  
629                            /****
630          // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                   * If no layers exist, we ignore the drag.
631          // + x2 + "," + y2);                   */
632          if ((x1 == x2) && (y1 == y2)) {                  if (context.getLayerCount() <= 0) {
633              if (isClickable()) {                          return;
634                  mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,                  }
635                          x1, y1, y2, false));                  
636              }                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
637                    // + x2 + "," + y2);
638              return;                  if ((x1 == x2) && (y1 == y2)) {
639          }                          if (isClickable()) {
640                                            mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,
641          Rectangle bounds = this.getBounds();                                                  x1, y1, y2, false));
642                            }
643          double mapWidth = mapArea.getWidth();  
644          double mapHeight = mapArea.getHeight();                          return;
645                    }
646          double startX = ((x1 * mapWidth) / (double) bounds.width)  
647                  + mapArea.getMinX();                  final Rectangle bounds = this.getBounds();
648          double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)  
649                  + mapArea.getMinY();                  final double mapWidth = mapArea.getWidth();
650          double endX = ((x2 * mapWidth) / (double) bounds.width)                  final double mapHeight = mapArea.getHeight();
651                  + mapArea.getMinX();  
652          double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)                  final double startX = ((x1 * mapWidth) / (double) bounds.width)
653                  + mapArea.getMinY();                                  + mapArea.getMinX();
654                    final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)
655          if (  (state == JMapPane.Pan) || (e.getButton()== MouseEvent.BUTTON3)) {                                  + mapArea.getMinY();
656              // move the image with the mouse                  final double endX = ((x2 * mapWidth) / (double) bounds.width)
657              // calculate X offsets from start point to the end Point                                  + mapArea.getMinX();
658              double deltaX1 = endX - startX;                  final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)
659                                    + mapArea.getMinY();
660              // System.out.println("deltaX " + deltaX1);  
661              // new edges                  if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {
662              double left = mapArea.getMinX() - deltaX1;                          // move the image with the mouse
663              double right = mapArea.getMaxX() - deltaX1;                          // calculate X offsets from start point to the end Point
664                            final double deltaX1 = endX - startX;
665              // now for Y  
666              double deltaY1 = endY - startY;                          // System.out.println("deltaX " + deltaX1);
667                            // new edges
668              // System.out.println("deltaY " + deltaY1);                          final double left = mapArea.getMinX() - deltaX1;
669              double bottom = mapArea.getMinY() - deltaY1;                          final double right = mapArea.getMaxX() - deltaX1;
670              double top = mapArea.getMaxY() - deltaY1;  
671              Coordinate ll = new Coordinate(left, bottom);                          // now for Y
672              Coordinate ur = new Coordinate(right, top);                          final double deltaY1 = endY - startY;
673  //xulu.sc  
674  //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // System.out.println("deltaY " + deltaY1);
675              setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );                          final double bottom = mapArea.getMinY() - deltaY1;
676  //xulu.ec                          final double top = mapArea.getMaxY() - deltaY1;
677          } else if (state == JMapPane.ZoomIn) {                          final Coordinate ll = new Coordinate(left, bottom);
678                                            final Coordinate ur = new Coordinate(right, top);
679                            // xulu.sc
680                  // Zu kleine Flächen sollen nicht gezoomt werden.                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
681                  //sk.bc                          
682                  if ( (Math.abs(x1-x2) * Math.abs(y2-y1) )<100 ) return;  
683                  // sk.ec                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
684                                            // xulu.ec
685                  drawRectangle(this.getGraphics());                  } else if (state == JMapPane.ZoomIn) {
686              // make the dragged rectangle (in map coords) the new BBOX  
687              double left = Math.min(startX, endX);                          // Zu kleine Flächen sollen nicht gezoomt werden.
688              double right = Math.max(startX, endX);                          // sk.bc
689              double bottom = Math.min(startY, endY);                          if ((Math.abs(x1 - x2) * Math.abs(y2 - y1)) < 150)
690              double top = Math.max(startY, endY);                                  return;
691              Coordinate ll = new Coordinate(left, bottom);                          // sk.ec
692              Coordinate ur = new Coordinate(right, top);  
693  //xulu.sc                          drawRectangle(this.getGraphics());
694  //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // make the dragged rectangle (in map coords) the new BBOX
695              setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );                          final double left = Math.min(startX, endX);
696  //xulu.ec                          final double right = Math.max(startX, endX);
697          } else if (state == JMapPane.ZoomOut) {                          final double bottom = Math.min(startY, endY);
698                  drawRectangle(this.getGraphics());                          final double top = Math.max(startY, endY);
699                                            final Coordinate ll = new Coordinate(left, bottom);
700                  // make the dragged rectangle in screen coords the new map size?                          final Coordinate ur = new Coordinate(right, top);
701              double left = Math.min(startX, endX);                          // xulu.sc
702              double right = Math.max(startX, endX);  
703              double bottom = Math.min(startY, endY);                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
704              double top = Math.max(startY, endY);                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
705              double nWidth = (mapWidth * mapWidth) / (right - left);  
706              double nHeight = (mapHeight * mapHeight) / (top - bottom);                          // sk.sc
707              double deltaX1 = left - mapArea.getMinX();                          // {
708              double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
709              double deltaY1 = bottom - mapArea.getMinY();                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
710              double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
711              Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
712                      mapArea.getMinY() - nDeltaY1);                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
713              double deltaX2 = mapArea.getMaxX() - right;                          // RenderingHints.VALUE_ANTIALIAS_OFF);
714              double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
715              double deltaY2 = mapArea.getMaxY() - top;                          // RenderingHints.VALUE_RENDER_SPEED);
716              double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
717              Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
718                      mapArea.getMaxY() + nDeltaY2);                          // }
719  //xulu.sc                                      // xulu.ec
720  //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                  } else if (state == JMapPane.ZoomOut) {
721              setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );                          drawRectangle(this.getGraphics());
722  //xulu.ec  
723          } else if (state == JMapPane.Select && selectionLayer !=null) {                          // make the dragged rectangle in screen coords the new map size?
724              double left = Math.min(startX, endX);                          final double left = Math.min(startX, endX);
725              double right = Math.max(startX, endX);                          final double right = Math.max(startX, endX);
726              double bottom = Math.min(startY, endY);                          final double bottom = Math.min(startY, endY);
727              double top = Math.max(startY, endY);                          final double top = Math.max(startY, endY);
728                            final double nWidth = (mapWidth * mapWidth) / (right - left);
729                            final double nHeight = (mapHeight * mapHeight) / (top - bottom);
730              String name = selectionLayer.getFeatureSource().getSchema()                          final double deltaX1 = left - mapArea.getMinX();
731                      .getDefaultGeometry().getLocalName();                          final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
732                            final double deltaY1 = bottom - mapArea.getMinY();
733              if (name == "") {                          final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
734                  name = "the_geom";                          final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
735              }                                          mapArea.getMinY() - nDeltaY1);
736              Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                          final double deltaX2 = mapArea.getMaxX() - right;
737                      getContext().getCoordinateReferenceSystem().toString());                          final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
738              //System.out.println(bb.toString());                          final double deltaY2 = mapArea.getMaxY() - top;
739              if(selectionManager!=null) {                          final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
740                  selectionManager.selectionChanged(this, bb);                          final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
741              }                                          mapArea.getMaxY() + nDeltaY2);
742              /*FeatureCollection fc;                          // xulu.sc
743              selection = null;                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
744              try {                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
745                  fc = selectionLayer.getFeatureSource().getFeatures(bb);  
746                  selection = fc;                          // xulu.ec
747              } catch (IOException e) {                  }
748                  e.printStackTrace();                  // else if (state == JMapPane.Select && selectionLayer != null) {
749              }                  // final double left = Math.min(startX, endX);
750  */                  // final double right = Math.max(startX, endX);
751          }                  // final double bottom = Math.min(startY, endY);
752                    // final double top = Math.max(startY, endY);
753  //xulu.so                  //
754  //        setMapArea(mapArea);                  // String name = selectionLayer.getFeatureSource().getSchema()
755  //xulu.eo                  // .getDefaultGeometry().getLocalName();
756          repaint();                  //
757      }                  // if (name == "") {
758                    // name = "the_geom";
759      private boolean isClickable() {                  // }
760          return clickable;                  // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
761      }                  // top,
762                    // getContext().getCoordinateReferenceSystem().toString());
763      private org.geotools.styling.Style setupStyle(int type, Color color) {                  // // System.out.println(bb.toString());
764          StyleFactory sf = org.geotools.factory.CommonFactoryFinder                  // if (selectionManager != null) {
765                  .getStyleFactory(null);                  // selectionManager.selectionChanged(this, bb);
766          StyleBuilder sb = new StyleBuilder();                  // }
767                    // /*
768          org.geotools.styling.Style s = sf.createStyle();                  // * FeatureCollection fc; selection = null; try { fc =
769          s.setTitle("selection");                  // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
770                    // * fc; } catch (IOException e) { e.printStackTrace(); }
771          // TODO parameterise the color                  // */
772          PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);                  // }
773          ps.setStroke(sb.createStroke(color));  
774                    // xulu.so
775          LineSymbolizer ls = sb.createLineSymbolizer(color);                  // setMapArea(mapArea);
776          Graphic h = sb.createGraphic();                  // xulu.eo
777          h.setMarks(new Mark[] { sb.createMark("square", color) });                  repaint();
778            }
779          PointSymbolizer pts = sb.createPointSymbolizer(h);  
780            private boolean isClickable() {
781          // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});                  return clickable;
782          switch (type) {          }
783          case POLYGON:  
784              s = sb.createStyle(ps);          //
785            // private org.geotools.styling.Style setupStyle(final int type, final Color
786              break;          // color) {
787            // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
788          case POINT:          // .getStyleFactory(null);
789              s = sb.createStyle(pts);          // final StyleBuilder sb = new StyleBuilder();
790            //
791              break;          // org.geotools.styling.Style s = sf.createStyle();
792            // s.setTitle("selection");
793          case LINE:          //
794              s = sb.createStyle(ls);          // // TODO parameterise the color
795          }          // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
796            // ps.setStroke(sb.createStroke(color));
797          return s;          //
798      }          // final LineSymbolizer ls = sb.createLineSymbolizer(color);
799            // final Graphic h = sb.createGraphic();
800      public void highlightChanged(HighlightChangedEvent e) {          // h.setMarks(new Mark[] { sb.createMark("square", color) });
801          org.opengis.filter.Filter f = e.getFilter();          //
802            // final PointSymbolizer pts = sb.createPointSymbolizer(h);
803          try {          //
804              highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);          // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
805          } catch (IOException e1) {          // switch (type) {
806              // TODO Auto-generated catch block          // case POLYGON:
807              e1.printStackTrace();          // s = sb.createStyle(ps);
808          }          //
809            // break;
810          repaint();          //
811      }          // case POINT:
812            // s = sb.createStyle(pts);
813      public void propertyChange(PropertyChangeEvent evt) {          //
814          String prop = evt.getPropertyName();          // break;
815            //
816          if (prop.equalsIgnoreCase("crs")) {          // case LINE:
817              context.setAreaOfInterest(context.getAreaOfInterest(),          // s = sb.createStyle(ls);
818                      (CoordinateReferenceSystem) evt.getNewValue());          // }
819          }          //
820      }          // return s;
821            // }
822      public boolean isReset() {  
823          return reset;          public void propertyChange(final PropertyChangeEvent evt) {
824      }                  final String prop = evt.getPropertyName();
825    
826      public void setReset(boolean reset) {                  if (prop.equalsIgnoreCase("crs")) {
827          this.reset = reset;                          context.setAreaOfInterest(context.getAreaOfInterest(),
828      }                                          (CoordinateReferenceSystem) evt.getNewValue());
829                    }
830      public void layerAdded(MapLayerListEvent event) {          }
831          changed = true;  
832            public boolean isReset() {
833          if (context.getLayers().length == 1) { // the first one                  return reset;
834            }
835              try {  
836  //xulu.sc              public void setReset(final boolean reset) {
837  //            mapArea = context.getLayerBounds();                  this.reset = reset;
838                mapArea = context.getAreaOfInterest();          }
839                if ( mapArea == null )  
840                  mapArea = context.getLayerBounds();          public void layerAdded(final MapLayerListEvent event) {
841  //xulu.ec                  changed = true;
842              } catch (IOException e) {  
843                  // TODO Auto-generated catch block                  if (context.getLayers().length == 1) { // the first one
844                  e.printStackTrace();  
845              }                          try {
846                                    // xulu.sc
847              reset = true;                                  // mapArea = context.getLayerBounds();
848          }                                  mapArea = context.getAreaOfInterest();
849                                    if (mapArea == null)
850          repaint();                                          mapArea = context.getLayerBounds();
851      }                                  // xulu.ec
852                            } catch (final IOException e) {
853      public void layerRemoved(MapLayerListEvent event) {                                  // TODO Auto-generated catch block
854          changed = true;                                  e.printStackTrace();
855          repaint();                          }
856      }  
857                            reset = true;
858      public void layerChanged(MapLayerListEvent event) {                  }
859          changed = true;  
860          // System.out.println("layer changed - repaint");                  repaint();
861          repaint();          }
862      }  
863            public void layerRemoved(final MapLayerListEvent event) {
864      public void layerMoved(MapLayerListEvent event) {                  changed = true;
865          changed = true;                  repaint();
866          repaint();          }
867      }  
868            public void layerChanged(final MapLayerListEvent event) {
869      protected void drawRectangle(Graphics graphics) {                  changed = true;
870          // undraw last box/draw new box                  // System.out.println("layer changed - repaint");
871          int left = Math.min(startX, lastX);                  repaint();
872          int right = Math.max(startX, lastX);          }
873          int top = Math.max(startY, lastY);  
874          int bottom = Math.min(startY, lastY);          public void layerMoved(final MapLayerListEvent event) {
875          int width = right - left;                  changed = true;
876          int height = top - bottom;                  repaint();
877          // System.out.println("drawing rect("+left+","+bottom+","+ width+","+          }
878          // height+")");  
879          graphics.drawRect(left, bottom, width, height);          protected void drawRectangle(final Graphics graphics) {
880      }                  // undraw last box/draw new box
881                    final int left = Math.min(startX, lastX);
882      /**                  final int right = Math.max(startX, lastX);
883       * if clickable is set to true then a single click on the map pane will zoom                  final int top = Math.max(startY, lastY);
884       * or pan the map.                  final int bottom = Math.min(startY, lastY);
885       *                  final int width = right - left;
886       * @param clickable                  final int height = top - bottom;
887       */                  // System.out.println("drawing rect("+left+","+bottom+","+ width+","+
888      public void setClickable(boolean clickable) {                  // height+")");
889          this.clickable = clickable;                  graphics.drawRect(left, bottom, width, height);
890      }          }
891    
892      public void mouseMoved(MouseEvent e) {          /**
893      }           * if clickable is set to true then a single click on the map pane will zoom
894             * or pan the map.
895      public FeatureCollection getSelection() {           *
896          return selection;           * @param clickable
897      }           */
898            public void setClickable(final boolean clickable) {
899      public void setSelection(FeatureCollection selection) {                  this.clickable = clickable;
900          this.selection = selection;          }
901          repaint();  
902      }          public void mouseMoved(final MouseEvent e) {
903            }
904      /* (non-Javadoc)  
905       * @see org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged(org.geotools.gui.swing.event.SelectionChangedEvent)          // xulu.sn
906       */          /**
907      public void selectionChanged(SelectionChangedEvent e) {           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
908             * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
909          try {           * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/>
910              selection = selectionLayer.getFeatureSource().getFeatures(e.getFilter());           * Since 21. April 09: Before thecalculation starts, the aspect ratio is
911              repaint();           * corrected. This change implies, that setMapArea() will most of the time
912          } catch (IOException e1) {           * not allow setting to a wrong aspectRatio.
913              e1.printStackTrace();           *
914          }           * @author <a href="mailto:[email protected]">Stefan Alfons
915      }           *         Kr&uuml;ger</a>
916             */
917      public SelectionManager getSelectionManager() {          public Envelope bestAllowedMapArea(Envelope env) {
918          return selectionManager;                  if (getWidth() == 0)
919      }                          return env;
920                    if (env == null)
921      public void setSelectionManager(SelectionManager selectionManager) {                          return env;
922          this.selectionManager = selectionManager;  
923          this.selectionManager.addSelectionChangeListener(this);                  Envelope newArea = null;
924    
925      }                  /**
926                     * Correct the aspect Ratio before we check the rest. Otherwise we might
927                     * easily fail.
928  //xulu.sn                   */
929      /**                  env = fixAspectRatio(this.getBounds(), env, false);
930       * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste erlaubte Flaeche damit  
931       * die Massstabsbeschaenkungen noch eingehalten werden, FALLS der uebergeben Envelope                  final double scale = env.getWidth() / getWidth();
932       * nicht schon gueltig sein sollte.                  final double centerX = env.getMinX() + env.getWidth() / 2.;
933       *                  final double centerY = env.getMinY() + env.getHeight() / 2.;
934       * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                  double newWidth2 = 0;
935       */                  double newHeight2 = 0;
936    public Envelope bestAllowedMapArea(Envelope env) {                  if (scale < getMaxZoomScale()) {
937      if (getWidth() == 0) return env;                          // ****************************************************************************
938      if (env == null) return env;                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
939                            // ****************************************************************************
940      double scale = env.getWidth() / getWidth();                          newWidth2 = getMaxZoomScale() * getWidth() / 2.;
941      double centerX = env.getMinX() + env.getWidth() / 2.;                          newHeight2 = getMaxZoomScale() * getHeight() / 2.;
942      double centerY = env.getMinY() + env.getHeight() / 2.;                  } else if (scale > getMinZoomScale()) {
943      double newWidth2;                          // ****************************************************************************
944      double newHeight2;                          // Wir zoomen weiter raus als erlaubt => Anpassen des envelope
945      if (scale < getMaxZoomScale()) {                          // ****************************************************************************
946        //****************************************************************************                          newWidth2 = getMinZoomScale() * getWidth() / 2.;
947        // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                          newHeight2 = getMinZoomScale() * getHeight() / 2.;
948        //****************************************************************************                  } else {
949        newWidth2 = getMaxZoomScale() * getWidth() / 2.;                          // ****************************************************************************
950        newHeight2 = getMaxZoomScale() * getHeight() / 2.;                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
951      } else if (scale > getMinZoomScale()) {                          // ****************************************************************************
952        //****************************************************************************                          newArea = env;
953        // Wir zoomen weiter raus als erlaubt => Anpassen des envelope                  }
954        //****************************************************************************  
955        newWidth2 = getMinZoomScale() * getWidth() / 2.;                  if (newArea == null) {
956        newHeight2 = getMinZoomScale() * getHeight() / 2.;  
957      } else {                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
958        //****************************************************************************                                          - newHeight2);
959        // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen                          final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
960        //****************************************************************************                                          + newHeight2);
961        return env;  
962      }                          newArea = new Envelope(ll, ur);
963                    }
964      Coordinate ll = new Coordinate(centerX - newWidth2, centerY  
965                                     - newHeight2);                  Envelope maxAllowedExtend = getMaxExtend();
966      Coordinate ur = new Coordinate(centerX + newWidth2, centerY                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) {
967                                     + newHeight2);                          /*
968                             * If a maxExtend is set, we have to honour that...
969      return new Envelope(ll, ur);                           */
970    }  
971                            // Exceeds top? Move down and maybe cut
972    /**                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
973     * Retuns the minimum allowed zoom scale. This is the bigger number value of the two.                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
974     * Defaults to {@link Double}.MAX_VALUE                                  LOGGER.debug("Moving area down by " + divY);
975     *  
976     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
977     */                                                  newArea.getMinY() - divY), new Coordinate(newArea
978    public Double getMinZoomScale() {                                                  .getMaxX(), newArea.getMaxY() - divY));
979      return minZoomScale;  
980    }                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
981                                            LOGGER.debug("Now it exeeds the bottom border.. cut!");
982    /**                                          // And cut the bottom if it moved out of the area
983     * Retuns the maximum allowed zoom scale. This is the smaller number value of the two.                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
984     * Defaults to {@link Double}.MIN_VALUE                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea
985     *                                                          .getMaxX(), newArea.getMaxY()));
986     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>  
987     */                                          LOGGER.debug("and fix aspect ratio");
988    public Double getMaxZoomScale() {  
989      return maxZoomScale;                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);
990    }                                  }
991                            }
992    /**  
993     * Set the maximum allowed zoom scale. This is the smaller number value of the two.                          // Exceeds bottom? Move up and maybe cut
994     *                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
995     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
996     */                                  LOGGER.debug("Moving area up by " + divY);
997    public void setMaxZoomScale(Double maxZoomScale) {  
998      // System.out.println("setting max scale to "+maxZoomScale);                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
999      this.maxZoomScale = maxZoomScale;                                                  newArea.getMinY() - divY), new Coordinate(newArea
1000    }                                                  .getMaxX(), newArea.getMaxY() - divY));
1001    
1002    /**                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
1003     * Set the minimum (nearest) allowed zoom scale. This is the bigger number value of the two.                                          LOGGER.debug("Now it exeeds the top border.. cut!");
1004     *                                          // And cut the bottom if it moved out of the area
1005     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
1006     */                                                          newArea.getMinY()), new Coordinate(newArea
1007    public void setMinZoomScale(Double minZoomScale) {                                                          .getMaxX(), maxAllowedExtend.getMaxY()));
1008      this.minZoomScale = minZoomScale;  
1009    }                                          LOGGER.debug("and fix aspect ratio");
1010  //xulu.en  
1011                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1012                                    }
1013                            }
1014    
1015                            // Exceeds to the right? move and maybe cut
1016                            if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1017    
1018                                    // Move left..
1019                                    double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
1020                                    LOGGER.debug("Moving area left by " + divX);
1021    
1022                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1023                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1024                                                    - divX, newArea.getMaxY()));
1025    
1026                                    if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1027                                            LOGGER.debug("Now it exeeds the left border.. cut!");
1028                                            // And cut the left if it moved out of the area
1029                                            newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(),
1030                                                            newArea.getMinY()), new Coordinate(newArea
1031                                                            .getMaxX(), newArea.getMaxY()));
1032    
1033                                            LOGGER.debug("and fix aspect ratio");
1034    
1035                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1036                                    }
1037                            }
1038    
1039                            // Exceeds to the left? move and maybe cut
1040                            if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1041    
1042                                    // Move right..
1043                                    double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
1044                                    LOGGER.debug("Moving area right by " + divX);
1045    
1046                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1047                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1048                                                    - divX, newArea.getMaxY()));
1049    
1050                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1051                                            LOGGER.debug("Now it exeeds the right border.. cut!");
1052                                            // And cut the left if it moved out of the area
1053                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1054                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
1055                                                            .getMaxX(), newArea.getMaxY()));
1056    
1057                                            LOGGER.debug("and fix aspect ratio");
1058    
1059                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1060                                    }
1061                            }
1062    
1063                    }
1064    
1065                    return newArea;
1066            }
1067    
1068            /**
1069             * Retuns the minimum allowed zoom scale. This is the bigger number value of
1070             * the two. Defaults to {@link Double}.MAX_VALUE
1071             *
1072             * @author <a href="mailto:[email protected]">Stefan Alfons
1073             *         Kr&uuml;ger</a>
1074             */
1075            public Double getMinZoomScale() {
1076                    return minZoomScale;
1077            }
1078    
1079            /**
1080             * Retuns the maximum allowed zoom scale. This is the smaller number value
1081             * of the two. Defaults to {@link Double}.MIN_VALUE
1082             *
1083             * @author <a href="mailto:[email protected]">Stefan Alfons
1084             *         Kr&uuml;ger</a>
1085             */
1086            public Double getMaxZoomScale() {
1087                    return maxZoomScale;
1088            }
1089    
1090            /**
1091             * Set the maximum allowed zoom scale. This is the smaller number value of
1092             * the two.
1093             *
1094             * @author <a href="mailto:[email protected]">Stefan Alfons
1095             *         Kr&uuml;ger</a>
1096             */
1097            public void setMaxZoomScale(final Double maxZoomScale) {
1098                    this.maxZoomScale = maxZoomScale;
1099            }
1100    
1101            /**
1102             * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1103             * value of the two.
1104             *
1105             * @author <a href="mailto:[email protected]">Stefan Alfons
1106             *         Kr&uuml;ger</a>
1107             */
1108            public void setMinZoomScale(final Double minZoomScale) {
1109                    this.minZoomScale = minZoomScale;
1110            }
1111    
1112            /**
1113             * Defines an evelope of the viwable area. The JMapPane will never show
1114             * anything outside of this extend.
1115             *
1116             * @param maxExtend
1117             *            <code>null</code> to not have this restriction.
1118             */
1119            public void setMaxExtend(Envelope maxExtend) {
1120                    this.maxExtend = maxExtend;
1121            }
1122    
1123            /**
1124             * Returns the evelope of the viewable area. The JMapPane will never show
1125             * anything outside of this extend. If this has been set to
1126             * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1127             * quickly the context's bounds. It it takes to long to determine the
1128             * context bounds, <code>null</code> is returned.
1129             *
1130             * @param maxExtend
1131             *            <code>null</code> to not have this restriction.
1132             */
1133    
1134            public Envelope getMaxExtend() {
1135                    if (maxExtend == null) {
1136                            try {
1137                                    return fixAspectRatio(this.getBounds(), context.getLayerBounds(), true);
1138                            } catch (IOException e) {
1139                                    LOGGER
1140                                                    .warn(
1141                                                                    "maxExtend == null; faild to getLayerBounds of context",
1142                                                                    e);
1143                            }
1144                    }
1145                    return maxExtend;
1146            }
1147    
1148  }  }

Legend:
Removed from v.2  
changed lines
  Added in v.431

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26