/[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 540 by alfonx, Fri Nov 20 19:34:50 2009 UTC revision 544 by alfonx, Sat Nov 21 17:13:31 2009 UTC
# Line 125  public class XMapPane extends JPanel { Line 125  public class XMapPane extends JPanel {
125           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
126           * renderers have finished.           * renderers have finished.
127           *           *
128           * @see #INITIAL_REPAINT_DELAYAL           * @see INITIAL_REPAINT_DELAYAL
129           * @see #REPEATING_REPAINT_DELAY           * @see #REPEATING_REPAINT_DELAY
130           */           */
131          final private Timer repaintTimer;          final private Timer repaintTimer;
# Line 141  public class XMapPane extends JPanel { Line 141  public class XMapPane extends JPanel {
141           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
142           * with previews.           * with previews.
143           */           */
144          public static final long REPEATING_REPAINT_DELAY = 500;          public static final int REPEATING_REPAINT_DELAY = 500;
145    
146          /**          /**
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             * @see #resizeTimer
151           */           */
152          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
153    
154            private final Timer resizeTimer;
155    
156          public static final int NONE = -123;          public static final int NONE = -123;
157    
158          /**          /**
# Line 186  public class XMapPane extends JPanel { Line 190  public class XMapPane extends JPanel {
190          public static final Cursor WAIT_CURSOR = Cursor          public static final Cursor WAIT_CURSOR = Cursor
191                          .getPredefinedCursor(Cursor.WAIT_CURSOR);                          .getPredefinedCursor(Cursor.WAIT_CURSOR);
192    
193            /**
194             * {@link Font} used to paint the wait messages into the map
195             *
196             * @see #addGadgets(Graphics2D, boolean)
197             */
198          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
199          final String waitMsg = SwingUtil.R("WaitMess");  
200            /**
201             * {@link Font} used to paint error messages into the map
202             *
203             * @see #addGadgets(Graphics2D, boolean)
204             */
205          final static Font errorFont = new Font("Arial", Font.BOLD, 13);          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
206    
207          /**          /**
208             * The wait message painted into the map while rendering is going on on
209             * another thread.
210             *
211             * @see #addGadgets(Graphics2D, boolean)
212             */
213            final String waitMsg = SwingUtil.R("WaitMess");
214    
215            /**
216           * Flag fuer Modus "Heran zoomen".           * Flag fuer Modus "Heran zoomen".
217           *           *
218           * @see #setState(int)           * @see #setState(int)
# Line 249  public class XMapPane extends JPanel { Line 271  public class XMapPane extends JPanel {
271    
272                  @Override                  @Override
273                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
   
274                          MapLayer layer = event.getLayer();                          MapLayer layer = event.getLayer();
   
275                          layer.addMapLayerListener(bgMapLayerListener);                          layer.addMapLayerListener(bgMapLayerListener);
   
                         if (localContext.getLayers().length == 0  
                                         && bgContext.getLayers().length == 1) { // the first one and  
                                 // localContext is  
                                 // empty  
                                 if (!setMapArea(localContext.getAreaOfInterest()))  
                                         requestStartRendering();  
                                 return;  
                         }  
   
                         // We need to redraw, even in case that the mapArea didn't change  
                         // mapImageInvalid = true;  
                         // repaint();  
276                          requestStartRendering();                          requestStartRendering();
277    
278                  }                  }
279    
280                  @Override                  @Override
281                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
282                          requestStartRendering();                          requestStartRendering();
283                  }                  }
284    
285                  @Override                  @Override
286                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
287                          requestStartRendering();                          requestStartRendering();
288                  }                  }
289    
# Line 288  public class XMapPane extends JPanel { Line 291  public class XMapPane extends JPanel {
291                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
292                          if (event.getLayer() != null)                          if (event.getLayer() != null)
293                                  event.getLayer().removeMapLayerListener(bgMapLayerListener);                                  event.getLayer().removeMapLayerListener(bgMapLayerListener);
                         // mapImageInvalid = true;  
                         // repaint();  
294                          requestStartRendering();                          requestStartRendering();
295                  }                  }
296          };          };
297    
298          /**          /**
299           * compass and icon are rendered into this image           * This {@link RenderingExecutor} manages the creation and cancellation of
300             * up to one {@link Thread} for rendering the {@link #localContext}.
301           */           */
302          // protected BufferedImage gadgetsImage;          private final RenderingExecutor localExecuter = new RenderingExecutor(this);
303    
304            /**
305             * This {@link RenderingExecutor} manages the creation and cancellation of
306             * up to one {@link Thread} for rendering the {@link #bgContext}.
307             */
308          protected RenderingExecutor bgExecuter;          protected RenderingExecutor bgExecuter;
309    
310          /**          /**
311           * The Renderer for the LocalLayers uses this Image. When set to null,           * The {@link #localRenderer} for the {@link #localContext} uses this
312           * please dispose this {@link Graphics2D}           * {@link Image}.
313           */           */
314          private BufferedImage localImage;          private BufferedImage localImage;
315    
         private BufferedImage finalImage;  
316          /**          /**
317           * If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background           * The {@link #bgRenderer} for the {@link #bgContext} uses this
318           * uses this Image. When set to null, please dispose the {@link Graphics2D}           * {@link Image}.
319           */           */
320          private BufferedImage bgImage;          private BufferedImage bgImage;
321    
322          /**          /**
323             * This {@link Image} is a merge of the {@link #bgImage},
324             * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
325             * updated with {@link #updateFinalImage()} and used for painting in
326             * {@link #paintComponent(Graphics)}
327             */
328            private BufferedImage finalImage;
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
332           * corner.           * corner.
333           *           *
# Line 331  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 391  public class XMapPane extends JPanel {
391                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
392    
393                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
   
                         if (localContext.getLayers().length == 1) { // the first one  
   
                                 // if the Area of Interest is unset, the LayerBounds are used  
                                 if (!setMapArea(localContext.getAreaOfInterest()))  
                                         repaint();  
   
                                 return;  
                         }  
   
                         // We need to redraw, even in case that the mapArea didn't change  
                         // mapImageInvalid = true;  
                         // repaint();  
394                          requestStartRendering();                          requestStartRendering();
395    
396                  }                  }
397    
398                  @Override                  @Override
399                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
400                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
401                          requestStartRendering();                          requestStartRendering();
402                  }                  }
403    
404                  @Override                  @Override
405                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
406                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
407                          requestStartRendering();                          requestStartRendering();
408                  }                  }
# Line 422  public class XMapPane extends JPanel { Line 411  public class XMapPane extends JPanel {
411                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
412                          if (event.getLayer() != null)                          if (event.getLayer() != null)
413                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
                         // mapImageInvalid = true;  
                         // repaint();  
