/[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 521 by alfonx, Tue Nov 17 12:51:37 2009 UTC
# Line 68  import org.geotools.renderer.GTRenderer; Line 68  import org.geotools.renderer.GTRenderer;
68  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
69  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
70  import org.geotools.swing.JMapPane;  import org.geotools.swing.JMapPane;
 import org.geotools.swing.RenderingExecutor;  
71  import org.geotools.swing.event.MapMouseEvent;  import org.geotools.swing.event.MapMouseEvent;
72  import org.geotools.swing.event.MapPaneEvent;  import org.geotools.swing.event.MapPaneEvent;
73  import org.geotools.swing.event.MapPaneListener;  import org.geotools.swing.event.MapPaneListener;
# Line 85  import schmitzm.geotools.gui.SelectableX Line 84  import schmitzm.geotools.gui.SelectableX
84  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
85  import schmitzm.geotools.map.event.MapLayerAdapter;  import schmitzm.geotools.map.event.MapLayerAdapter;
86  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
87    import skrueger.geotools.RenderingExecutor;
88    
89  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
90  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 174  public class XMapPane extends JPanel imp Line 174  public class XMapPane extends JPanel imp
174           * @see #setState(int)           * @see #setState(int)
175           */           */
176          public static final int SELECT_ONE_FROM_TOP = 104;          public static final int SELECT_ONE_FROM_TOP = 104;
177    //
178    //      /**
179    //       * While threads are working, we call {@link XMapPane#updateFinalImage()}
180    //       * regularly and repaint(). This {@link Timer} is stopped when all renderers
181    //       * have finished.
182    //       */
183    //      final private Timer repainterTimer;
184    //
185    //      /**
186    //       * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
187    //       * the {@link #repainterTimer} is regularly updating the {@link #finalImage}
188    //       * with previews.
189    //       */
190    //      public static final long REPEATING_REPAINT_DELAY = 500;
191    //      
192    //      /**
193    //       * The initial delay in milliseconds until the {@link #finalImage} is updated the first time.  
194    //       */
195    //      public static final long INITIAL_REPAINT_DELAY = 333;
196    
197          public static final long DEFAULT_REPAINTING_DELAY = 200;          protected RenderingExecutor bgExecuter;
   
         protected skrueger.geotools.RenderingExecutor bgExecuter;  
198    
199          /**          /**
200           * the map context to render           * the map context to render
# Line 218  public class XMapPane extends JPanel imp Line 235  public class XMapPane extends JPanel imp
235          /**          /**
236           * compass and icon are rendered into this image           * compass and icon are rendered into this image
237           */           */
238  //      protected BufferedImage gadgetsImage;          // protected BufferedImage gadgetsImage;
239    
240          /**          /**
241           * 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 264  public class XMapPane extends JPanel imp
264    
265                  // aktuelle Geo-Position ueber Transformation des JMapPane berechnen                  // aktuelle Geo-Position ueber Transformation des JMapPane berechnen
266                  if (e != null && e.getSource() instanceof XMapPane) {                  if (e != null && e.getSource() instanceof XMapPane) {
267                            
268                          final XMapPane xMapPane = (XMapPane) e.getSource();                          final XMapPane xMapPane = (XMapPane) e.getSource();
269                            
270                          if (!xMapPane.isWellDefined()) return null;                          if (!xMapPane.isWellDefined())
271                                                            return null;
272    
273                          AffineTransform at = xMapPane.getScreenToWorld();                          AffineTransform at = xMapPane.getScreenToWorld();
274                          if (at != null)                          if (at != null)
275                                  return at.transform(e.getPoint(), null);                                  return at.transform(e.getPoint(), null);
# Line 296  public class XMapPane extends JPanel imp Line 314  public class XMapPane extends JPanel imp
314          protected boolean paneResized = false;          protected boolean paneResized = false;
315    
316          /**          /**
          * 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;  
   
         /**  
317           * The flag {@link #requestStartRendering} can be set to true by events.           * The flag {@link #requestStartRendering} can be set to true by events.
318           * This {@link Timer} checks the flag regularly and starts one renderer           * This {@link Timer} checks the flag regularly and starts one renderer
319           * thread.           * thread.
# Line 404  public class XMapPane extends JPanel imp Line 415  public class XMapPane extends JPanel imp
415    
416                  });                  });
417    
418                  repainterTimer = new Timer((int) DEFAULT_REPAINTING_DELAY,  //              repainterTimer = new Timer((int) REPEATING_REPAINT_DELAY,
419                                  new ActionListener() {  //                              new ActionListener() {
420    //
421                                          @Override  //                                      @Override
422                                          public void actionPerformed(ActionEvent e) {  //                                      public void actionPerformed(ActionEvent e) {
423                                                  updateFinalImage();  //                                              updateFinalImage();
424                                                  XMapPane.this.repaint(DEFAULT_REPAINTING_DELAY);  //                                              XMapPane.this.repaint();
425                                          }  //                                      }
426                                  });  //                              });
427                  repainterTimer.setInitialDelay(1000);  //              repainterTimer.setInitialDelay(300);
428                  repainterTimer.setRepeats(true);  //              repainterTimer.setRepeats(true);
429    
430                  startRenderThreadsTimer = new Timer(200, new ActionListener() {                  startRenderThreadsTimer = new Timer(200, new ActionListener() {
431    
# Line 532  public class XMapPane extends JPanel imp Line 543  public class XMapPane extends JPanel imp
543           * {@link XMapPane} is visible and has bounds set.           * {@link XMapPane} is visible and has bounds set.
544           */           */
545          public boolean isWellDefined() {          public boolean isWellDefined() {
546                    
547                  try {                  try {
548                            
549                  if (getContext() == null)                          if (getContext() == null)
550                          return false;                                  return false;
551                  if (getContext().getLayerCount() <= 0)                          if (getContext().getLayerCount() <= 0)
552                          return false;                                  return false;
553                  if (getMapArea() == null)                          if (getMapArea() == null)
554                          return false;                                  return false;
555                  if (getBounds().getWidth() == 0)                          if (getBounds().getWidth() == 0)
556                          return false;                                  return false;
557                  if (getBounds().getHeight() == 0)                          if (getBounds().getHeight() == 0)
558                          return false;                                  return false;
559                  } catch (Exception e) {                  } catch (Exception e) {
560                          return false;                          return false;
561                  }                  }
# Line 602  public class XMapPane extends JPanel imp Line 613  public class XMapPane extends JPanel imp
613          /**          /**
614           * Abhaengig von selState wird der Cursor gesetzt           * Abhaengig von selState wird der Cursor gesetzt
615           */           */
616          public void updateCursorAndRepaintTimer() {          public void updateCursor() {
617    
618                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
619                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
620                          setCursor(WAIT_CURSOR);                          setCursor(WAIT_CURSOR);
621                          return;                          return;
622                  } else {                  } else {
623                          // Allow one last rendering  //                      // Allow one last rendering
624                          if (repainterTimer.isRunning()) {  //                      if (repainterTimer.isRunning()) {
625                                  repainterTimer.stop();  //                              repainterTimer.stop();
626                                  updateFinalImage();  //                              updateFinalImage();
627                                  repaint();  //                              repaint();
628                          }  //                      }
629                  }                  }
630    
631                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig                  // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
# Line 1015  public class XMapPane extends JPanel imp Line 1026  public class XMapPane extends JPanel imp
1026                          return false;                          return false;
1027                  }                  }
1028    
1029                  // Testen, ob der Unterschied nur im minimalen Rundungsfehlerbereich                  // Testing, whether NaN or Infinity are used in the newMapArea
1030                  // liegt                  if (newMapArea.isNull() || Double.isInfinite(newMapArea.getMaxX())
1031                                    || Double.isInfinite(newMapArea.getMaxY())
1032                                    || Double.isInfinite(newMapArea.getMinX())
1033                                    || Double.isInfinite(newMapArea.getMinY())) {
1034                            // No change.. ugly new values
1035                            LOGGER.warn("setMapArea has been called with newArea = "
1036                                            + newMapArea);
1037                            return false;
1038                    }
1039    
1040                    // Testing, whether the difference if just minimal
1041                  if (mapArea != null) {                  if (mapArea != null) {
1042                          Envelope candNew = bestAllowedMapArea(newMapArea);                          Envelope candNew = bestAllowedMapArea(newMapArea);
1043                          double tolX = mapArea.getWidth() / 1000.;                          double tolX = mapArea.getWidth() / 1000.;
# Line 1040  public class XMapPane extends JPanel imp Line 1061  public class XMapPane extends JPanel imp
1061    
1062                  oldMapArea = mapArea;                  oldMapArea = mapArea;
1063    
                 System.out.println("requested setting to \\t" + newMapArea);  
1064                  this.mapArea = bestAllowedMapArea(newMapArea);                  this.mapArea = bestAllowedMapArea(newMapArea);
                 System.out.println("set to \\t\\ŧ" + newMapArea);  
1065    
1066                  if (localContext != null) {                  if (localContext != null) {
1067                          localContext.setAreaOfInterest(mapArea, localContext                          localContext.setAreaOfInterest(mapArea, localContext
# Line 1056  public class XMapPane extends JPanel imp Line 1075  public class XMapPane extends JPanel imp
1075                  mapImageInvalid = true;                  mapImageInvalid = true;
1076                  mapAreaChanged = true;                  mapAreaChanged = true;
1077                  repaint();                  repaint();
1078    
1079    //              LOGGER.debug("New maparea = " + mapArea);
1080                  return true;                  return true;
1081          }          }
1082    
# Line 1076  public class XMapPane extends JPanel imp Line 1097  public class XMapPane extends JPanel imp
1097                                  || state == ZOOM_OUT || state == PAN));                                  || state == ZOOM_OUT || state == PAN));
1098    
1099                  // Je nach Aktion den Cursor umsetzen                  // Je nach Aktion den Cursor umsetzen
1100                  updateCursorAndRepaintTimer();                  updateCursor();
1101          }          }
1102    
1103          /** 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 1109  public class XMapPane extends JPanel imp
1109    
1110          public static final int NONE = -123;          public static final int NONE = -123;
1111    
1112          private skrueger.geotools.RenderingExecutor localExecuter;          private RenderingExecutor localExecuter;
1113    
1114          private BufferedImage finalImage;          private BufferedImage finalImage;
1115    
# Line 1108  public class XMapPane extends JPanel imp Line 1129  public class XMapPane extends JPanel imp
1129    
1130          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
1131                  // Maybe update the cursor                  // Maybe update the cursor
1132                  updateCursorAndRepaintTimer();                  updateCursor();
1133    
1134                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1135                          return;                          return;
# Line 1144  public class XMapPane extends JPanel imp Line 1165  public class XMapPane extends JPanel imp
1165                                  finalImage = null;                                  finalImage = null;
1166                                  localImage = null;                                  localImage = null;
1167                                  bgImage = null;                                  bgImage = null;
1168  //                              gadgetsImage = null;                                  // gadgetsImage = null;
1169                          }                          }
1170    
1171                          // Start the Threads and Timers to render the image                          // Start the Threads and Timers to render the image
# Line 1273  public class XMapPane extends JPanel imp Line 1294  public class XMapPane extends JPanel imp
1294                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1295                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
1296                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
                   
1297    
1298                  Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 - yy1);                  Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 - yy1);
1299    
1300                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea);
1301                    
1302                  addGadgets(graphics);                  addGadgets(graphics);
 //              graphics.drawImage(getGadgetsImage(), 0,0, (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),null);  
1303    
1304                  quickPreviewHint = 0;                  quickPreviewHint = 0;
1305    
1306                  graphics.dispose();                  graphics.dispose();
1307                    
1308                  // Something has been drawn                  // Something has been drawn
1309                  return true;                  return true;
1310          }          }
1311            
1312          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 30);
1313    
1314          /**          /**
1315           * 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
1316             * called as the last paint on the mapImage.
1317           */           */
1318          private void addGadgets(Graphics2D graphics) {          private void addGadgets(Graphics2D graphics) {
1319    
1320                  if (mapImage != null)                  if (mapImage != null)
1321                          graphics.drawImage(mapImage,                          graphics.drawImage(mapImage, getBounds().width
1322                                          getBounds().width - mapImage.getWidth() - 10,                                          - mapImage.getWidth() - 10, getBounds().height
1323                                          getBounds().height - mapImage.getHeight() - 10, this);                                          - mapImage.getHeight() - 10, this);
1324    
1325                  // If still rendering, paint a gray shadow or so...                  // If still rendering, paint a gray shadow or so...
1326                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
1327                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter != null && localExecuter.isRunning()) {
1328                          graphics.setColor(Color.BLACK);                          graphics.setColor(Color.BLACK);
1329                            
1330                          graphics.setFont(waitFont);                          graphics.setFont(waitFont);
1331                          graphics.drawString("Wait...", 40, 70);                          graphics.drawString("Wait...", 40, 70); //i8n
1332                            
1333                            graphics.setColor(getMapBackgroundColor());
1334                  }                  }
1335                    
1336          }          }
1337    
1338          /**          /**
# Line 1321  public class XMapPane extends JPanel imp Line 1344  public class XMapPane extends JPanel imp
1344    
1345                  final Graphics2D finalG = (Graphics2D) getFinalImage().getGraphics();                  final Graphics2D finalG = (Graphics2D) getFinalImage().getGraphics();
1346                  finalG.setBackground(getMapBackgroundColor());                  finalG.setBackground(getMapBackgroundColor());
1347                    
                   
1348                  // Render the two map images first, into the preFinalImage                  // Render the two map images first, into the preFinalImage
1349                  {                  {
1350                          final Graphics2D preFinalG = (Graphics2D) getPreFinalImage().getGraphics();                          final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()
1351                                            .getGraphics();
1352                          preFinalG.setBackground(getMapBackgroundColor());                          preFinalG.setBackground(getMapBackgroundColor());
1353    
1354                            preFinalG.drawImage(getBgImage(), 0, 0, getMapBackgroundColor(),
1355                                            null);
1356                                                    
                         preFinalG.drawImage(getBgImage(), 0, 0,  
                                         getMapBackgroundColor(), null);  
1357                          // // Draw the local layers image                          // // Draw the local layers image
1358                          preFinalG.drawImage(getLocalImage(), 0, 0, null);                          preFinalG.drawImage(getLocalImage(), 0, 0, null);
1359                          preFinalG.dispose();                          preFinalG.dispose();
1360                  }                  }
1361                    
1362                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
1363                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
1364    
                 // 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);  
   
1365                  final int finalImageHeight = getFinalImage().getHeight(null);                  final int finalImageHeight = getFinalImage().getHeight(null);
1366                  final int finalImageWidth = getFinalImage().getWidth(null);                  final int finalImageWidth = getFinalImage().getWidth(null);
1367    
# Line 1359  public class XMapPane extends JPanel imp Line 1370  public class XMapPane extends JPanel imp
1370                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
1371    
1372                  addGadgets(finalG);                  addGadgets(finalG);
 //              finalG.drawImage(getGadgetsImage(), 0, 0, null);  
1373    
1374                  finalG.dispose();                  finalG.dispose();
1375    
1376                  return finalImage;                  return finalImage;
1377          }          }
1378    
         /*  
          * 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));  
         }  
   
1379          private Image getFinalImage() {          private Image getFinalImage() {
1380    
1381                  if (finalImage == null) {                  if (finalImage == null) {
# Line 1387  public class XMapPane extends JPanel imp Line 1388  public class XMapPane extends JPanel imp
1388                  }                  }
1389                  return finalImage;                  return finalImage;
1390          }          }
1391            
1392          private Image getPreFinalImage() {          private Image getPreFinalImage() {
                   
1393                  if (preFinalImage == null) {                  if (preFinalImage == null) {
1394                          preFinalImage = null;                          preFinalImage = null;
1395                          Rectangle curPaintArea = getVisibleRect();                          Rectangle curPaintArea = getVisibleRect();
1396    
1397                          preFinalImage = new BufferedImage(curPaintArea.width,                          preFinalImage = new BufferedImage(curPaintArea.width,
1398                                          curPaintArea.height, BufferedImage.TYPE_INT_RGB);                                          curPaintArea.height, BufferedImage.TYPE_INT_RGB);
1399                            
1400                          requestStartRendering();                          requestStartRendering();
1401                  }                  }
1402                  return preFinalImage;                  return preFinalImage;
# Line 1422  public class XMapPane extends JPanel imp Line 1422  public class XMapPane extends JPanel imp
1422    
1423                  if (localExecuter != null)                  if (localExecuter != null)
1424                          localExecuter.cancelTask();                          localExecuter.cancelTask();
1425                  //          
                 //  
                 // 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");  
   
1426                  Rectangle curPaintArea = getVisibleRect();                  Rectangle curPaintArea = getVisibleRect();
1427    
                 // allow a single pixel margin at the right and bottom edges  
                 curPaintArea.width -= 1;  
                 curPaintArea.height -= 1;  
   
1428                  labelCache.clear();                  labelCache.clear();
1429    
1430                  /**                  /**
                  */  
   
                 /**  
1431                   * We have to set new renderer                   * We have to set new renderer
1432                   */                   */
1433    
1434                  if (getBgContext() != null) {                  if (getBgContext() != null) {
1435                          bgExecuter = new skrueger.geotools.RenderingExecutor(this);                          bgExecuter = new RenderingExecutor(this, 333l);
1436                          LOGGER.debug("starting bg renderer:");                          LOGGER.debug("starting bg renderer:");
1437                          // /* System.out.println("rendering"); */                          // /* System.out.println("rendering"); */
1438                          final GTRenderer createGTRenderer = GTUtil.createGTRenderer(                          final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
# Line 1474  public class XMapPane extends JPanel imp Line 1443  public class XMapPane extends JPanel imp
1443                  }                  }
1444    
1445                  if (getContext() != null) {                  if (getContext() != null) {
1446                          localExecuter = new skrueger.geotools.RenderingExecutor(this);                          localExecuter = new RenderingExecutor(this, 150l);
1447                          LOGGER.debug("starting local renderer:");                          LOGGER.debug("starting local renderer:");
1448                          final GTRenderer createGTRenderer = GTUtil.createGTRenderer(                          final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
1449                                          localContext, getRendererHints());                                          localContext, getRendererHints());
# Line 1484  public class XMapPane extends JPanel imp Line 1453  public class XMapPane extends JPanel imp
1453                                          createGTRenderer);                                          createGTRenderer);
1454                  }                  }
1455    
1456                  updateCursorAndRepaintTimer();                  updateCursor();
   
                 // start regular repaints until all renderers are done.  
                 repainterTimer.setRepeats(true);  
                 repainterTimer.restart();  
