/[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 533 by alfonx, Thu Nov 19 17:27:01 2009 UTC revision 543 by alfonx, Sat Nov 21 15:21:41 2009 UTC
# Line 30  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 43  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 145  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 293  public class XMapPane extends JPanel { Line 295  public class XMapPane extends JPanel {
295          };          };
296    
297          /**          /**
298           * compass and icon are rendered into this image           * This {@link RenderingExecutor} manages the creation and cancellation of
299             * up to one {@link Thread} for rendering the {@link #localContext}.
300           */           */
301          // protected BufferedImage gadgetsImage;          private final RenderingExecutor localExecuter = new RenderingExecutor(this);
302    
303            /**
304             * This {@link RenderingExecutor} manages the creation and cancellation of
305             * up to one {@link Thread} for rendering the {@link #bgContext}.
306             */
307          protected RenderingExecutor bgExecuter;          protected RenderingExecutor bgExecuter;
308    
309          /**          /**
310           * The Renderer for the LocalLayers uses this Image. When set to null,           * The {@link #localRenderer} for the {@link #localContext} uses this
311           * please dispose this {@link Graphics2D}           * {@link Image}.
312           */           */
313          private BufferedImage localImage;          private BufferedImage localImage;
314    
         private BufferedImage finalImage;  
315          /**          /**
316           * If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background           * The {@link #bgRenderer} for the {@link #bgContext} uses this
317           * uses this Image. When set to null, please dispose the {@link Graphics2D}           * {@link Image}.
318           */           */
319          private BufferedImage bgImage;          private BufferedImage bgImage;
320            
321            /**
322             * This {@link Image} is a merge of the {@link #bgImage},
323             * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
324             * updated with {@link #updateFinalImage()} and used for painting in
325             * {@link #paintComponent(Graphics)}
326             */
327            private BufferedImage finalImage;
328    
329    
330          /**          /**
331           * Optionally a transparent image to paint over the map in the lower right           * Optionally a transparent image to paint over the map in the lower right
# Line 329  public class XMapPane extends JPanel { Line 344  public class XMapPane extends JPanel {
344    
345                  @Override                  @Override
346                  public void layerChanged(final MapLayerEvent event) {                  public void layerChanged(final MapLayerEvent event) {
                         // Change of SLD for example  
                         // mapImageInvalid = true;  
                         // repaint();  
347                          requestStartRendering();                          requestStartRendering();
348                  }                  }
349    
350                  @Override                  @Override
351                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
352                          requestStartRendering();                          requestStartRendering();
353                  }                  }
354    
355                  @Override                  @Override
356                  public void layerShown(final MapLayerEvent event) {                  public void layerShown(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
357                          requestStartRendering();                          requestStartRendering();
358                  }                  }
359          };          };
# Line 385  public class XMapPane extends JPanel { Line 393  public class XMapPane extends JPanel {
393                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
394    
395                          if (localContext.getLayers().length == 1) { // the first one                          if (localContext.getLayers().length == 1) { // the first one
396    
397                                  // if the Area of Interest is unset, the LayerBounds are used                                  // if the Area of Interest is unset, the LayerBounds are used
398                                  if (!setMapArea(localContext.getAreaOfInterest()))                                  if (!setMapArea(localContext.getAreaOfInterest()))
399                                          repaint();                                          repaint();
# Line 426  public class XMapPane extends JPanel { Line 435  public class XMapPane extends JPanel {
435                  }                  }
436          };          };
437    
         private final RenderingExecutor localExecuter = new RenderingExecutor(this);  
   
438          /**          /**
439           * Listens to each layer in the local {@link MapContext} for changes and           * Listens to each layer in the local {@link MapContext} for changes and
440           * triggers repaints.           * triggers repaints.
# Line 533  public class XMapPane extends JPanel { Line 540  public class XMapPane extends JPanel {
540          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
541                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(localRenderer);
542    
543          private volatile Boolean requestStartRendering = false;          /** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #localImage} **/
544            private volatile Boolean requestStartRenderingLocal = false;
545            
546            /** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #bgImage} **/
547            private volatile Boolean requestStartRenderingBg = false;
548    
549          private final Timer resizeTimer;          private final Timer resizeTimer;
550    
         private final int resizingPaintDelay;  
   
