/[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 555 by alfonx, Tue Nov 24 09:17:22 2009 UTC branches/2.0-RC2/src/skrueger/geotools/XMapPane.java revision 677 by alfonx, Fri Feb 5 15:03:17 2010 UTC
# Line 13  import java.awt.event.ActionEvent; Line 13  import java.awt.event.ActionEvent;
13  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
14  import java.awt.event.ComponentAdapter;  import java.awt.event.ComponentAdapter;
15  import java.awt.event.ComponentEvent;  import java.awt.event.ComponentEvent;
 import java.awt.event.InputEvent;  
16  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
17  import java.awt.event.MouseListener;  import java.awt.event.MouseListener;
18  import java.awt.geom.AffineTransform;  import java.awt.geom.AffineTransform;
# Line 26  import java.util.HashMap; Line 25  import java.util.HashMap;
25  import java.util.Map;  import java.util.Map;
26  import java.util.Vector;  import java.util.Vector;
27    
28    import javax.swing.JList;
29  import javax.swing.Timer;  import javax.swing.Timer;
30    import javax.swing.border.Border;
31    
32  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
33    import org.geotools.factory.GeoTools;
34  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
35    import org.geotools.geometry.DirectPosition2D;
36  import org.geotools.geometry.jts.JTS;  import org.geotools.geometry.jts.JTS;
37  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
38  import org.geotools.map.DefaultMapContext;  import org.geotools.map.DefaultMapContext;
# Line 45  import org.geotools.renderer.label.Label Line 48  import org.geotools.renderer.label.Label
48  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
49  import org.geotools.renderer.lite.RendererUtilities;  import org.geotools.renderer.lite.RendererUtilities;
50  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
51    import org.geotools.resources.image.ImageUtilities;
52  import org.geotools.swing.JMapPane;  import org.geotools.swing.JMapPane;
53  import org.geotools.swing.event.MapMouseEvent;  import org.geotools.swing.event.MapMouseEvent;
54  import org.geotools.swing.event.MapPaneEvent;  import org.geotools.swing.event.MapPaneEvent;
# Line 65  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 95  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;          /**
104          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;           * If {@link #maxExtend} is <code>null</code> the following rules are used
105             * to create a default maximum.
106             * <ul>
107             * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
108             * margin</li>
109             * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
110             * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
111             * relative margin</li>
112             * </ul>
113             * **/
114            private double defaultMaxMapExtendMode = .05;
115    
116            // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
117            // private static final int IMAGETYPE_withAlpha =
118            // BufferedImage.TYPE_INT_ARGB;
119            private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
120    
121            public XMapPaneTool getTool() {
122                    return tool;
123            }
124    
125            private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;
126    
127          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
128    
129            /**
130             * A flag indicating whether the {@link XMapPane} is accepting repaints from
131             * the EDT. @see {@link XMapPane#setPainting(boolean))
132             **/
133          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
134    
135          /**          /**
# Line 140  public class XMapPane extends JPanel { Line 170  public class XMapPane extends JPanel {
170           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
171           * with previews.           * with previews.
172           */           */
173          public static final int REPEATING_REPAINT_DELAY = 600;          public static final int REPEATING_REPAINT_DELAY = 500;
174    
175          /**          /**
176           * Default delay (milliseconds) before the map will be redrawn when resizing           * Default delay (milliseconds) before the map will be redrawn when resizing
# Line 162  public class XMapPane extends JPanel { Line 192  public class XMapPane extends JPanel {
192           * Flag for no-tool.           * Flag for no-tool.
193           */           */
194          public static final int NONE = -123;          public static final int NONE = -123;
195            //
196          /**          // /**
197           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl          // * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
198           * moeglich!          // * moeglich!
199           *          // *
200           * @see #setState(int)          // * @see #setState(int)
201           */          // */
202          public static final int PAN = 1;          // public static final int PAN = 1;
203            //
204          /**          // /**
205           * Flag fuer Modus "Heran zoomen".          // * Flag fuer Modus "Heran zoomen".
206           *          // *
207           * @see #setState(int)          // * @see #setState(int)
208           * @see #setState(int)          // * @see #setState(int)
209           */          // */
210          public static final int ZOOM_IN = 2;          // public static final int ZOOM_IN = 2;
211            //
212          /**          // /**
213           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!          // * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
214           *          // *
215           * @see #setState(int)          // * @see #setState(int)
216           */          // */
217          public static final int ZOOM_OUT = 3;          // public static final int ZOOM_OUT = 3;
   
         /**  
          * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".  
          *  
          * @see #setState(int)  
          * @see #setState(int)  
          */  
         public static final int SELECT_ALL = 103;  
         /**  
          * Flag fuer Modus  
          * "Auswahl nur eines Features, das erste sichtbare von Oben".  
          *  
          * @see #setState(int)  
          * @see #setState(int)  
          */  
         public static final int SELECT_ONE_FROM_TOP = 104;  
         /**  
          * Flag fuer Modus  
          * "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer".  
          *  
          * @see #setState(int)  
          * @see #setState(int)  
          */  
         public static final int SELECT_TOP = 4;  
218    
219          /**          /**
220           * {@link Font} used to paint the wait messages into the map           * {@link Font} used to paint the wait messages into the map
221           *           *
222           * @see #addGadgets(Graphics2D, boolean)           * @see #addGadgets(Graphics2D, boolean)
223           */           */
224          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 28);
225    
226          /**          /**
227           * {@link Font} used to paint error messages into the map           * {@link Font} used to paint error messages into the map
# Line 225  public class XMapPane extends JPanel { Line 231  public class XMapPane extends JPanel {
231          final static Font errorFont = new Font("Arial", Font.BOLD, 13);          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
232    
233          /**          /**
234             * If last average last two renderings took more than that many ms, show the
235             * user a scaled preview
236             **/
237            private static final long PRESCALE_MINTIME = 230;
238    
239            /**
240           * The wait message painted into the map while rendering is going on on           * The wait message painted into the map while rendering is going on on
241           * another thread.           * another thread.
242           *           *
# Line 239  public class XMapPane extends JPanel { Line 251  public class XMapPane extends JPanel {
251           * @param e           * @param e
252           *            Maus-Ereignis           *            Maus-Ereignis
253           */           */
254          public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {          public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) {
255                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln
256                  if (e != null && e instanceof MapMouseEvent)                  if (e != null && e instanceof MapMouseEvent)
257                          try {                          try {
258                                  return ((MapMouseEvent) e).getMapPosition().toPoint2D();                                  return ((MapMouseEvent) e).getMapPosition();
259                          } catch (final Exception err) {                          } catch (final Exception err) {
260                                  LOGGER                                  LOGGER
261                                                  .error(                                                  .error(
# Line 260  public class XMapPane extends JPanel { Line 272  public class XMapPane extends JPanel {
272                                  return null;                                  return null;
273    
274                          final AffineTransform at = xMapPane.getScreenToWorld();                          final AffineTransform at = xMapPane.getScreenToWorld();
275                          if (at != null)                          if (at != null) {
276                                  return at.transform(e.getPoint(), null);                                  Point2D transformed = at.transform(e.getPoint(), null);
277                                    return new DirectPosition2D(xMapPane.getMapContext()
278                                                    .getCoordinateReferenceSystem(), transformed.getX(),
279                                                    transformed.getY());
280                            }
281                          return null;                          return null;
282                  }                  }
283                  throw new IllegalArgumentException(                  throw new IllegalArgumentException(
# Line 276  public class XMapPane extends JPanel { Line 292  public class XMapPane extends JPanel {
292    
293                  @Override                  @Override
294                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
295                          MapLayer layer = event.getLayer();                          final MapLayer layer = event.getLayer();
296                          layer.addMapLayerListener(bgMapLayerListener);                          layer.addMapLayerListener(bgMapLayerListener);
297                          requestStartRendering();                          requestStartRendering();
   
298                  }                  }
299    
300                  @Override                  @Override
# Line 373  public class XMapPane extends JPanel { Line 388  public class XMapPane extends JPanel {
388           * While dragging, the {@link #updateFinalImage()} method is translating the           * While dragging, the {@link #updateFinalImage()} method is translating the
389           * cached images while setting it together.           * cached images while setting it together.
390           **/           **/
391          Point imageOrigin = new Point(0, 0);          private final Point imageOrigin = new Point(0, 0);
392          /**          /**
393           * For every rendering thread started,           * For every rendering thread started,
394           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new
# Line 395  public class XMapPane extends JPanel { Line 410  public class XMapPane extends JPanel {
410                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
411                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
412    
413                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
414                          requestStartRendering();                          requestStartRendering();
415    
416                  }                  }
417    
418                  @Override                  @Override
419                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
420                          localRenderer.setContext(getMapContext());                          // getLocalRenderer().setContext(getMapContext()); geht doch auch
421                            // ohne?!?!? wow...
422                          requestStartRendering();                          requestStartRendering();
423                  }                  }
424    
425                  @Override                  @Override
426                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
427                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
428                          requestStartRendering();                          requestStartRendering();
429                  }                  }
430    
# Line 416  public class XMapPane extends JPanel { Line 432  public class XMapPane extends JPanel {
432                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
433                          if (event.getLayer() != null)                          if (event.getLayer() != null)
434                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
435                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
436                          requestStartRendering();                          requestStartRendering();
437                  }                  }
438          };          };
439    
440          /**          /**
441           * Listens to each layer in the local {@link MapContext} for changes and           * Listens to each layer in the local {@link MapContext} for changes and
442           * triggers repaints.           * triggers repaints. We don't have to listen layerChanged, because that is
443             * already done in {@link #localContextListener}
444           */           */
445          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
446    
447                  @Override                  // @Override
448                  public void layerChanged(final MapLayerEvent event) {                  // public void layerChanged(final MapLayerEvent event) {
449                          localRenderer.setContext(getMapContext()); // betters for SLD                  // // getLocalRenderer().setContext(getMapContext()); // betters for SLD
450                          // changes?!                  // // // changes?!
451                          requestStartRendering();                  // // requestStartRendering();
452                  }                  // }
453    
454                  @Override                  @Override
455                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
# Line 445  public class XMapPane extends JPanel { Line 462  public class XMapPane extends JPanel {
462                  }                  }
463          };          };
464    
465          private final GTRenderer localRenderer = GTUtil.createGTRenderer();          final private GTRenderer localRenderer = GTUtil.createGTRenderer();
466    
467          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
468    
# Line 466  public class XMapPane extends JPanel { Line 483  public class XMapPane extends JPanel {
483          /**          /**
484           * 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.
485           */           */
486          private Color mapBackgroundColor = Color.WHITE;          private Color mapBackgroundColor = null;
487    
488          /**          /**
489           * 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 515  public class XMapPane extends JPanel { Line 532  public class XMapPane extends JPanel {
532          private BufferedImage preFinalImage;          private BufferedImage preFinalImage;
533    
534          // ** if 0, no quick preview will be shown **/          // ** if 0, no quick preview will be shown **/
535          private int quickPreviewHint = 0;          // private int quickPreviewHint = 0;
536    
537          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
538                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(getLocalRenderer());
539    
540          /**          /**
541           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
# Line 538  public class XMapPane extends JPanel { Line 555  public class XMapPane extends JPanel {
555           * thread.           * thread.
556           */           */
557          final private Timer startRenderThreadsTimer;          final private Timer startRenderThreadsTimer;
558            //
559          /**          // /**
560           * The default state is ZOOM_IN, hence by default the          // * The default state is ZOOM_IN, hence by default the
561           * {@link #zoomMapPaneMouseListener} is also enabled.          // * {@link #xMapPaneMouseListener} is also enabled.
562           **/          // **/
563          private int state = ZOOM_IN;          // private int state = ZOOM_IN;
564            //
565          /**          // /**
566           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen          // * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
567           * MapPane-Funktion          // * MapPane-Funktion
568           */          // */
569          protected Cursor staticCursor = null;          // protected Cursor staticCursor = null;
570    
571          private AffineTransform worldToScreen;          private AffineTransform worldToScreen;
572    
573            // /**
574            // * This {@link MouseListener} is managing all zoom related tasks
575            // */
576            // private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new
577            // ZoomXMapPaneMouseListener(
578            // this);
579    
580          /**          /**
581           * This {@link MouseListener} is managing all zoom related tasks           * This {@link MouseListener} is managing all zoom related tasks
582           */           */
583          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(
584                          this);                          this);
585    
586          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
# Line 588  public class XMapPane extends JPanel { Line 612  public class XMapPane extends JPanel {
612                          final Map<Object, Object> rendererHints) {                          final Map<Object, Object> rendererHints) {
613                  super(true);                  super(true);
614    
615                    // A default setting
616                    RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT;
617                    setJava2dHints(hintsJava2d);
618    
619                  setRendererHints(rendererHints);                  setRendererHints(rendererHints);
620    
621                  setOpaque(true);                  setOpaque(true);
# Line 598  public class XMapPane extends JPanel { Line 626  public class XMapPane extends JPanel {
626                  /**                  /**
627                   * Adding the #zoomMapPaneMouseListener                   * Adding the #zoomMapPaneMouseListener
628                   */                   */
629                  this.addMouseListener(zoomMapPaneMouseListener);                  this.addMouseListener(xMapPaneMouseListener);
630                  this.addMouseMotionListener(zoomMapPaneMouseListener);                  this.addMouseMotionListener(xMapPaneMouseListener);
631                  this.addMouseWheelListener(zoomMapPaneMouseListener);                  this.addMouseWheelListener(xMapPaneMouseListener);
632    
633                    // By default the XMapPAne uses the ZOOM_IN tool.
634                    setTool(XMapPaneTool.ZOOM_IN);
635    
636                  /*                  /*
637                   * We use a Timer object to avoid rendering delays and flickering when                   * We use a Timer object to avoid rendering delays and flickering when
# Line 616  public class XMapPane extends JPanel { Line 647  public class XMapPane extends JPanel {
647                                                  if (!isWellDefined())                                                  if (!isWellDefined())
648                                                          return;                                                          return;
649    
650                                                  LOGGER.info("resizeTimer performed");                                                  // LOGGER.debug("resizeTimer performed");
651    
652                                                  final Rectangle bounds = getVisibleRect();                                                  // final Rectangle bounds = getVisibleRect();
653                                                  //                                                  //
654                                                  // System.out.println("\n\ntimer performs with bounds = "                                                  // System.out.println("\n\ntimer performs with bounds = "
655                                                  // + bounds);                                                  // + bounds);
656    
657                                                  final Envelope geoMapArea = tranformWindowToGeo(                                                  // final Envelope geoMapArea = tranformWindowToGeo(
658                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                  // bounds.x, bounds.y, bounds.x + bounds.width,
659                                                                  bounds.y + bounds.height);                                                  // bounds.y + bounds.height);
660    
661                                                  if (setMapArea(geoMapArea)) {                                                  paneResized = true;
662                                                          LOGGER.info("  maparea changed");                                                  if (!setMapArea(getMapArea())) {
663                                                          paneResized = true;                                                          // It's important to request new rendering here.
664                                                  } else                                                          // setMapArea only returns true and only calls
665                                                          LOGGER.info("  maparea NOT changed");                                                          // requestStartRendering if the maparea has changed.
666                                                            // But if the component is resized, the maparea
667                                                            // doesn't have to change.
668                                                            requestStartRendering();
669                                                    }
670    
671                                          }                                          }
672                                  });                                  });
673                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
# Line 643  public class XMapPane extends JPanel { Line 679  public class XMapPane extends JPanel {
679                          @Override                          @Override
680                          public void componentResized(final ComponentEvent e) {                          public void componentResized(final ComponentEvent e) {
681    
682                                  // Seems to be called twice with the same size..                                  // Seems to be called twice with the same size..
683                                  if (oldVisibleRect != null                                  if (oldVisibleRect != null
684                                                  && oldVisibleRect.equals(getVisibleRect())){                                                  && oldVisibleRect.equals(getVisibleRect())) {
685                                          LOGGER.info("skipping resize.");                                          // LOGGER.debug("skipping resize.");
686                                          return;                                          return;
687                                  }                                  }
688    
689                                  LOGGER.info("resized: " + getVisibleRect());                                  // LOGGER.debug("resized: " + getVisibleRect());
690                                  resizeTimer.restart();                                  resizeTimer.restart();
691                                  oldVisibleRect = getVisibleRect();                                  oldVisibleRect = getVisibleRect();
692                          }                          }
# Line 781  public class XMapPane extends JPanel { Line 817  public class XMapPane extends JPanel {
817    
818                  final Envelope maxAllowedExtend = getMaxExtend();                  final Envelope maxAllowedExtend = getMaxExtend();
819    
820                    /*
821                     * If a maxAllowedExtend is set, we have to honour that...
822                     */
823                    Envelope lastCalculatedArea = null;
824                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
825                                  && newArea != null && !newArea.isNull()                                  && newArea != null && !newArea.isNull()
826                                  && !Double.isNaN(newArea.getMinX())                                  && !Double.isNaN(newArea.getMinX())
827                                  && !Double.isNaN(newArea.getMaxX())                                  && !Double.isNaN(newArea.getMaxX())
828                                  && !Double.isNaN(newArea.getMinY())                                  && !Double.isNaN(newArea.getMinY())
829                                  && !Double.isNaN(newArea.getMaxY())) {                                  && !Double.isNaN(newArea.getMaxY())
830                          /*                                   ) // Due to Double precision problems, this may iterate for ever
831                           * If a maxExtend is set, we have to honour that...                  {
832                           */                          
833                            if (newArea.equals(lastCalculatedArea))
834                                    break;
835                            // Check that we are not iterating for ever due to double precision rounding errors
836                            lastCalculatedArea = newArea;
837                            
838                          // Exceeds top? Move down and maybe cut                          // Exceeds top? Move down and maybe cut
839                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
840                                  final double divY = newArea.getMaxY()                                  final double divY = newArea.getMaxY()
# Line 894  public class XMapPane extends JPanel { Line 938  public class XMapPane extends JPanel {
938                                                                          .getCoordinateReferenceSystem()), false);                                                                          .getCoordinateReferenceSystem()), false);
939                                  }                                  }
940                          }                          }
941                            
942                            
943                  }                  }
944    
945                  return new ReferencedEnvelope(newArea, env                  return new ReferencedEnvelope(newArea, env
# Line 950  public class XMapPane extends JPanel { Line 996  public class XMapPane extends JPanel {
996                  // Remove all mapPaneListeners that have registered with us                  // Remove all mapPaneListeners that have registered with us
997                  mapPaneListeners.clear();                  mapPaneListeners.clear();
998    
999                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(xMapPaneMouseListener);
1000                  removeMouseListener(zoomMapPaneMouseListener);                  removeMouseListener(xMapPaneMouseListener);
1001    
1002                  if (localContext != null)                  if (localContext != null)
1003                          getMapContext().clearLayerList();                          getMapContext().clearLayerList();
# Line 967  public class XMapPane extends JPanel { Line 1013  public class XMapPane extends JPanel {
1013           */           */
1014          protected void drawRectangle(final Graphics graphics, final Point startPos,          protected void drawRectangle(final Graphics graphics, final Point startPos,
1015                          final Point e) {                          final Point e) {
1016                    drawRectangle(graphics, startPos, e, Color.WHITE, false);
1017            }
1018    
1019            /**
1020             * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
1021             * given point. All in screen coordinates.
1022             */
1023            protected void drawRectangle(final Graphics graphics, final Point startPos,
1024                            final Point e, Color color, boolean fill) {
1025    
1026                  if (!isWellDefined())                  if (!isWellDefined())
1027                          return;                          return;
# Line 982  public class XMapPane extends JPanel { Line 1037  public class XMapPane extends JPanel {
1037                  if (width == 0 && height == 0)                  if (width == 0 && height == 0)
1038                          return;                          return;
1039    
1040                  graphics.setXORMode(Color.WHITE);                  graphics.setXORMode(color);
1041    
1042                    if (fill) {
1043                            graphics.fillRect(left, bottom, width, height);
1044                            graphics.setXORMode(Color.WHITE);
1045                    }
1046    
1047                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
1048          }          }
1049    
# Line 994  public class XMapPane extends JPanel { Line 1055  public class XMapPane extends JPanel {
1055           *           *
1056           * @param g           * @param g
1057           *            Graphics2D to paint the preview into           *            Graphics2D to paint the preview into
          *  
          * @param state  
          *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}  
1058           */           */
1059          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
1060    
1061                  // if (1 == 1)return false;                  // if (1 == 1)return false;
1062                    // if (quickPreviewHint == 0)
1063                    // return false;
1064    
1065                  if (quickPreviewHint == 0)                  if (oldMapArea == null)
1066                          return false;                          return false;
1067    
1068                  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)  
1069                          return false;                          return false;
1070    
1071                  final Rectangle visibleArea = getVisibleRect();                  final Rectangle visibleArea = getVisibleRect();
# Line 1027  public class XMapPane extends JPanel { Line 1080  public class XMapPane extends JPanel {
1080                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1081                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1082    
1083                    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1084                                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1085                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1086                                    RenderingHints.VALUE_ANTIALIAS_OFF);
1087                    graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1088                                    RenderingHints.VALUE_RENDER_SPEED);
1089    
1090                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1091                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1092                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
# Line 1035  public class XMapPane extends JPanel { Line 1095  public class XMapPane extends JPanel {
1095                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1096                                  - yy1);                                  - yy1);
1097    
1098                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea,
1099                                    getMapBackgroundColor());
1100    
1101                  addGadgets(graphics, true);                  addGadgets(graphics, true);
1102    
1103                  quickPreviewHint = 0;                  // quickPreviewHint = 0;
1104    
1105                  repaintTimer.restart();                  repaintTimer.restart();
1106    
                 graphics.dispose();  
   
