/[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 511 by alfonx, Thu Nov 5 17:41:33 2009 UTC revision 529 by alfonx, Wed Nov 18 20:47:00 2009 UTC
# Line 20  package gtmig.org.geotools.swing; Line 20  package gtmig.org.geotools.swing;
20   * In addition to   * In addition to
21   */   */
22    
 import java.awt.AlphaComposite;  
23  import java.awt.Color;  import java.awt.Color;
24  import java.awt.Cursor;  import java.awt.Cursor;
25  import java.awt.Font;  import java.awt.Font;
# Line 41  import java.awt.geom.AffineTransform; Line 40  import java.awt.geom.AffineTransform;
40  import java.awt.geom.NoninvertibleTransformException;  import java.awt.geom.NoninvertibleTransformException;
41  import java.awt.geom.Point2D;  import java.awt.geom.Point2D;
42  import java.awt.image.BufferedImage;  import java.awt.image.BufferedImage;
 import java.beans.PropertyChangeEvent;  
 import java.beans.PropertyChangeListener;  
43  import java.io.IOException;  import java.io.IOException;
44  import java.util.HashMap;  import java.util.HashMap;
45  import java.util.Map;  import java.util.Map;
46  import java.util.Vector;  import java.util.Vector;
47    
 import javax.swing.JFrame;  
48  import javax.swing.JPanel;  import javax.swing.JPanel;
49  import javax.swing.Timer;  import javax.swing.Timer;
50    
# Line 67  import org.geotools.referencing.CRS; Line 63  import org.geotools.referencing.CRS;
63  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
64  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
65  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
66    import org.geotools.renderer.lite.StreamingRenderer;
67  import org.geotools.swing.JMapPane;  import org.geotools.swing.JMapPane;
 import org.geotools.swing.RenderingExecutor;  
68  import org.geotools.swing.event.MapMouseEvent;  import org.geotools.swing.event.MapMouseEvent;
69  import org.geotools.swing.event.MapPaneEvent;  import org.geotools.swing.event.MapPaneEvent;
70  import org.geotools.swing.event.MapPaneListener;  import org.geotools.swing.event.MapPaneListener;
# Line 84  import schmitzm.geotools.JTSUtil; Line 80  import schmitzm.geotools.JTSUtil;
80  import schmitzm.geotools.gui.SelectableXMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
81  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
82  import schmitzm.geotools.map.event.MapLayerAdapter;  import schmitzm.geotools.map.event.MapLayerAdapter;
83    import schmitzm.lang.LangUtil;
84  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
85    import skrueger.geotools.RenderingExecutor;
86    import skrueger.swing.formatter.MbDecimalFormatter;
87    
88  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
89  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
90  import com.vividsolutions.jts.geom.Geometry;  import com.vividsolutions.jts.geom.Geometry;
91    
92  public class XMapPane extends JPanel implements PropertyChangeListener {  public class XMapPane extends JPanel {
93          private static Logger LOGGER = Logger.getLogger(XMapPane.class);          private static Logger LOGGER = Logger.getLogger(XMapPane.class);
94    
95          /**          /**
# Line 175  public class XMapPane extends JPanel imp Line 174  public class XMapPane extends JPanel imp
174           */           */
175          public static final int SELECT_ONE_FROM_TOP = 104;          public static final int SELECT_ONE_FROM_TOP = 104;
176    
177          public static final long DEFAULT_REPAINTING_DELAY = 200;          /**
178             * While threads are working, we call {@link XMapPane#updateFinalImage()}
179             * regularly and repaint(). This {@link Timer} is stopped when all renderers
180             * have finished.
181             */
182            final private Timer repainterTimer;
183    
184          protected skrueger.geotools.RenderingExecutor bgExecuter;          /**
185             * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
186             * the {@link #repainterTimer} is regularly updating the {@link #finalImage}
187             * with previews.
188             */
189            public static final long REPEATING_REPAINT_DELAY = 500;
190    
191            /**
192             * The initial delay in milliseconds until the {@link #finalImage} is
193             * updated the first time.
194             */
195            public static final long INITIAL_REPAINT_DELAY = 1000;
196    
197            protected RenderingExecutor bgExecuter;
198    
199          /**          /**
200           * the map context to render           * the map context to render
# Line 199  public class XMapPane extends JPanel imp Line 216  public class XMapPane extends JPanel imp
216          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
217    
218          /**          /**
          * the size of the pane last time we drew  
          */  
         protected Rectangle oldRect = null;  
   
         /**  
          * The Renderer for the Background uses this Image. When set to null, please  
          * dispose the {@link Graphics2D}  
          */  
         protected BufferedImage bgImage;  
   
         /**  
          * The Renderer for the LocalLayers uses this Image. When set to null,  
          * please dispose this {@link Graphics2D}  
          */  
         volatile protected BufferedImage localImage;  
   
         /**  
219           * compass and icon are rendered into this image           * compass and icon are rendered into this image
220           */           */
221  //      protected BufferedImage gadgetsImage;          // protected BufferedImage gadgetsImage;
222    
223          /**          /**
224           * The default state is ZOOM_IN, hence by default the           * The default state is ZOOM_IN, hence by default the
# Line 247  public class XMapPane extends JPanel imp Line 247  public class XMapPane extends JPanel imp
247    
248                  // aktuelle Geo-Position ueber Transformation des JMapPane berechnen                  // aktuelle Geo-Position ueber Transformation des JMapPane berechnen
249                  if (e != null && e.getSource() instanceof XMapPane) {                  if (e != null && e.getSource() instanceof XMapPane) {
250                            
251                          final XMapPane xMapPane = (XMapPane) e.getSource();                          final XMapPane xMapPane = (XMapPane) e.getSource();
252                            
253                          if (!xMapPane.isWellDefined()) return null;                          if (!xMapPane.isWellDefined())
254                                                            return null;
255    
256                          AffineTransform at = xMapPane.getScreenToWorld();                          AffineTransform at = xMapPane.getScreenToWorld();
257                          if (at != null)                          if (at != null)
258                                  return at.transform(e.getPoint(), null);                                  return at.transform(e.getPoint(), null);
# Line 296  public class XMapPane extends JPanel imp Line 297  public class XMapPane extends JPanel imp
297          protected boolean paneResized = false;          protected boolean paneResized = false;
298    
299          /**          /**
          * While threads are working, we call {@link XMapPane#updateFinalImage()}  
          * regularly and repaint(). This {@link Timer} is stoppen when all renderers  
          * finished.  
          */  
         final private Timer repainterTimer;  
   
         /**  
300           * The flag {@link #requestStartRendering} can be set to true by events.           * The flag {@link #requestStartRendering} can be set to true by events.
301           * This {@link Timer} checks the flag regularly and starts one renderer           * This {@link Timer} checks the flag regularly and starts one renderer
302           * thread.           * thread.
# Line 349  public class XMapPane extends JPanel imp Line 343  public class XMapPane extends JPanel imp
343           * @param localContext           * @param localContext
344           *            - {@link MapContext} of layer to render.           *            - {@link MapContext} of layer to render.
345           */           */
346          public XMapPane(final MapContext localContext,          public XMapPane(final MapContext localContext_,
347                          Map<Object, Object> rendererHints) {                          Map<Object, Object> rendererHints) {
348                  super(true);                  super(true);
349    
# Line 357  public class XMapPane extends JPanel imp Line 351  public class XMapPane extends JPanel imp
351    
352                  setOpaque(true);                  setOpaque(true);
353    
354                  setLocalContext(localContext);                  localRenderer = GTUtil.createGTRenderer();
355                    localRenderer.setJava2DHints(getJava2dHints());
356    
357                    if (localContext_ != null)
358                            setLocalContext(localContext_);
359    
360                  /**                  /**
361                   * Adding the #zoomMapPaneMouseListener                   * Adding the #zoomMapPaneMouseListener
# Line 404  public class XMapPane extends JPanel imp Line 402  public class XMapPane extends JPanel imp
402    
403                  });                  });
404    
405                  repainterTimer = new Timer((int) DEFAULT_REPAINTING_DELAY,                  repainterTimer = new Timer((int) REPEATING_REPAINT_DELAY,
406                                  new ActionListener() {                                  new ActionListener() {
407    
408                                          @Override                                          @Override
409                                          public void actionPerformed(ActionEvent e) {                                          public void actionPerformed(ActionEvent e) {
410                                                  updateFinalImage();                                                  updateFinalImage();
411                                                  XMapPane.this.repaint(DEFAULT_REPAINTING_DELAY);                                                  XMapPane.this.repaint();
412                                          }                                          }
413                                  });                                  });
414                  repainterTimer.setInitialDelay(1000);                  repainterTimer.setInitialDelay(300);
415                  repainterTimer.setRepeats(true);                  repainterTimer.setRepeats(true);
416    
417                  startRenderThreadsTimer = new Timer(200, new ActionListener() {                  startRenderThreadsTimer = new Timer(100, new ActionListener() {
418    
419                          @Override                          @Override
420                          public void actionPerformed(ActionEvent e) {                          public void actionPerformed(ActionEvent e) {
421                                  synchronized (requestStartRendering) {                                  synchronized (requestStartRendering) {
422                                          if (requestStartRendering && isValid())                                          if (requestStartRendering && isWellDefined()) {
423                                                  startRendering();  
424                                          requestStartRendering = false;                                                  if (localExecuter.isRunning()) {
425                                                            localExecuter.cancelTask();
426                                                    } else {
427                                                            requestStartRendering = false;
428                                                            startRendering();
429                                                    }
430                                            }
431                                  }                                  }
432                          }                          }
433                  });                  });
# Line 532  public class XMapPane extends JPanel imp Line 536  public class XMapPane extends JPanel imp
536           * {@link XMapPane} is visible and has bounds set.           * {@link XMapPane} is visible and has bounds set.
537           */           */
538          public boolean isWellDefined() {          public boolean isWellDefined() {
539                    
540                  try {                  try {
541                            
542                  if (getContext() == null)                          if (getContext() == null)
543                          return false;                                  return false;
544                  if (getContext().getLayerCount() <= 0)                          if (getContext().getLayerCount() <= 0)
545                          return false;                                  return false;
546                  if (getMapArea() == null)                          if (getMapArea() == null)
547                          return false;                                  return false;
548                  if (getBounds().getWidth() == 0)                          if (getBounds().getWidth() == 0)
549                          return false;                                  return false;
550                  if (getBounds().getHeight() == 0)                          if (getBounds().getHeight() == 0)
551                          return false;                                  return false;
552                  } catch (Exception e) {                  } catch (Exception e) {
553                          return false;                          return false;
554                  }                  }
# Line 602  public class XMapPane extends JPanel imp Line 606  public class XMapPane extends JPanel imp
606          /**          /**
607           * Abhaengig von selState wird der Cursor gesetzt           * Abhaengig von selState wird der Cursor gesetzt
608           */           */
609          public void updateCursorAndRepaintTimer() {          public void updateCursor() {
610    
611                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
612                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
# Line 730  public class XMapPane extends JPanel imp Line 734  public class XMapPane extends JPanel imp
734                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
735                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
736    
737    //                      System.out.println("added a layer context, now it'S "
738    //                                      + getContext().getLayerCount() + " layers");
739    //                      ;
740    
741                            localRenderer.setContext(getContext());
742    
743                          if (localContext.getLayers().length == 1) { // the first one                          if (localContext.getLayers().length == 1) { // the first one
744                                  // if the Area of Interest is unset, the LayerBounds are used                                  // if the Area of Interest is unset, the LayerBounds are used
745                                  if (!setMapArea(localContext.getAreaOfInterest()))                                  if (!setMapArea(localContext.getAreaOfInterest()))
# Line 751  public class XMapPane extends JPanel imp Line 761  public class XMapPane extends JPanel imp
761                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
762                          // mapImageInvalid = true;                          // mapImageInvalid = true;
763                          // repaint();                          // repaint();
764                            localRenderer.setContext(getContext());
765                          requestStartRendering();                          requestStartRendering();
766                  }                  }
767    
# Line 758  public class XMapPane extends JPanel imp Line 769  public class XMapPane extends JPanel imp
769                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
770                          // mapImageInvalid = true;                          // mapImageInvalid = true;
771                          // repaint();                          // repaint();
772                            localRenderer.setContext(getContext());
773                          requestStartRendering();                          requestStartRendering();
774                  }                  }
775    
# Line 765  public class XMapPane extends JPanel imp Line 777  public class XMapPane extends JPanel imp
777                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
778                          // mapImageInvalid = true;                          // mapImageInvalid = true;
779                          // repaint();                          // repaint();
780                            localRenderer.setContext(getContext());
781                          requestStartRendering();                          requestStartRendering();
782                  }                  }
783          };          };
# Line 841  public class XMapPane extends JPanel imp Line 854  public class XMapPane extends JPanel imp
854    
855                  @Override                  @Override
856                  public void layerChanged(MapLayerEvent event) {                  public void layerChanged(MapLayerEvent event) {
857                            localRenderer.setContext(getContext()); // betters for SLD changes?!
858                          // Change of SLD for example                          // Change of SLD for example
859                          // mapImageInvalid = true;                          // mapImageInvalid = true;
860                          // repaint();                          // repaint();
# Line 903  public class XMapPane extends JPanel imp Line 917  public class XMapPane extends JPanel imp
917    
918          public MapContext getContext() {          public MapContext getContext() {
919                  if (localContext == null) {                  if (localContext == null) {
920                          this.localContext = new DefaultMapContext();                          setLocalContext(new DefaultMapContext());
                         this.localContext.addMapLayerListListener(localContextListener);  
921                  }                  }
922                  return localContext;                  return localContext;
923          }          }
# Line 931  public class XMapPane extends JPanel imp Line 944  public class XMapPane extends JPanel imp
944                  this.localContext = context;                  this.localContext = context;
945    
946                  if (context != null) {                  if (context != null) {
947    
948                          setMapArea(localContext.getAreaOfInterest());                          setMapArea(localContext.getAreaOfInterest());
949    
950                            localRenderer.setContext(localContext);
951    
952                          this.localContext.addMapLayerListListener(localContextListener);                          this.localContext.addMapLayerListListener(localContextListener);
953    
954                          // adding listener to all layers                          // adding listener to all layers
# Line 980  public class XMapPane extends JPanel imp Line 996  public class XMapPane extends JPanel imp
996           */           */
997          public Envelope getMapArea() {          public Envelope getMapArea() {
998                  if (mapArea == null) {                  if (mapArea == null) {
999                          final Rectangle paneBounds = getBounds();                          ReferencedEnvelope mapArea_ = null;
   
1000                          try {                          try {
1001                                  mapArea = localContext.getLayerBounds();                                  mapArea_ = localContext.getLayerBounds();
1002                          } catch (final IOException e) {                          } catch (final IOException e) {
1003                                  LOGGER.warn("context.getLayerBounds()", e);                                  LOGGER.warn("context.getLayerBounds()", e);
1004                          }                          }
1005    
1006                          if (mapArea != null) {                          if (mapArea_ != null) {
                                 /* either the viewer size has changed or we've done a reset */  
1007                                  mapImageInvalid = true; /* note we need to redraw */                                  mapImageInvalid = true; /* note we need to redraw */
1008                                  oldRect = paneBounds; /* store what the current size is */                                  setMapArea(mapArea_);
                                 mapArea = bestAllowedMapArea(mapArea);  
1009                          }                          }
1010                  }                  }
1011    
# Line 1015  public class XMapPane extends JPanel imp Line 1028  public class XMapPane extends JPanel imp
1028                          return false;                          return false;
1029                  }                  }
1030    
1031                  // Testen, ob der Unterschied nur im minimalen Rundungsfehlerbereich                  // Testing, whether NaN or Infinity are used in the newMapArea
1032                  // liegt                  if (newMapArea.isNull() || Double.isInfinite(newMapArea.getMaxX())
1033                                    || Double.isInfinite(newMapArea.getMaxY())
1034                                    || Double.isInfinite(newMapArea.getMinX())
1035                                    || Double.isInfinite(newMapArea.getMinY())) {
1036                            // No change.. ugly new values
1037                            LOGGER.warn("setMapArea has been called with newArea = "
1038                                            + newMapArea);
1039                            return false;
1040                    }
1041    
1042                    // Testing, whether the difference if just minimal
1043                  if (mapArea != null) {                  if (mapArea != null) {
1044                          Envelope candNew = bestAllowedMapArea(newMapArea);                          Envelope candNew = bestAllowedMapArea(newMapArea);
1045                          double tolX = mapArea.getWidth() / 1000.;                          double tolX = mapArea.getWidth() / 1000.;
# Line 1040  public class XMapPane extends JPanel imp Line 1063  public class XMapPane extends JPanel imp
1063    
1064                  oldMapArea = mapArea;                  oldMapArea = mapArea;
1065    
                 System.out.println("requested setting to \\t" + newMapArea);  
1066                  this.mapArea = bestAllowedMapArea(newMapArea);                  this.mapArea = bestAllowedMapArea(newMapArea);
                 System.out.println("set to \\t\\ŧ" + newMapArea);  
1067    
1068                  if (localContext != null) {                  if (localContext != null) {
1069                          localContext.setAreaOfInterest(mapArea, localContext                          localContext.setAreaOfInterest(mapArea, localContext
# Line 1056  public class XMapPane extends JPanel imp Line 1077  public class XMapPane extends JPanel imp
1077                  mapImageInvalid = true;                  mapImageInvalid = true;
1078                  mapAreaChanged = true;                  mapAreaChanged = true;
1079                  repaint();                  repaint();
1080    
1081                    // LOGGER.debug("New maparea = " + mapArea);
1082                  return true;                  return true;
1083          }          }
1084    
# Line 1076  public class XMapPane extends JPanel imp Line 1099  public class XMapPane extends JPanel imp
1099                                  || state == ZOOM_OUT || state == PAN));                                  || state == ZOOM_OUT || state == PAN));
1100    
1101                  // Je nach Aktion den Cursor umsetzen                  // Je nach Aktion den Cursor umsetzen
1102                  updateCursorAndRepaintTimer();                  updateCursor();
1103          }          }
1104    
1105          /** Cursor wenn kein Mausbutton gedrueckt wird. default oder SwingUtil.PAN **/          /** Cursor wenn kein Mausbutton gedrueckt wird. default oder SwingUtil.PAN **/
# Line 1088  public class XMapPane extends JPanel imp Line 1111  public class XMapPane extends JPanel imp
1111    
1112          public static final int NONE = -123;          public static final int NONE = -123;
1113    
1114          private skrueger.geotools.RenderingExecutor localExecuter;          private RenderingExecutor localExecuter = new RenderingExecutor(this);
   
         private BufferedImage finalImage;  
1115    
1116          /**          /**
1117           * A flag set it {@link #setMapArea(Envelope)} to indicated the           * A flag set it {@link #setMapArea(Envelope)} to indicated the
# Line 1101  public class XMapPane extends JPanel imp Line 1122  public class XMapPane extends JPanel imp
1122           **/           **/
1123          private boolean mapAreaChanged = false;          private boolean mapAreaChanged = false;
1124    
         private JFrame finalImageFrame;  
   
1125          private volatile Boolean requestStartRendering = false;          private volatile Boolean requestStartRendering = false;
         private BufferedImage preFinalImage;  
1126    
1127          protected void paintComponent(final Graphics g) {          /**
1128                  // Maybe update the cursor           * The Renderer for the Background uses this Image. When set to null, please
1129                  updateCursorAndRepaintTimer();           * dispose the {@link Graphics2D}
1130             */
1131            private BufferedImage bgImage;// = new
1132            // BufferedImage(600,600,BufferedImage.TYPE_INT_ARGB);
1133    
1134            private BufferedImage finalImage;
1135    
1136            /**
1137             * The Renderer for the LocalLayers uses this Image. When set to null,
1138             * please dispose this {@link Graphics2D}
1139             */
1140            private BufferedImage localImage;// = new
1141            // BufferedImage(600,600,BufferedImage.TYPE_INT_ARGB);
1142            private BufferedImage preFinalImage;// = new
1143    
1144            // BufferedImage(600,600,BufferedImage.TYPE_INT_ARGB);
1145    
1146            protected void paintComponent(final Graphics g) {
1147                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1148                          return;                          return;
1149                    
1150                    // Maybe update the cursor
1151                    updateCursor();
1152                    
1153                    super.paintComponent(g);
1154    
1155                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1156    
# Line 1140  public class XMapPane extends JPanel imp Line 1179  public class XMapPane extends JPanel imp
1179    
1180                          if (paneResized) {                          if (paneResized) {
1181                                  paneResized = false;                                  paneResized = false;
1182                                  preFinalImage = null;  
1183                                  finalImage = null;                                  // if (preFinalImage != null)
1184                                  localImage = null;                                  // preFinalImage.flush();
1185                                  bgImage = null;                                  // preFinalImage = null;
1186  //                              gadgetsImage = null;                                  // if (finalImage != null) {
1187                                    // finalImage.flush();
1188                                    // }
1189                                    // finalImage = null;
1190                                    // if (localImage != null)
1191                                    // localImage.flush();
1192                                    // localImage = null;
1193                                    // if (bgImage != null)
1194                                    // bgImage.flush();
1195                                    // bgImage = null;
1196    
1197                                    // gadgetsImage = null;
1198                          }                          }
1199    
1200                          // Start the Threads and Timers to render the image                          // Start the Threads and Timers to render the image
# Line 1157  public class XMapPane extends JPanel imp Line 1207  public class XMapPane extends JPanel imp
1207                          // TODO Should just paint the getFinalImage(). Update should be                          // TODO Should just paint the getFinalImage(). Update should be
1208                          // called by timer every 300ms, and the repaint() until all threads                          // called by timer every 300ms, and the repaint() until all threads
1209                          // are done.                          // are done.
1210                          g.drawImage(getFinalImage(), 0, 0, this);                          g.drawImage(getFinalImage(), 0, 0, null);
1211    
1212                            g.dispose();
1213    
1214                          paintedSomething = true;                          paintedSomething = true;
1215                  }                  }
# Line 1175  public class XMapPane extends JPanel imp Line 1227  public class XMapPane extends JPanel imp
1227                  if (localExecuter != null)                  if (localExecuter != null)
1228                          localExecuter.cancelTask();                          localExecuter.cancelTask();
1229                  requestStartRendering = true;                  requestStartRendering = true;
1230    
1231          }          }
1232    
1233          /**          /**
# Line 1233  public class XMapPane extends JPanel imp Line 1286  public class XMapPane extends JPanel imp
1286           * to give the user something to look at while we are rendering. Method           * to give the user something to look at while we are rendering. Method
1287           * should be called after {@link #setMapArea(Envelope)} has been set to the           * should be called after {@link #setMapArea(Envelope)} has been set to the
1288           * new mapArea and transform has been reset.<br/>           * new mapArea and transform has been reset.<br/>
          * This method does nothing if the {@link #lastRenderingDuration} is smaller  
          * then a trashhold.  
1289           *           *
1290           * @param g           * @param g
1291           *            Graphics2D to paint the preview into           *            Graphics2D to paint the preview into
# Line 1273  public class XMapPane extends JPanel imp Line 1324  public class XMapPane extends JPanel imp
1324                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1325                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
1326                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
                   
1327    
1328                  Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 - yy1);                  Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 - yy1);
1329    
1330                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea);
1331                    
1332                  addGadgets(graphics);                  addGadgets(graphics);
 //              graphics.drawImage(getGadgetsImage(), 0,0, (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),null);  
1333    
1334                  quickPreviewHint = 0;                  quickPreviewHint = 0;
1335    
1336                  graphics.dispose();                  graphics.dispose();
1337    
1338                  // Something has been drawn                  // Something has been drawn
1339                  return true;                  return true;
1340          }          }
1341            
1342          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
1343    
1344          /**          /**
1345           * Paints some optinal stuff into the given {@link Graphics2D}. Usually called as the last paint on the mapImage.           * Paints some optinal stuff into the given {@link Graphics2D}. Usually
1346             * called as the last paint on the mapImage.
1347           */           */
1348          private void addGadgets(Graphics2D graphics) {          private void addGadgets(Graphics2D graphics) {
1349    
1350                  if (mapImage != null)                  if (mapImage != null)
1351                          graphics.drawImage(mapImage,                          graphics.drawImage(mapImage, getBounds().width
1352                                          getBounds().width - mapImage.getWidth() - 10,                                          - mapImage.getWidth() - 10, getBounds().height
1353                                          getBounds().height - mapImage.getHeight() - 10, this);                                          - mapImage.getHeight() - 10, null);
1354    
1355                  // If still rendering, paint a gray shadow or so...                  // If still rendering, paint a gray shadow or so...
1356                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
1357                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
1358    
1359                            Color c = graphics.getColor();
1360                          graphics.setColor(Color.BLACK);                          graphics.setColor(Color.BLACK);
1361                            
1362                          graphics.setFont(waitFont);                          graphics.setFont(waitFont);
1363                          graphics.drawString("Wait...", 40, 70);                          graphics.drawString("Wait...", 40, 70); // i8n
1364    
1365                            graphics.setColor(c);
1366                  }                  }
1367                    
1368          }          }
1369    
1370          /**          /**
# Line 1317  public class XMapPane extends JPanel imp Line 1372  public class XMapPane extends JPanel imp
1372           *           *
1373           * @return           * @return
1374           */           */
1375          synchronized protected BufferedImage updateFinalImage() {          synchronized protected Image updateFinalImage() {
1376    
                 final Graphics2D finalG = (Graphics2D) getFinalImage().getGraphics();  
                 finalG.setBackground(getMapBackgroundColor());  
                   
                   
1377                  // Render the two map images first, into the preFinalImage                  // Render the two map images first, into the preFinalImage
1378                  {                  if (bgExecuter != null) {
1379                          final Graphics2D preFinalG = (Graphics2D) getPreFinalImage().getGraphics();                          final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()
1380                                            .getGraphics();
1381                          preFinalG.setBackground(getMapBackgroundColor());                          preFinalG.setBackground(getMapBackgroundColor());
1382                            
1383                          preFinalG.drawImage(getBgImage(), 0, 0,                          preFinalG.drawImage(getBgImage(), 0, 0, getMapBackgroundColor(),
1384                                          getMapBackgroundColor(), null);                                          null);
1385    
1386                          // // Draw the local layers image                          // // Draw the local layers image
1387                          preFinalG.drawImage(getLocalImage(), 0, 0, null);                          preFinalG.drawImage(getLocalImage(), 0, 0, null);
1388                          preFinalG.dispose();                          preFinalG.dispose();
1389    
1390                    } else {
1391                            preFinalImage = getLocalImage();
1392                  }                  }
1393                    
1394                    final Graphics2D finalG = getFinalImage().createGraphics();
1395                    finalG.setBackground(getMapBackgroundColor());
1396                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
1397                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
1398    
                 // System.out.println(new Date().getTime() - startTime +  
                 // "ms for update");  
                 //  
                 // if (finalImageFrame == null) {  
                 // finalImageFrame = new JFrame();  
                 // finalImageFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);  
                 // SwingUtil.setRelativeFramePosition(finalImageFrame, 0, 0);  
                 // }  
                 // finalImageFrame.setContentPane(new JLabel(new  
                 // ImageIcon(finalImage)));  
                 // finalImageFrame.pack();  
                 // finalImageFrame.setVisible(true);  
   
1399                  final int finalImageHeight = getFinalImage().getHeight(null);                  final int finalImageHeight = getFinalImage().getHeight(null);
1400                  final int finalImageWidth = getFinalImage().getWidth(null);                  final int finalImageWidth = getFinalImage().getWidth(null);
1401    
# Line 1359  public class XMapPane extends JPanel imp Line 1404  public class XMapPane extends JPanel imp
1404                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
1405    
1406                  addGadgets(finalG);                  addGadgets(finalG);
 //              finalG.drawImage(getGadgetsImage(), 0, 0, null);  
1407    
1408                  finalG.dispose();                  finalG.dispose();
1409    
1410                  return finalImage;                  return finalImage;
1411          }          }
1412    
1413          /*          private BufferedImage getFinalImage() {
1414           * Set alpha composite. For example, pass in 1.0f to have 100% opacity pass                  //
          * in 0.25f to have 25% opacity.  
          */  
         private AlphaComposite makeComposite(float alpha) {  
                 int type = AlphaComposite.SRC_OVER;  
                 return (AlphaComposite.getInstance(type, alpha));  
         }  
   
         private Image getFinalImage() {  
   
1415                  if (finalImage == null) {                  if (finalImage == null) {
1416                          finalImage = null;                          // Rectangle curPaintArea = getVisibleRect();
1417                          Rectangle curPaintArea = getVisibleRect();                          finalImage = new BufferedImage(getBounds().width,
1418                          finalImage = new BufferedImage(curPaintArea.width,                                          getBounds().height, BufferedImage.TYPE_INT_RGB);
                                         curPaintArea.height, BufferedImage.TYPE_INT_RGB);  
1419    
1420                          requestStartRendering();                          requestStartRendering();
1421                  }                  }
1422                  return finalImage;                  return finalImage;
1423          }          }
           
         private Image getPreFinalImage() {  
                   
                 if (preFinalImage == null) {  
                         preFinalImage = null;  
                         Rectangle curPaintArea = getVisibleRect();  
1424    
1425                          preFinalImage = new BufferedImage(curPaintArea.width,          private Image getPreFinalImage() {
1426                                          curPaintArea.height, BufferedImage.TYPE_INT_RGB);                  // if (preFinalImage == null) {
1427                                            //                      
1428                          requestStartRendering();                  // // Rectangle curPaintArea = getVisibleRect();
1429                  }                  // // preFinalImage = new BufferedImage(curPaintArea.width,
1430                    // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);
1431                    //                      
1432                    // preFinalImage = createImage(getBounds().width, getBounds().height);
1433                    //
1434                    // requestStartRendering();
1435                    // }
1436                  return preFinalImage;                  return preFinalImage;
1437          }          }
1438    
# Line 1407  public class XMapPane extends JPanel imp Line 1441  public class XMapPane extends JPanel imp
1441           * cached images while setting it together.           * cached images while setting it together.
1442           **/           **/
1443          Point imageOrigin = new Point(0, 0);          Point imageOrigin = new Point(0, 0);
1444            private final GTRenderer localRenderer;
1445    
1446          /**          /**
1447           * Starts rendering on one or two threads           * Starts rendering on one or two threads
# Line 1416  public class XMapPane extends JPanel imp Line 1451  public class XMapPane extends JPanel imp
1451                  if (!isWellDefined())                  if (!isWellDefined())
1452                          return;                          return;
1453    
1454                  if (bgExecuter != null)                  if (bgExecuter != null) {
1455                          // Stop all renderers                          // Stop all renderers
1456                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1457                    }
1458    
1459                  if (localExecuter != null)                  if (localExecuter != null) {
1460                          localExecuter.cancelTask();                          localExecuter.cancelTask();
1461                  //                  }
                 //  
                 // LOGGER.debug("stopping any running renderes:");  
                 // int count = 0;  
                 // while (bgExecuter.isRunning() || localExecuter.isRunning()) {  
                 // LOGGER.debug("waiting for threads to stop");  
                 //  
                 // bgExecuter.cancelTask();  
                 // localExecuter.cancelTask();  
                 //  
                 // count++;  
                 //  
                 // try {  
                 // Thread.sleep(100);  
                 // } catch (InterruptedException e) {  
                 // LOGGER.error(e);  
                 // }  
                 //  
                 // if (count > 100) {  
                 // throw new RuntimeException(  
                 // "Unable to stop rendering thread for 10secs");  
                 // }  
                 // }  
                 // LOGGER.debug(" threads stopped after " + count / 10. + "secs");  
1462    
1463                  Rectangle curPaintArea = getVisibleRect();                  Rectangle curPaintArea = getVisibleRect();
1464    
                 // allow a single pixel margin at the right and bottom edges  
                 curPaintArea.width -= 1;  
                 curPaintArea.height -= 1;  
   
                 labelCache.clear();  
   
                 /**  
                  */  
