/[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

revision 632 by alfonx, Thu Jan 28 14:35:45 2010 UTC revision 660 by alfonx, Wed Feb 3 16:10:12 2010 UTC
# Line 13  import java.awt.event.ActionEvent; Line 13  import java.awt.event.ActionEvent;
13  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
14  import java.awt.event.ComponentAdapter;  import java.awt.event.ComponentAdapter;
15  import java.awt.event.ComponentEvent;  import java.awt.event.ComponentEvent;
 import java.awt.event.InputEvent;  
16  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
17  import java.awt.event.MouseListener;  import java.awt.event.MouseListener;
18  import java.awt.geom.AffineTransform;  import java.awt.geom.AffineTransform;
# Line 100  import com.vividsolutions.jts.geom.Geome Line 99  import com.vividsolutions.jts.geom.Geome
99   */   */
100  public class XMapPane extends JPanel {  public class XMapPane extends JPanel {
101    
102            /**
103             * If {@link #maxExtend} is <code>null</code> the following rules are used
104             * to create a default maximum.
105             * <ul>
106             * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
107             * margin</li>
108             * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
109             * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
110             * relative margin</li>
111             * </ul>
112             * **/
113            private double defaultMaxMapExtendMode = .05;
114    
115          // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;          // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
116          // private static final int IMAGETYPE_withAlpha =          // private static final int IMAGETYPE_withAlpha =
117          // BufferedImage.TYPE_INT_ARGB;          // BufferedImage.TYPE_INT_ARGB;
118          private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;          private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
119    
120            public XMapPaneTool getTool() {
121                    return tool;
122            }
123    
124          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;
125    
126          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
127    
128          /** A flag indicating whether the {@link XMapPane} is accepting repaints from the EDT. @see {@link XMapPane#setPainting(boolean)) **/          /**
129             * A flag indicating whether the {@link XMapPane} is accepting repaints from
130             * the EDT. @see {@link XMapPane#setPainting(boolean))
131             **/
132          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
133    
134          /**          /**
# Line 171  public class XMapPane extends JPanel { Line 191  public class XMapPane extends JPanel {
191           * Flag for no-tool.           * Flag for no-tool.
192           */           */
193          public static final int NONE = -123;          public static final int NONE = -123;
194            //
195          /**          // /**
196           * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl          // * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
197           * moeglich!          // * moeglich!
198           *          // *
199           * @see #setState(int)          // * @see #setState(int)
200           */          // */
201          public static final int PAN = 1;          // public static final int PAN = 1;
202            //
203          /**          // /**
204           * Flag fuer Modus "Heran zoomen".          // * Flag fuer Modus "Heran zoomen".
205           *          // *
206           * @see #setState(int)          // * @see #setState(int)
207           * @see #setState(int)          // * @see #setState(int)
208           */          // */
209          public static final int ZOOM_IN = 2;          // public static final int ZOOM_IN = 2;
210            //
211          /**          // /**
212           * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!          // * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
213           *          // *
214           * @see #setState(int)          // * @see #setState(int)
215           */          // */
216          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;  
217    
218          /**          /**
219           * {@link Font} used to paint the wait messages into the map           * {@link Font} used to paint the wait messages into the map
# Line 298  public class XMapPane extends JPanel { Line 294  public class XMapPane extends JPanel {
294                          final MapLayer layer = event.getLayer();                          final MapLayer layer = event.getLayer();
295                          layer.addMapLayerListener(bgMapLayerListener);                          layer.addMapLayerListener(bgMapLayerListener);
296                          requestStartRendering();                          requestStartRendering();
   
297                  }                  }
298    
299                  @Override                  @Override
# Line 392  public class XMapPane extends JPanel { Line 387  public class XMapPane extends JPanel {
387           * While dragging, the {@link #updateFinalImage()} method is translating the           * While dragging, the {@link #updateFinalImage()} method is translating the
388           * cached images while setting it together.           * cached images while setting it together.
389           **/           **/
390          Point imageOrigin = new Point(0, 0);          private final Point imageOrigin = new Point(0, 0);
391          /**          /**
392           * For every rendering thread started,           * For every rendering thread started,
393           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new           * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new
# Line 559  public class XMapPane extends JPanel { Line 554  public class XMapPane extends JPanel {
554           * thread.           * thread.
555           */           */
556          final private Timer startRenderThreadsTimer;          final private Timer startRenderThreadsTimer;
557            //
558          /**          // /**
559           * The default state is ZOOM_IN, hence by default the          // * The default state is ZOOM_IN, hence by default the
560           * {@link #xMapPaneMouseListener} is also enabled.          // * {@link #xMapPaneMouseListener} is also enabled.
561           **/          // **/
562          private int state = ZOOM_IN;          // private int state = ZOOM_IN;
563            //
564          /**          // /**
565           * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen          // * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
566           * MapPane-Funktion          // * MapPane-Funktion
567           */          // */
568          protected Cursor staticCursor = null;          // protected Cursor staticCursor = null;
569    
570          private AffineTransform worldToScreen;          private AffineTransform worldToScreen;
571    
572  //      /**          // /**
573  //       * This {@link MouseListener} is managing all zoom related tasks          // * This {@link MouseListener} is managing all zoom related tasks
574  //       */          // */
575  //      private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          // private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new
576  //                      this);          // ZoomXMapPaneMouseListener(
577                    // this);
578    
579          /**          /**
580           * This {@link MouseListener} is managing all zoom related tasks           * This {@link MouseListener} is managing all zoom related tasks
581           */           */
582          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(this);          private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener(
583                                    this);
584    
585          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
586          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
# Line 629  public class XMapPane extends JPanel { Line 625  public class XMapPane extends JPanel {
625                  this.addMouseMotionListener(xMapPaneMouseListener);                  this.addMouseMotionListener(xMapPaneMouseListener);
626                  this.addMouseWheelListener(xMapPaneMouseListener);                  this.addMouseWheelListener(xMapPaneMouseListener);
627    
628                    // By default the XMapPAne uses the ZOOM_IN tool.
629                    setTool(XMapPaneTool.ZOOM_IN);
630    
631                  /*                  /*
632                   * We use a Timer object to avoid rendering delays and flickering when                   * We use a Timer object to avoid rendering delays and flickering when
633                   * 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 999  public class XMapPane extends JPanel { Line 998  public class XMapPane extends JPanel {
998           */           */
999          protected void drawRectangle(final Graphics graphics, final Point startPos,          protected void drawRectangle(final Graphics graphics, final Point startPos,
1000                          final Point e) {                          final Point e) {
1001                    drawRectangle(graphics, startPos, e, Color.WHITE, false);
1002            }
1003    
1004            /**
1005             * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
1006             * given point. All in screen coordinates.
1007             */
1008            protected void drawRectangle(final Graphics graphics, final Point startPos,
1009                            final Point e, Color color, boolean fill) {
1010    
1011                  if (!isWellDefined())                  if (!isWellDefined())
1012                          return;                          return;
# Line 1014  public class XMapPane extends JPanel { Line 1022  public class XMapPane extends JPanel {
1022                  if (width == 0 && height == 0)                  if (width == 0 && height == 0)
1023                          return;                          return;
1024    
1025                  graphics.setXORMode(Color.WHITE);                  graphics.setXORMode(color);
1026    
1027                    if (fill) {
1028                            graphics.fillRect(left, bottom, width, height);
1029                            graphics.setXORMode(Color.WHITE);
1030                    }
1031    
1032                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
1033          }          }
1034    
# Line 1226  public class XMapPane extends JPanel { Line 1240  public class XMapPane extends JPanel {
1240                                  return null;                                  return null;
1241                          }                          }
1242    
1243                          // Vergrößerung um 10% nochmal rausgenommen                          return JTSUtil
1244                          // // // Kartenbereich um 10% vergroessern                                          .fixAspectRatio(getVisibleRect(), addDefaultMargin(layerBounds), true);
                         // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil  
                         // .expandEnvelope(layerBounds, 0.1), true);  
1245    
                         return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true);  