1107                  // Something has been drawn                  // Something has been drawn
1108                  return true;                  return true;
1109          }          }
# Line 1057  public class XMapPane extends JPanel { Line 1116  public class XMapPane extends JPanel {
1116           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1117           */           */
1118          private Image getBgImage() {          private Image getBgImage() {
1119                  //                  if (bgImage == null) {
1120                  // if (bgImage == null) {                          bgImage = new BufferedImage(getVisibleRect().width,
1121                  // bgImage = createImage(getBounds().width, getBounds().height);                                          getVisibleRect().height, IMAGETYPE);
1122                  // }                          SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1123                    }
1124    
1125                  return bgImage;                  return bgImage;
1126          }          }
# Line 1078  public class XMapPane extends JPanel { Line 1138  public class XMapPane extends JPanel {
1138                          // Rectangle curPaintArea = getVisibleRect();                          // Rectangle curPaintArea = getVisibleRect();
1139                          finalImage = new BufferedImage(getVisibleRect().width,                          finalImage = new BufferedImage(getVisibleRect().width,
1140                                          getVisibleRect().height, IMAGETYPE);                                          getVisibleRect().height, IMAGETYPE);
1141                            SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1142    
1143                          requestStartRendering();                          // requestStartRendering();
1144                  }                  }
1145                  return finalImage;                  return finalImage;
1146          }          }
1147    
         public RenderingHints getJava2dHints() {  
                 return java2dHints;  
         }  
   
