/[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 543 by alfonx, Sat Nov 21 15:21:41 2009 UTC revision 545 by alfonx, Sat Nov 21 18:22:36 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;
 import org.geotools.geometry.Envelope2D;  
33  import org.geotools.geometry.jts.JTS;  import org.geotools.geometry.jts.JTS;
34  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
35  import org.geotools.map.DefaultMapContext;  import org.geotools.map.DefaultMapContext;
# Line 125  public class XMapPane extends JPanel { Line 124  public class XMapPane extends JPanel {
124           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all           * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
125           * renderers have finished.           * renderers have finished.
126           *           *
127           * @see #INITIAL_REPAINT_DELAYAL           * @see INITIAL_REPAINT_DELAYAL
128           * @see #REPEATING_REPAINT_DELAY           * @see #REPEATING_REPAINT_DELAY
129           */           */
130          final private Timer repaintTimer;          final private Timer repaintTimer;
# Line 141  public class XMapPane extends JPanel { Line 140  public class XMapPane extends JPanel {
140           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
141           * with previews.           * with previews.
142           */           */
143          public static final long REPEATING_REPAINT_DELAY = 500;          public static final int REPEATING_REPAINT_DELAY = 500;
144    
145          /**          /**
146           * Default delay (milliseconds) before the map will be redrawn when resizing           * Default delay (milliseconds) before the map will be redrawn when resizing
147           * the pane. This is to avoid flickering while drag-resizing.           * the pane. This is to avoid flickering while drag-resizing.
148             *
149             * @see #resizeTimer
150           */           */
151          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
152    
153            private final Timer resizeTimer;
154    
155          public static final int NONE = -123;          public static final int NONE = -123;
156    
157          /**          /**
# Line 186  public class XMapPane extends JPanel { Line 189  public class XMapPane extends JPanel {
189          public static final Cursor WAIT_CURSOR = Cursor          public static final Cursor WAIT_CURSOR = Cursor
190                          .getPredefinedCursor(Cursor.WAIT_CURSOR);                          .getPredefinedCursor(Cursor.WAIT_CURSOR);
191    
192            /**
193             * {@link Font} used to paint the wait messages into the map
194             *
195             * @see #addGadgets(Graphics2D, boolean)
196             */
197          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
198          final String waitMsg = SwingUtil.R("WaitMess");  
199            /**
200             * {@link Font} used to paint error messages into the map
201             *
202             * @see #addGadgets(Graphics2D, boolean)
203             */
204          final static Font errorFont = new Font("Arial", Font.BOLD, 13);          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
205    
206          /**          /**
207             * The wait message painted into the map while rendering is going on on
208             * another thread.
209             *
210             * @see #addGadgets(Graphics2D, boolean)
211             */
212            final String waitMsg = SwingUtil.R("WaitMess");
213    
214            /**
215           * Flag fuer Modus "Heran zoomen".           * Flag fuer Modus "Heran zoomen".
216           *           *
217           * @see #setState(int)           * @see #setState(int)
# Line 249  public class XMapPane extends JPanel { Line 270  public class XMapPane extends JPanel {
270    
271                  @Override                  @Override
272                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
   
273                          MapLayer layer = event.getLayer();                          MapLayer layer = event.getLayer();
   
274                          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();  
275                          requestStartRendering();                          requestStartRendering();
276    
277                  }                  }
278    
279                  @Override                  @Override
280                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
281                          requestStartRendering();                          requestStartRendering();
282                  }                  }
283    
284                  @Override                  @Override
285                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
286                          requestStartRendering();                          requestStartRendering();
287                  }                  }
288    
# Line 288  public class XMapPane extends JPanel { Line 290  public class XMapPane extends JPanel {
290                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
291                          if (event.getLayer() != null)                          if (event.getLayer() != null)
292                                  event.getLayer().removeMapLayerListener(bgMapLayerListener);                                  event.getLayer().removeMapLayerListener(bgMapLayerListener);
                         // mapImageInvalid = true;  
                         // repaint();  
293                          requestStartRendering();                          requestStartRendering();
294                  }                  }
295          };          };
# Line 317  public class XMapPane extends JPanel { Line 317  public class XMapPane extends JPanel {
317           * {@link Image}.           * {@link Image}.
318           */           */
319          private BufferedImage bgImage;          private BufferedImage bgImage;
320            
321          /**          /**
322           * This {@link Image} is a merge of the {@link #bgImage},           * This {@link Image} is a merge of the {@link #bgImage},
323           * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is           * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
# Line 326  public class XMapPane extends JPanel { Line 326  public class XMapPane extends JPanel {
326           */           */
327          private BufferedImage finalImage;          private BufferedImage finalImage;
328    
   
329          /**          /**
330           * 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
331           * corner.           * corner.
# Line 391  public class XMapPane extends JPanel { Line 390  public class XMapPane extends JPanel {
390                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
391    
392                          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();  
393                          requestStartRendering();                          requestStartRendering();
394    
395                  }                  }
396    
397                  @Override                  @Override
398                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
399                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
400                          requestStartRendering();                          requestStartRendering();
401                  }                  }
402    
403                  @Override                  @Override
404                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
405                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
406                          requestStartRendering();                          requestStartRendering();
407                  }                  }
# Line 428  public class XMapPane extends JPanel { Line 410  public class XMapPane extends JPanel {
410                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
411                          if (event.getLayer() != null)                          if (event.getLayer() != null)
412                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
                         // mapImageInvalid = true;  
                         // repaint();  
413                          localRenderer.setContext(getContext());                          localRenderer.setContext(getContext());
414                          requestStartRendering();                          requestStartRendering();
415                  }                  }
# Line 444  public class XMapPane extends JPanel { Line 424  public class XMapPane extends JPanel {
424                  @Override                  @Override
425                  public void layerChanged(final MapLayerEvent event) {                  public void layerChanged(final MapLayerEvent event) {
426                          localRenderer.setContext(getContext()); // betters for SLD changes?!                          localRenderer.setContext(getContext()); // betters for SLD changes?!
                         // Change of SLD for example  
                         // mapImageInvalid = true;  
                         // repaint();  
427                          requestStartRendering();                          requestStartRendering();
428                  }                  }
429    
430                  @Override                  @Override
431                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
432                          requestStartRendering();                          requestStartRendering();
433                  }                  }
434    
435                  @Override                  @Override
436                  public void layerShown(final MapLayerEvent event) {                  public void layerShown(final MapLayerEvent event) {
                         // mapImageInvalid = true;  
                         // repaint();  
437                          requestStartRendering();                          requestStartRendering();
438                  }                  }
439          };          };
# Line 540  public class XMapPane extends JPanel { Line 513  public class XMapPane extends JPanel {
513          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
514                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(localRenderer);
515    
516          /** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #localImage} **/          /**
517          private volatile Boolean requestStartRenderingLocal = false;           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
518                     * start rendering {@link Thread}s
519          /** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #bgImage} **/           **/
520          private volatile Boolean requestStartRenderingBg = false;          private volatile Boolean requestStartRendering = false;
   
         private final Timer resizeTimer;  
521    
522          /**          /**
523           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten           * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
# Line 555  public class XMapPane extends JPanel { Line 526  public class XMapPane extends JPanel {
526          protected AffineTransform screenToWorld = null;          protected AffineTransform screenToWorld = null;
527    
528          /**          /**
529           * The flag {@link #requestStartRenderingLocal} can be set to true by events.           * The flag {@link #requestStartRendering} can be set to true by events.
530           * This {@link Timer} checks the flag regularly and starts one renderer           * This {@link Timer} checks the flag regularly and starts one renderer
531           * thread.           * thread.
532           */           */
# Line 584  public class XMapPane extends JPanel { Line 555  public class XMapPane extends JPanel {
555          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
556          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
557    
558            // /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet
559            // defined, but we are **/
560            // private Envelope mapAreaCondidate = null;
561    
562          public XMapPane() {          public XMapPane() {
563                  this(null, null);                  this(null, null);
564          }          }
# Line 629  public class XMapPane extends JPanel { Line 604  public class XMapPane extends JPanel {
604                                  new ActionListener() {                                  new ActionListener() {
605    
606                                          public void actionPerformed(final ActionEvent e) {                                          public void actionPerformed(final ActionEvent e) {
                                                 paneResized = true;  
   
607                                                  if (!isWellDefined())                                                  if (!isWellDefined())
608                                                          return;                                                          return;
609    
610                                                  final Rectangle bounds = getVisibleRect();                                                  final Rectangle bounds = getVisibleRect();
611                                                    //
612                                                    // System.out.println("\n\ntimer performs with bounds = "
613                                                    // + bounds);
614    
615                                                  final Envelope geoMapArea = tranformWindowToGeo(                                                  final Envelope geoMapArea = tranformWindowToGeo(
616                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                                  bounds.x, bounds.y, bounds.x + bounds.width,
617                                                                  bounds.y + bounds.height);                                                                  bounds.y + bounds.height);
618    
619                                                  setMapArea(bestAllowedMapArea(geoMapArea));                                                  if (setMapArea(geoMapArea))
620                                                            paneResized = true;
621                                                    // else
622                                                    // syso
623                                          }                                          }
624                                  });                                  });
625                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
626                    
627  //              this.addComponentListener(new ComponentAdapter() {                  this.addComponentListener(new ComponentAdapter() {
628  //  
629  //                      @Override                          @Override
630  //                      public void componentResized(final ComponentEvent e) {                          public void componentResized(final ComponentEvent e) {
631  //                              if (bgExecuter != null)  
632  //                                      bgExecuter.cancelTask();                                  // Already cancel the tasks...
633  //                              if (localExecuter != null)                                  if (bgExecuter != null)
634  //                                      localExecuter.cancelTask();                                          bgExecuter.cancelTask();
635  //                              resizeTimer.restart();                                  if (localExecuter != null)
636  //                      }                                          localExecuter.cancelTask();
637  //  
638  //              });                                  resizeTimer.restart();
639                            }
640    
641                    });
642    
643                  /*                  /*
644                   * Setting up the repaintTimer. Not started automatically.                   * Setting up the repaintTimer. Not started automatically.
645                   */                   */
646                  repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY,                  repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
                                 new ActionListener() {  
647    
648                                          @Override                          @Override
649                                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
650                                                  updateFinalImage();                                  if ((localExecuter != null && !localExecuter.isRunning())
651                                                  XMapPane.this.repaint();                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {
652                                          }                                          repaintTimer.stop();
653                                  });                                  } else {
654                                            updateFinalImage();
655                                            XMapPane.this.repaint(100);
656                                    }
657                            }
658                    });
659                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
660                  repaintTimer.setRepeats(true);                  repaintTimer.setRepeats(true);
661    
# Line 681  public class XMapPane extends JPanel { Line 667  public class XMapPane extends JPanel {
667    
668                          @Override                          @Override
669                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
670                                  synchronized (requestStartRenderingLocal) {                                  synchronized (requestStartRendering) {
671                                          if (requestStartRenderingLocal && isWellDefined()) {                                          if (requestStartRendering && isWellDefined()) {
672    
673                                                  if (localExecuter.isRunning()) {                                                  if (localExecuter.isRunning()) {
674                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
675                                                  } else {                                                  } else {
676                                                          requestStartRenderingLocal = false;  
677                                                            // Stupidly, but we have to recheck the
678                                                            setMapArea(getMapArea());
679                                                            requestStartRendering = false;
680                                                          startRendering();                                                          startRendering();
681                                                  }                                                  }
682                                          }                                          }
# Line 719  public class XMapPane extends JPanel { Line 708  public class XMapPane extends JPanel {
708           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
709           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
710           */           */
711          public Envelope bestAllowedMapArea(Envelope env) {          public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
712                  // return env;  
713                  if (getWidth() == 0)                  if (getWidth() == 0)
714                          return env;                          return env;
715    
716                  if (env == null)                  if (env == null)
717                          return null;                          return null;
718    
# Line 801  public class XMapPane extends JPanel { Line 791  public class XMapPane extends JPanel {
791    
792                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
793    
794                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
795                                                          false);                                                          new ReferencedEnvelope(newArea, env
796                                                                            .getCoordinateReferenceSystem()), false);
797                                  }                                  }
798                          }                          }
799    
# Line 825  public class XMapPane extends JPanel { Line 816  public class XMapPane extends JPanel {
816    
817                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
818    
819                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
820                                                          false);                                                          new ReferencedEnvelope(newArea, env
821                                                                            .getCoordinateReferenceSystem()), false);
822                                  }                                  }
823                          }                          }
824    
# Line 851  public class XMapPane extends JPanel { Line 843  public class XMapPane extends JPanel {
843    
844                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
845    
846                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
847                                                          false);                                                          new ReferencedEnvelope(newArea, env
848                                                                            .getCoordinateReferenceSystem()), false);
849                                  }                                  }
850                          }                          }
851    
# Line 877  public class XMapPane extends JPanel { Line 870  public class XMapPane extends JPanel {
870    
871                                          // LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
872    
873                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,                                          newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
874                                                          false);                                                          new ReferencedEnvelope(newArea, env
875                                                                            .getCoordinateReferenceSystem()), false);
876                                  }                                  }
877                          }                          }
878                  }                  }
879    
880                  return newArea;                  return new ReferencedEnvelope(newArea, env
881                                    .getCoordinateReferenceSystem());
882          }          }
883    
884          /**          /**
# Line 1098  public class XMapPane extends JPanel { Line 1093  public class XMapPane extends JPanel {
1093                          try {                          try {
1094                                  mapArea_ = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1095                          } catch (final IOException e) {                          } catch (final IOException e) {
1096                                  LOGGER.warn("context.getLayerBounds()", e);                                  LOGGER.warn("localContext.getLayerBounds()", e);
1097                            }
1098    
1099                            if (mapArea_ == null && bgContext != null) {
1100                                    try {
1101                                            mapArea_ = bgContext.getLayerBounds();
1102                                    } catch (final IOException e) {
1103                                            LOGGER.warn("bgContext.getLayerBounds()", e);
1104                                    }
1105                          }                          }
1106    
1107                          if (mapArea_ != null) {                          if (mapArea_ != null) {
                                 mapImageInvalid = true; /* note we need to redraw */  
                                 // setMapArea(mapArea_); // results in a loop  
