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);
// Don't 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
float newScale = com.bbn.openmap.proj.ProjMath.getScale(point1,
point2,
projection);
// Figure out the center of the rectangle
int centerx = Math.min(point1.x, point2.x) + dx / 2;
int centery = Math.min(point1.y, point2.y) + dy / 2;
com.bbn.openmap.LatLonPoint center = projection.inverse(centerx,
centery);
// Fire events on main map to change view to match rect1
// Debug.output("point1: " +point1);
// Debug.output("point2: " +point2);