/[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 606 by alfonx, Wed Dec 9 14:15:53 2009 UTC revision 607 by alfonx, Wed Dec 9 15:13:42 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;  import javax.swing.JList;
30  import javax.swing.Timer;  import javax.swing.Timer;
31  import javax.swing.border.Border;  import javax.swing.border.Border;
32    
33  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
34    import org.geotools.factory.GeoTools;
35  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
36  import org.geotools.geometry.jts.JTS;  import org.geotools.geometry.jts.JTS;
37  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
# Line 97  import com.vividsolutions.jts.geom.Geome Line 98  import com.vividsolutions.jts.geom.Geome
98   */   */
99  public class XMapPane extends JPanel {  public class XMapPane extends JPanel {
100    
101          private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;          // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
102          private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;          // private static final int IMAGETYPE_withAlpha =
103            // BufferedImage.TYPE_INT_ARGB;
104            private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
105            private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;
106    
107          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);          private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
108    
# Line 217  public class XMapPane extends JPanel { Line 221  public class XMapPane extends JPanel {
221           *           *
222           * @see #addGadgets(Graphics2D, boolean)           * @see #addGadgets(Graphics2D, boolean)
223           */           */
224          final static Font waitFont = new Font("Arial", Font.BOLD, 30);          final static Font waitFont = new Font("Arial", Font.BOLD, 28);
225    
226          /**          /**
227           * {@link Font} used to paint error messages into the map           * {@link Font} used to paint error messages into the map
# Line 227  public class XMapPane extends JPanel { Line 231  public class XMapPane extends JPanel {
231          final static Font errorFont = new Font("Arial", Font.BOLD, 13);          final static Font errorFont = new Font("Arial", Font.BOLD, 13);
232    
233          /**          /**
234             * If last average last two renderings took more than that many ms, show the
235             * user a scaled preview
236             **/
237            private static final long PRESCALE_MINTIME = 230;
238    
239            /**
240           * The wait message painted into the map while rendering is going on on           * The wait message painted into the map while rendering is going on on
241           * another thread.           * another thread.
242           *           *
# Line 278  public class XMapPane extends JPanel { Line 288  public class XMapPane extends JPanel {
288    
289                  @Override                  @Override
290                  public void layerAdded(final MapLayerListEvent event) {                  public void layerAdded(final MapLayerListEvent event) {
291                          MapLayer layer = event.getLayer();                          final MapLayer layer = event.getLayer();
292                          layer.addMapLayerListener(bgMapLayerListener);                          layer.addMapLayerListener(bgMapLayerListener);
293                          requestStartRendering();                          requestStartRendering();
294    
# Line 404  public class XMapPane extends JPanel { Line 414  public class XMapPane extends JPanel {
414    
415                  @Override                  @Override
416                  public void layerChanged(final MapLayerListEvent event) {                  public void layerChanged(final MapLayerListEvent event) {
417  //                      localRenderer = GTUtil.createGTRenderer();  //                      getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow...
                         getLocalRenderer().setContext(getMapContext());  
418                          requestStartRendering();                          requestStartRendering();
419                  }                  }
420    
# Line 426  public class XMapPane extends JPanel { Line 435  public class XMapPane extends JPanel {
435    
436          /**          /**
437           * Listens to each layer in the local {@link MapContext} for changes and           * Listens to each layer in the local {@link MapContext} for changes and
438           * triggers repaints.           * triggers repaints. We don't have to listen layerChanged, because that is
439             * already done in {@link #localContextListener}
440           */           */
441          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {          protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
442    
443                  @Override                  // @Override
444                  public void layerChanged(final MapLayerEvent event) {                  // public void layerChanged(final MapLayerEvent event) {
445                          getLocalRenderer().setContext(getMapContext()); // betters for SLD                  // // getLocalRenderer().setContext(getMapContext()); // betters for SLD
446                          // changes?!                  // // // changes?!
447                          requestStartRendering();                  // // requestStartRendering();
448                  }                  // }
449    
450                  @Override                  @Override
451                  public void layerHidden(final MapLayerEvent event) {                  public void layerHidden(final MapLayerEvent event) {
# Line 518  public class XMapPane extends JPanel { Line 528  public class XMapPane extends JPanel {
528          private BufferedImage preFinalImage;          private BufferedImage preFinalImage;
529    
530          // ** if 0, no quick preview will be shown **/          // ** if 0, no quick preview will be shown **/
531          private int quickPreviewHint = 0;          // private int quickPreviewHint = 0;
532    
533          private Map<Object, Object> rendererHints = GTUtil          private Map<Object, Object> rendererHints = GTUtil
534                          .getDefaultGTRendererHints(getLocalRenderer());                          .getDefaultGTRendererHints(getLocalRenderer());
# Line 619  public class XMapPane extends JPanel { Line 629  public class XMapPane extends JPanel {
629                                                  if (!isWellDefined())                                                  if (!isWellDefined())
630                                                          return;                                                          return;
631    
632                                                  LOGGER.debug("resizeTimer performed");                                                  // LOGGER.debug("resizeTimer performed");
633    
634                                                  final Rectangle bounds = getVisibleRect();                                                  // final Rectangle bounds = getVisibleRect();
635                                                  //                                                  //
636                                                  // System.out.println("\n\ntimer performs with bounds = "                                                  // System.out.println("\n\ntimer performs with bounds = "
637                                                  // + bounds);                                                  // + bounds);
638    
639                                                  final Envelope geoMapArea = tranformWindowToGeo(                                                  // final Envelope geoMapArea = tranformWindowToGeo(
640                                                                  bounds.x, bounds.y, bounds.x + bounds.width,                                                  // bounds.x, bounds.y, bounds.x + bounds.width,
641                                                                  bounds.y + bounds.height);                                                  // bounds.y + bounds.height);
642    
643                                                  if (setMapArea(geoMapArea)) {                                                  paneResized = true;
644                                                          LOGGER.debug("  maparea changed");                                                  if (!setMapArea(getMapArea())) {
645                                                          paneResized = true;                                                          // It's important to request new rendering here.
646                                                  } else                                                          // setMapArea only returns true and only calls
647                                                          LOGGER.debug("  maparea NOT changed");                                                          // requestStartRendering if the maparea has changed.
648                                                            // But if the component is resized, the maparea
649                                                            // doesn't have to change.
650                                                            requestStartRendering();
651                                                    }
652    
653                                          }                                          }
654                                  });                                  });
655                  resizeTimer.setRepeats(false);                  resizeTimer.setRepeats(false);
# Line 649  public class XMapPane extends JPanel { Line 664  public class XMapPane extends JPanel {
664                                  // Seems to be called twice with the same size..                                  // Seems to be called twice with the same size..
665                                  if (oldVisibleRect != null                                  if (oldVisibleRect != null
666                                                  && oldVisibleRect.equals(getVisibleRect())) {                                                  && oldVisibleRect.equals(getVisibleRect())) {
667                                          LOGGER.debug("skipping resize.");                                          // LOGGER.debug("skipping resize.");
668                                          return;                                          return;
669                                  }                                  }
670    
671                                  LOGGER.debug("resized: " + getVisibleRect());                                  // LOGGER.debug("resized: " + getVisibleRect());
672                                  resizeTimer.restart();                                  resizeTimer.restart();
673                                  oldVisibleRect = getVisibleRect();                                  oldVisibleRect = getVisibleRect();
674                          }                          }
# Line 997  public class XMapPane extends JPanel { Line 1012  public class XMapPane extends JPanel {
1012           *           *
1013           * @param g           * @param g
1014           *            Graphics2D to paint the preview into           *            Graphics2D to paint the preview into
          *  
          * @param state  
          *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}  
