/[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/skrueger/geotools/XMapPane.java revision 543 by alfonx, Sat Nov 21 15:21:41 2009 UTC branches/2.0-RC2/src/skrueger/geotools/XMapPane.java revision 656 by alfonx, Wed Feb 3 12:18:35 2010 UTC
# Line 26  import java.util.HashMap; Line 26  import java.util.HashMap;
26  import java.util.Map;  import java.util.Map;
27  import java.util.Vector;  import java.util.Vector;
28    
29    import javax.swing.JList;
30  import javax.swing.Timer;  import javax.swing.Timer;
31    import javax.swing.border.Border;
32    
33  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
34    import org.geotools.factory.GeoTools;
35  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
36  import org.geotools.geometry.Envelope2D;  import org.geotools.geometry.DirectPosition2D;
37  import org.geotools.geometry.jts.JTS;  import org.geotools.geometry.jts.JTS;
38  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
39  import org.geotools.map.DefaultMapContext;  import org.geotools.map.DefaultMapContext;
# Line 66  import schmitzm.geotools.map.event.MapLa Line 69  import schmitzm.geotools.map.event.MapLa
69  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
70  import schmitzm.swing.JPanel;  import schmitzm.swing.JPanel;
71  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
72    import schmitzm.swing.event.MouseInputType;
73    
74  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
75  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 96  import com.vividsolutions.jts.geom.Geome Line 100  import com.vividsolutions.jts.geom.Geome
100   */   */
101  public class XMapPane extends JPanel {  public class XMapPane extends JPanel {
102    
103          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;          // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
104          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;          // private static final int IMAGETYPE_withAlpha =
105            // BufferedImage.TYPE_INT_ARGB;
106            private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
107            public XMapPaneTool getTool() {
108                    return tool;
109            }
110    
111            private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;
112    
113          private static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
114    
115            /**
116             * A flag indicating whether the {@link XMapPane} is accepting repaints from
117             * the EDT. @see {@link XMapPane#setPainting(boolean))
118             **/
119          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
120    
121          /**          /**
# Line 125  public class XMapPane extends JPanel { Line 140  public class XMapPane extends JPanel {
140           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
141           * renderers have finished.           * renderers have finished.
142           *           *
143           * @see #INITIAL_REPAINT_DELAYAL           * @see INITIAL_REPAINT_DELAYAL
144           * @see #REPEATING_REPAINT_DELAY           * @see #REPEATING_REPAINT_DELAY
145           */           */
146          final private Timer repaintTimer;          final private Timer repaintTimer;
# Line 134  public class XMapPane extends JPanel { Line 149  public class XMapPane extends JPanel {
149           * The initial delay in milliseconds until the {@link #finalImage} is           * The initial delay in milliseconds until the {@link #finalImage} is
150           * updated the first time.           * updated the first time.
151           */           */
152          public static final int INITIAL_REPAINT_DELAY = 1000;          public static final int INITIAL_REPAINT_DELAY = 900;
153    
154          /**          /**
155           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
156           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
157           * with previews.           * with previews.
158           */           */
159          public static final long REPEATING_REPAINT_DELAY = 500;          public static final int REPEATING_REPAINT_DELAY = 500;
160    
161          /**          /**
162           * Default delay (milliseconds) before the map will be redrawn when resizing           * Default delay (milliseconds) before the map will be redrawn when resizing
163           * the pane. This is to avoid flickering while drag-resizing.           * the pane. This is to avoid flickering while drag-resizing.
164             *
165             * @see #resizeTimer
166           */           */
167          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
168    
         public static final int NONE = -123;  
   
169          /**          /**
170           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl           * This not-repeating {@link Timer} is re-started whenever the component is
171           * moeglich!           * resized. That means => only if the component is not resizing for
172           *           * {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the
173           * @see #setState(int)           * {@link XMapPane} react.
174           */           */
175          public static final int PAN = 1;          private final Timer resizeTimer;
176    
177          /**          /**
178           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".           * Flag for no-tool.
          *  
          * @see #setState(int)  
          * @see #setState(int)  
179           */           */
180          public static final int SELECT_ALL = 103;          public static final int NONE = -123;
181    //
182    //      /**
183    //       * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
184    //       * moeglich!
185    //       *
186    //       * @see #setState(int)
187    //       */
188    //      public static final int PAN = 1;
189    //
190    //      /**
191    //       * Flag fuer Modus "Heran zoomen".
192    //       *
193    //       * @see #setState(int)
194    //       * @see #setState(int)
195    //       */
196    //      public static final int ZOOM_IN = 2;
197    //
198    //      /**
199    //       * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
200    //       *
201    //       * @see #setState(int)
202    //       */
203    //      public static final int ZOOM_OUT = 3;
204    
205          /**          /**
206           * Flag fuer Modus           * {@link Font} used to paint the wait messages into the map
          * "Auswahl nur eines Features, das erste sichtbare von Oben".  
207           *           *
208           * @see #setState(int)           * @see #addGadgets(Graphics2D, boolean)
          * @see #setState(int)  
209           */           */
210          public static final int SELECT_ONE_FROM_TOP = 104;          final static Font waitFont = new Font("Arial", Font.BOLD, 28);
211    
212          /**          /**
213           * Flag fuer Modus           * {@link Font} used to paint error messages into the map
          * "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer".  
214           *           *
215           * @see #setState(int)           * @see #addGadgets(Graphics2D, boolean)
          * @see #setState(int)  
216           */           */
         public static final int SELECT_TOP = 4;  
   
         public static final Cursor WAIT_CURSOR = Cursor  
                         .getPredefinedCursor(Cursor.WAIT_CURSOR);  
   
         final static Font waitFont = new Font("Arial", Font.BOLD, 30);  
         final String waitMsg = SwingUtil.R("WaitMess");  
217          final static Font errorFont = new Font("Arial", Font.BOLD, 13);          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
218    
219          /**          /**
220           * Flag fuer Modus "Heran zoomen".           * If last average last two renderings took more than that many ms, show the
221           *           * user a scaled preview
222           * @see #setState(int)           **/
223           * @see #setState(int)          private static final long PRESCALE_MINTIME = 230;
          */  
         public static final int ZOOM_IN = 2;  
224    
225          /**          /**
226           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!           * The wait message painted into the map while rendering is going on on
227             * another thread.
228           *           *
229           * @see #setState(int)           * @see #addGadgets(Graphics2D, boolean)
230           */           */
231          public static final int ZOOM_OUT = 3;          final String waitMsg = SwingUtil.R("WaitMess");
232    
233          /**          /**
234           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in
# Line 212  public class XMapPane extends JPanel { Line 237  public class XMapPane extends JPanel {
237           * @param e           * @param e
238           *            Maus-Ereignis           *            Maus-Ereignis
239           */           */
240          public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {          public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) {
241                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln
242                  if (e != null && e instanceof MapMouseEvent)                  if (e != null && e instanceof MapMouseEvent)
243                          try {                          try {
244                                  return ((MapMouseEvent) e).getMapPosition().toPoint2D();                                  return ((MapMouseEvent) e).getMapPosition();
245                          } catch (final Exception err) {                          } catch (final Exception err) {
246                                  LOGGER                                  LOGGER
247                                                  .error(                                                  .error(
# Line 233  public class XMapPane extends JPanel { Line 258  public class XMapPane extends JPanel {
258                                  return null;                                  return null;
259    
260                          final AffineTransform at = xMapPane.getScreenToWorld();                          final AffineTransform at = xMapPane.getScreenToWorld();
261                          if (at != null)                          if (at != null) {
262                                  return at.transform(e.getPoint(), null);                                  Point2D transformed = at.transform(e.getPoint(), null);
263                                    return new DirectPosition2D(xMapPane.getMapContext()
264                                                    .getCoordinateReferenceSystem(), transformed.getX(),
265                                                    transformed.getY());
266                            }
267                          return null;                          return null;
268                  }                  }
269                  throw new IllegalArgumentException(                  throw new IllegalArgumentException(
# Line 249  public class XMapPane extends JPanel { Line 278  public class XMapPane extends JPanel {
278    
279                  @Override                  @Override
280                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
281                            final MapLayer layer = event.getLayer();
                         MapLayer layer = event.getLayer();  
   
282                          layer.addMapLayerListener(bgMapLayerListener);                          layer.addMapLayerListener(bgMapLayerListener);
   
                         if (localContext.getLayers().length == 0  
                                         && bgContext.getLayers().length == 1) { // the first one and  
                                 // localContext is  
                                 // empty  
                                 if (!setMapArea(localContext.getAreaOfInterest()))  
                                         requestStartRendering();  
                                 return;  
                         }  
   
                         // We need to redraw, even in case that the mapArea didn't change  
                         // mapImageInvalid = true;  
                         // repaint();  
283                          requestStartRendering();                          requestStartRendering();
   
284                  }                  }
285    
286                  @Override                  @Override
287                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
288                          requestStartRendering();                          requestStartRendering();
289                  }                  }
290    
291                  @Override                  @Override
292                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
293                          requestStartRendering();                          requestStartRendering();
294                  }                  }
295    
# Line 288  public class XMapPane extends JPanel { Line 297  public class XMapPane extends JPanel {
297                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
298                          if (event.getLayer() != null)                          if (event.getLayer() != null)
299                                  event.getLayer().removeMapLayerListener(bgMapLayerListener);                                  event.getLayer().removeMapLayerListener(bgMapLayerListener);
                         // mapImageInvalid = true;  
                         // repaint();  
300                          requestStartRendering();                          requestStartRendering();
301                  }                  }
302          };          };
# Line 317  public class XMapPane extends JPanel { Line 324  public class XMapPane extends JPanel {
324           * {@link Image}.           * {@link Image}.
325           */           */
326          private BufferedImage bgImage;          private BufferedImage bgImage;
327            
328          /**          /**
329           * This {@link Image} is a merge of the {@link #bgImage},           * This {@link Image} is a merge of the {@link #bgImage},
330           * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is           * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
# Line 326  public class XMapPane extends JPanel { Line 333  public class XMapPane extends JPanel {
333           */           */
334          private BufferedImage finalImage;          private BufferedImage finalImage;
335    
   
