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

branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java revision 524 by alfonx, Wed Nov 18 09:56:47 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 gtmig.org.geotools.swing;  
2    
 /**  
  * This class is 50% copied from GeoTools 2.6.x JMapPane. GeoTools is LGPL, SCHMITZM also.<br/>  
  * In addition to  
  */  
   
 import java.awt.AlphaComposite;  
3  import java.awt.Color;  import java.awt.Color;
4  import java.awt.Cursor;  import java.awt.Cursor;
5  import java.awt.Font;  import java.awt.Font;
# Line 41  import java.awt.geom.AffineTransform; Line 20  import java.awt.geom.AffineTransform;
20  import java.awt.geom.NoninvertibleTransformException;  import java.awt.geom.NoninvertibleTransformException;
21  import java.awt.geom.Point2D;  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.ArrayList;
25  import java.util.HashMap;  import java.util.HashMap;
26  import java.util.Map;  import java.util.Map;
27  import java.util.Vector;  import java.util.Vector;
28    
 import javax.swing.JFrame;  
 import javax.swing.JPanel;  
29  import javax.swing.Timer;  import javax.swing.Timer;
30    
31  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
# Line 67  import org.geotools.referencing.CRS; Line 43  import org.geotools.referencing.CRS;
43  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
44  import org.geotools.renderer.label.LabelCacheImpl;  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.RendererUtilities;
47    import org.geotools.renderer.lite.StreamingRenderer;
48  import org.geotools.swing.JMapPane;  import org.geotools.swing.JMapPane;
49  import org.geotools.swing.event.MapMouseEvent;  import org.geotools.swing.event.MapMouseEvent;
50  import org.geotools.swing.event.MapPaneEvent;  import org.geotools.swing.event.MapPaneEvent;
# Line 81  import org.opengis.referencing.operation Line 59  import org.opengis.referencing.operation
59  import schmitzm.geotools.GTUtil;  import schmitzm.geotools.GTUtil;
60  import schmitzm.geotools.JTSUtil;  import schmitzm.geotools.JTSUtil;
61  import schmitzm.geotools.gui.SelectableXMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
62    import schmitzm.geotools.io.GeoImportUtil;
63  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
64  import schmitzm.geotools.map.event.MapLayerAdapter;  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;
 import skrueger.geotools.RenderingExecutor;  
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;
72    
73  public class XMapPane extends JPanel implements PropertyChangeListener {  /**
74          private static Logger LOGGER = Logger.getLogger(XMapPane.class);   * The {@link XMapPane} class uses a Geotools {@link GTRenderer} to paint up to
75     * two {@link MapContext}s: a "local" {@link MapContext} and a "background"
76     * {@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     * <br>
81     * While the renderers are rending the map, a <br>
82     * The {@link XMapPane} is based on schmitzm {@link JPanel}, so
83     * {@link #print(Graphics)} will automatically set the background of components
84     * to pure white.
85     *
86     * 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     * {@link #setMapImage(BufferedImage)}<br>
89     *
90     * @see SelectableXMapPane - an extension of {@link XMapPane} that supports
91     *      selecting features.
92     *
93     * @author stefan
94     *
95     */
96    public class XMapPane extends JPanel {
97    
98            private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
99            private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;
100    
101            private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
102    
103            private boolean acceptsRepaintCalls = true;
104    
105          /**          /**
106           * Sets whether a layer is regarded or ignored on {@link #SELECT_TOP},           * Main {@link MapContext} that holds all layers that are rendered into the
107           * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions.           * {@link #localImage} by the {@link #localRenderer}
108             */
109            MapContext localContext;
110    
111            /**
112             * {@link MapContext} holding the background layers. Use it for layers that
113             * CAN take very long for rendering, like layer from the Internet: WMS, WFS,
114             * OSM...<br>
115             * <code>null</code> by default.
116           *           *
117           * @param layer           * @see #setBgContext(MapContext)
118           *            a layer           * @see #getBgContext()
          * @param selectable  
          *            if {@code false} the layer is ignored during the upper  
          *            mentioned actions. If <code>null</code>, the default (true)  
          *            will be used.  
119           */           */
120          public void setMapLayerSelectable(MapLayer layer, Boolean selectable) {          MapContext bgContext;
                 if (selectable == null)  
                         mapLayerSelectable.remove(layer);  
                 else  
                         mapLayerSelectable.put(layer, selectable);  
         }  
121    
122          /**          /**
123           * Holds a flag for each layer, whether it is regarded or ignored on           * While threads are working, calls {@link XMapPane#updateFinalImage()}
124           * {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
125           * actions.           * renderers have finished.
126             *
127             * @see INITIAL_REPAINT_DELAYAL
128             * @see #REPEATING_REPAINT_DELAY
129           */           */
130          final protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();          final private Timer repaintTimer;
131    
132          /**          /**
133           * Returns whether a layer is regarded or ignored on {@link #SELECT_TOP},           * The initial delay in milliseconds until the {@link #finalImage} is
134           * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions. Returns           * updated the first time.
135           * <code>true</code> if the selectability has not been defined.           */
136            public static final int INITIAL_REPAINT_DELAY = 900;
137    
138            /**
139             * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
140             * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
141             * with previews.
142             */
143            public static final int REPEATING_REPAINT_DELAY = 600;
144    
145            /**
146             * Default delay (milliseconds) before the map will be redrawn when resizing
147             * the pane. This is to avoid flickering while drag-resizing.
148           *           *
149           * @param layer           * @see #resizeTimer
          *            a layer  
150           */           */
151          public boolean isMapLayerSelectable(MapLayer layer) {          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
152                  Boolean selectable = mapLayerSelectable.get(layer);  
153                  return selectable == null ? true : selectable;          /**
154          }           * This not-repeating {@link Timer} is re-started whenever the component is
155             * 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             */
159            private final Timer resizeTimer;
160    
161            /**
162             * Flag for no-tool.
163             */
164            public static final int NONE = -123;
165    
166          /**          /**
167           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
# Line 138  public class XMapPane extends JPanel imp Line 170  public class XMapPane extends JPanel imp
170           * @see #setState(int)           * @see #setState(int)
171           */           */
172          public static final int PAN = 1;          public static final int PAN = 1;
173    
174          /**          /**
175           * Flag fuer Modus "Heran zoomen".           * Flag fuer Modus "Heran zoomen".
176           *           *
# Line 145  public class XMapPane extends JPanel imp Line 178  public class XMapPane extends JPanel imp
178           * @see #setState(int)           * @see #setState(int)
179           */           */
180          public static final int ZOOM_IN = 2;          public static final int ZOOM_IN = 2;
181    
182          /**          /**
183           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
184           *           *
185           * @see #setState(int)           * @see #setState(int)
186           */           */
187          public static final int ZOOM_OUT = 3;          public static final int ZOOM_OUT = 3;
188          /**  
          * Flag fuer Modus  
          * "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer".  
          *  
          * @see #setState(int)  
          * @see #setState(int)  
          */  
         public static final int SELECT_TOP = 4;  
189          /**          /**
190           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".
191           *           *
# Line 174  public class XMapPane extends JPanel imp Line 201  public class XMapPane extends JPanel imp
201           * @see #setState(int)           * @see #setState(int)
202           */           */
203          public static final int SELECT_ONE_FROM_TOP = 104;          public static final int SELECT_ONE_FROM_TOP = 104;
   
204          /**          /**
205           * While threads are working, we call {@link XMapPane#updateFinalImage()}           * Flag fuer Modus
206           * regularly and repaint(). This {@link Timer} is stopped when all renderers           * "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer".
207           * have finished.           *
208           */           * @see #setState(int)
209          final private Timer repainterTimer;           * @see #setState(int)
   
         /**  
          * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,  
          * the {@link #repainterTimer} is regularly updating the {@link #finalImage}  
          * with previews.  
          */  
         public static final long REPEATING_REPAINT_DELAY = 500;  
           
         /**  
          * The initial delay in milliseconds until the {@link #finalImage} is updated the first time.    
          */  
         public static final long INITIAL_REPAINT_DELAY = 1000;  
   
         protected RenderingExecutor bgExecuter;  
   
         /**  
          * the map context to render  
          */  
         MapContext localContext;  
         /**  
          * the map context to render  
          */  
         MapContext bgContext;  
   
         /**  
          * the area of the map to draw  
          */  
         protected Envelope mapArea = null;  
         /**  
          * We store the old mapArea for a moment to use it for the  
          * "quick scaled preview" in case of ZoomOut  
          **/  
         protected Envelope oldMapArea = null;  
   
         /**  
          * the size of the pane last time we drew  
210           */           */
211          protected Rectangle oldRect = null;          public static final int SELECT_TOP = 4;
212    
213          /**          /**
214           * The Renderer for the Background uses this Image. When set to null, please           * {@link Font} used to paint the wait messages into the map
215           * dispose the {@link Graphics2D}           *
216             * @see #addGadgets(Graphics2D, boolean)
217           */           */
218          protected BufferedImage bgImage;          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
219    
220          /**          /**
221           * The Renderer for the LocalLayers uses this Image. When set to null,           * {@link Font} used to paint error messages into the map
222           * please dispose this {@link Graphics2D}           *
223             * @see #addGadgets(Graphics2D, boolean)
224           */           */
225          volatile protected BufferedImage localImage;          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
226    
227          /**          /**
228           * compass and icon are rendered into this image           * The wait message painted into the map while rendering is going on on
229             * another thread.
230             *
231             * @see #addGadgets(Graphics2D, boolean)
232           */           */
233          // protected BufferedImage gadgetsImage;          final String waitMsg = SwingUtil.R("WaitMess");
   
         /**  
          * The default state is ZOOM_IN, hence by default the  
          * {@link #zoomMapPaneMouseListener} is also enabled.  
          **/  
         private int state = ZOOM_IN;  
234    
235          /**          /**
236           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in
# Line 250  public class XMapPane extends JPanel imp Line 239  public class XMapPane extends JPanel imp
239           * @param e           * @param e
240           *            Maus-Ereignis           *            Maus-Ereignis
241           */           */
242          public static Point2D getMapCoordinatesFromEvent(MouseEvent e) {          public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {
243                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln
244                  if (e != null && e instanceof MapMouseEvent)                  if (e != null && e instanceof MapMouseEvent)
245                          try {                          try {
246                                  return ((MapMouseEvent) e).getMapPosition().toPoint2D();                                  return ((MapMouseEvent) e).getMapPosition().toPoint2D();
247                          } catch (Exception err) {                          } catch (final Exception err) {
248                                  LOGGER                                  LOGGER
249                                                  .error(                                                  .error(
250                                                                  "return ((GeoMouseEvent) e).getMapCoordinate(null).toPoint2D();",                                                                  "return ((GeoMouseEvent) e).getMapCoordinate(null).toPoint2D();",
# Line 270  public class XMapPane extends JPanel imp Line 259  public class XMapPane extends JPanel imp
259                          if (!xMapPane.isWellDefined())                          if (!xMapPane.isWellDefined())
260                                  return null;                                  return null;
261    
262                          AffineTransform at = xMapPane.getScreenToWorld();                          final AffineTransform at = xMapPane.getScreenToWorld();
263                          if (at != null)                          if (at != null)
264                                  return at.transform(e.getPoint(), null);                                  return at.transform(e.getPoint(), null);
265                          return null;                          return null;
# Line 280  public class XMapPane extends JPanel imp Line 269  public class XMapPane extends JPanel imp
269          }          }
270    
271          /**          /**
272             * Listens to changes of the "background" {@link MapContext} and triggers
273             * repaints where needed.
274             */
275            private final MapLayerListListener bgContextListener = new MapLayerListListener() {
276    
277                    @Override
278                    public void layerAdded(final MapLayerListEvent event) {
279                            MapLayer layer = event.getLayer();
280                            layer.addMapLayerListener(bgMapLayerListener);
281                            requestStartRendering();
282    
283                    }
284    
285                    @Override
286                    public void layerChanged(final MapLayerListEvent event) {
287                            requestStartRendering();
288                    }
289    
290                    @Override
291                    public void layerMoved(final MapLayerListEvent event) {
292                            requestStartRendering();
293                    }
294    
295                    @Override
296                    public void layerRemoved(final MapLayerListEvent event) {
297                            if (event.getLayer() != null)
298                                    event.getLayer().removeMapLayerListener(bgMapLayerListener);
299                            requestStartRendering();
300                    }
301            };
302    
303            /**
304             * This {@link RenderingExecutor} manages the creation and cancellation of
305             * up to one {@link Thread} for rendering the {@link #localContext}.
306             */
307            private final RenderingExecutor localExecuter = new RenderingExecutor(this);
308    
309            /**
310             * This {@link RenderingExecutor} manages the creation and cancellation of
311             * up to one {@link Thread} for rendering the {@link #bgContext}.
312             */
313            protected RenderingExecutor bgExecuter;
314    
315            /**
316             * The {@link #localRenderer} for the {@link #localContext} uses this
317             * {@link Image}.
318             */
319            private BufferedImage localImage;
320    
321            /**
322             * The {@link #bgRenderer} for the {@link #bgContext} uses this
323             * {@link Image}.
324             */
325            private BufferedImage bgImage;
326    
327            /**
328             * This {@link Image} is a merge of the {@link #bgImage},
329             * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
330             * updated with {@link #updateFinalImage()} and used for painting in
331             * {@link #paintComponent(Graphics)}
332             */
333            private BufferedImage finalImage;
334    
335            /**
336             * Optionally a transparent image to paint over the map in the lower right
337             * corner.
338             *
339             * @see #addGadgets(Graphics2D)
340             * @see #setMapImage(BufferedImage)
341             **/
342            private BufferedImage mapImage = null;
343    
344            /**
345             * Listens to each layer in the local {@link MapContext} for changes and
346             * triggers repaints.
347             */
348            protected MapLayerListener bgMapLayerListener = new MapLayerAdapter() {
349    
350                    @Override
351                    public void layerChanged(final MapLayerEvent event) {
352                            requestStartRendering();
353                    }
354    
355                    @Override
356                    public void layerHidden(final MapLayerEvent event) {
357                            requestStartRendering();
358                    }
359    
360                    @Override
361                    public void layerShown(final MapLayerEvent event) {
362                            requestStartRendering();
363                    }
364            };
365    
366            /**
367             * A flag indicating if dispose() was already called. If true, then further
368             * use of this {@link SelectableXMapPane} is undefined.
369             */
370            private boolean disposed = false;
371    
372            /**
373             * While dragging, the {@link #updateFinalImage()} method is translating the
374             * cached images while setting it together.
375             **/
376            Point imageOrigin = new Point(0, 0);
377            /**
378             * 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             * {@link GTRenderer}. The java2dHints are the same for all renderers (bg
382             * and local).
383             */
384            private RenderingHints java2dHints;
385    
386            protected LabelCache labelCache = new LabelCacheImpl();
387    
388            /**
389             * Listens to changes of the "local" {@link MapContext} and triggers
390             * repaints where needed.
391             */
392            private final MapLayerListListener localContextListener = new MapLayerListListener() {
393    
394                    @Override
395                    public void layerAdded(final MapLayerListEvent event) {
396                            event.getLayer().addMapLayerListener(localMapLayerListener);
397    
398                            localRenderer.setContext(getMapContext());
399                            requestStartRendering();
400    
401                    }
402    
403                    @Override
404                    public void layerChanged(final MapLayerListEvent event) {
405                            localRenderer.setContext(getMapContext());
406                            requestStartRendering();
407                    }
408    
409                    @Override
410                    public void layerMoved(final MapLayerListEvent event) {
411                            localRenderer.setContext(getMapContext());
412                            requestStartRendering();
413                    }
414    
415                    @Override
416                    public void layerRemoved(final MapLayerListEvent event) {
417                            if (event.getLayer() != null)
418                                    event.getLayer().removeMapLayerListener(localMapLayerListener);
419                            localRenderer.setContext(getMapContext());
420                            requestStartRendering();
421                    }
422            };
423    
424            /**
425             * Listens to each layer in the local {@link MapContext} for changes and
426             * triggers repaints.
427             */
428            protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
429    
430                    @Override
431                    public void layerChanged(final MapLayerEvent event) {
432                            localRenderer.setContext(getMapContext()); // betters for SLD
433                            // changes?!
434                            requestStartRendering();
435                    }
436    
437                    @Override
438                    public void layerHidden(final MapLayerEvent event) {
439                            requestStartRendering();
440                    }
441    
442                    @Override
443                    public void layerShown(final MapLayerEvent event) {
444                            requestStartRendering();
445                    }
446            };
447    
448            private final GTRenderer localRenderer = GTUtil.createGTRenderer();
449    
450            private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
451    
452            /**
453             * the area of the map to draw
454             */
455            protected Envelope mapArea = null;
456    
457            /**
458             * A flag set it {@link #setMapArea(Envelope)} to indicated the
459             * {@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             * The flag is reset
463             **/
464            private boolean mapAreaChanged = false;
465    
466            /**
467             * This color is used as the default background color when painting a map.
468             */
469            private Color mapBackgroundColor = Color.WHITE;
470    
471            /**
472           * A flag indicating that the shown image is invalid and needs to be           * A flag indicating that the shown image is invalid and needs to be
473           * re-rendered.           * re-rendered.
474           */           */
475          protected boolean mapImageInvalid = true;          protected boolean mapImageInvalid = true;
476    
477          protected LabelCache labelCache = new LabelCacheImpl();          /**
478             * 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             * actions.
481             */
482            final protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
483    
484          /**          /**
485             * List of listeners of this {@link XMapPane}
486             */
487            protected Vector<JMapPaneListener> mapPaneListeners = new Vector<JMapPaneListener>();
488            /**
489           * If not <code>null</code>, the {@link XMapPane} will not allow to zoom/pan           * If not <code>null</code>, the {@link XMapPane} will not allow to zoom/pan
490           * out of that area           * out of that area
491           **/           **/
492          private Envelope maxExtend = null;          private Envelope maxExtend = null;
   
493          private Double maxZoomScale = Double.MIN_VALUE;          private Double maxZoomScale = Double.MIN_VALUE;
494    
495          private Double minZoomScale = Double.MAX_VALUE;          private Double minZoomScale = Double.MAX_VALUE;
496    
497          /**          /**
498           * This color is used as the default background color when painting a map.           * We store the old mapArea for a moment to use it for the
499           */           * "quick scaled preview" in case of ZoomOut
500          private Color mapBackgroundColor = Color.WHITE;           **/
501            protected Envelope oldMapArea = null;
502    
503          /**          /**
504           * This {@link MouseListener} is managing all zoom related tasks           * We store the old transform for a moment to use it for the
505           */           * "quick scaled preview" in case of ZoomIn
506          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(           **/
507                          this);          protected AffineTransform oldScreenToWorld = null;
508    
509          /**          /**
510           * A flag indicating, that the image size has changed and the buffered           * A flag indicating, that the image size has changed and the buffered
511           * images are not big enough any more           * images are not big enough any more
512           **/           **/
513          protected boolean paneResized = false;          protected boolean paneResized = true;
514    
515            private BufferedImage preFinalImage;
516    
517            // ** if 0, no quick preview will be shown **/
518            private int quickPreviewHint = 0;
519    
520            private Map<Object, Object> rendererHints = GTUtil
521                            .getDefaultGTRendererHints(localRenderer);
522    
523            /**
524             * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
525             * start rendering {@link Thread}s
526             **/
527            private volatile Boolean requestStartRendering = false;
528    
529            /**
530             * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
531             * (lat/lon)
532             */
533            protected AffineTransform screenToWorld = null;
534    
535          /**          /**
536           * The flag {@link #requestStartRendering} can be set to true by events.           * The flag {@link #requestStartRendering} can be set to true by events.
# Line 320  public class XMapPane extends JPanel imp Line 539  public class XMapPane extends JPanel imp
539           */           */
540          final private Timer startRenderThreadsTimer;          final private Timer startRenderThreadsTimer;
541    
542          private Map<Object, Object> rendererHints;          /**
543             * The default state is ZOOM_IN, hence by default the
544             * {@link #zoomMapPaneMouseListener} is also enabled.
545             **/
546            private int state = ZOOM_IN;
547    
548          public Map<Object, Object> getRendererHints() {          /**
549                  return rendererHints;           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
550          }           * MapPane-Funktion
551             */
552            protected Cursor staticCursor = null;
553    
554            private AffineTransform worldToScreen;
555    
556          /**          /**
557           * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht           * This {@link MouseListener} is managing all zoom related tasks
          * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.  
          *  
          * @author <a href="mailto:[email protected]">Stefan Alfons  
          *         Kr&uuml;ger</a>  
558           */           */
559          @Override          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(
560          public void print(Graphics g) {                          this);
                 Color orig = getBackground();  
                 setBackground(Color.WHITE);  
561    
562                  // wrap in try/finally so that we always restore the state          /** Is set if a renderer has an error **/
563                  try {          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
564                          super.print(g);  
565                  } finally {          /**
566                          setBackground(orig);           * If <code>true</code>, then rendering exceptions are rendererd into the
567                  }           * map pane
568             **/
569            private boolean showExceptions = false;
570    
571            public XMapPane() {
572                    this(null, null);
573          }          }
574    
575          /**          /**
576           * full constructor extending JPanel           * full constructor extending JPanel
577           *           *
578           * @param rendererHints           * @param rendererHints
579             *            may be <code>null</code>. Otherwise a {@link Map<Object,
580             *            Object>} of {@link RenderingHints} to override the default
581             *            from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)}
582           *           *
          * @param layout  
          *            - layout (probably shouldn't be set)  
          * @param isDoubleBuffered  
          *            - a Swing thing I don't really understand  
          * @param render  
          *            - what to draw the map with  
583           * @param localContext           * @param localContext
584           *            - {@link MapContext} of layer to render.           *            The main {@link MapContext} to use. If <code>null</code>, an
585             *            empty {@link DefaultMapContext} will be created.
586           */           */
587          public XMapPane(final MapContext localContext,          public XMapPane(final MapContext localContext_,
588                          Map<Object, Object> rendererHints) {                          final Map<Object, Object> rendererHints) {
589                  super(true);                  super(true);
590    
591                  setRendererHints(rendererHints);                  setRendererHints(rendererHints);
592    
593                  setOpaque(true);                  setOpaque(true);
594    
595                  setLocalContext(localContext);                  if (localContext_ != null)
596                            setLocalContext(localContext_);
597    
598                  /**                  /**
599                   * Adding the #zoomMapPaneMouseListener                   * Adding the #zoomMapPaneMouseListener
# Line 384  public class XMapPane extends JPanel imp Line 609  public class XMapPane extends JPanel imp
609                   * Using a ComponentListener doesn't work because, unlike a JFrame, the                   * Using a ComponentListener doesn't work because, unlike a JFrame, the
610                   * pane receives a stream of events during drag-resizing.                   * pane receives a stream of events during drag-resizing.
611                   */                   */
612                  resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY;                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
613                  resizeTimer = new Timer(resizingPaintDelay, new ActionListener() {                                  new ActionListener() {
614    
615                          public void actionPerformed(ActionEvent e) {                                          public void actionPerformed(final ActionEvent e) {
616                                  paneResized = true;                                                  if (!isWellDefined())
617                                                            return;
618    
619                                                    LOGGER.info("resizeTimer performed");
620    
621                                                    final Rectangle bounds = getVisibleRect();
622                                                    //
623                                                    // System.out.println("\n\ntimer performs with bounds = "
624                                                    // + bounds);
625    
626                                                    final Envelope geoMapArea = tranformWindowToGeo(
627                                                                    bounds.x, bounds.y, bounds.x + bounds.width,
628                                                                    bounds.y + bounds.height);
629    
630                                                    if (setMapArea(geoMapArea)) {
631                                                            LOGGER.info("  maparea changed");
632                                                            paneResized = true;
633                                                    } else
634                                                            LOGGER.info("  maparea NOT changed");
635                                            }
636                                    });
637                    resizeTimer.setRepeats(false);
638    
639                                  if (!isWellDefined())                  this.addComponentListener(new ComponentAdapter() {
                                         return;  
640    
641                                  Rectangle bounds = getVisibleRect();                          private Rectangle oldVisibleRect;
642    
643                                  Envelope geoMapArea = tranformWindowToGeo(bounds.x, bounds.y,                          @Override
644                                                  bounds.x + bounds.width, bounds.y + bounds.height);                          public void componentResized(final ComponentEvent e) {
645    
646                                  setMapArea(bestAllowedMapArea(geoMapArea));                                  // Seems to be called twice with the same size..
647                          }                                  if (oldVisibleRect != null
648                  });                                                  && oldVisibleRect.equals(getVisibleRect())){
649                  resizeTimer.setRepeats(false);                                          LOGGER.info("skipping resize.");
650                  this.addComponentListener(new ComponentAdapter() {                                          return;
651                                    }
652    
653                          @Override                                  LOGGER.info("resized: " + getVisibleRect());
                         public void componentResized(ComponentEvent e) {  
                                 if (bgExecuter != null)  
                                         bgExecuter.cancelTask();  
                                 if (localExecuter != null)  
                                         localExecuter.cancelTask();  
654                                  resizeTimer.restart();                                  resizeTimer.restart();
655                                    oldVisibleRect = getVisibleRect();
656                          }                          }
657    
658                  });                  });
659    
660                  repainterTimer = new Timer((int) REPEATING_REPAINT_DELAY,                  /*
661                                  new ActionListener() {                   * Setting up the repaintTimer. Not started automatically.
662                     */
663                    repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
664    
665                                          @Override                          @Override
666                                          public void actionPerformed(ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
667                                                  updateFinalImage();                                  if ((!localExecuter.isRunning())
668                                                  XMapPane.this.repaint();                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {
669                                          }                                          repaintTimer.stop();
670                                  });                                  } else {
671                  repainterTimer.setInitialDelay(300);                                          updateFinalImage();
672                  repainterTimer.setRepeats(true);                                          XMapPane.this.repaint(100);
673    
674                                    }
675                            }
676                    });
677    
678                    repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
679                    repaintTimer.setRepeats(true);
680    
681                    /*
682                     * Setting up the startRenderThreadsTimer. This Timer starts
683                     * automatically.
684                     */
685                  startRenderThreadsTimer = new Timer(100, new ActionListener() {                  startRenderThreadsTimer = new Timer(100, new ActionListener() {
686    
687                          @Override                          @Override
688                          public void actionPerformed(ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
689                                  synchronized (requestStartRendering) {                                  synchronized (requestStartRendering) {
690                                          if (requestStartRendering && isWellDefined()) {                                          if (requestStartRendering && isWellDefined()) {
691                                                    
692                                                  if (localExecuter.isRunning()){                                                  if (localExecuter.isRunning()) {
693                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
694                                                  } else {                                                  } else {
695                                                            // Stupidly, but we have to recheck the
696                                                            setMapArea(getMapArea());
697                                                          requestStartRendering = false;                                                          requestStartRendering = false;
698                                                          startRendering();                                                          startRendering();
699                                                  }                                                  }
# Line 448  public class XMapPane extends JPanel imp Line 705  public class XMapPane extends JPanel imp
705    
706          }          }
707    
708          // TODO doku          /**
709          public XMapPane() {           * Fuegt der Map einen Listener hinzu.
710                  this(null, null);           *
711             * @param l
712             *            neuer Listener
713             */
714            public void addMapPaneListener(final JMapPaneListener l) {
715                    mapPaneListeners.add(l);
716          }          }
717    
718          /**          /**
719           * Sets the mapArea to best possibly present the given features. If only one           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
720           * single point is given, the window is moved over the point.           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
721           *           * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br>
722           * Note: The method does not call {@link #repaint()} on the           * Since 21. April 09: Before thecalculation starts, the aspect ratio is
723           * {@link SelectableXMapPane} .           * corrected. This change implies, that setMapArea() will most of the time
724             * not allow setting to a wrong aspectRatio.
725           *           *
726           * @param features           * @author <a href="mailto:[email protected]">Stefan Alfons
727           *            if <code>null</code> or size==0, the function doesn nothing.           *         Kr&uuml;ger</a>
728           */           */
729          public void zoomTo(          public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
                         FeatureCollection<SimpleFeatureType, SimpleFeature> features) {  
730    
731                  CoordinateReferenceSystem mapCRS = getContext()                  if (getWidth() == 0)
732                                  .getCoordinateReferenceSystem();                          return env;
                 CoordinateReferenceSystem fCRS = features.getSchema()  
                                 .getGeometryDescriptor().getCoordinateReferenceSystem();  
733    
734                  double width = mapArea.getWidth();                  if (env == null)
735                  double height = mapArea.getHeight();                          return null;
                 double ratio = height / width;  
736    
737                  if (features == null || features.size() == 0) {                  Envelope newArea = null;
                         // feature count == 0 Zoom to the full extend  
                         return;  
                 } else if (features.size() == 1) {  
738    
739                          // feature count == 1 Just move the window to the point and zoom 'a                  /**
740                          // bit'                   * Correct the aspect Ratio before we check the rest. Otherwise we might
741                          SimpleFeature singleFeature = (SimpleFeature) features.iterator()                   * easily fail. We allow to grow here, because we don't check against
742                                          .next();                   * the maxExtend
743                     */
744                    final Rectangle curPaintArea = getVisibleRect();
745    
746                          if (((Geometry) singleFeature.getDefaultGeometry())                  env = JTSUtil.fixAspectRatio(curPaintArea, env, true);
747                                          .getCoordinates().length > 1) {  
748                                  // System.out.println("Zoomed to only pne poylgon");                  final double scale = env.getWidth() / getWidth();
749                                  // Poly                  final double centerX = env.getMinX() + env.getWidth() / 2.;
750                                  // TODO max width vs. height                  final double centerY = env.getMinY() + env.getHeight() / 2.;
751                                  width = features.getBounds().getWidth() * 3;                  double newWidth2 = 0;
752                                  height = ratio * width;                  double newHeight2 = 0;
753                          } else {                  if (scale < getMaxZoomScale()) {
754                                  // System.out.println("Zoomed in a bit becasue only one point");                          // ****************************************************************************
755                                  // width *= .9;                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
756                                  // height *= .9;                          // ****************************************************************************
757                            newWidth2 = getMaxZoomScale() * getWidth() / 2.;
758                            newHeight2 = getMaxZoomScale() * getHeight() / 2.;
759                    } else if (scale > getMinZoomScale()) {
760                            // ****************************************************************************
761                            // Wir zoomen weiter raus als erlaubt => Anpassen des envelope
762                            // ****************************************************************************
763                            newWidth2 = getMinZoomScale() * getWidth() / 2.;
764                            newHeight2 = getMinZoomScale() * getHeight() / 2.;
765                    } else {
766                            // ****************************************************************************
767                            // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
768                            // ****************************************************************************
769                            newArea = env;
770                    }
771    
772                    if (newArea == null) {
773    
774                            final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
775                                            - newHeight2);
776                            final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
777                                            + newHeight2);
778    
779                            newArea = new Envelope(ll, ur);
780                    }
781    
782                    final Envelope maxAllowedExtend = getMaxExtend();
783    
784                    while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
785                                    && newArea != null && !newArea.isNull()
786                                    && !Double.isNaN(newArea.getMinX())
787                                    && !Double.isNaN(newArea.getMaxX())
788                                    && !Double.isNaN(newArea.getMinY())
789                                    && !Double.isNaN(newArea.getMaxY())) {
790                            /*
791                             * If a maxExtend is set, we have to honour that...
792                             */
793    
794                            // Exceeds top? Move down and maybe cut
795                            if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
796                                    final double divY = newArea.getMaxY()
797                                                    - maxAllowedExtend.getMaxY();
798                                    // LOGGER.debug("Moving area down by " + divY);
799    
800                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
801                                                    newArea.getMinY() - divY), new Coordinate(newArea
802                                                    .getMaxX(), newArea.getMaxY() - divY));
803    
804                                    if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
805                                            // LOGGER.debug("Now it exeeds the bottom border.. cut!");
806                                            // And cut the bottom if it moved out of the area
807                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
808                                                            maxAllowedExtend.getMinY()), new Coordinate(newArea
809                                                            .getMaxX(), newArea.getMaxY()));
810    
811                                            // LOGGER.debug("and fix aspect ratio");
812    
813                                            newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
814                                                            new ReferencedEnvelope(newArea, env
815                                                                            .getCoordinateReferenceSystem()), false);
816                                    }
817                          }                          }
818    
819                          Coordinate centre = features.getBounds().centre();                          // Exceeds bottom? Move up and maybe cut
820                          if (!mapCRS.equals(fCRS)) {                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
821                                  // only to calculations if the CRS differ                                  final double divY = newArea.getMinY()
822                                  try {                                                  - maxAllowedExtend.getMinY();
823                                          MathTransform fToMap;                                  // LOGGER.debug("Moving area up by " + divY);
824                                          fToMap = CRS.findMathTransform(fCRS, mapCRS);  
825                                          // centre is transformed to the mapCRS                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
826                                          centre = JTS.transform(centre, null, fToMap);                                                  newArea.getMinY() - divY), new Coordinate(newArea
827                                  } catch (FactoryException e) {                                                  .getMaxX(), newArea.getMaxY() - divY));
828                                          LOGGER.error("Looking for a Math transform", e);  
829                                  } catch (TransformException e) {                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
830                                          LOGGER.error("Looking for a Math transform", e);                                          // 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                                                            .getMaxX(), maxAllowedExtend.getMaxY()));
835    
836                                            // LOGGER.debug("and fix aspect ratio");
837    
838                                            newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
839                                                            new ReferencedEnvelope(newArea, env
840                                                                            .getCoordinateReferenceSystem()), false);
841                                  }                                  }
842                          }                          }
843    
844                          Coordinate newLeftBottom = new Coordinate(centre.x - width / 2.,                          // Exceeds to the right? move and maybe cut
845                                          centre.y - height / 2.);                          if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
                         Coordinate newTopRight = new Coordinate(centre.x + width / 2.,  
                                         centre.y + height / 2.);  
846    
847                          Envelope newMapArea = new Envelope(newLeftBottom, newTopRight);                                  // Move left..
848                                    final double divX = newArea.getMaxX()
849                                                    - maxAllowedExtend.getMaxX();
850                                    // LOGGER.debug("Moving area left by " + divX);
851    
852                          setMapArea(newMapArea);                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
853                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
854                                                    - divX, newArea.getMaxY()));
855    
856                  } else {                                  if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
857                          ReferencedEnvelope fBounds = features.getBounds();                                          // LOGGER.debug("Now it exeeds the left border.. cut!");
858                                            // And cut the left if it moved out of the area
859                                            newArea = new Envelope(new Coordinate(maxAllowedExtend
860                                                            .getMinX(), newArea.getMinY()), new Coordinate(
861                                                            newArea.getMaxX(), newArea.getMaxY()));
862    
863                          Envelope bounds;                                          // LOGGER.debug("and fix aspect ratio");
864                          if (!mapCRS.equals(fCRS)) {  
865                                  bounds = JTSUtil.transformEnvelope(fBounds, fCRS, mapCRS);                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
866                          } else {                                                          new ReferencedEnvelope(newArea, env
867                                  bounds = fBounds;                                                                          .getCoordinateReferenceSystem()), false);
868                                    }
869                          }                          }
                         // BB umrechnen von Layer-CRS in Map-CRS  
