/[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 560 by alfonx, Tue Nov 24 14:57:05 2009 UTC branches/2.0-RC2/src/skrueger/geotools/XMapPane.java revision 655 by alfonx, Wed Feb 3 11:47:44 2010 UTC
# Line 26  import java.util.HashMap; Line 26  import java.util.HashMap;
26  import java.util.Map;  import java.util.Map;
27  import java.util.Vector;  import java.util.Vector;
28    
29  import javax.jws.soap.SOAPBinding.Style;  import javax.swing.JList;
30  import javax.swing.Timer;  import javax.swing.Timer;
31    import javax.swing.border.Border;
32    
33  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
34    import org.geotools.factory.GeoTools;
35  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
36    import org.geotools.geometry.DirectPosition2D;
37  import org.geotools.geometry.jts.JTS;  import org.geotools.geometry.jts.JTS;
38  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
39  import org.geotools.map.DefaultMapContext;  import org.geotools.map.DefaultMapContext;
# Line 66  import schmitzm.geotools.map.event.MapLa Line 69  import schmitzm.geotools.map.event.MapLa
69  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
70  import schmitzm.swing.JPanel;  import schmitzm.swing.JPanel;
71  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
72    import schmitzm.swing.event.MouseInputType;
73    
74  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
75  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 96  import com.vividsolutions.jts.geom.Geome Line 100  import com.vividsolutions.jts.geom.Geome
100   */   */
101  public class XMapPane extends JPanel {  public class XMapPane extends JPanel {
102    
103          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;          // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
104          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;          // private static final int IMAGETYPE_withAlpha =
105            // BufferedImage.TYPE_INT_ARGB;
106            private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
107            public XMapPaneTool getTool() {
108                    return tool;
109            }
110    
111            private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;
112    
113          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
114    
115            /**
116             * A flag indicating whether the {@link XMapPane} is accepting repaints from
117             * the EDT. @see {@link XMapPane#setPainting(boolean))
118             **/
119          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
120    
121          /**          /**
# Line 163  public class XMapPane extends JPanel { Line 178  public class XMapPane extends JPanel {
178           * Flag for no-tool.           * Flag for no-tool.
179           */           */
180          public static final int NONE = -123;          public static final int NONE = -123;
181    //
182          /**  //      /**
183           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl  //       * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
184           * moeglich!  //       * moeglich!
185           *  //       *
186           * @see #setState(int)  //       * @see #setState(int)
187           */  //       */
188          public static final int PAN = 1;  //      public static final int PAN = 1;
189    //
190          /**  //      /**
191           * Flag fuer Modus "Heran zoomen".  //       * Flag fuer Modus "Heran zoomen".
192           *  //       *
193           * @see #setState(int)  //       * @see #setState(int)
194           * @see #setState(int)  //       * @see #setState(int)
195           */  //       */
196          public static final int ZOOM_IN = 2;  //      public static final int ZOOM_IN = 2;
197    //
198          /**  //      /**
199           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!  //       * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
200           *  //       *
201           * @see #setState(int)  //       * @see #setState(int)
202           */  //       */
203          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;  
204    
205          /**          /**
206           * {@link Font} used to paint the wait messages into the map           * {@link Font} used to paint the wait messages into the map
207           *           *
208           * @see #addGadgets(Graphics2D, boolean)           * @see #addGadgets(Graphics2D, boolean)
209           */           */
210          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 28);
211    
212          /**          /**
213           * {@link Font} used to paint error messages into the map           * {@link Font} used to paint error messages into the map
# Line 226  public class XMapPane extends JPanel { Line 217  public class XMapPane extends JPanel {
217          final static Font errorFont = new Font("Arial", Font.BOLD, 13);          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
218    
219          /**          /**
220             * If last average last two renderings took more than that many ms, show the
221             * user a scaled preview
222             **/
223            private static final long PRESCALE_MINTIME = 230;
224    
225            /**
226           * 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
227           * another thread.           * another thread.
228           *           *
# Line 240  public class XMapPane extends JPanel { Line 237  public class XMapPane extends JPanel {
237           * @param e           * @param e
238           *            Maus-Ereignis           *            Maus-Ereignis
239           */           */
240          public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {          public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) {
241                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln
242                  if (e != null && e instanceof MapMouseEvent)                  if (e != null && e instanceof MapMouseEvent)
243                          try {                          try {
244                                  return ((MapMouseEvent) e).getMapPosition().toPoint2D();                                  return ((MapMouseEvent) e).getMapPosition();
245                          } catch (final Exception err) {                          } catch (final Exception err) {
246                                  LOGGER                                  LOGGER
247                                                  .error(                                                  .error(
# Line 261  public class XMapPane extends JPanel { Line 258  public class XMapPane extends JPanel {
258                                  return null;                                  return null;
259    
260                          final AffineTransform at = xMapPane.getScreenToWorld();                          final AffineTransform at = xMapPane.getScreenToWorld();
261                          if (at != null)                          if (at != null) {
262                                  return at.transform(e.getPoint(), null);                                  Point2D transformed = at.transform(e.getPoint(), null);
263                                    return new DirectPosition2D(xMapPane.getMapContext()
264                                                    .getCoordinateReferenceSystem(), transformed.getX(),
265                                                    transformed.getY());
266                            }
267                          return null;                          return null;
268                  }                  }
269                  throw new IllegalArgumentException(                  throw new IllegalArgumentException(
# Line 277  public class XMapPane extends JPanel { Line 278  public class XMapPane extends JPanel {
278    
279                  @Override                  @Override
280                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
281                          MapLayer layer = event.getLayer();                          final MapLayer layer = event.getLayer();
282                          layer.addMapLayerListener(bgMapLayerListener);                          layer.addMapLayerListener(bgMapLayerListener);
283                          requestStartRendering();                          requestStartRendering();
   
284                  }                  }
285    
286                  @Override                  @Override
# Line 374  public class XMapPane extends JPanel { Line 374  public class XMapPane extends JPanel {
374           * While dragging, the {@link #updateFinalImage()} method is translating the           * While dragging, the {@link #updateFinalImage()} method is translating the
375           * cached images while setting it together.           * cached images while setting it together.
376           **/           **/
377          Point imageOrigin = new Point(0, 0);          private final Point imageOrigin = new Point(0, 0);
378          /**          /**
379           * For every rendering thread started,           * For every rendering thread started,
380           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new
# Line 403  public class XMapPane extends JPanel { Line 403  public class XMapPane extends JPanel {
403    
404                  @Override                  @Override
405                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
406  //                      localRenderer = GTUtil.createGTRenderer();                          // getLocalRenderer().setContext(getMapContext()); geht doch auch
407                          getLocalRenderer().setContext(getMapContext());                          // ohne?!?!? wow...
408                          requestStartRendering();                          requestStartRendering();
409                  }                  }
410    
# Line 425  public class XMapPane extends JPanel { Line 425  public class XMapPane extends JPanel {
425    
426          /**          /**
427           * Listens to each layer in the local {@link MapContext} for changes and           * Listens to each layer in the local {@link MapContext} for changes and
428           * triggers repaints.           * triggers repaints. We don't have to listen layerChanged, because that is
429             * already done in {@link #localContextListener}
430           */           */
431          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
432    
433                  @Override                  // @Override
434                  public void layerChanged(final MapLayerEvent event) {                  // public void layerChanged(final MapLayerEvent event) {
435                          getLocalRenderer().setContext(getMapContext()); // betters for SLD                  // // getLocalRenderer().setContext(getMapContext()); // betters for SLD
436                          // changes?!                  // // // changes?!
437                          requestStartRendering();                  // // requestStartRendering();
438                  }                  // }
439    
440                  @Override                  @Override
441                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
# Line 517  public class XMapPane extends JPanel { Line 518  public class XMapPane extends JPanel {
518          private BufferedImage preFinalImage;          private BufferedImage preFinalImage;
519    
520          // ** if 0, no quick preview will be shown **/          // ** if 0, no quick preview will be shown **/
521          private int quickPreviewHint = 0;          // private int quickPreviewHint = 0;
522    
523          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
524                          .getDefaultGTRendererHints(getLocalRenderer());                          .getDefaultGTRendererHints(getLocalRenderer());
# Line 540  public class XMapPane extends JPanel { Line 541  public class XMapPane extends JPanel {
541           * thread.           * thread.
542           */           */
543          final private Timer startRenderThreadsTimer;          final private Timer startRenderThreadsTimer;
544    //
545          /**  //      /**
546           * The default state is ZOOM_IN, hence by default the  //       * The default state is ZOOM_IN, hence by default the
547           * {@link #zoomMapPaneMouseListener} is also enabled.  //       * {@link #xMapPaneMouseListener} is also enabled.
548           **/  //       **/
549          private int state = ZOOM_IN;  //      private int state = ZOOM_IN;
550    
551          /**          /**
552           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
# Line 555  public class XMapPane extends JPanel { Line 556  public class XMapPane extends JPanel {
556    
557          private AffineTransform worldToScreen;          private AffineTransform worldToScreen;
558    
559            // /**
560            // * This {@link MouseListener} is managing all zoom related tasks
561            // */
562            // private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new
563            // ZoomXMapPaneMouseListener(
564            // this);
565    
566          /**          /**
567           * This {@link MouseListener} is managing all zoom related tasks           * This {@link MouseListener} is managing all zoom related tasks
568           */           */
569          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(
570                          this);                          this);
571    
572          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
# Line 600  public class XMapPane extends JPanel { Line 608  public class XMapPane extends JPanel {
608                  /**                  /**
609                   * Adding the #zoomMapPaneMouseListener                   * Adding the #zoomMapPaneMouseListener
610                   */                   */
611                  this.addMouseListener(zoomMapPaneMouseListener);                  this.addMouseListener(xMapPaneMouseListener);
612                  this.addMouseMotionListener(zoomMapPaneMouseListener);                  this.addMouseMotionListener(xMapPaneMouseListener);
613                  this.addMouseWheelListener(zoomMapPaneMouseListener);                  this.addMouseWheelListener(xMapPaneMouseListener);
614                    
615                    // By default the XMapPAne uses the ZOOM_IN tool.
616                    setTool(XMapPaneTool.ZOOM_IN);
617                    
618                  /*                  /*
619                   * We use a Timer object to avoid rendering delays and flickering when                   * We use a Timer object to avoid rendering delays and flickering when
620                   * the user is drag-resizing the parent container of this map pane.                   * the user is drag-resizing the parent container of this map pane.
# Line 618  public class XMapPane extends JPanel { Line 629  public class XMapPane extends JPanel {
629                                                  if (!isWellDefined())                                                  if (!isWellDefined())
630                                                          return;                                                          return;
631    
632                                                  LOGGER.debug("resizeTimer performed");                                                  // LOGGER.debug("resizeTimer performed");
633    
634                                                  final Rectangle bounds = getVisibleRect();                                                  // final Rectangle bounds = getVisibleRect();
635                                                  //                                                  //
636                                                  // System.out.println("\n\ntimer performs with bounds = "                                                  // System.out.println("\n\ntimer performs with bounds = "
637                                                  // + bounds);                                                  // + bounds);
638    
639                                                  final Envelope geoMapArea = tranformWindowToGeo(                                                  // final Envelope geoMapArea = tranformWindowToGeo(
640                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                  // bounds.x, bounds.y, bounds.x + bounds.width,
641                                                                  bounds.y + bounds.height);                                                  // bounds.y + bounds.height);
642    
643                                                  if (setMapArea(geoMapArea)) {                                                  paneResized = true;
644                                                          LOGGER.debug("  maparea changed");                                                  if (!setMapArea(getMapArea())) {
645                                                          paneResized = true;                                                          // It's important to request new rendering here.
646                                                  } else                                                          // setMapArea only returns true and only calls
647                                                          LOGGER.debug("  maparea NOT changed");                                                          // requestStartRendering if the maparea has changed.
648                                                            // But if the component is resized, the maparea
649                                                            // doesn't have to change.
650                                                            requestStartRendering();
651                                                    }
652    
653                                          }                                          }
654                                  });                                  });
655                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
# Line 648  public class XMapPane extends JPanel { Line 664  public class XMapPane extends JPanel {
664                                  // Seems to be called twice with the same size..                                  // Seems to be called twice with the same size..
665                                  if (oldVisibleRect != null                                  if (oldVisibleRect != null
666                                                  && oldVisibleRect.equals(getVisibleRect())) {                                                  && oldVisibleRect.equals(getVisibleRect())) {
667                                          LOGGER.debug("skipping resize.");                                          // LOGGER.debug("skipping resize.");
668                                          return;                                          return;
669                                  }                                  }
670    
671                                  LOGGER.debug("resized: " + getVisibleRect());                                  // LOGGER.debug("resized: " + getVisibleRect());
672                                  resizeTimer.restart();                                  resizeTimer.restart();
673                                  oldVisibleRect = getVisibleRect();                                  oldVisibleRect = getVisibleRect();
674                          }                          }
# Line 952  public class XMapPane extends JPanel { Line 968  public class XMapPane extends JPanel {
968                  // Remove all mapPaneListeners that have registered with us                  // Remove all mapPaneListeners that have registered with us
969                  mapPaneListeners.clear();                  mapPaneListeners.clear();
970    
971                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(xMapPaneMouseListener);
972                  removeMouseListener(zoomMapPaneMouseListener);                  removeMouseListener(xMapPaneMouseListener);
973    
974                  if (localContext != null)                  if (localContext != null)
975                          getMapContext().clearLayerList();                          getMapContext().clearLayerList();
# Line 969  public class XMapPane extends JPanel { Line 985  public class XMapPane extends JPanel {
985           */           */
986          protected void drawRectangle(final Graphics graphics, final Point startPos,          protected void drawRectangle(final Graphics graphics, final Point startPos,
987                          final Point e) {                          final Point e) {
988                    drawRectangle(graphics, startPos, e, Color.WHITE, false);
989            }
990    
991            /**
992             * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
993             * given point. All in screen coordinates.
994             */
995            protected void drawRectangle(final Graphics graphics, final Point startPos,
996                            final Point e, Color color, boolean fill) {
997    
998                  if (!isWellDefined())                  if (!isWellDefined())
999                          return;                          return;
# Line 984  public class XMapPane extends JPanel { Line 1009  public class XMapPane extends JPanel {
1009                  if (width == 0 && height == 0)                  if (width == 0 && height == 0)
1010                          return;                          return;
1011    
1012                  graphics.setXORMode(Color.WHITE);                  graphics.setXORMode(color);
1013                    
1014                    if (fill) {
1015                            graphics.fillRect(left, bottom, width, height);
1016                            graphics.setXORMode(Color.WHITE);      
1017                    }
1018                    
1019                    
1020                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
1021          }          }
1022    
# Line 996  public class XMapPane extends JPanel { Line 1028  public class XMapPane extends JPanel {
1028           *           *
1029           * @param g           * @param g
1030           *            Graphics2D to paint the preview into           *            Graphics2D to paint the preview into
          *  
          * @param state  
          *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}  
1031           */           */
1032          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
1033    
1034                  // if (1 == 1)return false;                  // if (1 == 1)return false;
1035                    // if (quickPreviewHint == 0)
1036                    // return false;
1037    
1038                  if (quickPreviewHint == 0)                  if (oldMapArea == null)
1039                          return false;                          return false;
1040    
1041                  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                  if (getPreFinalImage() == null)
                                 RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  
                 graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
                                 RenderingHints.VALUE_ANTIALIAS_OFF);  
                 graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  
                                 RenderingHints.VALUE_RENDER_SPEED);  
   
                 if (oldMapArea == null)  
1042                          return false;                          return false;
1043    
1044                  final Rectangle visibleArea = getVisibleRect();                  final Rectangle visibleArea = getVisibleRect();
# Line 1029  public class XMapPane extends JPanel { Line 1053  public class XMapPane extends JPanel {
1053                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1054                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1055    
1056                    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1057                                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1058                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1059                                    RenderingHints.VALUE_ANTIALIAS_OFF);
1060                    graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1061                                    RenderingHints.VALUE_RENDER_SPEED);
1062    
1063                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1064                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1065                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
# Line 1037  public class XMapPane extends JPanel { Line 1068  public class XMapPane extends JPanel {
1068                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1069                                  - yy1);                                  - yy1);
1070    
1071                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea,
1072                                    getMapBackgroundColor());
1073    
1074                  addGadgets(graphics, true);                  addGadgets(graphics, true);
1075    
1076                  quickPreviewHint = 0;                  // quickPreviewHint = 0;
1077    
1078                  repaintTimer.restart();                  repaintTimer.restart();
1079    
                 graphics.dispose();  
   