1108                                  mapArea = bestAllowedMapArea(mapArea_);                                  mapArea = bestAllowedMapArea(mapArea_);
1109                                    requestStartRendering();
1110                          }                          }
1111                  }                  }
1112    
# Line 1277  public class XMapPane extends JPanel { Line 1279  public class XMapPane extends JPanel {
1279           * {@link XMapPane} is visible and has bounds set.           * {@link XMapPane} is visible and has bounds set.
1280           */           */
1281          public boolean isWellDefined() {          public boolean isWellDefined() {
   
1282                  try {                  try {
   
1283                          if (getContext() == null)                          if (getContext() == null)
1284                                  return false;                                  return false;
1285                          if (getContext().getLayerCount() <= 0)                          if (getContext().getLayerCount() <= 0)
1286                                  return false;                                  return false;
1287                          if (getMapArea() == null)                          if (getVisibleRect().getWidth() == 0)
1288                                  return false;                                  return false;
1289                          if (getBounds().getWidth() == 0)                          if (getVisibleRect().getHeight() == 0)
                                 return false;  
                         if (getBounds().getHeight() == 0)  
1290                                  return false;                                  return false;
1291                            // if (getMapArea() == null)
1292                            // return false;
1293                  } catch (final Exception e) {                  } catch (final Exception e) {
1294                          return false;                          return false;
1295                  }                  }
# Line 1377  public class XMapPane extends JPanel { Line 1377  public class XMapPane extends JPanel {
1377           * Called by the {@link RenderingExecutor} when rendering was cancelled.           * Called by the {@link RenderingExecutor} when rendering was cancelled.
1378           */           */
1379          public void onRenderingCancelled() {          public void onRenderingCancelled() {
                 repaintTimer.stop();  
1380                  LOGGER.debug("Rendering cancelled");                  LOGGER.debug("Rendering cancelled");
1381                    repaintTimer.stop();
1382          }          }
1383    
1384          /**          /**
# Line 1422  public class XMapPane extends JPanel { Line 1422  public class XMapPane extends JPanel {
1422    
1423          @Override          @Override
1424          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
1425    
1426                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1427                          return;                          return;
1428    
# Line 1441  public class XMapPane extends JPanel { Line 1442  public class XMapPane extends JPanel {
1442                          // happening.                          // happening.
1443                          if (mapAreaChanged && oldMapArea != null                          if (mapAreaChanged && oldMapArea != null
1444                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1445                                          & !getMapArea().equals(oldMapArea)) {                                          & !getMapArea().equals(oldMapArea) && !paneResized) {
1446    
1447                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1448    
# Line 1455  public class XMapPane extends JPanel { Line 1456  public class XMapPane extends JPanel {
1456    
1457                          }                          }
1458    
1459                          if (paneResized) {                          // if (paneResized) {
1460                                  paneResized = false;                          // paneResized = false;
1461                                  disposeImages();                          // disposeImages();
1462                          }                          // }
1463                            //
1464                          // Start the Threads and Timers to render the image                          // // Start the Threads and Timers to render the image
1465                          requestStartRendering();                          // requestStartRendering();
1466    
1467                  }                  }
1468    
# Line 1592  public class XMapPane extends JPanel { Line 1593  public class XMapPane extends JPanel {
1593                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1594                  if (localExecuter != null)                  if (localExecuter != null)
1595                          localExecuter.cancelTask();                          localExecuter.cancelTask();
                 requestStartRenderingLocal = true;  
1596    
1597          }                  mapImageInvalid = true;
1598                    if (paneResized) {
1599                            paneResized = false;
1600                            disposeImages();
1601                    }
1602                    requestStartRendering = true;
1603    
1604          //          }
         // /**  
         // * 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);  
         // }  
         // }  
1605    
1606          /**          /**
1607           * Calculate the affine transforms used to convert between world and pixel           * Calculate the affine transforms used to convert between world and pixel
# Line 1651  public class XMapPane extends JPanel { Line 1620  public class XMapPane extends JPanel {
1620                  ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,                  ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1621                                  getContext().getCoordinateReferenceSystem());                                  getContext().getCoordinateReferenceSystem());
1622    
1623                  Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!                  // System.out
1624                    // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1625                  //                          if (!isWellDefined())
1626                  // 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();  
1627    
1628                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,                  worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1629                                  paintArea);                                  getVisibleRect());
1630    
                 // worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,  
                 // yoff);  
1631                  try {                  try {
1632                          screenToWorld = worldToScreen.createInverse();                          screenToWorld = worldToScreen.createInverse();
1633    
1634                  } catch (NoninvertibleTransformException ex) {                  } catch (NoninvertibleTransformException ex) {
1635                          ex.printStackTrace();                          LOGGER
1636                                            .error("can't invert worldToScreen to get screenToWorld!",
1637                                                            ex);
1638                  }                  }
1639          }          }
1640    
# Line 1690  public class XMapPane extends JPanel { Line 1653  public class XMapPane extends JPanel {
1653                  this.bgContext = context;                  this.bgContext = context;
1654    
1655                  if (context != null) {                  if (context != null) {
1656                          setMapArea(bgContext.getAreaOfInterest());                          // setMapArea(bgContext.getAreaOfInterest());
1657    
1658                          this.bgContext.addMapLayerListListener(bgContextListener);                          this.bgContext.addMapLayerListListener(bgContextListener);
1659    
# Line 1699  public class XMapPane extends JPanel { Line 1662  public class XMapPane extends JPanel {
1662                                  mapLayer.addMapLayerListener(bgMapLayerListener);                                  mapLayer.addMapLayerListener(bgMapLayerListener);
1663                          }                          }
1664                  }                  }
1665                  mapImageInvalid = true;  
1666                  repaint();                  requestStartRendering();
1667          }          }
1668    
1669          public void setJava2dHints(final RenderingHints java2dHints) {          public void setJava2dHints(final RenderingHints java2dHints) {
1670                  this.java2dHints = java2dHints;                  this.java2dHints = java2dHints;
1671          }          }
1672    
         /**  
          *  
          * @param context  
          */  
1673          public void setLocalContext(final MapContext context) {          public void setLocalContext(final MapContext context) {
1674                  // Remove the default listener from the old context                  // Remove the default listener from the old context
1675                  if (this.localContext != null) {                  if (this.localContext != null) {
# Line 1726  public class XMapPane extends JPanel { Line 1685  public class XMapPane extends JPanel {
1685    
1686                  if (context != null) {                  if (context != null) {
1687    
1688                          setMapArea(localContext.getAreaOfInterest());                          // setMapArea(localContext.getAreaOfInterest());
1689    
1690                          localRenderer.setContext(localContext);                          localRenderer.setContext(localContext);
1691    
# Line 1738  public class XMapPane extends JPanel { Line 1697  public class XMapPane extends JPanel {
1697                          }                          }
1698                  }                  }
1699    
1700                  mapImageInvalid = true;                  requestStartRendering();
1701                  repaint();  
1702            }
1703    
1704            public boolean setMapArea(final Envelope newMapArea) {
1705                    return setMapArea(new ReferencedEnvelope(newMapArea, getContext()
1706                                    .getCoordinateReferenceSystem()));
1707          }          }
1708    
1709          /**          /**
# Line 1747  public class XMapPane extends JPanel { Line 1711  public class XMapPane extends JPanel {
1711           * @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
1712           *         has been triggered.           *         has been triggered.
1713           */           */
1714          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final ReferencedEnvelope newMapArea) {
1715                    //              
1716                    // if (getVisibleRect().getWidth() == 0 || (!isVisible()) ||
1717                    // getVisibleRect().getHeight() == 0) {
1718                    // // The window is not yet defined.. so we can not really determine the
1719                    // asepect ratio for the mapPane. We store this as a candidate mappane
1720                    // and handle it when the component resizes or becomes visible)
1721                    // mapAreaCondidate = newMapArea;
1722                    // }
1723    
1724                  if (newMapArea == null                  if (newMapArea == null
1725                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {
# Line 1802  public class XMapPane extends JPanel { Line 1774  public class XMapPane extends JPanel {
1774                          bgContext.setAreaOfInterest(mapArea, localContext                          bgContext.setAreaOfInterest(mapArea, localContext
1775                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
1776                  }                  }
1777                  mapImageInvalid = true;  
1778                  mapAreaChanged = true;                  mapAreaChanged = true;
                 repaint();  
1779    
1780                  LOGGER.debug("New maparea = " + mapArea);                  repaint(100);
1781    
1782                    requestStartRendering();
1783    
1784                  return true;                  return true;
1785          }          }
1786    
# Line 1956  public class XMapPane extends JPanel { Line 1930  public class XMapPane extends JPanel {
1930           */           */
1931          private void startRendering() {          private void startRendering() {
1932    
1933                  if (!isWellDefined())                  if (!isWellDefined() || !acceptsRepaintCalls) {
1934                            requestStartRendering = true;
1935                          return;                          return;
1936                    }
1937    
1938                  if (bgExecuter != null) {                  if (bgExecuter != null) {
1939                          // Stop all renderers                          // Stop all renderers
# Line 1996  public class XMapPane extends JPanel { Line 1972  public class XMapPane extends JPanel {
1972                          localRenderer.setJava2DHints(getJava2dHints());                          localRenderer.setJava2DHints(getJava2dHints());
1973                          localRenderer.setRendererHints(getRendererHints());                          localRenderer.setRendererHints(getRendererHints());
1974    
1975                          ReferencedEnvelope areaOfInterest = getMapArea();                          final boolean submitted = localExecuter.submit(getMapArea(),
                         final boolean submitted = localExecuter.submit(areaOfInterest,  
1976                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1977                                          localRenderer, getWorldToScreenTransform());                                          localRenderer
1978                            // , getWorldToScreenTransform()
1979                                            );
1980                          if (submitted)                          if (submitted)
1981                                  repaintTimer.restart();                                  repaintTimer.restart();
1982                          else                          else
1983                                  requestStartRenderingLocal = true; // Try to start rendering again in                                  requestStartRendering = true; // Try to start rendering
1984                            // again in
1985                          // a moment                          // a moment
1986                  }                  }
1987    
# Line 2079  public class XMapPane extends JPanel { Line 2057  public class XMapPane extends JPanel {
2057                  } else {                  } else {
2058                          // Allow one last rendering                          // Allow one last rendering
2059                          if (repaintTimer.isRunning()) {                          if (repaintTimer.isRunning()) {
2060                                  System.out.println("one last rendering....");                                  // System.out.println("one last rendering....");
2061                                  repaintTimer.stop();                                  repaintTimer.stop();
2062                                  updateFinalImage();                                  updateFinalImage();
2063                                  repaint();                                  repaint();
# Line 2220  public class XMapPane extends JPanel { Line 2198  public class XMapPane extends JPanel {
2198    
2199                                  String errStr = ex.getLocalizedMessage();                                  String errStr = ex.getLocalizedMessage();
2200    
2201                                    if (errStr == null)
2202                                            errStr = ex.getMessage();
2203                                    if (errStr == null)
2204                                            errStr = "unknown error: " + ex.getClass().getSimpleName();
2205    
2206                                  graphics.setColor(Color.WHITE);                                  graphics.setColor(Color.WHITE);
2207                                  graphics.drawString(errStr, 5, y);                                  graphics.drawString(errStr, 5, y);
2208                                  graphics.setColor(Color.RED);                                  graphics.setColor(Color.RED);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26