870    
871                          // Expand a bit                          // Exceeds to the left? move and maybe cut
872                          bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.);                          if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
873    
874                          setMapArea(bounds);                                  // Move right..
875                                    final double divX = newArea.getMinX()
876                                                    - maxAllowedExtend.getMinX();
877                                    // LOGGER.debug("Moving area right by " + divX);
878    
879                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
880                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
881                                                    - divX, newArea.getMaxY()));
882    
883                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
884                                            // LOGGER.debug("Now it exeeds the right border.. cut!");
885                                            // And cut the left if it moved out of the area
886                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
887                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
888                                                            .getMaxX(), newArea.getMaxY()));
889    
890                                            // LOGGER.debug("and fix aspect ratio");
891    
892                                            newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
893                                                            new ReferencedEnvelope(newArea, env
894                                                                            .getCoordinateReferenceSystem()), false);
895                                    }
896                            }
897                  }                  }
         }  
898    
899          private void setRendererHints(Map<Object, Object> rendererHints) {                  return new ReferencedEnvelope(newArea, env
900                  this.rendererHints = rendererHints;                                  .getCoordinateReferenceSystem());
901          }          }
902    
903          /**          /**
904           * Return <code>true</code> if a CRS and a {@link #mapArea} are set and the           * Should be called when the {@link JMapPane} is not needed no more to help
905           * {@link XMapPane} is visible and has bounds set.           * the GarbageCollector
906             *
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           */           */
912          public boolean isWellDefined() {          public void dispose() {
913                    if (isDisposed())
914                            return;
915    
916                  try {                  setPainting(false);
917    
918                          if (getContext() == null)                  resizeTimer.stop();
919                                  return false;                  startRenderThreadsTimer.stop();
920                          if (getContext().getLayerCount() <= 0)  
921                                  return false;                  disposed = true;
922                          if (getMapArea() == null)  
923                                  return false;                  if (bgExecuter != null) {
924                          if (getBounds().getWidth() == 0)                          bgExecuter.cancelTask();
925                                  return false;                          bgExecuter.dispose();
                         if (getBounds().getHeight() == 0)  
                                 return false;  
                 } catch (Exception e) {  
                         return false;  
926                  }                  }
                 return true;  
         }  
927    
928          /**                  if (localExecuter.isRunning()) {
929           * Default delay (milliseconds) before the map will be redrawn when resizing                          int i = 0;
930           * the pane. This is to avoid flickering while drag-resizing.                          localExecuter.cancelTask();
931           */                          while (i++ < 10 && localExecuter.isRunning()) {
932          public static final int DEFAULT_RESIZING_PAINT_DELAY = 500; // delay in                                  try {
933          // milliseconds                                          Thread.sleep(200);
934                                    } catch (final InterruptedException e) {
935                                            LOGGER
936                                                            .warn(
937                                                                            "while XMapPane we are waiting for the localExcutor to stop",
938                                                                            e);
939                                    }
940                            }
941                            if (localExecuter.isRunning()) {
942                                    LOGGER
943                                                    .warn("localExecutor Thread still running after 2s! Continuing anyways...");
944                            }
945                            localExecuter.dispose();
946                    }
947    
948          private Timer resizeTimer;                  disposeImages();
         private int resizingPaintDelay;  
         /**  
          * We store the old transform for a moment to use it for the  
          * "quick scaled preview" in case of ZoomIn  
          **/  
         protected AffineTransform oldScreenToWorld = null;  