1465    
1466                  /**                  /**
1467                   * We have to set new renderer                   * We have to set new renderer
1468                   */                   */
1469    
1470                  if (getBgContext() != null) {                  if (getBgContext() != null) {
1471                          bgExecuter = new skrueger.geotools.RenderingExecutor(this);                          // bgExecuter = new RenderingExecutor();
1472                          LOGGER.debug("starting bg renderer:");                          // LOGGER.debug("starting bg renderer:");
1473                          // /* System.out.println("rendering"); */                          // // /* System.out.println("rendering"); */
1474                          final GTRenderer createGTRenderer = GTUtil.createGTRenderer(                          // final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
1475                                          localContext, getRendererHints());                          // bgContext, getRendererHints());
1476                          createGTRenderer.setJava2DHints(getJava2dHints());                          // createGTRenderer.setJava2DHints(getJava2dHints());
1477                          bgExecuter.submit(getBgContext().getAreaOfInterest(), curPaintArea,                          // bgExecuter.submit(getBgContext().getAreaOfInterest(),
1478                                          (Graphics2D) getBgImage().getGraphics(), createGTRenderer);                          // curPaintArea,
1479                            // (Graphics2D) getBgImage().getGraphics(), createGTRenderer);
1480                  }                  }
1481    
1482                  if (getContext() != null) {                  if (getContext() != null) {
1483                          localExecuter = new skrueger.geotools.RenderingExecutor(this);                          // localExecuter = new RenderingExecutor(this, 150l);
1484                          LOGGER.debug("starting local renderer:");  //                      LOGGER.debug("starting local renderer:");
1485                          final GTRenderer createGTRenderer = GTUtil.createGTRenderer(                          
1486                                          localContext, getRendererHints());                          // Clear label cache
1487                          createGTRenderer.setJava2DHints(getJava2dHints());                          labelCache.clear();
1488                          localExecuter.submit(getContext().getAreaOfInterest(),                          Map<Object, Object> rh = localRenderer.getRendererHints();
1489                            rh.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
1490                            localRenderer.setRendererHints(rh);
1491    
1492                            boolean submitted = localExecuter.submit(getContext().getAreaOfInterest(),
1493                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1494                                          createGTRenderer);                                          localRenderer, getWorldToScreenTransform());
1495                            if (submitted) repainterTimer.restart();
1496                            else requestStartRendering = true; // Try to start rendering again in a moment
1497                  }                  }
1498    
1499                  updateCursorAndRepaintTimer();                  updateCursor();
   
                 // start regular repaints until all renderers are done.  
                 repainterTimer.setRepeats(true);  
                 repainterTimer.restart();  