336          /**          /**
337           * Optionally a transparent image to paint over the map in the lower right           * Optionally a transparent image to paint over the map in the lower right
338           * corner.           * corner.
# Line 368  public class XMapPane extends JPanel { Line 374  public class XMapPane extends JPanel {
374           * While dragging, the {@link #updateFinalImage()} method is translating the           * While dragging, the {@link #updateFinalImage()} method is translating the
375           * cached images while setting it together.           * cached images while setting it together.
376           **/           **/
377          Point imageOrigin = new Point(0, 0);          private final Point imageOrigin = new Point(0, 0);
378          /**          /**
379           * For every rendering thread started,           * For every rendering thread started,
380           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new
# Line 390  public class XMapPane extends JPanel { Line 396  public class XMapPane extends JPanel {
396                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
397                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
398    
399                          localRenderer.setContext(getContext());                          getLocalRenderer().setContext(getMapContext());
   
                         if (localContext.getLayers().length == 1) { // the first one  
   
                                 // if the Area of Interest is unset, the LayerBounds are used  
                                 if (!setMapArea(localContext.getAreaOfInterest()))  
                                         repaint();  
   
                                 return;  
                         }  
   
                         // We need to redraw, even in case that the mapArea didn't change  
                         // mapImageInvalid = true;  
                         // repaint();  
400                          requestStartRendering();                          requestStartRendering();
401    
402                  }                  }
403    
404                  @Override                  @Override
405                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
406                          // mapImageInvalid = true;                          // getLocalRenderer().setContext(getMapContext()); geht doch auch
407                          // repaint();                          // ohne?!?!? wow...
                         localRenderer.setContext(getContext());  
408                          requestStartRendering();                          requestStartRendering();
409                  }                  }
410    
411                  @Override                  @Override
412                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
413                          // mapImageInvalid = true;                          getLocalRenderer().setContext(getMapContext());
                         // repaint();  
                         localRenderer.setContext(getContext());  
414                          requestStartRendering();                          requestStartRendering();
415                  }                  }
416    
# Line 428  public class XMapPane extends JPanel { Line 418  public class XMapPane extends JPanel {
418                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
419                          if (event.getLayer() != null)                          if (event.getLayer() != null)
420                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
421                          // mapImageInvalid = true;                          getLocalRenderer().setContext(getMapContext());
                         // repaint();  
                         localRenderer.setContext(getContext());  
422                          requestStartRendering();                          requestStartRendering();
423                  }                  }
424          };          };
425    
426          /**          /**
427           * Listens to each layer in the local {@link MapContext} for changes and           * Listens to each layer in the local {@link MapContext} for changes and
428           * triggers repaints.           * triggers repaints. We don't have to listen layerChanged, because that is
429             * already done in {@link #localContextListener}
430           */           */
431          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
432    
433                  @Override                  // @Override
434                  public void layerChanged(final MapLayerEvent event) {                  // public void layerChanged(final MapLayerEvent event) {
435                          localRenderer.setContext(getContext()); // betters for SLD changes?!                  // // getLocalRenderer().setContext(getMapContext()); // betters for SLD
436                          // Change of SLD for example                  // // // changes?!
437                          // mapImageInvalid = true;                  // // requestStartRendering();
438                          // repaint();                  // }
                         requestStartRendering();  
                 }  
439    
440                  @Override                  @Override
441                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
442                          requestStartRendering();                          requestStartRendering();
443                  }                  }
444    
445                  @Override                  @Override
446                  public void layerShown(final MapLayerEvent event) {                  public void layerShown(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
447                          requestStartRendering();                          requestStartRendering();
448                  }                  }
449          };          };
450    
451          private final GTRenderer localRenderer = GTUtil.createGTRenderer();          final private GTRenderer localRenderer = GTUtil.createGTRenderer();
452    
453          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
454    
# Line 486  public class XMapPane extends JPanel { Line 469  public class XMapPane extends JPanel {
469          /**          /**
470           * This color is used as the default background color when painting a map.           * This color is used as the default background color when painting a map.
471           */           */
472          private Color mapBackgroundColor = Color.WHITE;          private Color mapBackgroundColor = null;
473    
474          /**          /**
475           * 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
# Line 530  public class XMapPane extends JPanel { Line 513  public class XMapPane extends JPanel {
513           * A flag indicating, that the image size has changed and the buffered           * A flag indicating, that the image size has changed and the buffered
514           * images are not big enough any more           * images are not big enough any more
515           **/           **/
516          protected boolean paneResized = false;          protected boolean paneResized = true;
517    
518          private BufferedImage preFinalImage;          private BufferedImage preFinalImage;
519    
520          // if null, no quick preview will be shown          // ** if 0, no quick preview will be shown **/
521          private int quickPreviewHint = 0;          // private int quickPreviewHint = 0;
522    
523          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
524                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(getLocalRenderer());
   
         /** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #localImage} **/  
         private volatile Boolean requestStartRenderingLocal = false;  
           
         /** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #bgImage} **/  
         private volatile Boolean requestStartRenderingBg = false;  
525    
526          private final Timer resizeTimer;          /**
527             * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
528             * start rendering {@link Thread}s
529             **/
530            private volatile Boolean requestStartRendering = false;
531    
532          /**          /**
533           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
# Line 555  public class XMapPane extends JPanel { Line 536  public class XMapPane extends JPanel {
536          protected AffineTransform screenToWorld = null;          protected AffineTransform screenToWorld = null;
537    
538          /**          /**
539           * The flag {@link #requestStartRenderingLocal} can be set to true by events.           * The flag {@link #requestStartRendering} can be set to true by events.
540           * This {@link Timer} checks the flag regularly and starts one renderer           * This {@link Timer} checks the flag regularly and starts one renderer
541           * thread.           * thread.
542           */           */
543          final private Timer startRenderThreadsTimer;          final private Timer startRenderThreadsTimer;
544    //
545          /**  //      /**
546           * The default state is ZOOM_IN, hence by default the  //       * The default state is ZOOM_IN, hence by default the
547           * {@link #zoomMapPaneMouseListener} is also enabled.  //       * {@link #xMapPaneMouseListener} is also enabled.
548           **/  //       **/
549          private int state = ZOOM_IN;  //      private int state = ZOOM_IN;
550    //
551          /**  //      /**
552           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen  //       * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
553           * MapPane-Funktion  //       * MapPane-Funktion
554           */  //       */
555          protected Cursor staticCursor = null;  //      protected Cursor staticCursor = null;
556    
557          private AffineTransform worldToScreen;          private AffineTransform worldToScreen;
558    
559            // /**
560            // * This {@link MouseListener} is managing all zoom related tasks
561            // */
562            // private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new
563            // ZoomXMapPaneMouseListener(
564            // this);
565    
566          /**          /**
567           * This {@link MouseListener} is managing all zoom related tasks           * This {@link MouseListener} is managing all zoom related tasks
568           */           */
569          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(
570                          this);                          this);
571    
572          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
573          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
574    
575            /**
576             * If <code>true</code>, then rendering exceptions are rendererd into the
577             * map pane
578             **/
579            private boolean showExceptions = false;
580    
581          public XMapPane() {          public XMapPane() {
582                  this(null, null);                  this(null, null);
583          }          }
# Line 614  public class XMapPane extends JPanel { Line 608  public class XMapPane extends JPanel {
608                  /**                  /**
609                   * Adding the #zoomMapPaneMouseListener                   * Adding the #zoomMapPaneMouseListener
610                   */                   */
611                  this.addMouseListener(zoomMapPaneMouseListener);                  this.addMouseListener(xMapPaneMouseListener);
612                  this.addMouseMotionListener(zoomMapPaneMouseListener);                  this.addMouseMotionListener(xMapPaneMouseListener);
613                  this.addMouseWheelListener(zoomMapPaneMouseListener);                  this.addMouseWheelListener(xMapPaneMouseListener);
614                    
615                    // By default the XMapPAne uses the ZOOM_IN tool.
616                    setTool(XMapPaneTool.ZOOM_IN);
617                    
618                  /*                  /*
619                   * We use a Timer object to avoid rendering delays and flickering when                   * We use a Timer object to avoid rendering delays and flickering when
620                   * the user is drag-resizing the parent container of this map pane.                   * the user is drag-resizing the parent container of this map pane.
# Line 629  public class XMapPane extends JPanel { Line 626  public class XMapPane extends JPanel {
626                                  new ActionListener() {                                  new ActionListener() {
627    
628                                          public void actionPerformed(final ActionEvent e) {                                          public void actionPerformed(final ActionEvent e) {
                                                 paneResized = true;  
   
629                                                  if (!isWellDefined())                                                  if (!isWellDefined())
630                                                          return;                                                          return;
631    
632                                                  final Rectangle bounds = getVisibleRect();                                                  // LOGGER.debug("resizeTimer performed");
633    
634                                                  final Envelope geoMapArea = tranformWindowToGeo(                                                  // final Rectangle bounds = getVisibleRect();
635                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                  //
636                                                                  bounds.y + bounds.height);                                                  // System.out.println("\n\ntimer performs with bounds = "
637                                                    // + bounds);
638    
639                                                    // final Envelope geoMapArea = tranformWindowToGeo(
640                                                    // bounds.x, bounds.y, bounds.x + bounds.width,
641                                                    // bounds.y + bounds.height);
642    
643                                                    paneResized = true;
644                                                    if (!setMapArea(getMapArea())) {
645                                                            // It's important to request new rendering here.
646                                                            // setMapArea only returns true and only calls
647                                                            // requestStartRendering if the maparea has changed.
648                                                            // But if the component is resized, the maparea
649                                                            // doesn't have to change.
650                                                            requestStartRendering();
651                                                    }
652    
                                                 setMapArea(bestAllowedMapArea(geoMapArea));  
653                                          }                                          }
654                                  });                                  });
655                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
656                    
657  //              this.addComponentListener(new ComponentAdapter() {                  this.addComponentListener(new ComponentAdapter() {
658  //  
659  //                      @Override                          private Rectangle oldVisibleRect;
660  //                      public void componentResized(final ComponentEvent e) {  
661  //                              if (bgExecuter != null)                          @Override
662  //                                      bgExecuter.cancelTask();                          public void componentResized(final ComponentEvent e) {
663  //                              if (localExecuter != null)  
664  //                                      localExecuter.cancelTask();                                  // Seems to be called twice with the same size..
665  //                              resizeTimer.restart();                                  if (oldVisibleRect != null
666  //                      }                                                  && oldVisibleRect.equals(getVisibleRect())) {
667  //                                          // LOGGER.debug("skipping resize.");
668  //              });                                          return;
669                                    }
670    
671                                    // LOGGER.debug("resized: " + getVisibleRect());
672                                    resizeTimer.restart();
673                                    oldVisibleRect = getVisibleRect();
674                            }
675    
676                    });
677    
678                  /*                  /*
679                   * Setting up the repaintTimer. Not started automatically.                   * Setting up the repaintTimer. Not started automatically.
680                   */                   */
681                  repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY,                  repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
682                                  new ActionListener() {  
683                            @Override
684                            public void actionPerformed(final ActionEvent e) {
685                                    if ((!localExecuter.isRunning())
686                                                    && (bgExecuter != null && !bgExecuter.isRunning())) {
687                                            repaintTimer.stop();
688                                    } else {
689                                            updateFinalImage();
690                                            XMapPane.this.repaint(100);
691    
692                                    }
693                            }
694                    });
695    
                                         @Override  
                                         public void actionPerformed(final ActionEvent e) {  
                                                 updateFinalImage();  
                                                 XMapPane.this.repaint();  
                                         }  
                                 });  
