use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class ZoomOverlay method panFinish.
public boolean panFinish(final MouseEvent event) {
if (event.getButton() == this.panButton) {
if (clearOverlayAction(ACTION_PAN) && this.panX1 != -1) {
this.panImage = null;
if (this.panX1 != this.panX2 || this.panY1 != this.panY2) {
final java.awt.Point point = event.getPoint();
final Viewport2D viewport = getViewport();
final Point fromPoint = viewport.toModelPoint(this.panX1, this.panY1);
final Point toPoint = viewport.toModelPoint(point);
final double deltaX = fromPoint.getX() - toPoint.getX();
final double deltaY = fromPoint.getY() - toPoint.getY();
final BoundingBox boundingBox = viewport.getBoundingBox();
final BoundingBox newBoundingBox = boundingBox.move(deltaX, deltaY);
final MapPanel map = getMap();
map.setBoundingBox(newBoundingBox);
}
panClear();
repaint();
return true;
}
}
return false;
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class ZoomOverlay method zoomBoxFinish.
protected boolean zoomBoxFinish(final MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1 && clearOverlayAction(ACTION_ZOOM_BOX)) {
final Viewport2D viewport = getViewport();
// Convert first point to envelope top left in map coords.
final int minX = Math.min(this.zoomBoxX1, this.zoomBoxX2);
final int minY = Math.min(this.zoomBoxY1, this.zoomBoxY2);
final Point topLeft = viewport.toModelPoint(minX, minY);
// Convert second point to envelope bottom right in map coords.
final int maxX = Math.max(this.zoomBoxX1, this.zoomBoxX2);
final int maxY = Math.max(this.zoomBoxY1, this.zoomBoxY2);
final Point bottomRight = viewport.toModelPoint(maxX, maxY);
final MapPanel map = getMap();
final GeometryFactory geometryFactory = map.getGeometryFactory();
final BoundingBox boundingBox = geometryFactory.newBoundingBox(topLeft.getX(), topLeft.getY(), bottomRight.getX(), bottomRight.getY());
if (boundingBox.isEmpty()) {
Toolkit.getDefaultToolkit().beep();
} else {
map.setBoundingBox(boundingBox);
}
zoomBoxClear();
if (SwingUtil.isShiftDown(event) && isMouseInMap()) {
setOverlayAction(ACTION_ZOOM_BOX);
}
return true;
}
return false;
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class ZoomOverlay method mouseWheelMoved.
@Override
public void mouseWheelMoved(final MouseWheelEvent event) {
if (canOverrideOverlayAction(ACTION_ZOOM)) {
if (Math.abs(event.getWheelRotation()) == 1 && event.getModifiersEx() == 0) {
int numSteps = 1;
if (event.getUnitsToScroll() < 0) {
numSteps = -1;
}
if (SwingUtil.isScrollReversed()) {
numSteps = -numSteps;
}
if (!isWheelForwardsZoomIn()) {
numSteps = -numSteps;
}
final int x = event.getX();
final int y = event.getY();
final Viewport2D viewport = getViewport();
final Point mapPoint = viewport.toModelPoint(x, y);
final MapPanel map = getMap();
map.zoom(mapPoint, numSteps);
event.consume();
}
}
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class AbstractOverlay method newXorLine.
protected LineString newXorLine(final GeometryFactory geometryFactory, final Point c0, final Point p1) {
final Viewport2D viewport = getViewport();
final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory2dFloating();
final LineSegment line = viewportGeometryFactory.lineSegment(c0, p1);
final double length = line.getLength();
if (length > 0) {
final double cursorRadius = viewport.getModelUnitsPerViewUnit() * 6;
final Point newC1 = line.pointAlongOffset((length - cursorRadius) / length, 0);
return geometryFactory.lineString(c0, newC1);
} else {
return null;
}
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class AbstractOverlay method getPoint.
protected Point getPoint(final GeometryFactory geometryFactory, final MouseEvent event) {
final Viewport2D viewport = getViewport();
final Point point = viewport.toModelPointRounded(geometryFactory, event.getX(), event.getY());
return point;
}
Aggregations