1500    
1501          }          }
1502    
1503          /**          /**
1504           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1505           */           */
1506          private BufferedImage getBgImage() {          private Image getBgImage() {
1507                    //
1508                  if (bgImage == null) {                  // if (bgImage == null) {
1509                          LOGGER.debug("creating a new background image");                  // bgImage = createImage(getBounds().width, getBounds().height);
1510                    // }
                         Rectangle curPaintArea = getVisibleRect();  
                         // allow a single pixel margin at the right and bottom edges  
                         curPaintArea.width -= 1;  
                         curPaintArea.height -= 1;  
   
                         bgImage = new BufferedImage(curPaintArea.width + 1,  
                                         curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);  
                 }  
1511    
1512                  return bgImage;                  return bgImage;
1513          }          }
# Line 1535  public class XMapPane extends JPanel imp Line 1535  public class XMapPane extends JPanel imp
1535           */           */
1536          public void setMapImage(BufferedImage mapImage) {          public void setMapImage(BufferedImage mapImage) {
1537                  this.mapImage = mapImage;                  this.mapImage = mapImage;
 //              gadgetsImage = null;  
1538          }          }
1539    
1540          /**          /**
# Line 1544  public class XMapPane extends JPanel imp Line 1543  public class XMapPane extends JPanel imp
1543          private BufferedImage getLocalImage() {          private BufferedImage getLocalImage() {
1544    
1545                  if (localImage == null) {                  if (localImage == null) {
1546                          LOGGER.debug("creating a new local image");                          localImage = new BufferedImage(getBounds().width,
1547                                            getBounds().height, BufferedImage.TYPE_INT_ARGB);
                         Rectangle curPaintArea = getVisibleRect();  
                         // allow a single pixel margin at the right and bottom edges  
                         curPaintArea.width -= 1;  
                         curPaintArea.height -= 1;  
   
                         localImage = new BufferedImage(curPaintArea.width + 1,  
                                         curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);  
1548                  }                  }
1549    
1550                  return localImage;                  return localImage;
1551          }          }
 //  
 //      /**  
 //       * Lazyly initializes a {@link BufferedImage} for the background renderer.  
 //       */  
 //      private BufferedImage getGadgetsImage() {  
 //  
 //              if (gadgetsImage == null) {  
 //                      LOGGER.debug("creating a new gadgets image");  
 //  
 //                      Rectangle curPaintArea = getVisibleRect();  
 //                      // allow a single pixel margin at the right and bottom edges  
 //                      curPaintArea.width -= 1;  
 //                      curPaintArea.height -= 1;  
 //  
 //                      gadgetsImage = new BufferedImage(curPaintArea.width + 1,  
 //                                      curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);  
 //  
 //                      if (mapImage != null)  
 //                              gadgetsImage.getGraphics().drawImage(mapImage,  
 //                                              curPaintArea.width - mapImage.getWidth() - 10,  
 //                                              curPaintArea.height - mapImage.getHeight() - 10, this);  
 //                        
 //              }  
 //  
 //              return gadgetsImage;  
 //      }  