696                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
697                  repaintTimer.setRepeats(true);                  repaintTimer.setRepeats(true);
698    
# Line 681  public class XMapPane extends JPanel { Line 704  public class XMapPane extends JPanel {
704    
705                          @Override                          @Override
706                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
707                                  synchronized (requestStartRenderingLocal) {                                  synchronized (requestStartRendering) {
708                                          if (requestStartRenderingLocal && isWellDefined()) {                                          if (requestStartRendering && isWellDefined()) {
709    
710                                                  if (localExecuter.isRunning()) {                                                  if (localExecuter.isRunning()) {
711                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
712                                                  } else {                                                  } else {
713                                                          requestStartRenderingLocal = false;                                                          // Stupidly, but we have to recheck the
714                                                            setMapArea(getMapArea());
715                                                            requestStartRendering = false;
716                                                          startRendering();                                                          startRendering();
717                                                  }                                                  }
718                                          }                                          }
# Line 719  public class XMapPane extends JPanel { Line 744  public class XMapPane extends JPanel {
744           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
745           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
746           */           */
747          public Envelope bestAllowedMapArea(Envelope env) {          public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
748                  // return env;  
749                  if (getWidth() == 0)                  if (getWidth() == 0)
750                          return env;                          return env;
751    
752                  if (env == null)                  if (env == null)
753                          return null;                          return null;
754    
# Line 772  public class XMapPane extends JPanel { Line 798  public class XMapPane extends JPanel {
798                  }                  }
799    
800                  final Envelope maxAllowedExtend = getMaxExtend();                  final Envelope maxAllowedExtend = getMaxExtend();
801    
802                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
803                                  && newArea != null && !newArea.isNull()                                  && newArea != null && !newArea.isNull()
804                                  && !Double.isNaN(newArea.getMinX())                                  && !Double.isNaN(newArea.getMinX())
# Line 801  public class XMapPane extends JPanel { Line 828  public class XMapPane extends JPanel {
828    
829                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
830    
831                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
832                                                          false);                                                          new ReferencedEnvelope(newArea, env
833                                                                            .getCoordinateReferenceSystem()), false);
834                                  }                                  }
835                          }                          }
836    
# Line 825  public class XMapPane extends JPanel { Line 853  public class XMapPane extends JPanel {
853    
854                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
855    
856                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
857                                                          false);                                                          new ReferencedEnvelope(newArea, env
858                                                                            .getCoordinateReferenceSystem()), false);
859                                  }                                  }
860                          }                          }
861    
# Line 851  public class XMapPane extends JPanel { Line 880  public class XMapPane extends JPanel {
880    
881                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
882    
883                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
884                                                          false);                                                          new ReferencedEnvelope(newArea, env
885                                                                            .getCoordinateReferenceSystem()), false);
886                                  }                                  }
887                          }                          }
888    
# Line 877  public class XMapPane extends JPanel { Line 907  public class XMapPane extends JPanel {
907    
908                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
909    
910                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
911                                                          false);                                                          new ReferencedEnvelope(newArea, env
912                                                                            .getCoordinateReferenceSystem()), false);
913                                  }                                  }
914                          }                          }
915                  }                  }
916    
917                  return newArea;                  return new ReferencedEnvelope(newArea, env
918                                    .getCoordinateReferenceSystem());
919          }          }
920    
921          /**          /**
# Line 911  public class XMapPane extends JPanel { Line 943  public class XMapPane extends JPanel {
943                          bgExecuter.dispose();                          bgExecuter.dispose();
944                  }                  }
945    
946                  if (localExecuter != null) {                  if (localExecuter.isRunning()) {
947                          int i = 0;                          int i = 0;
948                          localExecuter.cancelTask();                          localExecuter.cancelTask();
949                          while (i++ < 10 && localExecuter.isRunning()) {                          while (i++ < 10 && localExecuter.isRunning()) {
# Line 936  public class XMapPane extends JPanel { Line 968  public class XMapPane extends JPanel {
968                  // Remove all mapPaneListeners that have registered with us                  // Remove all mapPaneListeners that have registered with us
969                  mapPaneListeners.clear();                  mapPaneListeners.clear();
970    
971                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(xMapPaneMouseListener);
972                  removeMouseListener(zoomMapPaneMouseListener);                  removeMouseListener(xMapPaneMouseListener);
973    
974                  if (localContext != null)                  if (localContext != null)
975                          getContext().clearLayerList();                          getMapContext().clearLayerList();
976                  if (bgContext != null)                  if (bgContext != null)
977                          getBgContext().clearLayerList();                          getBgContext().clearLayerList();
978    
# Line 953  public class XMapPane extends JPanel { Line 985  public class XMapPane extends JPanel {
985           */           */
986          protected void drawRectangle(final Graphics graphics, final Point startPos,          protected void drawRectangle(final Graphics graphics, final Point startPos,
987                          final Point e) {                          final Point e) {
988                    drawRectangle(graphics, startPos, e, Color.WHITE, false);
989            }
990    
991            /**
992             * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
993             * given point. All in screen coordinates.
994             */
995            protected void drawRectangle(final Graphics graphics, final Point startPos,
996                            final Point e, Color color, boolean fill) {
997    
998                  if (!isWellDefined())                  if (!isWellDefined())
999                          return;                          return;
# Line 968  public class XMapPane extends JPanel { Line 1009  public class XMapPane extends JPanel {
1009                  if (width == 0 && height == 0)                  if (width == 0 && height == 0)
1010                          return;                          return;
1011    
1012                  graphics.setXORMode(Color.WHITE);                  graphics.setXORMode(color);
1013                    
1014                    if (fill) {
1015                            graphics.fillRect(left, bottom, width, height);
1016                            graphics.setXORMode(Color.WHITE);      
1017                    }
1018                    
1019                    
1020                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
1021          }          }
1022    
# Line 980  public class XMapPane extends JPanel { Line 1028  public class XMapPane extends JPanel {
1028           *           *
1029           * @param g           * @param g
1030           *            Graphics2D to paint the preview into           *            Graphics2D to paint the preview into
          *  
          * @param state  
          *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}  
1031           */           */
1032          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
1033    
1034                  // if (1 == 1)return false;                  // if (1 == 1)return false;
1035                    // if (quickPreviewHint == 0)
1036                    // return false;
1037    
1038                  if (quickPreviewHint == 0)                  if (oldMapArea == null)
1039                          return false;                          return false;
1040    
1041                  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                  if (getPreFinalImage() == null)
                                 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)  
1042                          return false;                          return false;
1043    
1044                  final Rectangle visibleArea = getVisibleRect();                  final Rectangle visibleArea = getVisibleRect();
# Line 1013  public class XMapPane extends JPanel { Line 1053  public class XMapPane extends JPanel {
1053                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1054                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1055    
1056                    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1057                                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1058                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1059                                    RenderingHints.VALUE_ANTIALIAS_OFF);
1060                    graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1061                                    RenderingHints.VALUE_RENDER_SPEED);
1062    
1063                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1064                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1065                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
# Line 1021  public class XMapPane extends JPanel { Line 1068  public class XMapPane extends JPanel {
1068                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1069                                  - yy1);                                  - yy1);
1070    
1071                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea,
1072                                    getMapBackgroundColor());
1073    
1074                  addGadgets(graphics, true);                  addGadgets(graphics, true);
1075    
1076                  quickPreviewHint = 0;                  // quickPreviewHint = 0;
1077    
1078                  repaintTimer.restart();                  repaintTimer.restart();
1079    
                 graphics.dispose();  
   
1080                  // Something has been drawn                  // Something has been drawn
1081                  return true;                  return true;
1082          }          }
# Line 1043  public class XMapPane extends JPanel { Line 1089  public class XMapPane extends JPanel {
1089           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1090           */           */
1091          private Image getBgImage() {          private Image getBgImage() {
1092                  //                  if (bgImage == null) {
1093                  // if (bgImage == null) {                          bgImage = new BufferedImage(getVisibleRect().width,
1094                  // bgImage = createImage(getBounds().width, getBounds().height);                                          getVisibleRect().height, IMAGETYPE);
1095                  // }                          SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1096                    }
1097    
1098                  return bgImage;                  return bgImage;
1099          }          }
1100    
1101          public MapContext getContext() {          public MapContext getMapContext() {
1102                  if (localContext == null) {                  if (localContext == null) {
1103                          setLocalContext(new DefaultMapContext());                          setLocalContext(new DefaultMapContext());
1104                  }                  }
# Line 1064  public class XMapPane extends JPanel { Line 1111  public class XMapPane extends JPanel {
1111                          // Rectangle curPaintArea = getVisibleRect();                          // Rectangle curPaintArea = getVisibleRect();
1112                          finalImage = new BufferedImage(getVisibleRect().width,                          finalImage = new BufferedImage(getVisibleRect().width,
1113                                          getVisibleRect().height, IMAGETYPE);                                          getVisibleRect().height, IMAGETYPE);
1114                            SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1115    
1116                          requestStartRendering();                          // requestStartRendering();
1117                  }                  }
1118                  return finalImage;                  return finalImage;
1119          }          }
1120    
         public RenderingHints getJava2dHints() {  
                 return java2dHints;  
         }  
   
