/[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 561 by mojays, Tue Nov 24 15:02:27 2009 UTC
# Line 26  import java.util.HashMap; Line 26  import java.util.HashMap;
26  import java.util.Map;  import java.util.Map;
27  import java.util.Vector;  import java.util.Vector;
28    
29    import javax.jws.soap.SOAPBinding.Style;
30  import javax.swing.Timer;  import javax.swing.Timer;
31    import javax.swing.border.Border;
32    
33  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
34  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
# Line 98  public class XMapPane extends JPanel { Line 100  public class XMapPane extends JPanel {
100          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
101          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;
102    
103          private static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
104    
105          private boolean acceptsRepaintCalls = true;          private boolean acceptsRepaintCalls = true;
106    
# Line 133  public class XMapPane extends JPanel { Line 135  public class XMapPane extends JPanel {
135           * The initial delay in milliseconds until the {@link #finalImage} is           * The initial delay in milliseconds until the {@link #finalImage} is
136           * updated the first time.           * updated the first time.
137           */           */
138          public static final int INITIAL_REPAINT_DELAY = 1000;          public static final int INITIAL_REPAINT_DELAY = 900;
139    
140          /**          /**
141           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,           * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
# Line 150  public class XMapPane extends JPanel { Line 152  public class XMapPane extends JPanel {
152           */           */
153          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;          public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
154    
155            /**
156             * This not-repeating {@link Timer} is re-started whenever the component is
157             * resized. That means => only if the component is not resizing for
158             * {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the
159             * {@link XMapPane} react.
160             */
161          private final Timer resizeTimer;          private final Timer resizeTimer;
162    
163            /**
164             * Flag for no-tool.
165             */
166          public static final int NONE = -123;          public static final int NONE = -123;
167    
168          /**          /**
# Line 163  public class XMapPane extends JPanel { Line 174  public class XMapPane extends JPanel {
174          public static final int PAN = 1;          public static final int PAN = 1;
175    
176          /**          /**
177             * Flag fuer Modus "Heran zoomen".
178             *
179             * @see #setState(int)
180             * @see #setState(int)
181             */
182            public static final int ZOOM_IN = 2;
183    
184            /**
185             * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
186             *
187             * @see #setState(int)
188             */
189            public static final int ZOOM_OUT = 3;
190    
191            /**
192           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".           * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".
193           *           *
194           * @see #setState(int)           * @see #setState(int)
# Line 186  public class XMapPane extends JPanel { Line 212  public class XMapPane extends JPanel {
212           */           */
213          public static final int SELECT_TOP = 4;          public static final int SELECT_TOP = 4;
214    
         public static final Cursor WAIT_CURSOR = Cursor  
                         .getPredefinedCursor(Cursor.WAIT_CURSOR);  
   
215          /**          /**
216           * {@link Font} used to paint the wait messages into the map           * {@link Font} used to paint the wait messages into the map
217           *           *
# Line 212  public class XMapPane extends JPanel { Line 235  public class XMapPane extends JPanel {
235          final String waitMsg = SwingUtil.R("WaitMess");          final String waitMsg = SwingUtil.R("WaitMess");
236    
237          /**          /**
          * 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;  
   
         /**  
238           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in           * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in
239           * Karten-Koordinaten.           * Karten-Koordinaten.
240           *           *
# Line 389  public class XMapPane extends JPanel { Line 397  public class XMapPane extends JPanel {
397                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
398                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
399    
400                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
401                          requestStartRendering();                          requestStartRendering();
402    
403                  }                  }
404    
405                  @Override                  @Override
406                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
407                          localRenderer.setContext(getMapContext());  //                      localRenderer = GTUtil.createGTRenderer();
408                            getLocalRenderer().setContext(getMapContext());
409                          requestStartRendering();                          requestStartRendering();
410                  }                  }
411    
412                  @Override                  @Override
413                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
414                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
415                          requestStartRendering();                          requestStartRendering();
416                  }                  }
417    
# Line 410  public class XMapPane extends JPanel { Line 419  public class XMapPane extends JPanel {
419                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
420                          if (event.getLayer() != null)                          if (event.getLayer() != null)
421                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
422                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
423                          requestStartRendering();                          requestStartRendering();
424                  }                  }
425          };          };
# Line 423  public class XMapPane extends JPanel { Line 432  public class XMapPane extends JPanel {
432    
433                  @Override                  @Override
434                  public void layerChanged(final MapLayerEvent event) {                  public void layerChanged(final MapLayerEvent event) {
435                          localRenderer.setContext(getMapContext()); // betters for SLD changes?!                          getLocalRenderer().setContext(getMapContext()); // betters for SLD
436                            // changes?!
437                          requestStartRendering();                          requestStartRendering();
438                  }                  }
439    
# Line 438  public class XMapPane extends JPanel { Line 448  public class XMapPane extends JPanel {
448                  }                  }
449          };          };
450    
451          private final GTRenderer localRenderer = GTUtil.createGTRenderer();          final private GTRenderer localRenderer = GTUtil.createGTRenderer();
452    
453          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
454    
# Line 459  public class XMapPane extends JPanel { Line 469  public class XMapPane extends JPanel {
469          /**          /**
470           * This color is used as the default background color when painting a map.           * This color is used as the default background color when painting a map.
471           */           */
472          private Color mapBackgroundColor = Color.WHITE;          private Color mapBackgroundColor = null;
473    
474          /**          /**
475           * A flag indicating that the shown image is invalid and needs to be           * A flag indicating that the shown image is invalid and needs to be
# Line 503  public class XMapPane extends JPanel { Line 513  public class XMapPane extends JPanel {
513           * A flag indicating, that the image size has changed and the buffered           * A flag indicating, that the image size has changed and the buffered
514           * images are not big enough any more           * images are not big enough any more
515           **/           **/
516          protected boolean paneResized = false;          protected boolean paneResized = true;
517    
518          private BufferedImage preFinalImage;          private BufferedImage preFinalImage;
519    
520          // if null, no quick preview will be shown          // ** if 0, no quick preview will be shown **/
521          private int quickPreviewHint = 0;          private int quickPreviewHint = 0;
522    
523          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
524                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(getLocalRenderer());
525    
526          /**          /**
527           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
# Line 554  public class XMapPane extends JPanel { Line 564  public class XMapPane extends JPanel {
564    
565          /** Is set if a renderer has an error **/          /** Is set if a renderer has an error **/
566          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();          protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
           
         /** If <code>true</code>, then rendering exceptions are rendererd into the map pane **/  
         private boolean showExceptions= false;  
567    
568          // /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet          /**
569          // defined, but we are **/           * If <code>true</code>, then rendering exceptions are rendererd into the
570          // private Envelope mapAreaCondidate = null;           * map pane
571             **/
572            private boolean showExceptions = false;
573    
574          public XMapPane() {          public XMapPane() {
575                  this(null, null);                  this(null, null);
# Line 610  public class XMapPane extends JPanel { Line 619  public class XMapPane extends JPanel {
619                                                  if (!isWellDefined())                                                  if (!isWellDefined())
620                                                          return;                                                          return;
621    
622                                                    LOGGER.debug("resizeTimer performed");
623    
624                                                  final Rectangle bounds = getVisibleRect();                                                  final Rectangle bounds = getVisibleRect();
625                                                  //                                                  //
626                                                  // System.out.println("\n\ntimer performs with bounds = "                                                  // System.out.println("\n\ntimer performs with bounds = "
# Line 619  public class XMapPane extends JPanel { Line 630  public class XMapPane extends JPanel {
630                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                                  bounds.x, bounds.y, bounds.x + bounds.width,
631                                                                  bounds.y + bounds.height);                                                                  bounds.y + bounds.height);
632    
633                                                  if (setMapArea(geoMapArea))                                                  if (setMapArea(geoMapArea)) {
634                                                            LOGGER.debug("  maparea changed");
635                                                          paneResized = true;                                                          paneResized = true;
636                                                  // else                                                  } else
637                                                  // syso                                                          LOGGER.debug("  maparea NOT changed");
638                                          }                                          }
639                                  });                                  });
640                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
641    
642                  this.addComponentListener(new ComponentAdapter() {                  this.addComponentListener(new ComponentAdapter() {
643    
644                            private Rectangle oldVisibleRect;
645    
646                          @Override                          @Override
647                          public void componentResized(final ComponentEvent e) {                          public void componentResized(final ComponentEvent e) {
648    
649                                  // Already cancel the tasks...                                  // Seems to be called twice with the same size..
650                                  if (bgExecuter != null)                                  if (oldVisibleRect != null
651                                          bgExecuter.cancelTask();                                                  && oldVisibleRect.equals(getVisibleRect())) {
652                                  if (localExecuter != null)                                          LOGGER.debug("skipping resize.");
653                                          localExecuter.cancelTask();                                          return;
654                                    }
655    
656                                    LOGGER.debug("resized: " + getVisibleRect());
657                                  resizeTimer.restart();                                  resizeTimer.restart();
658                                    oldVisibleRect = getVisibleRect();
659                          }                          }
660    
661                  });                  });
# Line 650  public class XMapPane extends JPanel { Line 667  public class XMapPane extends JPanel {
667    
668                          @Override                          @Override
669                          public void actionPerformed(final ActionEvent e) {                          public void actionPerformed(final ActionEvent e) {
670                                  if ((localExecuter != null && !localExecuter.isRunning())                                  if ((!localExecuter.isRunning())
671                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {                                                  && (bgExecuter != null && !bgExecuter.isRunning())) {
672                                          repaintTimer.stop();                                          repaintTimer.stop();
673                                  } else {                                  } else {
674                                          updateFinalImage();                                          updateFinalImage();
675                                          XMapPane.this.repaint(100);                                          XMapPane.this.repaint(100);
676    
677                                  }                                  }
678                          }                          }
679                  });                  });
680    
681                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);                  repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
682                  repaintTimer.setRepeats(true);                  repaintTimer.setRepeats(true);
683    
# Line 676  public class XMapPane extends JPanel { Line 695  public class XMapPane extends JPanel {
695                                                  if (localExecuter.isRunning()) {                                                  if (localExecuter.isRunning()) {
696                                                          localExecuter.cancelTask();                                                          localExecuter.cancelTask();
697                                                  } else {                                                  } else {
   
698                                                          // Stupidly, but we have to recheck the                                                          // Stupidly, but we have to recheck the
699                                                          setMapArea(getMapArea());                                                          setMapArea(getMapArea());
700                                                          requestStartRendering = false;                                                          requestStartRendering = false;
# Line 765  public class XMapPane extends JPanel { Line 783  public class XMapPane extends JPanel {
783                  }                  }
784    
785                  final Envelope maxAllowedExtend = getMaxExtend();                  final Envelope maxAllowedExtend = getMaxExtend();
786                    
787                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
788                                  && newArea != null && !newArea.isNull()                                  && newArea != null && !newArea.isNull()
789                                  && !Double.isNaN(newArea.getMinX())                                  && !Double.isNaN(newArea.getMinX())
# Line 910  public class XMapPane extends JPanel { Line 928  public class XMapPane extends JPanel {
928                          bgExecuter.dispose();                          bgExecuter.dispose();
929                  }                  }
930    
931                  if (localExecuter != null) {                  if (localExecuter.isRunning()) {
932                          int i = 0;                          int i = 0;
933                          localExecuter.cancelTask();                          localExecuter.cancelTask();
934                          while (i++ < 10 && localExecuter.isRunning()) {                          while (i++ < 10 && localExecuter.isRunning()) {
# Line 1131  public class XMapPane extends JPanel { Line 1149  public class XMapPane extends JPanel {
1149          }          }
1150    
1151          /**          /**
1152           * 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
1153             * methods looks for a parent component and will use its background color.
1154             * If no parent component is available, WHITE is returned.
1155           **/           **/
1156          public Color getMapBackgroundColor() {          public Color getMapBackgroundColor() {
1157                    if (mapBackgroundColor == null) {
1158                            if (getParent() != null)
1159                                    return getParent().getBackground();
1160                            else
1161                                    return Color.WHITE;
1162                    }
1163                  return mapBackgroundColor;                  return mapBackgroundColor;
1164          }          }
1165    
# Line 1161  public class XMapPane extends JPanel { Line 1187  public class XMapPane extends JPanel {
1187          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1188                  if (maxExtend == null) {                  if (maxExtend == null) {
1189                          // Commented-out because it takes soo much time!                          // Commented-out because it takes soo much time!
1190  //                          //
1191  //                      long start = System.currentTimeMillis();                          // long start = System.currentTimeMillis();
1192  //                      final ReferencedEnvelope layerBounds = GTUtil                          // final ReferencedEnvelope layerBounds = GTUtil
1193  //                                      .getVisibleLayoutBounds(localContext);                          // .getVisibleLayoutBounds(localContext);
1194  //                                                //                      
1195  //                      LOGGER.info( (System.currentTimeMillis()-start)+"m to get maxExtend");                          // LOGGER.info(
1196  //                                                // (System.currentTimeMillis()-start)+"m to get maxExtend");
1197  //                      if (layerBounds == null) {                          //                      
1198  //                              // TODO Last fallback could be the CRS valid area                          // if (layerBounds == null) {
1199  //                              return null;                          // // TODO Last fallback could be the CRS valid area
1200  //                      }                          // return null;
1201  //                          // }
1202  //                      // Kartenbereich um 10% vergroessern                          //
1203  //                      return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil                          // // Kartenbereich um 10% vergroessern
1204  //                                      .expandEnvelope(layerBounds, 0.1), true);                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1205                            // .expandEnvelope(layerBounds, 0.1), true);
1206                  }                  }
1207                  return maxExtend;                  return maxExtend;
1208          }          }
# Line 1306  public class XMapPane extends JPanel { Line 1333  public class XMapPane extends JPanel {
1333                  return true;                  return true;
1334          }          }
1335    
1336            /**
1337             * Called from the listeners while the mouse is dragging, this method either
1338             * paints a translated (moved/panned) version of the image, or a rectangle.
1339             *
1340             * @param startPos
1341             *            in screen coordinates
1342             * @param lastPos
1343             *            in screen coordinates
1344             * @param event
1345             *            the {@link MouseEvent} to read the mouse buttons from
1346             */
1347          public void mouseDragged(final Point startPos, final Point lastPos,          public void mouseDragged(final Point startPos, final Point lastPos,
1348                          final MouseEvent event) {                          final MouseEvent event) {
1349    
1350                  if ((getState() == XMapPane.PAN)                  if ((getState() == XMapPane.PAN)
1351                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {                                  || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
1352    
1353                            // Panning needs a panning coursor
1354                          if (getCursor() != SwingUtil.PANNING_CURSOR) {                          if (getCursor() != SwingUtil.PANNING_CURSOR) {
1355                                  setCursor(SwingUtil.PANNING_CURSOR);                                  setCursor(SwingUtil.PANNING_CURSOR);
1356    
1357                                  // While panning, we deactivate the rendering. So the tasts are                                  // While panning, we deactivate the rendering. So the tasks are
1358                                  // ready to start when the panning os done.                                  // ready to start when the panning is finished.
1359                                  if (bgExecuter != null)                                  if (bgExecuter != null && bgExecuter.isRunning())
1360                                          bgExecuter.cancelTask();                                          bgExecuter.cancelTask();
1361                                  if (localExecuter != null)                                  if (localExecuter.isRunning())
1362                                          localExecuter.cancelTask();                                          localExecuter.cancelTask();
1363                          }                          }
1364    
# Line 1366  public class XMapPane extends JPanel { Line 1405  public class XMapPane extends JPanel {
1405                  } else if ((getState() == XMapPane.ZOOM_IN)                  } else if ((getState() == XMapPane.ZOOM_IN)
1406                                  || (getState() == XMapPane.ZOOM_OUT)                                  || (getState() == XMapPane.ZOOM_OUT)
1407                                  || (getState() == XMapPane.SELECT_ALL)                                  || (getState() == XMapPane.SELECT_ALL)
1408                                  || (getState() == XMapPane.SELECT_TOP)                                  || (getState() == XMapPane.SELECT_TOP)) {
                 // || (getState() == XMapPane.SELECT_ONE_FROM_TOP)  
                 ) {  
                         final Graphics graphics = getGraphics();  
1409    
1410                            // Draws a rectangle
1411                            final Graphics graphics = getGraphics();
1412                          drawRectangle(graphics, startPos, event.getPoint());                          drawRectangle(graphics, startPos, event.getPoint());
1413                            if ((lastPos.x > 0) && (lastPos.y > 0))
                         if ((lastPos.x > 0) && (lastPos.y > 0)) {  
1414                                  drawRectangle(graphics, startPos, lastPos);                                  drawRectangle(graphics, startPos, lastPos);
                         }  
   
1415                          graphics.dispose();                          graphics.dispose();
   
1416                  }                  }
   
1417          }          }
1418    
1419          /**          /**
# Line 1396  public class XMapPane extends JPanel { Line 1429  public class XMapPane extends JPanel {
1429           * completed.           * completed.
1430           */           */
1431          public void onRenderingCompleted() {          public void onRenderingCompleted() {
1432                    LOGGER.debug("complete");
1433    
1434                  repaintTimer.stop();                  repaintTimer.stop();
1435                  updateFinalImage();  
1436                  repaint();                  // We "forget" about an exception every time we complete a rendering
1437                    // thread successfully
1438                  if (renderingErrors.size() > 0)                  if (renderingErrors.size() > 0)
1439                          renderingErrors.remove(0);                          renderingErrors.remove(0);
1440    
1441                    updateFinalImage();
1442                    repaint();
1443          }          }
1444    
1445          /**          /**
# Line 1416  public class XMapPane extends JPanel { Line 1455  public class XMapPane extends JPanel {
1455          public void onRenderingFailed(final Exception renderingError) {          public void onRenderingFailed(final Exception renderingError) {
1456    
1457                  // Store the exceptions so we can show it to the user:                  // Store the exceptions so we can show it to the user:
1458                  if (!(renderingError instanceof java.lang.IllegalArgumentException                  if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError
1459                                  && renderingError.getMessage().equals(                                  .getMessage().equals(
1460                                                  "Argument \"sourceCRS\" should not be null.")))                                                  "Argument \"sourceCRS\" should not be null.")))
1461                          this.renderingErrors.add(renderingError);                          this.renderingErrors.add(renderingError);
1462                  if (renderingErrors.size() > 3)                  if (renderingErrors.size() > 3)
1463                          renderingErrors.remove(0);                          renderingErrors.remove(0);
1464                    
1465                  repaintTimer.stop();                  repaintTimer.stop();
1466    
1467                  LOGGER.warn("Rendering failed", renderingError);                  LOGGER.warn("Rendering failed", renderingError);
1468                  updateFinalImage();                  updateFinalImage();
1469                  repaint();                  repaint();
1470    
1471          }          }
1472    
         public void onRenderingPending() {  
                 // LOGGER.debug("Pending rendering updates the preview...");  
                 updateFinalImage();  
                 repaint();  
         }  
   
1473          @Override          @Override
1474          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
1475    
1476                    // Maybe update the cursor and maybe stop the repainting timer
1477                    updateCursor();
1478    
1479                  if (!acceptsRepaintCalls)                  if (!acceptsRepaintCalls)
1480                          return;                          return;
1481    
1482                  // Maybe update the cursor and maybe stop the repainting timer                  if (!isWellDefined())
1483                  updateCursor();                          return;
1484    
1485                  // super.paintComponent(g); // candidate for removal  //               super.paintComponent(g); // candidate for removal
1486    
1487                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1488    
# Line 1463  public class XMapPane extends JPanel { Line 1500  public class XMapPane extends JPanel {
1500                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1501    
1502                                  if (getMapArea().covers(oldMapArea)) {                                  if (getMapArea().covers(oldMapArea)) {
1503                                          setQuickPreviewHint(ZOOM_OUT);                                          quickPreviewHint = ZOOM_OUT;
1504                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1505                                  } else if (oldMapArea.covers(getMapArea())) {                                  } else if (oldMapArea.covers(getMapArea())) {
1506                                          setQuickPreviewHint(ZOOM_IN);                                          quickPreviewHint = ZOOM_IN;
1507                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1508                                  }                                  }
   
1509                          }                          }
   
                         // if (paneResized) {  
                         // paneResized = false;  
                         // disposeImages();  
                         // }  
                         //  
                         // // Start the Threads and Timers to render the image  
                         // requestStartRendering();  
   
1510                  }                  }
1511    
1512                  if (!paintedSomething) {                  if (!paintedSomething) {
# Line 1567  public class XMapPane extends JPanel { Line 1594  public class XMapPane extends JPanel {
1594                          setCursor(SwingUtil.PAN_CURSOR);                          setCursor(SwingUtil.PAN_CURSOR);
1595          }          }
1596    
         //  
         // /**  
         // * 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);  
         // }  
         // }  
   
1597          /**          /**
1598           * Entfernt einen Listener von der Map.           * Entfernt einen Listener von der Map.
1599           *           *
# Line 1607  public class XMapPane extends JPanel { Line 1612  public class XMapPane extends JPanel {
1612          private void requestStartRendering() {          private void requestStartRendering() {
1613                  if (bgExecuter != null)                  if (bgExecuter != null)
1614                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1615                  if (localExecuter != null)  
1616                          localExecuter.cancelTask();                  localExecuter.cancelTask();
1617    
1618                  mapImageInvalid = true;                  mapImageInvalid = true;
1619                  if (paneResized) {                  if (paneResized) {
# Line 1703  public class XMapPane extends JPanel { Line 1708  public class XMapPane extends JPanel {
1708    
1709                          // setMapArea(localContext.getAreaOfInterest());                          // setMapArea(localContext.getAreaOfInterest());
1710    
1711                          localRenderer.setContext(localContext);                          getLocalRenderer().setContext(localContext);
1712    
1713                          this.localContext.addMapLayerListListener(localContextListener);                          this.localContext.addMapLayerListListener(localContextListener);
1714    
# Line 1716  public class XMapPane extends JPanel { Line 1721  public class XMapPane extends JPanel {
1721                  requestStartRendering();                  requestStartRendering();
1722    
1723          }          }
1724            
1725            public void setBorder(Border b) {
1726              super.setBorder(b);
1727            }
1728    
1729            /**
1730             * Triggers to repaint (fast) and re-render (slow) the JMapPane.
1731             */
1732            public void refresh() {
1733                    mapImageInvalid = true;
1734                    repaint();
1735            }
1736    
1737            // /**
1738            // * Triggers to use new {@link GTRenderer} and refresh the map. Should be
1739            // * called after {@link Style}s have been changed because GTRenderer is
1740            // * otherwise not working well.
1741            // */
1742            // public void refreshRenderers() {
1743            // localRenderer = GTUtil.createGTRenderer();
1744            // setLocalContext(getMapContext());
1745            // mapImageInvalid = true;
1746            // repaint();
1747            // }
1748    
1749        /**
1750         * Set the new map area.
1751         * @param newMapArea
1752         * @return <code>true</code> if the mapArea has been changed and a repaint
1753         *         has been triggered.
1754         */
1755          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1756                    if (newMapArea == null)
1757                            return false;
1758                    if (getMapContext().getCoordinateReferenceSystem() == null)
1759                            return false;
1760                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1761                                  .getCoordinateReferenceSystem()));                                  .getCoordinateReferenceSystem()));
1762          }          }
1763    
1764          /**          /**
1765         * Set the new map area.
1766           * @param newMapArea           * @param newMapArea
1767           * @return <code>true</code> if the mapArea has been changed and a repaint           * @return <code>true</code> if the mapArea has been changed and a repaint
1768           *         has been triggered.           *         has been triggered.
1769           */           */
1770          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;  
                 // }  
