/[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 555 by alfonx, Tue Nov 24 09:17:22 2009 UTC revision 560 by alfonx, Tue Nov 24 14:57:05 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    
32  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
# Line 140  public class XMapPane extends JPanel { Line 141  public class XMapPane extends JPanel {
141           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}           * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
142           * with previews.           * with previews.
143           */           */
144          public static final int REPEATING_REPAINT_DELAY = 600;          public static final int REPEATING_REPAINT_DELAY = 500;
145    
146          /**          /**
147           * Default delay (milliseconds) before the map will be redrawn when resizing           * Default delay (milliseconds) before the map will be redrawn when resizing
# Line 395  public class XMapPane extends JPanel { Line 396  public class XMapPane extends JPanel {
396                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
397                          event.getLayer().addMapLayerListener(localMapLayerListener);                          event.getLayer().addMapLayerListener(localMapLayerListener);
398    
399                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
400                          requestStartRendering();                          requestStartRendering();
401    
402                  }                  }
403    
404                  @Override                  @Override
405                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
406                          localRenderer.setContext(getMapContext());  //                      localRenderer = GTUtil.createGTRenderer();
407                            getLocalRenderer().setContext(getMapContext());
408                          requestStartRendering();                          requestStartRendering();
409                  }                  }
410    
411                  @Override                  @Override
412                  public void layerMoved(final MapLayerListEvent event) {                  public void layerMoved(final MapLayerListEvent event) {
413                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
414                          requestStartRendering();                          requestStartRendering();
415                  }                  }
416    
# Line 416  public class XMapPane extends JPanel { Line 418  public class XMapPane extends JPanel {
418                  public void layerRemoved(final MapLayerListEvent event) {                  public void layerRemoved(final MapLayerListEvent event) {
419                          if (event.getLayer() != null)                          if (event.getLayer() != null)
420                                  event.getLayer().removeMapLayerListener(localMapLayerListener);                                  event.getLayer().removeMapLayerListener(localMapLayerListener);
421                          localRenderer.setContext(getMapContext());                          getLocalRenderer().setContext(getMapContext());
422                          requestStartRendering();                          requestStartRendering();
423                  }                  }
424          };          };
# Line 429  public class XMapPane extends JPanel { Line 431  public class XMapPane extends JPanel {
431    
432                  @Override                  @Override
433                  public void layerChanged(final MapLayerEvent event) {                  public void layerChanged(final MapLayerEvent event) {
434                          localRenderer.setContext(getMapContext()); // betters for SLD                          getLocalRenderer().setContext(getMapContext()); // betters for SLD
435                          // changes?!                          // changes?!
436                          requestStartRendering();                          requestStartRendering();
437                  }                  }
# Line 445  public class XMapPane extends JPanel { Line 447  public class XMapPane extends JPanel {
447                  }                  }
448          };          };
449    
450          private final GTRenderer localRenderer = GTUtil.createGTRenderer();          final private GTRenderer localRenderer = GTUtil.createGTRenderer();
451    
452          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();          private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
453    
# Line 466  public class XMapPane extends JPanel { Line 468  public class XMapPane extends JPanel {
468          /**          /**
469           * 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.
470           */           */
471          private Color mapBackgroundColor = Color.WHITE;          private Color mapBackgroundColor = null;
472    
473          /**          /**
474           * 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 518  public class XMapPane extends JPanel { Line 520  public class XMapPane extends JPanel {
520          private int quickPreviewHint = 0;          private int quickPreviewHint = 0;
521    
522          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
523                          .getDefaultGTRendererHints(localRenderer);                          .getDefaultGTRendererHints(getLocalRenderer());
524    
525          /**          /**
526           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will           * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
# Line 616  public class XMapPane extends JPanel { Line 618  public class XMapPane extends JPanel {
618                                                  if (!isWellDefined())                                                  if (!isWellDefined())
619                                                          return;                                                          return;
620    
621                                                  LOGGER.info("resizeTimer performed");                                                  LOGGER.debug("resizeTimer performed");
622    
623                                                  final Rectangle bounds = getVisibleRect();                                                  final Rectangle bounds = getVisibleRect();
624                                                  //                                                  //
# Line 628  public class XMapPane extends JPanel { Line 630  public class XMapPane extends JPanel {
630                                                                  bounds.y + bounds.height);                                                                  bounds.y + bounds.height);
631    
632                                                  if (setMapArea(geoMapArea)) {                                                  if (setMapArea(geoMapArea)) {
633                                                          LOGGER.info("  maparea changed");                                                          LOGGER.debug("  maparea changed");
634                                                          paneResized = true;                                                          paneResized = true;
635                                                  } else                                                  } else
636                                                          LOGGER.info("  maparea NOT changed");                                                          LOGGER.debug("  maparea NOT changed");
637                                          }                                          }
638                                  });                                  });
639                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
# Line 643  public class XMapPane extends JPanel { Line 645  public class XMapPane extends JPanel {
645                          @Override                          @Override
646                          public void componentResized(final ComponentEvent e) {                          public void componentResized(final ComponentEvent e) {
647    
648                                  // Seems to be called twice with the same size..                                  // Seems to be called twice with the same size..
649                                  if (oldVisibleRect != null                                  if (oldVisibleRect != null
650                                                  && oldVisibleRect.equals(getVisibleRect())){                                                  && oldVisibleRect.equals(getVisibleRect())) {
651                                          LOGGER.info("skipping resize.");                                          LOGGER.debug("skipping resize.");
652                                          return;                                          return;
653                                  }                                  }
654    
655                                  LOGGER.info("resized: " + getVisibleRect());                                  LOGGER.debug("resized: " + getVisibleRect());
656                                  resizeTimer.restart();                                  resizeTimer.restart();
657                                  oldVisibleRect = getVisibleRect();                                  oldVisibleRect = getVisibleRect();
658                          }                          }
# Line 1146  public class XMapPane extends JPanel { Line 1148  public class XMapPane extends JPanel {
1148          }          }
1149    
1150          /**          /**
1151           * 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
1152             * methods looks for a parent component and will use its background color.
1153             * If no parent component is available, WHITE is returned.
1154           **/           **/
1155          public Color getMapBackgroundColor() {          public Color getMapBackgroundColor() {
1156                    if (mapBackgroundColor == null) {
1157                            if (getParent() != null)
1158                                    return getParent().getBackground();
1159                            else
1160                                    return Color.WHITE;
1161                    }
1162                  return mapBackgroundColor;                  return mapBackgroundColor;
1163          }          }
1164    
# Line 1418  public class XMapPane extends JPanel { Line 1428  public class XMapPane extends JPanel {
1428           * completed.           * completed.
1429           */           */
1430          public void onRenderingCompleted() {          public void onRenderingCompleted() {
1431                  LOGGER.info("complete");                  LOGGER.debug("complete");
1432    
1433                  repaintTimer.stop();                  repaintTimer.stop();
1434    
# Line 1471  public class XMapPane extends JPanel { Line 1481  public class XMapPane extends JPanel {
1481                  if (!isWellDefined())                  if (!isWellDefined())
1482                          return;                          return;
1483    
1484                  // super.paintComponent(g); // candidate for removal  //               super.paintComponent(g); // candidate for removal
1485    
1486                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1487    
# Line 1697  public class XMapPane extends JPanel { Line 1707  public class XMapPane extends JPanel {
1707    
1708                          // setMapArea(localContext.getAreaOfInterest());                          // setMapArea(localContext.getAreaOfInterest());
1709    
1710                          localRenderer.setContext(localContext);                          getLocalRenderer().setContext(localContext);
1711    
1712                          this.localContext.addMapLayerListListener(localContextListener);                          this.localContext.addMapLayerListListener(localContextListener);
1713    
# Line 1711  public class XMapPane extends JPanel { Line 1721  public class XMapPane extends JPanel {
1721    
1722          }          }
1723    
1724            /**
1725             * Triggers to repaint (fast) and re-render (slow) the JMapPane.
1726             */
1727            public void refresh() {
1728                    mapImageInvalid = true;
1729                    repaint();
1730            }
1731    
1732            // /**
1733            // * Triggers to use new {@link GTRenderer} and refresh the map. Should be
1734            // * called after {@link Style}s have been changed because GTRenderer is
1735            // * otherwise not working well.
1736            // */
1737            // public void refreshRenderers() {
1738            // localRenderer = GTUtil.createGTRenderer();
1739            // setLocalContext(getMapContext());
1740            // mapImageInvalid = true;
1741            // repaint();
1742            // }
1743    
1744          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1745                    if (newMapArea == null)
1746                            return false;
1747                    if (getMapContext().getCoordinateReferenceSystem() == null)
1748                            return false;
1749                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()                  return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1750                                  .getCoordinateReferenceSystem()));                                  .getCoordinateReferenceSystem()));
1751          }          }
# Line 1792  public class XMapPane extends JPanel { Line 1826  public class XMapPane extends JPanel {
1826           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1827           */           */
1828          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(Color bgColor) {
                 if (bgColor == null)  
                         bgColor = Color.WHITE;  
1829                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1830          }          }
1831    
# Line 1959  public class XMapPane extends JPanel { Line 1991  public class XMapPane extends JPanel {
1991                          // localExecuter = new RenderingExecutor(this, 150l);                          // localExecuter = new RenderingExecutor(this, 150l);
1992                          // LOGGER.debug("starting local renderer:");                          // LOGGER.debug("starting local renderer:");
1993    
1994                          localRenderer.setJava2DHints(getJava2dHints());                          getLocalRenderer().setJava2DHints(getJava2dHints());
1995                          localRenderer.setRendererHints(getRendererHints());                          getLocalRenderer().setRendererHints(getRendererHints());
1996    
1997                          final boolean submitted = localExecuter.submit(getMapArea(),                          final boolean submitted = localExecuter.submit(getMapArea(),
1998                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),                                          curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
1999                                          localRenderer);                                          getLocalRenderer());
2000                          if (submitted)                          if (submitted)
2001                                  repaintTimer.restart();                                  repaintTimer.restart();
2002                          else                          else
# Line 2186  public class XMapPane extends JPanel { Line 2218  public class XMapPane extends JPanel {
2218                                  if (errStr == null)                                  if (errStr == null)
2219                                          errStr = "unknown error: " + ex.getClass().getSimpleName();                                          errStr = "unknown error: " + ex.getClass().getSimpleName();
2220    
2221                                  graphics.setColor(Color.WHITE);                                  graphics.setColor(getMapBackgroundColor());
2222                                  graphics.drawString(errStr, 5, y);                                  graphics.drawString(errStr, 5, y);
2223                                  graphics.setColor(Color.RED);                                  graphics.setColor(Color.RED);
2224                                  graphics.drawString(errStr, 6, y + 1);                                  graphics.drawString(errStr, 6, y + 1);
# Line 2356  public class XMapPane extends JPanel { Line 2388  public class XMapPane extends JPanel {
2388                  return showExceptions;                  return showExceptions;
2389          }          }
2390    
2391            public GTRenderer getLocalRenderer() {
2392                    return localRenderer;
2393            }
2394    
2395  }  }

Legend:
Removed from v.555  
changed lines
  Added in v.560

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26