/[schmitzm]/trunk/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/XMapPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java revision 530 by alfonx, Thu Nov 19 09:31:14 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java revision 540 by alfonx, Fri Nov 20 19:34:50 2009 UTC
# Line 1  Line 1 
1  package gtmig.org.geotools.swing;  package skrueger.geotools;
2    
3  import java.awt.Color;  import java.awt.Color;
4  import java.awt.Cursor;  import java.awt.Cursor;
# Line 21  import java.awt.geom.NoninvertibleTransf Line 21  import java.awt.geom.NoninvertibleTransf
21  import java.awt.geom.Point2D;  import java.awt.geom.Point2D;
22  import java.awt.image.BufferedImage;  import java.awt.image.BufferedImage;
23  import java.io.IOException;  import java.io.IOException;
24    import java.util.ArrayList;
25  import java.util.HashMap;  import java.util.HashMap;
26  import java.util.Map;  import java.util.Map;
27  import java.util.Vector;  import java.util.Vector;
# Line 29  import javax.swing.Timer; Line 30  import javax.swing.Timer;
30    
31  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
32  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
33    import org.geotools.geometry.Envelope2D;
34  import org.geotools.geometry.jts.JTS;  import org.geotools.geometry.jts.JTS;
35  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
36  import org.geotools.map.DefaultMapContext;  import org.geotools.map.DefaultMapContext;
# Line 42  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 57  import org.opengis.referencing.operation Line 60  import org.opengis.referencing.operation
60  import schmitzm.geotools.GTUtil;  import schmitzm.geotools.GTUtil;
61  import schmitzm.geotools.JTSUtil;  import schmitzm.geotools.JTSUtil;
62  import schmitzm.geotools.gui.SelectableXMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
63    import schmitzm.geotools.io.GeoImportUtil;
64  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
65  import schmitzm.geotools.map.event.MapLayerAdapter;  import schmitzm.geotools.map.event.MapLayerAdapter;
66  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
67  import schmitzm.swing.JPanel;  import schmitzm.swing.JPanel;
68  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
 import skrueger.geotools.RenderingExecutor;  