1552    
1553          /**          /**
1554           * Called by the {@linkplain XMapPane.RenderingTask} when rendering has been           * Called by the {@linkplain XMapPane.RenderingTask} when rendering has been
# Line 1592  public class XMapPane extends JPanel imp Line 1558  public class XMapPane extends JPanel imp
1558           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1559           */           */
1560          public void onRenderingCompleted() {          public void onRenderingCompleted() {
1561                  System.out.println("onRenderingCompleted");                  repainterTimer.stop();
   
1562                  updateFinalImage();                  updateFinalImage();
   
1563                  repaint();                  repaint();
   
1564          }          }
1565    
1566          /**          /**
# Line 1608  public class XMapPane extends JPanel imp Line 1571  public class XMapPane extends JPanel imp
1571           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1572           */           */
1573          public void onRenderingCancelled() {          public void onRenderingCancelled() {
1574                    repainterTimer.stop();
1575                  LOGGER.debug("Rendering cancelled");                  LOGGER.debug("Rendering cancelled");
1576          }          }
1577    
# Line 1622  public class XMapPane extends JPanel imp Line 1586  public class XMapPane extends JPanel imp
1586           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1587           */           */
1588          public void onRenderingFailed(Exception renderingError) {          public void onRenderingFailed(Exception renderingError) {
1589                  // MapPaneEvent ev = new MapPaneEvent(this,                  repainterTimer.stop();
                 // MapPaneEvent.Type.RENDERING_STOPPED);  
                 // publishEvent(ev);  
1590                  LOGGER.warn("Rendering failed", renderingError);                  LOGGER.warn("Rendering failed", renderingError);
1591                  updateFinalImage();                  updateFinalImage();
1592                  repaint();                  repaint();
# Line 1632  public class XMapPane extends JPanel imp Line 1594  public class XMapPane extends JPanel imp
1594          }          }
1595    
1596          /**          /**
          * Called when a rendering request has been rejected. This will be common,  
          * such as when the user pauses during drag-resizing fo the map pane. The  
          * base implementation does nothing. It is provided for sub-classes to  
          * override if required.  
          */  
         public void onRenderingRejected() {  
                 LOGGER.warn("Rendering rejected");  
                 repaint();  
         }  
   
         @Override  
         public void propertyChange(final PropertyChangeEvent evt) {  
                 final String prop = evt.getPropertyName();  
   
                 if (prop.equalsIgnoreCase("crs")) {  
                         localContext.setAreaOfInterest(localContext.getAreaOfInterest(),  
                                         (CoordinateReferenceSystem) evt.getNewValue());  
                 }  
         }  
   
         // xulu.sn  
         /**  
1597           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
1598           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
1599           * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/>           * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/>
# Line 1821  public class XMapPane extends JPanel imp Line 1761  public class XMapPane extends JPanel imp
1761                                                          false);                                                          false);
1762                                  }                                  }
1763                          }                          }
   
1764                  }                  }
1765    
1766                  return newArea;                  return newArea;
# Line 1972  public class XMapPane extends JPanel imp Line 1911  public class XMapPane extends JPanel imp
1911                  mapPaneListeners.remove(l);                  mapPaneListeners.remove(l);
1912          }          }
1913    
1914          /** Stored the time used for the last real rendering in ms. **/  //      /** Stored the time used for the last real rendering in ms. **/
1915          private long lastRenderingDuration = Long.MAX_VALUE;  //      private long lastRenderingDuration = Long.MAX_VALUE;
1916    
1917          // if null, no quick preview will be shown          // if null, no quick preview will be shown
1918          private int quickPreviewHint = 0;          private int quickPreviewHint = 0;
# Line 1987  public class XMapPane extends JPanel imp Line 1926  public class XMapPane extends JPanel imp
1926           */           */
1927          private RenderingHints java2dHints;          private RenderingHints java2dHints;
1928    
1929          /**  //      /**
1930           * Returns in milli seconds the time the last rending of the  //       * Returns in milli seconds the time the last rending of the
1931           * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has not  //       * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has not
1932           * been rendered yet.  //       * been rendered yet.
1933           */  //       */
1934          public long getLastRenderingDuration() {  //      public long getLastRenderingDuration() {
1935                  return lastRenderingDuration;  //              return lastRenderingDuration;
1936          }  //      }
1937    
1938          /**          /**
1939           * Should be called when the {@link JMapPane} is not needed no more to help           * Should be called when the {@link JMapPane} is not needed no more to help
# Line 2009  public class XMapPane extends JPanel imp Line 1948  public class XMapPane extends JPanel imp
1948                  if (isDisposed())                  if (isDisposed())
1949                          return;                          return;
1950    
1951                    setPainting(false);
1952                    
1953                    resizeTimer.stop();
1954                    startRenderThreadsTimer.stop();
1955    
1956                  disposed = true;                  disposed = true;
1957    
1958                  if (bgExecuter != null) {                  if (bgExecuter != null) {
1959                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1960                            bgExecuter.dispose();
1961                  }                  }
1962    
1963                  if (localExecuter != null) {                  if (localExecuter != null) {
1964                            int i = 0;
1965                          localExecuter.cancelTask();                          localExecuter.cancelTask();
1966                            while (i++ < 10 && localExecuter.isRunning()){
1967                                    try {
1968                                            Thread.sleep(200);
1969                                    } catch (InterruptedException e) {
1970                                            // TODO Auto-generated catch block
1971                                            e.printStackTrace();
1972                                    }
1973                            }
1974                            if (localExecuter.isRunning()) {
1975                                    System.out.println("BAD BAD BAD... still running the thread....");
1976                            }
1977                            localExecuter.dispose();
1978                  }                  }
1979    
                 startRenderThreadsTimer.stop();  
                 repainterTimer.stop();  
1980    
1981                  if (bgImage != null)                  if (bgImage != null) {
1982                          bgImage.flush();                          bgImage = dispose(bgImage);
1983                  if (localImage != null)                          bgImage = null;
1984                          localImage.flush();  //                      LangUtil.gcTotal();
1985  //              if (gadgetsImage != null)                  }
1986  //                      gadgetsImage.flush();  
1987                  if (finalImage != null)                  if (localImage != null) {
1988                          finalImage.flush();                          localImage = dispose(localImage);
1989                  if (preFinalImage != null)                          localImage = null;
1990                          preFinalImage.flush();  //                      LangUtil.gcTotal();
1991                    }
1992                  // if (dragWaitCursorListener != null)  
1993                  // this.removeMouseListener(dragWaitCursorListener);                  if (finalImage != null) {
1994                  // if (mouseWheelZoomListener != null)                          finalImage = dispose(finalImage);
1995                  // this.removeMouseWheelListener(mouseWheelZoomListener);                          finalImage = null;
1996    //                      LangUtil.gcTotal();
1997                    }
1998    
1999                    if (preFinalImage != null) {
2000                            preFinalImage = dispose(preFinalImage);
2001                            preFinalImage=null;
2002                    }
2003                    
2004    //              LangUtil.gcTotal();
2005    
2006                  // Alle mapPaneListener entfernen                  // Alle mapPaneListener entfernen
2007                  mapPaneListeners.clear();                  mapPaneListeners.clear();
# Line 2052  public class XMapPane extends JPanel imp Line 2017  public class XMapPane extends JPanel imp
2017                  removeAll();                  removeAll();
2018          }          }
2019    
2020            private BufferedImage dispose(BufferedImage bi) {
2021    
2022    //              System.out.println("vorher = "
2023    //                      + new MbDecimalFormatter().format(LangUtil.gcTotal()));
2024                    bi.flush();
2025                    return bi = null;
2026    //              System.out.println("nacher = "
2027    //                              + new MbDecimalFormatter().format(LangUtil.gcTotal()));
2028    //
2029    //              System.out.println("\n");
2030            }
2031    
2032          /**          /**
2033           * A flag indicating if dispose() has already been called. If true, then           * A flag indicating if dispose() has already been called. If true, then
2034           * further use of this {@link SelectableXMapPane} is undefined.           * further use of this {@link SelectableXMapPane} is undefined.
# Line 2087  public class XMapPane extends JPanel imp Line 2064  public class XMapPane extends JPanel imp
2064    
2065                  Point2D gcenter = getScreenToWorld().transform(center, null);                  Point2D gcenter = getScreenToWorld().transform(center, null);
2066                  center = null;                  center = null;
2067                    
2068                  if (                  if (Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())
2069                                  Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())                                  || Double.isInfinite(gcenter.getX())
2070                                  ||                                  || Double.isInfinite(gcenter.getY())
2071                                  Double.isInfinite(gcenter.getX()) || Double.isInfinite(gcenter.getY())  
                                   
2072                  ) {                  ) {
2073                          // Not inside valid CRS area! cancel                          // Not inside valid CRS area! cancel
2074                          return;                          return;
2075                  }                  }
2076    
2077                  final Envelope mapArea = getMapArea();                  final Envelope mapArea = getMapArea();
2078                    
2079                  Envelope newMapArea = new Envelope(mapArea);                  Envelope newMapArea = new Envelope(mapArea);
2080                  newMapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2081                                  .expandBy((mapArea.getWidth() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2082                                                  .getWidth()) / 2., (mapArea.getHeight()                                  .getHeight()) / 2.);
                                                 * zoomFaktor - mapArea.getHeight()) / 2.);  
2083    
2084                  // Move the newMapArea above the new center                  // Move the newMapArea above the new center
2085                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter.getY()                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2086                                    .getY()
2087                                  - mapArea.centre().y);                                  - mapArea.centre().y);
2088    
2089                  setMapArea(newMapArea);                  setMapArea(newMapArea);
# Line 2195  public class XMapPane extends JPanel imp Line 2171  public class XMapPane extends JPanel imp
2171                                  drawRectangle(graphics, startPos, lastPos);                                  drawRectangle(graphics, startPos, lastPos);
2172                          }                          }
2173    
2174                            graphics.dispose();
2175    
2176                  }                  }
2177    
2178          }          }
# Line 2205  public class XMapPane extends JPanel imp Line 2183  public class XMapPane extends JPanel imp
2183           */           */
2184          protected void drawRectangle(final Graphics graphics, Point startPos,          protected void drawRectangle(final Graphics graphics, Point startPos,
2185                          Point e) {                          Point e) {
2186    
2187                    if (!isWellDefined())
2188                            return;
2189    
2190                  // undraw last box/draw new box                  // undraw last box/draw new box
2191                  final int left = Math.min(startPos.x, e.x);                  final int left = Math.min(startPos.x, e.x);
2192                  final int right = Math.max(startPos.x, e.x);                  final int right = Math.max(startPos.x, e.x);
# Line 2232  public class XMapPane extends JPanel imp Line 2214  public class XMapPane extends JPanel imp
2214                  imageOrigin.x = 0;                  imageOrigin.x = 0;
2215                  imageOrigin.y = 0;                  imageOrigin.y = 0;
2216    
2217                  if (!setMapArea(newMapArea)){                  if (!setMapArea(newMapArea)) {
2218                          updateFinalImage();                          updateFinalImage();
2219                          repaint();                          repaint();
2220                  }                  }
# Line 2241  public class XMapPane extends JPanel imp Line 2223  public class XMapPane extends JPanel imp
2223                          setCursor(SwingUtil.PAN_CURSOR);                          setCursor(SwingUtil.PAN_CURSOR);
2224          }          }
2225    
2226            public void onRenderingPending() {
2227                    // LOGGER.debug("Pending rendering updates the preview...");
2228                    updateFinalImage();
2229                    repaint();
2230            }
2231    
2232  }  }

Legend:
Removed from v.511  
changed lines
  Added in v.529

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26