949    
950          /**                  // Remove all mapPaneListeners that have registered with us
951           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen                  mapPaneListeners.clear();
          * MapPane-Funktion  
          */  
         protected Cursor staticCursor = null;  
952    
953          /**                  removeMouseMotionListener(zoomMapPaneMouseListener);
954           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,                  removeMouseListener(zoomMapPaneMouseListener);
          * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor  
          * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion  
          * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann  
          * {@code null} als Parameter uebergeben werden  
          *  
          * @param cursor  
          *            Cursor  
          */  
         public void setStaticCursor(Cursor cursor) {  
                 this.staticCursor = cursor;  
                 if (cursor != null)  
                         super.setCursor(cursor);  
         }  
955    
956          /**                  if (localContext != null)
957           * Liefert den statisch eingestellten Cursor, der unabhaengig von der                          getMapContext().clearLayerList();
958           * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.                  if (bgContext != null)
959           *                          getBgContext().clearLayerList();
960           * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der  
961           *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.                  removeAll();
          */  
         public Cursor getStaticCursor() {  
                 return this.staticCursor;  
962          }          }
963    
964          /**          /**
965           * Abhaengig von selState wird der Cursor gesetzt           * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
966             * given point. All in screen coordinates.
967           */           */
968          public void updateCursor() {          protected void drawRectangle(final Graphics graphics, final Point startPos,
969                            final Point e) {
970    
971                  if (bgExecuter != null && bgExecuter.isRunning()                  if (!isWellDefined())
                                 || localExecuter != null && localExecuter.isRunning()) {  
                         setCursor(WAIT_CURSOR);  
972                          return;                          return;
                 } else {  
                         // Allow one last rendering  
                         if (repainterTimer.isRunning()) {  
                                 repainterTimer.stop();  
                                 updateFinalImage();  
                                 repaint();  
                         }  
                 }  
973    
974                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig                  // undraw last box/draw new box
975                  // von der aktuellen Aktion                  final int left = Math.min(startPos.x, e.x);
976                  if (this.staticCursor != null) {                  final int right = Math.max(startPos.x, e.x);
977                          setCursor(staticCursor);                  final int top = Math.max(startPos.y, e.y);
978                          return;                  final int bottom = Math.min(startPos.y, e.y);
979                  }                  final int width = right - left;
980                  if (getCursor() == SwingUtil.PANNING_CURSOR) {                  final int height = top - bottom;
981                          // This cursor will reset itself  
982                    if (width == 0 && height == 0)
983                          return;                          return;
                 }  
984    
985                  // Je nach Aktion den Cursor umsetzen                  graphics.setXORMode(Color.WHITE);
986                  switch (state) {                  graphics.drawRect(left, bottom, width, height);
                 case SELECT_TOP:  
                 case SELECT_ONE_FROM_TOP:  
                 case SELECT_ALL:  
                         setCursor(SwingUtil.CROSSHAIR_CURSOR);  
                         break;  
                 case ZOOM_IN:  
                         setCursor(SwingUtil.ZOOMIN_CURSOR);  
                         break;  
                 case ZOOM_OUT:  
                         setCursor(SwingUtil.ZOOMOUT_CURSOR);  
                         break;  
                 case PAN:  
                         setCursor(SwingUtil.PAN_CURSOR);  
                         break;  
                 default:  
                         setCursor(normalCursor);  
                         break;  
                 }  
987          }          }
988    
         //  
         // /**  
         // * Gibt den "normalen" Cursor zurueck. Dieser kann neben dem "pointer"  
         // auch  
         // * ein Sanduhr-Wartecursor sein.  
         // *  
         // * @author <a href="mailto:[email protected]">Stefan Alfons  
         // * Kr&uuml;ger</a>  
         // */  
         // public Cursor getNormalCursor() {  
         // return normalCursor;  
         // }  
         //  
         // /**  
         // * Setzt den "normalen" Cursor. Dieser kann neben dem default "pointer"  
         // z.B.  
         // * auch ein Sanduhr-Wartecursor sein.  
         // *  
         // * @author <a href="mailto:[email protected]">Stefan Alfons  
         // * Kr&uuml;ger</a>  
         // */  
         // public void setNormalCursor(Cursor normalCursor) {  
         // this.normalCursor = normalCursor;  
         // }  
   