69    
70  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
71  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 144  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 184  public class XMapPane extends JPanel { Line 187  public class XMapPane extends JPanel {
187                          .getPredefinedCursor(Cursor.WAIT_CURSOR);                          .getPredefinedCursor(Cursor.WAIT_CURSOR);
188    
189          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
190            final String waitMsg = SwingUtil.R("WaitMess");
191            final static Font errorFont = new Font("Arial", Font.BOLD, 13);
192    
193          /**          /**
194           * Flag fuer Modus "Heran zoomen".           * Flag fuer Modus "Heran zoomen".
# Line 244  public class XMapPane extends JPanel { Line 249  public class XMapPane extends JPanel {
249    
250                  @Override                  @Override
251                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
252                          event.getLayer().addMapLayerListener(bgMapLayerListener);  
253                            MapLayer layer = event.getLayer();
254    
255                            layer.addMapLayerListener(bgMapLayerListener);
256    
257                          if (localContext.getLayers().length == 0                          if (localContext.getLayers().length == 0
258                                          && bgContext.getLayers().length == 1) { // the first one and                                          && bgContext.getLayers().length == 1) { // the first one and
# Line 379  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 453  public class XMapPane extends JPanel { Line 462  public class XMapPane extends JPanel {
462          };          };
463    
464          private final GTRenderer localRenderer = GTUtil.createGTRenderer();          private final GTRenderer localRenderer = GTUtil.createGTRenderer();
465            
466          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
467    
468          /**          /**
# Line 524  public class XMapPane extends JPanel { Line 533  public class XMapPane extends JPanel {
533          // if null, no quick preview will be shown          // if null, no quick preview will be shown
534          private int quickPreviewHint = 0;          private int quickPreviewHint = 0;
535    
536          private Map<Object, Object> rendererHints;          private Map<Object, Object> rendererHints = GTUtil
537                            .getDefaultGTRendererHints(localRenderer);
538    
539          private volatile Boolean requestStartRendering = false;          private volatile Boolean requestStartRendering = false;
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 565  public class XMapPane extends JPanel { Line 573  public class XMapPane extends JPanel {
573          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(          public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(
574                          this);                          this);
575    
576            /** Is set if a renderer has an error **/
577            protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
578    
579          // TODO doku          // TODO doku
580          public XMapPane() {          public XMapPane() {
581                  this(null, null);                  this(null, null);
# Line 592  public class XMapPane extends JPanel { Line 603  public class XMapPane extends JPanel {
603    
604                  setOpaque(true);                  setOpaque(true);
605    
                 localRenderer.setJava2DHints(getJava2dHints());  
   
606                  if (localContext_ != null)                  if (localContext_ != null)
607                          setLocalContext(localContext_);                          setLocalContext(localContext_);
608    
# Line 611  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 705  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 785  public class XMapPane extends JPanel { Line 794  public class XMapPane extends JPanel {
794    
795                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
796    
797                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
798                                                          false);                                                          false);
799                                  }                                  }
800                          }                          }
# Line 809  public class XMapPane extends JPanel { Line 818  public class XMapPane extends JPanel {
818    
819                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
820    
821                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
822                                                          false);                                                          false);
823                                  }                                  }
824                          }                          }
# Line 835  public class XMapPane extends JPanel { Line 844  public class XMapPane extends JPanel {
844    
845                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
846    
847                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
848                                                          false);                                                          false);
849                                  }                                  }
850                          }                          }
# Line 861  public class XMapPane extends JPanel { Line 870  public class XMapPane extends JPanel {
870    
871                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
872    
873                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
874                                                          false);                                                          false);
875                                  }                                  }
876                          }                          }
# Line 900  public class XMapPane extends JPanel { Line 909  public class XMapPane extends JPanel {
909                          localExecuter.cancelTask();                          localExecuter.cancelTask();
910                          while (i++ < 10 && localExecuter.isRunning()) {                          while (i++ < 10 && localExecuter.isRunning()) {
911                                  try {                                  try {
912                                          Thread.sleep(200);                                          Thread.sleep(100);
913                                  } catch (final InterruptedException e) {                                  } catch (final InterruptedException e) {
914                                          // TODO Auto-generated catch block                                          // TODO Auto-generated catch block
915                                          e.printStackTrace();                                          e.printStackTrace();
# Line 912  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 992  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 1010  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 1027  public class XMapPane extends JPanel { Line 1016  public class XMapPane extends JPanel {
1016    
1017                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea);
1018    
1019                  addGadgets(graphics);                  addGadgets(graphics, true);
1020    
1021                  quickPreviewHint = 0;                  quickPreviewHint = 0;
1022    
1023                    repaintTimer.restart();
1024    
1025                  graphics.dispose();                  graphics.dispose();
1026    
1027                  // Something has been drawn                  // Something has been drawn
# Line 1064  public class XMapPane extends JPanel { Line 1055  public class XMapPane extends JPanel {
1055                  //                  //
1056                  if (finalImage == null) {                  if (finalImage == null) {
1057                          // Rectangle curPaintArea = getVisibleRect();                          // Rectangle curPaintArea = getVisibleRect();
1058                          finalImage = new BufferedImage(getBounds().width,                          finalImage = new BufferedImage(getVisibleRect().width,
1059                                          getBounds().height, IMAGETYPE);                                          getVisibleRect().height, IMAGETYPE);
1060    
1061                          requestStartRendering();                          requestStartRendering();
1062                  }                  }
# Line 1082  public class XMapPane extends JPanel { Line 1073  public class XMapPane extends JPanel {
1073          private BufferedImage getLocalImage() {          private BufferedImage getLocalImage() {
1074    
1075                  if (localImage == null) {                  if (localImage == null) {
1076                          localImage = new BufferedImage(getBounds().width,                          localImage = new BufferedImage(getVisibleRect().width,
1077                                          getBounds().height, IMAGETYPE_withAlpha);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1078                  }                  }
1079    
1080                  return localImage;                  return localImage;
# Line 1094  public class XMapPane extends JPanel { Line 1085  public class XMapPane extends JPanel {
1085           *           *
1086           * @return           * @return
1087           */           */
1088          public Envelope getMapArea() {          public ReferencedEnvelope getMapArea() {
1089                  if (mapArea == null) {                  if (mapArea == null) {
1090                          ReferencedEnvelope mapArea_ = null;                          ReferencedEnvelope mapArea_ = null;
1091                          try {                          try {
# Line 1105  public class XMapPane extends JPanel { Line 1096  public class XMapPane extends JPanel {
1096    
1097                          if (mapArea_ != null) {                          if (mapArea_ != null) {
1098                                  mapImageInvalid = true; /* note we need to redraw */                                  mapImageInvalid = true; /* note we need to redraw */
1099  //                              setMapArea(mapArea_); // results in a loop                                  // setMapArea(mapArea_); // results in a loop
1100                                  mapArea = bestAllowedMapArea(mapArea_);                                  mapArea = bestAllowedMapArea(mapArea_);
1101                          }                          }
1102                  }                  }
# Line 1113  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                  return new Envelope(mapArea);                  // TODO is needed at all, this should go to setMapArea maybe
1108                    if (localContext.getCoordinateReferenceSystem() == null)
1109                            try {
1110                                    localContext.setCoordinateReferenceSystem(GeoImportUtil
1111                                                    .getDefaultCRS());
1112                            } catch (Exception e) {
1113                                    throw new RuntimeException("setting context CRS:", e);
1114                            }
1115    
1116                    return new ReferencedEnvelope(mapArea, localContext
1117                                    .getCoordinateReferenceSystem());
1118          }          }
1119    
1120          /**          /**
# Line 1154  public class XMapPane extends JPanel { Line 1155  public class XMapPane extends JPanel {
1155                          }                          }
1156    
1157                          // Kartenbereich um 10% vergroessern                          // Kartenbereich um 10% vergroessern
1158                          return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil                          return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1159                                          .expandEnvelope(layerBounds, 0.1), true);                                          .expandEnvelope(layerBounds, 0.1), true);
1160                  }                  }
1161                  return maxExtend;                  return maxExtend;
# Line 1197  public class XMapPane extends JPanel { Line 1198  public class XMapPane extends JPanel {
1198          }          }
1199    
1200          public Map<Object, Object> getRendererHints() {          public Map<Object, Object> getRendererHints() {
1201                    // Clear label cache
1202                    labelCache.clear();
1203                    rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
1204    
1205                  return rendererHints;                  return rendererHints;
1206          }          }
1207    
# Line 1377  public class XMapPane extends JPanel { Line 1382  public class XMapPane extends JPanel {
1382                  repaintTimer.stop();                  repaintTimer.stop();
1383                  updateFinalImage();                  updateFinalImage();
1384                  repaint();                  repaint();
1385                    if (renderingErrors.size() > 0)
1386                            renderingErrors.remove(0);
1387          }          }
1388    
1389          /**          /**
# Line 1390  public class XMapPane extends JPanel { Line 1397  public class XMapPane extends JPanel {
1397           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1398           */           */
1399          public void onRenderingFailed(final Exception renderingError) {          public void onRenderingFailed(final Exception renderingError) {
1400                    this.renderingErrors.add(renderingError);
1401                    if (renderingErrors.size() > 3)
1402                            renderingErrors.remove(0);
1403                  repaintTimer.stop();                  repaintTimer.stop();
1404                  LOGGER.warn("Rendering failed", renderingError);                  LOGGER.warn("Rendering failed", renderingError);
1405                  updateFinalImage();                  updateFinalImage();
# Line 1411  public class XMapPane extends JPanel { Line 1421  public class XMapPane extends JPanel {
1421                  // Maybe update the cursor and maybe stop the repainting timer                  // Maybe update the cursor and maybe stop the repainting timer
1422                  updateCursor();                  updateCursor();
1423    
1424                  super.paintComponent(g); // candidate for removal                  // super.paintComponent(g); // candidate for removal
1425    
1426                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1427    
# Line 1509  public class XMapPane extends JPanel { Line 1519  public class XMapPane extends JPanel {
1519           */           */
1520          public void performPan() {          public void performPan() {
1521    
1522                  final Rectangle winBounds = getBounds();                  Rectangle winBounds = getVisibleRect();
1523                    
1524                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1525                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1526                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y
# Line 1578  public class XMapPane extends JPanel { Line 1589  public class XMapPane extends JPanel {
1589    
1590          }          }
1591    
1592          /**          //
1593           * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten          // /**
1594           * neu.          // * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
1595           */          // * neu.
1596          protected void resetTransforms() {          // */
1597                  if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)          // protected void resetTransforms() {
1598                          return;          // if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
1599            // return;
1600            //
1601            // // We store the last Transform
1602            // oldScreenToWorld = screenToWorld;
1603            //
1604            // this.screenToWorld = new AffineTransform(
1605            // // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
1606            // // nach rechts (Osten) hin groesser
1607            // // --> positive Verschiebung
1608            // getMapArea().getWidth() / getWidth(),
1609            // // keine Verzerrung
1610            // 0.0, 0.0,
1611            // // Waehrend die Fenster-Koordinaten nach unten hin groesser
1612            // // werden,
1613            // // werden Latitude-Koordinaten nach Sueden hin keiner
1614            // // --> negative Verschiebung
1615            // -getMapArea().getHeight() / getHeight(),
1616            // // Die Longitude-Koordinaten werden nach Osten hin groesser
1617            // // --> obere linke Ecke des Fensters hat also den Minimalwert
1618            // getMapArea().getMinX(),
1619            // // Die Latitude-Koordinaten werden nach Norden hin groesser
1620            // // --> obere linke Ecke des Fensters hat also den Maximalwert
1621            // getMapArea().getMaxY());
1622            //
1623            // try {
1624            // this.worldToScreen = screenToWorld.createInverse();
1625            // } catch (final NoninvertibleTransformException e) {
1626            // LOGGER.error(e);
1627            // }
1628            // }
1629    
1630                  // We store the last Transform          /**
1631                  oldScreenToWorld = screenToWorld;           * Calculate the affine transforms used to convert between world and pixel
1632             * coordinates. The calculations here are very basic and assume a cartesian
1633             * reference system.
1634             * <p>
1635             * Tne transform is calculated such that {@code envelope} will be centred in
1636             * the display
1637             *
1638             * @param envelope
1639             *            the current map extent (world coordinates)
1640             * @param paintArea
1641             *            the current map pane extent (screen units)
1642             */
1643            private void resetTransforms() {
1644                    ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1645                                    getContext().getCoordinateReferenceSystem());
1646    
1647                    Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!
1648                    
1649                    //        
1650                    // double xscale = paintArea.getWidth() / refEnv.getWidth();
1651                    // double yscale = paintArea.getHeight() / refEnv.getHeight();
1652                    //
1653                    // double scale = Math.min(xscale, yscale);
1654                    //
1655                    // double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
1656                    // double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
1657    
1658                  this.screenToWorld = new AffineTransform(                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1659                  // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten                                  paintArea);
                                 // nach rechts (Osten) hin groesser  
                                 // --> positive Verschiebung  
                                 getMapArea().getWidth() / getWidth(),  
                                 // keine Verzerrung  
                                 0.0, 0.0,  
                                 // Waehrend die Fenster-Koordinaten nach unten hin groesser  
                                 // werden,  
                                 // werden Latitude-Koordinaten nach Sueden hin keiner  
                                 // --> negative Verschiebung  
                                 -getMapArea().getHeight() / getHeight(),  
                                 // Die Longitude-Koordinaten werden nach Osten hin groesser  
                                 // --> obere linke Ecke des Fensters hat also den Minimalwert  
                                 getMapArea().getMinX(),  
                                 // Die Latitude-Koordinaten werden nach Norden hin groesser  
                                 // --> obere linke Ecke des Fensters hat also den Maximalwert  
                                 getMapArea().getMaxY());  
1660    
1661                    // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,
1662                    // yoff);
1663                  try {                  try {
1664                          this.worldToScreen = screenToWorld.createInverse();                          screenToWorld = worldToScreen.createInverse();
1665                  } catch (final NoninvertibleTransformException e) {  
1666                          LOGGER.error(e);                  } catch (NoninvertibleTransformException ex) {
1667                            ex.printStackTrace();
1668                  }                  }
1669          }          }
1670    
# Line 1706  public class XMapPane extends JPanel { Line 1759  public class XMapPane extends JPanel {
1759                          return false;                          return false;
1760                  }                  }
1761    
1762                    final Envelope candNew = bestAllowedMapArea(newMapArea);
1763    
1764                  // Testing, whether the difference if just minimal                  // Testing, whether the difference if just minimal
1765                  if (mapArea != null) {                  if (mapArea != null) {
                         final Envelope candNew = bestAllowedMapArea(newMapArea);  
1766                          final double tolX = mapArea.getWidth() / 1000.;                          final double tolX = mapArea.getWidth() / 1000.;
1767                          final double tolY = mapArea.getHeight() / 1000.;                          final double tolY = mapArea.getHeight() / 1000.;
1768                          if ((candNew.getMinX() - tolX < mapArea.getMinX())                          if ((candNew.getMinX() - tolX < mapArea.getMinX())
# Line 1728  public class XMapPane extends JPanel { Line 1782  public class XMapPane extends JPanel {
1782                          }                          }
1783                  }                  }
1784    
1785                    // New map are is accepted:
1786                  oldMapArea = mapArea;                  oldMapArea = mapArea;
1787                    mapArea = candNew;
1788                  this.mapArea = bestAllowedMapArea(newMapArea);                  resetTransforms();
1789    
1790                  if (localContext != null) {                  if (localContext != null) {
1791                          localContext.setAreaOfInterest(mapArea, localContext                          localContext.setAreaOfInterest(mapArea, localContext
# Line 1740  public class XMapPane extends JPanel { Line 1795  public class XMapPane extends JPanel {
1795                          bgContext.setAreaOfInterest(mapArea, localContext                          bgContext.setAreaOfInterest(mapArea, localContext
1796                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
1797                  }                  }
                 resetTransforms();  
1798                  mapImageInvalid = true;                  mapImageInvalid = true;
1799                  mapAreaChanged = true;                  mapAreaChanged = true;
1800                  repaint();                  repaint();
1801    
1802                  // LOGGER.debug("New maparea = " + mapArea);                  LOGGER.debug("New maparea = " + mapArea);
1803                  return true;                  return true;
1804          }          }
1805    
# Line 1854  public class XMapPane extends JPanel { Line 1908  public class XMapPane extends JPanel {
1908          }          }
1909    
1910          private void setRendererHints(final Map<Object, Object> rendererHints) {          private void setRendererHints(final Map<Object, Object> rendererHints) {
1911                  this.rendererHints = rendererHints;                  if (rendererHints != null)
1912                            this.rendererHints = rendererHints;
1913          }          }
1914    
1915          /**          /**
# Line 1913  public class XMapPane extends JPanel { Line 1968  public class XMapPane extends JPanel {
1968                   */                   */
1969    
1970                  if (getBgContext() != null) {                  if (getBgContext() != null) {
1971                            bgRenderer.setJava2DHints(getJava2dHints());
1972                            bgRenderer.setRendererHints(getRendererHints());
1973    
1974                          // bgExecuter = new RenderingExecutor();                          // bgExecuter = new RenderingExecutor();
1975                          // LOGGER.debug("starting bg renderer:");                          // LOGGER.debug("starting bg renderer:");
1976                          // // /* System.out.println("rendering"); */                          // // /* System.out.println("rendering"); */
# Line 1928  public class XMapPane extends JPanel { Line 1986  public class XMapPane extends JPanel {
1986                          // localExecuter = new RenderingExecutor(this, 150l);                          // localExecuter = new RenderingExecutor(this, 150l);
1987                          // LOGGER.debug("starting local renderer:");                          // LOGGER.debug("starting local renderer:");
1988    
1989                          // Clear label cache                          localRenderer.setJava2DHints(getJava2dHints());
1990                          labelCache.clear();                          localRenderer.setRendererHints(getRendererHints());
1991                          final Map<Object, Object> rh = localRenderer.getRendererHints();  
1992                          rh.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);                          ReferencedEnvelope areaOfInterest = getMapArea();
1993                          localRenderer.setRendererHints(rh);                          final boolean submitted = localExecuter.submit(areaOfInterest,
1994                                            curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1995                          final boolean submitted = localExecuter.submit(getContext()                                          localRenderer, getWorldToScreenTransform());
                                         .getAreaOfInterest(), curPaintArea,  
                                         (Graphics2D) getLocalImage().getGraphics(), localRenderer,  
                                         getWorldToScreenTransform());  
1996                          if (submitted)                          if (submitted)
1997                                  repaintTimer.restart();                                  repaintTimer.restart();
1998                          else                          else
# Line 1964  public class XMapPane extends JPanel { Line 2019  public class XMapPane extends JPanel {
2019           *            {@link #getScreenToWorld()} is used.           *            {@link #getScreenToWorld()} is used.
2020           */           */
2021          public Envelope tranformGeoToWindow(final double ox, final double oy,          public Envelope tranformGeoToWindow(final double ox, final double oy,
2022                          final double px, final double py,                          final double px, final double py) {
2023                          final AffineTransform winToGeotransform) {                  final AffineTransform at = getWorldToScreenTransform();
                 final AffineTransform at = winToGeotransform == null ? getScreenToWorld()  
                                 : winToGeotransform;  
2024                  Point2D geoO;                  Point2D geoO;
2025                  try {                  // try {
2026                          geoO = at.inverseTransform(new Point2D.Double(ox, oy), null);                  geoO = at.transform(new Point2D.Double(ox, oy), null);
2027                          final Point2D geoP = at.inverseTransform(                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2028                                          new Point2D.Double(px, py), null);                  return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2029                          return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP                  // } catch (final NoninvertibleTransformException e) {
2030                                          .getY());                  // LOGGER.error(e);
2031                  } catch (final NoninvertibleTransformException e) {                  // return new Envelope(ox, oy, px, py);
2032                          LOGGER.error(e);                  // }
                         return new Envelope(ox, oy, px, py);  
                 }  
2033          }          }
2034    
2035          /**          /**
# Line 1998  public class XMapPane extends JPanel { Line 2049  public class XMapPane extends JPanel {
2049                  final AffineTransform at = getScreenToWorld();                  final AffineTransform at = getScreenToWorld();
2050                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
2051                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2052                  return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());                  
2053                    // Mmmmm... don't really understand why its x,x,y,y
2054    //              return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2055                    return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY()));
2056          }          }
2057    
2058          /**          /**
# Line 2016  public class XMapPane extends JPanel { Line 2070  public class XMapPane extends JPanel {
2070                  } else {                  } else {
2071                          // Allow one last rendering                          // Allow one last rendering
2072                          if (repaintTimer.isRunning()) {                          if (repaintTimer.isRunning()) {
2073                                    System.out.println("one last rendering....");
2074                                  repaintTimer.stop();                                  repaintTimer.stop();
2075                                  updateFinalImage();                                  updateFinalImage();
2076                                  repaint();                                  repaint();
# Line 2092  public class XMapPane extends JPanel { Line 2147  public class XMapPane extends JPanel {
2147                                  imageOrigin.y, finalImageWidth, finalImageHeight);                                  imageOrigin.y, finalImageWidth, finalImageHeight);
2148                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
2149    
2150                  addGadgets(finalG);                  addGadgets(finalG, false);
2151    
2152                  finalG.dispose();                  finalG.dispose();
2153    
# Line 2102  public class XMapPane extends JPanel { Line 2157  public class XMapPane extends JPanel {
2157          /**          /**
2158           * Paints some optional stuff into the given {@link Graphics2D}. Usually           * Paints some optional stuff into the given {@link Graphics2D}. Usually
2159           * called as the last layer when {@link #updateFinalImage()}           * called as the last layer when {@link #updateFinalImage()}
2160             *
2161             * @param forceWait
2162             *            if <code>true</code>, a Wait-message will be painted even
2163             *            though the rendering threads may not yet have started. If
2164             *            <code>false</code>, it will only depend on
2165             *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2166           */           */
2167          private void addGadgets(final Graphics2D graphics) {          private void addGadgets(final Graphics2D graphics, boolean forceWait) {
2168    
2169                  // Paint a logo to the bottom right if available                  // Paint a logo to the bottom right if available
2170                  if (mapImage != null) {                  if (mapImage != null) {
2171                          graphics.drawImage(mapImage, getBounds().width                          Rectangle visibleRect = getVisibleRect();
2172                                          - mapImage.getWidth() - 10, getBounds().height                          graphics.drawImage(mapImage, visibleRect.width
2173                                            - mapImage.getWidth() - 10, getVisibleRect().height
2174                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
2175                  }                  }
2176    
2177                    int y = 17;
2178    
2179                  // If the rendering process is still running, indicate this is the image                  // If the rendering process is still running, indicate this is the image
2180                  if (bgExecuter != null && bgExecuter.isRunning()                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2181                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
2182    
2183                            y += 8;
2184    
2185                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2186                          graphics.setFont(waitFont);                          graphics.setFont(waitFont);
2187                          String waitStr = "Wait..."; //i8n  
2188                                                    graphics.setColor(getMapBackgroundColor());
2189                          graphics.setColor(Color.WHITE);                          graphics.drawString(waitMsg, 5, y);
2190                          graphics.drawString(waitStr, 39, 69);                          graphics.setColor(getMapBackgroundColor());
2191                            graphics.drawString(waitMsg, 7, y + 2);
2192                          graphics.setColor(Color.BLACK);                          graphics.setColor(Color.BLACK);
2193                          graphics.drawString(waitStr, 40, 70);                          graphics.drawString(waitMsg, 6, y + 1);
2194    
2195                            graphics.setColor(c);
2196    
2197                            y += 24;
2198                    }
2199    
2200                    if (renderingErrors != null) {
2201    
2202                            final Color c = graphics.getColor();
2203                            graphics.setFont(errorFont);
2204    
2205                            for (Exception ex : renderingErrors) {
2206    
2207                                    if (ex instanceof java.lang.IllegalArgumentException
2208                                                    && ex.getMessage().equals(
2209                                                                    "Argument \"sourceCRS\" should not be null."))
2210                                            continue;
2211    
2212                                    String errStr = ex.getLocalizedMessage();
2213    
2214                                    graphics.setColor(Color.WHITE);
2215                                    graphics.drawString(errStr, 5, y);
2216                                    graphics.setColor(Color.RED);
2217                                    graphics.drawString(errStr, 6, y + 1);
2218    
2219                                    y += 19;
2220                            }
2221    
2222                          graphics.setColor(c);                          graphics.setColor(c);
2223                  }                  }
# Line 2131  public class XMapPane extends JPanel { Line 2225  public class XMapPane extends JPanel {
2225          }          }
2226    
2227          /**          /**
2228           * Sets the {@link #mapArea} to best possibly present the given features. If only one           * Sets the {@link #mapArea} to best possibly present the given features. If
2229           * single point is given, the window is moved over the point.           * only one single point is given, the window is moved over the point.
2230           *           *
2231           * @param features           * @param features
2232           *            if <code>null</code> or size==0, the function doesn nothing.           *            if <code>null</code> or size==0, the function doesn nothing.
# Line 2255  public class XMapPane extends JPanel { Line 2349  public class XMapPane extends JPanel {
2349                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2350                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2351                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2352                    
2353                  // Move the newMapArea above the new center  // TODO we actually want that
2354                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter  //              // Move the newMapArea above the new center
2355                                  .getY()  //              newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2356                                  - mapArea.centre().y);  //                              .getY()
2357    //                              - mapArea.centre().y);
2358    
2359                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2360          }          }

Legend:
Removed from v.530  
changed lines
  Added in v.540

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26