/[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 207 by alfonx, Thu Jul 9 20:14:21 2009 UTC branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java revision 504 by alfonx, Tue Oct 27 12:57:58 2009 UTC
# Line 13  Line 13 
13   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *    Lesser General Public License for more details.   *    Lesser General Public License for more details.
15   */   */
16  package org.geotools.gui.swing;  package gtmig.org.geotools.swing;
17    
18  /**  /**
19   * <b>Xulu:<br>   * <b>Xulu:<br>
# Line 58  import java.util.Map; Line 58  import java.util.Map;
58  import javax.swing.JPanel;  import javax.swing.JPanel;
59    
60  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
 import org.geotools.feature.FeatureCollection;  
 import org.geotools.filter.IllegalFilterException;  
 import org.geotools.gui.swing.event.HighlightChangeListener;  
 import org.geotools.gui.swing.event.HighlightChangedEvent;  
 import org.geotools.gui.swing.event.SelectionChangeListener;  
 import org.geotools.gui.swing.event.SelectionChangedEvent;  
 import org.geotools.map.DefaultMapContext;  
61  import org.geotools.map.MapContext;  import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;  
62  import org.geotools.map.event.MapLayerListEvent;  import org.geotools.map.event.MapLayerListEvent;
63  import org.geotools.map.event.MapLayerListListener;  import org.geotools.map.event.MapLayerListListener;
 import org.geotools.referencing.crs.DefaultGeographicCRS;  
64  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
65    import org.geotools.renderer.label.LabelCacheImpl;
66  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
 import org.geotools.renderer.lite.LabelCacheDefault;  
67  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
 import org.geotools.styling.Graphic;  
 import org.geotools.styling.LineSymbolizer;  
 import org.geotools.styling.Mark;  
 import org.geotools.styling.PointSymbolizer;  
 import org.geotools.styling.PolygonSymbolizer;  
 import org.geotools.styling.Style;  
 import org.geotools.styling.StyleBuilder;  
 import org.geotools.styling.StyleFactory;  
 import org.opengis.filter.Filter;  
68  import org.opengis.filter.FilterFactory2;  import org.opengis.filter.FilterFactory2;
69  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
70    
71    import schmitzm.geotools.JTSUtil;
72  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
73    
74  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
75  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;  
76  import com.vividsolutions.jts.geom.GeometryFactory;  import com.vividsolutions.jts.geom.GeometryFactory;
77    
78  public class JMapPane extends JPanel implements MouseListener,  public class JMapPane extends JPanel implements MouseListener,
79                  MouseMotionListener, HighlightChangeListener, SelectionChangeListener,                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {
80                  PropertyChangeListener, MapLayerListListener {          private static Logger LOGGER = Logger.getLogger(JMapPane.class);
         private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());  
81    
82          private static final long serialVersionUID = -8647971481359690499L;          private static final long serialVersionUID = -8647971481359690499L;
83    
# Line 110  public class JMapPane extends JPanel imp Line 91  public class JMapPane extends JPanel imp
91    
92          public static final int Select = 4;          public static final int Select = 4;
93    
         private static final int POLYGON = 0;  
   
         private static final int LINE = 1;  
   
         private static final int POINT = 2;  
   
94          /**          /**
95           * what renders the map           * what renders the map
96           */           */
97          GTRenderer renderer;          GTRenderer renderer;
98    
         private GTRenderer highlightRenderer, selectionRenderer;  
   
99          /**          /**
100           * the map context to render           * the map context to render
101           */           */
102          MapContext context;          MapContext context;
103    
         private MapContext selectionContext;  
   
104          /**          /**
105           * the area of the map to draw           * the area of the map to draw
106           */           */
         // xulu.sc  
         // Envelope mapArea;  
107          protected Envelope mapArea;          protected Envelope mapArea;
         // xulu.ec  
108    
109          /**          /**
110           * the size of the pane last time we drew           * the size of the pane last time we drew
111           */           */
         // xulu.sc  
         // private Rectangle oldRect = null;  
112          protected Rectangle oldRect = null;          protected Rectangle oldRect = null;
         // xulu.ec  
113    
114          /**          /**
115           * the last map area drawn.           * the last map area drawn.
116           */           */
         // xulu.sc  
         // private Envelope oldMapArea = null;  
117          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
         // xulu.ec  
118    
119          /**          /**
120           * the base image of the map           * the base image of the map
121           */           */
122          protected BufferedImage baseImage, panningImage;          protected BufferedImage baseImage, panningImage;
         // SK: private BufferedImage baseImage, panningImage;  
   
         /**  
          * image of selection  
          */  
         private BufferedImage selectImage;  
   
         /**  
          * style for selected items  
          */  
         private Style selectionStyle;  
   
         /**  
          * layer that selection works on  
          */  
         private MapLayer selectionLayer;  
   
         /**  
          * layer that highlight works on  
          */  
         private MapLayer highlightLayer;  
   
         /**  
          * the object which manages highlighting  
          */  
         private HighlightManager highlightManager;  
   
         /**  
          * is highlighting on or off  
          */  
         private boolean highlight = true;  
123    
124          /**          /**
125           * a factory for filters           * a factory for filters
# Line 200  public class JMapPane extends JPanel imp Line 131  public class JMapPane extends JPanel imp
131           */           */
132          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
133    
         /**  
          * the collections of features to be selected or highlighted  
          */  
         FeatureCollection selection;  
   
         /**  
          * the collections of features to be selected or highlighted  
          */  
         FeatureCollection highlightFeature;  
   
134          private int state = ZoomIn;          private int state = ZoomIn;
135    
136          /**          /**
# Line 217  public class JMapPane extends JPanel imp Line 138  public class JMapPane extends JPanel imp
138           */           */
139          private double zoomFactor = 2.0;          private double zoomFactor = 2.0;
140    
         Style lineHighlightStyle;  
   
         Style pointHighlightStyle;  
   
         Style polygonHighlightStyle;  
   
         Style polygonSelectionStyle;  
   
         Style pointSelectionStyle;  
   
         Style lineSelectionStyle;  
   
141          boolean changed = true;          boolean changed = true;
142    
143          LabelCache labelCache = new LabelCacheDefault();          LabelCache labelCache = new LabelCacheImpl();
144    
         // xulu.sc  
         // private boolean reset = false;  
145          protected boolean reset = false;          protected boolean reset = false;
         // xulu.ec  
146    
147          int startX;          int startX;
148    
149          int startY;          int startY;
150    
151            /**
152             * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
153             * out of that area
154             **/
155            private Envelope maxExtend = null;
156    
157            // /**
158            // * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If
159            // * <code>true</code> the extends has to be fully inside maxExtend
160            // **/
161            // boolean maxExtendForceMode = true;
162    
163          private boolean clickable;          private boolean clickable;
164    
165          int lastX;          int lastX;
166    
167          int lastY;          int lastY;
168    
         private SelectionManager selectionManager;  
         // xulu.sn  
169          private Double maxZoomScale = Double.MIN_VALUE;          private Double maxZoomScale = Double.MIN_VALUE;
170          private Double minZoomScale = Double.MAX_VALUE;          private Double minZoomScale = Double.MAX_VALUE;
         // xulu.en  
171    
         // sk.sn  
172          /**          /**
173           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
174           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
# Line 262  public class JMapPane extends JPanel imp Line 176  public class JMapPane extends JPanel imp
176           */           */
177          private boolean panning_started = false;          private boolean panning_started = false;
178    
         // sk.en  
   
179          public JMapPane() {          public JMapPane() {
180                  this(null, true, null, null);                  this(null, true, null, null);
181          }          }
# Line 276  public class JMapPane extends JPanel imp Line 188  public class JMapPane extends JPanel imp
188           * @param context           * @param context
189           *            - the map context to display           *            - the map context to display
190           */           */
191          public JMapPane(GTRenderer render, MapContext context) {          public JMapPane(final GTRenderer render, final MapContext context) {
192                  this(null, true, render, context);                  this(null, true, render, context);
193          }          }
194    
# Line 292  public class JMapPane extends JPanel imp Line 204  public class JMapPane extends JPanel imp
204           * @param context           * @param context
205           *            - what to draw           *            - what to draw
206           */           */
207          public JMapPane(LayoutManager layout, boolean isDoubleBuffered,          public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered,
208                          GTRenderer render, MapContext context) {                          final GTRenderer render, final MapContext context) {
209                  super(layout, isDoubleBuffered);                  super(layout, isDoubleBuffered);
210    
211                  ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder                  ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
# Line 304  public class JMapPane extends JPanel imp Line 216  public class JMapPane extends JPanel imp
216    
217                  this.addMouseListener(this);                  this.addMouseListener(this);
218                  this.addMouseMotionListener(this);                  this.addMouseMotionListener(this);
                 setHighlightManager(new HighlightManager(highlightLayer));  
                 setSelectionManager(new SelectionManager(selectionLayer));  
                 lineHighlightStyle = setupStyle(LINE, Color.red);  
   
                 pointHighlightStyle = setupStyle(POINT, Color.red);  
   
                 polygonHighlightStyle = setupStyle(POLYGON, Color.red);  
   
                 polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);  
   
                 pointSelectionStyle = setupStyle(POINT, Color.cyan);  
   
                 lineSelectionStyle = setupStyle(LINE, Color.cyan);  
219                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
220          }          }
221    
# Line 327  public class JMapPane extends JPanel imp Line 226  public class JMapPane extends JPanel imp
226                  return renderer;                  return renderer;
227          }          }
228    
229          public void setRenderer(GTRenderer renderer) {          public void setRenderer(final GTRenderer renderer) {
230                  Map hints = new HashMap();                  Map<Object, Object> hints = new HashMap<Object, Object>();
                 if (renderer instanceof StreamingRenderer) {  
                         hints = renderer.getRendererHints();  
                         if (hints == null) {  
                                 hints = new HashMap();  
                         }  
                         if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {  
                                 labelCache = (LabelCache) hints  
                                                 .get(StreamingRenderer.LABEL_CACHE_KEY);  
                         } else {  
                                 hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);  
                         }  
                         renderer.setRendererHints(hints);  
                 }  
231    
232                  this.renderer = renderer;                  this.renderer = renderer;
233  //              this.highlightRenderer = new StreamingRenderer();                  // MS: Apply hint also for ShapeFileRenderer
234  //              this.selectionRenderer = new StreamingRenderer();                  // if (renderer instanceof StreamingRenderer) {
235                    hints = renderer.getRendererHints();
236                    if (hints == null) {
237                            hints = new HashMap<Object, Object>();
238                    }
239                    if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
240                            labelCache = (LabelCache) hints
241                                            .get(StreamingRenderer.LABEL_CACHE_KEY);
242                    } else {
243                            hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
244                    }
245    
246                  hints.put("memoryPreloadingEnabled", Boolean.FALSE);                  hints.put("memoryPreloadingEnabled", Boolean.TRUE);
247  //              highlightRenderer.setRendererHints(hints);  
248  //              selectionRenderer.setRendererHints(hints);                  renderer.setRendererHints(hints);
249                    // }
250    
251                  if (this.context != null) {                  if (this.context != null) {
252                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
# Line 360  public class JMapPane extends JPanel imp Line 257  public class JMapPane extends JPanel imp
257                  return context;                  return context;
258          }          }
259    
260          public void setContext(MapContext context) {          public void setContext(final MapContext context) {
261                  if (this.context != null) {                  if (this.context != null) {
262                          this.context.removeMapLayerListListener(this);                          this.context.removeMapLayerListListener(this);
263                  }                  }
# Line 380  public class JMapPane extends JPanel imp Line 277  public class JMapPane extends JPanel imp
277                  return mapArea;                  return mapArea;
278          }          }
279    
280          public void setMapArea(Envelope mapArea) {          public void setMapArea(final Envelope mapArea) {
281                  this.mapArea = mapArea;                  this.mapArea = mapArea;
282          }          }
283    
# Line 388  public class JMapPane extends JPanel imp Line 285  public class JMapPane extends JPanel imp
285                  return state;                  return state;
286          }          }
287    
288          public void setState(int state) {          public void setState(final int state) {
289                  this.state = state;                  this.state = state;
290    
291                  // System.out.println("State: " + state);                  // System.out.println("State: " + state);
# Line 398  public class JMapPane extends JPanel imp Line 295  public class JMapPane extends JPanel imp
295                  return zoomFactor;                  return zoomFactor;
296          }          }
297    
298          public void setZoomFactor(double zoomFactor) {          public void setZoomFactor(final double zoomFactor) {
299                  this.zoomFactor = zoomFactor;                  this.zoomFactor = zoomFactor;
300          }          }
301    
302          public MapLayer getSelectionLayer() {          protected void paintComponent(final Graphics g) {
                 return selectionLayer;  
         }  
   
         public void setSelectionLayer(MapLayer selectionLayer) {  
                 this.selectionLayer = selectionLayer;  
                 if (selectionManager != null) {  
                         selectionManager.setSelectionLayer(selectionLayer);  
                 }  
         }  
   
         public boolean isHighlight() {  
                 return highlight;  
         }  
   
         public void setHighlight(boolean highlight) {  
                 this.highlight = highlight;  
         }  
   
         public MapLayer getHighlightLayer() {  
                 return highlightLayer;  
         }  
   
         public void setHighlightLayer(MapLayer highlightLayer) {  
                 this.highlightLayer = highlightLayer;  
   
                 if (highlightManager != null) {  
                         highlightManager.setHighlightLayer(highlightLayer);  
                 }  
         }  
   
         public HighlightManager getHighlightManager() {  
                 return highlightManager;  
         }  
   
         public void setHighlightManager(HighlightManager highlightManager) {  
                 this.highlightManager = highlightManager;  
                 this.highlightManager.addHighlightChangeListener(this);  
                 this.addMouseMotionListener(this.highlightManager);  
         }  
   
         public Style getLineHighlightStyle() {  
                 return lineHighlightStyle;  
         }  
   
         public void setLineHighlightStyle(Style lineHighlightStyle) {  
                 this.lineHighlightStyle = lineHighlightStyle;  
         }  
   
         public Style getLineSelectionStyle() {  
                 return lineSelectionStyle;  
         }  
   
         public void setLineSelectionStyle(Style lineSelectionStyle) {  
                 this.lineSelectionStyle = lineSelectionStyle;  
         }  
   
         public Style getPointHighlightStyle() {  
                 return pointHighlightStyle;  
         }  
   
         public void setPointHighlightStyle(Style pointHighlightStyle) {  
                 this.pointHighlightStyle = pointHighlightStyle;  
         }  
   
         public Style getPointSelectionStyle() {  
                 return pointSelectionStyle;  
         }  
   
         public void setPointSelectionStyle(Style pointSelectionStyle) {  
                 this.pointSelectionStyle = pointSelectionStyle;  
         }  
   
         public Style getPolygonHighlightStyle() {  
                 return polygonHighlightStyle;  
         }  
   
         public void setPolygonHighlightStyle(Style polygonHighlightStyle) {  
                 this.polygonHighlightStyle = polygonHighlightStyle;  
         }  
   
         public Style getPolygonSelectionStyle() {  
                 return polygonSelectionStyle;  
         }  
   
         public void setPolygonSelectionStyle(Style polygonSelectionStyle) {  
                 this.polygonSelectionStyle = polygonSelectionStyle;  
         }  
   
         protected void paintComponent(Graphics g) {  
303                  super.paintComponent(g);                  super.paintComponent(g);
304    
305                  if ((renderer == null) || (mapArea == null)) {                  if ((renderer == null) || (mapArea == null)) {
306                          return;                          return;
307                  }                  }
308    
309                  Rectangle r = getBounds();                  final Rectangle r = getBounds();
310                  Rectangle dr = new Rectangle(r.width, r.height);                  final Rectangle dr = new Rectangle(r.width, r.height);
311    
312                  if (!r.equals(oldRect) || reset) {                  if (!r.equals(oldRect) || reset) {
313                          if (!r.equals(oldRect) && (mapArea == null)) {                          if (!r.equals(oldRect) && (mapArea == null)) {
314                                  try {                                  try {
315                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
316                                  } catch (IOException e) {                                  } catch (final IOException e) {
317                                          // TODO Auto-generated catch block                                          LOGGER.warn("context.getLayerBounds()", e);
                                         e.printStackTrace();  
318                                  }                                  }
319                          }                          }
320    
# Line 517  public class JMapPane extends JPanel imp Line 324  public class JMapPane extends JPanel imp
324                                  reset = false; /* forget about the reset */                                  reset = false; /* forget about the reset */
325                                  oldRect = r; /* store what the current size is */                                  oldRect = r; /* store what the current size is */
326    
327                                  mapArea = fixAspectRatio(r, mapArea);                                  mapArea = JTSUtil.fixAspectRatio(r, mapArea, false);
328                          }                          }
329                  }                  }
330    
# Line 530  public class JMapPane extends JPanel imp Line 337  public class JMapPane extends JPanel imp
337                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
338                  }                  }
339    
340                  if (changed ) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
341                          changed = false;                          changed = false;
342                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
343                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_ARGB);
344    
345                          Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
346                          /* System.out.println("rendering"); */                          /* System.out.println("rendering"); */
347                          renderer.setContext(context);                          if (renderer.getContext() != null)
348                                    renderer.setContext(context);
349                          labelCache.clear(); // work around anoying labelcache bug                          labelCache.clear(); // work around anoying labelcache bug
350    
351                          // draw the map                          // draw the map
# Line 550  public class JMapPane extends JPanel imp Line 358  public class JMapPane extends JPanel imp
358                  }                  }
359    
360                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
   
                 if ((selection != null) && (selection.size() > 0)) {  
                         // paint selection  
   
                         String type = selectionLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getType().getName();  
                         /* String type = selection.getDefaultGeometry().getGeometryType(); */  
                         /* System.out.println(type); */  
                         if (type == null)  
                                 type = "polygon";  
   
                         /* String type = "point"; */  
   
                         if (type.toLowerCase().endsWith("polygon")) {  
                                 selectionStyle = polygonSelectionStyle;  
                         } else if (type.toLowerCase().endsWith("point")) {  
                                 selectionStyle = pointSelectionStyle;  
                         } else if (type.toLowerCase().endsWith("line")) {  
                                 selectionStyle = lineSelectionStyle;  
                         }  
   
                         selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);  
   
                         selectionContext.addLayer(selection, selectionStyle);  
                         selectionRenderer.setContext(selectionContext);  
   
                         selectImage = new BufferedImage(dr.width, dr.height,  
                                         BufferedImage.TYPE_INT_ARGB);  
   
                         Graphics2D ig = selectImage.createGraphics();  
                         /* System.out.println("rendering selection"); */  
                         selectionRenderer.paint((Graphics2D) ig, dr, mapArea);  
   
                         ((Graphics2D) g).drawImage(selectImage, 0, 0, this);  
                 }  
   
                 if (highlight && (highlightFeature != null)  
                                 && (highlightFeature.size() > 0)) {  
                         /*  
                          * String type = selection.getDefaultGeometry().getGeometryType();  
                          * System.out.println(type); if(type==null) type="polygon";  
                          */  
                         String type = highlightLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getType().getName();  
                         /* String type = selection.getDefaultGeometry().getGeometryType(); */  
                         // System.out.println(type);  
                         if (type == null)  
                                 type = "polygon";  
   
                         /* String type = "point"; */  
                         Style highlightStyle = null;  
                         if (type.toLowerCase().endsWith("polygon")) {  
                                 highlightStyle = polygonHighlightStyle;  
                         } else if (type.toLowerCase().endsWith("point")) {  
                                 highlightStyle = pointHighlightStyle;  
                         } else if (type.toLowerCase().endsWith("line")) {  
                                 highlightStyle = lineHighlightStyle;  
                         }  
   
                         MapContext highlightContext = new DefaultMapContext(  
                                         DefaultGeographicCRS.WGS84);  
   
                         highlightContext.addLayer(highlightFeature, highlightStyle);  
                         highlightRenderer.setContext(highlightContext);  
   
                         /* System.out.println("rendering highlight"); */  
                         highlightRenderer.paint((Graphics2D) g, dr, mapArea);  
                 }  