1148          /**          /**
1149           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1150           */           */
# Line 1096  public class XMapPane extends JPanel { Line 1153  public class XMapPane extends JPanel {
1153                  if (localImage == null) {                  if (localImage == null) {
1154                          localImage = new BufferedImage(getVisibleRect().width,                          localImage = new BufferedImage(getVisibleRect().width,
1155                                          getVisibleRect().height, IMAGETYPE_withAlpha);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1156                            SwingUtil.clearImage(localImage, getMapBackgroundColor());
1157                  }                  }
1158    
1159                  return localImage;                  return localImage;
# Line 1111  public class XMapPane extends JPanel { Line 1169  public class XMapPane extends JPanel {
1169                          ReferencedEnvelope mapArea_ = null;                          ReferencedEnvelope mapArea_ = null;
1170                          try {                          try {
1171                                  mapArea_ = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1172                          } catch (final IOException e) {                          } catch (final Exception e) {
1173                                  LOGGER.warn("localContext.getLayerBounds()", e);                                  LOGGER.warn("localContext.getLayerBounds()", e);
1174                          }                          }
1175    
# Line 1137  public class XMapPane extends JPanel { Line 1195  public class XMapPane extends JPanel {
1195                          try {                          try {
1196                                  localContext.setCoordinateReferenceSystem(GeoImportUtil                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1197                                                  .getDefaultCRS());                                                  .getDefaultCRS());
1198                          } catch (Exception e) {                          } catch (final Exception e) {
1199                                  throw new RuntimeException("setting context CRS:", e);                                  throw new RuntimeException("setting context CRS:", e);
1200                          }                          }
1201    
# Line 1146  public class XMapPane extends JPanel { Line 1204  public class XMapPane extends JPanel {
1204          }          }
1205    
1206          /**          /**
1207           * 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
1208             * methods looks for a parent component and will use its background color.
1209             * If no parent component is available, WHITE is returned.
1210           **/           **/
1211          public Color getMapBackgroundColor() {          public Color getMapBackgroundColor() {
1212                    if (mapBackgroundColor == null) {
1213                            if (getParent() != null)
1214                                    return getParent().getBackground();
1215                            else
1216                                    return Color.WHITE;
1217                    }
1218                  return mapBackgroundColor;                  return mapBackgroundColor;
1219          }          }
1220    
# Line 1175  public class XMapPane extends JPanel { Line 1241  public class XMapPane extends JPanel {
1241    
1242          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1243                  if (maxExtend == null) {                  if (maxExtend == null) {
1244                          // Commented-out because it takes soo much time!  
1245                          //                          // The next command may take long time!
1246                          // long start = System.currentTimeMillis();                          // long start = System.currentTimeMillis();
1247                          // final ReferencedEnvelope layerBounds = GTUtil                          final ReferencedEnvelope layerBounds = GTUtil
1248                          // .getVisibleLayoutBounds(localContext);                                          .getVisibleLayoutBounds(localContext);
1249                          //                                                //                      
1250                          // LOGGER.info(                          // LOGGER.info(
1251                          // (System.currentTimeMillis()-start)+"m to get maxExtend");                          // (System.currentTimeMillis()-start)+"m to get maxExtend");
1252                          //                                                //                      
1253                          // if (layerBounds == null) {                          if (layerBounds == null) {
1254                          // // TODO Last fallback could be the CRS valid area                                  // // TODO Last fallback could be the CRS valid area
1255                          // return null;                                  return null;
1256                          // }                          }
1257                          //  
1258                          // // Kartenbereich um 10% vergroessern                          return JTSUtil
1259                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil                                          .fixAspectRatio(getVisibleRect(), addDefaultMargin(layerBounds), true);
1260                          // .expandEnvelope(layerBounds, 0.1), true);  
1261                  }                  }
1262                  return maxExtend;                  return maxExtend;
1263          }          }
# Line 1219  public class XMapPane extends JPanel { Line 1285  public class XMapPane extends JPanel {
1285          }          }
1286    
1287          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();  
                 // }  
