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

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

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

trunk/src/org/geotools/gui/swing/JMapPane.java revision 2 by mojays, Tue Feb 24 22:43:52 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java revision 555 by alfonx, Tue Nov 24 09:17:22 2009 UTC
# Line 1  Line 1 
1  /*  package skrueger.geotools;
  *    GeoTools - OpenSource mapping toolkit  
  *    http://geotools.org  
  *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)  
  *  
  *    This library is free software; you can redistribute it and/or  
  *    modify it under the terms of the GNU Lesser General Public  
  *    License as published by the Free Software Foundation;  
  *    version 2.1 of the License.  
  *  
  *    This library is distributed in the hope that it will be useful,  
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of  
  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  
  *    Lesser General Public License for more details.  
  */  
 package org.geotools.gui.swing;  
   
 /**  
  * <b>Xulu:<br>  
  *    Code taken from gt-2.4.2 to make some changes (marked with {@code xulu}),  
  *    which can not be realized in a subclass:</b>  
  *    <ul>  
  *       <li>{@link #getMapArea()} declared as {@code final}<li>  
  *       <li>some variables declared as {@code protected}</li>  
  *       <li>minimal/maximal zoom scale</li>  
  *       <li>zoom in and zoom out via mouse click realized by setMapArea(..)</li>  
  *    </ul>  
  * <br><br>  
  * A simple map container that is a JPanel with a map in. provides simple  
  * pan,zoom, highlight and selection The mappane stores an image of the map  
  * (drawn from the context) and an image of the slected feature(s) to speed up  
  * rendering of the highlights. Thus the whole map is only redrawn when the bbox  
  * changes, selection is only redrawn when the selected feature changes.  
  *  
  *  
  * @author Ian Turton  
  *  
  */  
2    
3  import java.awt.Color;  import java.awt.Color;
4  import java.awt.Cursor;  import java.awt.Cursor;
5    import java.awt.Font;
6  import java.awt.Graphics;  import java.awt.Graphics;
7  import java.awt.Graphics2D;  import java.awt.Graphics2D;
8  import java.awt.LayoutManager;  import java.awt.Image;
9    import java.awt.Point;
10  import java.awt.Rectangle;  import java.awt.Rectangle;
11    import java.awt.RenderingHints;
12    import java.awt.event.ActionEvent;
13    import java.awt.event.ActionListener;
14    import java.awt.event.ComponentAdapter;
15    import java.awt.event.ComponentEvent;
16  import java.awt.event.InputEvent;  import java.awt.event.InputEvent;
17  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
18  import java.awt.event.MouseListener;  import java.awt.event.MouseListener;
19  import java.awt.event.MouseMotionListener;  import java.awt.geom.AffineTransform;
20    import java.awt.geom.NoninvertibleTransformException;
21    import java.awt.geom.Point2D;
22  import java.awt.image.BufferedImage;  import java.awt.image.BufferedImage;
 import java.beans.PropertyChangeEvent;  
 import java.beans.PropertyChangeListener;  
23  import java.io.IOException;  import java.io.IOException;
24  import java.util.Date;  import java.util.ArrayList;
25  import java.util.HashMap;  import java.util.HashMap;
26  import java.util.Map;  import java.util.Map;
27    import java.util.Vector;
28    
29  import javax.swing.JPanel;  import javax.swing.Timer;
30    
31  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
32  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
33  import org.geotools.filter.IllegalFilterException;  import org.geotools.geometry.jts.JTS;
34  import org.geotools.gui.swing.event.HighlightChangeListener;  import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.gui.swing.event.HighlightChangedEvent;  
 import org.geotools.gui.swing.event.SelectionChangeListener;  
 import org.geotools.gui.swing.event.SelectionChangedEvent;  
35  import org.geotools.map.DefaultMapContext;  import org.geotools.map.DefaultMapContext;
36  import org.geotools.map.MapContext;  import org.geotools.map.MapContext;
37  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
38    import org.geotools.map.event.MapLayerEvent;
39  import org.geotools.map.event.MapLayerListEvent;  import org.geotools.map.event.MapLayerListEvent;
40  import org.geotools.map.event.MapLayerListListener;  import org.geotools.map.event.MapLayerListListener;
41  import org.geotools.referencing.crs.DefaultGeographicCRS;  import org.geotools.map.event.MapLayerListener;
42    import org.geotools.referencing.CRS;
43  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
44    import org.geotools.renderer.label.LabelCacheImpl;
45  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
46  import org.geotools.renderer.lite.LabelCacheDefault;  import org.geotools.renderer.lite.RendererUtilities;
47  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
48  import org.geotools.styling.Graphic;  import org.geotools.swing.JMapPane;
49  import org.geotools.styling.LineSymbolizer;  import org.geotools.swing.event.MapMouseEvent;
50  import org.geotools.styling.Mark;  import org.geotools.swing.event.MapPaneEvent;
51  import org.geotools.styling.PointSymbolizer;  import org.geotools.swing.event.MapPaneListener;
52  import org.geotools.styling.PolygonSymbolizer;  import org.opengis.feature.simple.SimpleFeature;
53  import org.geotools.styling.Style;  import org.opengis.feature.simple.SimpleFeatureType;
54  import org.geotools.styling.StyleBuilder;  import org.opengis.referencing.FactoryException;
 import org.geotools.styling.StyleFactory;  
 import org.opengis.filter.Filter;  
 import org.opengis.filter.FilterFactory2;  