361          }          }
362    
363          private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {          public void mouseClicked(final MouseEvent e) {
364                    if (mapArea == null)
                 double mapWidth = mapArea.getWidth(); /* get the extent of the map */  
                 double mapHeight = mapArea.getHeight();  
                 double scaleX = r.getWidth() / mapArea.getWidth(); /*  
                                                                                                                          * calculate the new  
                                                                                                                          * scale  
                                                                                                                          */  
   
                 double scaleY = r.getHeight() / mapArea.getHeight();  
                 double scale = 1.0; // stupid compiler!  
   
                 if (scaleX < scaleY) { /* pick the smaller scale */  
                         scale = scaleX;  
                 } else {  
                         scale = scaleY;  
                 }  
   
                 /* calculate the difference in width and height of the new extent */  
                 double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);  
                 double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);  
   
                 /*  
                  * System.out.println("delta x " + deltaX);  
                  * System.out.println("delta y " + deltaY);  
                  */  
   
                 /* create the new extent */  
                 Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),  
                                 mapArea.getMinY() - (deltaY / 2.0));  
                 Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),  
                                 mapArea.getMaxY() + (deltaY / 2.0));  
   
                 return new Envelope(ll, ur);  
         }  
   
         public void doSelection(double x, double y, MapLayer layer) {  
   
                 Geometry geometry = gf.createPoint(new Coordinate(x, y));  
   
                 // org.opengis.geometry.Geometry geometry = new Point();  
   
                 findFeature(geometry, layer);  
   
         }  
   
         /**  
          * @param geometry  
          *            - a geometry to construct the filter with  
          * @param i  
          *            - the index of the layer to search  
          * @throws IndexOutOfBoundsException  
          */  
         private void findFeature(Geometry geometry, MapLayer layer)  
                         throws IndexOutOfBoundsException {  
                 org.opengis.filter.spatial.BinarySpatialOperator f = null;  
   
                 if ((context == null) || (layer == null)) {  
365                          return;                          return;
                 }  
   
                 try {  
                         String name = layer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getLocalName();  
   
                         if (name == "") {  
                                 name = "the_geom";  
                         }  
   
                         try {  
                                 f = ff.contains(ff.property(name), ff.literal(geometry));  
                                 if (selectionManager != null) {  
 //                                      System.out.println("selection changed");  
                                         selectionManager.selectionChanged(this, f);  
   
                                 }  
                         } catch (IllegalFilterException e) {  
                                 // TODO Auto-generated catch block  
                                 e.printStackTrace();  
                         }  
   
                         /*  
                          * // f.addLeftGeometry(ff.property(name)); //  
                          * System.out.println("looking with " + f); FeatureCollection fc =  
                          * layer.getFeatureSource().getFeatures(f);  
                          *  
                          *  
                          *  
                          * if (fcol == null) { fcol = fc;  
                          *  
                          * // here we should set the defaultgeom type } else {  
                          * fcol.addAll(fc); }  
                          */  
   
                         /*  
                          * GeometryAttributeType gat =  
                          * layer.getFeatureSource().getSchema().getDefaultGeometry();  
                          * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());  
                          */  
   
                         /*  
                          * Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat  
                          * = (Feature) fi.next(); System.out.println("selected " +  
                          * feat.getAttribute("STATE_NAME")); }  
                          */  
                 } catch (IllegalFilterException e) {  
                         // TODO Auto-generated catch block  
                         e.printStackTrace();  
                 }  
                 return;  
         }  
   
         public void mouseClicked(MouseEvent e) {  
                 if (mapArea == null) return;  
366                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
367                  // h:"+mapArea.getHeight());                  // h:"+mapArea.getHeight());
368                  Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
369                  double x = (double) (e.getX());                  final double x = (double) (e.getX());
370                  double y = (double) (e.getY());                  final double y = (double) (e.getY());
371                  double width = mapArea.getWidth();                  final double width = mapArea.getWidth();
372                  double height = mapArea.getHeight();                  final double height = mapArea.getHeight();
373                  // xulu.sc                  // xulu.sc
374                  // double width2 = mapArea.getWidth() / 2.0;                  // double width2 = mapArea.getWidth() / 2.0;
375                  // double height2 = mapArea.getHeight() / 2.0;                  // double height2 = mapArea.getHeight() / 2.0;
376                  double width2 = width / 2.0;                  final double width2 = width / 2.0;
377                  double height2 = height / 2.0;                  final double height2 = height / 2.0;
378                  // xulu.ec                  // xulu.ec
379                  double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();                  final double mapX = ((x * width) / (double) bounds.width)
380                  double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)                                  + mapArea.getMinX();
381                    final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
382                                  + mapArea.getMinY();                                  + mapArea.getMinY();
383    
384                  /*                  /*
# Line 778  public class JMapPane extends JPanel imp Line 408  public class JMapPane extends JPanel imp
408                          zlevel = 1.0 / zoomFactor;                          zlevel = 1.0 / zoomFactor;
409    
410                          break;                          break;
411                    //
412                  case Select:                  // case Select:
413                          doSelection(mapX, mapY, selectionLayer);                  // doSelection(mapX, mapY, selectionLayer);
414                    //
415                          return;                  // return;
416    
417                  default:                  default:
418                          return;                          return;
419                  }                  }
420    
421                  Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY                  final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY
422                                  - (height2 / zlevel));                                  - (height2 / zlevel));
423                  Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY                  final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY
424                                  + (height2 / zlevel));                                  + (height2 / zlevel));
425                  // xulu.sc SK: Check for min/max scale                  // xulu.sc SK: Check for min/max scale
426                  // mapArea = new Envelope(ll, ur);                  // mapArea = new Envelope(ll, ur);
# Line 805  public class JMapPane extends JPanel imp Line 435  public class JMapPane extends JPanel imp
435                  repaint();                  repaint();
436          }          }
437    
438          public void mouseEntered(MouseEvent e) {          public void mouseEntered(final MouseEvent e) {
439          }          }
440    
441          public void mouseExited(MouseEvent e) {          public void mouseExited(final MouseEvent e) {
442          }          }
443    
444          public void mousePressed(MouseEvent e) {          public void mousePressed(final MouseEvent e) {
445                  startX = e.getX();                  startX = e.getX();
446                  startY = e.getY();                  startY = e.getY();
447                  lastX = 0;                  lastX = 0;
448                  lastY = 0;                  lastY = 0;
449          }          }
450    
451          public void mouseReleased(MouseEvent e) {          public void mouseReleased(final MouseEvent e) {
452                  int endX = e.getX();                  final int endX = e.getX();
453                  int endY = e.getY();                  final int endY = e.getY();
454    
455                  processDrag(startX, startY, endX, endY, e);                  processDrag(startX, startY, endX, endY, e);
456                  lastX = 0;                  lastX = 0;
# Line 832  public class JMapPane extends JPanel imp Line 462  public class JMapPane extends JPanel imp
462                  panning_started = false;                  panning_started = false;
463          }          }
464    
465          public void mouseDragged(MouseEvent e) {          public void mouseDragged(final MouseEvent e) {
466                  Graphics graphics = this.getGraphics();                  final Graphics graphics = this.getGraphics();
467                  int x = e.getX();                  final int x = e.getX();
468                  int y = e.getY();                  final int y = e.getY();
469    
470                  if ((state == JMapPane.Pan)                  if ((state == JMapPane.Pan)
471                                  || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {                                  || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
# Line 849  public class JMapPane extends JPanel imp Line 479  public class JMapPane extends JPanel imp
479    
480                          // move the image with the mouse                          // move the image with the mouse
481                          if ((lastX > 0) && (lastY > 0)) {                          if ((lastX > 0) && (lastY > 0)) {
482                                  int dx = lastX - startX;                                  final int dx = lastX - startX;
483                                  int dy = lastY - startY;                                  final int dy = lastY - startY;
484                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
485                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
486                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige
487                                                                                                                          // farbe? am besten                                  // farbe? am besten
488                                                                                                                          // vom L&F die                                  // vom L&F die
489                                                                                                                          // hintergrundfarbe                                  // hintergrundfarbe
490                                                                                                                          // auslesen...                                  // auslesen...
491                                    
492                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
493                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
494                                  graphics.drawImage(panningImage, 0, 0, this);                                  graphics.drawImage(panningImage, 0, 0, this);
# Line 880  public class JMapPane extends JPanel imp Line 510  public class JMapPane extends JPanel imp
510                          lastX = x;                          lastX = x;
511                          lastY = y;                          lastY = y;
512                          drawRectangle(graphics);                          drawRectangle(graphics);
                 } else if (state == JMapPane.Select && selectionLayer != null) {  
   
                         // construct a new bbox filter  
                         Rectangle bounds = this.getBounds();  
   
                         double mapWidth = mapArea.getWidth();  
                         double mapHeight = mapArea.getHeight();  
   
                         double x1 = ((this.startX * mapWidth) / (double) bounds.width)  
                                         + mapArea.getMinX();  
                         double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)  
                                         + mapArea.getMinY();  
                         double x2 = ((x * mapWidth) / (double) bounds.width)  
                                         + mapArea.getMinX();  
                         double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)  
                                         + mapArea.getMinY();  
                         double left = Math.min(x1, x2);  
                         double right = Math.max(x1, x2);  
                         double bottom = Math.min(y1, y2);  
                         double top = Math.max(y1, y2);  
   
                         String name = selectionLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getName();  
   
                         if (name == "") {  
                                 name = "the_geom";  
                         }  
                         Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,  
                                         getContext().getCoordinateReferenceSystem().toString());  
                         if (selectionManager != null) {  
                                 selectionManager.selectionChanged(this, bb);  
                         }  
   
                         graphics.setXORMode(Color.green);  
   
                         /*  
                          * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }  
                          */  
   
                         // draw new box  
                         lastX = x;  
                         lastY = y;  
                         drawRectangle(graphics);  