1457    
1458          }          }
1459    
# Line 1498  public class XMapPane extends JPanel imp Line 1463  public class XMapPane extends JPanel imp
1463          private BufferedImage getBgImage() {          private BufferedImage getBgImage() {
1464    
1465                  if (bgImage == null) {                  if (bgImage == null) {
                         LOGGER.debug("creating a new background image");  
   
1466                          Rectangle curPaintArea = getVisibleRect();                          Rectangle curPaintArea = getVisibleRect();
                         // allow a single pixel margin at the right and bottom edges  
                         curPaintArea.width -= 1;  
                         curPaintArea.height -= 1;  
1467    
1468                          bgImage = new BufferedImage(curPaintArea.width + 1,                          bgImage = new BufferedImage(curPaintArea.width + 1,
1469                                          curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);                                          curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);
# Line 1535  public class XMapPane extends JPanel imp Line 1495  public class XMapPane extends JPanel imp
1495           */           */
1496          public void setMapImage(BufferedImage mapImage) {          public void setMapImage(BufferedImage mapImage) {
1497                  this.mapImage = mapImage;                  this.mapImage = mapImage;
 //              gadgetsImage = null;  
1498          }          }
1499    
1500          /**          /**
# Line 1544  public class XMapPane extends JPanel imp Line 1503  public class XMapPane extends JPanel imp
1503          private BufferedImage getLocalImage() {          private BufferedImage getLocalImage() {
1504    
1505                  if (localImage == null) {                  if (localImage == null) {
                         LOGGER.debug("creating a new local image");  
1506    
1507                          Rectangle curPaintArea = getVisibleRect();                          Rectangle curPaintArea = getVisibleRect();
                         // allow a single pixel margin at the right and bottom edges  
                         curPaintArea.width -= 1;  
                         curPaintArea.height -= 1;  
1508    
1509                          localImage = new BufferedImage(curPaintArea.width + 1,                          localImage = new BufferedImage(curPaintArea.width + 1,
1510                                          curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);                                          curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);
# Line 1557  public class XMapPane extends JPanel imp Line 1512  public class XMapPane extends JPanel imp
1512    
1513                  return localImage;                  return localImage;
1514          }          }
1515  //  
 //      /**  
 //       * 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;  
 //      }  
1516    
1517          /**          /**
1518           * 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 1522  public class XMapPane extends JPanel imp
1522           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1523           */           */
1524          public void onRenderingCompleted() {          public void onRenderingCompleted() {
                 System.out.println("onRenderingCompleted");  
   
1525                  updateFinalImage();                  updateFinalImage();
   
1526                  repaint();                  repaint();
   
1527          }          }
1528    
1529          /**          /**
# Line 1622  public class XMapPane extends JPanel imp Line 1548  public class XMapPane extends JPanel imp
1548           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)           * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1549           */           */
1550          public void onRenderingFailed(Exception renderingError) {          public void onRenderingFailed(Exception renderingError) {
                 // MapPaneEvent ev = new MapPaneEvent(this,  
                 // MapPaneEvent.Type.RENDERING_STOPPED);  
                 // publishEvent(ev);  
1551                  LOGGER.warn("Rendering failed", renderingError);                  LOGGER.warn("Rendering failed", renderingError);
1552                  updateFinalImage();                  updateFinalImage();
1553                  repaint();                  repaint();
# Line 1652  public class XMapPane extends JPanel imp Line 1575  public class XMapPane extends JPanel imp
1575                  }                  }
1576          }          }
1577    
         // xulu.sn  
1578          /**          /**
1579           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
1580           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
# Line 1821  public class XMapPane extends JPanel imp Line 1743  public class XMapPane extends JPanel imp
1743                                                          false);                                                          false);
1744                                  }                                  }
1745                          }                          }
   
1746                  }                  }
1747    
1748                  return newArea;                  return newArea;
# Line 2008  public class XMapPane extends JPanel imp Line 1929  public class XMapPane extends JPanel imp
1929          public void dispose() {          public void dispose() {
1930                  if (isDisposed())                  if (isDisposed())
1931                          return;                          return;
1932                    
1933                    setPainting(false);
1934    
1935                  disposed = true;                  disposed = true;
1936    
# Line 2020  public class XMapPane extends JPanel imp Line 1943  public class XMapPane extends JPanel imp
1943                  }                  }
1944    
1945                  startRenderThreadsTimer.stop();                  startRenderThreadsTimer.stop();
                 repainterTimer.stop();  
1946    
1947                  if (bgImage != null)                  if (bgImage != null)
1948                          bgImage.flush();                          bgImage.flush();
1949                  if (localImage != null)                  if (localImage != null)
1950                          localImage.flush();                          localImage.flush();
 //              if (gadgetsImage != null)  
 //                      gadgetsImage.flush();  
1951                  if (finalImage != null)                  if (finalImage != null)
1952                          finalImage.flush();                          finalImage.flush();
1953                  if (preFinalImage != null)                  if (preFinalImage != null)
1954                          preFinalImage.flush();                          preFinalImage.flush();
1955    
                 // if (dragWaitCursorListener != null)  
                 // this.removeMouseListener(dragWaitCursorListener);  
                 // if (mouseWheelZoomListener != null)  
                 // this.removeMouseWheelListener(mouseWheelZoomListener);  
   
1956                  // Alle mapPaneListener entfernen                  // Alle mapPaneListener entfernen
1957                  mapPaneListeners.clear();                  mapPaneListeners.clear();
1958    
# Line 2087  public class XMapPane extends JPanel imp Line 2002  public class XMapPane extends JPanel imp
2002    
2003                  Point2D gcenter = getScreenToWorld().transform(center, null);                  Point2D gcenter = getScreenToWorld().transform(center, null);
2004                  center = null;                  center = null;
2005                    
2006                  if (                  if (Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())
2007                                  Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())                                  || Double.isInfinite(gcenter.getX())
2008                                  ||                                  || Double.isInfinite(gcenter.getY())
2009                                  Double.isInfinite(gcenter.getX()) || Double.isInfinite(gcenter.getY())  
                                   
2010                  ) {                  ) {
2011                          // Not inside valid CRS area! cancel                          // Not inside valid CRS area! cancel
2012                          return;                          return;
2013                  }                  }
2014    
2015                  final Envelope mapArea = getMapArea();                  final Envelope mapArea = getMapArea();
2016                    
2017                  Envelope newMapArea = new Envelope(mapArea);                  Envelope newMapArea = new Envelope(mapArea);
2018                  newMapArea                  newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2019                                  .expandBy((mapArea.getWidth() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2020                                                  .getWidth()) / 2., (mapArea.getHeight()                                  .getHeight()) / 2.);
                                                 * zoomFaktor - mapArea.getHeight()) / 2.);  
2021    
2022                  // Move the newMapArea above the new center                  // Move the newMapArea above the new center
2023                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter.getY()                  newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2024                                    .getY()
2025                                  - mapArea.centre().y);                                  - mapArea.centre().y);
2026    
2027                  setMapArea(newMapArea);                  setMapArea(newMapArea);
# Line 2205  public class XMapPane extends JPanel imp Line 2119  public class XMapPane extends JPanel imp
2119           */           */
2120          protected void drawRectangle(final Graphics graphics, Point startPos,          protected void drawRectangle(final Graphics graphics, Point startPos,
2121                          Point e) {                          Point e) {
2122                    
2123                    if (!isWellDefined()) return;
2124                    
2125                  // undraw last box/draw new box                  // undraw last box/draw new box
2126                  final int left = Math.min(startPos.x, e.x);                  final int left = Math.min(startPos.x, e.x);
2127                  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 2149  public class XMapPane extends JPanel imp
2149                  imageOrigin.x = 0;                  imageOrigin.x = 0;
2150                  imageOrigin.y = 0;                  imageOrigin.y = 0;
2151    
2152                  if (!setMapArea(newMapArea)){                  if (!setMapArea(newMapArea)) {
2153                          updateFinalImage();                          updateFinalImage();
2154                          repaint();                          repaint();
2155                  }                  }
# Line 2241  public class XMapPane extends JPanel imp Line 2158  public class XMapPane extends JPanel imp
2158                          setCursor(SwingUtil.PAN_CURSOR);                          setCursor(SwingUtil.PAN_CURSOR);
2159          }          }
2160    
2161            public void onRenderingPending() {
2162    //              LOGGER.debug("Pending rendering updates the preview...");
2163                    updateFinalImage();
2164                    repaint();
2165            }
2166    
2167  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26