/[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/2.0-RC1/src/skrueger/geotools/XMapPane.java revision 607 by alfonx, Wed Dec 9 15:13:42 2009 UTC branches/2.0-RC2/src/skrueger/geotools/XMapPane.java revision 649 by alfonx, Thu Jan 28 17:24:15 2010 UTC
# Line 33  import javax.swing.border.Border; Line 33  import javax.swing.border.Border;
33  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
34  import org.geotools.factory.GeoTools;  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 68  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 106  public class XMapPane extends JPanel { Line 108  public class XMapPane extends JPanel {
108    
109          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
110    
111            /**
112             * A flag indicating whether the {@link XMapPane} is accepting repaints from
113             * the EDT. @see {@link XMapPane#setPainting(boolean))
114             **/
115          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
116    
117          /**          /**
# Line 251  public class XMapPane extends JPanel { Line 257  public class XMapPane extends JPanel {
257           * @param e           * @param e
258           *            Maus-Ereignis           *            Maus-Ereignis
259           */           */
260          public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {          public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) {
261                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln                  // aktuelle Geo-Position aus GeoMouseEvent ermitteln
262                  if (e != null && e instanceof MapMouseEvent)                  if (e != null && e instanceof MapMouseEvent)
263                          try {                          try {
264                                  return ((MapMouseEvent) e).getMapPosition().toPoint2D();                                  return ((MapMouseEvent) e).getMapPosition();
265                          } catch (final Exception err) {                          } catch (final Exception err) {
266                                  LOGGER                                  LOGGER
267                                                  .error(                                                  .error(
# Line 272  public class XMapPane extends JPanel { Line 278  public class XMapPane extends JPanel {
278                                  return null;                                  return null;
279    
280                          final AffineTransform at = xMapPane.getScreenToWorld();                          final AffineTransform at = xMapPane.getScreenToWorld();
281                          if (at != null)                          if (at != null) {
282                                  return at.transform(e.getPoint(), null);                                  Point2D transformed = at.transform(e.getPoint(), null);
283                                    return new DirectPosition2D(xMapPane.getMapContext()
284                                                    .getCoordinateReferenceSystem(), transformed.getX(),
285                                                    transformed.getY());
286                            }
287                          return null;                          return null;
288                  }                  }
289                  throw new IllegalArgumentException(                  throw new IllegalArgumentException(
# Line 414  public class XMapPane extends JPanel { Line 424  public class XMapPane extends JPanel {
424    
425                  @Override                  @Override
426                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
427  //                      getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow...                          // getLocalRenderer().setContext(getMapContext()); geht doch auch
428                            // ohne?!?!? wow...
429                          requestStartRendering();                          requestStartRendering();
430                  }                  }
431    
# Line 554  public class XMapPane extends JPanel { Line 565  public class XMapPane extends JPanel {
565    
566          /**          /**
567           * The default state is ZOOM_IN, hence by default the           * The default state is ZOOM_IN, hence by default the
568           * {@link #zoomMapPaneMouseListener} is also enabled.           * {@link #xMapPaneMouseListener} is also enabled.
569           **/           **/
570          private int state = ZOOM_IN;          private int state = ZOOM_IN;
571    
# Line 566  public class XMapPane extends JPanel { Line 577  public class XMapPane extends JPanel {
577    
578          private AffineTransform worldToScreen;          private AffineTransform worldToScreen;
579    
580            // /**
581            // * This {@link MouseListener} is managing all zoom related tasks
582            // */
583            // private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new
584            // ZoomXMapPaneMouseListener(
585            // this);
586    
587          /**          /**
588           * This {@link MouseListener} is managing all zoom related tasks           * This {@link MouseListener} is managing all zoom related tasks
589           */           */
590          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(
591                          this);                          this);
592    
593          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
# Line 611  public class XMapPane extends JPanel { Line 629  public class XMapPane extends JPanel {
629                  /**                  /**
630                   * Adding the #zoomMapPaneMouseListener                   * Adding the #zoomMapPaneMouseListener
631                   */                   */
632                  this.addMouseListener(zoomMapPaneMouseListener);                  this.addMouseListener(xMapPaneMouseListener);
633                  this.addMouseMotionListener(zoomMapPaneMouseListener);                  this.addMouseMotionListener(xMapPaneMouseListener);
634                  this.addMouseWheelListener(zoomMapPaneMouseListener);                  this.addMouseWheelListener(xMapPaneMouseListener);
635                    xMapPaneMouseListener.actions.put(MouseInputType.LClick,
636                                    XMapPaneAction.ZOOM_IN);
637                    xMapPaneMouseListener.actions.put(MouseInputType.LDrag,
638                                    XMapPaneAction.ZOOM_IN);
639                    xMapPaneMouseListener.actions.put(MouseInputType.Wheel,
640                                    XMapPaneAction.ZOOM_IN);
641    
642                    xMapPaneMouseListener.actions.put(MouseInputType.RClick,
643                                    XMapPaneAction.ZOOM_OUT);
644    
645                    xMapPaneMouseListener.actions.put(MouseInputType.RDrag,
646                                    XMapPaneAction.ZOOM_OUT);
647    
648                  /*                  /*
649                   * 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 968  public class XMapPane extends JPanel { Line 998  public class XMapPane extends JPanel {
998                  // Remove all mapPaneListeners that have registered with us                  // Remove all mapPaneListeners that have registered with us
999                  mapPaneListeners.clear();                  mapPaneListeners.clear();
1000    
1001                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(xMapPaneMouseListener);
1002                  removeMouseListener(zoomMapPaneMouseListener);                  removeMouseListener(xMapPaneMouseListener);
1003    
1004                  if (localContext != null)                  if (localContext != null)
1005                          getMapContext().clearLayerList();                          getMapContext().clearLayerList();
# Line 985  public class XMapPane extends JPanel { Line 1015  public class XMapPane extends JPanel {
1015           */           */
1016          protected void drawRectangle(final Graphics graphics, final Point startPos,          protected void drawRectangle(final Graphics graphics, final Point startPos,
1017                          final Point e) {                          final Point e) {
1018                    drawRectangle(graphics, startPos, e, Color.WHITE);
1019            }
1020    
1021            /**
1022             * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
1023             * given point. All in screen coordinates.
1024             */
1025            protected void drawRectangle(final Graphics graphics, final Point startPos,
1026                            final Point e, Color color) {
1027    
1028                  if (!isWellDefined())                  if (!isWellDefined())
1029                          return;                          return;
# Line 1000  public class XMapPane extends JPanel { Line 1039  public class XMapPane extends JPanel {
1039                  if (width == 0 && height == 0)                  if (width == 0 && height == 0)
1040                          return;                          return;
1041    
1042                  graphics.setXORMode(Color.WHITE);                  graphics.setXORMode(color);
1043                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
1044          }          }
1045    
# Line 1126  public class XMapPane extends JPanel { Line 1165  public class XMapPane extends JPanel {
1165                          ReferencedEnvelope mapArea_ = null;                          ReferencedEnvelope mapArea_ = null;
1166                          try {                          try {
1167                                  mapArea_ = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1168                          } catch (final IOException e) {                          } catch (final Exception e) {
1169                                  LOGGER.warn("localContext.getLayerBounds()", e);                                  LOGGER.warn("localContext.getLayerBounds()", e);
1170                          }                          }
1171    
# Line 1438  public class XMapPane extends JPanel { Line 1477  public class XMapPane extends JPanel {
1477           */           */
1478          public void onRenderingCompleted(final long l) {          public void onRenderingCompleted(final long l) {
1479                  lastRenderingDuration = (lastRenderingDuration + l) / 2;                  lastRenderingDuration = (lastRenderingDuration + l) / 2;
1480                  LOGGER                  // LOGGER
1481                                  .debug("complete rendering after " + lastRenderingDuration                  // .debug("complete rendering after " + lastRenderingDuration
1482                                                  + "ms");                  // + "ms");
1483    
1484                  repaintTimer.stop();                  repaintTimer.stop();
1485    
# Line 1656  public class XMapPane extends JPanel { Line 1695  public class XMapPane extends JPanel {
1695           *            the current map pane extent (screen units)           *            the current map pane extent (screen units)
1696           */           */
1697          private void resetTransforms() {          private void resetTransforms() {
                 final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,  
                                 getMapContext().getCoordinateReferenceSystem());  
   
1698                  // System.out                  // System.out
1699                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());                  // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1700                  if (!isWellDefined())                  if (!isWellDefined())
1701                          return;                          return;
1702    
1703                    if (mapArea == null)
1704                            return;
1705    
1706                    final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1707                                    getMapContext().getCoordinateReferenceSystem());
1708    
1709                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1710                                  getVisibleRect());                                  getVisibleRect());
1711    
# Line 1953  public class XMapPane extends JPanel { Line 1995  public class XMapPane extends JPanel {
1995           *           *
1996           * @param state           * @param state
1997           */           */
1998            @Deprecated
1999          public void setState(final int state) {          public void setState(final int state) {
2000                  this.state = state;                  this.state = state;
2001    
2002                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN                  // throw new RuntimeException("Old concept.. migrate to new concept!");
2003                                  || state == ZOOM_OUT || state == PAN));  
2004                    // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
2005                    // || state == ZOOM_OUT || state == PAN));
2006    
2007                  // Je nach Aktion den Cursor umsetzen                  // Je nach Aktion den Cursor umsetzen
2008                  updateCursor();                  updateCursor();
2009          }          }
2010    
2011            public void configureMouse(MouseInputType type, XMapPaneAction action) {
2012                    xMapPaneMouseListener.actions.put(type, action);
2013            }
2014    
2015          /**          /**
2016           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,
2017           * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor           * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
# Line 2375  public class XMapPane extends JPanel { Line 2424  public class XMapPane extends JPanel {
2424           * @param center           * @param center
2425           *            position in window coordinates           *            position in window coordinates
2426           * @param zoomFaktor           * @param zoomFaktor
2427           *            > 1 for zoom in, < 1 for zoom out. Default is 1.33.           *            > 1 for zoom out, < 1 for zoom in. Default is .5
2428           */           */
2429          public void zoomTo(Point center, Double zoomFaktor) {          public void zoomTo(Point center, Double zoomFaktor) {
2430                  if (zoomFaktor == null || zoomFaktor == 0.)                  if (zoomFaktor == null || zoomFaktor == 0.)
2431                          zoomFaktor = 2.;                          zoomFaktor = .5;
2432    
2433                  final Point2D gcenter = getScreenToWorld().transform(center, null);                  final Point2D gcenter = getScreenToWorld().transform(center, null);
2434                  center = null;                  center = null;
# Line 2401  public class XMapPane extends JPanel { Line 2450  public class XMapPane extends JPanel {
2450                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2451    
2452                  // // Move the newMapArea above the new center if we zoom in:                  // // Move the newMapArea above the new center if we zoom in:
2453                  if (zoomFaktor >= 1) {                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2454                          newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                                  .getY()
2455                                          .getY()                                  - mapArea.centre().y);
                                         - mapArea.centre().y);  
                 }  
2456    
2457                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2458          }          }
# Line 2429  public class XMapPane extends JPanel { Line 2476  public class XMapPane extends JPanel {
2476                  return localRenderer;                  return localRenderer;
2477          }          }
2478    
   
   
2479          /**          /**
2480           * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.           * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
2481           * Macht nichts, wenn {@code null} uebergeben wird.           * Macht nichts, wenn {@code null} uebergeben wird.
# Line 2560  public class XMapPane extends JPanel { Line 2605  public class XMapPane extends JPanel {
2605                  zoomToLayer(getMapContext().getLayerCount() - 1 - index);                  zoomToLayer(getMapContext().getLayerCount() - 1 - index);
2606          }          }
2607    
           
           
   
   
2608          /**          /**
2609           * Aktiviert oder deaktiviert das AntiAliasing for diese           * Aktiviert oder deaktiviert das AntiAliasing for diese
2610           * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer           * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
# Line 2578  public class XMapPane extends JPanel { Line 2619  public class XMapPane extends JPanel {
2619                  if (java2DHints == null) {                  if (java2DHints == null) {
2620                          java2DHints = GeoTools.getDefaultHints();                          java2DHints = GeoTools.getDefaultHints();
2621                  }                  }
2622                    
2623                  java2DHints.put(RenderingHints.KEY_ANTIALIASING,                  java2DHints.put(RenderingHints.KEY_ANTIALIASING,
2624                                  aa ? RenderingHints.VALUE_ANTIALIAS_ON                                  aa ? RenderingHints.VALUE_ANTIALIAS_ON
2625                                                  : RenderingHints.VALUE_ANTIALIAS_OFF);                                                  : RenderingHints.VALUE_ANTIALIAS_OFF);
# Line 2588  public class XMapPane extends JPanel { Line 2629  public class XMapPane extends JPanel {
2629                  java2DHints.put(RenderingHints.KEY_RENDERING,                  java2DHints.put(RenderingHints.KEY_RENDERING,
2630                                  aa ? RenderingHints.VALUE_RENDER_QUALITY                                  aa ? RenderingHints.VALUE_RENDER_QUALITY
2631                                                  : RenderingHints.VALUE_RENDER_SPEED);                                                  : RenderingHints.VALUE_RENDER_SPEED);
2632                    
2633          }          }
2634    
2635  }  }

Legend:
Removed from v.607  
changed lines
  Added in v.649

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26