989          /**          /**
990           * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten           * Diretly paints scaled preview into the {@link SelectableXMapPane}. Used
991           * neu.           * to give the user something to look at while we are rendering. Method
992             * should be called after {@link #setMapArea(Envelope)} has been set to the
993             * new mapArea and transform has been reset.<br>
994             *
995             * @param g
996             *            Graphics2D to paint the preview into
997             *
998             * @param state
999             *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}
1000           */           */
1001          protected void resetTransforms() {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
                 if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)  
                         return;  
1002    
1003                  // We store the last Transform                  // if (1 == 1)return false;
                 oldScreenToWorld = screenToWorld;  
1004    
1005                  this.screenToWorld = new AffineTransform(                  if (quickPreviewHint == 0)
1006                  // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten                          return false;
                                 // nach rechts (Osten) hin groesser  
                                 // --> positive Verschiebung  
                                 getMapArea().getWidth() / getWidth(),  
                                 // keine Verzerrung  
                                 0.0, 0.0,  
                                 // Waehrend die Fenster-Koordinaten nach unten hin groesser  
                                 // werden,  
                                 // werden Latitude-Koordinaten nach Sueden hin keiner  
                                 // --> negative Verschiebung  
                                 -getMapArea().getHeight() / getHeight(),  
                                 // Die Longitude-Koordinaten werden nach Osten hin groesser  
                                 // --> obere linke Ecke des Fensters hat also den Minimalwert  
                                 getMapArea().getMinX(),  
                                 // Die Latitude-Koordinaten werden nach Norden hin groesser  
                                 // --> obere linke Ecke des Fensters hat also den Maximalwert  
                                 getMapArea().getMaxY());  
1007    
1008                  try {                  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1009                          this.worldToScreen = screenToWorld.createInverse();                                  RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1010                  } catch (NoninvertibleTransformException e) {                  graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1011                          LOGGER.error(e);                                  RenderingHints.VALUE_ANTIALIAS_OFF);
1012                  }                  graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1013          }                                  RenderingHints.VALUE_RENDER_SPEED);
1014    
1015          /**                  if (oldMapArea == null)
1016           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten                          return false;
          * (lat/lon)  
          */  
         protected AffineTransform screenToWorld = null;  
1017    
1018          private AffineTransform worldToScreen;                  final Rectangle visibleArea = getVisibleRect();
1019    
1020          /**                  // Calculate the oldMapArea in the current WindowCoordinates:
1021           * Listens to changes of the "local" {@link MapContext} and triggers                  final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),
1022           * repaints where needed.                                  oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea
1023           */                                                  .getMaxY());
         private MapLayerListListener localContextListener = new MapLayerListListener() {  
1024    
1025                  @Override                  final int xx1 = (int) Math.round(oldMapWindow.getMinX());
1026                  public void layerAdded(final MapLayerListEvent event) {                  final int yy1 = (int) Math.round(oldMapWindow.getMinY());
1027                          event.getLayer().addMapLayerListener(localMapLayerListener);                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1028                    final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1029    
1030                          if (localContext.getLayers().length == 1) { // the first one                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1031                                  // if the Area of Interest is unset, the LayerBounds are used                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1032                                  if (!setMapArea(localContext.getAreaOfInterest()))                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
1033                                          repaint();                                  getMapBackgroundColor(), null);
1034    
1035                                  return;                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1036                          }                                  - yy1);
1037    
1038                          // We need to redraw, even in case that the mapArea didn't change                  SwingUtil.clearAround(graphics, painedArea, visibleArea);
                         // mapImageInvalid = true;  
                         // repaint();  
                         requestStartRendering();  
1039    
1040                  }                  addGadgets(graphics, true);
1041    
1042                  @Override                  quickPreviewHint = 0;
                 public void layerRemoved(final MapLayerListEvent event) {  
                         if (event.getLayer() != null)  
                                 event.getLayer().removeMapLayerListener(localMapLayerListener);  
                         // mapImageInvalid = true;  
                         // repaint();  
                         requestStartRendering();  
                 }  
1043    
1044                  @Override                  repaintTimer.restart();
1045                  public void layerChanged(final MapLayerListEvent event) {  
1046                          // mapImageInvalid = true;                  graphics.dispose();
1047                          // repaint();  
1048                          requestStartRendering();                  // Something has been drawn
1049                    return true;
1050            }
1051    
1052            public MapContext getBgContext() {
1053                    return bgContext;
1054            }
1055    
1056            /**
1057             * Lazyly initializes a {@link BufferedImage} for the background renderer.
1058             */
1059            private Image getBgImage() {
1060                    //
1061                    // if (bgImage == null) {
1062                    // bgImage = createImage(getBounds().width, getBounds().height);
1063                    // }
1064    
1065                    return bgImage;
1066            }
1067    
1068            public MapContext getMapContext() {
1069                    if (localContext == null) {
1070                            setLocalContext(new DefaultMapContext());
1071                  }                  }
1072                    return localContext;
1073            }
1074    
1075            private BufferedImage getFinalImage() {
1076                    //
1077                    if (finalImage == null) {
1078                            // Rectangle curPaintArea = getVisibleRect();
1079                            finalImage = new BufferedImage(getVisibleRect().width,
1080                                            getVisibleRect().height, IMAGETYPE);
1081    
                 @Override  
                 public void layerMoved(final MapLayerListEvent event) {  
                         // mapImageInvalid = true;  
                         // repaint();  
1082                          requestStartRendering();                          requestStartRendering();
1083                  }                  }
1084          };                  return finalImage;
1085            }
1086    
1087            public RenderingHints getJava2dHints() {
1088                    return java2dHints;
1089            }
1090    
1091          /**          /**
1092           * Listens to changes of the "background" {@link MapContext} and triggers           * Lazyly initializes a {@link BufferedImage} for the background renderer.
          * repaints where needed.  
1093           */           */
1094          private MapLayerListListener bgContextListener = new MapLayerListListener() {          private BufferedImage getLocalImage() {
1095    
1096                  @Override                  if (localImage == null) {
1097                  public void layerAdded(final MapLayerListEvent event) {                          localImage = new BufferedImage(getVisibleRect().width,
1098                          event.getLayer().addMapLayerListener(bgMapLayerListener);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1099                    }
1100    
1101                          if (localContext.getLayers().length == 0                  return localImage;
1102                                          && bgContext.getLayers().length == 1) { // the first one and          }
1103                                  // localContext is  
1104                                  // empty          /**
1105                                  if (!setMapArea(localContext.getAreaOfInterest()))           * Returns a copy of the mapArea
1106                                          requestStartRendering();           *
1107                                  return;           * @return
1108             */
1109            public ReferencedEnvelope getMapArea() {
1110                    if (mapArea == null) {
1111                            ReferencedEnvelope mapArea_ = null;
1112                            try {
1113                                    mapArea_ = localContext.getLayerBounds();
1114                            } catch (final IOException e) {
1115                                    LOGGER.warn("localContext.getLayerBounds()", e);
1116                          }                          }
1117    
1118                          // We need to redraw, even in case that the mapArea didn't change                          if (mapArea_ == null && bgContext != null) {
1119                          // mapImageInvalid = true;                                  try {
1120                          // repaint();                                          mapArea_ = bgContext.getLayerBounds();
1121                          requestStartRendering();                                  } catch (final IOException e) {
1122                                            LOGGER.warn("bgContext.getLayerBounds()", e);
1123                                    }
1124                            }
1125    
1126                            if (mapArea_ != null) {
1127                                    mapArea = bestAllowedMapArea(mapArea_);
1128                                    requestStartRendering();
1129                            }
1130                  }                  }
1131    
1132                  @Override                  if (mapArea == null)
1133                  public void layerRemoved(final MapLayerListEvent event) {                          return null;
                         if (event.getLayer() != null)  
                                 event.getLayer().removeMapLayerListener(bgMapLayerListener);  
                         // mapImageInvalid = true;  
                         // repaint();  
                         requestStartRendering();  
                 }  
1134    
1135                  @Override                  // TODO is needed at all, this should go to setMapArea maybe
1136                  public void layerChanged(final MapLayerListEvent event) {                  if (localContext.getCoordinateReferenceSystem() == null)
1137                          // mapImageInvalid = true;                          try {
1138                          // repaint();                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1139                          requestStartRendering();                                                  .getDefaultCRS());
1140                  }                          } catch (Exception e) {
1141                                    throw new RuntimeException("setting context CRS:", e);
1142                            }
1143    
1144                  @Override                  return new ReferencedEnvelope(mapArea, localContext
1145                  public void layerMoved(final MapLayerListEvent event) {                                  .getCoordinateReferenceSystem());
1146                          // mapImageInvalid = true;          }
                         // repaint();  
                         requestStartRendering();  
                 }  
         };  
1147    
1148          /**          /**
1149           * Listens to each layer in the local {@link MapContext} for changes and           * Returns the background {@link Color} of the map pane. Default is white.
1150           * triggers repaints.           **/
1151            public Color getMapBackgroundColor() {
1152                    return mapBackgroundColor;
1153            }
1154    
1155            /**
1156             * Get the BufferedImage to use as a flaoting icon in the lower right
1157             * corner.
1158             *
1159             * @return <code>null</code> if the feature is deactivated.
1160           */           */
1161          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {          public BufferedImage getMapImage() {
1162                    return mapImage;
1163            }
1164    
1165                  @Override          /**
1166                  public void layerShown(MapLayerEvent event) {           * Returns the evelope of the viewable area. The JMapPane will never show
1167                          // mapImageInvalid = true;           * anything outside of this extend. If this has been set to
1168                          // repaint();           * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1169                          requestStartRendering();           * quickly the context's bounds. It it takes to long to determine the
1170                  }           * context bounds, <code>null</code> is returned.
1171             *
1172             * @param maxExtend
1173             *            <code>null</code> to not have this restriction.
1174             */
1175    
1176                  @Override          public Envelope getMaxExtend() {
1177                  public void layerHidden(MapLayerEvent event) {                  if (maxExtend == null) {
1178                          // mapImageInvalid = true;                          // Commented-out because it takes soo much time!
1179                          // repaint();                          //
1180                          requestStartRendering();                          // long start = System.currentTimeMillis();
1181                            // final ReferencedEnvelope layerBounds = GTUtil
1182                            // .getVisibleLayoutBounds(localContext);
1183                            //                      
1184                            // LOGGER.info(
1185                            // (System.currentTimeMillis()-start)+"m to get maxExtend");
1186                            //                      
1187                            // if (layerBounds == null) {
1188                            // // TODO Last fallback could be the CRS valid area
1189                            // return null;
1190                            // }
1191                            //
1192                            // // Kartenbereich um 10% vergroessern
1193                            // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1194                            // .expandEnvelope(layerBounds, 0.1), true);
1195                  }                  }
1196                    return maxExtend;
1197            }
1198    
1199                  @Override          /**
1200                  public void layerChanged(MapLayerEvent event) {           * Retuns the maximum allowed zoom scale. This is the smaller number value
1201                          // Change of SLD for example           * of the two. Defaults to {@link Double}.MIN_VALUE
1202                          // mapImageInvalid = true;           *
1203                          // repaint();           * @author <a href="mailto:[email protected]">Stefan Alfons
1204                          requestStartRendering();           *         Kr&uuml;ger</a>
1205                  }           */
1206          };          public Double getMaxZoomScale() {
1207                    return maxZoomScale;
1208            }
1209    
1210          /**          /**
1211           * Listens to each layer in the local {@link MapContext} for changes and           * Retuns the minimum allowed zoom scale. This is the bigger number value of
1212           * triggers repaints.           * the two. Defaults to {@link Double}.MAX_VALUE
1213             *
1214             * @author <a href="mailto:[email protected]">Stefan Alfons
1215             *         Kr&uuml;ger</a>
1216           */           */
1217          protected MapLayerListener bgMapLayerListener = new MapLayerAdapter() {          public Double getMinZoomScale() {
1218                    return minZoomScale;
1219            }
1220    
1221                  @Override          private Image getPreFinalImage() {
1222                  public void layerShown(MapLayerEvent event) {                  // if (preFinalImage == null) {
1223                          // mapImageInvalid = true;                  //                      
1224                          // repaint();                  // // Rectangle curPaintArea = getVisibleRect();
1225                          requestStartRendering();                  // // preFinalImage = new BufferedImage(curPaintArea.width,
1226                  }                  // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);
1227                    //                      
1228                    // preFinalImage = createImage(getBounds().width, getBounds().height);
1229                    //
1230                    // requestStartRendering();
1231                    // }
1232                    return preFinalImage;
1233            }
1234    
1235                  @Override          public Map<Object, Object> getRendererHints() {
1236                  public void layerHidden(MapLayerEvent event) {                  // Clear label cache
1237                          // mapImageInvalid = true;                  labelCache.clear();
1238                          // repaint();                  rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
                         requestStartRendering();  
                 }  
1239    
1240                  @Override                  return rendererHints;
1241                  public void layerChanged(MapLayerEvent event) {          }
                         // Change of SLD for example  
                         // mapImageInvalid = true;  
                         // repaint();  
                         requestStartRendering();  
                 }  
         };  