513                  }                  }
514                    // else if (state == JMapPane.Select && selectionLayer != null) {
515                    //
516                    // // construct a new bbox filter
517                    // final Rectangle bounds = this.getBounds();
518                    //
519                    // final double mapWidth = mapArea.getWidth();
520                    // final double mapHeight = mapArea.getHeight();
521                    //
522                    // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
523                    // + mapArea.getMinX();
524                    // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
525                    // (double) bounds.height)
526                    // + mapArea.getMinY();
527                    // final double x2 = ((x * mapWidth) / (double) bounds.width)
528                    // + mapArea.getMinX();
529                    // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
530                    // bounds.height)
531                    // + mapArea.getMinY();
532                    // final double left = Math.min(x1, x2);
533                    // final double right = Math.max(x1, x2);
534                    // final double bottom = Math.min(y1, y2);
535                    // final double top = Math.max(y1, y2);
536                    //
537                    // String name = selectionLayer.getFeatureSource().getSchema()
538                    // .getDefaultGeometry().getName();
539                    //
540                    // if (name == "") {
541                    // name = "the_geom";
542                    // }
543                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
544                    // top,
545                    // getContext().getCoordinateReferenceSystem().toString());
546                    // if (selectionManager != null) {
547                    // selectionManager.selectionChanged(this, bb);
548                    // }
549                    //
550                    // graphics.setXORMode(Color.green);
551                    //
552                    // /*
553                    // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
554                    // */
555                    //
556                    // // draw new box
557                    // lastX = x;
558                    // lastY = y;
559                    // drawRectangle(graphics);
560                    // }
561    
562          }          }
563    
# Line 931  public class JMapPane extends JPanel imp Line 565  public class JMapPane extends JPanel imp
565          // private void processDrag(int x1, int y1, int x2, int y2) {          // private void processDrag(int x1, int y1, int x2, int y2) {
566          // sk.ce          // sk.ce
567          protected void processDrag(final int x1, final int y1, final int x2,          protected void processDrag(final int x1, final int y1, final int x2,
568                          final int y2, MouseEvent e) {                          final int y2, final MouseEvent e) {
569    
570                  /****                  /****
571                   * If no layer is availabe we dont want a NullPointerException                   * If no layers exist, we ignore the drag.
572                   */                   */
573                  if (mapArea == null)                  if (context.getLayerCount() <= 0) {
574                          return;                          return;
575                    }
576    
577                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
578                  // + x2 + "," + y2);                  // + x2 + "," + y2);
# Line 950  public class JMapPane extends JPanel imp Line 585  public class JMapPane extends JPanel imp
585                          return;                          return;
586                  }                  }
587    
588                  Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
589    
590                  double mapWidth = mapArea.getWidth();                  final double mapWidth = mapArea.getWidth();
591                  double mapHeight = mapArea.getHeight();                  final double mapHeight = mapArea.getHeight();
592    
593                  double startX = ((x1 * mapWidth) / (double) bounds.width)                  final double startX = ((x1 * mapWidth) / (double) bounds.width)
594                                  + mapArea.getMinX();                                  + mapArea.getMinX();
595                  double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)                  final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)
596                                  + mapArea.getMinY();                                  + mapArea.getMinY();
597                  double endX = ((x2 * mapWidth) / (double) bounds.width)                  final double endX = ((x2 * mapWidth) / (double) bounds.width)
598                                  + mapArea.getMinX();                                  + mapArea.getMinX();
599                  double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)                  final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)
600                                  + mapArea.getMinY();                                  + mapArea.getMinY();
601    
602                  if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {                  if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {
603                          // move the image with the mouse                          // move the image with the mouse
604                          // calculate X offsets from start point to the end Point                          // calculate X offsets from start point to the end Point
605                          double deltaX1 = endX - startX;                          final double deltaX1 = endX - startX;
606    
607                          // System.out.println("deltaX " + deltaX1);                          // System.out.println("deltaX " + deltaX1);
608                          // new edges                          // new edges
609                          double left = mapArea.getMinX() - deltaX1;                          final double left = mapArea.getMinX() - deltaX1;
610                          double right = mapArea.getMaxX() - deltaX1;                          final double right = mapArea.getMaxX() - deltaX1;
611    
612                          // now for Y                          // now for Y
613                          double deltaY1 = endY - startY;                          final double deltaY1 = endY - startY;
614    
615                          // System.out.println("deltaY " + deltaY1);                          // System.out.println("deltaY " + deltaY1);
616                          double bottom = mapArea.getMinY() - deltaY1;                          final double bottom = mapArea.getMinY() - deltaY1;
617                          double top = mapArea.getMaxY() - deltaY1;                          final double top = mapArea.getMaxY() - deltaY1;
618                          Coordinate ll = new Coordinate(left, bottom);                          final Coordinate ll = new Coordinate(left, bottom);
619                          Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
620                          // xulu.sc                          // xulu.sc
621                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
622                          setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));  
623                            setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
624                          // xulu.ec                          // xulu.ec
625                  } else if (state == JMapPane.ZoomIn) {                  } else if (state == JMapPane.ZoomIn) {
626    
# Line 996  public class JMapPane extends JPanel imp Line 632  public class JMapPane extends JPanel imp
632    
633                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
634                          // make the dragged rectangle (in map coords) the new BBOX                          // make the dragged rectangle (in map coords) the new BBOX
635                          double left = Math.min(startX, endX);                          final double left = Math.min(startX, endX);
636                          double right = Math.max(startX, endX);                          final double right = Math.max(startX, endX);
637                          double bottom = Math.min(startY, endY);                          final double bottom = Math.min(startY, endY);
638                          double top = Math.max(startY, endY);                          final double top = Math.max(startY, endY);
639                          Coordinate ll = new Coordinate(left, bottom);                          final Coordinate ll = new Coordinate(left, bottom);
640                          Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
641                          // xulu.sc                          // xulu.sc
642    
643                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
644                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
645    
646                          // sk.sc                          // sk.sc
647  //                      {                          // {
648  //                      // SK tries to paint a preview of the zoom ;-9 aha.... well                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
649  //                      Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
650  //                      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
651  //                                      RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
652  //                      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
653  //                                      RenderingHints.VALUE_ANTIALIAS_OFF);                          // RenderingHints.VALUE_ANTIALIAS_OFF);
654  //                      graphics.setRenderingHint(RenderingHints.KEY_RENDERING,                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
655  //                                      RenderingHints.VALUE_RENDER_SPEED);                          // RenderingHints.VALUE_RENDER_SPEED);
656  //                      graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
657  //                                      JMapPane.this.getHeight(), x1, y1, x2, y2, null);                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
658  //                      }                          // }
659                          // xulu.ec                          // xulu.ec
660                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
661                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
662    
663                          // make the dragged rectangle in screen coords the new map size?                          // make the dragged rectangle in screen coords the new map size?
664                          double left = Math.min(startX, endX);                          final double left = Math.min(startX, endX);
665                          double right = Math.max(startX, endX);                          final double right = Math.max(startX, endX);
666                          double bottom = Math.min(startY, endY);                          final double bottom = Math.min(startY, endY);
667                          double top = Math.max(startY, endY);                          final double top = Math.max(startY, endY);
668                          double nWidth = (mapWidth * mapWidth) / (right - left);                          final double nWidth = (mapWidth * mapWidth) / (right - left);
669                          double nHeight = (mapHeight * mapHeight) / (top - bottom);                          final double nHeight = (mapHeight * mapHeight) / (top - bottom);
670                          double deltaX1 = left - mapArea.getMinX();                          final double deltaX1 = left - mapArea.getMinX();
671                          double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;                          final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
672                          double deltaY1 = bottom - mapArea.getMinY();                          final double deltaY1 = bottom - mapArea.getMinY();
673                          double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;                          final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
674                          Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,                          final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
675                                          mapArea.getMinY() - nDeltaY1);                                          mapArea.getMinY() - nDeltaY1);
676                          double deltaX2 = mapArea.getMaxX() - right;                          final double deltaX2 = mapArea.getMaxX() - right;
677                          double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;                          final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
678                          double deltaY2 = mapArea.getMaxY() - top;                          final double deltaY2 = mapArea.getMaxY() - top;
679                          double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;                          final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
680                          Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,                          final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
681                                          mapArea.getMaxY() + nDeltaY2);                                          mapArea.getMaxY() + nDeltaY2);
682                          // xulu.sc                          // xulu.sc
683                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
684                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
685    
686                          // xulu.ec                          // 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(); }  
                          */  
