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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26