414                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
415                          requestStartRendering();                          requestStartRendering();
416                  }                  }
417          };          };
418    
         private final RenderingExecutor localExecuter = new RenderingExecutor(this);  
   
419          /**          /**
420           * Listens to each layer in the local {@link MapContext} for changes and           * Listens to each layer in the local {@link MapContext} for changes and
421           * triggers repaints.           * triggers repaints.
# Line 440  public class XMapPane extends JPanel { Line 425  public class XMapPane extends JPanel {
425                  @Override                  @Override
426                  public void layerChanged(final MapLayerEvent event) {                  public void layerChanged(final MapLayerEvent event) {
427                          localRenderer.setContext(getContext()); // betters for SLD changes?!                          localRenderer.setContext(getContext()); // betters for SLD changes?!
                         // Change of SLD for example  
                         // mapImageInvalid = true;  
                         // repaint();  
428                          requestStartRendering();                          requestStartRendering();
429                  }                  }
430    
431                  @Override                  @Override
432                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
433                          requestStartRendering();                          requestStartRendering();
434                  }                  }
435    
436                  @Override                  @Override
437                  public void layerShown(final MapLayerEvent event) {                  public void layerShown(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
438                          requestStartRendering();                          requestStartRendering();
439                  }                  }
440          };          };
# Line 536  public class XMapPane extends JPanel { Line 514  public class XMapPane extends JPanel {
514          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
515                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(localRenderer);
516    
517            /**
518             * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
519             * start rendering {@link Thread}s
520             **/
521          private volatile Boolean requestStartRendering = false;          private volatile Boolean requestStartRendering = false;
522    
         private final Timer resizeTimer;  
   