687                  }                  }
688                    // else if (state == JMapPane.Select && selectionLayer != null) {
689                    // final double left = Math.min(startX, endX);
690                    // final double right = Math.max(startX, endX);
691                    // final double bottom = Math.min(startY, endY);
692                    // final double top = Math.max(startY, endY);
693                    //
694                    // String name = selectionLayer.getFeatureSource().getSchema()
695                    // .getDefaultGeometry().getLocalName();
696                    //
697                    // if (name == "") {
698                    // name = "the_geom";
699                    // }
700                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
701                    // top,
702                    // getContext().getCoordinateReferenceSystem().toString());
703                    // // System.out.println(bb.toString());
704                    // if (selectionManager != null) {
705                    // selectionManager.selectionChanged(this, bb);
706                    // }
707                    // /*
708                    // * FeatureCollection fc; selection = null; try { fc =
709                    // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
710                    // * fc; } catch (IOException e) { e.printStackTrace(); }
711                    // */
712                    // }
713    
714                  // xulu.so                  // xulu.so
715                  // setMapArea(mapArea);                  // setMapArea(mapArea);
# Line 1083  public class JMapPane extends JPanel imp Line 721  public class JMapPane extends JPanel imp
721                  return clickable;                  return clickable;
722          }          }
723    
724          private org.geotools.styling.Style setupStyle(int type, Color color) {          //
725                  StyleFactory sf = org.geotools.factory.CommonFactoryFinder          // private org.geotools.styling.Style setupStyle(final int type, final Color
726                                  .getStyleFactory(null);          // color) {
727                  StyleBuilder sb = new StyleBuilder();          // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
728            // .getStyleFactory(null);
729                  org.geotools.styling.Style s = sf.createStyle();          // final StyleBuilder sb = new StyleBuilder();
730                  s.setTitle("selection");          //
731            // org.geotools.styling.Style s = sf.createStyle();
732                  // TODO parameterise the color          // s.setTitle("selection");
733                  PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);          //
734                  ps.setStroke(sb.createStroke(color));          // // TODO parameterise the color
735            // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
736                  LineSymbolizer ls = sb.createLineSymbolizer(color);          // ps.setStroke(sb.createStroke(color));
737                  Graphic h = sb.createGraphic();          //
738                  h.setMarks(new Mark[] { sb.createMark("square", color) });          // final LineSymbolizer ls = sb.createLineSymbolizer(color);
739            // final Graphic h = sb.createGraphic();
740                  PointSymbolizer pts = sb.createPointSymbolizer(h);          // h.setMarks(new Mark[] { sb.createMark("square", color) });
741            //
742                  // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});          // final PointSymbolizer pts = sb.createPointSymbolizer(h);
743                  switch (type) {          //
744                  case POLYGON:          // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
745                          s = sb.createStyle(ps);          // switch (type) {
746            // case POLYGON:
747                          break;          // s = sb.createStyle(ps);
748            //
749                  case POINT:          // break;
750                          s = sb.createStyle(pts);          //
751            // case POINT:
752                          break;          // s = sb.createStyle(pts);
753            //
754                  case LINE:          // break;
755                          s = sb.createStyle(ls);          //
756                  }          // case LINE:
757            // s = sb.createStyle(ls);
758                  return s;          // }
759          }          //
760            // return s;
761          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();  
         }  
