use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method splitLineKeyPress.
// K key to split a record
protected boolean splitLineKeyPress(final KeyEvent e) {
final int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_K) {
if (!isOverlayAction(ACTION_ADD_GEOMETRY) && hasMouseOverLocation()) {
for (final CloseLocation mouseLocation : getMouseOverLocations()) {
final LayerRecord record = mouseLocation.getRecord();
final AbstractRecordLayer layer = record.getLayer();
layer.splitRecord(record, mouseLocation);
}
e.consume();
return true;
}
}
return false;
}
use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method modeMoveGeometryFinish.
protected boolean modeMoveGeometryFinish(final MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1) {
if (clearOverlayAction(ACTION_MOVE_GEOMETRY)) {
clearOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES);
clearOverlayAction(ACTION_EDIT_GEOMETRY_VERTICES);
final MultipleUndo edit = new MultipleUndo();
for (final CloseLocation location : this.moveGeometryLocations) {
final GeometryFactory geometryFactory = location.getGeometryFactory();
final Point from = this.moveGeometryStart.convertGeometry(geometryFactory);
final Point to = this.moveGeometryEnd.convertGeometry(geometryFactory);
final double deltaX = to.getX() - from.getX();
final double deltaY = to.getY() - from.getY();
if (deltaX != 0 || deltaY != 0) {
final Geometry geometry = location.getGeometry();
if (geometry instanceof GeometryEditor<?>) {
final GeometryEditor<?> geometryEditor = (GeometryEditor<?>) geometry;
edit.addEdit(new MoveGeometryUndoEdit(geometryEditor, deltaX, deltaY));
} else {
final Geometry newGeometry = geometry.edit(editor -> {
editor.move(deltaX, deltaY);
for (final Vertex vertex : editor.vertices()) {
final double z = getElevation(vertex);
if (Double.isFinite(z)) {
vertex.setZ(z);
}
}
return editor;
});
final UndoableEdit geometryEdit = setGeometry(location, newGeometry);
edit.addEdit(geometryEdit);
}
}
}
if (!edit.isEmpty()) {
edit.addEdit(new ClearXorUndoEdit());
addUndo(edit);
}
modeMoveGeometryClear();
repaint();
return true;
}
}
return false;
}
use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method modeAddGeometryDrag.
protected boolean modeAddGeometryDrag(final MouseEvent event) {
if (isOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES)) {
if (this.addGeometryEditVerticesStart) {
Geometry xorGeometry = null;
final List<CloseLocation> mouseOverLocations = getMouseOverLocations();
for (final CloseLocation location : mouseOverLocations) {
final Geometry locationGeometry = getVertexGeometry(event, location);
if (locationGeometry != null) {
if (xorGeometry == null) {
xorGeometry = locationGeometry;
} else {
xorGeometry = xorGeometry.union(locationGeometry);
}
}
}
setXorGeometry(xorGeometry);
if (!hasSnapPoint()) {
setMapCursor(CURSOR_NODE_EDIT);
}
return true;
}
} else if (isOverlayAction(ACTION_ADD_GEOMETRY)) {
modeAddGeometryUpdateXorGeometry();
}
return false;
}
use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class MapPanel method findCloseLocation.
public CloseLocation findCloseLocation(final GeometryFactory viewportGeometryFactory2d, final AbstractRecordLayer layer, final LayerRecord record, final Geometry geometry, final double x, final double y, final double maxDistance) {
final Geometry convertedGeometry = geometry.convertGeometry(viewportGeometryFactory2d);
final Pair<GeometryComponent, Double> closestGeometryComponent = convertedGeometry.findClosestGeometryComponent(x, y, maxDistance);
if (!closestGeometryComponent.isEmpty()) {
final GeometryComponent geometryComponent = closestGeometryComponent.getValue1();
if (geometryComponent instanceof Vertex) {
final Vertex convertedVertex = (Vertex) geometryComponent;
final int[] vertexId = convertedVertex.getVertexId();
// Get the vertex from the original geometry
final Vertex vertex = geometry.getVertex(vertexId);
return new CloseLocation(layer, record, vertex);
} else if (geometryComponent instanceof Segment) {
final Segment convertedSegment = (Segment) geometryComponent;
final int[] segmentId = convertedSegment.getSegmentId();
// Get the segment from the original geometry
final Segment segment = geometry.getSegment(segmentId);
final Point closePoint = convertedSegment.project(x, y);
final Point sourcePoint = geometry.convertGeometry(closePoint);
return new CloseLocation(layer, record, segment, closePoint, sourcePoint);
}
}
return null;
}
use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class SelectRecordsOverlay method paintComponent.
@Override
public void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
final GeoreferencedImage imageSelected = this.imageSelected.getResource();
if (imageSelected != null) {
GeoreferencedImageLayerRenderer.render(viewport, graphics, imageSelected, false);
}
final GeometryFactory viewportGeometryFactory = getViewportGeometryFactory2d();
final MapPanel map = getMap();
final List<LayerRecord> closeSelectedRecords = map.getCloseSelectedRecords();
if (!closeSelectedRecords.isEmpty()) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
for (final LayerRecord record : closeSelectedRecords) {
final Geometry geometry = record.getGeometry();
if (record.isHighlighted()) {
this.highlightVertexRenderer.paintSelected(viewport, graphics, viewportGeometryFactory, geometry);
} else {
this.selectVertexRenderer.paintSelected(viewport, graphics, viewportGeometryFactory, geometry);
}
}
}
}
final List<CloseLocation> closeSelectedLocations = map.getCloseSelectedLocations();
if (Property.hasValue(closeSelectedLocations)) {
for (final CloseLocation location : closeSelectedLocations) {
final Vertex vertex = location.getVertex();
CLOSE_VERTEX_STYLE_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
}
}
paintSelectBox(graphics);
}
Aggregations