/[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 656 by alfonx, Wed Feb 3 12:18:35 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 102  public class XMapPane extends JPanel { Line 104  public class XMapPane extends JPanel {
104          // private static final int IMAGETYPE_withAlpha =          // private static final int IMAGETYPE_withAlpha =
105          // BufferedImage.TYPE_INT_ARGB;          // BufferedImage.TYPE_INT_ARGB;
106          private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;          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;          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 168  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
# Line 251  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 272  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 291  public class XMapPane extends JPanel { Line 281  public class XMapPane extends JPanel {
281                          final 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 385  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 414  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  //                      getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow...                          // getLocalRenderer().setContext(getMapContext()); geht doch auch
407                            // ohne?!?!? wow...
408                          requestStartRendering();                          requestStartRendering();
409                  }                  }
410    
# Line 551  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
553           * MapPane-Funktion  //       * MapPane-Funktion
554           */  //       */
555          protected Cursor staticCursor = null;  //      protected Cursor staticCursor = null;
556    
557          private AffineTransform worldToScreen;          private AffineTransform worldToScreen;
558    
559            // /**
560            // * This {@link MouseListener} is managing all zoom related tasks
561            // */
562            // private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new
563            // ZoomXMapPaneMouseListener(
564            // this);
565    
566          /**          /**
567           * This {@link MouseListener} is managing all zoom related tasks           * This {@link MouseListener} is managing all zoom related tasks
568           */           */
569          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(
570                          this);                          this);
571    
572          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
# Line 611  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 968  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 985  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 1000  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 1126  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 1272  public class XMapPane extends JPanel { Line 1288  public class XMapPane extends JPanel {
1288                  return new AffineTransform(screenToWorld);                  return new AffineTransform(screenToWorld);
1289          }          }
1290    
1291          public int getState() {  //      public int getState() {
1292                  return state;  //              return state;
1293          }  //      }
1294    //
1295          /**  //      /**
1296           * Liefert den statisch eingestellten Cursor, der unabhaengig von der  //       * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1297           * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.  //       * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1298           *  //       *
1299           * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der  //       * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der
1300           *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.  //       *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1301           */  //       */
1302          public Cursor getStaticCursor() {  //      public Cursor getStaticCursor() {
1303                  return this.staticCursor;  //              return this.staticCursor;
1304          }  //      }
1305    
1306          public AffineTransform getWorldToScreenTransform() {          public AffineTransform getWorldToScreenTransform() {
1307                  if (worldToScreen == null) {                  if (worldToScreen == null) {
# Line 1339  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 Graphics2D graphics = (Graphics2D) 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          /**          /**
# Line 1438  public class XMapPane extends JPanel { Line 1447  public class XMapPane extends JPanel {
1447           */           */
1448          public void onRenderingCompleted(final long l) {          public void onRenderingCompleted(final long l) {
1449                  lastRenderingDuration = (lastRenderingDuration + l) / 2;                  lastRenderingDuration = (lastRenderingDuration + l) / 2;
1450                  LOGGER                  // LOGGER
1451                                  .debug("complete rendering after " + lastRenderingDuration                  // .debug("complete rendering after " + lastRenderingDuration
1452                                                  + "ms");                  // + "ms");
1453    
1454                  repaintTimer.stop();                  repaintTimer.stop();
1455    
# Line 1580  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                  final 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 1656  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() {
                 final 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    
# Line 1916  public class XMapPane extends JPanel { Line 1928  public class XMapPane extends JPanel {
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 = 1000;          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 1947  public class XMapPane extends JPanel { Line 1960  public class XMapPane extends JPanel {
1960                          this.rendererHints = rendererHints;                          this.rendererHints = rendererHints;
1961          }          }
1962    
1963          /**  //      @Deprecated
1964           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the  //      public void setState(final int state) {
1965           * repaint Timer if  //              this.state = state;
1966           *  //
1967           * @param state  //              // throw new RuntimeException("Old concept.. migrate to new concept!");
1968           */  //
1969          public void setState(final int state) {  //              // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
1970                  this.state = state;  //              // || state == ZOOM_OUT || state == PAN));
1971    //
1972                  zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN  //              // Je nach Aktion den Cursor umsetzen
1973                                  || state == ZOOM_OUT || state == PAN));  //              updateCursor();
1974    //      }
1975    
1976                  // Je nach Aktion den Cursor umsetzen          public void configureMouse(MouseInputType type, XMapPaneAction action) {
1977                  updateCursor();                  xMapPaneMouseListener.actions.put(type, action);
1978          }          }
1979            
1980          /**          /**
1981           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,           * Configure the {@link XMapPaneTool} that active on the map. Passing
1982           * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor           * <code>null</code> will set the NO_ACTION tool.
1983           * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion           */
1984           * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann          public void setTool(XMapPaneTool tool) {
1985           * {@code null} als Parameter uebergeben werden                  if (tool == null)
1986           *                          tool = XMapPaneTool.NO_ACTION;
1987           * @param cursor                  this.tool = tool;
1988           *            Cursor                  xMapPaneMouseListener.configure(tool);
1989           */                  setCursor(tool.getCursor());
1990          public void setStaticCursor(final Cursor cursor) {          }
1991                  this.staticCursor = cursor;  
1992                  if (cursor != null)  //      /**
1993                          super.setCursor(cursor);  //       * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,
1994          }  //       * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
1995    //       * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
1996    //       * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
1997    //       * {@code null} als Parameter uebergeben werden
1998    //       *
1999    //       * @param cursor
2000    //       *            Cursor
2001    //       */
2002    //      public void setStaticCursor(final Cursor cursor) {
2003    //              this.staticCursor = cursor;
2004    //              if (cursor != null)
2005    //                      super.setCursor(cursor);
2006    //      }
2007    
2008          /**          /**
2009           * Starts rendering on one or two threads           * Starts rendering on one or two threads
# Line 2119  public class XMapPane extends JPanel { Line 2145  public class XMapPane extends JPanel {
2145                                  repaint();                                  repaint();
2146                          }                          }
2147                  }                  }
2148    //              
2149                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig  ////
2150                  // von der aktuellen Aktion  //              // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
2151                  if (this.staticCursor != null) {  //              // von der aktuellen Aktion
2152                          setCursor(staticCursor);  //              if (this.staticCursor != null) {
2153                          return;  //                      setCursor(staticCursor);
2154                  }  //                      return;
2155    //              }
2156    //              
2157                  if (getCursor() == SwingUtil.PANNING_CURSOR) {                  if (getCursor() == SwingUtil.PANNING_CURSOR) {
2158                          // This cursor will reset itself                          // This cursor will reset itself
2159                          return;                          return;
2160                  }                  }
2161                    
2162                  // Set the cursor depending on what tool is in use...                  setCursor(tool.getCursor());
2163                  switch (state) {                  
2164                  case SELECT_TOP:  //
2165                  case SELECT_ONE_FROM_TOP:  //              // Set the cursor depending on what tool is in use...
2166                  case SELECT_ALL:  //              switch (state) {
2167                          setCursor(SwingUtil.CROSSHAIR_CURSOR);  //              case SELECT_TOP:
2168                          break;  //              case SELECT_ONE_FROM_TOP:
2169                  case ZOOM_IN:  //              case SELECT_ALL:
2170                          setCursor(SwingUtil.ZOOMIN_CURSOR);  //                      setCursor(SwingUtil.CROSSHAIR_CURSOR);
2171                          break;  //                      break;
2172                  case ZOOM_OUT:  //              case ZOOM_IN:
2173                          setCursor(SwingUtil.ZOOMOUT_CURSOR);  //                      setCursor(SwingUtil.ZOOMIN_CURSOR);
2174                          break;  //                      break;
2175                  case PAN:  //              case ZOOM_OUT:
2176                          setCursor(SwingUtil.PAN_CURSOR);  //                      setCursor(SwingUtil.ZOOMOUT_CURSOR);
2177                          break;  //                      break;
2178                  default:  //              case PAN:
2179                          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  //                      setCursor(SwingUtil.PAN_CURSOR);
2180                          break;  //                      break;
2181                  }  //              default:
2182    //                      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2183    //                      break;
2184    //              }
2185          }          }
2186    
2187          /**          /**
# Line 2180  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                  // When panning, we have to clear the area around the image                  // When panning, we have to clear the area around the image
2218                  final Rectangle painedArea = new Rectangle(imageOrigin.x,                  final Rectangle painedArea = new Rectangle(getImageOrigin().x,
2219                                  imageOrigin.y, getFinalImage().getWidth(), getFinalImage()                                  getImageOrigin().y, getFinalImage().getWidth(), getFinalImage()
2220                                                  .getHeight());                                                  .getHeight());
2221                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
2222                                  getMapBackgroundColor());                                  getMapBackgroundColor());
2223    
2224                  addGadgets(finalG, false);  //              addGadgets(finalG, false);
2225    
2226                  finalG.dispose();                  finalG.dispose();
2227    
# Line 2375  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 2401  public class XMapPane extends JPanel { Line 2432  public class XMapPane extends JPanel {
2432                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2433    
2434                  // // Move the newMapArea above the new center if we zoom in:                  // // Move the newMapArea above the new center if we zoom in:
2435                  if (zoomFaktor >= 1) {                  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 2429  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.           * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
2463           * Macht nichts, wenn {@code null} uebergeben wird.           * Macht nichts, wenn {@code null} uebergeben wird.
# Line 2560  public class XMapPane extends JPanel { Line 2587  public class XMapPane extends JPanel {
2587                  zoomToLayer(getMapContext().getLayerCount() - 1 - index);                  zoomToLayer(getMapContext().getLayerCount() - 1 - index);
2588          }          }
2589    
           
           
   
   
2590          /**          /**
2591           * Aktiviert oder deaktiviert das AntiAliasing for diese           * Aktiviert oder deaktiviert das AntiAliasing for diese
2592           * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer           * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
# Line 2578  public class XMapPane extends JPanel { Line 2601  public class XMapPane extends JPanel {
2601                  if (java2DHints == null) {                  if (java2DHints == null) {
2602                          java2DHints = GeoTools.getDefaultHints();                          java2DHints = GeoTools.getDefaultHints();
2603                  }                  }
2604                    
2605                  java2DHints.put(RenderingHints.KEY_ANTIALIASING,                  java2DHints.put(RenderingHints.KEY_ANTIALIASING,
2606                                  aa ? RenderingHints.VALUE_ANTIALIAS_ON                                  aa ? RenderingHints.VALUE_ANTIALIAS_ON
2607                                                  : RenderingHints.VALUE_ANTIALIAS_OFF);                                                  : RenderingHints.VALUE_ANTIALIAS_OFF);
# Line 2588  public class XMapPane extends JPanel { Line 2611  public class XMapPane extends JPanel {
2611                  java2DHints.put(RenderingHints.KEY_RENDERING,                  java2DHints.put(RenderingHints.KEY_RENDERING,
2612                                  aa ? RenderingHints.VALUE_RENDER_QUALITY                                  aa ? RenderingHints.VALUE_RENDER_QUALITY
2613                                                  : RenderingHints.VALUE_RENDER_SPEED);                                                  : RenderingHints.VALUE_RENDER_SPEED);
2614                    
2615            }
2616    
2617            public Point getImageOrigin() {
2618                    return imageOrigin;
2619          }          }
2620    
2621  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26