523          /**          /**
524           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
525           * (lat/lon)           * (lat/lon)
# Line 576  public class XMapPane extends JPanel { Line 556  public class XMapPane extends JPanel {
556          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
557          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
558    
559          // TODO doku          // /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet
560            // defined, but we are **/
561            // private Envelope mapAreaCondidate = null;
562    
563          public XMapPane() {          public XMapPane() {
564                  this(null, null);                  this(null, null);
565          }          }
# Line 585  public class XMapPane extends JPanel { Line 568  public class XMapPane extends JPanel {
568           * full constructor extending JPanel           * full constructor extending JPanel
569           *           *
570           * @param rendererHints           * @param rendererHints
571             *            may be <code>null</code>. Otherwise a {@link Map<Object,
572             *            Object>} of {@link RenderingHints} to override the default
573             *            from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)}
574           *           *
          * @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  
575           * @param localContext           * @param localContext
576           *            - {@link MapContext} of layer to render.           *            The main {@link MapContext} to use. If <code>null</code>, an
577             *            empty {@link DefaultMapContext} will be created.
578           */           */
579          public XMapPane(final MapContext localContext_,          public XMapPane(final MapContext localContext_,
580                          final Map<Object, Object> rendererHints) {                          final Map<Object, Object> rendererHints) {
# Line 620  public class XMapPane extends JPanel { Line 601  public class XMapPane extends JPanel {
601                   * Using a ComponentListener doesn't work because, unlike a JFrame, the                   * Using a ComponentListener doesn't work because, unlike a JFrame, the
602                   * pane receives a stream of events during drag-resizing.                   * pane receives a stream of events during drag-resizing.
603                   */                   */
604                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() {                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
605                                    new ActionListener() {
                         public void actionPerformed(final ActionEvent e) {  
                                 paneResized = true;  
   
                                 if (!isWellDefined())  
                                         return;  
   
                                 final Rectangle bounds = getVisibleRect();  
606    
607                                  final Envelope geoMapArea = tranformWindowToGeo(bounds.x,                                          public void actionPerformed(final ActionEvent e) {
608                                                  bounds.y, bounds.x + bounds.width, bounds.y                                                  if (!isWellDefined())
609                                                                  + bounds.height);                                                          return;
610    
611                                  setMapArea(bestAllowedMapArea(geoMapArea));                                                  final Rectangle bounds = getVisibleRect();
612                          }                                                  //
613                  });                                                  // System.out.println("\n\ntimer performs with bounds = "
614                                                    // + bounds);
615    
616                                                    final Envelope geoMapArea = tranformWindowToGeo(
617                                                                    bounds.x, bounds.y, bounds.x + bounds.width,
618                                                                    bounds.y + bounds.height);
619    
620                                                    if (setMapArea(geoMapArea))
621                                                            paneResized = true;
622                                                    // else
623                                                    // syso
624                                            }
625                                    });
626                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
627    
628                  this.addComponentListener(new ComponentAdapter() {                  this.addComponentListener(new ComponentAdapter() {
629    
630                          @Override                          @Override
631                          public void componentResized(final ComponentEvent e) {                          public void componentResized(final ComponentEvent e) {
632    
633                                    // Already cancel the tasks...
634                                  if (bgExecuter != null)                                  if (bgExecuter != null)
635                                          bgExecuter.cancelTask();                                          bgExecuter.cancelTask();
636                                  if (localExecuter != null)                                  if (localExecuter != null)
637                                          localExecuter.cancelTask();                                          localExecuter.cancelTask();
638    
639                                  resizeTimer.restart();                                  resizeTimer.restart();
640                          }                          }
641    
# Line 654  public class XMapPane extends JPanel { Line 644  public class XMapPane extends JPanel {
644                  /*                  /*
645                   * Setting up the repaintTimer. Not started automatically.                   * Setting up the repaintTimer. Not started automatically.
646                   */                   */
647                  repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY,                  repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
                                 new ActionListener() {  
648    
649                                          @Override                          @Override
650                                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
651                                                  updateFinalImage();                                  if ((localExecuter != null && !localExecuter.isRunning())
652                                                  XMapPane.this.repaint();                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {
653                                          }                                          repaintTimer.stop();
654                                  });                                  } else {
655                                            updateFinalImage();
656                                            XMapPane.this.repaint(100);
657                                    }
658                            }
659                    });
660                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
661                  repaintTimer.setRepeats(true);                  repaintTimer.setRepeats(true);
662    
# Line 680  public class XMapPane extends JPanel { Line 674  public class XMapPane extends JPanel {
674                                                  if (localExecuter.isRunning()) {                                                  if (localExecuter.isRunning()) {
675                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
676                                                  } else {                                                  } else {
677    
678                                                            // Stupidly, but we have to recheck the
679                                                            setMapArea(getMapArea());
680                                                          requestStartRendering = false;                                                          requestStartRendering = false;
681                                                          startRendering();                                                          startRendering();
682                                                  }                                                  }
# Line 712  public class XMapPane extends JPanel { Line 709  public class XMapPane extends JPanel {
709           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
710           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
711           */           */
712          public Envelope bestAllowedMapArea(Envelope env) {          public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
713                  // return env;  
714                  if (getWidth() == 0)                  if (getWidth() == 0)
715                          return env;                          return env;
716    
717                  if (env == null)                  if (env == null)
718                          return null;                          return null;
719    
# Line 794  public class XMapPane extends JPanel { Line 792  public class XMapPane extends JPanel {
792    
793                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
794    
795                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
796                                                          false);                                                          new ReferencedEnvelope(newArea, env
797                                                                            .getCoordinateReferenceSystem()), false);
798                                  }                                  }
799                          }                          }
800    
# Line 818  public class XMapPane extends JPanel { Line 817  public class XMapPane extends JPanel {
817    
818                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
819    
820                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
821                                                          false);                                                          new ReferencedEnvelope(newArea, env
822                                                                            .getCoordinateReferenceSystem()), false);
823                                  }                                  }
824                          }                          }
825    
# Line 844  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(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
848                                                          false);                                                          new ReferencedEnvelope(newArea, env
849                                                                            .getCoordinateReferenceSystem()), false);
850                                  }                                  }
851                          }                          }
852    
# Line 870  public class XMapPane extends JPanel { Line 871  public class XMapPane extends JPanel {
871    
872                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
873    
874                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
875                                                          false);                                                          new ReferencedEnvelope(newArea, env
876                                                                            .getCoordinateReferenceSystem()), false);
877                                  }                                  }
878                          }                          }
879                  }                  }
880    
881                  return newArea;                  return new ReferencedEnvelope(newArea, env
882                                    .getCoordinateReferenceSystem());
883          }          }
884    
885          /**          /**
# Line 909  public class XMapPane extends JPanel { Line 912  public class XMapPane extends JPanel {
912                          localExecuter.cancelTask();                          localExecuter.cancelTask();
913                          while (i++ < 10 && localExecuter.isRunning()) {                          while (i++ < 10 && localExecuter.isRunning()) {
914                                  try {                                  try {
915                                          Thread.sleep(100);                                          Thread.sleep(200);
916                                  } catch (final InterruptedException e) {                                  } catch (final InterruptedException e) {
917                                          // TODO Auto-generated catch block                                          LOGGER
918                                          e.printStackTrace();                                                          .warn(
919                                                                            "while XMapPane we are waiting for the localExcutor to stop",
920                                                                            e);
921                                  }                                  }
922                          }                          }
923                          if (localExecuter.isRunning()) {                          if (localExecuter.isRunning()) {
924                                  System.out                                  LOGGER
925                                                  .println("BAD BAD BAD... still running the thread....");                                                  .warn("localExecutor Thread still running after 2s! Continuing anyways...");
926                          }                          }
927                          localExecuter.dispose();                          localExecuter.dispose();
928                  }                  }
929    
930                  disposeImages();                  disposeImages();
931    
932                  // LangUtil.gcTotal();                  // Remove all mapPaneListeners that have registered with us
   
                 // Alle mapPaneListener entfernen  
933                  mapPaneListeners.clear();                  mapPaneListeners.clear();
934    
935                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(zoomMapPaneMouseListener);
# Line 979  public class XMapPane extends JPanel { Line 982  public class XMapPane extends JPanel {
982           */           */
983          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
984    
985  //              if (1 == 1)return false;                  // if (1 == 1)return false;
986                    
987                  if (quickPreviewHint == 0)                  if (quickPreviewHint == 0)
988                          return false;                          return false;
989    
# Line 1091  public class XMapPane extends JPanel { Line 1094  public class XMapPane extends JPanel {
1094                          try {                          try {
1095                                  mapArea_ = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1096                          } catch (final IOException e) {                          } catch (final IOException e) {
1097                                  LOGGER.warn("context.getLayerBounds()", e);                                  LOGGER.warn("localContext.getLayerBounds()", e);
1098                            }
1099    
1100                            if (mapArea_ == null && bgContext != null) {
1101                                    try {
1102                                            mapArea_ = bgContext.getLayerBounds();
1103                                    } catch (final IOException e) {
1104                                            LOGGER.warn("bgContext.getLayerBounds()", e);
1105                                    }
1106                          }                          }
1107    
1108                          if (mapArea_ != null) {                          if (mapArea_ != null) {
                                 mapImageInvalid = true; /* note we need to redraw */  
                                 // setMapArea(mapArea_); // results in a loop  
1109                                  mapArea = bestAllowedMapArea(mapArea_);                                  mapArea = bestAllowedMapArea(mapArea_);
1110                                    requestStartRendering();
1111                          }                          }
1112                  }                  }
1113    
# Line 1270  public class XMapPane extends JPanel { Line 1280  public class XMapPane extends JPanel {
1280           * {@link XMapPane} is visible and has bounds set.           * {@link XMapPane} is visible and has bounds set.
1281           */           */
1282          public boolean isWellDefined() {          public boolean isWellDefined() {
   
1283                  try {                  try {
   
1284                          if (getContext() == null)                          if (getContext() == null)
1285                                  return false;                                  return false;
1286                          if (getContext().getLayerCount() <= 0)                          if (getContext().getLayerCount() <= 0)
1287                                  return false;                                  return false;
1288                          if (getMapArea() == null)                          if (getVisibleRect().getWidth() == 0)
                                 return false;  
                         if (getBounds().getWidth() == 0)  
1289                                  return false;                                  return false;
1290                          if (getBounds().getHeight() == 0)                          if (getVisibleRect().getHeight() == 0)
1291                                  return false;                                  return false;
1292                            // if (getMapArea() == null)
1293                            // return false;
1294                  } catch (final Exception e) {                  } catch (final Exception e) {
1295                          return false;                          return false;
1296                  }                  }
# Line 1370  public class XMapPane extends JPanel { Line 1378  public class XMapPane extends JPanel {
1378           * Called by the {@link RenderingExecutor} when rendering was cancelled.           * Called by the {@link RenderingExecutor} when rendering was cancelled.
1379           */           */
1380          public void onRenderingCancelled() {          public void onRenderingCancelled() {
                 repaintTimer.stop();  
1381                  LOGGER.debug("Rendering cancelled");                  LOGGER.debug("Rendering cancelled");
1382                    repaintTimer.stop();
1383          }          }
1384    
1385          /**          /**
# Line 1415  public class XMapPane extends JPanel { Line 1423  public class XMapPane extends JPanel {
1423    
1424          @Override          @Override
1425          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
1426    
1427                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1428                          return;                          return;
1429    
# Line 1434  public class XMapPane extends JPanel { Line 1443  public class XMapPane extends JPanel {
1443                          // happening.                          // happening.
1444                          if (mapAreaChanged && oldMapArea != null                          if (mapAreaChanged && oldMapArea != null
1445                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1446                                          & !getMapArea().equals(oldMapArea)) {                                          & !getMapArea().equals(oldMapArea) && !paneResized) {
1447    
1448                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1449    
# Line 1448  public class XMapPane extends JPanel { Line 1457  public class XMapPane extends JPanel {
1457    
1458                          }                          }
1459    
1460                          if (paneResized) {                          // if (paneResized) {
1461                                  paneResized = false;                          // paneResized = false;
1462                                  disposeImages();                          // disposeImages();
1463                          }                          // }
1464                            //
1465                          // Start the Threads and Timers to render the image                          // // Start the Threads and Timers to render the image
1466                          requestStartRendering();                          // requestStartRendering();
1467    
1468                  }                  }
1469    
# Line 1520  public class XMapPane extends JPanel { Line 1529  public class XMapPane extends JPanel {
1529          public void performPan() {          public void performPan() {
1530    
1531                  Rectangle winBounds = getVisibleRect();                  Rectangle winBounds = getVisibleRect();
1532                    
1533                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1534                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1535                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y
# Line 1585  public class XMapPane extends JPanel { Line 1594  public class XMapPane extends JPanel {
1594                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1595                  if (localExecuter != null)                  if (localExecuter != null)
1596                          localExecuter.cancelTask();                          localExecuter.cancelTask();
1597    
1598                    mapImageInvalid = true;
1599                    if (paneResized) {
1600                            paneResized = false;
1601                            disposeImages();
1602                    }
1603                  requestStartRendering = true;                  requestStartRendering = true;
1604    
1605          }          }
1606    
         //  
         // /**  
         // * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten  
         // * neu.  
         // */  
         // protected void resetTransforms() {  
         // if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)  
         // return;  
         //  
         // // We store the last Transform  
         // oldScreenToWorld = screenToWorld;  
         //  
         // this.screenToWorld = new AffineTransform(  
         // // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten  
         // // 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());  
         //  
         // try {  
         // this.worldToScreen = screenToWorld.createInverse();  
         // } catch (final NoninvertibleTransformException e) {  
         // LOGGER.error(e);  
         // }  
         // }  
   
1607          /**          /**
1608           * Calculate the affine transforms used to convert between world and pixel           * Calculate the affine transforms used to convert between world and pixel
1609           * coordinates. The calculations here are very basic and assume a cartesian           * coordinates. The calculations here are very basic and assume a cartesian
# Line 1644  public class XMapPane extends JPanel { Line 1621  public class XMapPane extends JPanel {
1621                  ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,                  ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1622                                  getContext().getCoordinateReferenceSystem());                                  getContext().getCoordinateReferenceSystem());
1623    
1624                  Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!                  // System.out
1625                                    // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1626                  //                          if (!isWellDefined())
1627                  // double xscale = paintArea.getWidth() / refEnv.getWidth();                          return;
                 // double yscale = paintArea.getHeight() / refEnv.getHeight();  
                 //  
                 // double scale = Math.min(xscale, yscale);  
                 //  
                 // double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();  
                 // double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();  
1628    
1629                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1630                                  paintArea);                                  getVisibleRect());
1631    
                 // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,  
                 // yoff);  
1632                  try {                  try {
1633                          screenToWorld = worldToScreen.createInverse();                          screenToWorld = worldToScreen.createInverse();
1634    
1635                  } catch (NoninvertibleTransformException ex) {                  } catch (NoninvertibleTransformException ex) {
1636                          ex.printStackTrace();                          LOGGER
1637                                            .error("can't invert worldToScreen to get screenToWorld!",
1638                                                            ex);
1639                  }                  }
1640          }          }
1641    
# Line 1683  public class XMapPane extends JPanel { Line 1654  public class XMapPane extends JPanel {
1654                  this.bgContext = context;                  this.bgContext = context;
1655    
1656                  if (context != null) {                  if (context != null) {
1657                          setMapArea(bgContext.getAreaOfInterest());                          // setMapArea(bgContext.getAreaOfInterest());
1658    
1659                          this.bgContext.addMapLayerListListener(bgContextListener);                          this.bgContext.addMapLayerListListener(bgContextListener);
1660    
# Line 1692  public class XMapPane extends JPanel { Line 1663  public class XMapPane extends JPanel {
1663                                  mapLayer.addMapLayerListener(bgMapLayerListener);                                  mapLayer.addMapLayerListener(bgMapLayerListener);
1664                          }                          }
1665                  }                  }
1666                  mapImageInvalid = true;  
1667                  repaint();                  requestStartRendering();
1668          }          }
1669    
1670          public void setJava2dHints(final RenderingHints java2dHints) {          public void setJava2dHints(final RenderingHints java2dHints) {
1671                  this.java2dHints = java2dHints;                  this.java2dHints = java2dHints;
1672          }          }
1673    
         /**  
          *  
          * @param context  
          */  
1674          public void setLocalContext(final MapContext context) {          public void setLocalContext(final MapContext context) {
1675                  // Remove the default listener from the old context                  // Remove the default listener from the old context
1676                  if (this.localContext != null) {                  if (this.localContext != null) {
# Line 1719  public class XMapPane extends JPanel { Line 1686  public class XMapPane extends JPanel {
1686    
1687                  if (context != null) {                  if (context != null) {
1688    
1689                          setMapArea(localContext.getAreaOfInterest());                          // setMapArea(localContext.getAreaOfInterest());
1690    
1691                          localRenderer.setContext(localContext);                          localRenderer.setContext(localContext);
1692    
# Line 1731  public class XMapPane extends JPanel { Line 1698  public class XMapPane extends JPanel {
1698                          }                          }
1699                  }                  }
1700    
1701                  mapImageInvalid = true;                  requestStartRendering();
1702                  repaint();  
1703            }
1704    
1705            public boolean setMapArea(final Envelope newMapArea) {
1706                    return setMapArea(new ReferencedEnvelope(newMapArea, getContext()
1707                                    .getCoordinateReferenceSystem()));
1708          }          }
1709    
1710          /**          /**
# Line 1740  public class XMapPane extends JPanel { Line 1712  public class XMapPane extends JPanel {
1712           * @return <code>true</code> if the mapArea has been changed and a repaint           * @return <code>true</code> if the mapArea has been changed and a repaint
1713           *         has been triggered.           *         has been triggered.
1714           */           */
1715          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final ReferencedEnvelope newMapArea) {
1716                    //              
1717                    // if (getVisibleRect().getWidth() == 0 || (!isVisible()) ||
1718                    // getVisibleRect().getHeight() == 0) {
1719                    // // The window is not yet defined.. so we can not really determine the
1720                    // asepect ratio for the mapPane. We store this as a candidate mappane
1721                    // and handle it when the component resizes or becomes visible)
1722                    // mapAreaCondidate = newMapArea;
1723                    // }
1724    
1725                  if (newMapArea == null                  if (newMapArea == null
1726                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {
# Line 1795  public class XMapPane extends JPanel { Line 1775  public class XMapPane extends JPanel {
1775                          bgContext.setAreaOfInterest(mapArea, localContext                          bgContext.setAreaOfInterest(mapArea, localContext
1776                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
1777                  }                  }
1778                  mapImageInvalid = true;  
1779                  mapAreaChanged = true;                  mapAreaChanged = true;
                 repaint();  
1780    
1781                  LOGGER.debug("New maparea = " + mapArea);                  repaint(100);
1782    
1783                    requestStartRendering();
1784    
1785                  return true;                  return true;
1786          }          }
1787    
# Line 1949  public class XMapPane extends JPanel { Line 1931  public class XMapPane extends JPanel {
1931           */           */
1932          private void startRendering() {          private void startRendering() {
1933    
1934                  if (!isWellDefined())                  if (!isWellDefined() || !acceptsRepaintCalls) {
1935                            requestStartRendering = true;
1936                          return;                          return;
1937                    }
1938    
1939                  if (bgExecuter != null) {                  if (bgExecuter != null) {
1940                          // Stop all renderers                          // Stop all renderers
# Line 1989  public class XMapPane extends JPanel { Line 1973  public class XMapPane extends JPanel {
1973                          localRenderer.setJava2DHints(getJava2dHints());                          localRenderer.setJava2DHints(getJava2dHints());
1974                          localRenderer.setRendererHints(getRendererHints());                          localRenderer.setRendererHints(getRendererHints());
1975    
1976                          ReferencedEnvelope areaOfInterest = getMapArea();                          final boolean submitted = localExecuter.submit(getMapArea(),
                         final boolean submitted = localExecuter.submit(areaOfInterest,  
1977                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1978                                          localRenderer, getWorldToScreenTransform());                                          localRenderer
1979                            // , getWorldToScreenTransform()
1980                                            );
1981                          if (submitted)                          if (submitted)
1982                                  repaintTimer.restart();                                  repaintTimer.restart();
1983                          else                          else
1984                                  requestStartRendering = true; // Try to start rendering again in                                  requestStartRendering = true; // Try to start rendering
1985                            // again in
1986                          // a moment                          // a moment
1987                  }                  }
1988    
# Line 2049  public class XMapPane extends JPanel { Line 2035  public class XMapPane extends JPanel {
2035                  final AffineTransform at = getScreenToWorld();                  final AffineTransform at = getScreenToWorld();
2036                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);                  final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
2037                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);                  final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2038                    
2039                  // Mmmmm... don't really understand why its x,x,y,y                  // Mmmmm... don't really understand why its x,x,y,y
2040  //              return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());                  // return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(),
2041                  return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY()));                  // geoP.getY());
2042                    return new Envelope(new Coordinate(geoO.getX(), geoO.getY()),
2043                                    new Coordinate(geoP.getX(), geoP.getY()));
2044          }          }
2045    
2046          /**          /**
# Line 2070  public class XMapPane extends JPanel { Line 2058  public class XMapPane extends JPanel {
2058                  } else {                  } else {
2059                          // Allow one last rendering                          // Allow one last rendering
2060                          if (repaintTimer.isRunning()) {                          if (repaintTimer.isRunning()) {
2061                                  System.out.println("one last rendering....");                                  // System.out.println("one last rendering....");
2062                                  repaintTimer.stop();                                  repaintTimer.stop();
2063                                  updateFinalImage();                                  updateFinalImage();
2064                                  repaint();                                  repaint();
# Line 2211  public class XMapPane extends JPanel { Line 2199  public class XMapPane extends JPanel {
2199    
2200                                  String errStr = ex.getLocalizedMessage();                                  String errStr = ex.getLocalizedMessage();
2201    
2202                                    if (errStr == null)
2203                                            errStr = ex.getMessage();
2204                                    if (errStr == null)
2205                                            errStr = "unknown error: " + ex.getClass().getSimpleName();
2206    
2207                                  graphics.setColor(Color.WHITE);                                  graphics.setColor(Color.WHITE);
2208                                  graphics.drawString(errStr, 5, y);                                  graphics.drawString(errStr, 5, y);
2209                                  graphics.setColor(Color.RED);                                  graphics.setColor(Color.RED);
# Line 2349  public class XMapPane extends JPanel { Line 2342  public class XMapPane extends JPanel {
2342                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2343                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2344                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2345                    
2346  // TODO we actually want that                  // TODO we actually want that
2347  //              // Move the newMapArea above the new center                  // // Move the newMapArea above the new center
2348  //              newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2349  //                              .getY()                  // .getY()
2350  //                              - mapArea.centre().y);                  // - mapArea.centre().y);
2351    
2352                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2353          }          }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26