1015           */           */
1016          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {          protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
1017    
1018                  // if (1 == 1)return false;                  // if (1 == 1)return false;
1019                    // if (quickPreviewHint == 0)
1020                    // return false;
1021    
1022                  if (quickPreviewHint == 0)                  if (oldMapArea == null)
1023                          return false;                          return false;
1024    
1025                  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                  if (getPreFinalImage() == null)
                                 RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  
                 graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
                                 RenderingHints.VALUE_ANTIALIAS_OFF);  
                 graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  
                                 RenderingHints.VALUE_RENDER_SPEED);  
   
                 if (oldMapArea == null)  
1026                          return false;                          return false;
1027    
1028                  final Rectangle visibleArea = getVisibleRect();                  final Rectangle visibleArea = getVisibleRect();
# Line 1030  public class XMapPane extends JPanel { Line 1037  public class XMapPane extends JPanel {
1037                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());                  final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1038                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());                  final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1039    
1040                    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1041                                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1042                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1043                                    RenderingHints.VALUE_ANTIALIAS_OFF);
1044                    graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1045                                    RenderingHints.VALUE_RENDER_SPEED);
1046    
1047                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,                  graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1048                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),                                  (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1049                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),                                  (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
# Line 1038  public class XMapPane extends JPanel { Line 1052  public class XMapPane extends JPanel {
1052                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2                  final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1053                                  - yy1);                                  - yy1);
1054    
1055                  SwingUtil.clearAround(graphics, painedArea, visibleArea);                  SwingUtil.clearAround(graphics, painedArea, visibleArea,
1056                                    getMapBackgroundColor());
1057    
1058                  addGadgets(graphics, true);                  addGadgets(graphics, true);
1059    
1060                  quickPreviewHint = 0;                  // quickPreviewHint = 0;
1061    
1062                  repaintTimer.restart();                  repaintTimer.restart();
1063    
                 graphics.dispose();  
   
