/[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 553 by alfonx, Mon Nov 23 21:39:17 2009 UTC revision 557 by alfonx, Tue Nov 24 13:00:54 2009 UTC
# Line 98  public class XMapPane extends JPanel { Line 98  public class XMapPane extends JPanel {
98          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
99          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;
100    
101          private static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
102    
103          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
104    
# Line 133  public class XMapPane extends JPanel { Line 133  public class XMapPane extends JPanel {
133           * The initial delay in milliseconds until the {@link #finalImage} is           * The initial delay in milliseconds until the {@link #finalImage} is
134           * updated the first time.           * updated the first time.
135           */           */
136          public static final int INITIAL_REPAINT_DELAY = 1000;          public static final int INITIAL_REPAINT_DELAY = 900;
137    
138          /**          /**
139           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
140           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
141           * with previews.           * with previews.
142           */           */
143          public static final int REPEATING_REPAINT_DELAY = 500;          public static final int REPEATING_REPAINT_DELAY = 600;
144    
145          /**          /**
146           * Default delay (milliseconds) before the map will be redrawn when resizing           * Default delay (milliseconds) before the map will be redrawn when resizing
# Line 150  public class XMapPane extends JPanel { Line 150  public class XMapPane extends JPanel {
150           */           */
151          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
152    
153            /**
154             * This not-repeating {@link Timer} is re-started whenever the component is
155             * resized. That means => only if the component is not resizing for
156             * {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the
157             * {@link XMapPane} react.
158             */
159          private final Timer resizeTimer;          private final Timer resizeTimer;
160    
161            /**
162             * Flag for no-tool.
163             */
164          public static final int NONE = -123;          public static final int NONE = -123;
165    
166          /**          /**
# Line 163  public class XMapPane extends JPanel { Line 172  public class XMapPane extends JPanel {
172          public static final int PAN = 1;          public static final int PAN = 1;
173    
174          /**          /**
175             * Flag fuer Modus "Heran zoomen".
176             *
177             * @see #setState(int)
178             * @see #setState(int)
179             */
180            public static final int ZOOM_IN = 2;
181    
182            /**
183             * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
184             *
185             * @see #setState(int)
186             */
187            public static final int ZOOM_OUT = 3;
188    
189            /**
190           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".
191           *           *
192           * @see #setState(int)           * @see #setState(int)
# Line 186  public class XMapPane extends JPanel { Line 210  public class XMapPane extends JPanel {
210           */           */
211          public static final int SELECT_TOP = 4;          public static final int SELECT_TOP = 4;
212    
         public static final Cursor WAIT_CURSOR = Cursor  
                         .getPredefinedCursor(Cursor.WAIT_CURSOR);  
   
213          /**          /**
214           * {@link Font} used to paint the wait messages into the map           * {@link Font} used to paint the wait messages into the map
215           *           *
# Line 212  public class XMapPane extends JPanel { Line 233  public class XMapPane extends JPanel {
233          final String waitMsg = SwingUtil.R("WaitMess");          final String waitMsg = SwingUtil.R("WaitMess");
234    
235          /**          /**
          * Flag fuer Modus "Heran zoomen".  
          *  
          * @see #setState(int)  
          * @see #setState(int)  
          */  
         public static final int ZOOM_IN = 2;  
   
         /**  
          * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!  
          *  
          * @see #setState(int)  
          */  
         public static final int ZOOM_OUT = 3;  
   
         /**  
236           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in
237           * Karten-Koordinaten.           * Karten-Koordinaten.
238           *           *
# Line 423  public class XMapPane extends JPanel { Line 429  public class XMapPane extends JPanel {
429    
430                  @Override                  @Override
431                  public void layerChanged(final MapLayerEvent event) {                  public void layerChanged(final MapLayerEvent event) {
432                          localRenderer.setContext(getMapContext()); // betters for SLD changes?!                          localRenderer.setContext(getMapContext()); // betters for SLD
433                            // changes?!
434                          requestStartRendering();                          requestStartRendering();
435                  }                  }
436    
# Line 503  public class XMapPane extends JPanel { Line 510  public class XMapPane extends JPanel {
510           * A flag indicating, that the image size has changed and the buffered           * A flag indicating, that the image size has changed and the buffered
511           * images are not big enough any more           * images are not big enough any more
512           **/           **/
513          protected boolean paneResized = false;          protected boolean paneResized = true;
514    
515          private BufferedImage preFinalImage;          private BufferedImage preFinalImage;
516    
517          // if null, no quick preview will be shown          // ** if 0, no quick preview will be shown **/
518          private int quickPreviewHint = 0;          private int quickPreviewHint = 0;
519    
520          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
# Line 554  public class XMapPane extends JPanel { Line 561  public class XMapPane extends JPanel {
561    
562          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
563          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
564            
565          /** If <code>true</code>, then rendering exceptions are rendererd into the map pane **/          /**
566          private boolean showExceptions= false;           * If <code>true</code>, then rendering exceptions are rendererd into the
567             * map pane
568          // /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet           **/
569          // defined, but we are **/          private boolean showExceptions = false;
         // private Envelope mapAreaCondidate = null;  
570    
571          public XMapPane() {          public XMapPane() {
572                  this(null, null);                  this(null, null);
# Line 610  public class XMapPane extends JPanel { Line 616  public class XMapPane extends JPanel {
616                                                  if (!isWellDefined())                                                  if (!isWellDefined())
617                                                          return;                                                          return;
618    
619                                                    LOGGER.debug("resizeTimer performed");
620    
621                                                  final Rectangle bounds = getVisibleRect();                                                  final Rectangle bounds = getVisibleRect();
622                                                  //                                                  //
623                                                  // System.out.println("\n\ntimer performs with bounds = "                                                  // System.out.println("\n\ntimer performs with bounds = "
# Line 619  public class XMapPane extends JPanel { Line 627  public class XMapPane extends JPanel {
627                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                                  bounds.x, bounds.y, bounds.x + bounds.width,
628                                                                  bounds.y + bounds.height);                                                                  bounds.y + bounds.height);
629    
630                                                  if (setMapArea(geoMapArea))                                                  if (setMapArea(geoMapArea)) {
631                                                            LOGGER.debug("  maparea changed");
632                                                          paneResized = true;                                                          paneResized = true;
633                                                  // else                                                  } else
634                                                  // syso                                                          LOGGER.debug("  maparea NOT changed");
635                                          }                                          }
636                                  });                                  });
637                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
638    
639                  this.addComponentListener(new ComponentAdapter() {                  this.addComponentListener(new ComponentAdapter() {
640    
641                            private Rectangle oldVisibleRect;
642    
643                          @Override                          @Override
644                          public void componentResized(final ComponentEvent e) {                          public void componentResized(final ComponentEvent e) {
645    
646                                  // Already cancel the tasks...                                  // Seems to be called twice with the same size..
647                                  if (bgExecuter != null)                                  if (oldVisibleRect != null
648                                          bgExecuter.cancelTask();                                                  && oldVisibleRect.equals(getVisibleRect())) {
649                                  if (localExecuter != null)                                          LOGGER.debug("skipping resize.");
650                                          localExecuter.cancelTask();                                          return;
651                                    }
652    
653                                    LOGGER.debug("resized: " + getVisibleRect());
654                                  resizeTimer.restart();                                  resizeTimer.restart();
655                                    oldVisibleRect = getVisibleRect();
656                          }                          }
657    
658                  });                  });
# Line 650  public class XMapPane extends JPanel { Line 664  public class XMapPane extends JPanel {
664    
665                          @Override                          @Override
666                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
667                                  if ((localExecuter != null && !localExecuter.isRunning())                                  if ((!localExecuter.isRunning())
668                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {
669                                          repaintTimer.stop();                                          repaintTimer.stop();
670                                  } else {                                  } else {
671                                          updateFinalImage();                                          updateFinalImage();
672                                          XMapPane.this.repaint(100);                                          XMapPane.this.repaint(100);
673    
674                                  }                                  }
675                          }                          }
676                  });                  });
677    
678                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
679                  repaintTimer.setRepeats(true);                  repaintTimer.setRepeats(true);
680    
# Line 676  public class XMapPane extends JPanel { Line 692  public class XMapPane extends JPanel {
692                                                  if (localExecuter.isRunning()) {                                                  if (localExecuter.isRunning()) {
693                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
694                                                  } else {                                                  } else {
   
695                                                          // Stupidly, but we have to recheck the                                                          // Stupidly, but we have to recheck the
696                                                          setMapArea(getMapArea());                                                          setMapArea(getMapArea());
697                                                          requestStartRendering = false;                                                          requestStartRendering = false;
# Line 765  public class XMapPane extends JPanel { Line 780  public class XMapPane extends JPanel {
780                  }                  }
781    
782                  final Envelope maxAllowedExtend = getMaxExtend();                  final Envelope maxAllowedExtend = getMaxExtend();
783                    
784                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
785                                  && newArea != null && !newArea.isNull()                                  && newArea != null && !newArea.isNull()
786                                  && !Double.isNaN(newArea.getMinX())                                  && !Double.isNaN(newArea.getMinX())
# Line 910  public class XMapPane extends JPanel { Line 925  public class XMapPane extends JPanel {
925                          bgExecuter.dispose();                          bgExecuter.dispose();
926                  }                  }
927    
928                  if (localExecuter != null) {                  if (localExecuter.isRunning()) {
929                          int i = 0;                          int i = 0;
930                          localExecuter.cancelTask();                          localExecuter.cancelTask();
931                          while (i++ < 10 && localExecuter.isRunning()) {                          while (i++ < 10 && localExecuter.isRunning()) {
# Line 1131  public class XMapPane extends JPanel { Line 1146  public class XMapPane extends JPanel {
1146          }          }
1147    
1148          /**          /**
1149           * Returns the background {@link Color} of the map pane. Default is white.           * Returns the background {@link Color} of the map pane. If not set, the
1150             * methods looks for a parent component and will use its background color.
1151             * If no parent component is available, WHITE is returned.
1152           **/           **/
1153          public Color getMapBackgroundColor() {          public Color getMapBackgroundColor() {
1154                    if (mapBackgroundColor == null){
1155                            if (getParent() != null) return getParent().getBackground();
1156                            else return Color.WHITE;
1157                    }
1158                  return mapBackgroundColor;                  return mapBackgroundColor;
1159          }          }
1160    
# Line 1161  public class XMapPane extends JPanel { Line 1182  public class XMapPane extends JPanel {
1182          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1183                  if (maxExtend == null) {                  if (maxExtend == null) {
1184                          // Commented-out because it takes soo much time!                          // Commented-out because it takes soo much time!
1185  //                          //
1186  //                      long start = System.currentTimeMillis();                          // long start = System.currentTimeMillis();
1187  //                      final ReferencedEnvelope layerBounds = GTUtil                          // final ReferencedEnvelope layerBounds = GTUtil
1188  //                                      .getVisibleLayoutBounds(localContext);                          // .getVisibleLayoutBounds(localContext);
1189  //                                                //                      
1190  //                      LOGGER.info( (System.currentTimeMillis()-start)+"m to get maxExtend");                          // LOGGER.info(
1191  //                                                // (System.currentTimeMillis()-start)+"m to get maxExtend");
1192  //                      if (layerBounds == null) {                          //                      
1193  //                              // TODO Last fallback could be the CRS valid area                          // if (layerBounds == null) {
1194  //                              return null;                          // // TODO Last fallback could be the CRS valid area
1195  //                      }                          // return null;
1196  //                          // }
1197  //                      // Kartenbereich um 10% vergroessern                          //
1198  //                      return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil                          // // Kartenbereich um 10% vergroessern
1199  //                                      .expandEnvelope(layerBounds, 0.1), true);                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1200                            // .expandEnvelope(layerBounds, 0.1), true);
1201                  }                  }
1202                  return maxExtend;                  return maxExtend;
1203          }          }
# Line 1306  public class XMapPane extends JPanel { Line 1328  public class XMapPane extends JPanel {
1328                  return true;                  return true;
1329          }          }
1330    
1331            /**
1332             * Called from the listeners while the mouse is dragging, this method either
1333             * paints a translated (moved/panned) version of the image, or a rectangle.
1334             *
1335             * @param startPos
1336             *            in screen coordinates
1337             * @param lastPos
1338             *            in screen coordinates
1339             * @param event
1340             *            the {@link MouseEvent} to read the mouse buttons from
1341             */
1342          public void mouseDragged(final Point startPos, final Point lastPos,          public void mouseDragged(final Point startPos, final Point lastPos,
1343                          final MouseEvent event) {                          final MouseEvent event) {
1344    
1345                  if ((getState() == XMapPane.PAN)                  if ((getState() == XMapPane.PAN)
1346                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
1347    
1348                            // Panning needs a panning coursor
1349                          if (getCursor() != SwingUtil.PANNING_CURSOR) {                          if (getCursor() != SwingUtil.PANNING_CURSOR) {
1350                                  setCursor(SwingUtil.PANNING_CURSOR);                                  setCursor(SwingUtil.PANNING_CURSOR);
1351    
1352                                  // While panning, we deactivate the rendering. So the tasts are                                  // While panning, we deactivate the rendering. So the tasks are
1353                                  // ready to start when the panning os done.                                  // ready to start when the panning is finished.
1354                                  if (bgExecuter != null)                                  if (bgExecuter != null && bgExecuter.isRunning())
1355                                          bgExecuter.cancelTask();                                          bgExecuter.cancelTask();
1356                                  if (localExecuter != null)                                  if (localExecuter.isRunning())
1357                                          localExecuter.cancelTask();                                          localExecuter.cancelTask();
1358                          }                          }
1359    
# Line 1366  public class XMapPane extends JPanel { Line 1400  public class XMapPane extends JPanel {
1400                  } else if ((getState() == XMapPane.ZOOM_IN)                  } else if ((getState() == XMapPane.ZOOM_IN)
1401                                  || (getState() == XMapPane.ZOOM_OUT)                                  || (getState() == XMapPane.ZOOM_OUT)
1402                                  || (getState() == XMapPane.SELECT_ALL)                                  || (getState() == XMapPane.SELECT_ALL)
1403                                  || (getState() == XMapPane.SELECT_TOP)                                  || (getState() == XMapPane.SELECT_TOP)) {
                 // || (getState() == XMapPane.SELECT_ONE_FROM_TOP)  
                 ) {  
                         final Graphics graphics = getGraphics();  
1404    
1405                            // Draws a rectangle
1406                            final Graphics graphics = getGraphics();
1407                          drawRectangle(graphics, startPos, event.getPoint());                          drawRectangle(graphics, startPos, event.getPoint());
1408                            if ((lastPos.x > 0) && (lastPos.y > 0))
                         if ((lastPos.x > 0) && (lastPos.y > 0)) {  
1409                                  drawRectangle(graphics, startPos, lastPos);                                  drawRectangle(graphics, startPos, lastPos);
                         }  
   
1410                          graphics.dispose();                          graphics.dispose();
   
1411                  }                  }
   
1412          }          }
1413    
1414          /**          /**
# Line 1396  public class XMapPane extends JPanel { Line 1424  public class XMapPane extends JPanel {
1424           * completed.           * completed.
1425           */           */
1426          public void onRenderingCompleted() {          public void onRenderingCompleted() {
1427                    LOGGER.debug("complete");
1428    
1429                  repaintTimer.stop();                  repaintTimer.stop();
1430                  updateFinalImage();  
1431                  repaint();                  // We "forget" about an exception every time we complete a rendering
1432                    // thread successfully
1433                  if (renderingErrors.size() > 0)                  if (renderingErrors.size() > 0)
1434                          renderingErrors.remove(0);                          renderingErrors.remove(0);
1435    
1436                    updateFinalImage();
1437                    repaint();
1438          }          }
1439    
1440          /**          /**
# Line 1416  public class XMapPane extends JPanel { Line 1450  public class XMapPane extends JPanel {
1450          public void onRenderingFailed(final Exception renderingError) {          public void onRenderingFailed(final Exception renderingError) {
1451    
1452                  // Store the exceptions so we can show it to the user:                  // Store the exceptions so we can show it to the user:
1453                  if (!(renderingError instanceof java.lang.IllegalArgumentException                  if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError
1454                                  && renderingError.getMessage().equals(                                  .getMessage().equals(
1455                                                  "Argument \"sourceCRS\" should not be null.")))                                                  "Argument \"sourceCRS\" should not be null.")))
1456                          this.renderingErrors.add(renderingError);                          this.renderingErrors.add(renderingError);
1457                  if (renderingErrors.size() > 3)                  if (renderingErrors.size() > 3)
1458                          renderingErrors.remove(0);                          renderingErrors.remove(0);
1459                    
1460                  repaintTimer.stop();                  repaintTimer.stop();
1461    
1462                  LOGGER.warn("Rendering failed", renderingError);                  LOGGER.warn("Rendering failed", renderingError);
1463                  updateFinalImage();                  updateFinalImage();
1464                  repaint();                  repaint();
1465    
1466          }          }
1467    
         public void onRenderingPending() {  
                 // LOGGER.debug("Pending rendering updates the preview...");  
                 updateFinalImage();  
                 repaint();  
         }  
   
1468          @Override          @Override
1469          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
1470    
1471                    // Maybe update the cursor and maybe stop the repainting timer
1472                    updateCursor();
1473    
1474                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1475                          return;                          return;
1476    
1477                  // Maybe update the cursor and maybe stop the repainting timer                  if (!isWellDefined())
1478                  updateCursor();                          return;
1479    
1480                  // super.paintComponent(g); // candidate for removal                  // super.paintComponent(g); // candidate for removal
1481    
# Line 1463  public class XMapPane extends JPanel { Line 1495  public class XMapPane extends JPanel {
1495                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1496    
1497                                  if (getMapArea().covers(oldMapArea)) {                                  if (getMapArea().covers(oldMapArea)) {
1498                                          setQuickPreviewHint(ZOOM_OUT);                                          quickPreviewHint = ZOOM_OUT;
1499                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1500                                  } else if (oldMapArea.covers(getMapArea())) {                                  } else if (oldMapArea.covers(getMapArea())) {
1501                                          setQuickPreviewHint(ZOOM_IN);                                          quickPreviewHint = ZOOM_IN;
1502                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1503                                  }                                  }
   
1504                          }                          }
   
                         // if (paneResized) {  
                         // paneResized = false;  
                         // disposeImages();  
                         // }  
                         //  
                         // // Start the Threads and Timers to render the image  
                         // requestStartRendering();  
   
1505                  }                  }
1506    
1507                  if (!paintedSomething) {                  if (!paintedSomething) {
# Line 1567  public class XMapPane extends JPanel { Line 1589  public class XMapPane extends JPanel {
1589                          setCursor(SwingUtil.PAN_CURSOR);                          setCursor(SwingUtil.PAN_CURSOR);
1590          }          }
1591    
         //  
         // /**  
         // * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot  
         // gemacht  
         // * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.  
         // *  
         // * @author <a href="mailto:[email protected]">Stefan Alfons  
         // * Kr&uuml;ger</a>  
         // */  
         // @Override  
         // public void print(final Graphics g) {  
         // final Color orig = getBackground();  
         // setBackground(Color.WHITE);  
         //  
         // // wrap in try/finally so that we always restore the state  
         // try {  
         // super.print(g);  
         // } finally {  
         // setBackground(orig);  
         // }  
         // }  
   
