if (!(obj instanceof MapBean) || !autoZoom || point1 == null
|| point2 == null)
return;
MapBean map = (MapBean) obj;
Projection projection = map.getProjection();
Proj p = (Proj) projection;
synchronized (this) {
point2 = getRatioPoint((MapBean) e.getSource(),
point1,
e.getPoint());
int dx = Math.abs(point2.x - point1.x);
int dy = Math.abs(point2.y - point1.y);
// Dont bother redrawing if the rectangle is too small
if ((dx < 5) || (dy < 5)) {
// clean up the rectangle, since point2 has the
// old value.
paintRectangle(map, point1, point2);
// If rectangle is too small in both x and y then
// recenter the map
if ((dx < 5) && (dy < 5)) {
LatLonPoint llp = projection.inverse(e.getPoint());
boolean shift = e.isShiftDown();
boolean control = e.isControlDown();
if (control) {
if (shift) {
p.setScale(p.getScale() * 2.0f);
} else {
p.setScale(p.getScale() / 2.0f);
}
}
// reset the points here so the point doesn't
// get rendered on the repaint.
point1 = null;
point2 = null;
p.setCenter(llp);
map.setProjection(p);
}
return;
}
// Figure out the new scale
dx = Math.abs(point2.x - point1.x);
dy = Math.abs(point2.y - point1.y);
// cornerPoint 1 should be the upper left.
Point cornerPoint1 = new Point(point2.x < point1.x ? point2.x
: point1.x, point2.y < point1.y ? point2.y : point1.y);
Point cornerPoint2 = new Point(cornerPoint1.x + 2 * dx, cornerPoint1.y
+ 2 * dy);
float newScale = com.bbn.openmap.proj.ProjMath.getScale(cornerPoint1,
cornerPoint2,
projection);
// Figure out the center of the rectangle
com.bbn.openmap.LatLonPoint center = projection.inverse(point1.x,
point1.y);
// Set the parameters of the projection and then set
// the projection of the map. This way we save having
// the MapBean fire two ProjectionEvents.