1080                  // Something has been drawn                  // Something has been drawn
1081                  return true;                  return true;
1082          }          }
# Line 1059  public class XMapPane extends JPanel { Line 1089  public class XMapPane extends JPanel {
1089           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1090           */           */
1091          private Image getBgImage() {          private Image getBgImage() {
1092                  //                  if (bgImage == null) {
1093                  // if (bgImage == null) {                          bgImage = new BufferedImage(getVisibleRect().width,
1094                  // bgImage = createImage(getBounds().width, getBounds().height);                                          getVisibleRect().height, IMAGETYPE);
1095                  // }                          SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1096                    }
1097    
1098                  return bgImage;                  return bgImage;
1099          }          }
# Line 1080  public class XMapPane extends JPanel { Line 1111  public class XMapPane extends JPanel {
1111                          // Rectangle curPaintArea = getVisibleRect();                          // Rectangle curPaintArea = getVisibleRect();
1112                          finalImage = new BufferedImage(getVisibleRect().width,                          finalImage = new BufferedImage(getVisibleRect().width,
1113                                          getVisibleRect().height, IMAGETYPE);                                          getVisibleRect().height, IMAGETYPE);
1114                            SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1115    
1116                          requestStartRendering();                          // requestStartRendering();
1117                  }                  }
1118                  return finalImage;                  return finalImage;
1119          }          }
1120    
         public RenderingHints getJava2dHints() {  
                 return java2dHints;  
         }  
   