1064                  // Something has been drawn                  // Something has been drawn
1065                  return true;                  return true;
1066          }          }
# Line 1060  public class XMapPane extends JPanel { Line 1073  public class XMapPane extends JPanel {
1073           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1074           */           */
1075          private Image getBgImage() {          private Image getBgImage() {
1076                  //                  if (bgImage == null) {
1077                  // if (bgImage == null) {                          bgImage = new BufferedImage(getVisibleRect().width,
1078                  // bgImage = createImage(getBounds().width, getBounds().height);                                          getVisibleRect().height, IMAGETYPE);
1079                  // }                          SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1080                    }
1081    
1082                  return bgImage;                  return bgImage;
1083          }          }
# Line 1081  public class XMapPane extends JPanel { Line 1095  public class XMapPane extends JPanel {
1095                          // Rectangle curPaintArea = getVisibleRect();                          // Rectangle curPaintArea = getVisibleRect();
1096                          finalImage = new BufferedImage(getVisibleRect().width,                          finalImage = new BufferedImage(getVisibleRect().width,
1097                                          getVisibleRect().height, IMAGETYPE);                                          getVisibleRect().height, IMAGETYPE);
1098                            SwingUtil.clearImage(finalImage, getMapBackgroundColor());
1099    
1100                          requestStartRendering();                          // requestStartRendering();
1101                  }                  }
1102                  return finalImage;                  return finalImage;
1103          }          }
1104    
         public RenderingHints getJava2dHints() {  
                 return java2dHints;  
         }  
   