1121          /**          /**
1122           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1123           */           */
# Line 1082  public class XMapPane extends JPanel { Line 1126  public class XMapPane extends JPanel {
1126                  if (localImage == null) {                  if (localImage == null) {
1127                          localImage = new BufferedImage(getVisibleRect().width,                          localImage = new BufferedImage(getVisibleRect().width,
1128                                          getVisibleRect().height, IMAGETYPE_withAlpha);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1129                            SwingUtil.clearImage(localImage, getMapBackgroundColor());
1130                  }                  }
1131    
1132                  return localImage;                  return localImage;
# Line 1097  public class XMapPane extends JPanel { Line 1142  public class XMapPane extends JPanel {
1142                          ReferencedEnvelope mapArea_ = null;                          ReferencedEnvelope mapArea_ = null;
1143                          try {                          try {
1144                                  mapArea_ = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1145                          } catch (final IOException e) {                          } catch (final Exception e) {
1146                                  LOGGER.warn("context.getLayerBounds()", e);                                  LOGGER.warn("localContext.getLayerBounds()", e);
1147                            }
1148    
1149                            if (mapArea_ == null && bgContext != null) {
1150                                    try {
1151                                            mapArea_ = bgContext.getLayerBounds();
1152                                    } catch (final IOException e) {
1153                                            LOGGER.warn("bgContext.getLayerBounds()", e);
1154                                    }
1155                          }                          }
1156    
1157                          if (mapArea_ != null) {                          if (mapArea_ != null) {
                                 mapImageInvalid = true; /* note we need to redraw */  
                                 // setMapArea(mapArea_); // results in a loop  
1158                                  mapArea = bestAllowedMapArea(mapArea_);                                  mapArea = bestAllowedMapArea(mapArea_);
1159                                    requestStartRendering();
1160                          }                          }
1161                  }                  }
1162    
# Line 1116  public class XMapPane extends JPanel { Line 1168  public class XMapPane extends JPanel {
1168                          try {                          try {
1169                                  localContext.setCoordinateReferenceSystem(GeoImportUtil                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1170                                                  .getDefaultCRS());                                                  .getDefaultCRS());
1171                          } catch (Exception e) {                          } catch (final Exception e) {
1172                                  throw new RuntimeException("setting context CRS:", e);                                  throw new RuntimeException("setting context CRS:", e);
1173                          }                          }
1174    
# Line 1125  public class XMapPane extends JPanel { Line 1177  public class XMapPane extends JPanel {
1177          }          }
1178    
1179          /**          /**
1180           * Returns the background {@link Color} of the map pane. Default is white.           * Returns the background {@link Color} of the map pane. If not set, the
1181             * methods looks for a parent component and will use its background color.
1182             * If no parent component is available, WHITE is returned.
1183           **/           **/
1184          public Color getMapBackgroundColor() {          public Color getMapBackgroundColor() {
1185                    if (mapBackgroundColor == null) {
1186                            if (getParent() != null)
1187                                    return getParent().getBackground();
1188                            else
1189                                    return Color.WHITE;
1190                    }
1191                  return mapBackgroundColor;                  return mapBackgroundColor;
1192          }          }
1193    
# Line 1154  public class XMapPane extends JPanel { Line 1214  public class XMapPane extends JPanel {
1214    
1215          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1216                  if (maxExtend == null) {                  if (maxExtend == null) {
1217    
1218                            // The next command may take long time!
1219                            // long start = System.currentTimeMillis();
1220                          final ReferencedEnvelope layerBounds = GTUtil                          final ReferencedEnvelope layerBounds = GTUtil
1221                                          .getVisibleLayoutBounds(localContext);                                          .getVisibleLayoutBounds(localContext);
1222                            //                      
1223                            // LOGGER.info(
1224                            // (System.currentTimeMillis()-start)+"m to get maxExtend");
1225                            //                      
1226                          if (layerBounds == null) {                          if (layerBounds == null) {
1227                                  // TODO Last fallback could be the CRS valid area                                  // // TODO Last fallback could be the CRS valid area
1228                                  return null;                                  return null;
1229                          }                          }
1230    
1231                          // Kartenbereich um 10% vergroessern                          // Vergrößerung um 10% nochmal rausgenommen
1232                          return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil                          // // // Kartenbereich um 10% vergroessern
1233                                          .expandEnvelope(layerBounds, 0.1), true);                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1234                            // .expandEnvelope(layerBounds, 0.1), true);
1235    
1236                            return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true);
1237                  }                  }
1238                  return maxExtend;                  return maxExtend;
1239          }          }
# Line 1191  public class XMapPane extends JPanel { Line 1261  public class XMapPane extends JPanel {
1261          }          }
1262    
1263          private Image getPreFinalImage() {          private Image getPreFinalImage() {
                 // if (preFinalImage == null) {  
                 //                        
                 // // Rectangle curPaintArea = getVisibleRect();  
                 // // preFinalImage = new BufferedImage(curPaintArea.width,  
                 // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);  
                 //                        
                 // preFinalImage = createImage(getBounds().width, getBounds().height);  
                 //  
                 // requestStartRendering();  
                 // }  
1264                  return preFinalImage;                  return preFinalImage;
1265          }          }
1266    
# Line 1228  public class XMapPane extends JPanel { Line 1288  public class XMapPane extends JPanel {
1288                  return new AffineTransform(screenToWorld);                  return new AffineTransform(screenToWorld);
1289          }          }
1290    
1291          public int getState() {  //      public int getState() {
1292                  return state;  //              return state;
1293          }  //      }
1294    //
1295          /**  //      /**
1296           * Liefert den statisch eingestellten Cursor, der unabhaengig von der  //       * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1297           * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.  //       * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1298           *  //       *
1299           * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der  //       * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der
1300           *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.  //       *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1301           */  //       */
1302          public Cursor getStaticCursor() {  //      public Cursor getStaticCursor() {
1303                  return this.staticCursor;  //              return this.staticCursor;
1304          }  //      }
1305    
1306          public AffineTransform getWorldToScreenTransform() {          public AffineTransform getWorldToScreenTransform() {
1307                  if (worldToScreen == null) {                  if (worldToScreen == null) {
# Line 1277  public class XMapPane extends JPanel { Line 1337  public class XMapPane extends JPanel {
1337           * {@link XMapPane} is visible and has bounds set.           * {@link XMapPane} is visible and has bounds set.
1338           */           */
1339          public boolean isWellDefined() {          public boolean isWellDefined() {
   
1340                  try {                  try {
1341                            if (getMapContext() == null)
                         if (getContext() == null)  
                                 return false;  
                         if (getContext().getLayerCount() <= 0)  
1342                                  return false;                                  return false;
1343                          if (getMapArea() == null)                          if (getMapContext().getLayerCount() <= 0)
1344                                  return false;                                  return false;
1345                          if (getBounds().getWidth() == 0)                          if (getVisibleRect().getWidth() == 0)
1346                                  return false;                                  return false;
1347                          if (getBounds().getHeight() == 0)                          if (getVisibleRect().getHeight() == 0)
1348                                  return false;                                  return false;
1349                            // if (getMapArea() == null)
1350                            // return false;
1351                  } catch (final Exception e) {                  } catch (final Exception e) {
1352                          return false;                          return false;
1353                  }                  }
1354                  return true;                  return true;
1355          }          }
1356    
1357          public void mouseDragged(final Point startPos, final Point lastPos,          /**
1358                          final MouseEvent event) {           * Usually called from {@link XMapPaneAction_Pan} to pan the image.
1359             *
1360                  if ((getState() == XMapPane.PAN)           * @param startPos
1361                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {           *            in screen coordinates
1362             * @param lastPos
1363                          if (getCursor() != SwingUtil.PANNING_CURSOR) {           *            in screen coordinates
1364                                  setCursor(SwingUtil.PANNING_CURSOR);           */
1365            public void pan(final int dX, final int dY) {
1366                                  // While panning, we deactivate the rendering. So the tasts are  
1367                                  // ready to start when the panning os done.                  // Panning needs a panning coursor
1368                                  if (bgExecuter != null)                  if (getCursor() != SwingUtil.PANNING_CURSOR) {
1369                                          bgExecuter.cancelTask();                          setCursor(SwingUtil.PANNING_CURSOR);
1370                                  if (localExecuter != null)  
1371                                          localExecuter.cancelTask();                          // While panning, we deactivate the rendering. So the tasks are
1372                          }                          // ready to start when the panning is finished.
1373                            if (bgExecuter != null && bgExecuter.isRunning())
1374                          if (lastPos.x > 0 && lastPos.y > 0) {                                  bgExecuter.cancelTask();
1375                                  final int dx = event.getX() - lastPos.x;                          if (localExecuter.isRunning())
1376                                  final int dy = event.getY() - lastPos.y;                                  localExecuter.cancelTask();
   
                                 // 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);  
                         }  
   
                         graphics.dispose();  
   
1377                  }                  }
1378                    //
1379                    // if (lastPos.x > 0 && lastPos.y > 0) {
1380                    // final int dx = event.getX() - lastPos.x;
1381                    // final int dy = event.getY() - lastPos.y;
1382    
1383                    // TODO Stop dragging when the drag would not be valid...
1384                    // boolean dragValid = true;
1385                    // // check if this panning results in a valid mapArea
1386                    // {
1387                    // Rectangle winBounds = xMapPane.getBounds();
1388                    // winBounds.translate(xMapPane.imageOrigin.x,
1389                    // -xMapPane.imageOrigin.y);
1390                    // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(
1391                    // winBounds.x, winBounds.y, winBounds.x
1392                    // + winBounds.width, winBounds.y
1393                    // + winBounds.height);
1394                    //                                      
1395                    //
1396                    // winBounds = xMapPane.getBounds();
1397                    // Point testIng = new Point(xMapPane.imageOrigin);
1398                    // testIng.translate(dx, dy);
1399                    // winBounds.translate(testIng.x, -testIng.y);
1400                    // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(
1401                    // winBounds.x, winBounds.y, winBounds.x
1402                    // + winBounds.width, winBounds.y
1403                    // + winBounds.height);
1404                    //
1405                    // // If the last drag doesn't change the MapArea anymore cancel
1406                    // it.
1407                    // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(
1408                    // xMapPane.bestAllowedMapArea(newMapAreaBefore))){
1409                    // dragValid = false;
1410                    // return;
1411                    // }
1412                    // }
1413    
1414                    getImageOrigin().translate(dX, dY);
1415                    updateFinalImage();
1416                    repaint();
1417                    // }
1418    
1419                    // } else if ((getState() == XMapPane.ZOOM_IN)
1420                    // || (getState() == XMapPane.ZOOM_OUT)
1421                    // || (getState() == XMapPane.SELECT_ALL)
1422                    // || (getState() == XMapPane.SELECT_TOP)) {
1423                    //
1424                    // // Draws a rectangle
1425                    // final Graphics2D graphics = (Graphics2D) getGraphics();
1426                    // drawRectangle(graphics, startPos, event.getPoint());
1427                    // if ((lastPos.x > 0) && (lastPos.y > 0))
1428                    // drawRectangle(graphics, startPos, lastPos);
1429                    // graphics.dispose();
1430                    // }
1431          }          }
1432    
1433          /**          /**
1434           * Called by the {@link RenderingExecutor} when rendering was cancelled.           * Called by the {@link RenderingExecutor} when rendering was cancelled.
1435           */           */
1436          public void onRenderingCancelled() {          public void onRenderingCancelled() {
1437                    // LOGGER.debug("Rendering cancelled");
1438                  repaintTimer.stop();                  repaintTimer.stop();
                 LOGGER.debug("Rendering cancelled");  
1439          }          }
1440    
1441          /**          /**
1442           * Called by the {@link RenderingExecutor} when rendering has been           * Called by the {@link RenderingExecutor} when rendering has been
1443           * completed.           * completed.
1444             *
1445             * @param l
1446             *            long ms the rendering took
1447           */           */
1448          public void onRenderingCompleted() {          public void onRenderingCompleted(final long l) {
1449                    lastRenderingDuration = (lastRenderingDuration + l) / 2;
1450                    // LOGGER
1451                    // .debug("complete rendering after " + lastRenderingDuration
1452                    // + "ms");
1453    
1454                  repaintTimer.stop();                  repaintTimer.stop();
1455                  updateFinalImage();  
1456                  repaint();                  // We "forget" about an exception every time we complete a rendering
1457                    // thread successfully
1458                  if (renderingErrors.size() > 0)                  if (renderingErrors.size() > 0)
1459                          renderingErrors.remove(0);                          renderingErrors.remove(0);
1460    
1461                    updateFinalImage();
1462                    repaint();
1463          }          }
1464    
1465          /**          /**
# Line 1404  public class XMapPane extends JPanel { Line 1473  public class XMapPane extends JPanel {
1473           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1474           */           */
1475          public void onRenderingFailed(final Exception renderingError) {          public void onRenderingFailed(final Exception renderingError) {
1476                  this.renderingErrors.add(renderingError);  
1477                    // Store the exceptions so we can show it to the user:
1478                    if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError
1479                                    .getMessage().equals(
1480                                                    "Argument \"sourceCRS\" should not be null.")))
1481                            this.renderingErrors.add(renderingError);
1482                  if (renderingErrors.size() > 3)                  if (renderingErrors.size() > 3)
1483                          renderingErrors.remove(0);                          renderingErrors.remove(0);
1484    
1485                  repaintTimer.stop();                  repaintTimer.stop();
1486    
1487                  LOGGER.warn("Rendering failed", renderingError);                  LOGGER.warn("Rendering failed", renderingError);
1488                  updateFinalImage();                  updateFinalImage();
1489                  repaint();                  repaint();
1490    
1491          }          }
1492    
         public void onRenderingPending() {  
                 // LOGGER.debug("Pending rendering updates the preview...");  
                 updateFinalImage();  
                 repaint();  
         }  
   
