/[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 538 by alfonx, Fri Nov 20 15:38:34 2009 UTC revision 539 by alfonx, Fri Nov 20 19:10:05 2009 UTC
# Line 44  import org.geotools.referencing.CRS; Line 44  import org.geotools.referencing.CRS;
44  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
45  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
46  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
47    import org.geotools.renderer.lite.RendererUtilities;
48  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
49  import org.geotools.swing.JMapPane;  import org.geotools.swing.JMapPane;
50  import org.geotools.swing.event.MapMouseEvent;  import org.geotools.swing.event.MapMouseEvent;
# Line 146  public class XMapPane extends JPanel { Line 147  public class XMapPane extends JPanel {
147           * Default delay (milliseconds) before the map will be redrawn when resizing           * Default delay (milliseconds) before the map will be redrawn when resizing
148           * the pane. This is to avoid flickering while drag-resizing.           * the pane. This is to avoid flickering while drag-resizing.
149           */           */
150          public static final int DEFAULT_RESIZING_PAINT_DELAY = 500;          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
151    
152          public static final int NONE = -123;          public static final int NONE = -123;
153    
# Line 386  public class XMapPane extends JPanel { Line 387  public class XMapPane extends JPanel {
387                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
388    
389                          if (localContext.getLayers().length == 1) { // the first one                          if (localContext.getLayers().length == 1) { // the first one
390    
391                                  // if the Area of Interest is unset, the LayerBounds are used                                  // if the Area of Interest is unset, the LayerBounds are used
392                                  if (!setMapArea(localContext.getAreaOfInterest()))                                  if (!setMapArea(localContext.getAreaOfInterest()))
393                                          repaint();                                          repaint();
# Line 538  public class XMapPane extends JPanel { Line 540  public class XMapPane extends JPanel {
540    
541          private final Timer resizeTimer;          private final Timer resizeTimer;
542    
         private final int resizingPaintDelay;  
   
543          /**          /**
544           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
545           * (lat/lon)           * (lat/lon)
# Line 620  public class XMapPane extends JPanel { Line 620  public class XMapPane extends JPanel {
620                   * Using a ComponentListener doesn't work because, unlike a JFrame, the                   * Using a ComponentListener doesn't work because, unlike a JFrame, the
621                   * pane receives a stream of events during drag-resizing.                   * pane receives a stream of events during drag-resizing.
622                   */                   */
623                  resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY;                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() {
                 resizeTimer = new Timer(resizingPaintDelay, new ActionListener() {  
624    
625                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
626                                  paneResized = true;                                  paneResized = true;
# Line 714  public class XMapPane extends JPanel { Line 713  public class XMapPane extends JPanel {
713           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
714           */           */
715          public Envelope bestAllowedMapArea(Envelope env) {          public Envelope bestAllowedMapArea(Envelope env) {
716                    // return env;
717                  if (getWidth() == 0)                  if (getWidth() == 0)
718                          return env;                          return env;
719                  if (env == null)                  if (env == null)
# Line 921  public class XMapPane extends JPanel { Line 921  public class XMapPane extends JPanel {
921                          }                          }
922                          localExecuter.dispose();                          localExecuter.dispose();
923                  }                  }
924                  //  
                 // if (bgImage != null) {  
                 // bgImage = dispose(bgImage);  
                 // bgImage = null;  
                 // // LangUtil.gcTotal();  
                 // }  
                 //  
                 // if (localImage != null) {  
                 // localImage = dispose(localImage);  
                 // localImage = null;  
                 // // LangUtil.gcTotal();  
                 // }  
                 //  
                 // if (finalImage != null) {  
                 // finalImage = dispose(finalImage);  
                 // finalImage = null;  
                 // // LangUtil.gcTotal();  
                 // }  
                 //  
                 // if (preFinalImage != null) {  
                 // preFinalImage = dispose(preFinalImage);  
                 // preFinalImage = null;  
                 // }  
925                  disposeImages();                  disposeImages();
926    
927                  // LangUtil.gcTotal();                  // LangUtil.gcTotal();
# Line 1001  public class XMapPane extends JPanel { Line 979  public class XMapPane extends JPanel {
979           */           */
980          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
981    
982                    if (1 == 1)return false;
983                    
984                  if (quickPreviewHint == 0)                  if (quickPreviewHint == 0)
985                          return false;                          return false;
986    
# Line 1019  public class XMapPane extends JPanel { Line 999  public class XMapPane extends JPanel {
999                  // Calculate the oldMapArea in the current WindowCoordinates:                  // Calculate the oldMapArea in the current WindowCoordinates:
1000                  final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),                  final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),
1001                                  oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea                                  oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea
1002                                                  .getMaxY(), null);                                                  .getMaxY());
1003    
1004                  final int xx1 = (int) Math.round(oldMapWindow.getMinX());                  final int xx1 = (int) Math.round(oldMapWindow.getMinX());
1005                  final int yy1 = (int) Math.round(oldMapWindow.getMinY());                  final int yy1 = (int) Math.round(oldMapWindow.getMinY());
# Line 1124  public class XMapPane extends JPanel { Line 1104  public class XMapPane extends JPanel {
1104                  if (mapArea == null)                  if (mapArea == null)
1105                          return null;                          return null;
1106    
1107                    // TODO is needed at all, this should go to setMapArea maybe
1108                  if (localContext.getCoordinateReferenceSystem() == null)                  if (localContext.getCoordinateReferenceSystem() == null)
1109                          try {                          try {
1110                                  localContext.setCoordinateReferenceSystem(GeoImportUtil                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1111                                                  .getDefaultCRS());                                                  .getDefaultCRS());
1112                          } catch (TransformException e) {                          } catch (Exception e) {
1113                                  // TODO Auto-generated catch block                                  throw new RuntimeException("setting context CRS:", e);
                                 e.printStackTrace();  
                         } catch (FactoryException e) {  
                                 // TODO Auto-generated catch block  
                                 e.printStackTrace();  
1114                          }                          }
1115    
1116                  return new ReferencedEnvelope(mapArea, localContext                  return new ReferencedEnvelope(mapArea, localContext
# Line 1610  public class XMapPane extends JPanel { Line 1587  public class XMapPane extends JPanel {
1587                  requestStartRendering = true;                  requestStartRendering = true;
1588    
1589          }          }
1590  //  
1591  //      /**          //
1592  //       * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten          // /**
1593  //       * neu.          // * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
1594  //       */          // * neu.
1595  //      protected void resetTransforms() {          // */
1596  //              if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)          // protected void resetTransforms() {
1597  //                      return;          // if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
1598  //          // return;
1599  //              // We store the last Transform          //
1600  //              oldScreenToWorld = screenToWorld;          // // We store the last Transform
1601  //          // oldScreenToWorld = screenToWorld;
1602  //              this.screenToWorld = new AffineTransform(          //
1603  //              // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten          // this.screenToWorld = new AffineTransform(
1604  //                              // nach rechts (Osten) hin groesser          // // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
1605  //                              // --> positive Verschiebung          // // nach rechts (Osten) hin groesser
1606  //                              getMapArea().getWidth() / getWidth(),          // // --> positive Verschiebung
1607  //                              // keine Verzerrung          // getMapArea().getWidth() / getWidth(),
1608  //                              0.0, 0.0,          // // keine Verzerrung
1609  //                              // Waehrend die Fenster-Koordinaten nach unten hin groesser          // 0.0, 0.0,
1610  //                              // werden,          // // Waehrend die Fenster-Koordinaten nach unten hin groesser
1611  //                              // werden Latitude-Koordinaten nach Sueden hin keiner          // // werden,
1612  //                              // --> negative Verschiebung          // // werden Latitude-Koordinaten nach Sueden hin keiner
1613  //                              -getMapArea().getHeight() / getHeight(),          // // --> negative Verschiebung
1614  //                              // Die Longitude-Koordinaten werden nach Osten hin groesser          // -getMapArea().getHeight() / getHeight(),
1615  //                              // --> obere linke Ecke des Fensters hat also den Minimalwert          // // Die Longitude-Koordinaten werden nach Osten hin groesser
1616  //                              getMapArea().getMinX(),          // // --> obere linke Ecke des Fensters hat also den Minimalwert
1617  //                              // Die Latitude-Koordinaten werden nach Norden hin groesser          // getMapArea().getMinX(),
1618  //                              // --> obere linke Ecke des Fensters hat also den Maximalwert          // // Die Latitude-Koordinaten werden nach Norden hin groesser
1619  //                              getMapArea().getMaxY());          // // --> obere linke Ecke des Fensters hat also den Maximalwert
1620  //          // getMapArea().getMaxY());
1621  //              try {          //
1622  //                      this.worldToScreen = screenToWorld.createInverse();          // try {
1623  //              } catch (final NoninvertibleTransformException e) {          // this.worldToScreen = screenToWorld.createInverse();
1624  //                      LOGGER.error(e);          // } catch (final NoninvertibleTransformException e) {
1625  //              }          // LOGGER.error(e);
1626  //      }          // }
1627                    // }
1628            
1629            /**
1630      /**           * Calculate the affine transforms used to convert between world and pixel
1631       * Calculate the affine transforms used to convert between           * coordinates. The calculations here are very basic and assume a cartesian
1632       * world and pixel coordinates. The calculations here are very           * reference system.
1633       * basic and assume a cartesian reference system.           * <p>
1634       * <p>           * Tne transform is calculated such that {@code envelope} will be centred in
1635       * Tne transform is calculated such that {@code envelope} will           * the display
1636       * be centred in the display           *
1637       *           * @param envelope
1638       * @param envelope the current map extent (world coordinates)           *            the current map extent (world coordinates)
1639       * @param paintArea the current map pane extent (screen units)           * @param paintArea
1640       */           *            the current map pane extent (screen units)
1641      private void resetTransforms() {           */
1642          ReferencedEnvelope refEnv = new ReferencedEnvelope(mapArea, getContext().getCoordinateReferenceSystem());          private void resetTransforms() {
1643                    ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1644          Rectangle paintArea = getBounds();                                  getContext().getCoordinateReferenceSystem());
1645                            //
1646          double xscale = paintArea.getWidth() / refEnv.getWidth();                  Rectangle paintArea = getBounds();
1647          double yscale = paintArea.getHeight() / refEnv.getHeight();                  
1648                    if (!getBounds().equals(getVisibleRect())) {
1649          double scale = Math.min(xscale, yscale);                          System.out.println("did we expect that?");
1650                    }
1651          double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();                  //        
1652          double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();                  // double xscale = paintArea.getWidth() / refEnv.getWidth();
1653                    // double yscale = paintArea.getHeight() / refEnv.getHeight();
1654          worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff);                  //
1655          try {                  // double scale = Math.min(xscale, yscale);
1656              screenToWorld = worldToScreen.createInverse();                  //
1657                    // double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
1658          } catch (NoninvertibleTransformException ex) {                  // double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
1659              ex.printStackTrace();  
1660          }                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1661      }                                  paintArea);
1662            
1663                            // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,
1664                    // yoff);
1665                    try {
1666                            screenToWorld = worldToScreen.createInverse();
1667    
1668                    } catch (NoninvertibleTransformException ex) {
1669                            ex.printStackTrace();
1670                    }
1671            }
1672    
1673          public void setBgContext(final MapContext context) {          public void setBgContext(final MapContext context) {
1674    
# Line 1776  public class XMapPane extends JPanel { Line 1761  public class XMapPane extends JPanel {
1761                          return false;                          return false;
1762                  }                  }
1763    
1764                    final Envelope candNew = bestAllowedMapArea(newMapArea);
1765    
1766                  // Testing, whether the difference if just minimal                  // Testing, whether the difference if just minimal
1767                  if (mapArea != null) {                  if (mapArea != null) {
                         final Envelope candNew = bestAllowedMapArea(newMapArea);  
1768                          final double tolX = mapArea.getWidth() / 1000.;                          final double tolX = mapArea.getWidth() / 1000.;
1769                          final double tolY = mapArea.getHeight() / 1000.;                          final double tolY = mapArea.getHeight() / 1000.;
1770                          if ((candNew.getMinX() - tolX < mapArea.getMinX())                          if ((candNew.getMinX() - tolX < mapArea.getMinX())
# Line 1798  public class XMapPane extends JPanel { Line 1784  public class XMapPane extends JPanel {
1784                          }                          }
1785                  }                  }
1786    
1787                    // New map are is accepted:
1788                  oldMapArea = mapArea;                  oldMapArea = mapArea;
1789                    mapArea = candNew;
1790                  this.mapArea = bestAllowedMapArea(newMapArea);                  resetTransforms();
1791    
1792                  if (localContext != null) {                  if (localContext != null) {
1793                          localContext.setAreaOfInterest(mapArea, localContext                          localContext.setAreaOfInterest(mapArea, localContext
# Line 1810  public class XMapPane extends JPanel { Line 1797  public class XMapPane extends JPanel {
1797                          bgContext.setAreaOfInterest(mapArea, localContext                          bgContext.setAreaOfInterest(mapArea, localContext
1798                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
1799                  }                  }
                 resetTransforms();  
1800                  mapImageInvalid = true;                  mapImageInvalid = true;
1801                  mapAreaChanged = true;                  mapAreaChanged = true;
1802                  repaint();                  repaint();
1803    
1804                  // LOGGER.debug("New maparea = " + mapArea);                  LOGGER.debug("New maparea = " + mapArea);
1805                  return true;                  return true;
1806          }          }
1807    
# Line 2035  public class XMapPane extends JPanel { Line 2021  public class XMapPane extends JPanel {
2021           *            {@link #getScreenToWorld()} is used.           *            {@link #getScreenToWorld()} is used.
2022           */           */
2023          public Envelope tranformGeoToWindow(final double ox, final double oy,          public Envelope tranformGeoToWindow(final double ox, final double oy,
2024                          final double px, final double py,                          final double px, final double py) {
2025                          final AffineTransform winToGeotransform) {                  final AffineTransform at = getWorldToScreenTransform();
                 final AffineTransform at = winToGeotransform == null ? getScreenToWorld()  
                                 : winToGeotransform;  
2026                  Point2D geoO;                  Point2D geoO;
2027                  try {                  // try {
2028                          geoO = at.inverseTransform(new Point2D.Double(ox, oy), null);                  geoO = at.transform(new Point2D.Double(ox, oy), null);
2029                          final Point2D geoP = at.inverseTransform(                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2030                                          new Point2D.Double(px, py), null);                  return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2031                          return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP                  // } catch (final NoninvertibleTransformException e) {
2032                                          .getY());                  // LOGGER.error(e);
2033                  } catch (final NoninvertibleTransformException e) {                  // return new Envelope(ox, oy, px, py);
2034                          LOGGER.error(e);                  // }
                         return new Envelope(ox, oy, px, py);  
                 }  
2035          }          }
2036    
2037          /**          /**
# Line 2069  public class XMapPane extends JPanel { Line 2051  public class XMapPane extends JPanel {
2051                  final AffineTransform at = getScreenToWorld();                  final AffineTransform at = getScreenToWorld();
2052                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
2053                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2054                  return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());                  
2055                    // Mmmmm... don't really understand why its x,x,y,y
2056    //              return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2057                    return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY()));
2058          }          }
2059    
2060          /**          /**
# Line 2189  public class XMapPane extends JPanel { Line 2174  public class XMapPane extends JPanel {
2174                                          - mapImage.getWidth() - 10, getBounds().height                                          - mapImage.getWidth() - 10, getBounds().height
2175                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
2176                  }                  }
2177                    
                   
2178                  int y = 17;                  int y = 17;
2179    
2180                  // If the rendering process is still running, indicate this is the image                  // If the rendering process is still running, indicate this is the image
2181                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2182                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
2183                            
2184                          y+=8;                          y += 8;
2185    
2186                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2187                          graphics.setFont(waitFont);                          graphics.setFont(waitFont);
 //                      String waitStr = "Wait..."; // i8n  
2188    
2189                          graphics.setColor(getMapBackgroundColor());                          graphics.setColor(getMapBackgroundColor());
2190                          graphics.drawString(waitMsg, 5, y);                          graphics.drawString(waitMsg, 5, y);
2191                          graphics.setColor(getMapBackgroundColor());                          graphics.setColor(getMapBackgroundColor());
2192                          graphics.drawString(waitMsg, 7, y+2);                          graphics.drawString(waitMsg, 7, y + 2);
2193                          graphics.setColor(Color.BLACK);                          graphics.setColor(Color.BLACK);
2194                          graphics.drawString(waitMsg, 6, y+1);                          graphics.drawString(waitMsg, 6, y + 1);
2195    
2196                          graphics.setColor(c);                          graphics.setColor(c);
2197                            
2198                          y += 24;                          y += 24;
2199                  }                  }
2200    
# Line 2367  public class XMapPane extends JPanel { Line 2350  public class XMapPane extends JPanel {
2350                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2351                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2352                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2353                    
2354                  // Move the newMapArea above the new center  // TODO we actually want that
2355                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter  //              // Move the newMapArea above the new center
2356                                  .getY()  //              newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2357                                  - mapArea.centre().y);  //                              .getY()
2358    //                              - mapArea.centre().y);
2359    
2360                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2361          }          }

Legend:
Removed from v.538  
changed lines
  Added in v.539

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26