1592          /**          /**
1593           * Entfernt einen Listener von der Map.           * Entfernt einen Listener von der Map.
1594           *           *
# Line 1607  public class XMapPane extends JPanel { Line 1607  public class XMapPane extends JPanel {
1607          private void requestStartRendering() {          private void requestStartRendering() {
1608                  if (bgExecuter != null)                  if (bgExecuter != null)
1609                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1610                  if (localExecuter != null)  
1611                          localExecuter.cancelTask();                  localExecuter.cancelTask();
1612    
1613                  mapImageInvalid = true;                  mapImageInvalid = true;
1614                  if (paneResized) {                  if (paneResized) {
# Line 1718  public class XMapPane extends JPanel { Line 1718  public class XMapPane extends JPanel {
1718          }          }
1719    
1720          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1721                    if (newMapArea == null)
1722                            return false;
1723                    if (getMapContext()
1724                                    .getCoordinateReferenceSystem() == null) return false;
1725                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1726                                  .getCoordinateReferenceSystem()));                                  .getCoordinateReferenceSystem()));
1727          }          }
# Line 1728  public class XMapPane extends JPanel { Line 1732  public class XMapPane extends JPanel {
1732           *         has been triggered.           *         has been triggered.
1733           */           */
1734          public boolean setMapArea(final ReferencedEnvelope newMapArea) {          public boolean setMapArea(final ReferencedEnvelope newMapArea) {
                 //                
                 // if (getVisibleRect().getWidth() == 0 || (!isVisible()) ||  
                 // getVisibleRect().getHeight() == 0) {  
                 // // The window is not yet defined.. so we can not really determine the  
                 // asepect ratio for the mapPane. We store this as a candidate mappane  
                 // and handle it when the component resizes or becomes visible)  
                 // mapAreaCondidate = newMapArea;  
                 // }  
1735    
1736                  if (newMapArea == null                  if (newMapArea == null
1737                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {
# Line 1793  public class XMapPane extends JPanel { Line 1789  public class XMapPane extends JPanel {
1789    
1790                  mapAreaChanged = true;                  mapAreaChanged = true;
1791    
1792                  repaint(100);                  repaint(200); // Do not remove it!
1793    
1794                  requestStartRendering();                  requestStartRendering();
1795    
# Line 1806  public class XMapPane extends JPanel { Line 1802  public class XMapPane extends JPanel {
1802           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1803           */           */
1804          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(Color bgColor) {
                 if (bgColor == null)  
                         bgColor = Color.WHITE;  
1805                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1806          }          }
1807    
# Line 1882  public class XMapPane extends JPanel { Line 1876  public class XMapPane extends JPanel {
1876          }          }
1877    
1878          /**          /**
1879           *           * If <code>true</code>, allow the {@link XMapPane} to process #repaint()
1880           * @param b           * requests. Otherwise the map will not paint anything and not start any
1881             * rendering {@link Thread}s.
1882           */           */
1883          public void setPainting(final boolean b) {          public void setPainting(final boolean b) {
1884                  acceptsRepaintCalls = b;                  acceptsRepaintCalls = b;
1885          }                  if (acceptsRepaintCalls == true)
1886                            repaint();
         // /**  
         // * Returns in milli seconds the time the last rending of the  
         // * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has  
         // not  
         // * been rendered yet.  
         // */  
         // public long getLastRenderingDuration() {  
         // return lastRenderingDuration;  
         // }  
   
         public void setQuickPreviewHint(final int quickPreviewHint) {  
                 this.quickPreviewHint = quickPreviewHint;  
   
1887          }          }
1888    
1889          private void setRendererHints(final Map<Object, Object> rendererHints) {          private void setRendererHints(final Map<Object, Object> rendererHints) {
# Line 1947  public class XMapPane extends JPanel { Line 1929  public class XMapPane extends JPanel {
1929          private void startRendering() {          private void startRendering() {
1930    
1931                  if (!isWellDefined() || !acceptsRepaintCalls) {                  if (!isWellDefined() || !acceptsRepaintCalls) {
1932                            // if we are not ready to start rendering, try it again the next
1933                            // time the timer is chacking the flag.
1934                          requestStartRendering = true;                          requestStartRendering = true;
1935                          return;                          return;
1936                  }                  }
# Line 1956  public class XMapPane extends JPanel { Line 1940  public class XMapPane extends JPanel {
1940                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1941                  }                  }
1942    
1943                  if (localExecuter != null) {                  localExecuter.cancelTask();
                         localExecuter.cancelTask();  
                 }  
1944    
1945                  final Rectangle curPaintArea = getVisibleRect();                  final Rectangle curPaintArea = getVisibleRect();
1946    
# Line 1990  public class XMapPane extends JPanel { Line 1972  public class XMapPane extends JPanel {
1972    
1973                          final boolean submitted = localExecuter.submit(getMapArea(),                          final boolean submitted = localExecuter.submit(getMapArea(),
1974                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1975                                          localRenderer                                          localRenderer);
                         // , getWorldToScreenTransform()  
                                         );  
1976                          if (submitted)                          if (submitted)
1977                                  repaintTimer.restart();                                  repaintTimer.restart();
1978                          else                          else
# Line 2067  public class XMapPane extends JPanel { Line 2047  public class XMapPane extends JPanel {
2047                  // if the renderers have stopped, also stop the timer that is updating                  // if the renderers have stopped, also stop the timer that is updating
2048                  // the final image                  // the final image
2049                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
2050                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter.isRunning()) {
2051                          setCursor(WAIT_CURSOR);                          setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
2052                          return;                          return;
2053                  } else {                  } else {
2054                          // Allow one last rendering                          // Allow one last rendering
# Line 2181  public class XMapPane extends JPanel { Line 2161  public class XMapPane extends JPanel {
2161    
2162                  // If the rendering process is still running, indicate this is the image                  // If the rendering process is still running, indicate this is the image
2163                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2164                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter.isRunning()) {
2165    
2166                          y += 8;                          y += 8;
2167    
# Line 2200  public class XMapPane extends JPanel { Line 2180  public class XMapPane extends JPanel {
2180                          y += 24;                          y += 24;
2181                  }                  }
2182    
2183                  if (renderingErrors != null && isShowExceptions()) {                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
2184    
2185                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2186                          graphics.setFont(errorFont);                          graphics.setFont(errorFont);
# Line 2247  public class XMapPane extends JPanel { Line 2227  public class XMapPane extends JPanel {
2227                  ReferencedEnvelope _mapArea;                  ReferencedEnvelope _mapArea;
2228                  if (mapArea == null)                  if (mapArea == null)
2229                          _mapArea = features.getBounds();                          _mapArea = features.getBounds();
2230                  else _mapArea = getMapArea();                  else
2231                            _mapArea = getMapArea();
2232                  double width = _mapArea.getWidth();                  double width = _mapArea.getWidth();
2233                  double height = _mapArea.getHeight();                  double height = _mapArea.getHeight();
2234                  final double ratio = height / width;                  final double ratio = height / width;

Legend:
Removed from v.553  
changed lines
  Added in v.557

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26