1105          /**          /**
1106           * Lazyly initializes a {@link BufferedImage} for the background renderer.           * Lazyly initializes a {@link BufferedImage} for the background renderer.
1107           */           */
# Line 1099  public class XMapPane extends JPanel { Line 1110  public class XMapPane extends JPanel {
1110                  if (localImage == null) {                  if (localImage == null) {
1111                          localImage = new BufferedImage(getVisibleRect().width,                          localImage = new BufferedImage(getVisibleRect().width,
1112                                          getVisibleRect().height, IMAGETYPE_withAlpha);                                          getVisibleRect().height, IMAGETYPE_withAlpha);
1113                            SwingUtil.clearImage(localImage, getMapBackgroundColor());
1114                  }                  }
1115    
1116                  return localImage;                  return localImage;
# Line 1140  public class XMapPane extends JPanel { Line 1152  public class XMapPane extends JPanel {
1152                          try {                          try {
1153                                  localContext.setCoordinateReferenceSystem(GeoImportUtil                                  localContext.setCoordinateReferenceSystem(GeoImportUtil
1154                                                  .getDefaultCRS());                                                  .getDefaultCRS());
1155                          } catch (Exception e) {                          } catch (final Exception e) {
1156                                  throw new RuntimeException("setting context CRS:", e);                                  throw new RuntimeException("setting context CRS:", e);
1157                          }                          }
1158    
# Line 1186  public class XMapPane extends JPanel { Line 1198  public class XMapPane extends JPanel {
1198    
1199          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1200                  if (maxExtend == null) {                  if (maxExtend == null) {
1201                          // Commented-out because it takes soo much time!  
1202                          //                          // The next command may take long time!
1203                          // long start = System.currentTimeMillis();                          // long start = System.currentTimeMillis();
1204                          // final ReferencedEnvelope layerBounds = GTUtil                          final ReferencedEnvelope layerBounds = GTUtil
1205                          // .getVisibleLayoutBounds(localContext);                                          .getVisibleLayoutBounds(localContext);
1206                          //                                                //                      
1207                          // LOGGER.info(                          // LOGGER.info(
1208                          // (System.currentTimeMillis()-start)+"m to get maxExtend");                          // (System.currentTimeMillis()-start)+"m to get maxExtend");
1209                          //                                                //                      
1210                          // if (layerBounds == null) {                          if (layerBounds == null) {
1211                          // // TODO Last fallback could be the CRS valid area                                  // // TODO Last fallback could be the CRS valid area
1212                          // return null;                                  return null;
1213                          // }                          }
1214                          //  
1215                          // // Kartenbereich um 10% vergroessern                          // Vergrößerung um 10% nochmal rausgenommen
1216                            // // // Kartenbereich um 10% vergroessern
1217                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil                          // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1218                          // .expandEnvelope(layerBounds, 0.1), true);                          // .expandEnvelope(layerBounds, 0.1), true);
1219    
1220                            return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true);
1221                  }                  }
1222                  return maxExtend;                  return maxExtend;
1223          }          }
# Line 1230  public class XMapPane extends JPanel { Line 1245  public class XMapPane extends JPanel {
1245          }          }
1246    
1247          private Image getPreFinalImage() {          private Image getPreFinalImage() {
                 // if (preFinalImage == null) {  
                 //                        
                 // // Rectangle curPaintArea = getVisibleRect();  
                 // // preFinalImage = new BufferedImage(curPaintArea.width,  
                 // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);  
                 //                        
                 // preFinalImage = createImage(getBounds().width, getBounds().height);  
                 //  
                 // requestStartRendering();  
                 // }  
1248                  return preFinalImage;                  return preFinalImage;
1249          }          }
1250    
# Line 1408  public class XMapPane extends JPanel { Line 1413  public class XMapPane extends JPanel {
1413                                  || (getState() == XMapPane.SELECT_TOP)) {                                  || (getState() == XMapPane.SELECT_TOP)) {
1414    
1415                          // Draws a rectangle                          // Draws a rectangle
1416                          final Graphics graphics = getGraphics();                          final Graphics2D graphics = (Graphics2D) getGraphics();
1417                          drawRectangle(graphics, startPos, event.getPoint());                          drawRectangle(graphics, startPos, event.getPoint());
1418                          if ((lastPos.x > 0) && (lastPos.y > 0))                          if ((lastPos.x > 0) && (lastPos.y > 0))
1419                                  drawRectangle(graphics, startPos, lastPos);                                  drawRectangle(graphics, startPos, lastPos);
# Line 1420  public class XMapPane extends JPanel { Line 1425  public class XMapPane extends JPanel {
1425           * Called by the {@link RenderingExecutor} when rendering was cancelled.           * Called by the {@link RenderingExecutor} when rendering was cancelled.
1426           */           */
1427          public void onRenderingCancelled() {          public void onRenderingCancelled() {
1428                  LOGGER.debug("Rendering cancelled");                  // LOGGER.debug("Rendering cancelled");
1429                  repaintTimer.stop();                  repaintTimer.stop();
1430          }          }
1431    
1432          /**          /**
1433           * Called by the {@link RenderingExecutor} when rendering has been           * Called by the {@link RenderingExecutor} when rendering has been
1434           * completed.           * completed.
1435             *
1436             * @param l
1437             *            long ms the rendering took
1438           */           */
1439          public void onRenderingCompleted() {          public void onRenderingCompleted(final long l) {
1440                  LOGGER.debug("complete");                  lastRenderingDuration = (lastRenderingDuration + l) / 2;
1441                    LOGGER
1442                                    .debug("complete rendering after " + lastRenderingDuration
1443                                                    + "ms");
1444    
1445                  repaintTimer.stop();                  repaintTimer.stop();
1446    
# Line 1481  public class XMapPane extends JPanel { Line 1492  public class XMapPane extends JPanel {
1492    
1493                  if (!isWellDefined())                  if (!isWellDefined())
1494                          return;                          return;
1495                    //
1496                    // if (paneResized) {
1497                    // // ((Graphics2D) g).setBackground(getMapBackgroundColor());
1498                    // // g.clearRect(0, 0, getVisibleRect().width,
1499                    // getVisibleRect().height);
1500                    // return;
1501                    // }
1502    
1503  //               super.paintComponent(g); // candidate for removal                  // super.paintComponent(g); // candidate for removal
1504    
1505                  boolean paintedSomething = false;                  boolean paintedSomething = false;
1506    
# Line 1493  public class XMapPane extends JPanel { Line 1511  public class XMapPane extends JPanel {
1511                          // If the new mapArea and the oldMapArea intersect, we can draw some                          // If the new mapArea and the oldMapArea intersect, we can draw some
1512                          // quick scaled preview to make the user feel that something is                          // quick scaled preview to make the user feel that something is
1513                          // happening.                          // happening.
1514                          if (mapAreaChanged && oldMapArea != null                          if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged
1515                                            && oldMapArea != null
1516                                          && getMapArea().intersects(oldMapArea)                                          && getMapArea().intersects(oldMapArea)
1517                                          & !getMapArea().equals(oldMapArea) && !paneResized) {                                          && !getMapArea().equals(oldMapArea) && !paneResized) {
1518    
1519                                  mapAreaChanged = false;                                  mapAreaChanged = false;
1520    
1521                                  if (getMapArea().covers(oldMapArea)) {                                  // if (getMapArea().covers(oldMapArea)) {
1522                                          quickPreviewHint = ZOOM_OUT;                                  // // quickPreviewHint = ZOOM_OUT;
1523                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D)
1524                                  } else if (oldMapArea.covers(getMapArea())) {                                  // g);
1525                                          quickPreviewHint = ZOOM_IN;                                  // } else if (oldMapArea.covers(getMapArea())) {
1526                                          paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);                                  // quickPreviewHint = ZOOM_IN;
1527                                  }                                  paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1528                                    // }
1529                          }                          }
1530                  }                  }
1531    
# Line 1513  public class XMapPane extends JPanel { Line 1533  public class XMapPane extends JPanel {
1533    
1534                          g.drawImage(getFinalImage(), 0, 0, null);                          g.drawImage(getFinalImage(), 0, 0, null);
1535    
                         g.dispose(); // cand. for removal  
   