1121          /**          /**
1122           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1123           */           */
# Line 1098  public class XMapPane extends JPanel { Line 1126  public class XMapPane extends JPanel {
1126                  if (localImage == null) {                  if (localImage == null) {
1127                          localImage = new BufferedImage(getVisibleRect().width,                          localImage = new BufferedImage(getVisibleRect().width,
1128                                          getVisibleRect().height, IMAGETYPE_withAlpha);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1129                            SwingUtil.clearImage(localImage, getMapBackgroundColor());
1130                  }                  }
1131    
1132                  return localImage;                  return localImage;
# Line 1113  public class XMapPane extends JPanel { Line 1142  public class XMapPane extends JPanel {
1142                          ReferencedEnvelope mapArea_ = null;                          ReferencedEnvelope mapArea_ = null;
1143                          try {                          try {
1144                                  mapArea_ = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1145                          } catch (final IOException e) {                          } catch (final Exception e) {
1146                                  LOGGER.warn("localContext.getLayerBounds()", e);                                  LOGGER.warn("localContext.getLayerBounds()", e);
1147                          }                          }
1148    
# Line 1139  public class XMapPane extends JPanel { Line 1168  public class XMapPane extends JPanel {
1168                          try {                          try {
1169                                  localContext.setCoordinateReferenceSystem(GeoImportUtil                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1170                                                  .getDefaultCRS());                                                  .getDefaultCRS());
1171                          } catch (Exception e) {                          } catch (final Exception e) {
1172                                  throw new RuntimeException("setting context CRS:", e);                                  throw new RuntimeException("setting context CRS:", e);
1173                          }                          }
1174    
# Line 1185  public class XMapPane extends JPanel { Line 1214  public class XMapPane extends JPanel {
1214    
1215          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1216                  if (maxExtend == null) {                  if (maxExtend == null) {
1217                          // Commented-out because it takes soo much time!  
1218                          //                          // The next command may take long time!
1219                          // long start = System.currentTimeMillis();                          // long start = System.currentTimeMillis();
1220                          // final ReferencedEnvelope layerBounds = GTUtil                          final ReferencedEnvelope layerBounds = GTUtil
1221                          // .getVisibleLayoutBounds(localContext);                                          .getVisibleLayoutBounds(localContext);
1222                          //                                                //                      
1223                          // LOGGER.info(                          // LOGGER.info(
1224                          // (System.currentTimeMillis()-start)+"m to get maxExtend");                          // (System.currentTimeMillis()-start)+"m to get maxExtend");
1225                          //                                                //                      
1226                          // if (layerBounds == null) {                          if (layerBounds == null) {
1227                          // // TODO Last fallback could be the CRS valid area                                  // // TODO Last fallback could be the CRS valid area
1228                          // return null;                                  return null;
1229                          // }                          }
1230                          //  
1231                          // // Kartenbereich um 10% vergroessern                          // Vergrößerung um 10% nochmal rausgenommen
1232                            // // // Kartenbereich um 10% vergroessern
1233                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1234                          // .expandEnvelope(layerBounds, 0.1), true);                          // .expandEnvelope(layerBounds, 0.1), true);
1235    
1236                            return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true);
1237                  }                  }
1238                  return maxExtend;                  return maxExtend;
1239          }          }
# Line 1229  public class XMapPane extends JPanel { Line 1261  public class XMapPane extends JPanel {
1261          }          }
1262    
1263          private Image getPreFinalImage() {          private Image getPreFinalImage() {
                 // if (preFinalImage == null) {  
                 //                        
                 // // Rectangle curPaintArea = getVisibleRect();  
                 // // preFinalImage = new BufferedImage(curPaintArea.width,  
                 // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);  
                 //                        
                 // preFinalImage = createImage(getBounds().width, getBounds().height);  
                 //  
                 // requestStartRendering();  
                 // }  
1264                  return preFinalImage;                  return preFinalImage;
1265          }          }
1266    
# Line 1266  public class XMapPane extends JPanel { Line 1288  public class XMapPane extends JPanel {
1288                  return new AffineTransform(screenToWorld);                  return new AffineTransform(screenToWorld);
1289          }          }
1290    
1291          public int getState() {  //      public int getState() {
1292                  return state;  //              return state;
1293          }  //      }
1294    
1295          /**          /**
1296           * Liefert den statisch eingestellten Cursor, der unabhaengig von der           * Liefert den statisch eingestellten Cursor, der unabhaengig von der
# Line 1333  public class XMapPane extends JPanel { Line 1355  public class XMapPane extends JPanel {
1355          }          }
1356    
1357          /**          /**
1358           * 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.  
1359           *           *
1360           * @param startPos           * @param startPos
1361           *            in screen coordinates           *            in screen coordinates
1362           * @param lastPos           * @param lastPos
1363           *            in screen coordinates           *            in screen coordinates
          * @param event  
          *            the {@link MouseEvent} to read the mouse buttons from  
1364           */           */
1365          public void mouseDragged(final Point startPos, final Point lastPos,          public void pan(final int dX, final int dY) {
                         final MouseEvent event) {  
1366    
1367                  if ((getState() == XMapPane.PAN)                  // Panning needs a panning coursor
1368                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {                  if (getCursor() != SwingUtil.PANNING_CURSOR) {
1369                            setCursor(SwingUtil.PANNING_CURSOR);
1370                          // Panning needs a panning coursor  
1371                          if (getCursor() != SwingUtil.PANNING_CURSOR) {                          // While panning, we deactivate the rendering. So the tasks are
1372                                  setCursor(SwingUtil.PANNING_CURSOR);                          // ready to start when the panning is finished.
1373                            if (bgExecuter != null && bgExecuter.isRunning())
1374                                  // While panning, we deactivate the rendering. So the tasks are                                  bgExecuter.cancelTask();
1375                                  // ready to start when the panning is finished.                          if (localExecuter.isRunning())
1376                                  if (bgExecuter != null && bgExecuter.isRunning())                                  localExecuter.cancelTask();
1377                                          bgExecuter.cancelTask();                  }
1378                                  if (localExecuter.isRunning())                  //
1379                                          localExecuter.cancelTask();                  // if (lastPos.x > 0 && lastPos.y > 0) {
1380                          }                  // final int dx = event.getX() - lastPos.x;
1381                    // final int dy = event.getY() - lastPos.y;
1382                          if (lastPos.x > 0 && lastPos.y > 0) {  
1383                                  final int dx = event.getX() - lastPos.x;                  // TODO Stop dragging when the drag would not be valid...
1384                                  final int dy = event.getY() - lastPos.y;                  // boolean dragValid = true;
1385                    // // check if this panning results in a valid mapArea
1386                                  // TODO Stop dragging when the drag would not be valid...                  // {
1387                                  // boolean dragValid = true;                  // Rectangle winBounds = xMapPane.getBounds();
1388                                  // // check if this panning results in a valid mapArea                  // winBounds.translate(xMapPane.imageOrigin.x,
1389                                  // {                  // -xMapPane.imageOrigin.y);
1390                                  // Rectangle winBounds = xMapPane.getBounds();                  // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(
1391                                  // winBounds.translate(xMapPane.imageOrigin.x,                  // winBounds.x, winBounds.y, winBounds.x
1392                                  // -xMapPane.imageOrigin.y);                  // + winBounds.width, winBounds.y
1393                                  // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(                  // + winBounds.height);
1394                                  // winBounds.x, winBounds.y, winBounds.x                  //                                      
1395                                  // + winBounds.width, winBounds.y                  //
1396                                  // + winBounds.height);                  // winBounds = xMapPane.getBounds();
1397                                  //                                                        // Point testIng = new Point(xMapPane.imageOrigin);
1398                                  //                  // testIng.translate(dx, dy);
1399                                  // winBounds = xMapPane.getBounds();                  // winBounds.translate(testIng.x, -testIng.y);
1400                                  // Point testIng = new Point(xMapPane.imageOrigin);                  // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(
1401                                  // testIng.translate(dx, dy);                  // winBounds.x, winBounds.y, winBounds.x
1402                                  // winBounds.translate(testIng.x, -testIng.y);                  // + winBounds.width, winBounds.y
1403                                  // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(                  // + winBounds.height);
1404                                  // winBounds.x, winBounds.y, winBounds.x                  //
1405                                  // + winBounds.width, winBounds.y                  // // If the last drag doesn't change the MapArea anymore cancel
1406                                  // + winBounds.height);                  // it.
1407                                  //                  // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(
1408                                  // // If the last drag doesn't change the MapArea anymore cancel                  // xMapPane.bestAllowedMapArea(newMapAreaBefore))){
1409                                  // it.                  // dragValid = false;
1410                                  // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(                  // return;
1411                                  // xMapPane.bestAllowedMapArea(newMapAreaBefore))){                  // }
1412                                  // dragValid = false;                  // }
                                 // return;  
                                 // }  
                                 // }  
1413    
1414                                  imageOrigin.translate(dx, dy);                  getImageOrigin().translate(dX, dY);
1415                                  updateFinalImage();                  updateFinalImage();
1416                                  repaint();                  repaint();
1417                          }                  // }
1418    
1419                  } else if ((getState() == XMapPane.ZOOM_IN)                  // } else if ((getState() == XMapPane.ZOOM_IN)
1420                                  || (getState() == XMapPane.ZOOM_OUT)                  // || (getState() == XMapPane.ZOOM_OUT)
1421                                  || (getState() == XMapPane.SELECT_ALL)                  // || (getState() == XMapPane.SELECT_ALL)
1422                                  || (getState() == XMapPane.SELECT_TOP)) {                  // || (getState() == XMapPane.SELECT_TOP)) {
1423                    //
1424                          // Draws a rectangle                  // // Draws a rectangle
1425                          final Graphics graphics = getGraphics();                  // final Graphics2D graphics = (Graphics2D) getGraphics();
1426                          drawRectangle(graphics, startPos, event.getPoint());                  // drawRectangle(graphics, startPos, event.getPoint());
1427                          if ((lastPos.x > 0) && (lastPos.y > 0))                  // if ((lastPos.x > 0) && (lastPos.y > 0))
1428                                  drawRectangle(graphics, startPos, lastPos);                  // drawRectangle(graphics, startPos, lastPos);
1429                          graphics.dispose();                  // graphics.dispose();
1430                  }                  // }
1431          }          }
1432    
1433          /**          /**
1434           * Called by the {@link RenderingExecutor} when rendering was cancelled.           * Called by the {@link RenderingExecutor} when rendering was cancelled.
1435           */           */
1436          public void onRenderingCancelled() {          public void onRenderingCancelled() {
1437                  LOGGER.debug("Rendering cancelled");                  // LOGGER.debug("Rendering cancelled");
1438                  repaintTimer.stop();                  repaintTimer.stop();
1439          }          }
1440    
1441          /**          /**
1442           * Called by the {@link RenderingExecutor} when rendering has been           * Called by the {@link RenderingExecutor} when rendering has been
1443           * completed.           * completed.
1444             *
1445             * @param l
1446             *            long ms the rendering took
1447           */           */
1448          public void onRenderingCompleted() {          public void onRenderingCompleted(final long l) {
1449                  LOGGER.debug("complete");                  lastRenderingDuration = (lastRenderingDuration + l) / 2;
1450                    // LOGGER
1451                    // .debug("complete rendering after " + lastRenderingDuration
1452                    // + "ms");
1453    
1454                  repaintTimer.stop();                  repaintTimer.stop();
1455    
# Line 1480  public class XMapPane extends JPanel { Line 1501  public class XMapPane extends JPanel {
1501    
1502                  if (!isWellDefined())                  if (!isWellDefined())
1503                          return;                          return;
1504                    //
1505                    // if (paneResized) {
1506                    // // ((Graphics2D) g).setBackground(getMapBackgroundColor());
1507                    // // g.clearRect(0, 0, getVisibleRect().width,
1508                    // getVisibleRect().height);
1509                    // return;
1510                    // }
1511    
1512  //               super.paintComponent(g); // candidate for removal                  // super.paintComponent(g); // candidate for removal
1513    
1514                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1515    
# Line 1492  public class XMapPane extends JPanel { Line 1520  public class XMapPane extends JPanel {
1520                          // If the new mapArea and the oldMapArea intersect, we can draw some                          // If the new mapArea and the oldMapArea intersect, we can draw some
1521                          // quick scaled preview to make the user feel that something is                          // quick scaled preview to make the user feel that something is
1522                          // happening.                          // happening.
1523                          if (mapAreaChanged && oldMapArea != null                          if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged
1524                                            && oldMapArea != null
1525                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1526                                          & !getMapArea().equals(oldMapArea) && !paneResized) {                                          && !getMapArea().equals(oldMapArea) && !paneResized) {
1527    
1528                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1529    
1530                                  if (getMapArea().covers(oldMapArea)) {                                  // if (getMapArea().covers(oldMapArea)) {
1531                                          quickPreviewHint = ZOOM_OUT;                                  // // quickPreviewHint = ZOOM_OUT;
1532                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D)
1533                                  } else if (oldMapArea.covers(getMapArea())) {                                  // g);
1534                                          quickPreviewHint = ZOOM_IN;                                  // } else if (oldMapArea.covers(getMapArea())) {
1535                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // quickPreviewHint = ZOOM_IN;
1536                                  }                                  paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1537                                    // }
1538                          }                          }
1539                  }                  }
1540    
# Line 1512  public class XMapPane extends JPanel { Line 1542  public class XMapPane extends JPanel {
1542    
1543                          g.drawImage(getFinalImage(), 0, 0, null);                          g.drawImage(getFinalImage(), 0, 0, null);
1544    
                         g.dispose(); // cand. for removal  
   