762    
763          public void propertyChange(PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
764                  String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
765    
766                  if (prop.equalsIgnoreCase("crs")) {                  if (prop.equalsIgnoreCase("crs")) {
767                          context.setAreaOfInterest(context.getAreaOfInterest(),                          context.setAreaOfInterest(context.getAreaOfInterest(),
# Line 1146  public class JMapPane extends JPanel imp Line 773  public class JMapPane extends JPanel imp
773                  return reset;                  return reset;
774          }          }
775    
776          public void setReset(boolean reset) {          public void setReset(final boolean reset) {
777                  this.reset = reset;                  this.reset = reset;
778          }          }
779    
780          public void layerAdded(MapLayerListEvent event) {          public void layerAdded(final MapLayerListEvent event) {
781                  changed = true;                  changed = true;
782    
783                  if (context.getLayers().length == 1) { // the first one                  if (context.getLayers().length == 1) { // the first one
# Line 1162  public class JMapPane extends JPanel imp Line 789  public class JMapPane extends JPanel imp
789                                  if (mapArea == null)                                  if (mapArea == null)
790                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
791                                  // xulu.ec                                  // xulu.ec
792                          } catch (IOException e) {                          } catch (final IOException e) {
793                                  // TODO Auto-generated catch block                                  // TODO Auto-generated catch block
794                                  e.printStackTrace();                                  e.printStackTrace();
795                          }                          }
# Line 1173  public class JMapPane extends JPanel imp Line 800  public class JMapPane extends JPanel imp
800                  repaint();                  repaint();
801          }          }
802    
803          public void layerRemoved(MapLayerListEvent event) {          public void layerRemoved(final MapLayerListEvent event) {
804                  changed = true;                  changed = true;
805                  repaint();                  repaint();
806          }          }
807    
808          public void layerChanged(MapLayerListEvent event) {          public void layerChanged(final MapLayerListEvent event) {
809                  changed = true;                  changed = true;
810                  // System.out.println("layer changed - repaint");                  // System.out.println("layer changed - repaint");
811                  repaint();                  repaint();
812          }          }
813    
814          public void layerMoved(MapLayerListEvent event) {          public void layerMoved(final MapLayerListEvent event) {
815                  changed = true;                  changed = true;
816                  repaint();                  repaint();
817          }          }
818    
819          protected void drawRectangle(Graphics graphics) {          protected void drawRectangle(final Graphics graphics) {
820                  // undraw last box/draw new box                  // undraw last box/draw new box
821                  int left = Math.min(startX, lastX);                  final int left = Math.min(startX, lastX);
822                  int right = Math.max(startX, lastX);                  final int right = Math.max(startX, lastX);
823                  int top = Math.max(startY, lastY);                  final int top = Math.max(startY, lastY);
824                  int bottom = Math.min(startY, lastY);                  final int bottom = Math.min(startY, lastY);
825                  int width = right - left;                  final int width = right - left;
826                  int height = top - bottom;                  final int height = top - bottom;
827                  // System.out.println("drawing rect("+left+","+bottom+","+ width+","+                  // System.out.println("drawing rect("+left+","+bottom+","+ width+","+
828                  // height+")");                  // height+")");
829                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
# Line 1208  public class JMapPane extends JPanel imp Line 835  public class JMapPane extends JPanel imp
835           *           *
836           * @param clickable           * @param clickable
837           */           */
838          public void setClickable(boolean clickable) {          public void setClickable(final boolean clickable) {
839                  this.clickable = clickable;                  this.clickable = clickable;
840          }          }
841    
842          public void mouseMoved(MouseEvent e) {          public void mouseMoved(final 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);  
   
843          }          }
844    
845          // xulu.sn          // xulu.sn
# Line 1270  public class JMapPane extends JPanel imp Line 860  public class JMapPane extends JPanel imp
860                  if (env == null)                  if (env == null)
861                          return env;                          return env;
862    
863                    Envelope newArea = null;
864    
865                  /**                  /**
866                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
867                   * easily fail.                   * easily fail. We allow to grow here, because we don't check against
868                     * the maxExtend
869                   */                   */
870                  env = fixAspectRatio(this.getBounds(), env);                  env = JTSUtil.fixAspectRatio(this.getBounds(), env, true);
871    
872                  double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
873                  double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
874                  double centerY = env.getMinY() + env.getHeight() / 2.;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
875                  double newWidth2;                  double newWidth2 = 0;
876                  double newHeight2;                  double newHeight2 = 0;
877                  if (scale < getMaxZoomScale()) {                  if (scale < getMaxZoomScale()) {
878                          // ****************************************************************************                          // ****************************************************************************
879                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
# Line 1297  public class JMapPane extends JPanel imp Line 890  public class JMapPane extends JPanel imp
890                          // ****************************************************************************                          // ****************************************************************************
891                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
892                          // ****************************************************************************                          // ****************************************************************************
893                          return env;                          newArea = env;
894                  }                  }
895    
896                  Coordinate ll = new Coordinate(centerX - newWidth2, centerY                  if (newArea == null) {
897                                  - newHeight2);  
898                  Coordinate ur = new Coordinate(centerX + newWidth2, centerY                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
899                                  + newHeight2);                                          - newHeight2);
900                            final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
901                                            + newHeight2);
902    
903                            newArea = new Envelope(ll, ur);
904                    }
905    
906                    Envelope maxAllowedExtend = getMaxExtend();
907                    while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
908                                    && newArea != null && !newArea.isNull()
909                                    && !Double.isNaN(newArea.getMinX())
910                                    && !Double.isNaN(newArea.getMaxX())
911                                    && !Double.isNaN(newArea.getMinY())
912                                    && !Double.isNaN(newArea.getMaxY())) {
913                            /*
914                             * If a maxExtend is set, we have to honour that...
915                             */
916    
917                            // Exceeds top? Move down and maybe cut
918                            if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
919                                    double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
920                                    // LOGGER.debug("Moving area down by " + divY);
921    
922                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
923                                                    newArea.getMinY() - divY), new Coordinate(newArea
924                                                    .getMaxX(), newArea.getMaxY() - divY));
925    
926                                    if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
927                                            // LOGGER.debug("Now it exeeds the bottom border.. cut!");
928                                            // And cut the bottom if it moved out of the area
929                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
930                                                            maxAllowedExtend.getMinY()), new Coordinate(newArea
931                                                            .getMaxX(), newArea.getMaxY()));
932    
933                                            // LOGGER.debug("and fix aspect ratio");
934    
935                                            newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
936                                                            false);
937                                    }
938                            }
939    
940                            // Exceeds bottom? Move up and maybe cut
941                            if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
942                                    double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
943                                    // LOGGER.debug("Moving area up by " + divY);
944    
945                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
946                                                    newArea.getMinY() - divY), new Coordinate(newArea
947                                                    .getMaxX(), newArea.getMaxY() - divY));
948    
949                                    if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
950                                            // LOGGER.debug("Now it exeeds the top border.. cut!");
951                                            // And cut the bottom if it moved out of the area
952                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
953                                                            newArea.getMinY()), new Coordinate(newArea
954                                                            .getMaxX(), maxAllowedExtend.getMaxY()));
955    
956                                            // LOGGER.debug("and fix aspect ratio");
957    
958                  return new Envelope(ll, ur);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
959                                                            false);
960                                    }
961                            }
962    
963                            // Exceeds to the right? move and maybe cut
964                            if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
965    
966                                    // Move left..
967                                    double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
968                                    // LOGGER.debug("Moving area left by " + divX);
969    
970                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
971                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
972                                                    - divX, newArea.getMaxY()));
973    
974                                    if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
975                                            // LOGGER.debug("Now it exeeds the left border.. cut!");
976                                            // And cut the left if it moved out of the area
977                                            newArea = new Envelope(new Coordinate(maxAllowedExtend
978                                                            .getMinX(), newArea.getMinY()), new Coordinate(
979                                                            newArea.getMaxX(), newArea.getMaxY()));
980    
981                                            // LOGGER.debug("and fix aspect ratio");
982    
983                                            newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
984                                                            false);
985                                    }
986                            }
987    
988                            // Exceeds to the left? move and maybe cut
989                            if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
990    
991                                    // Move right..
992                                    double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
993                                    // LOGGER.debug("Moving area right by " + divX);
994    
995                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
996                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
997                                                    - divX, newArea.getMaxY()));
998    
999                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1000                                            // LOGGER.debug("Now it exeeds the right border.. cut!");
1001                                            // And cut the left if it moved out of the area
1002                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1003                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
1004                                                            .getMaxX(), newArea.getMaxY()));
1005    
1006                                            // LOGGER.debug("and fix aspect ratio");
1007    
1008                                            newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
1009                                                            false);
1010                                    }
1011                            }
1012    
1013                    }
1014    
1015                    return newArea;
1016          }          }
1017    
1018          /**          /**
# Line 1332  public class JMapPane extends JPanel imp Line 1039  public class JMapPane extends JPanel imp
1039    
1040          /**          /**
1041           * Set the maximum allowed zoom scale. This is the smaller number value of           * Set the maximum allowed zoom scale. This is the smaller number value of
1042           * the two.           * the two. If <code>null</code> is passed, Double.MINVALUE are used which
1043             * mean there is no restriction.
1044           *           *
1045           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1046           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1047           */           */
1048          public void setMaxZoomScale(Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
1049                  // System.out.println("setting max scale to "+maxZoomScale);                  this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
1050                  this.maxZoomScale = maxZoomScale;                                  : maxZoomScale;
1051          }          }
1052    
1053          /**          /**
1054           * Set the minimum (nearest) allowed zoom scale. This is the bigger number           * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1055           * value of the two.           * value of the two. If <code>null</code> is passed, Double.MAXVALUE are
1056             * used which mean there is no restriction.
1057             *
1058           *           *
1059           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1060           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1061           */           */
1062          public void setMinZoomScale(Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1063                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE
1064                                    : minZoomScale;
1065            }
1066    
1067            /**
1068             * Defines an evelope of the viwable area. The JMapPane will never show
1069             * anything outside of this extend.
1070             *
1071             * @param maxExtend
1072             *            <code>null</code> to not have this restriction.
1073             */
1074            public void setMaxExtend(Envelope maxExtend) {
1075                    this.maxExtend = maxExtend;
1076            }
1077    
1078            /**
1079             * Returns the evelope of the viewable area. The JMapPane will never show
1080             * anything outside of this extend. If this has been set to
1081             * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1082             * quickly the context's bounds. It it takes to long to determine the
1083             * context bounds, <code>null</code> is returned.
1084             *
1085             * @param maxExtend
1086             *            <code>null</code> to not have this restriction.
1087             */
1088    
1089            public Envelope getMaxExtend() {
1090                    if (maxExtend == null) {
1091                            try {
1092                                    return JTSUtil.fixAspectRatio(this.getBounds(),
1093                                                    // Kartenbereich um 10% vergroessern
1094                                                    JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1095                                                    true);
1096                            } catch (IOException e) {
1097                                    LOGGER
1098                                                    .warn(
1099                                                                    "maxExtend == null; failed to getLayerBounds of context",
1100                                                                    e);
1101                            }
1102                    }
1103                    return maxExtend;
1104          }          }
         // xulu.en  
1105    
1106  }  }

Legend:
Removed from v.207  
changed lines
  Added in v.504

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26