/[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 493 by mojays, Fri Oct 23 14:09:27 2009 UTC revision 494 by mojays, Fri Oct 23 14:16:17 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 also NULL");  
                         return null;  
                 }  
                 if ( r == null || r.width == 0 || r.height == 0 ) {  
           LOGGER.warn("Empty rectangle in method fixAspectRatio, returning an unmodified mapArea!");  
           return mapArea;  
                 }  
   
                 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 922  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 982  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 1004  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 1028  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 1052  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    

Legend:
Removed from v.493  
changed lines
  Added in v.494

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26