Search in sources :

Example 1 with DeleteVertexUndoEdit

use of com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method keyReleased.

@Override
public void keyReleased(final KeyEvent e) {
    final int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_ALT) {
        if (!this.dragged) {
            if (isOverlayAction(ACTION_MOVE_GEOMETRY)) {
                if (clearOverlayAction(ACTION_MOVE_GEOMETRY)) {
                    if (this.addLayer != null) {
                        modeAddGeometryMove(null);
                    } else {
                        updateMouseOverLocations();
                    }
                }
            } else {
                if (this.addLayer == null) {
                    updateMouseOverLocations();
                } else {
                    modeAddGeometryMove(null);
                }
            }
        }
    } else if (keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE) {
        if (hasMouseOverLocation()) {
            final MultipleUndo edit = new MultipleUndo();
            for (final CloseLocation location : getMouseOverLocations()) {
                final Geometry geometry = location.getGeometry();
                final int[] vertexId = location.getVertexId();
                if (vertexId != null) {
                    try {
                        if (this.addGeometryEditor == null) {
                            final GeometryEditor<?> geometryEditor = geometry.newGeometryEditor();
                            geometryEditor.deleteVertex(vertexId);
                            if (geometryEditor.isModified()) {
                                final Geometry newGeometry = geometryEditor.newGeometry();
                                if (newGeometry.isEmpty()) {
                                    Toolkit.getDefaultToolkit().beep();
                                } else {
                                    final UndoableEdit geometryEdit = setGeometry(location, newGeometry);
                                    edit.addEdit(geometryEdit);
                                }
                            }
                        } else {
                            edit.addEdit(new DeleteVertexUndoEdit(this.addGeometryEditor, vertexId));
                        }
                    } catch (final Exception t) {
                        Toolkit.getDefaultToolkit().beep();
                    }
                }
            }
            if (!edit.isEmpty()) {
                edit.addEdit(new ClearXorUndoEdit());
                addUndo(edit);
            }
            clearMouseOverLocations();
        }
    } else if (keyCode == KeyEvent.VK_F2 || keyCode == KeyEvent.VK_F) {
        clearMouseOverLocations();
        modeMoveGeometryClear();
        if (this.addCompleteAction != null) {
            final Geometry addGeometry = this.addGeometryEditor.newGeometry();
            this.addCompleteAction.addComplete(this, addGeometry);
        }
        modeAddGeometryClear();
    } else if (splitLineKeyPress(e)) {
    }
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Geometry(com.revolsys.geometry.model.Geometry) DeleteVertexUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit) 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 Point (com.revolsys.geometry.model.Point)1 GeometryEditor (com.revolsys.geometry.model.editor.GeometryEditor)1 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)1 DeleteVertexUndoEdit (com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit)1 AbstractUndoableEdit (com.revolsys.swing.undo.AbstractUndoableEdit)1 MultipleUndo (com.revolsys.swing.undo.MultipleUndo)1 UndoableEdit (javax.swing.undo.UndoableEdit)1