1242    
1243          /**          /**
1244           * Liefert eine affine Transformation, um von den Fenster-Koordinaten in die           * Liefert eine affine Transformation, um von den Fenster-Koordinaten in die
# Line 910  public class XMapPane extends JPanel imp Line 1256  public class XMapPane extends JPanel imp
1256                  return new AffineTransform(screenToWorld);                  return new AffineTransform(screenToWorld);
1257          }          }
1258    
1259            public int getState() {
1260                    return state;
1261            }
1262    
1263            /**
1264             * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1265             * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1266             *
1267             * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der
1268             *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1269             */
1270            public Cursor getStaticCursor() {
1271                    return this.staticCursor;
1272            }
1273    
1274          public AffineTransform getWorldToScreenTransform() {          public AffineTransform getWorldToScreenTransform() {
1275                  if (worldToScreen == null) {                  if (worldToScreen == null) {
1276                          resetTransforms();                          resetTransforms();
# Line 918  public class XMapPane extends JPanel imp Line 1279  public class XMapPane extends JPanel imp
1279                  return new AffineTransform(worldToScreen);                  return new AffineTransform(worldToScreen);
1280          }          }
1281    
1282          public MapContext getContext() {          /**
1283                  if (localContext == null) {           * A flag indicating if dispose() has already been called. If true, then
1284                          this.localContext = new DefaultMapContext();           * further use of this {@link SelectableXMapPane} is undefined.
1285                          this.localContext.addMapLayerListListener(localContextListener);           */
1286                  }          private boolean isDisposed() {
1287                  return localContext;                  return disposed;
         }  
   
         public MapContext getBgContext() {  
                 return bgContext;  
1288          }          }
1289    
1290          /**          /**
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           *           *
1295           * @param context           * @param layer
1296             *            a layer
1297           */           */
1298          public void setLocalContext(final MapContext context) {          public boolean isMapLayerSelectable(final MapLayer layer) {
1299                  // Remove the default listener from the old context                  final Boolean selectable = mapLayerSelectable.get(layer);
1300                  if (this.localContext != null) {                  return selectable == null ? true : selectable;
1301                          this.localContext.removeMapLayerListListener(localContextListener);          }
1302    
1303                          // adding listener to all layers          /**
1304                          for (MapLayer mapLayer : localContext.getLayers()) {           * Return <code>true</code> if a CRS and a {@link #mapArea} are set and the
1305                                  mapLayer.removeMapLayerListener(localMapLayerListener);           * {@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                  this.localContext = context;          /**
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 (context != null) {                  if ((getState() == XMapPane.PAN)
1340                          setMapArea(localContext.getAreaOfInterest());                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
1341    
1342                          this.localContext.addMapLayerListListener(localContextListener);                          // Panning needs a panning coursor
1343                            if (getCursor() != SwingUtil.PANNING_CURSOR) {
1344                                    setCursor(SwingUtil.PANNING_CURSOR);
1345    
1346                          // adding listener to all layers                                  // While panning, we deactivate the rendering. So the tasks are
1347                          for (MapLayer mapLayer : localContext.getLayers()) {                                  // ready to start when the panning is finished.
1348                                  mapLayer.addMapLayerListener(localMapLayerListener);                                  if (bgExecuter != null && bgExecuter.isRunning())
1349                                            bgExecuter.cancelTask();
1350                                    if (localExecuter.isRunning())
1351                                            localExecuter.cancelTask();
1352                          }                          }
                 }  
1353    
1354                  mapImageInvalid = true;                          if (lastPos.x > 0 && lastPos.y > 0) {
1355                  repaint();                                  final int dx = event.getX() - lastPos.x;
1356          }                                  final int dy = event.getY() - lastPos.y;
   
         public void setBgContext(final MapContext context) {  
1357    
1358                  // Remove the default listener from the old context                                  // TODO Stop dragging when the drag would not be valid...
1359                  if (this.bgContext != null) {                                  // boolean dragValid = true;
1360                          this.bgContext.removeMapLayerListListener(bgContextListener);                                  // // 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                          // adding listener to all layers                                  imageOrigin.translate(dx, dy);
1390                          for (MapLayer mapLayer : bgContext.getLayers()) {                                  updateFinalImage();
1391                                  mapLayer.removeMapLayerListener(bgMapLayerListener);                                  repaint();
1392                          }                          }
                 }  
   
                 this.bgContext = context;  
1393    
1394                  if (context != null) {                  } else if ((getState() == XMapPane.ZOOM_IN)
1395                          setMapArea(bgContext.getAreaOfInterest());                                  || (getState() == XMapPane.ZOOM_OUT)
1396                                    || (getState() == XMapPane.SELECT_ALL)
1397                          this.bgContext.addMapLayerListListener(bgContextListener);                                  || (getState() == XMapPane.SELECT_TOP)) {
1398    
1399                          // adding listener to all layers                          // Draws a rectangle
1400                          for (MapLayer mapLayer : bgContext.getLayers()) {                          final Graphics graphics = getGraphics();
1401                                  mapLayer.addMapLayerListener(bgMapLayerListener);                          drawRectangle(graphics, startPos, event.getPoint());
1402                          }                          if ((lastPos.x > 0) && (lastPos.y > 0))
1403                                    drawRectangle(graphics, startPos, lastPos);
1404                            graphics.dispose();
1405                  }                  }
                 mapImageInvalid = true;  
                 repaint();  
1406          }          }
1407    
1408          /**          /**
1409           * Returns a copy of the mapArea           * Called by the {@link RenderingExecutor} when rendering was cancelled.
          *  
          * @return  
1410           */           */
1411          public Envelope getMapArea() {          public void onRenderingCancelled() {
1412                  if (mapArea == null) {                  LOGGER.debug("Rendering cancelled");
1413                          final Rectangle paneBounds = getBounds();                  repaintTimer.stop();
   
                         try {  
                                 mapArea = localContext.getLayerBounds();  
                         } catch (final IOException e) {  
                                 LOGGER.warn("context.getLayerBounds()", e);  
                         }  
   
                         if (mapArea != null) {  
                                 /* either the viewer size has changed or we've done a reset */  
                                 mapImageInvalid = true; /* note we need to redraw */  
                                 oldRect = paneBounds; /* store what the current size is */  
                                 mapArea = bestAllowedMapArea(mapArea);  
                         }  
                 }  
   
                 if (mapArea == null)  
                         return null;  
   
                 return new Envelope(mapArea);  
1414          }          }
1415    
1416          /**          /**
1417           * @param newMapArea           * Called by the {@link RenderingExecutor} when rendering has been
1418           * @return <code>true</code> if the mapArea has been changed and a repaint           * completed.
          *         has been triggered.  
1419           */           */
1420          public boolean setMapArea(final Envelope newMapArea) {          public void onRenderingCompleted() {
1421                    LOGGER.info("complete");
                 if (newMapArea == null  
                                 || bestAllowedMapArea(newMapArea).equals(mapArea)) {  
                         // No change.. no need to repaint  
                         return false;  
                 }  
   
                 // Testing, whether NaN or Infinity are used in the newMapArea  
                 if (newMapArea.isNull() || Double.isInfinite(newMapArea.getMaxX())  
                                 || Double.isInfinite(newMapArea.getMaxY())  
                                 || Double.isInfinite(newMapArea.getMinX())  
                                 || Double.isInfinite(newMapArea.getMinY())) {  
                         // No change.. ugly new values  
                         LOGGER.warn("setMapArea has been called with newArea = "  
                                         + newMapArea);  
                         return false;  
                 }  
   
                 // Testing, whether the difference if just minimal  
                 if (mapArea != null) {  
                         Envelope candNew = bestAllowedMapArea(newMapArea);  
                         double tolX = mapArea.getWidth() / 1000.;  
                         double tolY = mapArea.getHeight() / 1000.;  
                         if ((candNew.getMinX() - tolX < mapArea.getMinX())  
                                         && (mapArea.getMinX() < candNew.getMinX() + tolX)  
                                         && (candNew.getMaxX() - tolX < mapArea.getMaxX())  
                                         && (mapArea.getMaxX() < candNew.getMaxX() + tolX)  
   
                                         && (candNew.getMinY() - tolY < mapArea.getMinY())  
                                         && (mapArea.getMinY() < candNew.getMinY() + tolY)  
                                         && (candNew.getMaxY() - tolY < mapArea.getMaxY())  
                                         && (mapArea.getMaxY() < candNew.getMaxY() + tolY)  
   
                         ) {  
                                 // The two mapAreas only differ my 1/1000th.. ignore  
   
                                 return false;  
                         }  
                 }  
1422    
1423                  oldMapArea = mapArea;                  repaintTimer.stop();
1424    
1425                  this.mapArea = bestAllowedMapArea(newMapArea);                  // 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                  if (localContext != null) {                  updateFinalImage();
                         localContext.setAreaOfInterest(mapArea, localContext  
                                         .getCoordinateReferenceSystem());  
                 }  
                 if (bgContext != null) {  
                         bgContext.setAreaOfInterest(mapArea, localContext  
                                         .getCoordinateReferenceSystem());  
                 }  
                 resetTransforms();  
                 mapImageInvalid = true;  
                 mapAreaChanged = true;  
1431                  repaint();                  repaint();
   
 //              LOGGER.debug("New maparea = " + mapArea);  
                 return true;  
         }  
   
         public int getState() {  
                 return state;  
1432          }          }
1433    
1434          /**          /**
1435           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the           * Called by the {@linkplain XMapPane.RenderingTask} when rendering failed.
1436           * repaint Timer if           * Publishes a {@linkplain MapPaneEvent} of type {@code
1437             * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.
1438           *           *
1439           * @param state           * @param renderingError
1440             *            The error that occured during rendering
1441             *
1442             * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1443           */           */
1444          public void setState(final int state) {          public void onRenderingFailed(final Exception renderingError) {
                 this.state = state;  
1445    
1446                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN                  // Store the exceptions so we can show it to the user:
1447                                  || state == ZOOM_OUT || state == PAN));                  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                  // Je nach Aktion den Cursor umsetzen                  repaintTimer.stop();
                 updateCursor();  
         }  
   
         /** Cursor wenn kein Mausbutton gedrueckt wird. default oder SwingUtil.PAN **/  
         protected static Cursor normalCursor = Cursor  
                         .getPredefinedCursor(Cursor.DEFAULT_CURSOR);  
   
         public static final Cursor WAIT_CURSOR = Cursor  
                         .getPredefinedCursor(Cursor.WAIT_CURSOR);  
   
         public static final int NONE = -123;  
   
         private RenderingExecutor localExecuter = new RenderingExecutor(this, 150l);  
   
         private BufferedImage finalImage;  
   
         /**  
          * A flag set it {@link #setMapArea(Envelope)} to indicated the  
          * {@link #paintComponent(Graphics)} method, that the image on-screen is  
          * associated with {@link #oldMapArea} and may hence be scaled for a quick  
          * preview.<br/>  
          * The flag is reset  
          **/  
         private boolean mapAreaChanged = false;  
1455    
1456          private JFrame finalImageFrame;                  LOGGER.warn("Rendering failed", renderingError);
1457                    updateFinalImage();
1458                    repaint();
1459    
1460          private volatile Boolean requestStartRendering = false;          }
         private BufferedImage preFinalImage;  
1461    
1462            @Override
1463          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
1464                  // Maybe update the cursor  
1465                    // Maybe update the cursor and maybe stop the repainting timer
1466                  updateCursor();                  updateCursor();
1467    
1468                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1469                          return;                          return;
1470    
1471                    if (!isWellDefined())
1472                            return;
1473    
1474                    // super.paintComponent(g); // candidate for removal
1475    
1476                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1477    
1478                  if (mapImageInvalid) { /* if the map changed then redraw */                  if (mapImageInvalid) { /* if the map changed then redraw */
# Line 1151  public class XMapPane extends JPanel imp Line 1484  public class XMapPane extends JPanel imp
1484                          // happening.                          // happening.
1485                          if (mapAreaChanged && oldMapArea != null                          if (mapAreaChanged && oldMapArea != null
1486                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1487                                          & !getMapArea().equals(oldMapArea)) {                                          & !getMapArea().equals(oldMapArea) && !paneResized) {
1488    
1489                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1490    
1491                                  if (getMapArea().covers(oldMapArea)) {                                  if (getMapArea().covers(oldMapArea)) {
1492                                          setQuickPreviewHint(ZOOM_OUT);                                          quickPreviewHint = ZOOM_OUT;
1493                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1494                                  } else if (oldMapArea.covers(getMapArea())) {                                  } else if (oldMapArea.covers(getMapArea())) {
1495                                          setQuickPreviewHint(ZOOM_IN);                                          quickPreviewHint = ZOOM_IN;
1496                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1497                                  }                                  }
   
1498                          }                          }
   
                         if (paneResized) {  
                                 paneResized = false;  
                                 preFinalImage = null;  
                                 finalImage = null;  
                                 localImage = null;  
                                 bgImage = null;  
                                 // gadgetsImage = null;  
                         }  
   
                         // Start the Threads and Timers to render the image  
                         requestStartRendering();  
   
1499                  }                  }
1500    
1501                  if (!paintedSomething) {                  if (!paintedSomething) {
1502    
1503                          // TODO Should just paint the getFinalImage(). Update should be                          g.drawImage(getFinalImage(), 0, 0, null);
1504                          // called by timer every 300ms, and the repaint() until all threads  
1505                          // are done.                          g.dispose(); // cand. for removal
                         g.drawImage(getFinalImage(), 0, 0, this);  
1506    
1507                          paintedSomething = true;                          paintedSomething = true; // cand. for removal
1508                  }                  }
1509    
1510          }          }
1511    
1512          /**          /**
1513           * Cancels all running renderers and sets the flag to start new ones. <br/>           * 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           * @see #startRenderThreadsTimer           * 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 requestStartRendering() {          private void disposeImages() {
                 if (bgExecuter != null)  
                         bgExecuter.cancelTask();  
                 if (localExecuter != null)  
                         localExecuter.cancelTask();  
                 requestStartRendering = true;  
                   
         }  
1522    
1523          /**                  // System.out.println("vorher = "
1524           * Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten.                  // + new MbDecimalFormatter().format(LangUtil.gcTotal()));
1525           *                  // bi.flush();
1526           * @param ox                  // return bi = null;
1527           *            X-Koordinate der VON-Position                  // System.out.println("nacher = "
1528           * @param oy                  // + new MbDecimalFormatter().format(LangUtil.gcTotal()));
1529           *            Y-Koordinate der VON-Position                  //
1530           * @param px                  // System.out.println("\n");
          *            X-Koordinate der BIS-Position  
          * @param py  
          *            Y-Koordinate der BIS-Position  
          */  
         public Envelope tranformWindowToGeo(int ox, int oy, int px, int py) {  
                 AffineTransform at = getScreenToWorld();  
                 Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);  
                 Point2D geoP = at.transform(new Point2D.Double(px, py), null);  
                 return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());  
         }  