551          /**          /**
552           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
553           * (lat/lon)           * (lat/lon)
# Line 546  public class XMapPane extends JPanel { Line 555  public class XMapPane extends JPanel {
555          protected AffineTransform screenToWorld = null;          protected AffineTransform screenToWorld = null;
556    
557          /**          /**
558           * The flag {@link #requestStartRendering} can be set to true by events.           * The flag {@link #requestStartRenderingLocal} can be set to true by events.
559           * This {@link Timer} checks the flag regularly and starts one renderer           * This {@link Timer} checks the flag regularly and starts one renderer
560           * thread.           * thread.
561           */           */
# Line 575  public class XMapPane extends JPanel { Line 584  public class XMapPane extends JPanel {
584          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
585          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
586    
         // TODO doku  
587          public XMapPane() {          public XMapPane() {
588                  this(null, null);                  this(null, null);
589          }          }
# Line 584  public class XMapPane extends JPanel { Line 592  public class XMapPane extends JPanel {
592           * full constructor extending JPanel           * full constructor extending JPanel
593           *           *
594           * @param rendererHints           * @param rendererHints
595             *            may be <code>null</code>. Otherwise a {@link Map<Object,
596             *            Object>} of {@link RenderingHints} to override the default
597             *            from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)}
598           *           *
          * @param layout  
          *            - layout (probably shouldn't be set)  
          * @param isDoubleBuffered  
          *            - a Swing thing I don't really understand  
          * @param render  
          *            - what to draw the map with  
599           * @param localContext           * @param localContext
600           *            - {@link MapContext} of layer to render.           *            The main {@link MapContext} to use. If <code>null</code>, an
601             *            empty {@link DefaultMapContext} will be created.
602           */           */
603          public XMapPane(final MapContext localContext_,          public XMapPane(final MapContext localContext_,
604                          final Map<Object, Object> rendererHints) {                          final Map<Object, Object> rendererHints) {
# Line 619  public class XMapPane extends JPanel { Line 625  public class XMapPane extends JPanel {
625                   * Using a ComponentListener doesn't work because, unlike a JFrame, the                   * Using a ComponentListener doesn't work because, unlike a JFrame, the
626                   * pane receives a stream of events during drag-resizing.                   * pane receives a stream of events during drag-resizing.
627                   */                   */
628                  resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY;                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
629                  resizeTimer = new Timer(resizingPaintDelay, new ActionListener() {                                  new ActionListener() {
630    
631                          public void actionPerformed(final ActionEvent e) {                                          public void actionPerformed(final ActionEvent e) {
632                                  paneResized = true;                                                  paneResized = true;
633    
634                                  if (!isWellDefined())                                                  if (!isWellDefined())
635                                          return;                                                          return;
636    
637                                  final Rectangle bounds = getVisibleRect();                                                  final Rectangle bounds = getVisibleRect();
638    
639                                  final Envelope geoMapArea = tranformWindowToGeo(bounds.x,                                                  final Envelope geoMapArea = tranformWindowToGeo(
640                                                  bounds.y, bounds.x + bounds.width, bounds.y                                                                  bounds.x, bounds.y, bounds.x + bounds.width,
641                                                                  + bounds.height);                                                                  bounds.y + bounds.height);
642    
643                                  setMapArea(bestAllowedMapArea(geoMapArea));                                                  setMapArea(bestAllowedMapArea(geoMapArea));
644                          }                                          }
645                  });                                  });
646                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
647                  this.addComponentListener(new ComponentAdapter() {                  
648    //              this.addComponentListener(new ComponentAdapter() {
649                          @Override  //
650                          public void componentResized(final ComponentEvent e) {  //                      @Override
651                                  if (bgExecuter != null)  //                      public void componentResized(final ComponentEvent e) {
652                                          bgExecuter.cancelTask();  //                              if (bgExecuter != null)
653                                  if (localExecuter != null)  //                                      bgExecuter.cancelTask();
654                                          localExecuter.cancelTask();  //                              if (localExecuter != null)
655                                  resizeTimer.restart();  //                                      localExecuter.cancelTask();
656                          }  //                              resizeTimer.restart();
657    //                      }
658                  });  //
659    //              });
660    
661                  /*                  /*
662                   * Setting up the repaintTimer. Not started automatically.                   * Setting up the repaintTimer. Not started automatically.
# Line 674  public class XMapPane extends JPanel { Line 681  public class XMapPane extends JPanel {
681    
682                          @Override                          @Override
683                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
684                                  synchronized (requestStartRendering) {                                  synchronized (requestStartRenderingLocal) {
685                                          if (requestStartRendering && isWellDefined()) {                                          if (requestStartRenderingLocal && isWellDefined()) {
686    
687                                                  if (localExecuter.isRunning()) {                                                  if (localExecuter.isRunning()) {
688                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
689                                                  } else {                                                  } else {
690                                                          requestStartRendering = false;                                                          requestStartRenderingLocal = false;
691                                                          startRendering();                                                          startRendering();
692                                                  }                                                  }
693                                          }                                          }
# Line 713  public class XMapPane extends JPanel { Line 720  public class XMapPane extends JPanel {
720           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
721           */           */
722          public Envelope bestAllowedMapArea(Envelope env) {          public Envelope bestAllowedMapArea(Envelope env) {
723                    // return env;
724                  if (getWidth() == 0)                  if (getWidth() == 0)
725                          return env;                          return env;
726                  if (env == null)                  if (env == null)
# Line 793  public class XMapPane extends JPanel { Line 801  public class XMapPane extends JPanel {
801    
802                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
803    
804                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
805                                                          false);                                                          false);
806                                  }                                  }
807                          }                          }
# Line 817  public class XMapPane extends JPanel { Line 825  public class XMapPane extends JPanel {
825    
826                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
827    
828                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
829                                                          false);                                                          false);
830                                  }                                  }
831                          }                          }
# Line 843  public class XMapPane extends JPanel { Line 851  public class XMapPane extends JPanel {
851    
852                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
853    
854                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
855                                                          false);                                                          false);
856                                  }                                  }
857                          }                          }
# Line 869  public class XMapPane extends JPanel { Line 877  public class XMapPane extends JPanel {
877    
878                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
879    
880                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
881                                                          false);                                                          false);
882                                  }                                  }
883                          }                          }
# Line 908  public class XMapPane extends JPanel { Line 916  public class XMapPane extends JPanel {
916                          localExecuter.cancelTask();                          localExecuter.cancelTask();
917                          while (i++ < 10 && localExecuter.isRunning()) {                          while (i++ < 10 && localExecuter.isRunning()) {
918                                  try {                                  try {
919                                          Thread.sleep(100);                                          Thread.sleep(200);
920                                  } catch (final InterruptedException e) {                                  } catch (final InterruptedException e) {
921                                          // TODO Auto-generated catch block                                          LOGGER
922                                          e.printStackTrace();                                                          .warn(
923                                                                            "while XMapPane we are waiting for the localExcutor to stop",
924                                                                            e);
925                                  }                                  }
926                          }                          }
927                          if (localExecuter.isRunning()) {                          if (localExecuter.isRunning()) {
928                                  System.out                                  LOGGER
929                                                  .println("BAD BAD BAD... still running the thread....");                                                  .warn("localExecutor Thread still running after 2s! Continuing anyways...");
930                          }                          }
931                          localExecuter.dispose();                          localExecuter.dispose();
932                  }                  }
                 //  
                 // 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;  
                 // }  
                 disposeImages();  
