use of com.revolsys.swing.undo.MultipleUndo 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)) {
}
}
use of com.revolsys.swing.undo.MultipleUndo 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.undo.MultipleUndo in project com.revolsys.open by revolsys.
the class MergeRecordsDialog method finish.
public void finish() {
final MultipleUndo multipleUndo = new MultipleUndo();
for (final Record mergedRecord : this.mergedRecords.keySet()) {
final CreateRecordUndo createRecordUndo = new CreateRecordUndo(this.layer, mergedRecord);
multipleUndo.addEdit(createRecordUndo);
}
for (final LayerRecord record : this.replacedOriginalRecords) {
final DeleteLayerRecordUndo deleteRecordUndo = new DeleteLayerRecordUndo(record);
multipleUndo.addEdit(deleteRecordUndo);
}
if (this.undoManager == null) {
multipleUndo.redo();
} else {
this.undoManager.addEdit(multipleUndo);
}
setVisible(false);
}
use of com.revolsys.swing.undo.MultipleUndo in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method modeEditGeometryVerticesFinish.
protected boolean modeEditGeometryVerticesFinish(final MouseEvent event) {
if (this.editGeometryVerticesStart && clearOverlayAction(ACTION_EDIT_GEOMETRY_VERTICES)) {
if (this.dragged && event.getButton() == MouseEvent.BUTTON1) {
try {
final MultipleUndo edit = new MultipleUndo();
final List<CloseLocation> locations = getMouseOverLocations();
for (final CloseLocation location : locations) {
final GeometryEditor<?> geometryEditor = geometryEdit(event, location);
if (geometryEditor.isModified()) {
final Geometry newGeometry = geometryEditor.newGeometry();
final UndoableEdit geometryEdit = setGeometry(location, newGeometry);
edit.addEdit(geometryEdit);
}
}
if (!edit.isEmpty()) {
addUndo(edit);
}
} finally {
modeEditGeometryVerticesClear();
}
return true;
}
}
return false;
}
Aggregations