1288                  return preFinalImage;                  return preFinalImage;
1289          }          }
1290    
# Line 1256  public class XMapPane extends JPanel { Line 1312  public class XMapPane extends JPanel {
1312                  return new AffineTransform(screenToWorld);                  return new AffineTransform(screenToWorld);
1313          }          }
1314    
1315          public int getState() {          // public int getState() {
1316                  return state;          // return state;
1317          }          // }
1318            //
1319          /**          // /**
1320           * Liefert den statisch eingestellten Cursor, der unabhaengig von der          // * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1321           * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.          // * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1322           *          // *
1323           * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der          // * @return {@code null}, wenn kein statischer Cursor verwendet, sondern
1324           *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.          // der
1325           */          // * Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1326          public Cursor getStaticCursor() {          // */
1327                  return this.staticCursor;          // public Cursor getStaticCursor() {
1328          }          // return this.staticCursor;
1329            // }
1330    
1331          public AffineTransform getWorldToScreenTransform() {          public AffineTransform getWorldToScreenTransform() {
1332                  if (worldToScreen == null) {                  if (worldToScreen == null) {
# Line 1323  public class XMapPane extends JPanel { Line 1380  public class XMapPane extends JPanel {
1380          }          }
1381    
1382          /**          /**
1383           * Called from the listeners while the mouse is dragging, this method either           * Usually called from {@link XMapPaneAction_Pan} to pan the image.
          * paints a translated (moved/panned) version of the image, or a rectangle.  
1384           *           *
1385           * @param startPos           * @param startPos
1386           *            in screen coordinates           *            in screen coordinates
1387           * @param lastPos           * @param lastPos
1388           *            in screen coordinates           *            in screen coordinates
          * @param event  
          *            the {@link MouseEvent} to read the mouse buttons from  
1389           */           */
1390          public void mouseDragged(final Point startPos, final Point lastPos,          public void pan(final int dX, final int dY) {
                         final MouseEvent event) {  
1391    
1392                  if ((getState() == XMapPane.PAN)                  // Panning needs a panning coursor
1393                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {                  if (getCursor() != SwingUtil.PANNING_CURSOR) {
1394                            setCursor(SwingUtil.PANNING_CURSOR);
1395                          // Panning needs a panning coursor  
1396                          if (getCursor() != SwingUtil.PANNING_CURSOR) {                          // While panning, we deactivate the rendering. So the tasks are
1397                                  setCursor(SwingUtil.PANNING_CURSOR);                          // ready to start when the panning is finished.
1398                            if (bgExecuter != null && bgExecuter.isRunning())
1399                                  // While panning, we deactivate the rendering. So the tasks are                                  bgExecuter.cancelTask();
1400                                  // ready to start when the panning is finished.                          if (localExecuter.isRunning())
1401                                  if (bgExecuter != null && bgExecuter.isRunning())                                  localExecuter.cancelTask();
1402                                          bgExecuter.cancelTask();                  }
1403                                  if (localExecuter.isRunning())                  //
1404                                          localExecuter.cancelTask();                  // if (lastPos.x > 0 && lastPos.y > 0) {
1405                          }                  // final int dx = event.getX() - lastPos.x;
1406                    // final int dy = event.getY() - lastPos.y;
1407                          if (lastPos.x > 0 && lastPos.y > 0) {  
1408                                  final int dx = event.getX() - lastPos.x;                  // TODO Stop dragging when the drag would not be valid...
1409                                  final int dy = event.getY() - lastPos.y;                  // boolean dragValid = true;
1410                    // // check if this panning results in a valid mapArea
1411                                  // TODO Stop dragging when the drag would not be valid...                  // {
1412                                  // boolean dragValid = true;                  // Rectangle winBounds = xMapPane.getBounds();
1413                                  // // check if this panning results in a valid mapArea                  // winBounds.translate(xMapPane.imageOrigin.x,
1414                                  // {                  // -xMapPane.imageOrigin.y);
1415                                  // Rectangle winBounds = xMapPane.getBounds();                  // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(
1416                                  // winBounds.translate(xMapPane.imageOrigin.x,                  // winBounds.x, winBounds.y, winBounds.x
1417                                  // -xMapPane.imageOrigin.y);                  // + winBounds.width, winBounds.y
1418                                  // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(                  // + winBounds.height);
1419                                  // winBounds.x, winBounds.y, winBounds.x                  //                                      
1420                                  // + winBounds.width, winBounds.y                  //
1421                                  // + winBounds.height);                  // winBounds = xMapPane.getBounds();
1422                                  //                                                        // Point testIng = new Point(xMapPane.imageOrigin);
1423                                  //                  // testIng.translate(dx, dy);
1424                                  // winBounds = xMapPane.getBounds();                  // winBounds.translate(testIng.x, -testIng.y);
1425                                  // Point testIng = new Point(xMapPane.imageOrigin);                  // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(
1426                                  // testIng.translate(dx, dy);                  // winBounds.x, winBounds.y, winBounds.x
1427                                  // winBounds.translate(testIng.x, -testIng.y);                  // + winBounds.width, winBounds.y
1428                                  // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(                  // + winBounds.height);
1429                                  // winBounds.x, winBounds.y, winBounds.x                  //
1430                                  // + winBounds.width, winBounds.y                  // // If the last drag doesn't change the MapArea anymore cancel
1431                                  // + winBounds.height);                  // it.
1432                                  //                  // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(
1433                                  // // If the last drag doesn't change the MapArea anymore cancel                  // xMapPane.bestAllowedMapArea(newMapAreaBefore))){
1434                                  // it.                  // dragValid = false;
1435                                  // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(                  // return;
1436                                  // xMapPane.bestAllowedMapArea(newMapAreaBefore))){                  // }
1437                                  // dragValid = false;                  // }
                                 // return;  
                                 // }  
                                 // }  
1438    
1439                                  imageOrigin.translate(dx, dy);                  getImageOrigin().translate(dX, dY);
1440                                  updateFinalImage();                  updateFinalImage();
1441                                  repaint();                  repaint();
1442                          }                  // }
1443    
1444                  } else if ((getState() == XMapPane.ZOOM_IN)                  // } else if ((getState() == XMapPane.ZOOM_IN)
1445                                  || (getState() == XMapPane.ZOOM_OUT)                  // || (getState() == XMapPane.ZOOM_OUT)
1446                                  || (getState() == XMapPane.SELECT_ALL)                  // || (getState() == XMapPane.SELECT_ALL)
1447                                  || (getState() == XMapPane.SELECT_TOP)) {                  // || (getState() == XMapPane.SELECT_TOP)) {
1448                    //
1449                          // Draws a rectangle                  // // Draws a rectangle
1450                          final Graphics graphics = getGraphics();                  // final Graphics2D graphics = (Graphics2D) getGraphics();
1451                          drawRectangle(graphics, startPos, event.getPoint());                  // drawRectangle(graphics, startPos, event.getPoint());
1452                          if ((lastPos.x > 0) && (lastPos.y > 0))                  // if ((lastPos.x > 0) && (lastPos.y > 0))
1453                                  drawRectangle(graphics, startPos, lastPos);                  // drawRectangle(graphics, startPos, lastPos);
1454                          graphics.dispose();                  // graphics.dispose();
1455                  }                  // }
1456          }          }
1457    
1458          /**          /**
1459           * Called by the {@link RenderingExecutor} when rendering was cancelled.           * Called by the {@link RenderingExecutor} when rendering was cancelled.
1460           */           */
1461          public void onRenderingCancelled() {          public void onRenderingCancelled() {
1462                  LOGGER.debug("Rendering cancelled");                  // LOGGER.debug("Rendering cancelled");
1463                  repaintTimer.stop();                  repaintTimer.stop();
1464          }          }
1465    
1466          /**          /**
1467           * Called by the {@link RenderingExecutor} when rendering has been           * Called by the {@link RenderingExecutor} when rendering has been
1468           * completed.           * completed.
1469             *
1470             * @param l
1471             *            long ms the rendering took
1472           */           */
1473          public void onRenderingCompleted() {          public void onRenderingCompleted(final long l) {
1474                  LOGGER.info("complete");                  lastRenderingDuration = (lastRenderingDuration + l) / 2;
1475                    // LOGGER
1476                    // .debug("complete rendering after " + lastRenderingDuration
1477                    // + "ms");
1478    
1479                  repaintTimer.stop();                  repaintTimer.stop();
1480    
# Line 1470  public class XMapPane extends JPanel { Line 1526  public class XMapPane extends JPanel {
1526    
1527                  if (!isWellDefined())                  if (!isWellDefined())
1528                          return;                          return;
1529                    //
1530                    // if (paneResized) {
1531                    // // ((Graphics2D) g).setBackground(getMapBackgroundColor());
1532                    // // g.clearRect(0, 0, getVisibleRect().width,
1533                    // getVisibleRect().height);
1534                    // return;
1535                    // }
1536    
1537                  // super.paintComponent(g); // candidate for removal                  // super.paintComponent(g); // candidate for removal
1538    
# Line 1482  public class XMapPane extends JPanel { Line 1545  public class XMapPane extends JPanel {
1545                          // If the new mapArea and the oldMapArea intersect, we can draw some                          // If the new mapArea and the oldMapArea intersect, we can draw some
1546                          // quick scaled preview to make the user feel that something is                          // quick scaled preview to make the user feel that something is
1547                          // happening.                          // happening.
1548                          if (mapAreaChanged && oldMapArea != null                          if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged
1549                                            && oldMapArea != null
1550                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1551                                          & !getMapArea().equals(oldMapArea) && !paneResized) {                                          && !getMapArea().equals(oldMapArea) && !paneResized) {
1552    
1553                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1554    
1555                                  if (getMapArea().covers(oldMapArea)) {                                  // if (getMapArea().covers(oldMapArea)) {
1556                                          quickPreviewHint = ZOOM_OUT;                                  // // quickPreviewHint = ZOOM_OUT;
1557                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D)
1558                                  } else if (oldMapArea.covers(getMapArea())) {                                  // g);
1559                                          quickPreviewHint = ZOOM_IN;                                  // } else if (oldMapArea.covers(getMapArea())) {
1560                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // quickPreviewHint = ZOOM_IN;
1561                                  }                                  paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1562                                    // }
1563                          }                          }
1564                  }                  }
1565    
# Line 1502  public class XMapPane extends JPanel { Line 1567  public class XMapPane extends JPanel {
1567    
1568                          g.drawImage(getFinalImage(), 0, 0, null);                          g.drawImage(getFinalImage(), 0, 0, null);
1569    
                         g.dispose(); // cand. for removal  
   
1570                          paintedSomething = true; // cand. for removal                          paintedSomething = true; // cand. for removal
1571                  }                  }
1572    
# Line 1552  public class XMapPane extends JPanel { Line 1615  public class XMapPane extends JPanel {
1615    
1616          }          }
1617    
1618          /**          //
1619           * Performs a {@value #PAN} action. During panning, the displacement is          // /**
1620           * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will          // * Performs a {@value #PAN} action. During panning, the displacement is
1621           * reset the offset and call {@link #setMapArea(Envelope)}.          // * stored in {@link #imageOrigin} object. Calling {@link #performPan()}
1622           */          // will
1623          public void performPan() {          // * reset the offset and call {@link #setMapArea(Envelope)}.
1624            // */
1625                  Rectangle winBounds = getVisibleRect();          // public void performPan() {
1626            //
1627                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);          // final Rectangle winBounds = getVisibleRect();
1628                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,          //
1629                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y          // winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1630                                                  + winBounds.height);          // final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1631            // winBounds.y, winBounds.x + winBounds.width, winBounds.y
1632                  imageOrigin.x = 0;          // + winBounds.height);
1633                  imageOrigin.y = 0;          //
1634            // imageOrigin.x = 0;
1635                  if (!setMapArea(newMapArea)) {          // imageOrigin.y = 0;
1636                          /**          //
1637                           * If setMapArea returns true, the finalImage is updated anyways.          // if (!setMapArea(newMapArea)) {
1638                           * This if-case exists to ensure that we repaint a correct image          // /**
1639                           * even if the new panning area has been denied.          // * If setMapArea returns true, the finalImage is updated anyways.
1640                           */          // * This if-case exists to ensure that we repaint a correct image
1641                          updateFinalImage();          // * even if the new panning area has been denied.
1642                          repaint();          // */
1643                  }          // updateFinalImage();
1644            // repaint();
1645                  if (getCursor() == SwingUtil.PANNING_CURSOR)          // }
1646                          setCursor(SwingUtil.PAN_CURSOR);          //
1647          }          // if (getCursor() == SwingUtil.PANNING_CURSOR)
1648            // setCursor(SwingUtil.PAN_CURSOR);
1649            // }
1650    
1651          /**          /**
1652           * Entfernt einen Listener von der Map.           * Entfernt einen Listener von der Map.
# Line 1627  public class XMapPane extends JPanel { Line 1692  public class XMapPane extends JPanel {
1692           *            the current map pane extent (screen units)           *            the current map pane extent (screen units)
1693           */           */
1694          private void resetTransforms() {          private void resetTransforms() {
                 ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,  
                                 getMapContext().getCoordinateReferenceSystem());  
   
1695                  // System.out                  // System.out
1696                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1697                  if (!isWellDefined())                  if (!isWellDefined())
1698                          return;                          return;
1699    
1700                    if (mapArea == null)
1701                            return;
1702    
1703                    final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1704                                    getMapContext().getCoordinateReferenceSystem());
1705    
1706                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1707                                  getVisibleRect());                                  getVisibleRect());
1708    
1709                  try {                  try {
1710                          screenToWorld = worldToScreen.createInverse();                          screenToWorld = worldToScreen.createInverse();
1711    
1712                  } catch (NoninvertibleTransformException ex) {                  } catch (final NoninvertibleTransformException ex) {
1713                          LOGGER                          LOGGER
1714                                          .error("can't invert worldToScreen to get screenToWorld!",                                          .error("can't invert worldToScreen to get screenToWorld!",
1715                                                          ex);                                                          ex);
# Line 1697  public class XMapPane extends JPanel { Line 1765  public class XMapPane extends JPanel {
1765    
1766                          // setMapArea(localContext.getAreaOfInterest());                          // setMapArea(localContext.getAreaOfInterest());
1767    
1768                          localRenderer.setContext(localContext);                          getLocalRenderer().setContext(localContext);
1769    
1770                          this.localContext.addMapLayerListListener(localContextListener);                          this.localContext.addMapLayerListListener(localContextListener);
1771    
# Line 1711  public class XMapPane extends JPanel { Line 1779  public class XMapPane extends JPanel {
1779    
1780          }          }
1781    
1782            public void setBorder(final Border b) {
1783                    super.setBorder(b);
1784            }
1785    
1786            /**
1787             * Triggers to repaint (fast) and re-render (slow) the JMapPane.
1788             */
1789            public void refresh() {
1790                    mapImageInvalid = true;
1791                    repaint();
1792            }
1793    
1794            // /**
1795            // * Triggers to use new {@link GTRenderer} and refresh the map. Should be
1796            // * called after {@link Style}s have been changed because GTRenderer is
1797            // * otherwise not working well.
1798            // */
1799            // public void refreshRenderers() {
1800            // localRenderer = GTUtil.createGTRenderer();
1801            // setLocalContext(getMapContext());
1802            // mapImageInvalid = true;
1803            // repaint();
1804            // }
1805    
1806            /**
1807             * Set the new map area.
1808             *
1809             * @param newMapArea
1810             * @return <code>true</code> if the mapArea has been changed and a repaint
1811             *         has been triggered.
1812             */
1813          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1814                    if (newMapArea == null)
1815                            return false;
1816                    if (getMapContext().getCoordinateReferenceSystem() == null)
1817                            return false;
1818                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1819                                  .getCoordinateReferenceSystem()));                                  .getCoordinateReferenceSystem()));
1820          }          }
1821    
1822          /**          /**
1823             * Set the new map area.
1824             *
1825           * @param newMapArea           * @param newMapArea
1826           * @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
1827           *         has been triggered.           *         has been triggered.
# Line 1791  public class XMapPane extends JPanel { Line 1896  public class XMapPane extends JPanel {
1896           *           *
1897           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1898           */           */
1899          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(final Color bgColor) {
                 if (bgColor == null)  
                         bgColor = Color.WHITE;  
1900                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1901          }          }
1902    
# Line 1851  public class XMapPane extends JPanel { Line 1954  public class XMapPane extends JPanel {
1954          }          }
1955    
1956          // /** Stored the time used for the last real rendering in ms. **/          // /** Stored the time used for the last real rendering in ms. **/
1957          // private long lastRenderingDuration = Long.MAX_VALUE;          private long lastRenderingDuration = 1000;
1958            private XMapPaneTool tool = null;
1959    
1960          /**          /**
1961           * 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 1883  public class XMapPane extends JPanel { Line 1987  public class XMapPane extends JPanel {
1987                          this.rendererHints = rendererHints;                          this.rendererHints = rendererHints;
1988          }          }
1989    
1990          /**          // @Deprecated
1991           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the          // public void setState(final int state) {
1992           * repaint Timer if          // this.state = state;
1993           *          //
1994           * @param state          // // throw new RuntimeException("Old concept.. migrate to new concept!");
1995           */          //
1996          public void setState(final int state) {          // // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
1997                  this.state = state;          // // || state == ZOOM_OUT || state == PAN));
1998            //
1999                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN          // // Je nach Aktion den Cursor umsetzen
2000                                  || state == ZOOM_OUT || state == PAN));          // updateCursor();
2001            // }
2002                  // Je nach Aktion den Cursor umsetzen  
2003                  updateCursor();          public void configureMouse(MouseInputType type, XMapPaneAction action) {
2004                    xMapPaneMouseListener.actions.put(type, action);
2005          }          }
2006    
2007          /**          /**
2008           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,           * Configure the {@link XMapPaneTool} that active on the map. Passing
2009           * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor           * <code>null</code> will set the NO_ACTION tool.
2010           * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion           */
2011           * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann          public void setTool(XMapPaneTool tool) {
2012           * {@code null} als Parameter uebergeben werden                  if (tool == null)
2013           *                          tool = XMapPaneTool.NO_ACTION;
2014           * @param cursor                  this.tool = tool;
2015           *            Cursor                  xMapPaneMouseListener.configure(tool);
2016           */                  setCursor(tool.getCursor());
2017          public void setStaticCursor(final Cursor cursor) {          }
2018                  this.staticCursor = cursor;  
2019                  if (cursor != null)          // /**
2020                          super.setCursor(cursor);          // * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion
2021          }          // (Zoom,
2022            // * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
2023            // * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
2024            // * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
2025            // * {@code null} als Parameter uebergeben werden
2026            // *
2027            // * @param cursor
2028            // * Cursor
2029            // */
2030            // public void setStaticCursor(final Cursor cursor) {
2031            // this.staticCursor = cursor;
2032            // if (cursor != null)
2033            // super.setCursor(cursor);
2034            // }
2035    
2036          /**          /**
2037           * Starts rendering on one or two threads           * Starts rendering on one or two threads
# Line 1959  public class XMapPane extends JPanel { Line 2077  public class XMapPane extends JPanel {
2077                          // localExecuter = new RenderingExecutor(this, 150l);                          // localExecuter = new RenderingExecutor(this, 150l);
2078                          // LOGGER.debug("starting local renderer:");                          // LOGGER.debug("starting local renderer:");
2079    
2080                          localRenderer.setJava2DHints(getJava2dHints());                          getLocalRenderer().setJava2DHints(getJava2dHints());
2081                          localRenderer.setRendererHints(getRendererHints());                          getLocalRenderer().setRendererHints(getRendererHints());
2082    
2083                          final boolean submitted = localExecuter.submit(getMapArea(),                          final boolean submitted = localExecuter.submit(getMapArea(),
2084                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
2085                                          localRenderer);                                          getLocalRenderer());
2086                          if (submitted)                          if (submitted)
2087                                  repaintTimer.restart();                                  repaintTimer.restart();
2088                          else                          else
# Line 1976  public class XMapPane extends JPanel { Line 2094  public class XMapPane extends JPanel {
2094                  updateCursor();                  updateCursor();
2095          }          }
2096    
2097            private RenderingHints getJava2dHints() {
2098                    return java2dHints;
2099            }
2100    
2101          /**          /**
2102           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.
2103           *           *
# Line 2051  public class XMapPane extends JPanel { Line 2173  public class XMapPane extends JPanel {
2173                                  repaint();                                  repaint();
2174                          }                          }
2175                  }                  }
2176                    //              
2177                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig                  // //
2178                  // von der aktuellen Aktion                  // // wenn manueller Cursor gesetzt ist, dann diesen verwenden
2179                  if (this.staticCursor != null) {                  // (unabhaengig
2180                          setCursor(staticCursor);                  // // von der aktuellen Aktion
2181                          return;                  // if (this.staticCursor != null) {
2182                  }                  // setCursor(staticCursor);
2183                    // return;
2184                    // }
2185                    //              
2186                  if (getCursor() == SwingUtil.PANNING_CURSOR) {                  if (getCursor() == SwingUtil.PANNING_CURSOR) {
2187                          // This cursor will reset itself                          // This cursor will reset itself
2188                          return;                          return;
2189                  }                  }
2190    
2191                  // Set the cursor depending on what tool is in use...                  setCursor(tool.getCursor());
2192                  switch (state) {  
2193                  case SELECT_TOP:                  //
2194                  case SELECT_ONE_FROM_TOP:                  // // Set the cursor depending on what tool is in use...
2195                  case SELECT_ALL:                  // switch (state) {
2196                          setCursor(SwingUtil.CROSSHAIR_CURSOR);                  // case SELECT_TOP:
2197                          break;                  // case SELECT_ONE_FROM_TOP:
2198                  case ZOOM_IN:                  // case SELECT_ALL:
2199                          setCursor(SwingUtil.ZOOMIN_CURSOR);                  // setCursor(SwingUtil.CROSSHAIR_CURSOR);
2200                          break;                  // break;
2201                  case ZOOM_OUT:                  // case ZOOM_IN:
2202                          setCursor(SwingUtil.ZOOMOUT_CURSOR);                  // setCursor(SwingUtil.ZOOMIN_CURSOR);
2203                          break;                  // break;
2204                  case PAN:                  // case ZOOM_OUT:
2205                          setCursor(SwingUtil.PAN_CURSOR);                  // setCursor(SwingUtil.ZOOMOUT_CURSOR);
2206                          break;                  // break;
2207                  default:                  // case PAN:
2208                          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));                  // setCursor(SwingUtil.PAN_CURSOR);
2209                          break;                  // break;
2210                  }                  // default:
2211                    // setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2212                    // break;
2213                    // }
2214          }          }
2215    
2216          /**          /**
# Line 2112  public class XMapPane extends JPanel { Line 2240  public class XMapPane extends JPanel {
2240    
2241                  final Graphics2D finalG = getFinalImage().createGraphics();                  final Graphics2D finalG = getFinalImage().createGraphics();
2242                  finalG.setBackground(getMapBackgroundColor());                  finalG.setBackground(getMapBackgroundColor());
2243                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), getImageOrigin().x,
2244                                  getMapBackgroundColor(), null);                                  getImageOrigin().y, getMapBackgroundColor(), null);
2245    
2246                  final int finalImageHeight = getFinalImage().getHeight(null);                  // When panning, we have to clear the area around the image
2247                  final int finalImageWidth = getFinalImage().getWidth(null);                  final Rectangle painedArea = new Rectangle(getImageOrigin().x,
2248                                    getImageOrigin().y, getFinalImage().getWidth(), getFinalImage()
2249                                                    .getHeight());
2250                    SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
2251                                    getMapBackgroundColor());
2252    
2253                  final Rectangle painedArea = new Rectangle(imageOrigin.x,                   addGadgets(finalG, false);
                                 imageOrigin.y, finalImageWidth, finalImageHeight);  
                 SwingUtil.clearAround(finalG, painedArea, getVisibleRect());  
   
                 addGadgets(finalG, false);  
2254    
2255                  finalG.dispose();                  finalG.dispose();
2256    
# Line 2139  public class XMapPane extends JPanel { Line 2267  public class XMapPane extends JPanel {
2267           *            <code>false</code>, it will only depend on           *            <code>false</code>, it will only depend on
2268           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2269           */           */
2270          private void addGadgets(final Graphics2D graphics, boolean forceWait) {          private void addGadgets(final Graphics2D graphics, final boolean forceWait) {
2271    
2272                  // Paint a logo to the bottom right if available                  // Paint a logo to the bottom right if available
2273                  if (mapImage != null) {                  if (mapImage != null) {
2274                          Rectangle visibleRect = getVisibleRect();                          final Rectangle visibleRect = getVisibleRect();
2275                          graphics.drawImage(mapImage, visibleRect.width                          graphics.drawImage(mapImage, visibleRect.width
2276                                          - mapImage.getWidth() - 10, getVisibleRect().height                                          - mapImage.getWidth() - 10, getVisibleRect().height
2277                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
# Line 2169  public class XMapPane extends JPanel { Line 2297  public class XMapPane extends JPanel {
2297    
2298                          graphics.setColor(c);                          graphics.setColor(c);
2299    
2300                          y += 24;                          y += 21;
2301                  }                  }
2302    
2303                  if (!renderingErrors.isEmpty() && isShowExceptions()) {                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
# Line 2177  public class XMapPane extends JPanel { Line 2305  public class XMapPane extends JPanel {
2305                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2306                          graphics.setFont(errorFont);                          graphics.setFont(errorFont);
2307    
2308                          for (Exception ex : renderingErrors) {                          for (final Exception ex : renderingErrors) {
2309    
2310                                  String errStr = ex.getLocalizedMessage();                                  String errStr = ex.getLocalizedMessage();
2311    
# Line 2186  public class XMapPane extends JPanel { Line 2314  public class XMapPane extends JPanel {
2314                                  if (errStr == null)                                  if (errStr == null)
2315                                          errStr = "unknown error: " + ex.getClass().getSimpleName();                                          errStr = "unknown error: " + ex.getClass().getSimpleName();
2316    
2317                                  graphics.setColor(Color.WHITE);                                  graphics.setColor(getMapBackgroundColor());
2318                                  graphics.drawString(errStr, 5, y);                                  graphics.drawString(errStr, 5, y);
2319                                  graphics.setColor(Color.RED);                                  graphics.setColor(Color.RED);
2320                                  graphics.drawString(errStr, 6, y + 1);                                  graphics.drawString(errStr, 6, y + 1);
# Line 2214  public class XMapPane extends JPanel { Line 2342  public class XMapPane extends JPanel {
2342                  final CoordinateReferenceSystem mapCRS = getMapContext()                  final CoordinateReferenceSystem mapCRS = getMapContext()
2343                                  .getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2344                  final CoordinateReferenceSystem fCRS = features.getSchema()                  final CoordinateReferenceSystem fCRS = features.getSchema()
2345                                  .getGeometryDescriptor().getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2346    
2347                  ReferencedEnvelope _mapArea;                  ReferencedEnvelope _mapArea;
2348                  if (mapArea == null)                  if (mapArea == null)
# Line 2283  public class XMapPane extends JPanel { Line 2411  public class XMapPane extends JPanel {
2411                          // BB umrechnen von Layer-CRS in Map-CRS                          // BB umrechnen von Layer-CRS in Map-CRS
2412    
2413                          // Expand a bit                          // Expand a bit
2414                          bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.);                          addDefaultMargin(bounds);
2415    
2416                          setMapArea(bounds);                          setMapArea(bounds);
2417                  }                  }
2418          }          }
2419    
2420            private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) {
2421                    return JTSUtil.expandEnvelope(bounds, Math.max(0,
2422                                    defaultMaxMapExtendMode));
2423            }
2424    
2425            private Envelope addDefaultMargin(Envelope bounds) {
2426                    return JTSUtil.expandEnvelope(bounds, Math.max(0,
2427                                    defaultMaxMapExtendMode));
2428            }
2429    
2430          /**          /**
2431           * Zooms towards a point.           * Zooms towards a point.
2432           *           *
# Line 2307  public class XMapPane extends JPanel { Line 2445  public class XMapPane extends JPanel {
2445           * @param center           * @param center
2446           *            position in window coordinates           *            position in window coordinates
2447           * @param zoomFaktor           * @param zoomFaktor
2448           *            > 1 for zoom in, < 1 for zoom out. Default is 1.33.           *            > 1 for zoom out, < 1 for zoom in. Default is .5
2449           */           */
2450          public void zoomTo(Point center, Double zoomFaktor) {          public void zoomTo(Point center, Double zoomFaktor) {
2451                  if (zoomFaktor == null || zoomFaktor == 0.)                  if (zoomFaktor == null || zoomFaktor == 0.)
2452                          zoomFaktor = 2.;                          zoomFaktor = .5;
2453    
2454                  final Point2D gcenter = getScreenToWorld().transform(center, null);                  final Point2D gcenter = getScreenToWorld().transform(center, null);
2455                  center = null;                  center = null;
# Line 2332  public class XMapPane extends JPanel { Line 2470  public class XMapPane extends JPanel {
2470                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2471                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2472    
2473                  // TODO we actually want that                  // // Move the newMapArea above the new center if we zoom in:
2474                  // // Move the newMapArea above the new center                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2475                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                                  .getY()
2476                  // .getY()                                  - mapArea.centre().y);
                 // - mapArea.centre().y);  
2477    
2478                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2479          }          }
# Line 2345  public class XMapPane extends JPanel { Line 2482  public class XMapPane extends JPanel {
2482           * Shall non-fatal rendering exceptions be reported in the mappane or be           * Shall non-fatal rendering exceptions be reported in the mappane or be
2483           * dropped quitely.           * dropped quitely.
2484           */           */
2485          public void setShowExceptions(boolean showExceptions) {          public void setShowExceptions(final boolean showExceptions) {
2486                  this.showExceptions = showExceptions;                  this.showExceptions = showExceptions;
2487          }          }
2488    
# Line 2356  public class XMapPane extends JPanel { Line 2493  public class XMapPane extends JPanel {
2493                  return showExceptions;                  return showExceptions;
2494          }          }
2495    
2496            public GTRenderer getLocalRenderer() {
2497                    return localRenderer;
2498            }
2499    
2500            /**
2501             * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
2502             * Macht nichts, wenn {@code null} uebergeben wird.
2503             *
2504             * <br>
2505             *
2506             * @param layer
2507             *            ein Layer
2508             */
2509            public void zoomToLayer(MapLayer layer) {
2510                    if (layer == null)
2511                            return;
2512                    try {
2513    
2514                            // BB umrechnen von Layer-CRS in Map-CRS
2515                            final CoordinateReferenceSystem targetCRS = getMapContext()
2516                                            .getCoordinateReferenceSystem();
2517                            final CoordinateReferenceSystem sourceCRS = layer
2518                                            .getFeatureSource().getSchema()
2519                                            .getCoordinateReferenceSystem();
2520    
2521                            Envelope mapAreaNew;
2522                            if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
2523                                    mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource()
2524                                                    .getBounds(), sourceCRS, targetCRS);
2525                            } else {
2526                                    try {
2527                                            mapAreaNew = layer.getFeatureSource().getBounds();
2528                                    } catch (java.lang.IllegalArgumentException e) {
2529                                            LOGGER.error("Can't calc layers bounds...", e);
2530                                            mapAreaNew = null;
2531    
2532                                            /**
2533                                             *
2534                                             23.10.2009 11:20:50
2535                                             * org.geotools.data.shapefile.shp.PolygonHandler read
2536                                             * WARNUNG: only one hole in this polygon record ERROR
2537                                             * JMapPane zoomToLayer Zoom to layer did not terminate
2538                                             * correctly java.lang.IllegalArgumentException: Points of
2539                                             * LinearRing do not form a closed linestring at
2540                                             * com.vividsolutions
2541                                             * .jts.geom.LinearRing.validateConstruction
2542                                             * (LinearRing.java:105) at
2543                                             * com.vividsolutions.jts.geom.LinearRing
2544                                             * .<init>(LinearRing.java:100) at
2545                                             * com.vividsolutions.jts.geom
2546                                             * .GeometryFactory.createLinearRing
2547                                             * (GeometryFactory.java:339) at
2548                                             * org.geotools.data.shapefile.
2549                                             * shp.PolygonHandler.read(PolygonHandler.java:188) at
2550                                             * org.geotools
2551                                             * .data.shapefile.shp.ShapefileReader$Record.shape
2552                                             * (ShapefileReader.java:106) at
2553                                             * org.geotools.data.shapefile.
2554                                             * ShapefileAttributeReader.next(
2555                                             * ShapefileAttributeReader.java:157) at
2556                                             * org.geotools.data.shapefile
2557                                             * .indexed.IndexedShapefileAttributeReader
2558                                             * .next(IndexedShapefileAttributeReader.java:122) at
2559                                             * org.geotools
2560                                             * .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at
2561                                             * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.
2562                                             * java:55) at org.geotools.data.MaxFeatureReader.next(
2563                                             * MaxFeatureReader.java:61) at
2564                                             * org.geotools.data.MaxFeatureReader
2565                                             * .next(MaxFeatureReader.java:61)
2566                                             **/
2567                                    }
2568                            }
2569    
2570                            // Kartenbereich um 10% vergroessern, damit z.B. auch ein
2571                            // Punkt-Layer,
2572                            // welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen
2573                            // sonst
2574                            // genau auf dem Rand der angezeigten Flaeche)
2575    
2576                            if (mapAreaNew != null) {
2577    
2578                                    mapAreaNew = addDefaultMargin(mapAreaNew);
2579                                    setMapArea(mapAreaNew);
2580                            } else {
2581                                    LOGGER
2582                                                    .warn("Couldn't transformEnvelope when zooming to the layer");
2583                            }
2584                    } catch (Exception err) {
2585                            LOGGER.error("Zoom to layer did not terminate correctly", err);
2586                    }
2587            }
2588    
2589            /**
2590             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer.
2591             *
2592             * <br>
2593             * A refresh of the map is not done automatically
2594             *
2595             * @param index
2596             *            Index of the {@link MapLayer} in the {@link MapContext} (from
2597             *            back to top)
2598             *
2599             * @author <a href="mailto:[email protected]">Stefan Alfons
2600             *         Kr&uuml;ger</a>
2601             */
2602            public void zoomToLayer(int index) {
2603                    final MapContext context = getMapContext();
2604                    if (context != null)
2605                            zoomToLayer(context.getLayer(index));
2606            }
2607    
2608            /**
2609             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the
2610             * selected layer. The layer is selected by the idx, counting from front to
2611             * back, like humans would expect in a {@link JList}
2612             *
2613             * <br>
2614             * A refresh of the map is not done automatically
2615             *
2616             *
2617             *
2618             * @param index
2619             *            Reverse index of the {@link MapLayer} in the
2620             *            {@link MapContext}
2621             *
2622             * @author <a href="mailto:[email protected]">Stefan Alfons
2623             *         Kr&uuml;ger</a>
2624             */
2625            public void zoomToLayerIdxReverse(int index) {
2626                    zoomToLayer(getMapContext().getLayerCount() - 1 - index);
2627            }
2628    
2629            /**
2630             * Aktiviert oder deaktiviert das AntiAliasing for diese
2631             * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
2632             * Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance.
2633             *
2634             * @author <a href="mailto:[email protected]">Stefan Alfons
2635             *         Kr&uuml;ger</a>
2636             */
2637            public void setAntiAliasing(final boolean aa) {
2638                    // LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa);
2639                    RenderingHints java2DHints = java2dHints;
2640                    if (java2DHints == null) {
2641                            java2DHints = GeoTools.getDefaultHints();
2642                    }
2643    
2644                    java2DHints.put(RenderingHints.KEY_ANTIALIASING,
2645                                    aa ? RenderingHints.VALUE_ANTIALIAS_ON
2646                                                    : RenderingHints.VALUE_ANTIALIAS_OFF);
2647                    java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
2648                                    aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
2649                                                    : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
2650                    java2DHints.put(RenderingHints.KEY_RENDERING,
2651                                    aa ? RenderingHints.VALUE_RENDER_QUALITY
2652                                                    : RenderingHints.VALUE_RENDER_SPEED);
2653    
2654            }
2655    
2656            public Point getImageOrigin() {
2657                    return imageOrigin;
2658            }
2659    
2660            /**
2661             * If {@link #maxExtend} is <code>null</code> the following rules are used
2662             * to create a default maximum.
2663             * <ul>
2664             * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
2665             * margin</li>
2666             * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
2667             * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
2668             * relative margin</li>
2669             * </ul>
2670             * **/
2671            public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode) {
2672                    this.defaultMaxMapExtendMode = defaultMaxMapExtendMode;
2673            }
2674    
2675            /**
2676             * If {@link #maxExtend} is <code>null</code> the following rules are used
2677             * to create a default maximum.
2678             * <ul>
2679             * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
2680             * margin</li>
2681             * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
2682             * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
2683             * relative margin</li>
2684             * </ul>
2685             * **/
2686            public double getDefaultMaxMapExtendMode() {
2687                    return defaultMaxMapExtendMode;
2688            }
2689    
2690  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26