933    
934                  // LangUtil.gcTotal();                  disposeImages();
935    
936                  // Alle mapPaneListener entfernen                  // Remove all mapPaneListeners that have registered with us
937                  mapPaneListeners.clear();                  mapPaneListeners.clear();
938    
939                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(zoomMapPaneMouseListener);
# Line 1000  public class XMapPane extends JPanel { Line 986  public class XMapPane extends JPanel {
986           */           */
987          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
988    
989                    // if (1 == 1)return false;
990    
991                  if (quickPreviewHint == 0)                  if (quickPreviewHint == 0)
992                          return false;                          return false;
993    
# Line 1018  public class XMapPane extends JPanel { Line 1006  public class XMapPane extends JPanel {
1006                  // Calculate the oldMapArea in the current WindowCoordinates:                  // Calculate the oldMapArea in the current WindowCoordinates:
1007                  final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),                  final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),
1008                                  oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea                                  oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea
1009                                                  .getMaxY(), null);                                                  .getMaxY());
1010    
1011                  final int xx1 = (int) Math.round(oldMapWindow.getMinX());                  final int xx1 = (int) Math.round(oldMapWindow.getMinX());
1012                  final int yy1 = (int) Math.round(oldMapWindow.getMinY());                  final int yy1 = (int) Math.round(oldMapWindow.getMinY());
# Line 1074  public class XMapPane extends JPanel { Line 1062  public class XMapPane extends JPanel {
1062                  //                  //
1063                  if (finalImage == null) {                  if (finalImage == null) {
1064                          // Rectangle curPaintArea = getVisibleRect();                          // Rectangle curPaintArea = getVisibleRect();
1065                          finalImage = new BufferedImage(getBounds().width,                          finalImage = new BufferedImage(getVisibleRect().width,
1066                                          getBounds().height, IMAGETYPE);                                          getVisibleRect().height, IMAGETYPE);
1067    
1068                          requestStartRendering();                          requestStartRendering();
1069                  }                  }
# Line 1092  public class XMapPane extends JPanel { Line 1080  public class XMapPane extends JPanel {
1080          private BufferedImage getLocalImage() {          private BufferedImage getLocalImage() {
1081    
1082                  if (localImage == null) {                  if (localImage == null) {
1083                          localImage = new BufferedImage(getBounds().width,                          localImage = new BufferedImage(getVisibleRect().width,
1084                                          getBounds().height, IMAGETYPE_withAlpha);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1085                  }                  }
1086    
1087                  return localImage;                  return localImage;
# Line 1123  public class XMapPane extends JPanel { Line 1111  public class XMapPane extends JPanel {
1111                  if (mapArea == null)                  if (mapArea == null)
1112                          return null;                          return null;
1113    
1114                    // TODO is needed at all, this should go to setMapArea maybe
1115                  if (localContext.getCoordinateReferenceSystem() == null)                  if (localContext.getCoordinateReferenceSystem() == null)
1116                          try {                          try {
1117                                  localContext.setCoordinateReferenceSystem(GeoImportUtil                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1118                                                  .getDefaultCRS());                                                  .getDefaultCRS());
1119                          } catch (TransformException e) {                          } catch (Exception e) {
1120                                  // TODO Auto-generated catch block                                  throw new RuntimeException("setting context CRS:", e);
                                 e.printStackTrace();  
                         } catch (FactoryException e) {  
                                 // TODO Auto-generated catch block  
                                 e.printStackTrace();  
1121                          }                          }
1122    
1123                  return new ReferencedEnvelope(mapArea, localContext                  return new ReferencedEnvelope(mapArea, localContext
# Line 1177  public class XMapPane extends JPanel { Line 1162  public class XMapPane extends JPanel {
1162                          }                          }
1163    
1164                          // Kartenbereich um 10% vergroessern                          // Kartenbereich um 10% vergroessern
1165                          return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil                          return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1166                                          .expandEnvelope(layerBounds, 0.1), true);                                          .expandEnvelope(layerBounds, 0.1), true);
1167                  }                  }
1168                  return maxExtend;                  return maxExtend;
# Line 1541  public class XMapPane extends JPanel { Line 1526  public class XMapPane extends JPanel {
1526           */           */
1527          public void performPan() {          public void performPan() {
1528    
1529                  final Rectangle winBounds = getBounds();                  Rectangle winBounds = getVisibleRect();
1530    
1531                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1532                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1533                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y
# Line 1606  public class XMapPane extends JPanel { Line 1592  public class XMapPane extends JPanel {
1592                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1593                  if (localExecuter != null)                  if (localExecuter != null)
1594                          localExecuter.cancelTask();                          localExecuter.cancelTask();
1595                  requestStartRendering = true;                  requestStartRenderingLocal = true;
1596    
1597          }          }
1598    
1599          /**          //
1600           * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten          // /**
1601           * neu.          // * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
1602           */          // * neu.
1603          protected void resetTransforms() {          // */
1604                  if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)          // protected void resetTransforms() {
1605                          return;          // if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
1606            // return;
1607            //
1608            // // We store the last Transform
1609            // oldScreenToWorld = screenToWorld;
1610            //
1611            // this.screenToWorld = new AffineTransform(
1612            // // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
1613            // // nach rechts (Osten) hin groesser
1614            // // --> positive Verschiebung
1615            // getMapArea().getWidth() / getWidth(),
1616            // // keine Verzerrung
1617            // 0.0, 0.0,
1618            // // Waehrend die Fenster-Koordinaten nach unten hin groesser
1619            // // werden,
1620            // // werden Latitude-Koordinaten nach Sueden hin keiner
1621            // // --> negative Verschiebung
1622            // -getMapArea().getHeight() / getHeight(),
1623            // // Die Longitude-Koordinaten werden nach Osten hin groesser
1624            // // --> obere linke Ecke des Fensters hat also den Minimalwert
1625            // getMapArea().getMinX(),
1626            // // Die Latitude-Koordinaten werden nach Norden hin groesser
1627            // // --> obere linke Ecke des Fensters hat also den Maximalwert
1628            // getMapArea().getMaxY());
1629            //
1630            // try {
1631            // this.worldToScreen = screenToWorld.createInverse();
1632            // } catch (final NoninvertibleTransformException e) {
1633            // LOGGER.error(e);
1634            // }
1635            // }
1636    
1637                  // We store the last Transform          /**
1638                  oldScreenToWorld = screenToWorld;           * Calculate the affine transforms used to convert between world and pixel
1639             * coordinates. The calculations here are very basic and assume a cartesian
1640             * reference system.
1641             * <p>
1642             * Tne transform is calculated such that {@code envelope} will be centred in
1643             * the display
1644             *
1645             * @param envelope
1646             *            the current map extent (world coordinates)
1647             * @param paintArea
1648             *            the current map pane extent (screen units)
1649             */
1650            private void resetTransforms() {
1651                    ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1652                                    getContext().getCoordinateReferenceSystem());
1653    
1654                    Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!
1655    
1656                    //        
1657                    // double xscale = paintArea.getWidth() / refEnv.getWidth();
1658                    // double yscale = paintArea.getHeight() / refEnv.getHeight();
1659                    //
1660                    // double scale = Math.min(xscale, yscale);
1661                    //
1662                    // double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
1663                    // double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
1664    
1665                  this.screenToWorld = new AffineTransform(                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1666                  // 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());  
1667    
1668                    // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,
1669                    // yoff);
1670                  try {                  try {
1671                          this.worldToScreen = screenToWorld.createInverse();                          screenToWorld = worldToScreen.createInverse();
1672                  } catch (final NoninvertibleTransformException e) {  
1673                          LOGGER.error(e);                  } catch (NoninvertibleTransformException ex) {
1674                            ex.printStackTrace();
1675                  }                  }
1676          }          }
1677    
# Line 1738  public class XMapPane extends JPanel { Line 1766  public class XMapPane extends JPanel {
1766                          return false;                          return false;
1767                  }                  }
1768    
1769                    final Envelope candNew = bestAllowedMapArea(newMapArea);
1770    
1771                  // Testing, whether the difference if just minimal                  // Testing, whether the difference if just minimal
1772                  if (mapArea != null) {                  if (mapArea != null) {
                         final Envelope candNew = bestAllowedMapArea(newMapArea);  
1773                          final double tolX = mapArea.getWidth() / 1000.;                          final double tolX = mapArea.getWidth() / 1000.;
1774                          final double tolY = mapArea.getHeight() / 1000.;                          final double tolY = mapArea.getHeight() / 1000.;
1775                          if ((candNew.getMinX() - tolX < mapArea.getMinX())                          if ((candNew.getMinX() - tolX < mapArea.getMinX())
# Line 1760  public class XMapPane extends JPanel { Line 1789  public class XMapPane extends JPanel {
1789                          }                          }
1790                  }                  }
1791    
1792                    // New map are is accepted:
1793                  oldMapArea = mapArea;                  oldMapArea = mapArea;
1794                    mapArea = candNew;
1795                  this.mapArea = bestAllowedMapArea(newMapArea);                  resetTransforms();
1796    
1797                  if (localContext != null) {                  if (localContext != null) {
1798                          localContext.setAreaOfInterest(mapArea, localContext                          localContext.setAreaOfInterest(mapArea, localContext
# Line 1772  public class XMapPane extends JPanel { Line 1802  public class XMapPane extends JPanel {
1802                          bgContext.setAreaOfInterest(mapArea, localContext                          bgContext.setAreaOfInterest(mapArea, localContext
1803                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
1804                  }                  }
                 resetTransforms();  
1805                  mapImageInvalid = true;                  mapImageInvalid = true;
1806                  mapAreaChanged = true;                  mapAreaChanged = true;
1807                  repaint();                  repaint();
1808    
1809                  // LOGGER.debug("New maparea = " + mapArea);                  LOGGER.debug("New maparea = " + mapArea);
1810                  return true;                  return true;
1811          }          }
1812    
# Line 1974  public class XMapPane extends JPanel { Line 2003  public class XMapPane extends JPanel {
2003                          if (submitted)                          if (submitted)
2004                                  repaintTimer.restart();                                  repaintTimer.restart();
2005                          else                          else
2006                                  requestStartRendering = true; // Try to start rendering again in                                  requestStartRenderingLocal = true; // Try to start rendering again in
2007                          // a moment                          // a moment
2008                  }                  }
2009    
# Line 1997  public class XMapPane extends JPanel { Line 2026  public class XMapPane extends JPanel {
2026           *            {@link #getScreenToWorld()} is used.           *            {@link #getScreenToWorld()} is used.
2027           */           */
2028          public Envelope tranformGeoToWindow(final double ox, final double oy,          public Envelope tranformGeoToWindow(final double ox, final double oy,
2029                          final double px, final double py,                          final double px, final double py) {
2030                          final AffineTransform winToGeotransform) {                  final AffineTransform at = getWorldToScreenTransform();
                 final AffineTransform at = winToGeotransform == null ? getScreenToWorld()  
                                 : winToGeotransform;  
2031                  Point2D geoO;                  Point2D geoO;
2032                  try {                  // try {
2033                          geoO = at.inverseTransform(new Point2D.Double(ox, oy), null);                  geoO = at.transform(new Point2D.Double(ox, oy), null);
2034                          final Point2D geoP = at.inverseTransform(                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2035                                          new Point2D.Double(px, py), null);                  return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2036                          return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP                  // } catch (final NoninvertibleTransformException e) {
2037                                          .getY());                  // LOGGER.error(e);
2038                  } catch (final NoninvertibleTransformException e) {                  // return new Envelope(ox, oy, px, py);
2039                          LOGGER.error(e);                  // }
                         return new Envelope(ox, oy, px, py);  
                 }  
2040          }          }
2041    
2042          /**          /**
# Line 2031  public class XMapPane extends JPanel { Line 2056  public class XMapPane extends JPanel {
2056                  final AffineTransform at = getScreenToWorld();                  final AffineTransform at = getScreenToWorld();
2057                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
2058                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2059                  return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());  
2060                    // Mmmmm... don't really understand why its x,x,y,y
2061                    // return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(),
2062                    // geoP.getY());
2063                    return new Envelope(new Coordinate(geoO.getX(), geoO.getY()),
2064                                    new Coordinate(geoP.getX(), geoP.getY()));
2065          }          }
2066    
2067          /**          /**
# Line 2147  public class XMapPane extends JPanel { Line 2177  public class XMapPane extends JPanel {
2177    
2178                  // Paint a logo to the bottom right if available                  // Paint a logo to the bottom right if available
2179                  if (mapImage != null) {                  if (mapImage != null) {
2180                          graphics.drawImage(mapImage, getBounds().width                          Rectangle visibleRect = getVisibleRect();
2181                                          - mapImage.getWidth() - 10, getBounds().height                          graphics.drawImage(mapImage, visibleRect.width
2182                                            - mapImage.getWidth() - 10, getVisibleRect().height
2183                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
2184                  }                  }
2185                    
                   
2186                  int y = 17;                  int y = 17;
2187    
2188                  // If the rendering process is still running, indicate this is the image                  // If the rendering process is still running, indicate this is the image
2189                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2190                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
2191                            
2192                          y+=8;                          y += 8;
2193    
2194                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2195                          graphics.setFont(waitFont);                          graphics.setFont(waitFont);
 //                      String waitStr = "Wait..."; // i8n  
2196    
2197                          graphics.setColor(getMapBackgroundColor());                          graphics.setColor(getMapBackgroundColor());
2198                          graphics.drawString(waitMsg, 5, y);                          graphics.drawString(waitMsg, 5, y);
2199                          graphics.setColor(getMapBackgroundColor());                          graphics.setColor(getMapBackgroundColor());
2200                          graphics.drawString(waitMsg, 7, y+2);                          graphics.drawString(waitMsg, 7, y + 2);
2201                          graphics.setColor(Color.BLACK);                          graphics.setColor(Color.BLACK);
2202                          graphics.drawString(waitMsg, 6, y+1);                          graphics.drawString(waitMsg, 6, y + 1);
2203    
2204                          graphics.setColor(c);                          graphics.setColor(c);
2205                            
2206                          y += 24;                          y += 24;
2207                  }                  }
2208    
# Line 2330  public class XMapPane extends JPanel { Line 2359  public class XMapPane extends JPanel {
2359                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2360                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2361    
2362                  // Move the newMapArea above the new center                  // TODO we actually want that
2363                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                  // // Move the newMapArea above the new center
2364                                  .getY()                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2365                                  - mapArea.centre().y);                  // .getY()
2366                    // - mapArea.centre().y);
2367    
2368                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2369          }          }

Legend:
Removed from v.533  
changed lines
  Added in v.543

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26