55  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
56    import org.opengis.referencing.operation.MathTransform;
57    import org.opengis.referencing.operation.TransformException;
58    
59    import schmitzm.geotools.GTUtil;
60    import schmitzm.geotools.JTSUtil;
61    import schmitzm.geotools.gui.SelectableXMapPane;
62    import schmitzm.geotools.io.GeoImportUtil;
63    import schmitzm.geotools.map.event.JMapPaneListener;
64    import schmitzm.geotools.map.event.MapLayerAdapter;
65    import schmitzm.lang.LangUtil;
66    import schmitzm.swing.JPanel;
67  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
68    
69  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
70  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
71  import com.vividsolutions.jts.geom.Geometry;  import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;  
72    
73  public class JMapPane extends JPanel implements MouseListener,  /**
74          MouseMotionListener, HighlightChangeListener,SelectionChangeListener, PropertyChangeListener,   * The {@link XMapPane} class uses a Geotools {@link GTRenderer} to paint up to
75          MapLayerListListener {   * two {@link MapContext}s: a "local" {@link MapContext} and a "background"
76      private static Logger LOGGER = Logger.getLogger( JMapPane.class.getName() );   * {@link MapContext}. The idea is, that rendering a background layer made up of
77     /**   * e.g. OSM data, may take much longer than rendering local data.<br>
78       *   * Every {@link MapContext} is rendered on a {@link Thread} of it's own.
79       */   * Starting/ cancelling these threads is done by the {@link RenderingExecutor}.<br>
80      private static final long serialVersionUID = -8647971481359690499L;   * <br>
81     * While the renderers are rending the map, a <br>
82      public static final int Reset = 0;   * The {@link XMapPane} is based on schmitzm {@link JPanel}, so
83     * {@link #print(Graphics)} will automatically set the background of components
84      public static final int ZoomIn = 1;   * to pure white.
85     *
86      public static final int ZoomOut = 2;   * The XMapPane has a {@link MouseListener} that manages zooming.<br>
87     * A logo/icon to float in the lower left corner may be set with
88      public static final int Pan = 3;   * {@link #setMapImage(BufferedImage)}<br>
89     *
90      public static final int Select = 4;   * @see SelectableXMapPane - an extension of {@link XMapPane} that supports
91     *      selecting features.
92      private static final int POLYGON = 0;   *
93     * @author stefan
94      private static final int LINE = 1;   *
95     */
96      private static final int POINT = 2;  public class XMapPane extends JPanel {
97    
98      /**          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
99       * what renders the map          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;
100       */  
101      GTRenderer renderer;          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
102    
103      private GTRenderer highlightRenderer, selectionRenderer;          private boolean acceptsRepaintCalls = true;
104    
105      /**          /**
106       * the map context to render           * Main {@link MapContext} that holds all layers that are rendered into the
107       */           * {@link #localImage} by the {@link #localRenderer}
108      MapContext context;           */
109            MapContext localContext;
110      private MapContext selectionContext;  
111            /**
112      /**           * {@link MapContext} holding the background layers. Use it for layers that
113       * the area of the map to draw           * CAN take very long for rendering, like layer from the Internet: WMS, WFS,
114       */           * OSM...<br>
115  //xulu.sc           * <code>null</code> by default.
116  //    Envelope mapArea;           *
117      protected Envelope mapArea;           * @see #setBgContext(MapContext)
118  //xulu.ec           * @see #getBgContext()
119             */
120      /**          MapContext bgContext;
121       * the size of the pane last time we drew  
122       */          /**
123  //xulu.sc           * While threads are working, calls {@link XMapPane#updateFinalImage()}
124  //    private Rectangle oldRect = null;           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
125      protected Rectangle oldRect = null;           * renderers have finished.
126  //xulu.ec           *
127             * @see INITIAL_REPAINT_DELAYAL
128      /**           * @see #REPEATING_REPAINT_DELAY
129       * the last map area drawn.           */
130       */          final private Timer repaintTimer;
131  //xulu.sc  
132  //    private Envelope oldMapArea = null;          /**
133      protected Envelope oldMapArea = null;           * The initial delay in milliseconds until the {@link #finalImage} is
134  //xulu.ec           * updated the first time.
135             */
136      /**          public static final int INITIAL_REPAINT_DELAY = 900;
137       * the base image of the map  
138       */          /**
139      protected  BufferedImage baseImage, panningImage;           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
140      // SK: private BufferedImage baseImage, panningImage;           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
141             * with previews.
142      /**           */
143       * image of selection          public static final int REPEATING_REPAINT_DELAY = 600;
144       */  
145      private BufferedImage selectImage;          /**
146             * Default delay (milliseconds) before the map will be redrawn when resizing
147      /**           * the pane. This is to avoid flickering while drag-resizing.
148       * style for selected items           *
149       */           * @see #resizeTimer
150      private Style selectionStyle;           */
151            public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
152      /**  
153       * layer that selection works on          /**
154       */           * This not-repeating {@link Timer} is re-started whenever the component is
155      private MapLayer selectionLayer;           * resized. That means => only if the component is not resizing for
156             * {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the
157      /**           * {@link XMapPane} react.
158       * layer that highlight works on           */
159       */          private final Timer resizeTimer;
160      private MapLayer highlightLayer;  
161            /**
162      /**           * Flag for no-tool.
163       * the object which manages highlighting           */
164       */          public static final int NONE = -123;
165      private HighlightManager highlightManager;  
166            /**
167      /**           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
168       * is highlighting on or off           * moeglich!
169       */           *
170      private boolean highlight = true;           * @see #setState(int)
171             */
172      /**          public static final int PAN = 1;
173       * a factory for filters  
174       */          /**
175      FilterFactory2 ff;           * Flag fuer Modus "Heran zoomen".
176             *
177      /**           * @see #setState(int)
178       * a factory for geometries           * @see #setState(int)
179       */           */
180      GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);          public static final int ZOOM_IN = 2;
181    
182      /**          /**
183       * the collections of features to be selected or highlighted           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
184       */           *
185      FeatureCollection selection;           * @see #setState(int)
186             */
187      /**          public static final int ZOOM_OUT = 3;
188       * the collections of features to be selected or highlighted  
189       */          /**
190      FeatureCollection highlightFeature;           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".
191             *
192      private int state = ZoomIn;           * @see #setState(int)
193             * @see #setState(int)
194      /**           */
195       * how far to zoom in or out          public static final int SELECT_ALL = 103;
196       */          /**
197      private double zoomFactor = 2.0;           * Flag fuer Modus
198             * "Auswahl nur eines Features, das erste sichtbare von Oben".
199      Style lineHighlightStyle;           *
200             * @see #setState(int)
201      Style pointHighlightStyle;           * @see #setState(int)
202             */
203      Style polygonHighlightStyle;          public static final int SELECT_ONE_FROM_TOP = 104;
204            /**
205      Style polygonSelectionStyle;           * Flag fuer Modus
206             * "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer".
207      Style pointSelectionStyle;           *
208             * @see #setState(int)
209      Style lineSelectionStyle;           * @see #setState(int)
210             */
211      boolean changed = true;          public static final int SELECT_TOP = 4;
212    
213      LabelCache labelCache = new LabelCacheDefault();          /**
214             * {@link Font} used to paint the wait messages into the map
215  //xulu.sc           *
216  //    private boolean reset = false;           * @see #addGadgets(Graphics2D, boolean)
217      protected boolean reset = false;           */
218  //xulu.ec          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
219    
220      int startX;          /**
221             * {@link Font} used to paint error messages into the map
222      int startY;           *
223             * @see #addGadgets(Graphics2D, boolean)
224      private boolean clickable;           */
225            final static Font errorFont = new Font("Arial", Font.BOLD, 13);
226      int lastX;  
227            /**
228      int lastY;           * The wait message painted into the map while rendering is going on on
229             * another thread.
230      private SelectionManager selectionManager;           *
231  //xulu.sn           * @see #addGadgets(Graphics2D, boolean)
232      private Double maxZoomScale = Double.MIN_VALUE;           */
233      private Double minZoomScale = Double.MAX_VALUE;          final String waitMsg = SwingUtil.R("WaitMess");
234  //xulu.en  
235            /**
236  // sk.sn               * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in
237      /**           * Karten-Koordinaten.
238       * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu setzen.           *
239       */           * @param e
240          private boolean panning_started = false;           *            Maus-Ereignis
241  // sk.en                   */
242            public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {
243      public JMapPane() {                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln
244          this(null, true, null, null);                  if (e != null && e instanceof MapMouseEvent)
245      }                          try {
246                                    return ((MapMouseEvent) e).getMapPosition().toPoint2D();
247      /**                          } catch (final Exception err) {
248       * create a basic JMapPane                                  LOGGER
249       *                                                  .error(
250       * @param render -                                                                  "return ((GeoMouseEvent) e).getMapCoordinate(null).toPoint2D();",
251       *            how to draw the map                                                                  err);
252       * @param context -                          }
253       *            the map context to display  
254       */                  // aktuelle Geo-Position ueber Transformation des JMapPane berechnen
255      public JMapPane(GTRenderer render, MapContext context) {                  if (e != null && e.getSource() instanceof XMapPane) {
256          this(null, true, render, context);  
257      }                          final XMapPane xMapPane = (XMapPane) e.getSource();
258    
259      /**                          if (!xMapPane.isWellDefined())
260       * full constructor extending JPanel                                  return null;
261       *  
262       * @param layout -                          final AffineTransform at = xMapPane.getScreenToWorld();
263       *            layout (probably shouldn't be set)                          if (at != null)
264       * @param isDoubleBuffered -                                  return at.transform(e.getPoint(), null);
265       *            a Swing thing I don't really understand                          return null;
266       * @param render -                  }
267       *            what to draw the map with                  throw new IllegalArgumentException(
268       * @param context -                                  "MouseEvent has to be of instance MapMouseEvent or come from an XMapPane");
269       *            what to draw          }
270       */  
271      public JMapPane(LayoutManager layout, boolean isDoubleBuffered,          /**
272              GTRenderer render, MapContext context) {           * Listens to changes of the "background" {@link MapContext} and triggers
273          super(layout, isDoubleBuffered);           * repaints where needed.
274             */
275          ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder          private final MapLayerListListener bgContextListener = new MapLayerListListener() {
276                  .getFilterFactory(null);  
277          setRenderer(render);                  @Override
278                    public void layerAdded(final MapLayerListEvent event) {
279          setContext(context);                          MapLayer layer = event.getLayer();
280                            layer.addMapLayerListener(bgMapLayerListener);
281          this.addMouseListener(this);                          requestStartRendering();
282          this.addMouseMotionListener(this);  
283          setHighlightManager(new HighlightManager(highlightLayer));                  }
284          setSelectionManager(new SelectionManager(selectionLayer));  
285          lineHighlightStyle = setupStyle(LINE, Color.red);                  @Override
286                    public void layerChanged(final MapLayerListEvent event) {
287          pointHighlightStyle = setupStyle(POINT, Color.red);                          requestStartRendering();
288                    }
289          polygonHighlightStyle = setupStyle(POLYGON, Color.red);  
290                    @Override
291          polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);                  public void layerMoved(final MapLayerListEvent event) {
292                            requestStartRendering();
293          pointSelectionStyle = setupStyle(POINT, Color.cyan);                  }
294    
295          lineSelectionStyle = setupStyle(LINE, Color.cyan);                  @Override
296          setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));                  public void layerRemoved(final MapLayerListEvent event) {
297      }                          if (event.getLayer() != null)
298                                    event.getLayer().removeMapLayerListener(bgMapLayerListener);
299      /**                          requestStartRendering();
300       * get the renderer                  }
301       */          };
302      public GTRenderer getRenderer() {  
303          return renderer;          /**
304      }           * This {@link RenderingExecutor} manages the creation and cancellation of
305             * up to one {@link Thread} for rendering the {@link #localContext}.
306      public void setRenderer(GTRenderer renderer) {           */
307          Map hints = new HashMap();          private final RenderingExecutor localExecuter = new RenderingExecutor(this);
308          if (renderer instanceof StreamingRenderer) {  
309              hints = renderer.getRendererHints();          /**
310              if (hints == null) {           * This {@link RenderingExecutor} manages the creation and cancellation of
311                  hints = new HashMap();           * up to one {@link Thread} for rendering the {@link #bgContext}.
312              }           */
313              if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {          protected RenderingExecutor bgExecuter;
314                  labelCache = (LabelCache) hints  
315                          .get(StreamingRenderer.LABEL_CACHE_KEY);          /**
316              } else {           * The {@link #localRenderer} for the {@link #localContext} uses this
317                  hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);           * {@link Image}.
318              }           */
319              renderer.setRendererHints(hints);          private BufferedImage localImage;
320          }  
321            /**
322          this.renderer = renderer;           * The {@link #bgRenderer} for the {@link #bgContext} uses this
323          this.highlightRenderer = new StreamingRenderer();           * {@link Image}.
324          this.selectionRenderer = new StreamingRenderer();           */
325            private BufferedImage bgImage;
326          hints.put("memoryPreloadingEnabled", Boolean.FALSE);  
327          highlightRenderer.setRendererHints(hints);          /**
328          selectionRenderer.setRendererHints(hints);           * This {@link Image} is a merge of the {@link #bgImage},
329             * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
330          if (this.context != null) {           * updated with {@link #updateFinalImage()} and used for painting in
331              this.renderer.setContext(this.context);           * {@link #paintComponent(Graphics)}
332          }           */
333      }          private BufferedImage finalImage;
334    
335      public MapContext getContext() {          /**
336          return context;           * Optionally a transparent image to paint over the map in the lower right
337      }           * corner.
338             *
339      public void setContext(MapContext context) {           * @see #addGadgets(Graphics2D)
340          if (this.context != null) {           * @see #setMapImage(BufferedImage)
341              this.context.removeMapLayerListListener(this);           **/
342          }          private BufferedImage mapImage = null;
343    
344          this.context = context;          /**
345             * Listens to each layer in the local {@link MapContext} for changes and
346          if (context != null) {           * triggers repaints.
347              this.context.addMapLayerListListener(this);           */
348          }          protected MapLayerListener bgMapLayerListener = new MapLayerAdapter() {
349    
350          if (renderer != null) {                  @Override
351              renderer.setContext(this.context);                  public void layerChanged(final MapLayerEvent event) {
352          }                          requestStartRendering();
353      }                  }
354    
355      public Envelope getMapArea() {                  @Override
356          return mapArea;                  public void layerHidden(final MapLayerEvent event) {
357      }                          requestStartRendering();
358                    }
359      public void setMapArea(Envelope mapArea) {  
360          this.mapArea = mapArea;                  @Override
361      }                  public void layerShown(final MapLayerEvent event) {
362                            requestStartRendering();
363      public int getState() {                  }
364          return state;          };
365      }  
366            /**
367      public void setState(int state) {           * A flag indicating if dispose() was already called. If true, then further
368          this.state = state;           * use of this {@link SelectableXMapPane} is undefined.
369             */
370          // System.out.println("State: " + state);          private boolean disposed = false;
371      }  
372            /**
373      public double getZoomFactor() {           * While dragging, the {@link #updateFinalImage()} method is translating the
374          return zoomFactor;           * cached images while setting it together.
375      }           **/
376            Point imageOrigin = new Point(0, 0);
377      public void setZoomFactor(double zoomFactor) {          /**
378          this.zoomFactor = zoomFactor;           * For every rendering thread started,
379      }           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new
380             * renderer. These Java2D rendering hints are passed to the
381      public MapLayer getSelectionLayer() {           * {@link GTRenderer}. The java2dHints are the same for all renderers (bg
382          return selectionLayer;           * and local).
383      }           */
384            private RenderingHints java2dHints;
385      public void setSelectionLayer(MapLayer selectionLayer) {  
386          this.selectionLayer = selectionLayer;          protected LabelCache labelCache = new LabelCacheImpl();
387          if(selectionManager!=null) {  
388              selectionManager.setSelectionLayer(selectionLayer);          /**
389          }           * Listens to changes of the "local" {@link MapContext} and triggers
390      }           * repaints where needed.
391             */
392      public boolean isHighlight() {          private final MapLayerListListener localContextListener = new MapLayerListListener() {
393          return highlight;  
394      }                  @Override
395                    public void layerAdded(final MapLayerListEvent event) {
396      public void setHighlight(boolean highlight) {                          event.getLayer().addMapLayerListener(localMapLayerListener);
397          this.highlight = highlight;  
398      }                          localRenderer.setContext(getMapContext());
399                            requestStartRendering();
400      public MapLayer getHighlightLayer() {  
401          return highlightLayer;                  }
402      }  
403                    @Override
404      public void setHighlightLayer(MapLayer highlightLayer) {                  public void layerChanged(final MapLayerListEvent event) {
405          this.highlightLayer = highlightLayer;                          localRenderer.setContext(getMapContext());
406                            requestStartRendering();
407          if (highlightManager != null) {                  }
408              highlightManager.setHighlightLayer(highlightLayer);  
409          }                  @Override
410      }                  public void layerMoved(final MapLayerListEvent event) {
411                            localRenderer.setContext(getMapContext());
412      public HighlightManager getHighlightManager() {                          requestStartRendering();
413          return highlightManager;                  }
414      }  
415                    @Override
416      public void setHighlightManager(HighlightManager highlightManager) {                  public void layerRemoved(final MapLayerListEvent event) {
417          this.highlightManager = highlightManager;                          if (event.getLayer() != null)
418          this.highlightManager.addHighlightChangeListener(this);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
419          this.addMouseMotionListener(this.highlightManager);                          localRenderer.setContext(getMapContext());
420      }                          requestStartRendering();
421                    }
422      public Style getLineHighlightStyle() {          };
423          return lineHighlightStyle;  
424      }          /**
425             * Listens to each layer in the local {@link MapContext} for changes and
426      public void setLineHighlightStyle(Style lineHighlightStyle) {           * triggers repaints.
427          this.lineHighlightStyle = lineHighlightStyle;           */
428      }          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
429    
430      public Style getLineSelectionStyle() {                  @Override
431          return lineSelectionStyle;                  public void layerChanged(final MapLayerEvent event) {
432      }                          localRenderer.setContext(getMapContext()); // betters for SLD
433                            // changes?!
434      public void setLineSelectionStyle(Style lineSelectionStyle) {                          requestStartRendering();
435          this.lineSelectionStyle = lineSelectionStyle;                  }
436      }  
437                    @Override
438      public Style getPointHighlightStyle() {                  public void layerHidden(final MapLayerEvent event) {
439          return pointHighlightStyle;                          requestStartRendering();
440      }                  }
441    
442      public void setPointHighlightStyle(Style pointHighlightStyle) {                  @Override
443          this.pointHighlightStyle = pointHighlightStyle;                  public void layerShown(final MapLayerEvent event) {
444      }                          requestStartRendering();
445                    }
446      public Style getPointSelectionStyle() {          };
447          return pointSelectionStyle;  
448      }          private final GTRenderer localRenderer = GTUtil.createGTRenderer();
449    
450      public void setPointSelectionStyle(Style pointSelectionStyle) {          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
451          this.pointSelectionStyle = pointSelectionStyle;  
452      }          /**
453             * the area of the map to draw
454      public Style getPolygonHighlightStyle() {           */
455          return polygonHighlightStyle;          protected Envelope mapArea = null;
456      }  
457            /**
458      public void setPolygonHighlightStyle(Style polygonHighlightStyle) {           * A flag set it {@link #setMapArea(Envelope)} to indicated the
459          this.polygonHighlightStyle = polygonHighlightStyle;           * {@link #paintComponent(Graphics)} method, that the image on-screen is
460      }           * associated with {@link #oldMapArea} and may hence be scaled for a quick
461             * preview.<br>
462      public Style getPolygonSelectionStyle() {           * The flag is reset
463          return polygonSelectionStyle;           **/
464      }          private boolean mapAreaChanged = false;
465    
466      public void setPolygonSelectionStyle(Style polygonSelectionStyle) {          /**
467          this.polygonSelectionStyle = polygonSelectionStyle;           * This color is used as the default background color when painting a map.
468      }           */
469            private Color mapBackgroundColor = Color.WHITE;
470      protected void paintComponent(Graphics g) {  
471          super.paintComponent(g);          /**
472             * A flag indicating that the shown image is invalid and needs to be
473          if ((renderer == null) || (mapArea == null)  ) {           * re-rendered.
474              return;           */
475          }          protected boolean mapImageInvalid = true;
476    
477          Rectangle r = getBounds();          /**
478          Rectangle dr = new Rectangle(r.width, r.height);           * Holds a flag for each layer, whether it is regarded or ignored on
479             * {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
480          if (!r.equals(oldRect) || reset) {           * actions.
481                  if(!r.equals(oldRect) && (mapArea == null)) {           */
482                          try {          final protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
483                                          mapArea=context.getLayerBounds();  
484                                  } catch (IOException e) {          /**
485                                          // TODO Auto-generated catch block           * List of listeners of this {@link XMapPane}
486                                          e.printStackTrace();           */
487                                  }          protected Vector<JMapPaneListener> mapPaneListeners = new Vector<JMapPaneListener>();
488                  }          /**
489                             * If not <code>null</code>, the {@link XMapPane} will not allow to zoom/pan
490                  if (mapArea != null){           * out of that area
491                          /* either the viewer size has changed or we've done a reset */           **/
492                          changed = true; /* note we need to redraw */          private Envelope maxExtend = null;
493                          reset = false; /* forget about the reset */          private Double maxZoomScale = Double.MIN_VALUE;
494                          oldRect = r; /* store what the current size is */  
495                                    private Double minZoomScale = Double.MAX_VALUE;
496                          mapArea = fixAspectRatio(r, mapArea);  
497                  }          /**
498          }           * We store the old mapArea for a moment to use it for the
499             * "quick scaled preview" in case of ZoomOut
500          if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */           **/
501              changed = true;          protected Envelope oldMapArea = null;
502              oldMapArea = mapArea;  
503  //          when we tell the context that the bounds have changed WMSLayers          /**
504              // can refresh them selves           * We store the old transform for a moment to use it for the
505              context.setAreaOfInterest(mapArea, context           * "quick scaled preview" in case of ZoomIn
506                      .getCoordinateReferenceSystem());           **/
507          }          protected AffineTransform oldScreenToWorld = null;
508    
509          if (changed) { /* if the map changed then redraw */          /**
510              changed = false;           * A flag indicating, that the image size has changed and the buffered
511              baseImage = new BufferedImage(dr.width, dr.height,           * images are not big enough any more
512                      BufferedImage.TYPE_INT_ARGB);           **/
513            protected boolean paneResized = true;
514              Graphics2D ig = baseImage.createGraphics();  
515              /* System.out.println("rendering"); */          private BufferedImage preFinalImage;
516              renderer.setContext(context);  
517              labelCache.clear(); // work around anoying labelcache bug          // ** if 0, no quick preview will be shown **/
518            private int quickPreviewHint = 0;
519    
520              // draw the map          private Map<Object, Object> rendererHints = GTUtil
521              renderer.paint((Graphics2D) ig, dr, mapArea);                          .getDefaultGTRendererHints(localRenderer);
522    
523              // TODO , nur machen, wenn panning beginnt          /**
524              panningImage = new BufferedImage(dr.width, dr.height,           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
525                          BufferedImage.TYPE_INT_RGB);           * start rendering {@link Thread}s
526                         **/
527          }          private volatile Boolean requestStartRendering = false;
528    
529          ((Graphics2D) g).drawImage(baseImage, 0, 0, this);          /**
530             * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
531          if ((selection != null) && (selection.size() > 0)) {           * (lat/lon)
532              // paint selection           */
533            protected AffineTransform screenToWorld = null;
534              String type = selectionLayer.getFeatureSource().getSchema()  
535              .getDefaultGeometry().getType().getName();          /**
536              /*String type = selection.getDefaultGeometry().getGeometryType();*/           * The flag {@link #requestStartRendering} can be set to true by events.
537              /*System.out.println(type);*/           * This {@link Timer} checks the flag regularly and starts one renderer
538              if (type == null)           * thread.
539                  type = "polygon";           */
540            final private Timer startRenderThreadsTimer;
541              /* String type = "point"; */  
542            /**
543              if (type.toLowerCase().endsWith("polygon")) {           * The default state is ZOOM_IN, hence by default the
544                  selectionStyle = polygonSelectionStyle;           * {@link #zoomMapPaneMouseListener} is also enabled.
545              } else if (type.toLowerCase().endsWith("point")) {           **/
546                  selectionStyle = pointSelectionStyle;          private int state = ZOOM_IN;
547              } else if (type.toLowerCase().endsWith("line")) {  
548                  selectionStyle = lineSelectionStyle;          /**
549              }           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
550             * MapPane-Funktion
551              selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);           */
552            protected Cursor staticCursor = null;
553              selectionContext.addLayer(selection, selectionStyle);  
554              selectionRenderer.setContext(selectionContext);          private AffineTransform worldToScreen;
555    
556              selectImage = new BufferedImage(dr.width, dr.height,          /**
557                      BufferedImage.TYPE_INT_ARGB);           * This {@link MouseListener} is managing all zoom related tasks
558             */
559              Graphics2D ig = selectImage.createGraphics();          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(
560              /* System.out.println("rendering selection"); */                          this);
561              selectionRenderer.paint((Graphics2D) ig, dr, mapArea);  
562            /** Is set if a renderer has an error **/
563              ((Graphics2D) g).drawImage(selectImage, 0, 0, this);          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
564          }  
565            /**
566          if (highlight && (highlightFeature != null)           * If <code>true</code>, then rendering exceptions are rendererd into the
567                  && (highlightFeature.size() > 0)) {           * map pane
568              /*           **/
569               * String type = selection.getDefaultGeometry().getGeometryType();          private boolean showExceptions = false;
570               * System.out.println(type); if(type==null) type="polygon";  
571               */          public XMapPane() {
572              String type = highlightLayer.getFeatureSource().getSchema()                  this(null, null);
573              .getDefaultGeometry().getType().getName();          }
574              /*String type = selection.getDefaultGeometry().getGeometryType();*/  
575              //System.out.println(type);          /**
576              if (type == null)           * full constructor extending JPanel
577                  type = "polygon";           *
578             * @param rendererHints
579              /* String type = "point"; */           *            may be <code>null</code>. Otherwise a {@link Map<Object,
580              Style highlightStyle = null;           *            Object>} of {@link RenderingHints} to override the default
581              if (type.toLowerCase().endsWith("polygon")) {           *            from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)}
582                  highlightStyle = polygonHighlightStyle;           *
583              } else if (type.toLowerCase().endsWith("point")) {           * @param localContext
584                  highlightStyle = pointHighlightStyle;           *            The main {@link MapContext} to use. If <code>null</code>, an
585              } else if (type.toLowerCase().endsWith("line")) {           *            empty {@link DefaultMapContext} will be created.
586                  highlightStyle = lineHighlightStyle;           */
587              }          public XMapPane(final MapContext localContext_,
588                            final Map<Object, Object> rendererHints) {
589                    super(true);
590    
591                    setRendererHints(rendererHints);
592              MapContext highlightContext = new DefaultMapContext(  
593                      DefaultGeographicCRS.WGS84);                  setOpaque(true);
594    
595              highlightContext.addLayer(highlightFeature, highlightStyle);                  if (localContext_ != null)
596              highlightRenderer.setContext(highlightContext);                          setLocalContext(localContext_);
597    
598              /* System.out.println("rendering highlight"); */                  /**
599              highlightRenderer.paint((Graphics2D) g, dr, mapArea);                   * Adding the #zoomMapPaneMouseListener
600          }                   */
601      }                  this.addMouseListener(zoomMapPaneMouseListener);
602                    this.addMouseMotionListener(zoomMapPaneMouseListener);
603      private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {                  this.addMouseWheelListener(zoomMapPaneMouseListener);
604            
605          double mapWidth = mapArea.getWidth(); /* get the extent of the map */                  /*
606          double mapHeight = mapArea.getHeight();                   * We use a Timer object to avoid rendering delays and flickering when
607          double scaleX = r.getWidth() / mapArea.getWidth(); /*                   * the user is drag-resizing the parent container of this map pane.
608                                                               * calculate the new                   *
609                                                               * scale                   * Using a ComponentListener doesn't work because, unlike a JFrame, the
610                                                               */                   * pane receives a stream of events during drag-resizing.
611                     */
612          double scaleY = r.getHeight() / mapArea.getHeight();                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
613          double scale = 1.0; // stupid compiler!                                  new ActionListener() {
614    
615          if (scaleX < scaleY) { /* pick the smaller scale */                                          public void actionPerformed(final ActionEvent e) {
616              scale = scaleX;                                                  if (!isWellDefined())
617          } else {                                                          return;
618              scale = scaleY;  
619          }                                                  LOGGER.info("resizeTimer performed");
620    
621          /* calculate the difference in width and height of the new extent */                                                  final Rectangle bounds = getVisibleRect();
622          double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);                                                  //
623          double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);                                                  // System.out.println("\n\ntimer performs with bounds = "
624                                                    // + bounds);
625          /*  
626           * System.out.println("delta x " + deltaX); System.out.println("delta y " +                                                  final Envelope geoMapArea = tranformWindowToGeo(
627           * deltaY);                                                                  bounds.x, bounds.y, bounds.x + bounds.width,
628           */                                                                  bounds.y + bounds.height);
629    
630          /* create the new extent */                                                  if (setMapArea(geoMapArea)) {
631          Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),                                                          LOGGER.info("  maparea changed");
632                  mapArea.getMinY() - (deltaY / 2.0));                                                          paneResized = true;
633          Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),                                                  } else
634                  mapArea.getMaxY() + (deltaY / 2.0));                                                          LOGGER.info("  maparea NOT changed");
635                                            }
636          return new Envelope(ll, ur);                                  });
637      }                  resizeTimer.setRepeats(false);
638    
639      public void doSelection(double x, double y, MapLayer layer) {                  this.addComponentListener(new ComponentAdapter() {
640    
641          Geometry geometry = gf.createPoint(new Coordinate(x, y));                          private Rectangle oldVisibleRect;
642    
643          // org.opengis.geometry.Geometry geometry = new Point();                          @Override
644                            public void componentResized(final ComponentEvent e) {
645              findFeature(geometry, layer);  
646                                    // Seems to be called twice with the same size..
647      }                                  if (oldVisibleRect != null
648                                                    && oldVisibleRect.equals(getVisibleRect())){
649      /**                                          LOGGER.info("skipping resize.");
650       * @param geometry -                                          return;
651       *            a geometry to construct the filter with                                  }
652       * @param i -  
653       *            the index of the layer to search                                  LOGGER.info("resized: " + getVisibleRect());
654       * @throws IndexOutOfBoundsException                                  resizeTimer.restart();
655       */                                  oldVisibleRect = getVisibleRect();
656      private void findFeature(Geometry geometry, MapLayer layer)                          }
657              throws IndexOutOfBoundsException {  
658          org.opengis.filter.spatial.BinarySpatialOperator f = null;                  });
659    
660                    /*
661          if ((context == null) || (layer==null)) {                   * Setting up the repaintTimer. Not started automatically.
662              return ;                   */
663          }                  repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
664    
665                            @Override
666                            public void actionPerformed(final ActionEvent e) {
667          try {                                  if ((!localExecuter.isRunning())
668              String name = layer.getFeatureSource().getSchema()                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {
669                      .getDefaultGeometry().getName();                                          repaintTimer.stop();
670                                    } else {
671              if (name == "") {                                          updateFinalImage();
672                  name = "the_geom";                                          XMapPane.this.repaint(100);
673              }  
674                                    }
675              try {                          }
676                  f = ff.contains(ff.property(name), ff.literal(geometry));                  });
677                  if(selectionManager!=null) {  
678                      System.out.println("selection changed");                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
679                      selectionManager.selectionChanged(this, f);                  repaintTimer.setRepeats(true);
680    
681                  }                  /*
682              } catch (IllegalFilterException e) {                   * Setting up the startRenderThreadsTimer. This Timer starts
683                  // TODO Auto-generated catch block                   * automatically.
684                  e.printStackTrace();                   */
685              }                  startRenderThreadsTimer = new Timer(100, new ActionListener() {
686    
687              /*// f.addLeftGeometry(ff.property(name));                          @Override
688              // System.out.println("looking with " + f);                          public void actionPerformed(final ActionEvent e) {
689              FeatureCollection fc = layer.getFeatureSource().getFeatures(f);                                  synchronized (requestStartRendering) {
690                                            if (requestStartRendering && isWellDefined()) {
691    
692                                                    if (localExecuter.isRunning()) {
693              if (fcol == null) {                                                          localExecuter.cancelTask();
694                  fcol = fc;                                                  } else {
695                                                            // Stupidly, but we have to recheck the
696                  // here we should set the defaultgeom type                                                          setMapArea(getMapArea());
697              } else {                                                          requestStartRendering = false;
698                  fcol.addAll(fc);                                                          startRendering();
699              }*/                                                  }
700                                            }
701              /*                                  }
702               * GeometryAttributeType gat =                          }
703               * layer.getFeatureSource().getSchema().getDefaultGeometry();                  });
704               * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());                  startRenderThreadsTimer.start();
705               */  
706            }
707              /*  
708               * Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat =          /**
709               * (Feature) fi.next(); System.out.println("selected " +           * Fuegt der Map einen Listener hinzu.
710               * feat.getAttribute("STATE_NAME")); }           *
711               */           * @param l
712          } catch (IllegalFilterException e) {           *            neuer Listener
713              // TODO Auto-generated catch block           */
714              e.printStackTrace();          public void addMapPaneListener(final JMapPaneListener l) {
715          }                  mapPaneListeners.add(l);
716          return ;          }
717      }  
718            /**
719      public void mouseClicked(MouseEvent e) {           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
720          // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
721          // h:"+mapArea.getHeight());           * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br>
722          Rectangle bounds = this.getBounds();           * Since 21. April 09: Before thecalculation starts, the aspect ratio is
723          double x = (double) (e.getX());           * corrected. This change implies, that setMapArea() will most of the time
724          double y = (double) (e.getY());           * not allow setting to a wrong aspectRatio.
725          double width = mapArea.getWidth();           *
726          double height = mapArea.getHeight();           * @author <a href="mailto:[email protected]">Stefan Alfons
727  //xulu.sc           *         Kr&uuml;ger</a>
728  //        double width2 = mapArea.getWidth() / 2.0;           */
729  //        double height2 = mapArea.getHeight() / 2.0;          public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
730          double width2 = width / 2.0;  
731          double height2 = height / 2.0;                  if (getWidth() == 0)
732  //xulu.ec                          return env;
733          double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();  
734          double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)                  if (env == null)
735                  + mapArea.getMinY();                          return null;
736    
737          /*                  Envelope newArea = null;
738           * System.out.println(""+x+"->"+mapX);  
739           * System.out.println(""+y+"->"+mapY);                  /**
740           */                   * Correct the aspect Ratio before we check the rest. Otherwise we might
741                     * easily fail. We allow to grow here, because we don't check against
742          /*                   * the maxExtend
743           * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());                   */
744           * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());                  final Rectangle curPaintArea = getVisibleRect();
745           */  
746          double zlevel = 1.0;                  env = JTSUtil.fixAspectRatio(curPaintArea, env, true);
747    
748          switch (state) {                  final double scale = env.getWidth() / getWidth();
749          case Pan:                  final double centerX = env.getMinX() + env.getWidth() / 2.;
750              zlevel = 1.0;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
751  //xulu.sc SK: return here.. a mouselistener is maanaging the PANNING                  double newWidth2 = 0;
752  //            break;                  double newHeight2 = 0;
753              return;                  if (scale < getMaxZoomScale()) {
754  //xulu.ec                          // ****************************************************************************
755          case ZoomIn:                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
756              zlevel = zoomFactor;                          // ****************************************************************************
757                            newWidth2 = getMaxZoomScale() * getWidth() / 2.;
758              break;                          newHeight2 = getMaxZoomScale() * getHeight() / 2.;
759                    } else if (scale > getMinZoomScale()) {
760          case ZoomOut:                          // ****************************************************************************
761              zlevel = 1.0 / zoomFactor;                          // Wir zoomen weiter raus als erlaubt => Anpassen des envelope
762                            // ****************************************************************************
763              break;                          newWidth2 = getMinZoomScale() * getWidth() / 2.;
764                            newHeight2 = getMinZoomScale() * getHeight() / 2.;
765          case Select:                  } else {
766              doSelection(mapX, mapY, selectionLayer);                          // ****************************************************************************
767                            // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
768                            // ****************************************************************************
769              return;                          newArea = env;
770                    }
771          default:  
772              return;                  if (newArea == null) {
773          }  
774                            final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
775          Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY                                          - newHeight2);
776                  - (height2 / zlevel));                          final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
777          Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY                                          + newHeight2);
778                  + (height2 / zlevel));  
779  //xulu.sc SK: Check for min/max scale                          newArea = new Envelope(ll, ur);
780  //        mapArea = new Envelope(ll, ur);                  }
781          final Envelope newMapArea = new Envelope(ll, ur);  
782          setMapArea( bestAllowedMapArea( newMapArea ) );                  final Envelope maxAllowedExtend = getMaxExtend();
783  //xulu.ec  
784                    while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
785          // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"                                  && newArea != null && !newArea.isNull()
786          // h:"+mapArea.getHeight());                                  && !Double.isNaN(newArea.getMinX())
787          repaint();                                  && !Double.isNaN(newArea.getMaxX())
788      }                                  && !Double.isNaN(newArea.getMinY())
789                                    && !Double.isNaN(newArea.getMaxY())) {
790      public void mouseEntered(MouseEvent e) {                          /*
791      }                           * If a maxExtend is set, we have to honour that...
792                             */
793      public void mouseExited(MouseEvent e) {  
794      }                          // Exceeds top? Move down and maybe cut
795                            if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
796      public void mousePressed(MouseEvent e) {                                  final double divY = newArea.getMaxY()
797          startX = e.getX();                                                  - maxAllowedExtend.getMaxY();
798          startY = e.getY();                                  // LOGGER.debug("Moving area down by " + divY);
799          lastX = 0;  
800          lastY = 0;                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
801      }                                                  newArea.getMinY() - divY), new Coordinate(newArea
802                                                        .getMaxX(), newArea.getMaxY() - divY));
803      public void mouseReleased(MouseEvent e) {  
804          int endX = e.getX();                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
805          int endY = e.getY();                                          // LOGGER.debug("Now it exeeds the bottom border.. cut!");
806                                                    // And cut the bottom if it moved out of the area
807          processDrag(startX, startY, endX, endY, e);                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
808          lastX = 0;                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea
809          lastY = 0;                                                          .getMaxX(), newArea.getMaxY()));
810            
811          /**                                          // LOGGER.debug("and fix aspect ratio");
812           * Es wird nicht (mehr) gepannt!  
813           */                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
814          panning_started = false;                                                          new ReferencedEnvelope(newArea, env
815      }                                                                          .getCoordinateReferenceSystem()), false);
816                                    }
817      public void mouseDragged(MouseEvent e) {                          }
818          Graphics graphics = this.getGraphics();  
819          int x = e.getX();                          // Exceeds bottom? Move up and maybe cut
820          int y = e.getY();                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
821                                            final double divY = newArea.getMinY()
822                                                    - maxAllowedExtend.getMinY();
823          if ( (state == JMapPane.Pan) || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0))  {                                  // LOGGER.debug("Moving area up by " + divY);
824              /**  
825               * SK:                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
826               * Der Cursor wird auf PANNING gesetzt.                                                  newArea.getMinY() - divY), new Coordinate(newArea
827               */                                                  .getMaxX(), newArea.getMaxY() - divY));
828                  if (panning_started == false){  
829                          panning_started = true;                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
830                          setCursor( SwingUtil.PANNING_CURSOR );                                          // LOGGER.debug("Now it exeeds the top border.. cut!");
831                  }                                          // And cut the bottom if it moved out of the area
832                                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
833                                                                            newArea.getMinY()), new Coordinate(newArea
834              // move the image with the mouse                                                          .getMaxX(), maxAllowedExtend.getMaxY()));
835              if ((lastX > 0) && (lastY > 0)) {  
836                  int dx = lastX - startX;                                          // LOGGER.debug("and fix aspect ratio");
837                  int dy = lastY - startY;  
838                  // System.out.println("translate "+dx+","+dy);                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
839                  final Graphics2D g2 = panningImage.createGraphics();                                                          new ReferencedEnvelope(newArea, env
840                  g2.setBackground( new Color(240,240,240) ); //TODO richtige farbe? am besten vom L&F die hintergrundfarbe auslesen...                                                                          .getCoordinateReferenceSystem()), false);
841                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  }
842                                  g2.drawImage(baseImage, dx, dy, this);                          }
843                  graphics.drawImage(panningImage, 0, 0, this);  
844              }                          // Exceeds to the right? move and maybe cut
845                            if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
846              lastX = x;  
847              lastY = y;                                  // Move left..
848          } else                                  final double divX = newArea.getMaxX()
849                                                                    - maxAllowedExtend.getMaxX();
850          if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {                                  // LOGGER.debug("Moving area left by " + divX);
851            
852                                            newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
853              graphics.setXORMode(Color.WHITE);                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
854                                                    - divX, newArea.getMaxY()));
855              if ((lastX > 0) && (lastY > 0)) {  
856                  drawRectangle(graphics);                                  if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
857              }                                          // LOGGER.debug("Now it exeeds the left border.. cut!");
858                                            // And cut the left if it moved out of the area
859              // draw new box                                          newArea = new Envelope(new Coordinate(maxAllowedExtend
860              lastX = x;                                                          .getMinX(), newArea.getMinY()), new Coordinate(
861              lastY = y;                                                          newArea.getMaxX(), newArea.getMaxY()));
862              drawRectangle(graphics);  
863          } else if (state == JMapPane.Select && selectionLayer != null) {                                          // LOGGER.debug("and fix aspect ratio");
864    
865              // construct a new bbox filter                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
866              Rectangle bounds = this.getBounds();                                                          new ReferencedEnvelope(newArea, env
867                                                                            .getCoordinateReferenceSystem()), false);
868              double mapWidth = mapArea.getWidth();                                  }
869              double mapHeight = mapArea.getHeight();                          }
870    
871              double x1 = ((this.startX * mapWidth) / (double) bounds.width)                          // Exceeds to the left? move and maybe cut
872                      + mapArea.getMinX();                          if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
873              double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)  
874                      + mapArea.getMinY();                                  // Move right..
875              double x2 = ((x * mapWidth) / (double) bounds.width)                                  final double divX = newArea.getMinX()
876                      + mapArea.getMinX();                                                  - maxAllowedExtend.getMinX();
877              double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)                                  // LOGGER.debug("Moving area right by " + divX);
878                      + mapArea.getMinY();  
879              double left = Math.min(x1, x2);                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
880              double right = Math.max(x1, x2);                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
881              double bottom = Math.min(y1, y2);                                                  - divX, newArea.getMaxY()));
882              double top = Math.max(y1, y2);  
883                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
884                                            // LOGGER.debug("Now it exeeds the right border.. cut!");
885              String name = selectionLayer.getFeatureSource().getSchema()                                          // And cut the left if it moved out of the area
886                      .getDefaultGeometry().getName();                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
887                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
888              if (name == "") {                                                          .getMaxX(), newArea.getMaxY()));
889                  name = "the_geom";  
890              }                                          // LOGGER.debug("and fix aspect ratio");
891              Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,  
892                      getContext().getCoordinateReferenceSystem().toString());                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
893              if(selectionManager!=null) {                                                          new ReferencedEnvelope(newArea, env
894                  selectionManager.selectionChanged(this, bb);                                                                          .getCoordinateReferenceSystem()), false);
895              }                                  }
896                            }
897              graphics.setXORMode(Color.green);                  }
898    
899              /*                  return new ReferencedEnvelope(newArea, env
900               * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }                                  .getCoordinateReferenceSystem());
901               */          }
902    
903              // draw new box          /**
904              lastX = x;           * Should be called when the {@link JMapPane} is not needed no more to help
905              lastY = y;           * the GarbageCollector
906              drawRectangle(graphics);           *
907         }           * Removes all {@link JMapPaneListener}s that are registered
908                 *
909      }           * @author <a href="mailto:[email protected]">Stefan Alfons
910             *         Kr&uuml;ger</a>
911      // sk.cs           */
912  //    private void processDrag(int x1, int y1, int x2, int y2) {          public void dispose() {
913      // sk.ce                  if (isDisposed())
914      protected void processDrag(int x1, int y1, int x2, int y2, MouseEvent e) {                          return;
915            
916          /****                  setPainting(false);
917           * If no layer is availabe we dont want a NullPointerException  
918           */                  resizeTimer.stop();
919          if (mapArea == null) return;                  startRenderThreadsTimer.stop();
920            
921          // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                  disposed = true;
922          // + x2 + "," + y2);  
923          if ((x1 == x2) && (y1 == y2)) {                  if (bgExecuter != null) {
924              if (isClickable()) {                          bgExecuter.cancelTask();
925                  mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,                          bgExecuter.dispose();
926                          x1, y1, y2, false));                  }
927              }  
928                    if (localExecuter.isRunning()) {
929              return;                          int i = 0;
930          }                          localExecuter.cancelTask();
931                                    while (i++ < 10 && localExecuter.isRunning()) {
932          Rectangle bounds = this.getBounds();                                  try {
933                                            Thread.sleep(200);
934          double mapWidth = mapArea.getWidth();                                  } catch (final InterruptedException e) {
935          double mapHeight = mapArea.getHeight();                                          LOGGER
936                                                            .warn(
937          double startX = ((x1 * mapWidth) / (double) bounds.width)                                                                          "while XMapPane we are waiting for the localExcutor to stop",
938                  + mapArea.getMinX();                                                                          e);
939          double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)                                  }
940                  + mapArea.getMinY();                          }
941          double endX = ((x2 * mapWidth) / (double) bounds.width)                          if (localExecuter.isRunning()) {
942                  + mapArea.getMinX();                                  LOGGER
943          double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)                                                  .warn("localExecutor Thread still running after 2s! Continuing anyways...");
944                  + mapArea.getMinY();                          }
945                            localExecuter.dispose();
946          if (  (state == JMapPane.Pan) || (e.getButton()== MouseEvent.BUTTON3)) {                  }
947              // move the image with the mouse  
948              // calculate X offsets from start point to the end Point                  disposeImages();
949              double deltaX1 = endX - startX;  
950                    // Remove all mapPaneListeners that have registered with us
951              // System.out.println("deltaX " + deltaX1);                  mapPaneListeners.clear();
952              // new edges  
953              double left = mapArea.getMinX() - deltaX1;                  removeMouseMotionListener(zoomMapPaneMouseListener);
954              double right = mapArea.getMaxX() - deltaX1;                  removeMouseListener(zoomMapPaneMouseListener);
955    
956              // now for Y                  if (localContext != null)
957              double deltaY1 = endY - startY;                          getMapContext().clearLayerList();
958                    if (bgContext != null)
959              // System.out.println("deltaY " + deltaY1);                          getBgContext().clearLayerList();
960              double bottom = mapArea.getMinY() - deltaY1;  
961              double top = mapArea.getMaxY() - deltaY1;                  removeAll();
962              Coordinate ll = new Coordinate(left, bottom);          }
963              Coordinate ur = new Coordinate(right, top);  
964  //xulu.sc          /**
965  //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));           * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
966              setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );           * given point. All in screen coordinates.
967  //xulu.ec           */
968          } else if (state == JMapPane.ZoomIn) {          protected void drawRectangle(final Graphics graphics, final Point startPos,
969                                            final Point e) {
970    
971                  // Zu kleine Flächen sollen nicht gezoomt werden.                  if (!isWellDefined())
972                  //sk.bc                          return;
973                  if ( (Math.abs(x1-x2) * Math.abs(y2-y1) )<100 ) return;  
974                  // sk.ec                  // undraw last box/draw new box
975                                    final int left = Math.min(startPos.x, e.x);
976                  drawRectangle(this.getGraphics());                  final int right = Math.max(startPos.x, e.x);
977              // make the dragged rectangle (in map coords) the new BBOX                  final int top = Math.max(startPos.y, e.y);
978              double left = Math.min(startX, endX);                  final int bottom = Math.min(startPos.y, e.y);
979              double right = Math.max(startX, endX);                  final int width = right - left;
980              double bottom = Math.min(startY, endY);                  final int height = top - bottom;
981              double top = Math.max(startY, endY);  
982              Coordinate ll = new Coordinate(left, bottom);                  if (width == 0 && height == 0)
983              Coordinate ur = new Coordinate(right, top);                          return;
984  //xulu.sc  
985  //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                  graphics.setXORMode(Color.WHITE);
986              setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );                  graphics.drawRect(left, bottom, width, height);
987  //xulu.ec          }
988          } else if (state == JMapPane.ZoomOut) {  
989                  drawRectangle(this.getGraphics());          /**
990                             * Diretly paints scaled preview into the {@link SelectableXMapPane}. Used
991                  // make the dragged rectangle in screen coords the new map size?           * to give the user something to look at while we are rendering. Method
992              double left = Math.min(startX, endX);           * should be called after {@link #setMapArea(Envelope)} has been set to the
993              double right = Math.max(startX, endX);           * new mapArea and transform has been reset.<br>
994              double bottom = Math.min(startY, endY);           *
995              double top = Math.max(startY, endY);           * @param g
996              double nWidth = (mapWidth * mapWidth) / (right - left);           *            Graphics2D to paint the preview into
997              double nHeight = (mapHeight * mapHeight) / (top - bottom);           *
998              double deltaX1 = left - mapArea.getMinX();           * @param state
999              double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;           *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}
1000              double deltaY1 = bottom - mapArea.getMinY();           */
1001              double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
1002              Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,  
1003                      mapArea.getMinY() - nDeltaY1);                  // if (1 == 1)return false;
1004              double deltaX2 = mapArea.getMaxX() - right;  
1005              double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;                  if (quickPreviewHint == 0)
1006              double deltaY2 = mapArea.getMaxY() - top;                          return false;
1007              double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;  
1008              Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,                  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1009                      mapArea.getMaxY() + nDeltaY2);                                  RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1010  //xulu.sc                              graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1011  //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                                  RenderingHints.VALUE_ANTIALIAS_OFF);
1012              setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );                  graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1013  //xulu.ec                                  RenderingHints.VALUE_RENDER_SPEED);
1014          } else if (state == JMapPane.Select && selectionLayer !=null) {  
1015              double left = Math.min(startX, endX);                  if (oldMapArea == null)
1016              double right = Math.max(startX, endX);                          return false;
1017              double bottom = Math.min(startY, endY);  
1018              double top = Math.max(startY, endY);                  final Rectangle visibleArea = getVisibleRect();
1019    
1020                    // Calculate the oldMapArea in the current WindowCoordinates:
1021              String name = selectionLayer.getFeatureSource().getSchema()                  final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),
1022                      .getDefaultGeometry().getLocalName();                                  oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea
1023                                                    .getMaxY());
1024              if (name == "") {  
1025                  name = "the_geom";                  final int xx1 = (int) Math.round(oldMapWindow.getMinX());
1026              }                  final int yy1 = (int) Math.round(oldMapWindow.getMinY());
1027              Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1028                      getContext().getCoordinateReferenceSystem().toString());                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1029              //System.out.println(bb.toString());  
1030              if(selectionManager!=null) {                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1031                  selectionManager.selectionChanged(this, bb);                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1032              }                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
1033              /*FeatureCollection fc;                                  getMapBackgroundColor(), null);
1034              selection = null;  
1035              try {                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1036                  fc = selectionLayer.getFeatureSource().getFeatures(bb);                                  - yy1);
1037                  selection = fc;  
1038              } catch (IOException e) {                  SwingUtil.clearAround(graphics, painedArea, visibleArea);
1039                  e.printStackTrace();  
1040              }                  addGadgets(graphics, true);
1041  */  
1042          }                  quickPreviewHint = 0;
1043    
1044  //xulu.so                  repaintTimer.restart();
1045  //        setMapArea(mapArea);  
1046  //xulu.eo                  graphics.dispose();
1047          repaint();  
1048      }                  // Something has been drawn
1049                    return true;
1050      private boolean isClickable() {          }
1051          return clickable;  
1052      }          public MapContext getBgContext() {
1053                    return bgContext;
1054      private org.geotools.styling.Style setupStyle(int type, Color color) {          }
1055          StyleFactory sf = org.geotools.factory.CommonFactoryFinder  
1056                  .getStyleFactory(null);          /**
1057          StyleBuilder sb = new StyleBuilder();           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1058             */
1059          org.geotools.styling.Style s = sf.createStyle();          private Image getBgImage() {
1060          s.setTitle("selection");                  //
1061                    // if (bgImage == null) {
1062          // TODO parameterise the color                  // bgImage = createImage(getBounds().width, getBounds().height);
1063          PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);                  // }
1064          ps.setStroke(sb.createStroke(color));  
1065                    return bgImage;
1066          LineSymbolizer ls = sb.createLineSymbolizer(color);          }
1067          Graphic h = sb.createGraphic();  
1068          h.setMarks(new Mark[] { sb.createMark("square", color) });          public MapContext getMapContext() {
1069                    if (localContext == null) {
1070          PointSymbolizer pts = sb.createPointSymbolizer(h);                          setLocalContext(new DefaultMapContext());
1071                    }
1072          // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});                  return localContext;
1073          switch (type) {          }
1074          case POLYGON:  
1075              s = sb.createStyle(ps);          private BufferedImage getFinalImage() {
1076                    //
1077              break;                  if (finalImage == null) {
1078                            // Rectangle curPaintArea = getVisibleRect();
1079          case POINT:                          finalImage = new BufferedImage(getVisibleRect().width,
1080              s = sb.createStyle(pts);                                          getVisibleRect().height, IMAGETYPE);
1081    
1082              break;                          requestStartRendering();
1083                    }
1084          case LINE:                  return finalImage;
1085              s = sb.createStyle(ls);          }
1086          }  
1087            public RenderingHints getJava2dHints() {
1088          return s;                  return java2dHints;
1089      }          }
1090    
1091      public void highlightChanged(HighlightChangedEvent e) {          /**
1092          org.opengis.filter.Filter f = e.getFilter();           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1093             */
1094          try {          private BufferedImage getLocalImage() {
1095              highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);  
1096          } catch (IOException e1) {                  if (localImage == null) {
1097              // TODO Auto-generated catch block                          localImage = new BufferedImage(getVisibleRect().width,
1098              e1.printStackTrace();                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1099          }                  }
1100    
1101          repaint();                  return localImage;
1102      }          }
1103    
1104      public void propertyChange(PropertyChangeEvent evt) {          /**
1105          String prop = evt.getPropertyName();           * Returns a copy of the mapArea
1106             *
1107          if (prop.equalsIgnoreCase("crs")) {           * @return
1108              context.setAreaOfInterest(context.getAreaOfInterest(),           */
1109                      (CoordinateReferenceSystem) evt.getNewValue());          public ReferencedEnvelope getMapArea() {
1110          }                  if (mapArea == null) {
1111      }                          ReferencedEnvelope mapArea_ = null;
1112                            try {
1113      public boolean isReset() {                                  mapArea_ = localContext.getLayerBounds();
1114          return reset;                          } catch (final IOException e) {
1115      }                                  LOGGER.warn("localContext.getLayerBounds()", e);
1116                            }
1117      public void setReset(boolean reset) {  
1118          this.reset = reset;                          if (mapArea_ == null && bgContext != null) {
1119      }                                  try {
1120                                            mapArea_ = bgContext.getLayerBounds();
1121      public void layerAdded(MapLayerListEvent event) {                                  } catch (final IOException e) {
1122          changed = true;                                          LOGGER.warn("bgContext.getLayerBounds()", e);
1123                                    }
1124          if (context.getLayers().length == 1) { // the first one                          }
1125    
1126              try {                          if (mapArea_ != null) {
1127  //xulu.sc                                      mapArea = bestAllowedMapArea(mapArea_);
1128  //            mapArea = context.getLayerBounds();                                  requestStartRendering();
1129                mapArea = context.getAreaOfInterest();                          }
1130                if ( mapArea == null )                  }
1131                  mapArea = context.getLayerBounds();  
1132  //xulu.ec                  if (mapArea == null)
1133              } catch (IOException e) {                          return null;
1134                  // TODO Auto-generated catch block  
1135                  e.printStackTrace();                  // TODO is needed at all, this should go to setMapArea maybe
1136              }                  if (localContext.getCoordinateReferenceSystem() == null)
1137                            try {
1138              reset = true;                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1139          }                                                  .getDefaultCRS());
1140                            } catch (Exception e) {
1141          repaint();                                  throw new RuntimeException("setting context CRS:", e);
1142      }                          }
1143    
1144      public void layerRemoved(MapLayerListEvent event) {                  return new ReferencedEnvelope(mapArea, localContext
1145          changed = true;                                  .getCoordinateReferenceSystem());
1146          repaint();          }
1147      }  
1148            /**
1149      public void layerChanged(MapLayerListEvent event) {           * Returns the background {@link Color} of the map pane. Default is white.
1150          changed = true;           **/
1151          // System.out.println("layer changed - repaint");          public Color getMapBackgroundColor() {
1152          repaint();                  return mapBackgroundColor;
1153      }          }
1154    
1155      public void layerMoved(MapLayerListEvent event) {          /**
1156          changed = true;           * Get the BufferedImage to use as a flaoting icon in the lower right
1157          repaint();           * corner.
1158      }           *
1159             * @return <code>null</code> if the feature is deactivated.
1160      protected void drawRectangle(Graphics graphics) {           */
1161          // undraw last box/draw new box          public BufferedImage getMapImage() {
1162          int left = Math.min(startX, lastX);                  return mapImage;
1163          int right = Math.max(startX, lastX);          }
1164          int top = Math.max(startY, lastY);  
1165          int bottom = Math.min(startY, lastY);          /**
1166          int width = right - left;           * Returns the evelope of the viewable area. The JMapPane will never show
1167          int height = top - bottom;           * anything outside of this extend. If this has been set to
1168          // System.out.println("drawing rect("+left+","+bottom+","+ width+","+           * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1169          // height+")");           * quickly the context's bounds. It it takes to long to determine the
1170          graphics.drawRect(left, bottom, width, height);           * context bounds, <code>null</code> is returned.
1171      }           *
1172             * @param maxExtend
1173      /**           *            <code>null</code> to not have this restriction.
1174       * if clickable is set to true then a single click on the map pane will zoom           */
1175       * or pan the map.  
1176       *          public Envelope getMaxExtend() {
1177       * @param clickable                  if (maxExtend == null) {
1178       */                          // Commented-out because it takes soo much time!
1179      public void setClickable(boolean clickable) {                          //
1180          this.clickable = clickable;                          // long start = System.currentTimeMillis();
1181      }                          // final ReferencedEnvelope layerBounds = GTUtil
1182                            // .getVisibleLayoutBounds(localContext);
1183      public void mouseMoved(MouseEvent e) {                          //                      
1184      }                          // LOGGER.info(
1185                            // (System.currentTimeMillis()-start)+"m to get maxExtend");
1186      public FeatureCollection getSelection() {                          //                      
1187          return selection;                          // if (layerBounds == null) {
1188      }                          // // TODO Last fallback could be the CRS valid area
1189                            // return null;
1190      public void setSelection(FeatureCollection selection) {                          // }
1191          this.selection = selection;                          //
1192          repaint();                          // // Kartenbereich um 10% vergroessern
1193      }                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1194                            // .expandEnvelope(layerBounds, 0.1), true);
1195      /* (non-Javadoc)                  }
1196       * @see org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged(org.geotools.gui.swing.event.SelectionChangedEvent)                  return maxExtend;
1197       */          }
1198      public void selectionChanged(SelectionChangedEvent e) {  
1199            /**
1200          try {           * Retuns the maximum allowed zoom scale. This is the smaller number value
1201              selection = selectionLayer.getFeatureSource().getFeatures(e.getFilter());           * of the two. Defaults to {@link Double}.MIN_VALUE
1202              repaint();           *
1203          } catch (IOException e1) {           * @author <a href="mailto:[email protected]">Stefan Alfons
1204              e1.printStackTrace();           *         Kr&uuml;ger</a>
1205          }           */
1206      }          public Double getMaxZoomScale() {
1207                    return maxZoomScale;
1208      public SelectionManager getSelectionManager() {          }
1209          return selectionManager;  
1210      }          /**
1211             * Retuns the minimum allowed zoom scale. This is the bigger number value of
1212      public void setSelectionManager(SelectionManager selectionManager) {           * the two. Defaults to {@link Double}.MAX_VALUE
1213          this.selectionManager = selectionManager;           *
1214          this.selectionManager.addSelectionChangeListener(this);           * @author <a href="mailto:[email protected]">Stefan Alfons
1215             *         Kr&uuml;ger</a>
1216      }           */
1217            public Double getMinZoomScale() {
1218                    return minZoomScale;
1219  //xulu.sn          }
1220      /**  
1221       * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste erlaubte Flaeche damit          private Image getPreFinalImage() {
1222       * die Massstabsbeschaenkungen noch eingehalten werden, FALLS der uebergeben Envelope                  // if (preFinalImage == null) {
1223       * nicht schon gueltig sein sollte.                  //                      
1224       *                  // // Rectangle curPaintArea = getVisibleRect();
1225       * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                  // // preFinalImage = new BufferedImage(curPaintArea.width,
1226       */                  // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);
1227    public Envelope bestAllowedMapArea(Envelope env) {                  //                      
1228      if (getWidth() == 0) return env;                  // preFinalImage = createImage(getBounds().width, getBounds().height);
1229      if (env == null) return env;                  //
1230                    // requestStartRendering();
1231      double scale = env.getWidth() / getWidth();                  // }
1232      double centerX = env.getMinX() + env.getWidth() / 2.;                  return preFinalImage;
1233      double centerY = env.getMinY() + env.getHeight() / 2.;          }
1234      double newWidth2;  
1235      double newHeight2;          public Map<Object, Object> getRendererHints() {
1236      if (scale < getMaxZoomScale()) {                  // Clear label cache
1237        //****************************************************************************                  labelCache.clear();
1238        // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                  rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
1239        //****************************************************************************  
1240        newWidth2 = getMaxZoomScale() * getWidth() / 2.;                  return rendererHints;
1241        newHeight2 = getMaxZoomScale() * getHeight() / 2.;          }
1242      } else if (scale > getMinZoomScale()) {  
1243        //****************************************************************************          /**
1244        // Wir zoomen weiter raus als erlaubt => Anpassen des envelope           * Liefert eine affine Transformation, um von den Fenster-Koordinaten in die
1245        //****************************************************************************           * Karten-Koordinaten (Lat/Lon) umzurechnen.
1246        newWidth2 = getMinZoomScale() * getWidth() / 2.;           *
1247        newHeight2 = getMinZoomScale() * getHeight() / 2.;           * @return eine Kopie der aktuellen Transformation; <code>null</code> wenn
1248      } else {           *         noch keine Karte angezeigt wird
1249        //****************************************************************************           */
1250        // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen          public AffineTransform getScreenToWorld() {
1251        //****************************************************************************                  if (screenToWorld == null)
1252        return env;                          resetTransforms();
1253      }                  // nur Kopie der Transformation zurueckgeben!
1254                    if (screenToWorld == null)
1255      Coordinate ll = new Coordinate(centerX - newWidth2, centerY                          return null;
1256                                     - newHeight2);                  return new AffineTransform(screenToWorld);
1257      Coordinate ur = new Coordinate(centerX + newWidth2, centerY          }
1258                                     + newHeight2);  
1259            public int getState() {
1260      return new Envelope(ll, ur);                  return state;
1261    }          }
1262    
1263    /**          /**
1264     * Retuns the minimum allowed zoom scale. This is the bigger number value of the two.           * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1265     * Defaults to {@link Double}.MAX_VALUE           * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1266     *           *
1267     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>           * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der
1268     */           *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1269    public Double getMinZoomScale() {           */
1270      return minZoomScale;          public Cursor getStaticCursor() {
1271    }                  return this.staticCursor;
1272            }
1273    /**  
1274     * Retuns the maximum allowed zoom scale. This is the smaller number value of the two.          public AffineTransform getWorldToScreenTransform() {
1275     * Defaults to {@link Double}.MIN_VALUE                  if (worldToScreen == null) {
1276     *                          resetTransforms();
1277     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                  }
1278     */                  // nur Kopie der Transformation zurueckgeben!
1279    public Double getMaxZoomScale() {                  return new AffineTransform(worldToScreen);
1280      return maxZoomScale;          }
1281    }  
1282            /**
1283    /**           * A flag indicating if dispose() has already been called. If true, then
1284     * Set the maximum allowed zoom scale. This is the smaller number value of the two.           * further use of this {@link SelectableXMapPane} is undefined.
1285     *           */
1286     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>          private boolean isDisposed() {
1287     */                  return disposed;
1288    public void setMaxZoomScale(Double maxZoomScale) {          }
1289      // System.out.println("setting max scale to "+maxZoomScale);  
1290      this.maxZoomScale = maxZoomScale;          /**
1291    }           * Returns whether a layer is regarded or ignored on {@link #SELECT_TOP},
1292             * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions. Returns
1293    /**           * <code>true</code> if the selectability has not been defined.
1294     * Set the minimum (nearest) allowed zoom scale. This is the bigger number value of the two.           *
1295     *           * @param layer
1296     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>           *            a layer
1297     */           */
1298    public void setMinZoomScale(Double minZoomScale) {          public boolean isMapLayerSelectable(final MapLayer layer) {
1299      this.minZoomScale = minZoomScale;                  final Boolean selectable = mapLayerSelectable.get(layer);
1300    }                  return selectable == null ? true : selectable;
1301  //xulu.en          }
1302    
1303            /**
1304             * Return <code>true</code> if a CRS and a {@link #mapArea} are set and the
1305             * {@link XMapPane} is visible and has bounds set.
1306             */
1307            public boolean isWellDefined() {
1308                    try {
1309                            if (getMapContext() == null)
1310                                    return false;
1311                            if (getMapContext().getLayerCount() <= 0)
1312                                    return false;
1313                            if (getVisibleRect().getWidth() == 0)
1314                                    return false;
1315                            if (getVisibleRect().getHeight() == 0)
1316                                    return false;
1317                            // if (getMapArea() == null)
1318                            // return false;
1319                    } catch (final Exception e) {
1320                            return false;
1321                    }
1322                    return true;
1323            }
1324    
1325            /**
1326             * Called from the listeners while the mouse is dragging, this method either
1327             * paints a translated (moved/panned) version of the image, or a rectangle.
1328             *
1329             * @param startPos
1330             *            in screen coordinates
1331             * @param lastPos
1332             *            in screen coordinates
1333             * @param event
1334             *            the {@link MouseEvent} to read the mouse buttons from
1335             */
1336            public void mouseDragged(final Point startPos, final Point lastPos,
1337                            final MouseEvent event) {
1338    
1339                    if ((getState() == XMapPane.PAN)
1340                                    || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
1341    
1342                            // Panning needs a panning coursor
1343                            if (getCursor() != SwingUtil.PANNING_CURSOR) {
1344                                    setCursor(SwingUtil.PANNING_CURSOR);
1345    
1346                                    // While panning, we deactivate the rendering. So the tasks are
1347                                    // ready to start when the panning is finished.
1348                                    if (bgExecuter != null && bgExecuter.isRunning())
1349                                            bgExecuter.cancelTask();
1350                                    if (localExecuter.isRunning())
1351                                            localExecuter.cancelTask();
1352                            }
1353    
1354                            if (lastPos.x > 0 && lastPos.y > 0) {
1355                                    final int dx = event.getX() - lastPos.x;
1356                                    final int dy = event.getY() - lastPos.y;
1357    
1358                                    // TODO Stop dragging when the drag would not be valid...
1359                                    // boolean dragValid = true;
1360                                    // // check if this panning results in a valid mapArea
1361                                    // {
1362                                    // Rectangle winBounds = xMapPane.getBounds();
1363                                    // winBounds.translate(xMapPane.imageOrigin.x,
1364                                    // -xMapPane.imageOrigin.y);
1365                                    // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(
1366                                    // winBounds.x, winBounds.y, winBounds.x
1367                                    // + winBounds.width, winBounds.y
1368                                    // + winBounds.height);
1369                                    //                                      
1370                                    //
1371                                    // winBounds = xMapPane.getBounds();
1372                                    // Point testIng = new Point(xMapPane.imageOrigin);
1373                                    // testIng.translate(dx, dy);
1374                                    // winBounds.translate(testIng.x, -testIng.y);
1375                                    // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(
1376                                    // winBounds.x, winBounds.y, winBounds.x
1377                                    // + winBounds.width, winBounds.y
1378                                    // + winBounds.height);
1379                                    //
1380                                    // // If the last drag doesn't change the MapArea anymore cancel
1381                                    // it.
1382                                    // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(
1383                                    // xMapPane.bestAllowedMapArea(newMapAreaBefore))){
1384                                    // dragValid = false;
1385                                    // return;
1386                                    // }
1387                                    // }
1388    
1389                                    imageOrigin.translate(dx, dy);
1390                                    updateFinalImage();
1391                                    repaint();
1392                            }
1393    
1394                    } else if ((getState() == XMapPane.ZOOM_IN)
1395                                    || (getState() == XMapPane.ZOOM_OUT)
1396                                    || (getState() == XMapPane.SELECT_ALL)
1397                                    || (getState() == XMapPane.SELECT_TOP)) {
1398    
1399                            // Draws a rectangle
1400                            final Graphics graphics = getGraphics();
1401                            drawRectangle(graphics, startPos, event.getPoint());
1402                            if ((lastPos.x > 0) && (lastPos.y > 0))
1403                                    drawRectangle(graphics, startPos, lastPos);
1404                            graphics.dispose();
1405                    }
1406            }
1407    
1408            /**
1409             * Called by the {@link RenderingExecutor} when rendering was cancelled.
1410             */
1411            public void onRenderingCancelled() {
1412                    LOGGER.debug("Rendering cancelled");
1413                    repaintTimer.stop();
1414            }
1415    
1416            /**
1417             * Called by the {@link RenderingExecutor} when rendering has been
1418             * completed.
1419             */
1420            public void onRenderingCompleted() {
1421                    LOGGER.info("complete");
1422    
1423                    repaintTimer.stop();
1424    
1425                    // We "forget" about an exception every time we complete a rendering
1426                    // thread successfully
1427                    if (renderingErrors.size() > 0)
1428                            renderingErrors.remove(0);
1429    
1430                    updateFinalImage();
1431                    repaint();
1432            }
1433    
1434            /**
1435             * Called by the {@linkplain XMapPane.RenderingTask} when rendering failed.
1436             * Publishes a {@linkplain MapPaneEvent} of type {@code
1437             * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.
1438             *
1439             * @param renderingError
1440             *            The error that occured during rendering
1441             *
1442             * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1443             */
1444            public void onRenderingFailed(final Exception renderingError) {
1445    
1446                    // Store the exceptions so we can show it to the user:
1447                    if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError
1448                                    .getMessage().equals(
1449                                                    "Argument \"sourceCRS\" should not be null.")))
1450                            this.renderingErrors.add(renderingError);
1451                    if (renderingErrors.size() > 3)
1452                            renderingErrors.remove(0);
1453    
1454                    repaintTimer.stop();
1455    
1456                    LOGGER.warn("Rendering failed", renderingError);
1457                    updateFinalImage();
1458                    repaint();
1459    
1460            }
1461    
1462            @Override
1463            protected void paintComponent(final Graphics g) {
1464    
1465                    // Maybe update the cursor and maybe stop the repainting timer
1466                    updateCursor();
1467    
1468                    if (!acceptsRepaintCalls)
1469                            return;
1470    
1471                    if (!isWellDefined())
1472                            return;
1473    
1474                    // super.paintComponent(g); // candidate for removal
1475    
1476                    boolean paintedSomething = false;
1477    
1478                    if (mapImageInvalid) { /* if the map changed then redraw */
1479    
1480                            mapImageInvalid = false; // Reset for next round
1481    
1482                            // If the new mapArea and the oldMapArea intersect, we can draw some
1483                            // quick scaled preview to make the user feel that something is
1484                            // happening.
1485                            if (mapAreaChanged && oldMapArea != null
1486                                            && getMapArea().intersects(oldMapArea)
1487                                            & !getMapArea().equals(oldMapArea) && !paneResized) {
1488    
1489                                    mapAreaChanged = false;
1490    
1491                                    if (getMapArea().covers(oldMapArea)) {
1492                                            quickPreviewHint = ZOOM_OUT;
1493                                            paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1494                                    } else if (oldMapArea.covers(getMapArea())) {
1495                                            quickPreviewHint = ZOOM_IN;
1496                                            paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1497                                    }
1498                            }
1499                    }
1500    
1501                    if (!paintedSomething) {
1502    
1503                            g.drawImage(getFinalImage(), 0, 0, null);
1504    
1505                            g.dispose(); // cand. for removal
1506    
1507                            paintedSomething = true; // cand. for removal
1508                    }
1509    
1510            }
1511    
1512            /**
1513             * Heavily works on releasing all resources related to the four
1514             * {@link Image}s used to cache the results of the different renderers.<br>
1515             * In November 2009 i had some memory leaking problems with {@link XMapPane}
1516             * . The resources of the buffered images were never released. It seem to be
1517             * important to call the GC right after flushing the images.<br>
1518             * Hence this method may take a while, because it calls the GC up to four
1519             * times.
1520             */
1521            private void disposeImages() {
1522    
1523                    // System.out.println("vorher = "
1524                    // + new MbDecimalFormatter().format(LangUtil.gcTotal()));
1525                    // bi.flush();
1526                    // return bi = null;
1527                    // System.out.println("nacher = "
1528                    // + new MbDecimalFormatter().format(LangUtil.gcTotal()));
1529                    //
1530                    // System.out.println("\n");
1531    
1532                    if (preFinalImage != null) {
1533                            preFinalImage.flush();
1534                            preFinalImage = null;
1535                            LangUtil.gc();
1536                    }
1537                    if (finalImage != null) {
1538                            finalImage.flush();
1539                            finalImage = null;
1540                            LangUtil.gc();
1541                    }
1542                    if (localImage != null) {
1543                            localImage.flush();
1544                            localImage = null;
1545                            LangUtil.gc();
1546                    }
1547                    if (bgImage != null) {
1548                            bgImage.flush();
1549                            bgImage = null;
1550                            LangUtil.gc();
1551                    }
1552    
1553            }
1554    
1555            /**
1556             * Performs a {@value #PAN} action. During panning, the displacement is
1557             * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
1558             * reset the offset and call {@link #setMapArea(Envelope)}.
1559             */
1560            public void performPan() {
1561    
1562                    Rectangle winBounds = getVisibleRect();
1563    
1564                    winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1565                    final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1566                                    winBounds.y, winBounds.x + winBounds.width, winBounds.y
1567                                                    + winBounds.height);
1568    
1569                    imageOrigin.x = 0;
1570                    imageOrigin.y = 0;
1571    
1572                    if (!setMapArea(newMapArea)) {
1573                            /**
1574                             * If setMapArea returns true, the finalImage is updated anyways.
1575                             * This if-case exists to ensure that we repaint a correct image
1576                             * even if the new panning area has been denied.
1577                             */
1578                            updateFinalImage();
1579                            repaint();
1580                    }
1581    
1582                    if (getCursor() == SwingUtil.PANNING_CURSOR)
1583                            setCursor(SwingUtil.PAN_CURSOR);
1584            }
1585    
1586            /**
1587             * Entfernt einen Listener von der Map.
1588             *
1589             * @param l
1590             *            zu entfernender Listener
1591             */
1592            public void removeMapPaneListener(final JMapPaneListener l) {
1593                    mapPaneListeners.remove(l);
1594            }
1595    
1596            /**
1597             * Cancels all running renderers and sets the flag to start new ones. <br>
1598             *
1599             * @see #startRenderThreadsTimer
1600             */
1601            private void requestStartRendering() {
1602                    if (bgExecuter != null)
1603                            bgExecuter.cancelTask();
1604    
1605                    localExecuter.cancelTask();
1606    
1607                    mapImageInvalid = true;
1608                    if (paneResized) {
1609                            paneResized = false;
1610                            disposeImages();
1611                    }
1612                    requestStartRendering = true;
1613    
1614            }
1615    
1616            /**
1617             * Calculate the affine transforms used to convert between world and pixel
1618             * coordinates. The calculations here are very basic and assume a cartesian
1619             * reference system.
1620             * <p>
1621             * Tne transform is calculated such that {@code envelope} will be centred in
1622             * the display
1623             *
1624             * @param envelope
1625             *            the current map extent (world coordinates)
1626             * @param paintArea
1627             *            the current map pane extent (screen units)
1628             */
1629            private void resetTransforms() {
1630                    ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1631                                    getMapContext().getCoordinateReferenceSystem());
1632    
1633                    // System.out
1634                    // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1635                    if (!isWellDefined())
1636                            return;
1637    
1638                    worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1639                                    getVisibleRect());
1640    
1641                    try {
1642                            screenToWorld = worldToScreen.createInverse();
1643    
1644                    } catch (NoninvertibleTransformException ex) {
1645                            LOGGER
1646                                            .error("can't invert worldToScreen to get screenToWorld!",
1647                                                            ex);
1648                    }
1649            }
1650    
1651            public void setBgContext(final MapContext context) {
1652    
1653                    // Remove the default listener from the old context
1654                    if (this.bgContext != null) {
1655                            this.bgContext.removeMapLayerListListener(bgContextListener);
1656    
1657                            // adding listener to all layers
1658                            for (final MapLayer mapLayer : bgContext.getLayers()) {
1659                                    mapLayer.removeMapLayerListener(bgMapLayerListener);
1660                            }
1661                    }
1662    
1663                    this.bgContext = context;
1664    
1665                    if (context != null) {
1666                            // setMapArea(bgContext.getAreaOfInterest());
1667    
1668                            this.bgContext.addMapLayerListListener(bgContextListener);
1669    
1670                            // adding listener to all layers
1671                            for (final MapLayer mapLayer : bgContext.getLayers()) {
1672                                    mapLayer.addMapLayerListener(bgMapLayerListener);
1673                            }
1674                    }
1675    
1676                    requestStartRendering();
1677            }
1678    
1679            public void setJava2dHints(final RenderingHints java2dHints) {
1680                    this.java2dHints = java2dHints;
1681            }
1682    
1683            public void setLocalContext(final MapContext context) {
1684                    // Remove the default listener from the old context
1685                    if (this.localContext != null) {
1686                            this.localContext.removeMapLayerListListener(localContextListener);
1687    
1688                            // adding listener to all layers
1689                            for (final MapLayer mapLayer : localContext.getLayers()) {
1690                                    mapLayer.removeMapLayerListener(localMapLayerListener);
1691                            }
1692                    }
1693    
1694                    this.localContext = context;
1695    
1696                    if (context != null) {
1697    
1698                            // setMapArea(localContext.getAreaOfInterest());
1699    
1700                            localRenderer.setContext(localContext);
1701    
1702                            this.localContext.addMapLayerListListener(localContextListener);
1703    
1704                            // adding listener to all layers
1705                            for (final MapLayer mapLayer : localContext.getLayers()) {
1706                                    mapLayer.addMapLayerListener(localMapLayerListener);
1707                            }
1708                    }
1709    
1710                    requestStartRendering();
1711    
1712            }
1713    
1714            public boolean setMapArea(final Envelope newMapArea) {
1715                    return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1716                                    .getCoordinateReferenceSystem()));
1717            }
1718    
1719            /**
1720             * @param newMapArea
1721             * @return <code>true</code> if the mapArea has been changed and a repaint
1722             *         has been triggered.
1723             */
1724            public boolean setMapArea(final ReferencedEnvelope newMapArea) {
1725    
1726                    if (newMapArea == null
1727                                    || bestAllowedMapArea(newMapArea).equals(mapArea)) {
1728                            // No change.. no need to repaint
1729                            return false;
1730                    }
1731    
1732                    // Testing, whether NaN or Infinity are used in the newMapArea
1733                    if (newMapArea.isNull() || Double.isInfinite(newMapArea.getMaxX())
1734                                    || Double.isInfinite(newMapArea.getMaxY())
1735                                    || Double.isInfinite(newMapArea.getMinX())
1736                                    || Double.isInfinite(newMapArea.getMinY())) {
1737                            // No change.. ugly new values
1738                            LOGGER.warn("setMapArea has been called with newArea = "
1739                                            + newMapArea);
1740                            return false;
1741                    }
1742    
1743                    final Envelope candNew = bestAllowedMapArea(newMapArea);
1744    
1745                    // Testing, whether the difference if just minimal
1746                    if (mapArea != null) {
1747                            final double tolX = mapArea.getWidth() / 1000.;
1748                            final double tolY = mapArea.getHeight() / 1000.;
1749                            if ((candNew.getMinX() - tolX < mapArea.getMinX())
1750                                            && (mapArea.getMinX() < candNew.getMinX() + tolX)
1751                                            && (candNew.getMaxX() - tolX < mapArea.getMaxX())
1752                                            && (mapArea.getMaxX() < candNew.getMaxX() + tolX)
1753    
1754                                            && (candNew.getMinY() - tolY < mapArea.getMinY())
1755                                            && (mapArea.getMinY() < candNew.getMinY() + tolY)
1756                                            && (candNew.getMaxY() - tolY < mapArea.getMaxY())
1757                                            && (mapArea.getMaxY() < candNew.getMaxY() + tolY)
1758    
1759                            ) {
1760                                    // The two mapAreas only differ my 1/1000th.. ignore
1761    
1762                                    return false;
1763                            }
1764                    }
1765    
1766                    // New map are is accepted:
1767                    oldMapArea = mapArea;
1768                    mapArea = candNew;
1769                    resetTransforms();
1770    
1771                    if (localContext != null) {
1772                            localContext.setAreaOfInterest(mapArea, localContext
1773                                            .getCoordinateReferenceSystem());
1774                    }
1775                    if (bgContext != null) {
1776                            bgContext.setAreaOfInterest(mapArea, localContext
1777                                            .getCoordinateReferenceSystem());
1778                    }
1779    
1780                    mapAreaChanged = true;
1781    
1782                    repaint(200); // Do not remove it!
1783    
1784                    requestStartRendering();
1785    
1786                    return true;
1787            }
1788    
1789            /**
1790             * Set the background color of the map.
1791             *
1792             * @param if <code>null</code>, white is used.
1793             */
1794            public void setMapBackgroundColor(Color bgColor) {
1795                    if (bgColor == null)
1796                            bgColor = Color.WHITE;
1797                    this.mapBackgroundColor = bgColor;
1798            }
1799    
1800            /**
1801             * Set the BufferedImage to use as a flaoting icon in the lower right corner
1802             *
1803             * @param mapImageIcon
1804             *            <code>null</code> is allowed and deactivates this icon.
1805             */
1806            public void setMapImage(final BufferedImage mapImage) {
1807                    this.mapImage = mapImage;
1808            }
1809    
1810            /**
1811             * Sets whether a layer is regarded or ignored on {@link #SELECT_TOP},
1812             * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions.
1813             *
1814             * @param layer
1815             *            a layer
1816             * @param selectable
1817             *            if {@code false} the layer is ignored during the upper
1818             *            mentioned actions. If <code>null</code>, the default (true)
1819             *            will be used.
1820             */
1821            public void setMapLayerSelectable(final MapLayer layer,
1822                            final Boolean selectable) {
1823                    if (selectable == null)
1824                            mapLayerSelectable.remove(layer);
1825                    else
1826                            mapLayerSelectable.put(layer, selectable);
1827            }
1828    
1829            /**
1830             * Defines an evelope of the viwable area. The JMapPane will never show
1831             * anything outside of this extend.
1832             *
1833             * @param maxExtend
1834             *            <code>null</code> to not have this restriction.
1835             */
1836            public void setMaxExtend(final Envelope maxExtend) {
1837                    this.maxExtend = maxExtend;
1838            }
1839    
1840            /**
1841             * Set the maximum allowed zoom scale. This is the smaller number value of
1842             * the two. If <code>null</code> is passed, Double.MINVALUE are used which
1843             * mean there is no restriction.
1844             *
1845             * @author <a href="mailto:[email protected]">Stefan Alfons
1846             *         Kr&uuml;ger</a>
1847             */
1848            public void setMaxZoomScale(final Double maxZoomScale) {
1849                    this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
1850                                    : maxZoomScale;
1851            }
1852    
1853            // /** Stored the time used for the last real rendering in ms. **/
1854            // private long lastRenderingDuration = Long.MAX_VALUE;
1855    
1856            /**
1857             * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1858             * value of the two. If <code>null</code> is passed, Double.MAXVALUE are
1859             * used which mean there is no restriction.
1860             *
1861             *
1862             * @author <a href="mailto:[email protected]">Stefan Alfons
1863             *         Kr&uuml;ger</a>
1864             */
1865            public void setMinZoomScale(final Double minZoomScale) {
1866                    this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE
1867                                    : minZoomScale;
1868            }
1869    
1870            /**
1871             * If <code>true</code>, allow the {@link XMapPane} to process #repaint()
1872             * requests. Otherwise the map will not paint anything and not start any
1873             * rendering {@link Thread}s.
1874             */
1875            public void setPainting(final boolean b) {
1876                    acceptsRepaintCalls = b;
1877                    if (acceptsRepaintCalls == true)
1878                            repaint();
1879            }
1880    
1881            private void setRendererHints(final Map<Object, Object> rendererHints) {
1882                    if (rendererHints != null)
1883                            this.rendererHints = rendererHints;
1884            }
1885    
1886            /**
1887             * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the
1888             * repaint Timer if
1889             *
1890             * @param state
1891             */
1892            public void setState(final int state) {
1893                    this.state = state;
1894    
1895                    zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN
1896                                    || state == ZOOM_OUT || state == PAN));
1897    
1898                    // Je nach Aktion den Cursor umsetzen
1899                    updateCursor();
1900            }
1901    
1902            /**
1903             * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,
1904             * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
1905             * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
1906             * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
1907             * {@code null} als Parameter uebergeben werden
1908             *
1909             * @param cursor
1910             *            Cursor
1911             */
1912            public void setStaticCursor(final Cursor cursor) {
1913                    this.staticCursor = cursor;
1914                    if (cursor != null)
1915                            super.setCursor(cursor);
1916            }
1917    
1918            /**
1919             * Starts rendering on one or two threads
1920             */
1921            private void startRendering() {
1922    
1923                    if (!isWellDefined() || !acceptsRepaintCalls) {
1924                            // if we are not ready to start rendering, try it again the next
1925                            // time the timer is chacking the flag.
1926                            requestStartRendering = true;
1927                            return;
1928                    }
1929    
1930                    if (bgExecuter != null) {
1931                            // Stop all renderers
1932                            bgExecuter.cancelTask();
1933                    }
1934    
1935                    localExecuter.cancelTask();
1936    
1937                    final Rectangle curPaintArea = getVisibleRect();
1938    
1939                    /**
1940                     * We have to set new renderer
1941                     */
1942    
1943                    if (getBgContext() != null) {
1944                            bgRenderer.setJava2DHints(getJava2dHints());
1945                            bgRenderer.setRendererHints(getRendererHints());
1946    
1947                            // bgExecuter = new RenderingExecutor();
1948                            // LOGGER.debug("starting bg renderer:");
1949                            // // /* System.out.println("rendering"); */
1950                            // final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
1951                            // bgContext, getRendererHints());
1952                            // createGTRenderer.setJava2DHints(getJava2dHints());
1953                            // bgExecuter.submit(getBgContext().getAreaOfInterest(),
1954                            // curPaintArea,
1955                            // (Graphics2D) getBgImage().getGraphics(), createGTRenderer);
1956                    }
1957    
1958                    if (getMapContext() != null) {
1959                            // localExecuter = new RenderingExecutor(this, 150l);
1960                            // LOGGER.debug("starting local renderer:");
1961    
1962                            localRenderer.setJava2DHints(getJava2dHints());
1963                            localRenderer.setRendererHints(getRendererHints());
1964    
1965                            final boolean submitted = localExecuter.submit(getMapArea(),
1966                                            curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1967                                            localRenderer);
1968                            if (submitted)
1969                                    repaintTimer.restart();
1970                            else
1971                                    requestStartRendering = true; // Try to start rendering
1972                            // again in
1973                            // a moment
1974                    }
1975    
1976                    updateCursor();
1977            }
1978    
1979            /**
1980             * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.
1981             *
1982             * @param ox
1983             *            X-Koordinate der VON-Position
1984             * @param oy
1985             *            Y-Koordinate der VON-Position
1986             * @param px
1987             *            X-Koordinate der BIS-Position
1988             * @param py
1989             *            Y-Koordinate der BIS-Position
1990             * @param winToGeotransform
1991             *            Eine Window to Geo transform. If <code>null</code>,
1992             *            {@link #getScreenToWorld()} is used.
1993             */
1994            public Envelope tranformGeoToWindow(final double ox, final double oy,
1995                            final double px, final double py) {
1996                    final AffineTransform at = getWorldToScreenTransform();
1997                    Point2D geoO;
1998                    // try {
1999                    geoO = at.transform(new Point2D.Double(ox, oy), null);
2000                    final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2001                    return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2002                    // } catch (final NoninvertibleTransformException e) {
2003                    // LOGGER.error(e);
2004                    // return new Envelope(ox, oy, px, py);
2005                    // }
2006            }
2007    
2008            /**
2009             * Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten.
2010             *
2011             * @param ox
2012             *            X-Koordinate der VON-Position
2013             * @param oy
2014             *            Y-Koordinate der VON-Position
2015             * @param px
2016             *            X-Koordinate der BIS-Position
2017             * @param py
2018             *            Y-Koordinate der BIS-Position
2019             */
2020            public Envelope tranformWindowToGeo(final int ox, final int oy,
2021                            final int px, final int py) {
2022                    final AffineTransform at = getScreenToWorld();
2023                    final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
2024                    final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2025    
2026                    // Mmmmm... don't really understand why its x,x,y,y
2027                    // return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(),
2028                    // geoP.getY());
2029                    return new Envelope(new Coordinate(geoO.getX(), geoO.getY()),
2030                                    new Coordinate(geoP.getX(), geoP.getY()));
2031            }
2032    
2033            /**
2034             * Will update the cursor. If all rendering is finished also stops the
2035             * {@link #repaintTimer}
2036             */
2037            public void updateCursor() {
2038    
2039                    // if the renderers have stopped, also stop the timer that is updating
2040                    // the final image
2041                    if (bgExecuter != null && bgExecuter.isRunning()
2042                                    || localExecuter.isRunning()) {
2043                            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
2044                            return;
2045                    } else {
2046                            // Allow one last rendering
2047                            if (repaintTimer.isRunning()) {
2048                                    // System.out.println("one last rendering....");
2049                                    repaintTimer.stop();
2050                                    updateFinalImage();
2051                                    repaint();
2052                            }
2053                    }
2054    
2055                    // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
2056                    // von der aktuellen Aktion
2057                    if (this.staticCursor != null) {
2058                            setCursor(staticCursor);
2059                            return;
2060                    }
2061                    if (getCursor() == SwingUtil.PANNING_CURSOR) {
2062                            // This cursor will reset itself
2063                            return;
2064                    }
2065    
2066                    // Set the cursor depending on what tool is in use...
2067                    switch (state) {
2068                    case SELECT_TOP:
2069                    case SELECT_ONE_FROM_TOP:
2070                    case SELECT_ALL:
2071                            setCursor(SwingUtil.CROSSHAIR_CURSOR);
2072                            break;
2073                    case ZOOM_IN:
2074                            setCursor(SwingUtil.ZOOMIN_CURSOR);
2075                            break;
2076                    case ZOOM_OUT:
2077                            setCursor(SwingUtil.ZOOMOUT_CURSOR);
2078                            break;
2079                    case PAN:
2080                            setCursor(SwingUtil.PAN_CURSOR);
2081                            break;
2082                    default:
2083                            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2084                            break;
2085                    }
2086            }
2087    
2088            /**
2089             * The renderers are all rendering into their own {@link Image}s. This
2090             * method combines all images to one {@link #finalImage}. The
2091             * {@link #repaintTimer} is calling this method regularely to update the
2092             * {@link #finalImage} even if the renderers are still working.
2093             */
2094            synchronized protected Image updateFinalImage() {
2095    
2096                    // Render the two map images first, into the preFinalImage
2097                    if (bgExecuter != null) {
2098                            final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()
2099                                            .getGraphics();
2100                            preFinalG.setBackground(getMapBackgroundColor());
2101    
2102                            preFinalG.drawImage(getBgImage(), 0, 0, getMapBackgroundColor(),
2103                                            null);
2104    
2105                            // // Draw the local layers image
2106                            preFinalG.drawImage(getLocalImage(), 0, 0, null);
2107                            preFinalG.dispose();
2108    
2109                    } else {
2110                            preFinalImage = getLocalImage();
2111                    }
2112    
2113                    final Graphics2D finalG = getFinalImage().createGraphics();
2114                    finalG.setBackground(getMapBackgroundColor());
2115                    finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
2116                                    getMapBackgroundColor(), null);
2117    
2118                    final int finalImageHeight = getFinalImage().getHeight(null);
2119                    final int finalImageWidth = getFinalImage().getWidth(null);
2120    
2121                    final Rectangle painedArea = new Rectangle(imageOrigin.x,
2122                                    imageOrigin.y, finalImageWidth, finalImageHeight);
2123                    SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
2124    
2125                    addGadgets(finalG, false);
2126    
2127                    finalG.dispose();
2128    
2129                    return finalImage;
2130            }
2131    
2132            /**
2133             * Paints some optional stuff into the given {@link Graphics2D}. Usually
2134             * called as the last layer when {@link #updateFinalImage()}
2135             *
2136             * @param forceWait
2137             *            if <code>true</code>, a Wait-message will be painted even
2138             *            though the rendering threads may not yet have started. If
2139             *            <code>false</code>, it will only depend on
2140             *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2141             */
2142            private void addGadgets(final Graphics2D graphics, boolean forceWait) {
2143    
2144                    // Paint a logo to the bottom right if available
2145                    if (mapImage != null) {
2146                            Rectangle visibleRect = getVisibleRect();
2147                            graphics.drawImage(mapImage, visibleRect.width
2148                                            - mapImage.getWidth() - 10, getVisibleRect().height
2149                                            - mapImage.getHeight() - 10, null);
2150                    }
2151    
2152                    int y = 17;
2153    
2154                    // If the rendering process is still running, indicate this is the image
2155                    if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2156                                    || localExecuter.isRunning()) {
2157    
2158                            y += 8;
2159    
2160                            final Color c = graphics.getColor();
2161                            graphics.setFont(waitFont);
2162    
2163                            graphics.setColor(getMapBackgroundColor());
2164                            graphics.drawString(waitMsg, 5, y);
2165                            graphics.setColor(getMapBackgroundColor());
2166                            graphics.drawString(waitMsg, 7, y + 2);
2167                            graphics.setColor(Color.BLACK);
2168                            graphics.drawString(waitMsg, 6, y + 1);
2169    
2170                            graphics.setColor(c);
2171    
2172                            y += 24;
2173                    }
2174    
2175                    if (!renderingErrors.isEmpty() && isShowExceptions()) {
2176    
2177                            final Color c = graphics.getColor();
2178                            graphics.setFont(errorFont);
2179    
2180                            for (Exception ex : renderingErrors) {
2181    
2182                                    String errStr = ex.getLocalizedMessage();
2183    
2184                                    if (errStr == null)
2185                                            errStr = ex.getMessage();
2186                                    if (errStr == null)
2187                                            errStr = "unknown error: " + ex.getClass().getSimpleName();
2188    
2189                                    graphics.setColor(Color.WHITE);
2190                                    graphics.drawString(errStr, 5, y);
2191                                    graphics.setColor(Color.RED);
2192                                    graphics.drawString(errStr, 6, y + 1);
2193    
2194                                    y += 19;
2195                            }
2196    
2197                            graphics.setColor(c);
2198                    }
2199    
2200            }
2201    
2202            /**
2203             * Sets the {@link #mapArea} to best possibly present the given features. If
2204             * only one single point is given, the window is moved over the point.
2205             *
2206             * @param features
2207             *            if <code>null</code> or size==0, the function doesn nothing.
2208             */
2209            public void zoomTo(
2210                            final FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
2211    
2212                    // if (!isWellDefined()) return;
2213    
2214                    final CoordinateReferenceSystem mapCRS = getMapContext()
2215                                    .getCoordinateReferenceSystem();
2216                    final CoordinateReferenceSystem fCRS = features.getSchema()
2217                                    .getGeometryDescriptor().getCoordinateReferenceSystem();
2218    
2219                    ReferencedEnvelope _mapArea;
2220                    if (mapArea == null)
2221                            _mapArea = features.getBounds();
2222                    else
2223                            _mapArea = getMapArea();
2224                    double width = _mapArea.getWidth();
2225                    double height = _mapArea.getHeight();
2226                    final double ratio = height / width;
2227    
2228                    if (features == null || features.size() == 0) {
2229                            // feature count == 0 Zoom to the full extend
2230                            return;
2231                    } else if (features.size() == 1) {
2232    
2233                            // feature count == 1 Just move the window to the point and zoom 'a
2234                            // bit'
2235                            final SimpleFeature singleFeature = features.iterator().next();
2236    
2237                            if (((Geometry) singleFeature.getDefaultGeometry())
2238                                            .getCoordinates().length > 1) {
2239                                    // System.out.println("Zoomed to only pne poylgon");
2240                                    // Poly
2241                                    // TODO max width vs. height
2242                                    width = features.getBounds().getWidth() * 3;
2243                                    height = ratio * width;
2244                            } else {
2245                                    // System.out.println("Zoomed in a bit becasue only one point");
2246                                    // width *= .9;
2247                                    // height *= .9;
2248                            }
2249    
2250                            Coordinate centre = features.getBounds().centre();
2251                            if (!mapCRS.equals(fCRS)) {
2252                                    // only to calculations if the CRS differ
2253                                    try {
2254                                            MathTransform fToMap;
2255                                            fToMap = CRS.findMathTransform(fCRS, mapCRS);
2256                                            // centre is transformed to the mapCRS
2257                                            centre = JTS.transform(centre, null, fToMap);
2258                                    } catch (final FactoryException e) {
2259                                            LOGGER.error("Looking for a Math transform", e);
2260                                    } catch (final TransformException e) {
2261                                            LOGGER.error("Looking for a Math transform", e);
2262                                    }
2263                            }
2264    
2265                            final Coordinate newLeftBottom = new Coordinate(centre.x - width
2266                                            / 2., centre.y - height / 2.);
2267                            final Coordinate newTopRight = new Coordinate(
2268                                            centre.x + width / 2., centre.y + height / 2.);
2269    
2270                            final Envelope newMapArea = new Envelope(newLeftBottom, newTopRight);
2271    
2272                            setMapArea(newMapArea);
2273    
2274                    } else {
2275                            final ReferencedEnvelope fBounds = features.getBounds();
2276    
2277                            ReferencedEnvelope bounds;
2278                            if (!mapCRS.equals(fCRS)) {
2279                                    bounds = JTSUtil.transformEnvelope(fBounds, mapCRS);
2280                            } else {
2281                                    bounds = fBounds;
2282                            }
2283                            // BB umrechnen von Layer-CRS in Map-CRS
2284    
2285                            // Expand a bit
2286                            bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.);
2287    
2288                            setMapArea(bounds);
2289                    }
2290            }
2291    
2292            /**
2293             * Zooms towards a point.
2294             *
2295             * @param center
2296             *            position in window coordinates
2297             * @param zoomFactor
2298             *            > 1 for zoom in, < 1 for zoom out. Default is 1.33
2299             */
2300            public void zoomTo(final Point center) {
2301                    zoomTo(center, null);
2302            }
2303    
2304            /**
2305             * Zooms towards a point.
2306             *
2307             * @param center
2308             *            position in window coordinates
2309             * @param zoomFaktor
2310             *            > 1 for zoom in, < 1 for zoom out. Default is 1.33.
2311             */
2312            public void zoomTo(Point center, Double zoomFaktor) {
2313                    if (zoomFaktor == null || zoomFaktor == 0.)
2314                            zoomFaktor = 2.;
2315    
2316                    final Point2D gcenter = getScreenToWorld().transform(center, null);
2317                    center = null;
2318    
2319                    if (Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())
2320                                    || Double.isInfinite(gcenter.getX())
2321                                    || Double.isInfinite(gcenter.getY())
2322    
2323                    ) {
2324                            // Not inside valid CRS area! cancel
2325                            return;
2326                    }
2327    
2328                    final Envelope mapArea = getMapArea();
2329    
2330                    final Envelope newMapArea = new Envelope(mapArea);
2331                    newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2332                                    .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2333                                    .getHeight()) / 2.);
2334    
2335                    // TODO we actually want that
2336                    // // Move the newMapArea above the new center
2337                    // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2338                    // .getY()
2339                    // - mapArea.centre().y);
2340    
2341                    setMapArea(newMapArea);
2342            }
2343    
2344            /**
2345             * Shall non-fatal rendering exceptions be reported in the mappane or be
2346             * dropped quitely.
2347             */
2348            public void setShowExceptions(boolean showExceptions) {
2349                    this.showExceptions = showExceptions;
2350            }
2351    
2352            /**
2353             * Shall exceptions be reported in the mappane?
2354             */
2355            public boolean isShowExceptions() {
2356                    return showExceptions;
2357            }
2358    
2359  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26