1531    
1532          /**                  if (preFinalImage != null) {
1533           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.                          preFinalImage.flush();
1534           *                          preFinalImage = null;
1535           * @param ox                          LangUtil.gc();
1536           *            X-Koordinate der VON-Position                  }
1537           * @param oy                  if (finalImage != null) {
1538           *            Y-Koordinate der VON-Position                          finalImage.flush();
1539           * @param px                          finalImage = null;
1540           *            X-Koordinate der BIS-Position                          LangUtil.gc();
1541           * @param py                  }
1542           *            Y-Koordinate der BIS-Position                  if (localImage != null) {
1543           * @param winToGeotransform                          localImage.flush();
1544           *            Eine Window to Geo transform. If <code>null</code>,                          localImage = null;
1545           *            {@link #getScreenToWorld()} is used.                          LangUtil.gc();
1546           */                  }
1547          public Envelope tranformGeoToWindow(double ox, double oy, double px,                  if (bgImage != null) {
1548                          double py, AffineTransform winToGeotransform) {                          bgImage.flush();
1549                  AffineTransform at = winToGeotransform == null ? getScreenToWorld()                          bgImage = null;
1550                                  : winToGeotransform;                          LangUtil.gc();
                 Point2D geoO;  
                 try {  
                         geoO = at.inverseTransform(new Point2D.Double(ox, oy), null);  
                         Point2D geoP = at  
                                         .inverseTransform(new Point2D.Double(px, py), null);  
                         return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP  
                                         .getY());  
                 } catch (NoninvertibleTransformException e) {  
                         LOGGER.error(e);  
                         return new Envelope(ox, oy, px, py);  
1551                  }                  }
1552    
1553          }          }
1554    
1555          /**          /**
1556           * Diretly paints scaled preview into the {@link SelectableXMapPane}. Used           * Performs a {@value #PAN} action. During panning, the displacement is
1557           * to give the user something to look at while we are rendering. Method           * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
1558           * should be called after {@link #setMapArea(Envelope)} has been set to the           * reset the offset and call {@link #setMapArea(Envelope)}.
          * new mapArea and transform has been reset.<br/>  
          * This method does nothing if the {@link #lastRenderingDuration} is smaller  
          * then a trashhold.  
          *  
          * @param g  
          *            Graphics2D to paint the preview into  
          *  
          * @param state  
          *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}  
1559           */           */
1560          protected boolean drawScaledPreviewImage_Zoom(Graphics2D graphics) {          public void performPan() {
   
                 if (quickPreviewHint == 0)  
                         return false;  
   
                 graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  
                                 RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  
                 graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
                                 RenderingHints.VALUE_ANTIALIAS_OFF);  
                 graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  
                                 RenderingHints.VALUE_RENDER_SPEED);  
   
                 if (oldMapArea == null)  
                         return false;  
   
                 Rectangle visibleArea = getVisibleRect();  
   
                 // Calculate the oldMapArea in the current WindowCoordinates:  
                 Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),  
                                 oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea  
                                                 .getMaxY(), null);  
   
                 int xx1 = (int) Math.round(oldMapWindow.getMinX());  
                 int yy1 = (int) Math.round(oldMapWindow.getMinY());  
                 int xx2 = (int) Math.round(oldMapWindow.getMaxX());  
                 int yy2 = (int) Math.round(oldMapWindow.getMaxY());  
   
                 graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,  
                                 (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),  
                                 (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),  
                                 getMapBackgroundColor(), null);  
1561    
1562                  Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 - yy1);                  Rectangle winBounds = getVisibleRect();
1563    
1564                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  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                  addGadgets(graphics);                  imageOrigin.x = 0;
1570                    imageOrigin.y = 0;
1571    
1572                  quickPreviewHint = 0;                  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                  graphics.dispose();                  if (getCursor() == SwingUtil.PANNING_CURSOR)
1583                                            setCursor(SwingUtil.PAN_CURSOR);
                 // Something has been drawn  
                 return true;  
1584          }          }
1585    
         final static Font waitFont = new Font("Arial", Font.BOLD, 30);  
   
1586          /**          /**
1587           * Paints some optinal stuff into the given {@link Graphics2D}. Usually           * Entfernt einen Listener von der Map.
1588           * called as the last paint on the mapImage.           *
1589             * @param l
1590             *            zu entfernender Listener
1591           */           */
1592          private void addGadgets(Graphics2D graphics) {          public void removeMapPaneListener(final JMapPaneListener l) {
1593                    mapPaneListeners.remove(l);
                 if (mapImage != null)  
                         graphics.drawImage(mapImage, getBounds().width  
                                         - mapImage.getWidth() - 10, getBounds().height  
                                         - mapImage.getHeight() - 10, this);  
   
                 // If still rendering, paint a gray shadow or so...  
                 if (bgExecuter != null && bgExecuter.isRunning()  
                                 || localExecuter != null && localExecuter.isRunning()) {  
                         graphics.setColor(Color.BLACK);  
   
                         graphics.setFont(waitFont);  
                         graphics.drawString("Wait...", 40, 70); //i8n  
                           
                         graphics.setColor(getMapBackgroundColor());  
                 }  
   
1594          }          }
1595    
1596          /**          /**
1597           * Accumulates all three images           * Cancels all running renderers and sets the flag to start new ones. <br>
1598           *           *
1599           * @return           * @see #startRenderThreadsTimer
1600           */           */
1601          synchronized protected BufferedImage updateFinalImage() {          private void requestStartRendering() {
   
                 final Graphics2D finalG = (Graphics2D) getFinalImage().getGraphics();  
                 finalG.setBackground(getMapBackgroundColor());  
   
                 // Render the two map images first, into the preFinalImage  
1602                  if (bgExecuter != null)                  if (bgExecuter != null)
1603                  {                          bgExecuter.cancelTask();
                         final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()  
                                         .getGraphics();  
                         preFinalG.setBackground(getMapBackgroundColor());  
   
                         preFinalG.drawImage(getBgImage(), 0, 0, getMapBackgroundColor(),  
                                         null);  
                           
                         // // Draw the local layers image  
                         preFinalG.drawImage(getLocalImage(), 0, 0, null);  
                         preFinalG.dispose();  
                 } else {  
                         preFinalImage = getLocalImage();  
                 }  
   
                 finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,  
                                 getMapBackgroundColor(), null);  
   
                 final int finalImageHeight = getFinalImage().getHeight(null);  
                 final int finalImageWidth = getFinalImage().getWidth(null);  
   
                 Rectangle painedArea = new Rectangle(imageOrigin.x, imageOrigin.y,  
                                 finalImageWidth, finalImageHeight);  
                 SwingUtil.clearAround(finalG, painedArea, getVisibleRect());  
   
                 addGadgets(finalG);  
   
                 finalG.dispose();  
   
                 return finalImage;  
         }  
1604    
1605          private Image getFinalImage() {                  localExecuter.cancelTask();
1606    
1607                  if (finalImage == null) {                  mapImageInvalid = true;
1608                          finalImage = null;                  if (paneResized) {
1609                          Rectangle curPaintArea = getVisibleRect();                          paneResized = false;
1610                          finalImage = new BufferedImage(curPaintArea.width,                          disposeImages();
                                         curPaintArea.height, BufferedImage.TYPE_INT_RGB);  
   
                         requestStartRendering();  
1611                  }                  }
1612                  return finalImage;                  requestStartRendering = true;
         }  
   
         private Image getPreFinalImage() {  
                 if (preFinalImage == null) {  
                         preFinalImage = null;  
                         Rectangle curPaintArea = getVisibleRect();  
   
                         preFinalImage = new BufferedImage(curPaintArea.width,  
                                         curPaintArea.height, BufferedImage.TYPE_INT_RGB);  
1613    
                         requestStartRendering();  
                 }  
                 return preFinalImage;  
1614          }          }
1615    
1616          /**          /**
1617           * While dragging, the {@link #updateFinalImage()} method is translating the           * Calculate the affine transforms used to convert between world and pixel
1618           * cached images while setting it together.           * coordinates. The calculations here are very basic and assume a cartesian
1619           **/           * reference system.
1620          Point imageOrigin = new Point(0, 0);           * <p>
1621             * Tne transform is calculated such that {@code envelope} will be centred in
1622          /**           * the display
1623           * Starts rendering on one or two threads           *
1624           */           * @param envelope
1625          private void startRendering() {           *            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())                  if (!isWellDefined())
1636                          return;                          return;
1637    
1638                  if (bgExecuter != null){                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1639                          // Stop all renderers                                  getVisibleRect());
                         bgExecuter.cancelTask();  
                 }  
   
                 if (localExecuter != null){  
                         localExecuter.cancelTask();  
                 }  
           
                 Rectangle curPaintArea = getVisibleRect();  
   
                 labelCache.clear();  
1640    
1641                  /**                  try {
1642                   * We have to set new renderer                          screenToWorld = worldToScreen.createInverse();
                  */  
1643    
1644                  if (getBgContext() != null) {                  } catch (NoninvertibleTransformException ex) {
1645                          bgExecuter = new RenderingExecutor(this, 333l);                          LOGGER
1646                          LOGGER.debug("starting bg renderer:");                                          .error("can't invert worldToScreen to get screenToWorld!",
1647                          // /* System.out.println("rendering"); */                                                          ex);
                         final GTRenderer createGTRenderer = GTUtil.createGTRenderer(  
                                         bgContext, getRendererHints());  
                         createGTRenderer.setJava2DHints(getJava2dHints());  
                         bgExecuter.submit(getBgContext().getAreaOfInterest(), curPaintArea,  
                                         (Graphics2D) getBgImage().getGraphics(), createGTRenderer);  
                 }  
   
                 if (getContext() != null) {  
 //                      localExecuter = new RenderingExecutor(this, 150l);  
                         LOGGER.debug("starting local renderer:");  
                         final GTRenderer createGTRenderer = GTUtil.createGTRenderer(  
                                         localContext, getRendererHints());  
                         createGTRenderer.setJava2DHints(getJava2dHints());  
                         localExecuter.submit(getContext().getAreaOfInterest(),  
                                         curPaintArea, (Graphics2D) getLocalImage().getGraphics(),  
                                         createGTRenderer);  
1648                  }                  }
   
                 updateCursor();  
   
1649          }          }
1650    
1651          /**          public void setBgContext(final MapContext context) {
          * Lazyly initializes a {@link BufferedImage} for the background renderer.  
          */  
         private BufferedImage getBgImage() {  
1652    
1653                  if (bgImage == null) {                  // Remove the default listener from the old context
1654                          Rectangle curPaintArea = getVisibleRect();                  if (this.bgContext != null) {
1655                            this.bgContext.removeMapLayerListListener(bgContextListener);
1656    
1657                          bgImage = new BufferedImage(curPaintArea.width + 1,                          // adding listener to all layers
1658                                          curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);                          for (final MapLayer mapLayer : bgContext.getLayers()) {
1659                                    mapLayer.removeMapLayerListener(bgMapLayerListener);
1660                            }
1661                  }                  }
1662    
1663                  return bgImage;                  this.bgContext = context;
         }  
1664    
1665          /** An (transparent) image to paint over the map in the lower right corner **/                  if (context != null) {
1666          private BufferedImage mapImage = null;                          // setMapArea(bgContext.getAreaOfInterest());
1667    
1668          private boolean acceptsRepaintCalls = true;                          this.bgContext.addMapLayerListListener(bgContextListener);
1669    
1670          /**                          // adding listener to all layers
1671           * Get the BufferedImage to use as a flaoting icon in the lower right                          for (final MapLayer mapLayer : bgContext.getLayers()) {
1672           * corner.                                  mapLayer.addMapLayerListener(bgMapLayerListener);
1673           *                          }
1674           * @return <code>null</code> if the feature is deactivated.                  }
          */  
         public BufferedImage getMapImage() {  
                 return mapImage;  
         }  
1675    
1676          /**                  requestStartRendering();
          * Set the BufferedImage to use as a flaoting icon in the lower right corner  
          *  
          * @param mapImageIcon  
          *            <code>null</code> is allowed and deactivates this icon.  
          */  
         public void setMapImage(BufferedImage mapImage) {  
                 this.mapImage = mapImage;  
1677          }          }
1678    
1679          /**          public void setJava2dHints(final RenderingHints java2dHints) {
1680           * Lazyly initializes a {@link BufferedImage} for the background renderer.                  this.java2dHints = java2dHints;
1681           */          }
         private BufferedImage getLocalImage() {  
   
                 if (localImage == null) {  
1682    
1683                          Rectangle curPaintArea = getVisibleRect();          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                          localImage = new BufferedImage(curPaintArea.width + 1,                          // adding listener to all layers
1689                                          curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);                          for (final MapLayer mapLayer : localContext.getLayers()) {
1690                                    mapLayer.removeMapLayerListener(localMapLayerListener);
1691                            }
1692                  }                  }
1693    
1694                  return localImage;                  this.localContext = context;
         }  