1246                  }                  }
1247                  return maxExtend;                  return maxExtend;
1248          }          }
# Line 1286  public class XMapPane extends JPanel { Line 1297  public class XMapPane extends JPanel {
1297                  return new AffineTransform(screenToWorld);                  return new AffineTransform(screenToWorld);
1298          }          }
1299    
1300          public int getState() {          // public int getState() {
1301                  return state;          // return state;
1302          }          // }
1303            //
1304          /**          // /**
1305           * Liefert den statisch eingestellten Cursor, der unabhaengig von der          // * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1306           * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.          // * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1307           *          // *
1308           * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der          // * @return {@code null}, wenn kein statischer Cursor verwendet, sondern
1309           *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.          // der
1310           */          // * Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1311          public Cursor getStaticCursor() {          // */
1312                  return this.staticCursor;          // public Cursor getStaticCursor() {
1313          }          // return this.staticCursor;
1314            // }
1315    
1316          public AffineTransform getWorldToScreenTransform() {          public AffineTransform getWorldToScreenTransform() {
1317                  if (worldToScreen == null) {                  if (worldToScreen == null) {
# Line 1353  public class XMapPane extends JPanel { Line 1365  public class XMapPane extends JPanel {
1365          }          }
1366    
1367          /**          /**
1368           * 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.  
1369           *           *
1370           * @param startPos           * @param startPos
1371           *            in screen coordinates           *            in screen coordinates
1372           * @param lastPos           * @param lastPos
1373           *            in screen coordinates           *            in screen coordinates
          * @param event  
          *            the {@link MouseEvent} to read the mouse buttons from  
1374           */           */
1375          public void mouseDragged(final Point startPos, final Point lastPos,          public void pan(final int dX, final int dY) {
                         final MouseEvent event) {  
   
                 if ((getState() == XMapPane.PAN)  
                                 || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {  
1376    
1377                          // Panning needs a panning coursor                  // Panning needs a panning coursor
1378                          if (getCursor() != SwingUtil.PANNING_CURSOR) {                  if (getCursor() != SwingUtil.PANNING_CURSOR) {
1379                                  setCursor(SwingUtil.PANNING_CURSOR);                          setCursor(SwingUtil.PANNING_CURSOR);
1380    
1381                                  // While panning, we deactivate the rendering. So the tasks are                          // While panning, we deactivate the rendering. So the tasks are
1382                                  // ready to start when the panning is finished.                          // ready to start when the panning is finished.
1383                                  if (bgExecuter != null && bgExecuter.isRunning())                          if (bgExecuter != null && bgExecuter.isRunning())
1384                                          bgExecuter.cancelTask();                                  bgExecuter.cancelTask();
1385                                  if (localExecuter.isRunning())                          if (localExecuter.isRunning())
1386                                          localExecuter.cancelTask();                                  localExecuter.cancelTask();
1387                          }                  }
1388                    //
1389                          if (lastPos.x > 0 && lastPos.y > 0) {                  // if (lastPos.x > 0 && lastPos.y > 0) {
1390                                  final int dx = event.getX() - lastPos.x;                  // final int dx = event.getX() - lastPos.x;
1391                                  final int dy = event.getY() - lastPos.y;                  // final int dy = event.getY() - lastPos.y;
1392    
1393                                  // TODO Stop dragging when the drag would not be valid...                  // TODO Stop dragging when the drag would not be valid...
1394                                  // boolean dragValid = true;                  // boolean dragValid = true;
1395                                  // // check if this panning results in a valid mapArea                  // // check if this panning results in a valid mapArea
1396                                  // {                  // {
1397                                  // Rectangle winBounds = xMapPane.getBounds();                  // Rectangle winBounds = xMapPane.getBounds();
1398                                  // winBounds.translate(xMapPane.imageOrigin.x,                  // winBounds.translate(xMapPane.imageOrigin.x,
1399                                  // -xMapPane.imageOrigin.y);                  // -xMapPane.imageOrigin.y);
1400                                  // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(                  // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(
1401                                  // winBounds.x, winBounds.y, winBounds.x                  // winBounds.x, winBounds.y, winBounds.x
1402                                  // + winBounds.width, winBounds.y                  // + winBounds.width, winBounds.y
1403                                  // + winBounds.height);                  // + winBounds.height);
1404                                  //                                                        //                                      
1405                                  //                  //
1406                                  // winBounds = xMapPane.getBounds();                  // winBounds = xMapPane.getBounds();
1407                                  // Point testIng = new Point(xMapPane.imageOrigin);                  // Point testIng = new Point(xMapPane.imageOrigin);
1408                                  // testIng.translate(dx, dy);                  // testIng.translate(dx, dy);
1409                                  // winBounds.translate(testIng.x, -testIng.y);                  // winBounds.translate(testIng.x, -testIng.y);
1410                                  // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(                  // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(
1411                                  // winBounds.x, winBounds.y, winBounds.x                  // winBounds.x, winBounds.y, winBounds.x
1412                                  // + winBounds.width, winBounds.y                  // + winBounds.width, winBounds.y
1413                                  // + winBounds.height);                  // + winBounds.height);
1414                                  //                  //
1415                                  // // If the last drag doesn't change the MapArea anymore cancel                  // // If the last drag doesn't change the MapArea anymore cancel
1416                                  // it.                  // it.
1417                                  // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(                  // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(
1418                                  // xMapPane.bestAllowedMapArea(newMapAreaBefore))){                  // xMapPane.bestAllowedMapArea(newMapAreaBefore))){
1419                                  // dragValid = false;                  // dragValid = false;
1420                                  // return;                  // return;
1421                                  // }                  // }
1422                                  // }                  // }
1423    
1424                                  imageOrigin.translate(dx, dy);                  getImageOrigin().translate(dX, dY);
1425                                  updateFinalImage();                  updateFinalImage();
1426                                  repaint();                  repaint();
1427                          }                  // }
1428    
1429                  } else if ((getState() == XMapPane.ZOOM_IN)                  // } else if ((getState() == XMapPane.ZOOM_IN)
1430                                  || (getState() == XMapPane.ZOOM_OUT)                  // || (getState() == XMapPane.ZOOM_OUT)
1431                                  || (getState() == XMapPane.SELECT_ALL)                  // || (getState() == XMapPane.SELECT_ALL)
1432                                  || (getState() == XMapPane.SELECT_TOP)) {                  // || (getState() == XMapPane.SELECT_TOP)) {
1433                    //
1434                          // Draws a rectangle                  // // Draws a rectangle
1435                          final Graphics2D graphics = (Graphics2D) getGraphics();                  // final Graphics2D graphics = (Graphics2D) getGraphics();
1436                          drawRectangle(graphics, startPos, event.getPoint());                  // drawRectangle(graphics, startPos, event.getPoint());
1437                          if ((lastPos.x > 0) && (lastPos.y > 0))                  // if ((lastPos.x > 0) && (lastPos.y > 0))
1438                                  drawRectangle(graphics, startPos, lastPos);                  // drawRectangle(graphics, startPos, lastPos);
1439                          graphics.dispose();                  // graphics.dispose();
1440                  }                  // }
1441          }          }
1442    
1443          /**          /**
# Line 1595  public class XMapPane extends JPanel { Line 1600  public class XMapPane extends JPanel {
1600    
1601          }          }
1602    
1603          /**          //
1604           * Performs a {@value #PAN} action. During panning, the displacement is          // /**
1605           * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will          // * Performs a {@value #PAN} action. During panning, the displacement is
1606           * reset the offset and call {@link #setMapArea(Envelope)}.          // * stored in {@link #imageOrigin} object. Calling {@link #performPan()}
1607           */          // will
1608          public void performPan() {          // * reset the offset and call {@link #setMapArea(Envelope)}.
1609            // */
1610                  final Rectangle winBounds = getVisibleRect();          // public void performPan() {
1611            //
1612                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);          // final Rectangle winBounds = getVisibleRect();
1613                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,          //
1614                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y          // winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1615                                                  + winBounds.height);          // final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1616            // winBounds.y, winBounds.x + winBounds.width, winBounds.y
1617                  imageOrigin.x = 0;          // + winBounds.height);
1618                  imageOrigin.y = 0;          //
1619            // imageOrigin.x = 0;
1620                  if (!setMapArea(newMapArea)) {          // imageOrigin.y = 0;
1621                          /**          //
1622                           * If setMapArea returns true, the finalImage is updated anyways.          // if (!setMapArea(newMapArea)) {
1623                           * This if-case exists to ensure that we repaint a correct image          // /**
1624                           * even if the new panning area has been denied.          // * If setMapArea returns true, the finalImage is updated anyways.
1625                           */          // * This if-case exists to ensure that we repaint a correct image
1626                          updateFinalImage();          // * even if the new panning area has been denied.
1627                          repaint();          // */
1628                  }          // updateFinalImage();
1629            // repaint();
1630                  if (getCursor() == SwingUtil.PANNING_CURSOR)          // }
1631                          setCursor(SwingUtil.PAN_CURSOR);          //
1632          }          // if (getCursor() == SwingUtil.PANNING_CURSOR)
1633            // setCursor(SwingUtil.PAN_CURSOR);
1634            // }
1635    
1636          /**          /**
1637           * Entfernt einen Listener von der Map.           * Entfernt einen Listener von der Map.
# Line 1677  public class XMapPane extends JPanel { Line 1684  public class XMapPane extends JPanel {
1684    
1685                  if (mapArea == null)                  if (mapArea == null)
1686                          return;                          return;
1687                    
1688                  final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,                  final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1689                                  getMapContext().getCoordinateReferenceSystem());                                  getMapContext().getCoordinateReferenceSystem());
1690    
# Line 1933  public class XMapPane extends JPanel { Line 1940  public class XMapPane extends JPanel {
1940    
1941          // /** Stored the time used for the last real rendering in ms. **/          // /** Stored the time used for the last real rendering in ms. **/
1942          private long lastRenderingDuration = 1000;          private long lastRenderingDuration = 1000;
1943            private XMapPaneTool tool = null;
1944    
1945          /**          /**
1946           * 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 1964  public class XMapPane extends JPanel { Line 1972  public class XMapPane extends JPanel {
1972                          this.rendererHints = rendererHints;                          this.rendererHints = rendererHints;
1973          }          }
1974    
1975          /**          // @Deprecated
1976           * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the          // public void setState(final int state) {
1977           * repaint Timer if          // this.state = state;
1978           *          //
1979           * @param state          // // throw new RuntimeException("Old concept.. migrate to new concept!");
1980           */          //
1981          @Deprecated          // // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
1982          public void setState(final int state) {          // // || state == ZOOM_OUT || state == PAN));
1983                  this.state = state;          //
1984                            // // Je nach Aktion den Cursor umsetzen
1985                  throw new RuntimeException("Old concept.. migrate to new concept!");          // updateCursor();
1986            // }
 //              xMapPaneMouseListener.setEnabled((state == ZOOM_IN  
 //                              || state == ZOOM_OUT || state == PAN));  
1987    
1988                  // Je nach Aktion den Cursor umsetzen          public void configureMouse(MouseInputType type, XMapPaneAction action) {
1989  //              updateCursor();                  xMapPaneMouseListener.actions.put(type, action);
         }  
           
         public void configureMouse(MouseInputType type, XMapPaneAction action){  
                   
1990          }          }
1991    
1992          /**          /**
1993           * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,           * Configure the {@link XMapPaneTool} that active on the map. Passing
1994           * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor           * <code>null</code> will set the NO_ACTION tool.
          * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion  
          * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann  
          * {@code null} als Parameter uebergeben werden  
          *  
          * @param cursor  
          *            Cursor  
1995           */           */
1996          public void setStaticCursor(final Cursor cursor) {          public void setTool(XMapPaneTool tool) {
1997                  this.staticCursor = cursor;                  if (tool == null)
1998                  if (cursor != null)                          tool = XMapPaneTool.NO_ACTION;
1999                          super.setCursor(cursor);                  this.tool = tool;
2000                    xMapPaneMouseListener.configure(tool);
2001                    setCursor(tool.getCursor());
2002          }          }
2003    
2004            // /**
2005            // * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion
2006            // (Zoom,
2007            // * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
2008            // * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
2009            // * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
2010            // * {@code null} als Parameter uebergeben werden
2011            // *
2012            // * @param cursor
2013            // * Cursor
2014            // */
2015            // public void setStaticCursor(final Cursor cursor) {
2016            // this.staticCursor = cursor;
2017            // if (cursor != null)
2018            // super.setCursor(cursor);
2019            // }
2020    
2021          /**          /**
2022           * Starts rendering on one or two threads           * Starts rendering on one or two threads
2023           */           */
# Line 2143  public class XMapPane extends JPanel { Line 2158  public class XMapPane extends JPanel {
2158                                  repaint();                                  repaint();
2159                          }                          }
2160                  }                  }
2161                    //              
2162                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig                  // //
2163                  // von der aktuellen Aktion                  // // wenn manueller Cursor gesetzt ist, dann diesen verwenden
2164                  if (this.staticCursor != null) {                  // (unabhaengig
2165                          setCursor(staticCursor);                  // // von der aktuellen Aktion
2166                          return;                  // if (this.staticCursor != null) {
2167                  }                  // setCursor(staticCursor);
2168                    // return;
2169                    // }
2170                    //              
2171                  if (getCursor() == SwingUtil.PANNING_CURSOR) {                  if (getCursor() == SwingUtil.PANNING_CURSOR) {
2172                          // This cursor will reset itself                          // This cursor will reset itself
2173                          return;                          return;
2174                  }                  }
2175    
2176                  // Set the cursor depending on what tool is in use...                  setCursor(tool.getCursor());
2177                  switch (state) {  
2178                  case SELECT_TOP:                  //
2179                  case SELECT_ONE_FROM_TOP:                  // // Set the cursor depending on what tool is in use...
2180                  case SELECT_ALL:                  // switch (state) {
2181                          setCursor(SwingUtil.CROSSHAIR_CURSOR);                  // case SELECT_TOP:
2182                          break;                  // case SELECT_ONE_FROM_TOP:
2183                  case ZOOM_IN:                  // case SELECT_ALL:
2184                          setCursor(SwingUtil.ZOOMIN_CURSOR);                  // setCursor(SwingUtil.CROSSHAIR_CURSOR);
2185                          break;                  // break;
2186                  case ZOOM_OUT:                  // case ZOOM_IN:
2187                          setCursor(SwingUtil.ZOOMOUT_CURSOR);                  // setCursor(SwingUtil.ZOOMIN_CURSOR);
2188                          break;                  // break;
2189                  case PAN:                  // case ZOOM_OUT:
2190                          setCursor(SwingUtil.PAN_CURSOR);                  // setCursor(SwingUtil.ZOOMOUT_CURSOR);
2191                          break;                  // break;
2192                  default:                  // case PAN:
2193                          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));                  // setCursor(SwingUtil.PAN_CURSOR);
2194                          break;                  // break;
2195                  }                  // default:
2196                    // setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2197                    // break;
2198                    // }
2199          }          }
2200    
2201          /**          /**
# Line 2204  public class XMapPane extends JPanel { Line 2225  public class XMapPane extends JPanel {
2225    
2226                  final Graphics2D finalG = getFinalImage().createGraphics();                  final Graphics2D finalG = getFinalImage().createGraphics();
2227                  finalG.setBackground(getMapBackgroundColor());                  finalG.setBackground(getMapBackgroundColor());
2228                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), getImageOrigin().x,
2229                                  getMapBackgroundColor(), null);                                  getImageOrigin().y, getMapBackgroundColor(), null);
2230    
2231                  // When panning, we have to clear the area around the image                  // When panning, we have to clear the area around the image
2232                  final Rectangle painedArea = new Rectangle(imageOrigin.x,                  final Rectangle painedArea = new Rectangle(getImageOrigin().x,
2233                                  imageOrigin.y, getFinalImage().getWidth(), getFinalImage()                                  getImageOrigin().y, getFinalImage().getWidth(), getFinalImage()
2234                                                  .getHeight());                                                  .getHeight());
2235                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
2236                                  getMapBackgroundColor());                                  getMapBackgroundColor());
2237    
2238                  addGadgets(finalG, false);                  // addGadgets(finalG, false);
2239    
2240                  finalG.dispose();                  finalG.dispose();
2241    
# Line 2375  public class XMapPane extends JPanel { Line 2396  public class XMapPane extends JPanel {
2396                          // BB umrechnen von Layer-CRS in Map-CRS                          // BB umrechnen von Layer-CRS in Map-CRS
2397    
2398                          // Expand a bit                          // Expand a bit
2399                          bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.);                          addDefaultMargin(bounds);
2400    
2401                          setMapArea(bounds);                          setMapArea(bounds);
2402                  }                  }
2403          }          }
2404    
2405            private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) {
2406                    return JTSUtil.expandEnvelope(bounds, Math.max(0,
2407                                    defaultMaxMapExtendMode));
2408            }
2409    
2410            private Envelope addDefaultMargin(Envelope bounds) {
2411                    return JTSUtil.expandEnvelope(bounds, Math.max(0,
2412                                    defaultMaxMapExtendMode));
2413            }
2414    
2415          /**          /**
2416           * Zooms towards a point.           * Zooms towards a point.
2417           *           *
# Line 2528  public class XMapPane extends JPanel { Line 2559  public class XMapPane extends JPanel {
2559                          // genau auf dem Rand der angezeigten Flaeche)                          // genau auf dem Rand der angezeigten Flaeche)
2560    
2561                          if (mapAreaNew != null) {                          if (mapAreaNew != null) {
2562                                  mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew  
2563                                                  .getHeight() * 0.1);                                  mapAreaNew = addDefaultMargin(mapAreaNew);
2564                                  setMapArea(mapAreaNew);                                  setMapArea(mapAreaNew);
2565                          } else {                          } else {
2566                                  LOGGER                                  LOGGER
# Line 2607  public class XMapPane extends JPanel { Line 2638  public class XMapPane extends JPanel {
2638    
2639          }          }
2640    
2641            public Point getImageOrigin() {
2642                    return imageOrigin;
2643            }
2644    
2645            /**
2646             * If {@link #maxExtend} is <code>null</code> the following rules are used
2647             * to create a default maximum.
2648             * <ul>
2649             * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
2650             * margin</li>
2651             * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
2652             * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
2653             * relative margin</li>
2654             * </ul>
2655             * **/
2656            public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode) {
2657                    this.defaultMaxMapExtendMode = defaultMaxMapExtendMode;
2658            }
2659    
2660            /**
2661             * If {@link #maxExtend} is <code>null</code> the following rules are used
2662             * to create a default maximum.
2663             * <ul>
2664             * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
2665             * margin</li>
2666             * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
2667             * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
2668             * relative margin</li>
2669             * </ul>
2670             * **/
2671            public double getDefaultMaxMapExtendMode() {
2672                    return defaultMaxMapExtendMode;
2673            }
2674    
2675  }  }

Legend:
Removed from v.632  
changed lines
  Added in v.660

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26