Search in sources :

Example 1 with MoveGeometryUndoEdit

use of com.revolsys.swing.map.overlay.record.geometryeditor.MoveGeometryUndoEdit 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;
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Geometry(com.revolsys.geometry.model.Geometry) MoveGeometryUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.MoveGeometryUndoEdit) Vertex(com.revolsys.geometry.model.vertex.Vertex) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(com.revolsys.swing.undo.AbstractUndoableEdit) Point(com.revolsys.geometry.model.Point) MultipleUndo(com.revolsys.swing.undo.MultipleUndo) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 GeometryEditor (com.revolsys.geometry.model.editor.GeometryEditor)1 Vertex (com.revolsys.geometry.model.vertex.Vertex)1 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)1 MoveGeometryUndoEdit (com.revolsys.swing.map.overlay.record.geometryeditor.MoveGeometryUndoEdit)1 AbstractUndoableEdit (com.revolsys.swing.undo.AbstractUndoableEdit)1 MultipleUndo (com.revolsys.swing.undo.MultipleUndo)1 UndoableEdit (javax.swing.undo.UndoableEdit)1