1695    
1696                    if (context != null) {
1697    
1698          /**                          // setMapArea(localContext.getAreaOfInterest());
          * Called by the {@linkplain XMapPane.RenderingTask} when rendering has been  
          * completed Publishes a {@linkplain MapPaneEvent} of type {@code  
          * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.  
          *  
          * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)  
          */  
         public void onRenderingCompleted() {  
                 repainterTimer.stop();  
                 updateFinalImage();  
                 repaint();  
         }  
1699    
1700          /**                          localRenderer.setContext(localContext);
          * Called by the {@linkplain XMapPane.RenderingTask} when rendering was  
          * cancelled. Publishes a {@linkplain MapPaneEvent} of type {@code  
          * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.  
          *  
          * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)  
          */  
         public void onRenderingCancelled() {  
                 repainterTimer.stop();  
                 LOGGER.debug("Rendering cancelled");  
         }  
1701    
1702          /**                          this.localContext.addMapLayerListListener(localContextListener);
          * Called by the {@linkplain XMapPane.RenderingTask} when rendering failed.  
          * Publishes a {@linkplain MapPaneEvent} of type {@code  
          * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.  
          *  
          * @param renderingError  
          *            The error that occured during rendering  
          *  
          * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)  
          */  
         public void onRenderingFailed(Exception renderingError) {  
                 repainterTimer.stop();  
                 LOGGER.warn("Rendering failed", renderingError);  
                 updateFinalImage();  
                 repaint();  
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          @Override          }
         public void propertyChange(final PropertyChangeEvent evt) {  
                 final String prop = evt.getPropertyName();  
1713    
1714                  if (prop.equalsIgnoreCase("crs")) {          public boolean setMapArea(final Envelope newMapArea) {
1715                          localContext.setAreaOfInterest(localContext.getAreaOfInterest(),                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1716                                          (CoordinateReferenceSystem) evt.getNewValue());                                  .getCoordinateReferenceSystem()));
                 }  
1717          }          }
1718    
1719          /**          /**
1720           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * @param newMapArea
1721           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten           * @return <code>true</code> if the mapArea has been changed and a repaint
1722           * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/>           *         has been triggered.
          * Since 21. April 09: Before thecalculation starts, the aspect ratio is  
          * corrected. This change implies, that setMapArea() will most of the time  
          * not allow setting to a wrong aspectRatio.  
          *  
          * @author <a href="mailto:[email protected]">Stefan Alfons  
          *         Kr&uuml;ger</a>  
1723           */           */
1724          public Envelope bestAllowedMapArea(Envelope env) {          public boolean setMapArea(final ReferencedEnvelope newMapArea) {
                 if (getWidth() == 0)  
                         return env;  
                 if (env == null)  
                         return null;  
   
                 Envelope newArea = null;  
   
                 /**  
                  * Correct the aspect Ratio before we check the rest. Otherwise we might  
                  * easily fail. We allow to grow here, because we don't check against  
                  * the maxExtend  
                  */  
                 Rectangle curPaintArea = getVisibleRect();  
1725    
1726                  env = JTSUtil.fixAspectRatio(curPaintArea, env, true);                  if (newMapArea == null
1727                                    || bestAllowedMapArea(newMapArea).equals(mapArea)) {
1728                  final double scale = env.getWidth() / getWidth();                          // No change.. no need to repaint
1729                  final double centerX = env.getMinX() + env.getWidth() / 2.;                          return false;
                 final double centerY = env.getMinY() + env.getHeight() / 2.;  
                 double newWidth2 = 0;  
                 double newHeight2 = 0;  
                 if (scale < getMaxZoomScale()) {  
                         // ****************************************************************************  
                         // Wir zoomen weiter rein als erlaubt => Anpassen des envelope  
                         // ****************************************************************************  
                         newWidth2 = getMaxZoomScale() * getWidth() / 2.;  
                         newHeight2 = getMaxZoomScale() * getHeight() / 2.;  
                 } else if (scale > getMinZoomScale()) {  
                         // ****************************************************************************  
                         // Wir zoomen weiter raus als erlaubt => Anpassen des envelope  
                         // ****************************************************************************  
                         newWidth2 = getMinZoomScale() * getWidth() / 2.;  
                         newHeight2 = getMinZoomScale() * getHeight() / 2.;  
                 } else {  
                         // ****************************************************************************  
                         // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen  
                         // ****************************************************************************  
                         newArea = env;  
1730                  }                  }
1731    
1732                  if (newArea == null) {                  // Testing, whether NaN or Infinity are used in the newMapArea
1733                    if (newMapArea.isNull() || Double.isInfinite(newMapArea.getMaxX())
1734                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY                                  || Double.isInfinite(newMapArea.getMaxY())
1735                                          - newHeight2);                                  || Double.isInfinite(newMapArea.getMinX())
1736                          final Coordinate ur = new Coordinate(centerX + newWidth2, centerY                                  || Double.isInfinite(newMapArea.getMinY())) {
1737                                          + newHeight2);                          // No change.. ugly new values
1738                            LOGGER.warn("setMapArea has been called with newArea = "
1739                          newArea = new Envelope(ll, ur);                                          + newMapArea);
1740                            return false;
1741                  }                  }
1742    
1743                  Envelope maxAllowedExtend = getMaxExtend();                  final Envelope candNew = bestAllowedMapArea(newMapArea);
                 while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)  
                                 && newArea != null && !newArea.isNull()  
                                 && !Double.isNaN(newArea.getMinX())  
                                 && !Double.isNaN(newArea.getMaxX())  
                                 && !Double.isNaN(newArea.getMinY())  
                                 && !Double.isNaN(newArea.getMaxY())) {  
                         /*  
                          * If a maxExtend is set, we have to honour that...  
                          */  
1744    
1745                          // Exceeds top? Move down and maybe cut                  // Testing, whether the difference if just minimal
1746                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                  if (mapArea != null) {
1747                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();                          final double tolX = mapArea.getWidth() / 1000.;
1748                                  // LOGGER.debug("Moving area down by " + divY);                          final double tolY = mapArea.getHeight() / 1000.;
1749                            if ((candNew.getMinX() - tolX < mapArea.getMinX())
1750                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          && (mapArea.getMinX() < candNew.getMinX() + tolX)
1751                                                  newArea.getMinY() - divY), new Coordinate(newArea                                          && (candNew.getMaxX() - tolX < mapArea.getMaxX())
1752                                                  .getMaxX(), newArea.getMaxY() - divY));                                          && (mapArea.getMaxX() < candNew.getMaxX() + tolX)
   
                                 if (newArea.getMinY() < maxAllowedExtend.getMinY()) {  
                                         // LOGGER.debug("Now it exeeds the bottom border.. cut!");  
                                         // And cut the bottom if it moved out of the area  
                                         newArea = new Envelope(new Coordinate(newArea.getMinX(),  
                                                         maxAllowedExtend.getMinY()), new Coordinate(newArea  
                                                         .getMaxX(), newArea.getMaxY()));  
   
                                         // LOGGER.debug("and fix aspect ratio");  
   
                                         newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,  
                                                         false);  
                                 }  
                         }  
   
                         // Exceeds bottom? Move up and maybe cut  
                         if (newArea.getMinY() < maxAllowedExtend.getMinY()) {  
                                 double divY = newArea.getMinY() - maxAllowedExtend.getMinY();  
                                 // LOGGER.debug("Moving area up by " + divY);  
   
                                 newArea = new Envelope(new Coordinate(newArea.getMinX(),  
                                                 newArea.getMinY() - divY), new Coordinate(newArea  
                                                 .getMaxX(), newArea.getMaxY() - divY));  
1753    
1754                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                                          && (candNew.getMinY() - tolY < mapArea.getMinY())
1755                                          // LOGGER.debug("Now it exeeds the top border.. cut!");                                          && (mapArea.getMinY() < candNew.getMinY() + tolY)
1756                                          // And cut the bottom if it moved out of the area                                          && (candNew.getMaxY() - tolY < mapArea.getMaxY())
1757                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          && (mapArea.getMaxY() < candNew.getMaxY() + tolY)
                                                         newArea.getMinY()), new Coordinate(newArea  
                                                         .getMaxX(), maxAllowedExtend.getMaxY()));  
1758    
1759                                          // LOGGER.debug("and fix aspect ratio");                          ) {
1760                                    // The two mapAreas only differ my 1/1000th.. ignore
1761    
1762                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                  return false;
                                                         false);  
                                 }  
1763                          }                          }
1764                    }
1765    
1766                          // Exceeds to the right? move and maybe cut                  // New map are is accepted:
1767                          if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {                  oldMapArea = mapArea;
1768                    mapArea = candNew;
1769                                  // Move left..                  resetTransforms();
                                 double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();  
                                 // LOGGER.debug("Moving area left by " + divX);  
   
                                 newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,  
                                                 newArea.getMinY()), new Coordinate(newArea.getMaxX()  
                                                 - divX, newArea.getMaxY()));  
   
                                 if (newArea.getMinX() < maxAllowedExtend.getMinX()) {  
                                         // LOGGER.debug("Now it exeeds the left border.. cut!");  
                                         // And cut the left if it moved out of the area  
                                         newArea = new Envelope(new Coordinate(maxAllowedExtend  
                                                         .getMinX(), newArea.getMinY()), new Coordinate(  
                                                         newArea.getMaxX(), newArea.getMaxY()));  
   
                                         // LOGGER.debug("and fix aspect ratio");  
   
                                         newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,  
                                                         false);  
                                 }  
                         }  
1770    
1771                          // Exceeds to the left? move and maybe cut                  if (localContext != null) {
1772                          if (newArea.getMinX() < maxAllowedExtend.getMinX()) {                          localContext.setAreaOfInterest(mapArea, localContext
1773                                            .getCoordinateReferenceSystem());
1774                    }
1775                    if (bgContext != null) {
1776                            bgContext.setAreaOfInterest(mapArea, localContext
1777                                            .getCoordinateReferenceSystem());
1778                    }
1779    
1780                                  // Move right..                  mapAreaChanged = true;
                                 double divX = newArea.getMinX() - maxAllowedExtend.getMinX();  
                                 // LOGGER.debug("Moving area right by " + divX);  
1781    
1782                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                  repaint(200); // Do not remove it!
                                                 newArea.getMinY()), new Coordinate(newArea.getMaxX()  
                                                 - divX, newArea.getMaxY()));  
