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

Legend:
Removed from v.114  
changed lines
  Added in v.318

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26