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 |
|
|
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; |
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.; |
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|