1783    
1784                                  if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {                  requestStartRendering();
                                         // LOGGER.debug("Now it exeeds the right border.. cut!");  
                                         // And cut the left if it moved out of the area  
                                         newArea = new Envelope(new Coordinate(newArea.getMinX(),  
                                                         newArea.getMinY()), new Coordinate(maxAllowedExtend  
                                                         .getMaxX(), newArea.getMaxY()));  
1785    
1786                                          // LOGGER.debug("and fix aspect ratio");                  return true;
1787            }
1788    
1789                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,          /**
1790                                                          false);           * 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                  return newArea;          /**
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           * Retuns the minimum allowed zoom scale. This is the bigger number value of           * Sets whether a layer is regarded or ignored on {@link #SELECT_TOP},
1812           * the two. Defaults to {@link Double}.MAX_VALUE           * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions.
1813           *           *
1814           * @author <a href="mailto:[email protected]">Stefan Alfons           * @param layer
1815           *         Kr&uuml;ger</a>           *            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 Double getMinZoomScale() {          public void setMapLayerSelectable(final MapLayer layer,
1822                  return minZoomScale;                          final Boolean selectable) {
1823                    if (selectable == null)
1824                            mapLayerSelectable.remove(layer);
1825                    else
1826                            mapLayerSelectable.put(layer, selectable);
1827          }          }
1828    
1829          /**          /**
1830           * Retuns the maximum allowed zoom scale. This is the smaller number value           * Defines an evelope of the viwable area. The JMapPane will never show
1831           * of the two. Defaults to {@link Double}.MIN_VALUE           * anything outside of this extend.
1832           *           *
1833           * @author <a href="mailto:[email protected]">Stefan Alfons           * @param maxExtend
1834           *         Kr&uuml;ger</a>           *            <code>null</code> to not have this restriction.
1835           */           */
1836          public Double getMaxZoomScale() {          public void setMaxExtend(final Envelope maxExtend) {
1837                  return maxZoomScale;                  this.maxExtend = maxExtend;
1838          }          }
1839    
1840          /**          /**
# Line 1788  public class XMapPane extends JPanel imp Line 1850  public class XMapPane extends JPanel imp
1850                                  : maxZoomScale;                                  : 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           * 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           * value of the two. If <code>null</code> is passed, Double.MAXVALUE are
# Line 1803  public class XMapPane extends JPanel imp Line 1868  public class XMapPane extends JPanel imp
1868          }          }
1869    
1870          /**          /**
1871           * Defines an evelope of the viwable area. The JMapPane will never show           * If <code>true</code>, allow the {@link XMapPane} to process #repaint()
1872           * anything outside of this extend.           * requests. Otherwise the map will not paint anything and not start any
1873           *           * rendering {@link Thread}s.
          * @param maxExtend  
          *            <code>null</code> to not have this restriction.  
1874           */           */
1875          public void setMaxExtend(Envelope maxExtend) {          public void setPainting(final boolean b) {
1876                  this.maxExtend = maxExtend;                  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           * Returns the evelope of the viewable area. The JMapPane will never show           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the
1888           * anything outside of this extend. If this has been set to           * repaint Timer if
          * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return  
          * quickly the context's bounds. It it takes to long to determine the  
          * context bounds, <code>null</code> is returned.  
1889           *           *
1890           * @param maxExtend           * @param state
          *            <code>null</code> to not have this restriction.  
1891           */           */
1892            public void setState(final int state) {
1893                    this.state = state;
1894    
1895          public Envelope getMaxExtend() {                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN
1896                  if (maxExtend == null) {                                  || state == ZOOM_OUT || state == PAN));
                         final ReferencedEnvelope layerBounds = GTUtil  
                                         .getVisibleLayoutBounds(localContext);  
                         if (layerBounds == null) {  
                                 // TODO Last fallback could be the CRS valid area  
                                 return null;  
                         }  
1897    
1898                          // Kartenbereich um 10% vergroessern                  // Je nach Aktion den Cursor umsetzen
1899                          return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil                  updateCursor();
                                         .expandEnvelope(layerBounds, 0.1), true);  
                 }  
                 return maxExtend;  
1900          }          }
1901    
1902          /**          /**
1903           * Set the background color of the map.           * 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 if <code>null</code>, white is used.           * @param cursor
1910             *            Cursor
1911           */           */
1912          public void setMapBackgroundColor(Color bgColor) {          public void setStaticCursor(final Cursor cursor) {
1913                  if (bgColor == null)                  this.staticCursor = cursor;
1914                          bgColor = Color.WHITE;                  if (cursor != null)
1915                  this.mapBackgroundColor = bgColor;                          super.setCursor(cursor);
1916          }          }
1917    
1918          /**          /**
1919           * Returns the background {@link Color} of the map pane. Default is white.           * Starts rendering on one or two threads
1920           **/           */
1921          public Color getMapBackgroundColor() {          private void startRendering() {
1922                  return mapBackgroundColor;  
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 b           * @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 void setPainting(boolean b) {          public Envelope tranformGeoToWindow(final double ox, final double oy,
1995                  acceptsRepaintCalls = b;                          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           * Fuegt der Map einen Listener hinzu.           * Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten.
2010           *           *
2011           * @param l           * @param ox
2012           *            neuer Listener           *            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 void addMapPaneListener(JMapPaneListener l) {          public Envelope tranformWindowToGeo(final int ox, final int oy,
2021                  mapPaneListeners.add(l);                          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           * Liste der angeschlossenen Listener, die auf Aktionen des MapPanes           * Will update the cursor. If all rendering is finished also stops the
2035           * lauschen.           * {@link #repaintTimer}
2036           */           */
2037          protected Vector<JMapPaneListener> mapPaneListeners = new Vector<JMapPaneListener>();          public void updateCursor() {
2038    
2039          /**                  // if the renderers have stopped, also stop the timer that is updating
2040           * A flag indicating if dispose() was already called. If true, then further                  // the final image
2041           * use of this {@link SelectableXMapPane} is undefined.                  if (bgExecuter != null && bgExecuter.isRunning()
2042           */                                  || localExecuter.isRunning()) {
2043          private boolean disposed = false;                          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           * Entfernt einen Listener von der Map.           * The renderers are all rendering into their own {@link Image}s. This
2090           *           * method combines all images to one {@link #finalImage}. The
2091           * @param l           * {@link #repaintTimer} is calling this method regularely to update the
2092           *            zu entfernender Listener           * {@link #finalImage} even if the renderers are still working.
2093           */           */
2094          public void removeMapPaneListener(JMapPaneListener l) {          synchronized protected Image updateFinalImage() {
                 mapPaneListeners.remove(l);  
         }  
2095    
2096          /** Stored the time used for the last real rendering in ms. **/                  // Render the two map images first, into the preFinalImage
2097          private long lastRenderingDuration = Long.MAX_VALUE;                  if (bgExecuter != null) {
2098                            final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()
2099                                            .getGraphics();
2100                            preFinalG.setBackground(getMapBackgroundColor());
2101    
2102          // if null, no quick preview will be shown                          preFinalG.drawImage(getBgImage(), 0, 0, getMapBackgroundColor(),
2103          private int quickPreviewHint = 0;                                          null);
2104    
2105          /**                          // // Draw the local layers image
2106           * For every rendering thread started,                          preFinalG.drawImage(getLocalImage(), 0, 0, null);
2107           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new                          preFinalG.dispose();
          * renderer. These Java2D rendering hints are passed to the  
          * {@link GTRenderer}. The java2dHints are the same for all renderers (bg  
          * and local).  
          */  
         private RenderingHints java2dHints;  
2108    
2109          /**                  } else {
2110           * Returns in milli seconds the time the last rending of the                          preFinalImage = getLocalImage();
2111           * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has not                  }
2112           * been rendered yet.  
2113           */                  final Graphics2D finalG = getFinalImage().createGraphics();
2114          public long getLastRenderingDuration() {                  finalG.setBackground(getMapBackgroundColor());
2115                  return lastRenderingDuration;                  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           * Should be called when the {@link JMapPane} is not needed no more to help           * Paints some optional stuff into the given {@link Graphics2D}. Usually
2134           * the GarbageCollector           * called as the last layer when {@link #updateFinalImage()}
          *  
          * Removes all {@link JMapPaneListener}s that are registered  
2135           *           *
2136           * @author <a href="mailto:[email protected]">Stefan Alfons           * @param forceWait
2137           *         Kr&uuml;ger</a>           *            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          public void dispose() {          private void addGadgets(final Graphics2D graphics, boolean forceWait) {
                 if (isDisposed())  
                         return;  
                   
                   
                 setPainting(false);  
2143    
2144                  disposed = true;                  // Paint a logo to the bottom right if available
2145                    if (mapImage != null) {
2146                  if (bgExecuter != null) {                          Rectangle visibleRect = getVisibleRect();
2147                          bgExecuter.cancelTask();                          graphics.drawImage(mapImage, visibleRect.width
2148                          bgExecuter.dispose();                                          - mapImage.getWidth() - 10, getVisibleRect().height
2149                                            - mapImage.getHeight() - 10, null);
2150                  }                  }
2151    
2152                  if (localExecuter != null) {                  int y = 17;
2153                          localExecuter.cancelTask();  
2154                          localExecuter.dispose();                  // 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                  startRenderThreadsTimer.stop();                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
2176    
2177                  if (bgImage != null)                          final Color c = graphics.getColor();
2178                          bgImage.flush();                          graphics.setFont(errorFont);
                 if (localImage != null)  
                         localImage.flush();  
                 if (finalImage != null)  
                         finalImage.flush();  
                 if (preFinalImage != null)  
                         preFinalImage.flush();  
2179    
2180                  // Alle mapPaneListener entfernen                          for (Exception ex : renderingErrors) {
                 mapPaneListeners.clear();  
2181    
2182                  removeMouseMotionListener(zoomMapPaneMouseListener);                                  String errStr = ex.getLocalizedMessage();
                 removeMouseListener(zoomMapPaneMouseListener);  
2183    
2184                  if (localContext != null)                                  if (errStr == null)
2185                          getContext().clearLayerList();                                          errStr = ex.getMessage();
2186                  if (bgContext != null)                                  if (errStr == null)
2187                          getBgContext().clearLayerList();                                          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    
                 removeAll();  
2200          }          }
2201    
2202          /**          /**
2203           * A flag indicating if dispose() has already been called. If true, then           * Sets the {@link #mapArea} to best possibly present the given features. If
2204           * further use of this {@link SelectableXMapPane} is undefined.           * 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          private boolean isDisposed() {          public void zoomTo(
2210                  return disposed;                          final FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
         }  
2211    
2212          public void setQuickPreviewHint(int quickPreviewHint) {                  // if (!isWellDefined()) return;
                 this.quickPreviewHint = quickPreviewHint;  
2213    
2214          }                  final CoordinateReferenceSystem mapCRS = getMapContext()
2215                                    .getCoordinateReferenceSystem();
2216                    final CoordinateReferenceSystem fCRS = features.getSchema()
2217                                    .getGeometryDescriptor().getCoordinateReferenceSystem();
2218    
2219          public void setJava2dHints(RenderingHints java2dHints) {                  ReferencedEnvelope _mapArea;
2220                  this.java2dHints = java2dHints;                  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          public RenderingHints getJava2dHints() {          /**
2293                  return java2dHints;           * 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          /**          /**
# Line 2008  public class XMapPane extends JPanel imp Line 2313  public class XMapPane extends JPanel imp
2313                  if (zoomFaktor == null || zoomFaktor == 0.)                  if (zoomFaktor == null || zoomFaktor == 0.)
2314                          zoomFaktor = 2.;                          zoomFaktor = 2.;
2315    
2316                  Point2D gcenter = getScreenToWorld().transform(center, null);                  final Point2D gcenter = getScreenToWorld().transform(center, null);
2317                  center = null;                  center = null;
2318    
2319                  if (Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())                  if (Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())
# Line 2022  public class XMapPane extends JPanel imp Line 2327  public class XMapPane extends JPanel imp
2327    
2328                  final Envelope mapArea = getMapArea();                  final Envelope mapArea = getMapArea();
2329    
2330                  Envelope newMapArea = new Envelope(mapArea);                  final Envelope newMapArea = new Envelope(mapArea);
2331                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2332                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2333                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2334    
2335                  // Move the newMapArea above the new center                  // TODO we actually want that
2336                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                  // // Move the newMapArea above the new center
2337                                  .getY()                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2338                                  - mapArea.centre().y);                  // .getY()
2339                    // - mapArea.centre().y);
2340    
2341                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2342          }          }
2343    
2344          /**          /**
2345           * Zooms towards a point.           * Shall non-fatal rendering exceptions be reported in the mappane or be
2346           *           * dropped quitely.
          * @param center  
          *            position in window coordinates  
          * @param zoomFactor  
          *            > 1 for zoom in, < 1 for zoom out. Default is 1.33  
2347           */           */
2348          public void zoomTo(Point center) {          public void setShowExceptions(boolean showExceptions) {
2349                  zoomTo(center, null);                  this.showExceptions = showExceptions;
         }  
   
         public void mouseDragged(Point startPos, Point lastPos, MouseEvent event) {  
   
                 if ((getState() == XMapPane.PAN)  
                                 || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {  
   
                         if (getCursor() != SwingUtil.PANNING_CURSOR) {  
                                 setCursor(SwingUtil.PANNING_CURSOR);  
   
                                 // While panning, we deactivate the rendering. So the tasts are  
                                 // ready to start when the panning os done.  
                                 if (bgExecuter != null)  
                                         bgExecuter.cancelTask();  
                                 if (localExecuter != null)  
                                         localExecuter.cancelTask();  
                         }  
   
                         if (lastPos.x > 0 && lastPos.y > 0) {  
                                 final int dx = event.getX() - lastPos.x;  
                                 final int dy = event.getY() - lastPos.y;  
   
                                 // TODO Stop dragging when the drag would not be valid...  
                                 // boolean dragValid = true;  
                                 // // check if this panning results in a valid mapArea  
                                 // {  
                                 // Rectangle winBounds = xMapPane.getBounds();  
                                 // winBounds.translate(xMapPane.imageOrigin.x,  
                                 // -xMapPane.imageOrigin.y);  
                                 // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(  
                                 // winBounds.x, winBounds.y, winBounds.x  
                                 // + winBounds.width, winBounds.y  
                                 // + winBounds.height);  
                                 //                                        
                                 //  
                                 // winBounds = xMapPane.getBounds();  
                                 // Point testIng = new Point(xMapPane.imageOrigin);  
                                 // testIng.translate(dx, dy);  
                                 // winBounds.translate(testIng.x, -testIng.y);  
                                 // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(  
                                 // winBounds.x, winBounds.y, winBounds.x  
                                 // + winBounds.width, winBounds.y  
                                 // + winBounds.height);  
                                 //  
                                 // // If the last drag doesn't change the MapArea anymore cancel  
                                 // it.  
                                 // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(  
                                 // xMapPane.bestAllowedMapArea(newMapAreaBefore))){  
                                 // dragValid = false;  
                                 // return;  
                                 // }  
                                 // }  
   
                                 imageOrigin.translate(dx, dy);  
                                 updateFinalImage();  
                                 repaint();  
                         }  
   
                 } else if ((getState() == XMapPane.ZOOM_IN)  
                                 || (getState() == XMapPane.ZOOM_OUT)  
                                 || (getState() == XMapPane.SELECT_ALL)  
                                 || (getState() == XMapPane.SELECT_TOP)  
                 // || (getState() == XMapPane.SELECT_ONE_FROM_TOP)  
                 ) {  
                         final Graphics graphics = getGraphics();  
   
                         drawRectangle(graphics, startPos, event.getPoint());  
   
                         if ((lastPos.x > 0) && (lastPos.y > 0)) {  
                                 drawRectangle(graphics, startPos, lastPos);  
                         }  
   
                 }  
   
2350          }          }
2351    
2352          /**          /**
2353           * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the           * Shall exceptions be reported in the mappane?
          * given point. All in screen coordinates.  
2354           */           */
2355          protected void drawRectangle(final Graphics graphics, Point startPos,          public boolean isShowExceptions() {
2356                          Point e) {                  return showExceptions;
                   
                 if (!isWellDefined()) return;  
                   
                 // undraw last box/draw new box  
                 final int left = Math.min(startPos.x, e.x);  
                 final int right = Math.max(startPos.x, e.x);  
                 final int top = Math.max(startPos.y, e.y);  
                 final int bottom = Math.min(startPos.y, e.y);  
                 final int width = right - left;  
                 final int height = top - bottom;  
   
                 if (width == 0 && height == 0)  
                         return;  
   
                 graphics.setXORMode(Color.WHITE);  
                 graphics.drawRect(left, bottom, width, height);  
         }  
   
         /**  
          * Finalizes a PAN action  
          */  
         public void performPan() {  
                 Rectangle winBounds = getBounds();  
                 winBounds.translate(-imageOrigin.x, -imageOrigin.y);  
                 Envelope newMapArea = tranformWindowToGeo(winBounds.x, winBounds.y,  
                                 winBounds.x + winBounds.width, winBounds.y + winBounds.height);  
   
                 imageOrigin.x = 0;  
                 imageOrigin.y = 0;  
   
                 if (!setMapArea(newMapArea)) {  
                         updateFinalImage();  
                         repaint();  
                 }  
   
                 if (getCursor() == SwingUtil.PANNING_CURSOR)  
                         setCursor(SwingUtil.PAN_CURSOR);  
         }  
   
         public void onRenderingPending() {  
 //              LOGGER.debug("Pending rendering updates the preview...");  
                 updateFinalImage();  
                 repaint();  
2357          }          }
2358    
2359  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26