1771    
1772                  if (newMapArea == null                  if (newMapArea == null
1773                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {                                  || bestAllowedMapArea(newMapArea).equals(mapArea)) {
# Line 1793  public class XMapPane extends JPanel { Line 1825  public class XMapPane extends JPanel {
1825    
1826                  mapAreaChanged = true;                  mapAreaChanged = true;
1827    
1828                  repaint(100);                  repaint(200); // Do not remove it!
1829    
1830                  requestStartRendering();                  requestStartRendering();
1831    
# Line 1806  public class XMapPane extends JPanel { Line 1838  public class XMapPane extends JPanel {
1838           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1839           */           */
1840          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(Color bgColor) {
                 if (bgColor == null)  
                         bgColor = Color.WHITE;  
1841                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1842          }          }
1843    
# Line 1882  public class XMapPane extends JPanel { Line 1912  public class XMapPane extends JPanel {
1912          }          }
1913    
1914          /**          /**
1915           *           * If <code>true</code>, allow the {@link XMapPane} to process #repaint()
1916           * @param b           * requests. Otherwise the map will not paint anything and not start any
1917             * rendering {@link Thread}s.
1918           */           */
1919          public void setPainting(final boolean b) {          public void setPainting(final boolean b) {
1920                  acceptsRepaintCalls = b;                  acceptsRepaintCalls = b;
1921          }                  if (acceptsRepaintCalls == true)
1922                            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;  
   
1923          }          }
1924    
1925          private void setRendererHints(final Map<Object, Object> rendererHints) {          private void setRendererHints(final Map<Object, Object> rendererHints) {
# Line 1947  public class XMapPane extends JPanel { Line 1965  public class XMapPane extends JPanel {
1965          private void startRendering() {          private void startRendering() {
1966    
1967                  if (!isWellDefined() || !acceptsRepaintCalls) {                  if (!isWellDefined() || !acceptsRepaintCalls) {
1968                            // if we are not ready to start rendering, try it again the next
1969                            // time the timer is chacking the flag.
1970                          requestStartRendering = true;                          requestStartRendering = true;
1971                          return;                          return;
1972                  }                  }
# Line 1956  public class XMapPane extends JPanel { Line 1976  public class XMapPane extends JPanel {
1976                          bgExecuter.cancelTask();                          bgExecuter.cancelTask();
1977                  }                  }
1978    
1979                  if (localExecuter != null) {                  localExecuter.cancelTask();
                         localExecuter.cancelTask();  
                 }  
1980    
1981                  final Rectangle curPaintArea = getVisibleRect();                  final Rectangle curPaintArea = getVisibleRect();
1982    
# Line 1985  public class XMapPane extends JPanel { Line 2003  public class XMapPane extends JPanel {
2003                          // localExecuter = new RenderingExecutor(this, 150l);                          // localExecuter = new RenderingExecutor(this, 150l);
2004                          // LOGGER.debug("starting local renderer:");                          // LOGGER.debug("starting local renderer:");
2005    
2006                          localRenderer.setJava2DHints(getJava2dHints());                          getLocalRenderer().setJava2DHints(getJava2dHints());
2007                          localRenderer.setRendererHints(getRendererHints());                          getLocalRenderer().setRendererHints(getRendererHints());
2008    
2009                          final boolean submitted = localExecuter.submit(getMapArea(),                          final boolean submitted = localExecuter.submit(getMapArea(),
2010                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
2011                                          localRenderer                                          getLocalRenderer());
                         // , getWorldToScreenTransform()  
                                         );  
2012                          if (submitted)                          if (submitted)
2013                                  repaintTimer.restart();                                  repaintTimer.restart();
2014                          else                          else
# Line 2067  public class XMapPane extends JPanel { Line 2083  public class XMapPane extends JPanel {
2083                  // if the renderers have stopped, also stop the timer that is updating                  // if the renderers have stopped, also stop the timer that is updating
2084                  // the final image                  // the final image
2085                  if (bgExecuter != null && bgExecuter.isRunning()                  if (bgExecuter != null && bgExecuter.isRunning()
2086                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter.isRunning()) {
2087                          setCursor(WAIT_CURSOR);                          setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
2088                          return;                          return;
2089                  } else {                  } else {
2090                          // Allow one last rendering                          // Allow one last rendering
# Line 2181  public class XMapPane extends JPanel { Line 2197  public class XMapPane extends JPanel {
2197    
2198                  // If the rendering process is still running, indicate this is the image                  // If the rendering process is still running, indicate this is the image
2199                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()                  if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2200                                  || localExecuter != null && localExecuter.isRunning()) {                                  || localExecuter.isRunning()) {
2201    
2202                          y += 8;                          y += 8;
2203    
# Line 2200  public class XMapPane extends JPanel { Line 2216  public class XMapPane extends JPanel {
2216                          y += 24;                          y += 24;
2217                  }                  }
2218    
2219                  if (renderingErrors != null && isShowExceptions()) {                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
2220    
2221                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2222                          graphics.setFont(errorFont);                          graphics.setFont(errorFont);
# Line 2214  public class XMapPane extends JPanel { Line 2230  public class XMapPane extends JPanel {
2230                                  if (errStr == null)                                  if (errStr == null)
2231                                          errStr = "unknown error: " + ex.getClass().getSimpleName();                                          errStr = "unknown error: " + ex.getClass().getSimpleName();
2232    
2233                                  graphics.setColor(Color.WHITE);                                  graphics.setColor(getMapBackgroundColor());
2234                                  graphics.drawString(errStr, 5, y);                                  graphics.drawString(errStr, 5, y);
2235                                  graphics.setColor(Color.RED);                                  graphics.setColor(Color.RED);
2236                                  graphics.drawString(errStr, 6, y + 1);                                  graphics.drawString(errStr, 6, y + 1);
# Line 2247  public class XMapPane extends JPanel { Line 2263  public class XMapPane extends JPanel {
2263                  ReferencedEnvelope _mapArea;                  ReferencedEnvelope _mapArea;
2264                  if (mapArea == null)                  if (mapArea == null)
2265                          _mapArea = features.getBounds();                          _mapArea = features.getBounds();
2266                  else _mapArea = getMapArea();                  else
2267                            _mapArea = getMapArea();
2268                  double width = _mapArea.getWidth();                  double width = _mapArea.getWidth();
2269                  double height = _mapArea.getHeight();                  double height = _mapArea.getHeight();
2270                  final double ratio = height / width;                  final double ratio = height / width;
# Line 2383  public class XMapPane extends JPanel { Line 2400  public class XMapPane extends JPanel {
2400                  return showExceptions;                  return showExceptions;
2401          }          }
2402    
2403            public GTRenderer getLocalRenderer() {
2404                    return localRenderer;
2405            }
2406    
2407  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26