use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method paintComponent.
@Override
public void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
final GeometryFactory geometryFactory2dFloating = getViewportGeometryFactory2d();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (isOverlayAction(ACTION_MOVE_GEOMETRY) && this.moveGeometryStart != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
for (final CloseLocation location : this.moveGeometryLocations) {
Geometry geometry = location.getGeometry();
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();
geometry = geometry.edit(editor -> editor.move(deltaX, deltaY));
GEOMETRY_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
GEOMETRY_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
}
}
} else if (this.addGeometryEditor != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final Geometry addGeometry = this.addGeometryEditor.getCurrentGeometry();
GEOMETRY_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, addGeometry);
GEOMETRY_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, addGeometry);
}
}
if (this.moveGeometryStart == null) {
final List<CloseLocation> mouseOverLocations = getMouseOverLocations();
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
for (final CloseLocation location : mouseOverLocations) {
final Geometry geometry = location.getGeometry();
GEOMETRY_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
}
}
for (final CloseLocation location : mouseOverLocations) {
final Geometry geometry = location.getGeometry();
GEOMETRY_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
if (!isOverlayAction(ACTION_MOVE_GEOMETRY) && !this.addGeometryEditVerticesStart && !this.editGeometryVerticesStart) {
final Vertex vertex = location.getVertex();
if (vertex == null) {
final MarkerStyle style = MarkerStyle.marker("xLine", 9, WebColors.Blue, 3, WebColors.Blue);
final double orientation = location.getSegment().getOrientaton();
final Point pointOnLine = location.getViewportPoint();
MarkerStyleRenderer.renderMarker(viewport, graphics, pointOnLine, style, orientation);
} else {
GEOMETRY_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, vertex);
}
}
}
}
drawXorGeometry(graphics);
}
use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method modeEditGeometryVerticesDrag.
protected boolean modeEditGeometryVerticesDrag(final MouseEvent event) {
if (this.editGeometryVerticesStart && isOverlayAction(ACTION_EDIT_GEOMETRY_VERTICES)) {
this.dragged = true;
Geometry xorGeometry = null;
for (final CloseLocation location : getMouseOverLocations()) {
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_ADD);
}
return true;
}
return false;
}
use of com.revolsys.swing.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method modeAddGeometryMove.
protected boolean modeAddGeometryMove(final MouseEvent event) {
if (this.addGeometryEditor != null) {
if (isOverlayAction(ACTION_ADD_GEOMETRY) || isOverlayAction(ACTION_MOVE_GEOMETRY) || isOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES)) {
final MapPanel map = getMap();
final CloseLocation location = map.findCloseLocation(this.addLayer, null, this.addGeometryEditor);
final List<CloseLocation> locations = new ArrayList<>();
if (location != null) {
locations.add(location);
}
final boolean hasMouseOver = setMouseOverLocations(locations);
if (event != null && event.isAltDown()) {
if (hasMouseOver) {
setOverlayAction(ACTION_MOVE_GEOMETRY);
} else {
clearOverlayAction(ACTION_MOVE_GEOMETRY);
if (!hasMouseOverLocation()) {
clearMapCursor();
}
}
} else {
clearOverlayAction(ACTION_MOVE_GEOMETRY);
// TODO make work with multi-part
if (hasMouseOver) {
setOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES);
} else {
clearOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES);
modeAddGeometryUpdateXorGeometry();
}
}
return true;
}
}
return false;
}
use of com.revolsys.swing.map.overlay.CloseLocation 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.map.overlay.CloseLocation in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method getSnapLayers.
@Override
protected List<AbstractRecordLayer> getSnapLayers() {
final Project project = getProject();
final double scale = project.getMapPanel().getScale();
final Set<AbstractRecordLayer> layers = new LinkedHashSet<>();
boolean snapAll = false;
if (isOverlayAction(ACTION_ADD_GEOMETRY)) {
snapAll = addSnapLayers(layers, project, this.addLayer, scale);
} else {
for (final CloseLocation location : getMouseOverLocations()) {
final AbstractRecordLayer layer = location.getLayer();
snapAll |= addSnapLayers(layers, project, layer, scale);
}
}
if (snapAll) {
final List<AbstractRecordLayer> visibleDescendants = project.getVisibleDescendants(AbstractRecordLayer.class, scale);
return visibleDescendants;
}
return new ArrayList<>(layers);
}
Aggregations