1493          @Override          @Override
1494          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
                 if (!acceptsRepaintCalls)  
                         return;  
1495    
1496                  // Maybe update the cursor and maybe stop the repainting timer                  // Maybe update the cursor and maybe stop the repainting timer
1497                  updateCursor();                  updateCursor();
1498    
1499                    if (!acceptsRepaintCalls)
1500                            return;
1501    
1502                    if (!isWellDefined())
1503                            return;
1504                    //
1505                    // if (paneResized) {
1506                    // // ((Graphics2D) g).setBackground(getMapBackgroundColor());
1507                    // // g.clearRect(0, 0, getVisibleRect().width,
1508                    // getVisibleRect().height);
1509                    // return;
1510                    // }
1511    
1512                  // super.paintComponent(g); // candidate for removal                  // super.paintComponent(g); // candidate for removal
1513    
1514                  boolean paintedSomething = false;                  boolean paintedSomething = false;
# Line 1439  public class XMapPane extends JPanel { Line 1520  public class XMapPane extends JPanel {
1520                          // If the new mapArea and the oldMapArea intersect, we can draw some                          // If the new mapArea and the oldMapArea intersect, we can draw some
1521                          // quick scaled preview to make the user feel that something is                          // quick scaled preview to make the user feel that something is
1522                          // happening.                          // happening.
1523                          if (mapAreaChanged && oldMapArea != null                          if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged
1524                                            && oldMapArea != null
1525                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1526                                          & !getMapArea().equals(oldMapArea)) {                                          && !getMapArea().equals(oldMapArea) && !paneResized) {
1527    
1528                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1529    
1530                                  if (getMapArea().covers(oldMapArea)) {                                  // if (getMapArea().covers(oldMapArea)) {
1531                                          setQuickPreviewHint(ZOOM_OUT);                                  // // quickPreviewHint = ZOOM_OUT;
1532                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D)
1533                                  } else if (oldMapArea.covers(getMapArea())) {                                  // g);
1534                                          setQuickPreviewHint(ZOOM_IN);                                  // } else if (oldMapArea.covers(getMapArea())) {
1535                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // quickPreviewHint = ZOOM_IN;
1536                                  }                                  paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1537                                    // }
                         }  
   
                         if (paneResized) {  
                                 paneResized = false;  
                                 disposeImages();  
1538                          }                          }
   
                         // Start the Threads and Timers to render the image  
                         requestStartRendering();  
   
1539                  }                  }
1540    
1541                  if (!paintedSomething) {                  if (!paintedSomething) {
1542    
1543                          g.drawImage(getFinalImage(), 0, 0, null);                          g.drawImage(getFinalImage(), 0, 0, null);
1544    
                         g.dispose(); // cand. for removal  
   
1545                          paintedSomething = true; // cand. for removal                          paintedSomething = true; // cand. for removal
1546                  }                  }
1547    
# Line 1518  public class XMapPane extends JPanel { Line 1589  public class XMapPane extends JPanel {
1589                  }                  }
1590    
1591          }          }
1592    //
1593          /**  //      /**
1594           * Performs a {@value #PAN} action. During panning, the displacement is  //       * Performs a {@value #PAN} action. During panning, the displacement is
1595           * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will  //       * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
1596           * reset the offset and call {@link #setMapArea(Envelope)}.  //       * reset the offset and call {@link #setMapArea(Envelope)}.
1597           */  //       */
1598          public void performPan() {  //      public void performPan() {
1599    //
1600                  Rectangle winBounds = getVisibleRect();  //              final Rectangle winBounds = getVisibleRect();
1601    //
1602                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);  //              winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1603                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,  //              final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1604                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y  //                              winBounds.y, winBounds.x + winBounds.width, winBounds.y
1605                                                  + winBounds.height);  //                                              + winBounds.height);
1606    //
1607                  imageOrigin.x = 0;  //              imageOrigin.x = 0;
1608                  imageOrigin.y = 0;  //              imageOrigin.y = 0;
1609    //
1610                  if (!setMapArea(newMapArea)) {  //              if (!setMapArea(newMapArea)) {
1611                          /**  //                      /**
1612                           * If setMapArea returns true, the finalImage is updated anyways.  //                       * If setMapArea returns true, the finalImage is updated anyways.
1613                           * This if-case exists to ensure that we repaint a correct image  //                       * This if-case exists to ensure that we repaint a correct image
1614                           * even if the new panning area has been denied.  //                       * even if the new panning area has been denied.
1615                           */  //                       */
1616                          updateFinalImage();  //                      updateFinalImage();
1617                          repaint();  //                      repaint();
1618                  }  //              }
1619    //
1620                  if (getCursor() == SwingUtil.PANNING_CURSOR)  //              if (getCursor() == SwingUtil.PANNING_CURSOR)
1621                          setCursor(SwingUtil.PAN_CURSOR);  //                      setCursor(SwingUtil.PAN_CURSOR);
1622          }  //      }
   
         //  
         // /**  
         // * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot  
         // gemacht  
         // * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.  
         // *  
         // * @author <a href="mailto:[email protected]">Stefan Alfons  
         // * Kr&uuml;ger</a>  
         // */  
         // @Override  
         // public void print(final Graphics g) {  
         // final Color orig = getBackground();  
         // setBackground(Color.WHITE);  
         //  
         // // wrap in try/finally so that we always restore the state  
         // try {  
         // super.print(g);  
         // } finally {  
         // setBackground(orig);  
         // }  
         // }  
1623    
1624          /**          /**
1625           * Entfernt einen Listener von der Map.           * Entfernt einen Listener von der Map.
# Line 1590  public class XMapPane extends JPanel { Line 1639  public class XMapPane extends JPanel {
1639          private void requestStartRendering() {          private void requestStartRendering() {
1640                  if (bgExecuter != null)                  if (bgExecuter != null)
1641                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
                 if (localExecuter != null)  
                         localExecuter.cancelTask();  
                 requestStartRenderingLocal = true;  
1642    
1643          }                  localExecuter.cancelTask();
1644    
1645          //                  mapImageInvalid = true;
1646          // /**                  if (paneResized) {
1647          // * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten                          paneResized = false;
1648          // * neu.                          disposeImages();
1649          // */                  }
1650          // protected void resetTransforms() {                  requestStartRendering = true;
1651          // if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)  
1652          // return;          }
         //  
         // // We store the last Transform  
         // oldScreenToWorld = screenToWorld;  
         //  
         // this.screenToWorld = new AffineTransform(  
         // // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten  
         // // 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());  
         //  
         // try {  
         // this.worldToScreen = screenToWorld.createInverse();  
         // } catch (final NoninvertibleTransformException e) {  
         // LOGGER.error(e);  
         // }  
         // }  