1536                          paintedSomething = true; // cand. for removal                          paintedSomething = true; // cand. for removal
1537                  }                  }
1538    
# Line 1570  public class XMapPane extends JPanel { Line 1588  public class XMapPane extends JPanel {
1588           */           */
1589          public void performPan() {          public void performPan() {
1590    
1591                  Rectangle winBounds = getVisibleRect();                  final Rectangle winBounds = getVisibleRect();
1592    
1593                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1594                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,                  final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
# Line 1638  public class XMapPane extends JPanel { Line 1656  public class XMapPane extends JPanel {
1656           *            the current map pane extent (screen units)           *            the current map pane extent (screen units)
1657           */           */
1658          private void resetTransforms() {          private void resetTransforms() {
1659                  ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,                  final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1660                                  getMapContext().getCoordinateReferenceSystem());                                  getMapContext().getCoordinateReferenceSystem());
1661    
1662                  // System.out                  // System.out
# Line 1652  public class XMapPane extends JPanel { Line 1670  public class XMapPane extends JPanel {
1670                  try {                  try {
1671                          screenToWorld = worldToScreen.createInverse();                          screenToWorld = worldToScreen.createInverse();
1672    
1673                  } catch (NoninvertibleTransformException ex) {                  } catch (final NoninvertibleTransformException ex) {
1674                          LOGGER                          LOGGER
1675                                          .error("can't invert worldToScreen to get screenToWorld!",                                          .error("can't invert worldToScreen to get screenToWorld!",
1676                                                          ex);                                                          ex);
# Line 1721  public class XMapPane extends JPanel { Line 1739  public class XMapPane extends JPanel {
1739                  requestStartRendering();                  requestStartRendering();
1740    
1741          }          }
1742            
1743          public void setBorder(Border b) {          public void setBorder(final Border b) {
1744            super.setBorder(b);                  super.setBorder(b);
1745          }          }
1746    
1747          /**          /**
# Line 1746  public class XMapPane extends JPanel { Line 1764  public class XMapPane extends JPanel {
1764          // repaint();          // repaint();
1765          // }          // }
1766    
1767      /**          /**
1768       * Set the new map area.           * Set the new map area.
1769       * @param newMapArea           *
1770       * @return <code>true</code> if the mapArea has been changed and a repaint           * @param newMapArea
1771       *         has been triggered.           * @return <code>true</code> if the mapArea has been changed and a repaint
1772       */           *         has been triggered.
1773             */
1774          public boolean setMapArea(final Envelope newMapArea) {          public boolean setMapArea(final Envelope newMapArea) {
1775                  if (newMapArea == null)                  if (newMapArea == null)
1776                          return false;                          return false;
# Line 1762  public class XMapPane extends JPanel { Line 1781  public class XMapPane extends JPanel {
1781          }          }
1782    
1783          /**          /**
1784       * Set the new map area.           * Set the new map area.
1785             *
1786           * @param newMapArea           * @param newMapArea
1787           * @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
1788           *         has been triggered.           *         has been triggered.
# Line 1837  public class XMapPane extends JPanel { Line 1857  public class XMapPane extends JPanel {
1857           *           *
1858           * @param if <code>null</code>, white is used.           * @param if <code>null</code>, white is used.
1859           */           */
1860          public void setMapBackgroundColor(Color bgColor) {          public void setMapBackgroundColor(final Color bgColor) {
1861                  this.mapBackgroundColor = bgColor;                  this.mapBackgroundColor = bgColor;
1862          }          }
1863    
# Line 1895  public class XMapPane extends JPanel { Line 1915  public class XMapPane extends JPanel {
1915          }          }
1916    
1917          // /** Stored the time used for the last real rendering in ms. **/          // /** Stored the time used for the last real rendering in ms. **/
1918          // private long lastRenderingDuration = Long.MAX_VALUE;          private long lastRenderingDuration = 1000;
1919    
1920          /**          /**
1921           * Set the minimum (nearest) allowed zoom scale. This is the bigger number           * Set the minimum (nearest) allowed zoom scale. This is the bigger number
# Line 2020  public class XMapPane extends JPanel { Line 2040  public class XMapPane extends JPanel {
2040                  updateCursor();                  updateCursor();
2041          }          }
2042    
2043            private RenderingHints getJava2dHints() {
2044                    return java2dHints;
2045            }
2046    
2047          /**          /**
2048           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.           * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.
2049           *           *
# Line 2159  public class XMapPane extends JPanel { Line 2183  public class XMapPane extends JPanel {
2183                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,                  finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
2184                                  getMapBackgroundColor(), null);                                  getMapBackgroundColor(), null);
2185    
2186                  final int finalImageHeight = getFinalImage().getHeight(null);                  // When panning, we have to clear the area around the image
                 final int finalImageWidth = getFinalImage().getWidth(null);  
   
2187                  final Rectangle painedArea = new Rectangle(imageOrigin.x,                  final Rectangle painedArea = new Rectangle(imageOrigin.x,
2188                                  imageOrigin.y, finalImageWidth, finalImageHeight);                                  imageOrigin.y, getFinalImage().getWidth(), getFinalImage()
2189                  SwingUtil.clearAround(finalG, painedArea, getVisibleRect());                                                  .getHeight());
2190                    SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
2191                                    getMapBackgroundColor());
2192    
2193                  addGadgets(finalG, false);                  addGadgets(finalG, false);
2194    
# Line 2183  public class XMapPane extends JPanel { Line 2207  public class XMapPane extends JPanel {
2207           *            <code>false</code>, it will only depend on           *            <code>false</code>, it will only depend on
2208           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning           *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2209           */           */
2210          private void addGadgets(final Graphics2D graphics, boolean forceWait) {          private void addGadgets(final Graphics2D graphics, final boolean forceWait) {
2211    
2212                  // Paint a logo to the bottom right if available                  // Paint a logo to the bottom right if available
2213                  if (mapImage != null) {                  if (mapImage != null) {
2214                          Rectangle visibleRect = getVisibleRect();                          final Rectangle visibleRect = getVisibleRect();
2215                          graphics.drawImage(mapImage, visibleRect.width                          graphics.drawImage(mapImage, visibleRect.width
2216                                          - mapImage.getWidth() - 10, getVisibleRect().height                                          - mapImage.getWidth() - 10, getVisibleRect().height
2217                                          - mapImage.getHeight() - 10, null);                                          - mapImage.getHeight() - 10, null);
# Line 2213  public class XMapPane extends JPanel { Line 2237  public class XMapPane extends JPanel {
2237    
2238                          graphics.setColor(c);                          graphics.setColor(c);
2239    
2240                          y += 24;                          y += 21;
2241                  }                  }
2242    
2243                  if (!renderingErrors.isEmpty() && isShowExceptions()) {                  if (!renderingErrors.isEmpty() && isShowExceptions()) {
# Line 2221  public class XMapPane extends JPanel { Line 2245  public class XMapPane extends JPanel {
2245                          final Color c = graphics.getColor();                          final Color c = graphics.getColor();
2246                          graphics.setFont(errorFont);                          graphics.setFont(errorFont);
2247    
2248                          for (Exception ex : renderingErrors) {                          for (final Exception ex : renderingErrors) {
2249    
2250                                  String errStr = ex.getLocalizedMessage();                                  String errStr = ex.getLocalizedMessage();
2251    
# Line 2258  public class XMapPane extends JPanel { Line 2282  public class XMapPane extends JPanel {
2282                  final CoordinateReferenceSystem mapCRS = getMapContext()                  final CoordinateReferenceSystem mapCRS = getMapContext()
2283                                  .getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2284                  final CoordinateReferenceSystem fCRS = features.getSchema()                  final CoordinateReferenceSystem fCRS = features.getSchema()
2285                                  .getGeometryDescriptor().getCoordinateReferenceSystem();                                  .getCoordinateReferenceSystem();
2286    
2287                  ReferencedEnvelope _mapArea;                  ReferencedEnvelope _mapArea;
2288                  if (mapArea == null)                  if (mapArea == null)
# Line 2376  public class XMapPane extends JPanel { Line 2400  public class XMapPane extends JPanel {
2400                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea                                  .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2401                                  .getHeight()) / 2.);                                  .getHeight()) / 2.);
2402    
2403                  // TODO we actually want that                  // // Move the newMapArea above the new center if we zoom in:
2404                  // // Move the newMapArea above the new center                  if (zoomFaktor >= 1) {
2405                  // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter                          newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2406                  // .getY()                                          .getY()
2407                  // - mapArea.centre().y);                                          - mapArea.centre().y);
2408                    }
2409    
2410                  setMapArea(newMapArea);                  setMapArea(newMapArea);
2411          }          }
# Line 2389  public class XMapPane extends JPanel { Line 2414  public class XMapPane extends JPanel {
2414           * Shall non-fatal rendering exceptions be reported in the mappane or be           * Shall non-fatal rendering exceptions be reported in the mappane or be
2415           * dropped quitely.           * dropped quitely.
2416           */           */
2417          public void setShowExceptions(boolean showExceptions) {          public void setShowExceptions(final boolean showExceptions) {
2418                  this.showExceptions = showExceptions;                  this.showExceptions = showExceptions;
2419          }          }
2420    
# Line 2404  public class XMapPane extends JPanel { Line 2429  public class XMapPane extends JPanel {
2429                  return localRenderer;                  return localRenderer;
2430          }          }
2431    
2432    
2433    
2434            /**
2435             * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
2436             * Macht nichts, wenn {@code null} uebergeben wird.
2437             *
2438             * <br>
2439             *
2440             * @param layer
2441             *            ein Layer
2442             */
2443            public void zoomToLayer(MapLayer layer) {
2444                    if (layer == null)
2445                            return;
2446                    try {
2447    
2448                            // BB umrechnen von Layer-CRS in Map-CRS
2449                            final CoordinateReferenceSystem targetCRS = getMapContext()
2450                                            .getCoordinateReferenceSystem();
2451                            final CoordinateReferenceSystem sourceCRS = layer
2452                                            .getFeatureSource().getSchema()
2453                                            .getCoordinateReferenceSystem();
2454    
2455                            Envelope mapAreaNew;
2456                            if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
2457                                    mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource()
2458                                                    .getBounds(), sourceCRS, targetCRS);
2459                            } else {
2460                                    try {
2461                                            mapAreaNew = layer.getFeatureSource().getBounds();
2462                                    } catch (java.lang.IllegalArgumentException e) {
2463                                            LOGGER.error("Can't calc layers bounds...", e);
2464                                            mapAreaNew = null;
2465    
2466                                            /**
2467                                             *
2468                                             23.10.2009 11:20:50
2469                                             * org.geotools.data.shapefile.shp.PolygonHandler read
2470                                             * WARNUNG: only one hole in this polygon record ERROR
2471                                             * JMapPane zoomToLayer Zoom to layer did not terminate
2472                                             * correctly java.lang.IllegalArgumentException: Points of
2473                                             * LinearRing do not form a closed linestring at
2474                                             * com.vividsolutions
2475                                             * .jts.geom.LinearRing.validateConstruction
2476                                             * (LinearRing.java:105) at
2477                                             * com.vividsolutions.jts.geom.LinearRing
2478                                             * .<init>(LinearRing.java:100) at
2479                                             * com.vividsolutions.jts.geom
2480                                             * .GeometryFactory.createLinearRing
2481                                             * (GeometryFactory.java:339) at
2482                                             * org.geotools.data.shapefile.
2483                                             * shp.PolygonHandler.read(PolygonHandler.java:188) at
2484                                             * org.geotools
2485                                             * .data.shapefile.shp.ShapefileReader$Record.shape
2486                                             * (ShapefileReader.java:106) at
2487                                             * org.geotools.data.shapefile.
2488                                             * ShapefileAttributeReader.next(
2489                                             * ShapefileAttributeReader.java:157) at
2490                                             * org.geotools.data.shapefile
2491                                             * .indexed.IndexedShapefileAttributeReader
2492                                             * .next(IndexedShapefileAttributeReader.java:122) at
2493                                             * org.geotools
2494                                             * .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at
2495                                             * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.
2496                                             * java:55) at org.geotools.data.MaxFeatureReader.next(
2497                                             * MaxFeatureReader.java:61) at
2498                                             * org.geotools.data.MaxFeatureReader
2499                                             * .next(MaxFeatureReader.java:61)
2500                                             **/
2501                                    }
2502                            }
2503    
2504                            // Kartenbereich um 10% vergroessern, damit z.B. auch ein
2505                            // Punkt-Layer,
2506                            // welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen
2507                            // sonst
2508                            // genau auf dem Rand der angezeigten Flaeche)
2509    
2510                            if (mapAreaNew != null) {
2511                                    mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew
2512                                                    .getHeight() * 0.1);
2513                                    setMapArea(mapAreaNew);
2514                            } else {
2515                                    LOGGER
2516                                                    .warn("Couldn't transformEnvelope when zooming to the layer");
2517                            }
2518                    } catch (Exception err) {
2519                            LOGGER.error("Zoom to layer did not terminate correctly", err);
2520                    }
2521            }
2522    
2523            /**
2524             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer.
2525             *
2526             * <br>
2527             * A refresh of the map is not done automatically
2528             *
2529             * @param index
2530             *            Index of the {@link MapLayer} in the {@link MapContext} (from
2531             *            back to top)
2532             *
2533             * @author <a href="mailto:[email protected]">Stefan Alfons
2534             *         Kr&uuml;ger</a>
2535             */
2536            public void zoomToLayer(int index) {
2537                    final MapContext context = getMapContext();
2538                    if (context != null)
2539                            zoomToLayer(context.getLayer(index));
2540            }
2541    
2542            /**
2543             * Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the
2544             * selected layer. The layer is selected by the idx, counting from front to
2545             * back, like humans would expect in a {@link JList}
2546             *
2547             * <br>
2548             * A refresh of the map is not done automatically
2549             *
2550             *
2551             *
2552             * @param index
2553             *            Reverse index of the {@link MapLayer} in the
2554             *            {@link MapContext}
2555             *
2556             * @author <a href="mailto:[email protected]">Stefan Alfons
2557             *         Kr&uuml;ger</a>
2558             */
2559            public void zoomToLayerIdxReverse(int index) {
2560                    zoomToLayer(getMapContext().getLayerCount() - 1 - index);
2561            }
2562    
2563            
2564            
2565    
2566    
2567            /**
2568             * Aktiviert oder deaktiviert das AntiAliasing for diese
2569             * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
2570             * Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance.
2571             *
2572             * @author <a href="mailto:[email protected]">Stefan Alfons
2573             *         Kr&uuml;ger</a>
2574             */
2575            public void setAntiAliasing(final boolean aa) {
2576                    // LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa);
2577                    RenderingHints java2DHints = java2dHints;
2578                    if (java2DHints == null) {
2579                            java2DHints = GeoTools.getDefaultHints();
2580                    }
2581                    
2582                    java2DHints.put(RenderingHints.KEY_ANTIALIASING,
2583                                    aa ? RenderingHints.VALUE_ANTIALIAS_ON
2584                                                    : RenderingHints.VALUE_ANTIALIAS_OFF);
2585                    java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
2586                                    aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
2587                                                    : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
2588                    java2DHints.put(RenderingHints.KEY_RENDERING,
2589                                    aa ? RenderingHints.VALUE_RENDER_QUALITY
2590                                                    : RenderingHints.VALUE_RENDER_SPEED);
2591                    
2592            }
2593    
2594  }  }

Legend:
Removed from v.606  
changed lines
  Added in v.607

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26