1545                          paintedSomething = true; // cand. for removal                          paintedSomething = true; // cand. for removal
1546                  }                  }
1547    
# Line 1561  public class XMapPane extends JPanel { Line 1589  public class XMapPane extends JPanel {
1589                  }                  }
1590    
1591          }          }
1592    //
1593          /**  //      /**
1594           * Performs a {@value #PAN} action. During panning, the displacement is  //       * Performs a {@value #PAN} action. During panning, the displacement is
1595           * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will  //       * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
1596           * reset the offset and call {@link #setMapArea(Envelope)}.  //       * reset the offset and call {@link #setMapArea(Envelope)}.
1597           */  //       */
1598          public void performPan() {  //      public void performPan() {
1599    //
1600                  Rectangle winBounds = getVisibleRect();  //              final Rectangle winBounds = getVisibleRect();
1601    //
1602                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);  //              winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1603                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,  //              final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1604                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y  //                              winBounds.y, winBounds.x + winBounds.width, winBounds.y
1605                                                  + winBounds.height);  //                                              + winBounds.height);
1606    //
1607                  imageOrigin.x = 0;  //              imageOrigin.x = 0;
1608                  imageOrigin.y = 0;  //              imageOrigin.y = 0;
1609    //
1610                  if (!setMapArea(newMapArea)) {  //              if (!setMapArea(newMapArea)) {
1611                          /**  //                      /**
1612                           * If setMapArea returns true, the finalImage is updated anyways.  //                       * If setMapArea returns true, the finalImage is updated anyways.
1613                           * This if-case exists to ensure that we repaint a correct image  //                       * This if-case exists to ensure that we repaint a correct image
1614                           * even if the new panning area has been denied.  //                       * even if the new panning area has been denied.
1615                           */  //                       */
1616                          updateFinalImage();  //                      updateFinalImage();
1617                          repaint();  //                      repaint();
1618                  }  //              }
1619    //
1620                  if (getCursor() == SwingUtil.PANNING_CURSOR)  //              if (getCursor() == SwingUtil.PANNING_CURSOR)
1621                          setCursor(SwingUtil.PAN_CURSOR);  //                      setCursor(SwingUtil.PAN_CURSOR);
1622          }  //      }
1623    
1624          /**          /**
1625           * Entfernt einen Listener von der Map.           * Entfernt einen Listener von der Map.
# Line 1637  public class XMapPane extends JPanel { Line 1665  public class XMapPane extends JPanel {
1665           *            the current map pane extent (screen units)           *            the current map pane extent (screen units)
1666           */           */
1667          private void resetTransforms() {          private void resetTransforms() {
                 ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,  
                                 getMapContext().getCoordinateReferenceSystem());  
   
1668                  // System.out                  // System.out
1669                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1670                  if (!isWellDefined())                  if (!isWellDefined())
1671                          return;                          return;
1672    
1673                    if (mapArea == null)
1674                            return;
1675    
1676                    final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1677                                    getMapContext().getCoordinateReferenceSystem());
1678    
1679                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1680                                  getVisibleRect());                                  getVisibleRect());
1681    
1682                  try {                  try {
1683                          screenToWorld = worldToScreen.createInverse();                          screenToWorld = worldToScreen.createInverse();
1684    
1685                  } catch (NoninvertibleTransformException ex) {                  } catch (final NoninvertibleTransformException ex) {
1686                          LOGGER                          LOGGER
1687                                          .error("can't invert worldToScreen to get screenToWorld!",                                          .error("can't invert worldToScreen to get screenToWorld!",
1688                                                          ex);                                                          ex);
# Line 1721  public class XMapPane extends JPanel { Line 1752  public class XMapPane extends JPanel {
1752    
1753          }          }
1754    
1755            public void setBorder(final Border b) {
1756                    super.setBorder(b);
1757            }
1758    
1759          /**          /**
1760           * Triggers to repaint (fast) and re-render (slow) the JMapPane.           * Triggers to repaint (fast) and re-render (slow) the JMapPane.
1761           */           */
# Line 1741  public class XMapPane extends JPanel { Line 1776  public class XMapPane extends JPanel {
1776          // repaint();          // repaint();
1777          // }          // }
1778    
1779            /**
1780             * Set the new map area.
1781             *
1782             * @param newMapArea
1783             * @return <code>true</code> if the mapArea has been changed and a repaint
1784             *         has been triggered.
1785             */
1786          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1787                  if (newMapArea == null)                  if (newMapArea == null)
1788                          return false;                          return false;
# Line 1751  public class XMapPane extends JPanel { Line 1793  public class XMapPane extends JPanel {
1793          }          }
1794    
1795          /**          /**
1796             * Set the new map area.
1797             *
1798           * @param newMapArea           * @param newMapArea
1799           * @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
1800           *         has been triggered.           *         has been triggered.
# Line 1825  public class XMapPane extends JPanel { Line 1869  public class XMapPane extends JPanel {
1869           *           *
1870           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1871           */           */
1872          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(final Color bgColor) {
1873                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1874          }          }
1875    
# Line 1883  public class XMapPane extends JPanel { Line 1927  public class XMapPane extends JPanel {
1927          }          }
1928    
1929          // /** Stored the time used for the last real rendering in ms. **/          // /** Stored the time used for the last real rendering in ms. **/
1930          // private long lastRenderingDuration = Long.MAX_VALUE;          private long lastRenderingDuration = 1000;
1931            private XMapPaneTool tool = null;
1932    
1933          /**          /**
1934           * Set the minimum (nearest) allowed zoom scale. This is the bigger number           * Set the minimum (nearest) allowed zoom scale. This is the bigger number
# Line 1915  public class XMapPane extends JPanel { Line 1960  public class XMapPane extends JPanel {
1960                          this.rendererHints = rendererHints;                          this.rendererHints = rendererHints;
1961          }          }
1962    
1963          /**  //      @Deprecated
1964           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the  //      public void setState(final int state) {
1965           * repaint Timer if  //              this.state = state;
1966           *  //
1967           * @param state  //              // throw new RuntimeException("Old concept.. migrate to new concept!");
1968           */  //
1969          public void setState(final int state) {  //              // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
1970                  this.state = state;  //              // || state == ZOOM_OUT || state == PAN));
1971    //
1972                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN  //              // Je nach Aktion den Cursor umsetzen
1973                                  || state == ZOOM_OUT || state == PAN));  //              updateCursor();
1974    //      }
1975                  // Je nach Aktion den Cursor umsetzen  
1976                  updateCursor();          public void configureMouse(MouseInputType type, XMapPaneAction action) {
1977                    xMapPaneMouseListener.actions.put(type, action);
1978            }
1979            
1980            /**
1981             * Configure the {@link XMapPaneTool} that active on the map. Passing
1982             * <code>null</code> will set the NO_ACTION tool.
1983             */
1984            public void setTool(XMapPaneTool tool) {
1985                    if (tool == null)
1986                            tool = XMapPaneTool.NO_ACTION;
1987                    this.tool = tool;
1988                    xMapPaneMouseListener.configure(tool);
1989                    setCursor(tool.cursor);
1990          }          }
1991    
1992          /**          /**
# Line 2008  public class XMapPane extends JPanel { Line 2066  public class XMapPane extends JPanel {
2066                  updateCursor();                  updateCursor();
2067          }          }
2068    
2069            private RenderingHints getJava2dHints() {
2070                    return java2dHints;
2071            }
2072    
2073          /**          /**
2074           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.
2075           *           *
# Line 2083  public class XMapPane extends JPanel { Line 2145  public class XMapPane extends JPanel {
2145                                  repaint();                                  repaint();
2146                          }                          }
2147                  }                  }
2148                    
2149    //
2150                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
2151                  // von der aktuellen Aktion                  // von der aktuellen Aktion
2152                  if (this.staticCursor != null) {                  if (this.staticCursor != null) {
2153                          setCursor(staticCursor);                          setCursor(staticCursor);
2154                          return;                          return;
2155                  }                  }
2156                    
2157                  if (getCursor() == SwingUtil.PANNING_CURSOR) {                  if (getCursor() == SwingUtil.PANNING_CURSOR) {
2158                          // This cursor will reset itself                          // This cursor will reset itself
2159                          return;                          return;
2160                  }                  }
2161                    
2162                  // Set the cursor depending on what tool is in use...                  setCursor(tool.cursor);
2163                  switch (state) {                  
2164                  case SELECT_TOP:  //
2165                  case SELECT_ONE_FROM_TOP:  //              // Set the cursor depending on what tool is in use...
2166                  case SELECT_ALL:  //              switch (state) {
2167                          setCursor(SwingUtil.CROSSHAIR_CURSOR);  //              case SELECT_TOP:
2168                          break;  //              case SELECT_ONE_FROM_TOP:
2169                  case ZOOM_IN:  //              case SELECT_ALL:
2170                          setCursor(SwingUtil.ZOOMIN_CURSOR);  //                      setCursor(SwingUtil.CROSSHAIR_CURSOR);
2171                          break;  //                      break;
2172                  case ZOOM_OUT:  //              case ZOOM_IN:
2173                          setCursor(SwingUtil.ZOOMOUT_CURSOR);  //                      setCursor(SwingUtil.ZOOMIN_CURSOR);
2174                          break;  //                      break;
2175                  case PAN:  //              case ZOOM_OUT:
2176                          setCursor(SwingUtil.PAN_CURSOR);  //                      setCursor(SwingUtil.ZOOMOUT_CURSOR);
2177                          break;  //                      break;
2178                  default:  //              case PAN:
2179                          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  //                      setCursor(SwingUtil.PAN_CURSOR);
2180                          break;  //                      break;
2181                  }  //              default:
2182    //                      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2183    //                      break;
2184    //              }
2185          }          }
2186    
2187          /**          /**
# Line 2144  public class XMapPane extends JPanel { Line 2211  public class XMapPane extends JPanel {
2211    
2212                  final Graphics2D finalG = getFinalImage().createGraphics();                  final Graphics2D finalG = getFinalImage().createGraphics();
2213                  finalG.setBackground(getMapBackgroundColor());                  finalG.setBackground(getMapBackgroundColor());
2214                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), getImageOrigin().x, getImageOrigin().y,
2215                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
2216    
2217                  final int finalImageHeight = getFinalImage().getHeight(null);                  // When panning, we have to clear the area around the image
2218                  final int finalImageWidth = getFinalImage().getWidth(null);                  final Rectangle painedArea = new Rectangle(getImageOrigin().x,
2219                                    getImageOrigin().y, getFinalImage().getWidth(), getFinalImage()
2220                  final Rectangle painedArea = new Rectangle(imageOrigin.x,                                                  .getHeight());
2221                                  imageOrigin.y, finalImageWidth, finalImageHeight);                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
2222                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());                                  getMapBackgroundColor());
2223    
2224                  addGadgets(finalG, false);  //              addGadgets(finalG, false);
2225    
2226                  finalG.dispose();                  finalG.dispose();
2227    
# Line 2171  public class XMapPane extends JPanel { Line 2238  public class XMapPane extends JPanel {
2238           *            <code>false</code>, it will only depend on           *            <code>false</code>, it will only depend on
2239           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2240           */           */
2241          private void addGadgets(final Graphics2D graphics, boolean forceWait) {          private void addGadgets(final Graphics2D graphics, final boolean forceWait) {
2242    
2243                  // Paint a logo to the bottom right if available                  // Paint a logo to the bottom right if available
2244                  if (mapImage != null) {                  if (mapImage != null) {
2245                          Rectangle visibleRect = getVisibleRect();                          final Rectangle visibleRect = getVisibleRect();
2246                          graphics.drawImage(mapImage, visibleRect.width                          graphics.drawImage(mapImage, visibleRect.width
2247                                          - mapImage.getWidth() - 10, getVisibleRect().height                                          - mapImage.getWidth() - 10, getVisibleRect().height
2248                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
# Line 2201  public class XMapPane extends JPanel { Line 2268  public class XMapPane extends JPanel {
2268    
2269                          graphics.setColor(c);                          graphics.setColor(c);
2270    
2271                          y += 24;                          y += 21;
2272                  }                  }
2273    
2274                  if (!renderingErrors.isEmpty() && isShowExceptions()) {                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
# Line 2209  public class XMapPane extends JPanel { Line 2276  public class XMapPane extends JPanel {
2276                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2277                          graphics.setFont(errorFont);                          graphics.setFont(errorFont);
2278    
2279                          for (Exception ex : renderingErrors) {                          for (final Exception ex : renderingErrors) {
2280    
2281                                  String errStr = ex.getLocalizedMessage();                                  String errStr = ex.getLocalizedMessage();
2282    
# Line 2246  public class XMapPane extends JPanel { Line 2313  public class XMapPane extends JPanel {
2313                  final CoordinateReferenceSystem mapCRS = getMapContext()                  final CoordinateReferenceSystem mapCRS = getMapContext()
2314                                  .getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2315                  final CoordinateReferenceSystem fCRS = features.getSchema()                  final CoordinateReferenceSystem fCRS = features.getSchema()
2316                                  .getGeometryDescriptor().getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2317    
2318                  ReferencedEnvelope _mapArea;                  ReferencedEnvelope _mapArea;
2319                  if (mapArea == null)                  if (mapArea == null)
# Line 2339  public class XMapPane extends JPanel { Line 2406  public class XMapPane extends JPanel {
2406           * @param center           * @param center
2407           *            position in window coordinates           *            position in window coordinates
2408           * @param zoomFaktor           * @param zoomFaktor
2409           *            > 1 for zoom in, < 1 for zoom out. Default is 1.33.           *            > 1 for zoom out, < 1 for zoom in. Default is .5
2410           */           */
2411          public void zoomTo(Point center, Double zoomFaktor) {          public void zoomTo(Point center, Double zoomFaktor) {
2412                  if (zoomFaktor == null || zoomFaktor == 0.)                  if (zoomFaktor == null || zoomFaktor == 0.)
2413                          zoomFaktor = 2.;                          zoomFaktor = .5;
2414    
2415                  final Point2D gcenter = getScreenToWorld().transform(center, null);                  final Point2D gcenter = getScreenToWorld().transform(center, null);
2416                  center = null;                  center = null;
# Line 2364  public class XMapPane extends JPanel { Line 2431  public class XMapPane extends JPanel {
2431                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2432                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2433    
2434                  // TODO we actually want that                  // // Move the newMapArea above the new center if we zoom in:
2435                  // // Move the newMapArea above the new center                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2436                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                                  .getY()
2437                  // .getY()                                  - mapArea.centre().y);
                 // - mapArea.centre().y);  
2438    
2439                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2440          }          }
# Line 2377  public class XMapPane extends JPanel { Line 2443  public class XMapPane extends JPanel {
2443           * Shall non-fatal rendering exceptions be reported in the mappane or be           * Shall non-fatal rendering exceptions be reported in the mappane or be
2444           * dropped quitely.           * dropped quitely.
2445           */           */
2446          public void setShowExceptions(boolean showExceptions) {          public void setShowExceptions(final boolean showExceptions) {
2447                  this.showExceptions = showExceptions;                  this.showExceptions = showExceptions;
2448          }          }
2449    
# Line 2392  public class XMapPane extends JPanel { Line 2458  public class XMapPane extends JPanel {
2458                  return localRenderer;                  return localRenderer;
2459          }          }
2460    
2461            /**
2462             * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
2463             * Macht nichts, wenn {@code null} uebergeben wird.
2464             *
2465             * <br>
2466             *
2467             * @param layer
2468             *            ein Layer
2469             */
2470            public void zoomToLayer(MapLayer layer) {
2471                    if (layer == null)
2472                            return;
2473                    try {
2474    
2475                            // BB umrechnen von Layer-CRS in Map-CRS
2476                            final CoordinateReferenceSystem targetCRS = getMapContext()
2477                                            .getCoordinateReferenceSystem();
2478                            final CoordinateReferenceSystem sourceCRS = layer
2479                                            .getFeatureSource().getSchema()
2480                                            .getCoordinateReferenceSystem();
2481    
2482                            Envelope mapAreaNew;
2483                            if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
2484                                    mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource()
2485                                                    .getBounds(), sourceCRS, targetCRS);
2486                            } else {
2487                                    try {
2488                                            mapAreaNew = layer.getFeatureSource().getBounds();
2489                                    } catch (java.lang.IllegalArgumentException e) {
2490                                            LOGGER.error("Can't calc layers bounds...", e);
2491                                            mapAreaNew = null;
2492    
2493                                            /**
2494                                             *
2495                                             23.10.2009 11:20:50
2496                                             * org.geotools.data.shapefile.shp.PolygonHandler read
2497                                             * WARNUNG: only one hole in this polygon record ERROR
2498                                             * JMapPane zoomToLayer Zoom to layer did not terminate
2499                                             * correctly java.lang.IllegalArgumentException: Points of
2500                                             * LinearRing do not form a closed linestring at
2501                                             * com.vividsolutions
2502                                             * .jts.geom.LinearRing.validateConstruction
2503                                             * (LinearRing.java:105) at
2504                                             * com.vividsolutions.jts.geom.LinearRing
2505                                             * .<init>(LinearRing.java:100) at
2506                                             * com.vividsolutions.jts.geom
2507                                             * .GeometryFactory.createLinearRing
2508                                             * (GeometryFactory.java:339) at
2509                                             * org.geotools.data.shapefile.
2510                                             * shp.PolygonHandler.read(PolygonHandler.java:188) at
2511                                             * org.geotools
2512                                             * .data.shapefile.shp.ShapefileReader$Record.shape
2513                                             * (ShapefileReader.java:106) at
2514                                             * org.geotools.data.shapefile.
2515                                             * ShapefileAttributeReader.next(
2516                                             * ShapefileAttributeReader.java:157) at
2517                                             * org.geotools.data.shapefile
2518                                             * .indexed.IndexedShapefileAttributeReader
2519                                             * .next(IndexedShapefileAttributeReader.java:122) at
2520                                             * org.geotools
2521                                             * .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at
2522                                             * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.
2523                                             * java:55) at org.geotools.data.MaxFeatureReader.next(
2524                                             * MaxFeatureReader.java:61) at
2525                                             * org.geotools.data.MaxFeatureReader
2526                                             * .next(MaxFeatureReader.java:61)
2527                                             **/
2528                                    }
2529                            }
2530    
2531                            // Kartenbereich um 10% vergroessern, damit z.B. auch ein
2532                            // Punkt-Layer,
2533                            // welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen
2534                            // sonst
2535                            // genau auf dem Rand der angezeigten Flaeche)
2536    
2537                            if (mapAreaNew != null) {
2538                                    mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew
2539                                                    .getHeight() * 0.1);
2540                                    setMapArea(mapAreaNew);
2541                            } else {
2542                                    LOGGER
2543                                                    .warn("Couldn't transformEnvelope when zooming to the layer");
2544                            }
2545                    } catch (Exception err) {
2546                            LOGGER.error("Zoom to layer did not terminate correctly", err);
2547                    }
2548            }
2549    
2550            /**
2551             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer.
2552             *
2553             * <br>
2554             * A refresh of the map is not done automatically
2555             *
2556             * @param index
2557             *            Index of the {@link MapLayer} in the {@link MapContext} (from
2558             *            back to top)
2559             *
2560             * @author <a href="mailto:[email protected]">Stefan Alfons
2561             *         Kr&uuml;ger</a>
2562             */
2563            public void zoomToLayer(int index) {
2564                    final MapContext context = getMapContext();
2565                    if (context != null)
2566                            zoomToLayer(context.getLayer(index));
2567            }
2568    
2569            /**
2570             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the
2571             * selected layer. The layer is selected by the idx, counting from front to
2572             * back, like humans would expect in a {@link JList}
2573             *
2574             * <br>
2575             * A refresh of the map is not done automatically
2576             *
2577             *
2578             *
2579             * @param index
2580             *            Reverse index of the {@link MapLayer} in the
2581             *            {@link MapContext}
2582             *
2583             * @author <a href="mailto:[email protected]">Stefan Alfons
2584             *         Kr&uuml;ger</a>
2585             */
2586            public void zoomToLayerIdxReverse(int index) {
2587                    zoomToLayer(getMapContext().getLayerCount() - 1 - index);
2588            }
2589    
2590            /**
2591             * Aktiviert oder deaktiviert das AntiAliasing for diese
2592             * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
2593             * Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance.
2594             *
2595             * @author <a href="mailto:[email protected]">Stefan Alfons
2596             *         Kr&uuml;ger</a>
2597             */
2598            public void setAntiAliasing(final boolean aa) {
2599                    // LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa);
2600                    RenderingHints java2DHints = java2dHints;
2601                    if (java2DHints == null) {
2602                            java2DHints = GeoTools.getDefaultHints();
2603                    }
2604    
2605                    java2DHints.put(RenderingHints.KEY_ANTIALIASING,
2606                                    aa ? RenderingHints.VALUE_ANTIALIAS_ON
2607                                                    : RenderingHints.VALUE_ANTIALIAS_OFF);
2608                    java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
2609                                    aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
2610                                                    : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
2611                    java2DHints.put(RenderingHints.KEY_RENDERING,
2612                                    aa ? RenderingHints.VALUE_RENDER_QUALITY
2613                                                    : RenderingHints.VALUE_RENDER_SPEED);
2614    
2615            }
2616    
2617            public Point getImageOrigin() {
2618                    return imageOrigin;
2619            }
2620    
2621  }  }

Legend:
Removed from v.560  
changed lines
  Added in v.655

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26