1653    
1654          /**          /**
1655           * Calculate the affine transforms used to convert between world and pixel           * Calculate the affine transforms used to convert between world and pixel
# Line 1648  public class XMapPane extends JPanel { Line 1665  public class XMapPane extends JPanel {
1665           *            the current map pane extent (screen units)           *            the current map pane extent (screen units)
1666           */           */
1667          private void resetTransforms() {          private void resetTransforms() {
1668                  ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,                  // System.out
1669                                  getContext().getCoordinateReferenceSystem());                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1670                    if (!isWellDefined())
1671                            return;
1672    
1673                  Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!                  if (mapArea == null)
1674                            return;
1675    
1676                  //                          final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1677                  // double xscale = paintArea.getWidth() / refEnv.getWidth();                                  getMapContext().getCoordinateReferenceSystem());
                 // double yscale = paintArea.getHeight() / refEnv.getHeight();  
                 //  
                 // double scale = Math.min(xscale, yscale);  
                 //  
                 // double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();  
                 // double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();  
1678    
1679                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1680                                  paintArea);                                  getVisibleRect());
1681    
                 // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,  
                 // yoff);  
1682                  try {                  try {
1683                          screenToWorld = worldToScreen.createInverse();                          screenToWorld = worldToScreen.createInverse();
1684    
1685                  } catch (NoninvertibleTransformException ex) {                  } catch (final NoninvertibleTransformException ex) {
1686                          ex.printStackTrace();                          LOGGER
1687                                            .error("can't invert worldToScreen to get screenToWorld!",
1688                                                            ex);
1689                  }                  }
1690          }          }
1691    
# Line 1690  public class XMapPane extends JPanel { Line 1704  public class XMapPane extends JPanel {
1704                  this.bgContext = context;                  this.bgContext = context;
1705    
1706                  if (context != null) {                  if (context != null) {
1707                          setMapArea(bgContext.getAreaOfInterest());                          // setMapArea(bgContext.getAreaOfInterest());
1708    
1709                          this.bgContext.addMapLayerListListener(bgContextListener);                          this.bgContext.addMapLayerListListener(bgContextListener);
1710    
# Line 1699  public class XMapPane extends JPanel { Line 1713  public class XMapPane extends JPanel {
1713                                  mapLayer.addMapLayerListener(bgMapLayerListener);                                  mapLayer.addMapLayerListener(bgMapLayerListener);
1714                          }                          }
1715                  }                  }
1716                  mapImageInvalid = true;  
1717                  repaint();                  requestStartRendering();
1718          }          }
1719    
1720          public void setJava2dHints(final RenderingHints java2dHints) {          public void setJava2dHints(final RenderingHints java2dHints) {
1721                  this.java2dHints = java2dHints;                  this.java2dHints = java2dHints;
1722          }          }
1723    
         /**  
          *  
          * @param context  
          */  
