/[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 478 by mojays, Tue Oct 20 10:37:01 2009 UTC revision 495 by mojays, Fri Oct 23 14:19:46 2009 UTC
# Line 324  public class JMapPane extends JPanel imp Line 324  public class JMapPane extends JPanel imp
324                                  reset = false; /* forget about the reset */                                  reset = false; /* forget about the reset */
325                                  oldRect = r; /* store what the current size is */                                  oldRect = r; /* store what the current size is */
326    
327                                  mapArea = fixAspectRatio(r, mapArea, false);                                  mapArea = JTSUtil.fixAspectRatio(r, mapArea, false);
328                          }                          }
329                  }                  }
330    
# Line 360  public class JMapPane extends JPanel imp Line 360  public class JMapPane extends JPanel imp
360                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
361          }          }
362    
         /**  
          * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle  
          * @param grow  
          *            If <code>true</code>, than the area will be enlarged to match  
          *            the aspect ratio. If <code>false</code>, it will only shrink.  
          */  
         private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,  
                         boolean grow) {  
                   
                 if (mapArea == null) {  
                         LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified ");  
                 }  
   
                 final double mapWidth = mapArea.getWidth(); /* get the extent of the map */  
                 final double mapHeight = mapArea.getHeight();  
                 final double scaleX = r.getWidth() / mapArea.getWidth(); /*  
                                                                                                                                  * calculate the  
                                                                                                                                  * new scale  
                                                                                                                                  */  
   
                 final double scaleY = r.getHeight() / mapArea.getHeight();  
                 double scale = 1.0; // stupid compiler!  
   
                 if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {  
                         scale = scaleX;  
                 } else {  
                         scale = scaleY;  
                 }  
   
                 /* calculate the difference in width and height of the new extent */  
                 final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);  
                 final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);  
   
                 /*  
                  * System.out.println("delta x " + deltaX);  
                  * System.out.println("delta y " + deltaY);  
                  */  
   
                 /* create the new extent */  
                 final Coordinate ll = new Coordinate(  
                                 mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()  
                                                 - (deltaY / 2.0));  
                 final Coordinate ur = new Coordinate(  
                                 mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()  
                                                 + (deltaY / 2.0));  
   
                 return new Envelope(ll, ur);  
         }  
   
363          public void mouseClicked(final MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
364                  if (mapArea == null)                  if (mapArea == null)
365                          return;                          return;
# Line 917  public class JMapPane extends JPanel imp Line 868  public class JMapPane extends JPanel imp
868                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
869                   * easily fail.                   * easily fail.
870                   */                   */
871                  env = fixAspectRatio(this.getBounds(), env, false);                  env = JTSUtil.fixAspectRatio(this.getBounds(), env, false);
872    
873                  final double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
874                  final double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
# Line 977  public class JMapPane extends JPanel imp Line 928  public class JMapPane extends JPanel imp
928    
929  //                                      LOGGER.debug("and fix aspect ratio");  //                                      LOGGER.debug("and fix aspect ratio");
930    
931                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false);
932                                  }                                  }
933                          }                          }
934    
# Line 999  public class JMapPane extends JPanel imp Line 950  public class JMapPane extends JPanel imp
950    
951  //                                      LOGGER.debug("and fix aspect ratio");  //                                      LOGGER.debug("and fix aspect ratio");
952    
953                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false);
954                                  }                                  }
955                          }                          }
956    
# Line 1023  public class JMapPane extends JPanel imp Line 974  public class JMapPane extends JPanel imp
974    
975  //                                      LOGGER.debug("and fix aspect ratio");  //                                      LOGGER.debug("and fix aspect ratio");
976    
977                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false);
978                                  }                                  }
979                          }                          }
980    
# Line 1047  public class JMapPane extends JPanel imp Line 998  public class JMapPane extends JPanel imp
998    
999  //                                      LOGGER.debug("and fix aspect ratio");  //                                      LOGGER.debug("and fix aspect ratio");
1000    
1001                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false);
1002                                  }                                  }
1003                          }                          }
1004    
# Line 1125  public class JMapPane extends JPanel imp Line 1076  public class JMapPane extends JPanel imp
1076          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1077                  if (maxExtend == null) {                  if (maxExtend == null) {
1078                          try {                          try {
1079                                  return fixAspectRatio(                                  return JTSUtil.fixAspectRatio(
1080                                      this.getBounds(),                                      this.getBounds(),
1081                          // Kartenbereich um 10% vergroessern                          // Kartenbereich um 10% vergroessern
1082                                      JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),                                      JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
# Line 1133  public class JMapPane extends JPanel imp Line 1084  public class JMapPane extends JPanel imp
1084                                  );                                  );
1085                          } catch (IOException e) {                          } catch (IOException e) {
1086                                  LOGGER.warn(                                  LOGGER.warn(
1087                                                                  "maxExtend == null; faild to getLayerBounds of context",                                                                  "maxExtend == null; failed to getLayerBounds of context",
1088                                                                  e);                                                                  e);
1089                          }                          }
1090                  }                  }

Legend:
Removed from v.478  
changed lines
  Added in v.495

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26