/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Diff of /branches/2.0-RC2/src/skrueger/geotools/XMapPane.java

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

revision 542 by alfonx, Fri Nov 20 19:34:50 2009 UTC revision 543 by alfonx, Sat Nov 21 15:21:41 2009 UTC
# Line 295  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 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 429  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 536  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    
# Line 547  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 576  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 585  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 620  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                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() {                  resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
629                                    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 909  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                  }                  }
933    
934                  disposeImages();                  disposeImages();
935    
936                  // LangUtil.gcTotal();                  // Remove all mapPaneListeners that have registered with us
   
                 // Alle mapPaneListener entfernen  
937                  mapPaneListeners.clear();                  mapPaneListeners.clear();
938    
939                  removeMouseMotionListener(zoomMapPaneMouseListener);                  removeMouseMotionListener(zoomMapPaneMouseListener);
# Line 979  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;                  // if (1 == 1)return false;
990                    
991                  if (quickPreviewHint == 0)                  if (quickPreviewHint == 0)
992                          return false;                          return false;
993    
# Line 1520  public class XMapPane extends JPanel { Line 1527  public class XMapPane extends JPanel {
1527          public void performPan() {          public void performPan() {
1528    
1529                  Rectangle winBounds = getVisibleRect();                  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 1585  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    
# Line 1645  public class XMapPane extends JPanel { Line 1652  public class XMapPane extends JPanel {
1652                                  getContext().getCoordinateReferenceSystem());                                  getContext().getCoordinateReferenceSystem());
1653    
1654                  Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!                  Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!
1655                    
1656                  //                          //        
1657                  // double xscale = paintArea.getWidth() / refEnv.getWidth();                  // double xscale = paintArea.getWidth() / refEnv.getWidth();
1658                  // double yscale = paintArea.getHeight() / refEnv.getHeight();                  // double yscale = paintArea.getHeight() / refEnv.getHeight();
# Line 1996  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 2049  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                    
2060                  // Mmmmm... don't really understand why its x,x,y,y                  // Mmmmm... don't really understand why its x,x,y,y
2061  //              return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());                  // return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(),
2062                  return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY()));                  // geoP.getY());
2063                    return new Envelope(new Coordinate(geoO.getX(), geoO.getY()),
2064                                    new Coordinate(geoP.getX(), geoP.getY()));
2065          }          }
2066    
2067          /**          /**
# Line 2349  public class XMapPane extends JPanel { Line 2358  public class XMapPane extends JPanel {
2358                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2359                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2360                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2361                    
2362  // TODO we actually want that                  // TODO we actually want that
2363  //              // Move the newMapArea above the new center                  // // Move the newMapArea above the new center
2364  //              newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2365  //                              .getY()                  // .getY()
2366  //                              - mapArea.centre().y);                  // - mapArea.centre().y);
2367    
2368                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2369          }          }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26