1724          public void setLocalContext(final MapContext context) {          public void setLocalContext(final MapContext context) {
1725                  // Remove the default listener from the old context                  // Remove the default listener from the old context
1726                  if (this.localContext != null) {                  if (this.localContext != null) {
# Line 1726  public class XMapPane extends JPanel { Line 1736  public class XMapPane extends JPanel {
1736    
1737                  if (context != null) {                  if (context != null) {
1738    
1739                          setMapArea(localContext.getAreaOfInterest());                          // setMapArea(localContext.getAreaOfInterest());
1740    
1741                          localRenderer.setContext(localContext);                          getLocalRenderer().setContext(localContext);
1742    
1743                          this.localContext.addMapLayerListListener(localContextListener);                          this.localContext.addMapLayerListListener(localContextListener);
1744    
# Line 1738  public class XMapPane extends JPanel { Line 1748  public class XMapPane extends JPanel {
1748                          }                          }
1749                  }                  }
1750    
1751                    requestStartRendering();
1752    
1753            }
1754    
1755            public void setBorder(final Border b) {
1756                    super.setBorder(b);
1757            }
1758    
1759            /**
1760             * Triggers to repaint (fast) and re-render (slow) the JMapPane.
1761             */
1762            public void refresh() {
1763                  mapImageInvalid = true;                  mapImageInvalid = true;
1764                  repaint();                  repaint();
1765          }          }
1766    
1767            // /**
1768            // * Triggers to use new {@link GTRenderer} and refresh the map. Should be
1769            // * called after {@link Style}s have been changed because GTRenderer is
1770            // * otherwise not working well.
1771            // */
1772            // public void refreshRenderers() {
1773            // localRenderer = GTUtil.createGTRenderer();
1774            // setLocalContext(getMapContext());
1775            // mapImageInvalid = true;
1776            // repaint();
1777            // }
1778    
1779          /**          /**
1780             * Set the new map area.
1781             *
1782           * @param newMapArea           * @param newMapArea
1783           * @return <code>true</code> if the mapArea has been changed and a repaint           * @return <code>true</code> if the mapArea has been changed and a repaint
1784           *         has been triggered.           *         has been triggered.
1785           */           */
1786          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1787                    if (newMapArea == null)
1788                            return false;
1789                    if (getMapContext().getCoordinateReferenceSystem() == null)
1790                            return false;
1791                    return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1792                                    .getCoordinateReferenceSystem()));
1793            }
1794    
1795            /**
1796             * Set the new map area.
1797             *
1798             * @param newMapArea
1799             * @return <code>true</code> if the mapArea has been changed and a repaint
1800             *         has been triggered.
1801             */
1802            public boolean setMapArea(final ReferencedEnvelope newMapArea) {
1803    
1804                  if (newMapArea == null                  if (newMapArea == null
1805                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {
# Line 1802  public class XMapPane extends JPanel { Line 1854  public class XMapPane extends JPanel {
1854                          bgContext.setAreaOfInterest(mapArea, localContext                          bgContext.setAreaOfInterest(mapArea, localContext
1855                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
1856                  }                  }
1857                  mapImageInvalid = true;  
1858                  mapAreaChanged = true;                  mapAreaChanged = true;
                 repaint();  
1859    
1860                  LOGGER.debug("New maparea = " + mapArea);                  repaint(200); // Do not remove it!
1861    
1862                    requestStartRendering();
1863    
1864                  return true;                  return true;
1865          }          }
1866    
# Line 1815  public class XMapPane extends JPanel { Line 1869  public class XMapPane extends JPanel {
1869           *           *
1870           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1871           */           */
1872          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(final Color bgColor) {
                 if (bgColor == null)  
                         bgColor = Color.WHITE;  
1873                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1874          }          }
1875    
# Line 1875  public class XMapPane extends JPanel { Line 1927  public class XMapPane extends JPanel {
1927          }          }
1928    
1929          // /** Stored the time used for the last real rendering in ms. **/          // /** Stored the time used for the last real rendering in ms. **/
1930          // private long lastRenderingDuration = Long.MAX_VALUE;          private long lastRenderingDuration = 1000;
1931            private XMapPaneTool tool = null;
1932    
1933          /**          /**
1934           * Set the minimum (nearest) allowed zoom scale. This is the bigger number           * Set the minimum (nearest) allowed zoom scale. This is the bigger number
# Line 1892  public class XMapPane extends JPanel { Line 1945  public class XMapPane extends JPanel {
1945          }          }
1946    
1947          /**          /**
1948           *           * If <code>true</code>, allow the {@link XMapPane} to process #repaint()
1949           * @param b           * requests. Otherwise the map will not paint anything and not start any
1950             * rendering {@link Thread}s.
1951           */           */
1952          public void setPainting(final boolean b) {          public void setPainting(final boolean b) {
1953                  acceptsRepaintCalls = b;                  acceptsRepaintCalls = b;
1954          }                  if (acceptsRepaintCalls == true)
1955                            repaint();
         // /**  
         // * Returns in milli seconds the time the last rending of the  
         // * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has  
         // not  
         // * been rendered yet.  
         // */  
         // public long getLastRenderingDuration() {  
         // return lastRenderingDuration;  
         // }  
   
         public void setQuickPreviewHint(final int quickPreviewHint) {  
                 this.quickPreviewHint = quickPreviewHint;  
   
1956          }          }
1957    
1958          private void setRendererHints(final Map<Object, Object> rendererHints) {          private void setRendererHints(final Map<Object, Object> rendererHints) {
# Line 1919  public class XMapPane extends JPanel { Line 1960  public class XMapPane extends JPanel {
1960                          this.rendererHints = rendererHints;                          this.rendererHints = rendererHints;
1961          }          }
1962    
1963          /**  //      @Deprecated
1964           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the  //      public void setState(final int state) {
1965           * repaint Timer if  //              this.state = state;
1966           *  //
1967           * @param state  //              // throw new RuntimeException("Old concept.. migrate to new concept!");
1968           */  //
1969          public void setState(final int state) {  //              // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
1970                  this.state = state;  //              // || state == ZOOM_OUT || state == PAN));
1971    //
1972                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN  //              // Je nach Aktion den Cursor umsetzen
1973                                  || state == ZOOM_OUT || state == PAN));  //              updateCursor();
1974    //      }
1975    
1976                  // Je nach Aktion den Cursor umsetzen          public void configureMouse(MouseInputType type, XMapPaneAction action) {
1977                  updateCursor();                  xMapPaneMouseListener.actions.put(type, action);
1978          }          }
1979            
1980          /**          /**
1981           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,           * Configure the {@link XMapPaneTool} that active on the map. Passing
1982           * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor           * <code>null</code> will set the NO_ACTION tool.
1983           * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion           */
1984           * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann          public void setTool(XMapPaneTool tool) {
1985           * {@code null} als Parameter uebergeben werden                  if (tool == null)
1986           *                          tool = XMapPaneTool.NO_ACTION;
1987           * @param cursor                  this.tool = tool;
1988           *            Cursor                  xMapPaneMouseListener.configure(tool);
1989           */                  setCursor(tool.getCursor());
1990          public void setStaticCursor(final Cursor cursor) {          }
1991                  this.staticCursor = cursor;  
1992                  if (cursor != null)  //      /**
1993                          super.setCursor(cursor);  //       * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,
1994          }  //       * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
1995    //       * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
1996    //       * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
1997    //       * {@code null} als Parameter uebergeben werden
1998    //       *
1999    //       * @param cursor
2000    //       *            Cursor
2001    //       */
2002    //      public void setStaticCursor(final Cursor cursor) {
2003    //              this.staticCursor = cursor;
2004    //              if (cursor != null)
2005    //                      super.setCursor(cursor);
2006    //      }
2007    
2008          /**          /**
2009           * Starts rendering on one or two threads           * Starts rendering on one or two threads
2010           */           */
2011          private void startRendering() {          private void startRendering() {
2012    
2013                  if (!isWellDefined())                  if (!isWellDefined() || !acceptsRepaintCalls) {
2014                            // if we are not ready to start rendering, try it again the next
2015                            // time the timer is chacking the flag.
2016                            requestStartRendering = true;
2017                          return;                          return;
2018                    }
2019    
2020                  if (bgExecuter != null) {                  if (bgExecuter != null) {
2021                          // Stop all renderers                          // Stop all renderers
2022                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
2023                  }                  }
2024    
2025                  if (localExecuter != null) {                  localExecuter.cancelTask();
                         localExecuter.cancelTask();  
                 }  
2026    
2027                  final Rectangle curPaintArea = getVisibleRect();                  final Rectangle curPaintArea = getVisibleRect();
2028    
# Line 1989  public class XMapPane extends JPanel { Line 2045  public class XMapPane extends JPanel {
2045                          // (Graphics2D) getBgImage().getGraphics(), createGTRenderer);                          // (Graphics2D) getBgImage().getGraphics(), createGTRenderer);
2046                  }                  }
2047    
2048                  if (getContext() != null) {                  if (getMapContext() != null) {
2049                          // localExecuter = new RenderingExecutor(this, 150l);                          // localExecuter = new RenderingExecutor(this, 150l);
2050                          // LOGGER.debug("starting local renderer:");                          // LOGGER.debug("starting local renderer:");
2051    
2052                          localRenderer.setJava2DHints(getJava2dHints());                          getLocalRenderer().setJava2DHints(getJava2dHints());
2053                          localRenderer.setRendererHints(getRendererHints());                          getLocalRenderer().setRendererHints(getRendererHints());
2054    
2055                          ReferencedEnvelope areaOfInterest = getMapArea();                          final boolean submitted = localExecuter.submit(getMapArea(),
                         final boolean submitted = localExecuter.submit(areaOfInterest,  
2056                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
2057                                          localRenderer, getWorldToScreenTransform());                                          getLocalRenderer());
2058                          if (submitted)                          if (submitted)
2059                                  repaintTimer.restart();                                  repaintTimer.restart();
2060                          else                          else
2061                                  requestStartRenderingLocal = true; // Try to start rendering again in                                  requestStartRendering = true; // Try to start rendering
2062                            // again in
2063                          // a moment                          // a moment
2064                  }                  }
2065    
2066                  updateCursor();                  updateCursor();
2067          }          }
2068    
2069            private RenderingHints getJava2dHints() {
2070                    return java2dHints;
2071            }
2072    
2073          /**          /**
2074           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.
2075           *           *
# Line 2073  public class XMapPane extends JPanel { Line 2133  public class XMapPane extends JPanel {
2133                  // if the renderers have stopped, also stop the timer that is updating                  // if the renderers have stopped, also stop the timer that is updating
2134                  // the final image                  // the final image
2135                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
2136                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter.isRunning()) {
2137                          setCursor(WAIT_CURSOR);                          setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
2138                          return;                          return;
2139                  } else {                  } else {
2140                          // Allow one last rendering                          // Allow one last rendering
2141                          if (repaintTimer.isRunning()) {                          if (repaintTimer.isRunning()) {
2142                                  System.out.println("one last rendering....");                                  // System.out.println("one last rendering....");
2143                                  repaintTimer.stop();                                  repaintTimer.stop();
2144                                  updateFinalImage();                                  updateFinalImage();
2145                                  repaint();                                  repaint();
2146                          }                          }
2147                  }                  }
2148    //              
2149                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig  ////
2150                  // von der aktuellen Aktion  //              // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
2151                  if (this.staticCursor != null) {  //              // von der aktuellen Aktion
2152                          setCursor(staticCursor);  //              if (this.staticCursor != null) {
2153                          return;  //                      setCursor(staticCursor);
2154                  }  //                      return;
2155    //              }
2156    //              
2157                  if (getCursor() == SwingUtil.PANNING_CURSOR) {                  if (getCursor() == SwingUtil.PANNING_CURSOR) {
2158                          // This cursor will reset itself                          // This cursor will reset itself
2159                          return;                          return;
2160                  }                  }
2161                    
2162                  // Set the cursor depending on what tool is in use...                  setCursor(tool.getCursor());
2163                  switch (state) {                  
2164                  case SELECT_TOP:  //
2165                  case SELECT_ONE_FROM_TOP:  //              // Set the cursor depending on what tool is in use...
2166                  case SELECT_ALL:  //              switch (state) {
2167                          setCursor(SwingUtil.CROSSHAIR_CURSOR);  //              case SELECT_TOP:
2168                          break;  //              case SELECT_ONE_FROM_TOP:
2169                  case ZOOM_IN:  //              case SELECT_ALL:
2170                          setCursor(SwingUtil.ZOOMIN_CURSOR);  //                      setCursor(SwingUtil.CROSSHAIR_CURSOR);
2171                          break;  //                      break;
2172                  case ZOOM_OUT:  //              case ZOOM_IN:
2173                          setCursor(SwingUtil.ZOOMOUT_CURSOR);  //                      setCursor(SwingUtil.ZOOMIN_CURSOR);
2174                          break;  //                      break;
2175                  case PAN:  //              case ZOOM_OUT:
2176                          setCursor(SwingUtil.PAN_CURSOR);  //                      setCursor(SwingUtil.ZOOMOUT_CURSOR);
2177                          break;  //                      break;
2178                  default:  //              case PAN:
2179                          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  //                      setCursor(SwingUtil.PAN_CURSOR);
2180                          break;  //                      break;
2181                  }  //              default:
2182    //                      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2183    //                      break;
2184    //              }
2185          }          }
2186    
2187          /**          /**
# Line 2146  public class XMapPane extends JPanel { Line 2211  public class XMapPane extends JPanel {
2211    
2212                  final Graphics2D finalG = getFinalImage().createGraphics();                  final Graphics2D finalG = getFinalImage().createGraphics();
2213                  finalG.setBackground(getMapBackgroundColor());                  finalG.setBackground(getMapBackgroundColor());
2214                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), getImageOrigin().x, getImageOrigin().y,
2215                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
2216    
2217                  final int finalImageHeight = getFinalImage().getHeight(null);                  // When panning, we have to clear the area around the image
2218                  final int finalImageWidth = getFinalImage().getWidth(null);                  final Rectangle painedArea = new Rectangle(getImageOrigin().x,
2219                                    getImageOrigin().y, getFinalImage().getWidth(), getFinalImage()
2220                  final Rectangle painedArea = new Rectangle(imageOrigin.x,                                                  .getHeight());
2221                                  imageOrigin.y, finalImageWidth, finalImageHeight);                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
2222                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());                                  getMapBackgroundColor());
2223    
2224                  addGadgets(finalG, false);  //              addGadgets(finalG, false);
2225    
2226                  finalG.dispose();                  finalG.dispose();
2227    
# Line 2173  public class XMapPane extends JPanel { Line 2238  public class XMapPane extends JPanel {
2238           *            <code>false</code>, it will only depend on           *            <code>false</code>, it will only depend on
2239           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2240           */           */
2241          private void addGadgets(final Graphics2D graphics, boolean forceWait) {          private void addGadgets(final Graphics2D graphics, final boolean forceWait) {
2242    
2243                  // Paint a logo to the bottom right if available                  // Paint a logo to the bottom right if available
2244                  if (mapImage != null) {                  if (mapImage != null) {
2245                          Rectangle visibleRect = getVisibleRect();                          final Rectangle visibleRect = getVisibleRect();
2246                          graphics.drawImage(mapImage, visibleRect.width                          graphics.drawImage(mapImage, visibleRect.width
2247                                          - mapImage.getWidth() - 10, getVisibleRect().height                                          - mapImage.getWidth() - 10, getVisibleRect().height
2248                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
# Line 2187  public class XMapPane extends JPanel { Line 2252  public class XMapPane extends JPanel {
2252    
2253                  // If the rendering process is still running, indicate this is the image                  // If the rendering process is still running, indicate this is the image
2254                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2255                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter.isRunning()) {
2256    
2257                          y += 8;                          y += 8;
2258    
# Line 2203  public class XMapPane extends JPanel { Line 2268  public class XMapPane extends JPanel {
2268    
2269                          graphics.setColor(c);                          graphics.setColor(c);
2270    
2271                          y += 24;                          y += 21;
2272                  }                  }
2273    
2274                  if (renderingErrors != null) {                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
2275    
2276                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2277                          graphics.setFont(errorFont);                          graphics.setFont(errorFont);
2278    
2279                          for (Exception ex : renderingErrors) {                          for (final Exception ex : renderingErrors) {
   
                                 if (ex instanceof java.lang.IllegalArgumentException  
                                                 && ex.getMessage().equals(  
                                                                 "Argument \"sourceCRS\" should not be null."))  
                                         continue;  
2280    
2281                                  String errStr = ex.getLocalizedMessage();                                  String errStr = ex.getLocalizedMessage();
2282    
2283                                  graphics.setColor(Color.WHITE);                                  if (errStr == null)
2284                                            errStr = ex.getMessage();
2285                                    if (errStr == null)
2286                                            errStr = "unknown error: " + ex.getClass().getSimpleName();
2287    
2288                                    graphics.setColor(getMapBackgroundColor());
2289                                  graphics.drawString(errStr, 5, y);                                  graphics.drawString(errStr, 5, y);
2290                                  graphics.setColor(Color.RED);                                  graphics.setColor(Color.RED);
2291                                  graphics.drawString(errStr, 6, y + 1);                                  graphics.drawString(errStr, 6, y + 1);
# Line 2243  public class XMapPane extends JPanel { Line 2308  public class XMapPane extends JPanel {
2308          public void zoomTo(          public void zoomTo(
2309                          final FeatureCollection<SimpleFeatureType, SimpleFeature> features) {                          final FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
2310    
2311                  final CoordinateReferenceSystem mapCRS = getContext()                  // if (!isWellDefined()) return;
2312    
2313                    final CoordinateReferenceSystem mapCRS = getMapContext()
2314                                  .getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2315                  final CoordinateReferenceSystem fCRS = features.getSchema()                  final CoordinateReferenceSystem fCRS = features.getSchema()
2316                                  .getGeometryDescriptor().getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2317    
2318                  double width = mapArea.getWidth();                  ReferencedEnvelope _mapArea;
2319                  double height = mapArea.getHeight();                  if (mapArea == null)
2320                            _mapArea = features.getBounds();
2321                    else
2322                            _mapArea = getMapArea();
2323                    double width = _mapArea.getWidth();
2324                    double height = _mapArea.getHeight();
2325                  final double ratio = height / width;                  final double ratio = height / width;
2326    
2327                  if (features == null || features.size() == 0) {                  if (features == null || features.size() == 0) {
# Line 2301  public class XMapPane extends JPanel { Line 2373  public class XMapPane extends JPanel {
2373                  } else {                  } else {
2374                          final ReferencedEnvelope fBounds = features.getBounds();                          final ReferencedEnvelope fBounds = features.getBounds();
2375    
2376                          Envelope bounds;                          ReferencedEnvelope bounds;
2377                          if (!mapCRS.equals(fCRS)) {                          if (!mapCRS.equals(fCRS)) {
2378                                  bounds = JTSUtil.transformEnvelope(fBounds, fCRS, mapCRS);                                  bounds = JTSUtil.transformEnvelope(fBounds, mapCRS);
2379                          } else {                          } else {
2380                                  bounds = fBounds;                                  bounds = fBounds;
2381                          }                          }
# Line 2334  public class XMapPane extends JPanel { Line 2406  public class XMapPane extends JPanel {
2406           * @param center           * @param center
2407           *            position in window coordinates           *            position in window coordinates
2408           * @param zoomFaktor           * @param zoomFaktor
2409           *            > 1 for zoom in, < 1 for zoom out. Default is 1.33.           *            > 1 for zoom out, < 1 for zoom in. Default is .5
2410           */           */
2411          public void zoomTo(Point center, Double zoomFaktor) {          public void zoomTo(Point center, Double zoomFaktor) {
2412                  if (zoomFaktor == null || zoomFaktor == 0.)                  if (zoomFaktor == null || zoomFaktor == 0.)
2413                          zoomFaktor = 2.;                          zoomFaktor = .5;
2414    
2415                  final Point2D gcenter = getScreenToWorld().transform(center, null);                  final Point2D gcenter = getScreenToWorld().transform(center, null);
2416                  center = null;                  center = null;
# Line 2359  public class XMapPane extends JPanel { Line 2431  public class XMapPane extends JPanel {
2431                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2432                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2433    
2434                  // TODO we actually want that                  // // Move the newMapArea above the new center if we zoom in:
2435                  // // Move the newMapArea above the new center                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2436                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                                  .getY()
2437                  // .getY()                                  - mapArea.centre().y);
                 // - mapArea.centre().y);  
2438    
2439                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2440          }          }
2441    
2442            /**
2443             * Shall non-fatal rendering exceptions be reported in the mappane or be
2444             * dropped quitely.
2445             */
2446            public void setShowExceptions(final boolean showExceptions) {
2447                    this.showExceptions = showExceptions;
2448            }
2449    
2450            /**
2451             * Shall exceptions be reported in the mappane?
2452             */
2453            public boolean isShowExceptions() {
2454                    return showExceptions;
2455            }
2456    
2457            public GTRenderer getLocalRenderer() {
2458                    return localRenderer;
2459            }
2460    
2461            /**
2462             * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
2463             * Macht nichts, wenn {@code null} uebergeben wird.
2464             *
2465             * <br>
2466             *
2467             * @param layer
2468             *            ein Layer
2469             */
2470            public void zoomToLayer(MapLayer layer) {
2471                    if (layer == null)
2472                            return;
2473                    try {
2474    
2475                            // BB umrechnen von Layer-CRS in Map-CRS
2476                            final CoordinateReferenceSystem targetCRS = getMapContext()
2477                                            .getCoordinateReferenceSystem();
2478                            final CoordinateReferenceSystem sourceCRS = layer
2479                                            .getFeatureSource().getSchema()
2480                                            .getCoordinateReferenceSystem();
2481    
2482                            Envelope mapAreaNew;
2483                            if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
2484                                    mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource()
2485                                                    .getBounds(), sourceCRS, targetCRS);
2486                            } else {
2487                                    try {
2488                                            mapAreaNew = layer.getFeatureSource().getBounds();
2489                                    } catch (java.lang.IllegalArgumentException e) {
2490                                            LOGGER.error("Can't calc layers bounds...", e);
2491                                            mapAreaNew = null;
2492    
2493                                            /**
2494                                             *
2495                                             23.10.2009 11:20:50
2496                                             * org.geotools.data.shapefile.shp.PolygonHandler read
2497                                             * WARNUNG: only one hole in this polygon record ERROR
2498                                             * JMapPane zoomToLayer Zoom to layer did not terminate
2499                                             * correctly java.lang.IllegalArgumentException: Points of
2500                                             * LinearRing do not form a closed linestring at
2501                                             * com.vividsolutions
2502                                             * .jts.geom.LinearRing.validateConstruction
2503                                             * (LinearRing.java:105) at
2504                                             * com.vividsolutions.jts.geom.LinearRing
2505                                             * .<init>(LinearRing.java:100) at
2506                                             * com.vividsolutions.jts.geom
2507                                             * .GeometryFactory.createLinearRing
2508                                             * (GeometryFactory.java:339) at
2509                                             * org.geotools.data.shapefile.
2510                                             * shp.PolygonHandler.read(PolygonHandler.java:188) at
2511                                             * org.geotools
2512                                             * .data.shapefile.shp.ShapefileReader$Record.shape
2513                                             * (ShapefileReader.java:106) at
2514                                             * org.geotools.data.shapefile.
2515                                             * ShapefileAttributeReader.next(
2516                                             * ShapefileAttributeReader.java:157) at
2517                                             * org.geotools.data.shapefile
2518                                             * .indexed.IndexedShapefileAttributeReader
2519                                             * .next(IndexedShapefileAttributeReader.java:122) at
2520                                             * org.geotools
2521                                             * .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at
2522                                             * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.
2523                                             * java:55) at org.geotools.data.MaxFeatureReader.next(
2524                                             * MaxFeatureReader.java:61) at
2525                                             * org.geotools.data.MaxFeatureReader
2526                                             * .next(MaxFeatureReader.java:61)
2527                                             **/
2528                                    }
2529                            }
2530    
2531                            // Kartenbereich um 10% vergroessern, damit z.B. auch ein
2532                            // Punkt-Layer,
2533                            // welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen
2534                            // sonst
2535                            // genau auf dem Rand der angezeigten Flaeche)
2536    
2537                            if (mapAreaNew != null) {
2538                                    mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew
2539                                                    .getHeight() * 0.1);
2540                                    setMapArea(mapAreaNew);
2541                            } else {
2542                                    LOGGER
2543                                                    .warn("Couldn't transformEnvelope when zooming to the layer");
2544                            }
2545                    } catch (Exception err) {
2546                            LOGGER.error("Zoom to layer did not terminate correctly", err);
2547                    }
2548            }
2549    
2550            /**
2551             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer.
2552             *
2553             * <br>
2554             * A refresh of the map is not done automatically
2555             *
2556             * @param index
2557             *            Index of the {@link MapLayer} in the {@link MapContext} (from
2558             *            back to top)
2559             *
2560             * @author <a href="mailto:[email protected]">Stefan Alfons
2561             *         Kr&uuml;ger</a>
2562             */
2563            public void zoomToLayer(int index) {
2564                    final MapContext context = getMapContext();
2565                    if (context != null)
2566                            zoomToLayer(context.getLayer(index));
2567            }
2568    
2569            /**
2570             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the
2571             * selected layer. The layer is selected by the idx, counting from front to
2572             * back, like humans would expect in a {@link JList}
2573             *
2574             * <br>
2575             * A refresh of the map is not done automatically
2576             *
2577             *
2578             *
2579             * @param index
2580             *            Reverse index of the {@link MapLayer} in the
2581             *            {@link MapContext}
2582             *
2583             * @author <a href="mailto:[email protected]">Stefan Alfons
2584             *         Kr&uuml;ger</a>
2585             */
2586            public void zoomToLayerIdxReverse(int index) {
2587                    zoomToLayer(getMapContext().getLayerCount() - 1 - index);
2588            }
2589    
2590            /**
2591             * Aktiviert oder deaktiviert das AntiAliasing for diese
2592             * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
2593             * Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance.
2594             *
2595             * @author <a href="mailto:[email protected]">Stefan Alfons
2596             *         Kr&uuml;ger</a>
2597             */
2598            public void setAntiAliasing(final boolean aa) {
2599                    // LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa);
2600                    RenderingHints java2DHints = java2dHints;
2601                    if (java2DHints == null) {
2602                            java2DHints = GeoTools.getDefaultHints();
2603                    }
2604    
2605                    java2DHints.put(RenderingHints.KEY_ANTIALIASING,
2606                                    aa ? RenderingHints.VALUE_ANTIALIAS_ON
2607                                                    : RenderingHints.VALUE_ANTIALIAS_OFF);
2608                    java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
2609                                    aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
2610                                                    : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
2611                    java2DHints.put(RenderingHints.KEY_RENDERING,
2612                                    aa ? RenderingHints.VALUE_RENDER_QUALITY
2613                                                    : RenderingHints.VALUE_RENDER_SPEED);
2614    
2615            }
2616    
2617            public Point getImageOrigin() {
2618                    return imageOrigin;
2619            }
2620    
2621  }  }

Legend:
Removed from v.543  
changed lines
  Added in v.656

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26