Search in sources :

Example 1 with CloseLocation

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);
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Geometry(com.revolsys.geometry.model.Geometry) LineSegment(com.revolsys.geometry.model.segment.LineSegment) Arrays(java.util.Arrays) Icons(com.revolsys.swing.Icons) ElevationModelLayer(com.revolsys.swing.map.layer.elevation.ElevationModelLayer) Point2D(java.awt.geom.Point2D) FieldDefinition(com.revolsys.record.schema.FieldDefinition) CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) SwingUtil(com.revolsys.swing.SwingUtil) Cursor(java.awt.Cursor) RenderingHints(java.awt.RenderingHints) VertexStyleRenderer(com.revolsys.swing.map.overlay.VertexStyleRenderer) Layer(com.revolsys.swing.map.layer.Layer) SetVertexUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.SetVertexUndoEdit) Viewport2D(com.revolsys.swing.map.Viewport2D) Map(java.util.Map) BaseCloseable(com.revolsys.io.BaseCloseable) InsertVertexUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.InsertVertexUndoEdit) MouseListener(java.awt.event.MouseListener) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) UndoableEdit(javax.swing.undo.UndoableEdit) GeometryDataType(com.revolsys.geometry.model.GeometryDataType) ZoomOverlay(com.revolsys.swing.map.overlay.ZoomOverlay) Collection(java.util.Collection) Project(com.revolsys.swing.map.layer.Project) Set(java.util.Set) Maps(com.revolsys.collection.map.Maps) KeyEvent(java.awt.event.KeyEvent) DeleteVertexUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit) Logs(com.revolsys.logging.Logs) AddGeometryCompleteAction(com.revolsys.swing.map.overlay.AddGeometryCompleteAction) AppendVertexUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.AppendVertexUndoEdit) MultipleUndo(com.revolsys.swing.undo.MultipleUndo) List(java.util.List) MarkerStyle(com.revolsys.swing.map.layer.record.style.MarkerStyle) PropertyChangeListener(java.beans.PropertyChangeListener) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) AbstractUndoableEdit(com.revolsys.swing.undo.AbstractUndoableEdit) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Toolkit(java.awt.Toolkit) Point(com.revolsys.geometry.model.Point) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer) InputEvent(java.awt.event.InputEvent) ActionListener(java.awt.event.ActionListener) LineString(com.revolsys.geometry.model.LineString) RecordDefinition(com.revolsys.record.schema.RecordDefinition) LayerRecordMenu(com.revolsys.swing.map.layer.record.LayerRecordMenu) ArrayList(java.util.ArrayList) WebColors(com.revolsys.awt.WebColors) Graphics2D(java.awt.Graphics2D) Vertex(com.revolsys.geometry.model.vertex.Vertex) PropertyChangeEvent(java.beans.PropertyChangeEvent) LinkedHashSet(java.util.LinkedHashSet) MapPanel(com.revolsys.swing.map.MapPanel) MoveGeometryUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.MoveGeometryUndoEdit) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) DataTypes(com.revolsys.datatype.DataTypes) MouseEvent(java.awt.event.MouseEvent) MarkerStyleRenderer(com.revolsys.swing.map.layer.record.renderer.MarkerStyleRenderer) TreeMap(java.util.TreeMap) MouseMotionListener(java.awt.event.MouseMotionListener) AbstractOverlay(com.revolsys.swing.map.overlay.AbstractOverlay) LayerGroup(com.revolsys.swing.map.layer.LayerGroup) DataType(com.revolsys.datatype.DataType) Geometry(com.revolsys.geometry.model.Geometry) Collections(java.util.Collections) BoundingBox(com.revolsys.geometry.model.BoundingBox) Vertex(com.revolsys.geometry.model.vertex.Vertex) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point) MarkerStyle(com.revolsys.swing.map.layer.record.style.MarkerStyle)

Example 2 with CloseLocation

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;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CloseLocation(com.revolsys.swing.map.overlay.CloseLocation)

Example 3 with CloseLocation

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;
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) MapPanel(com.revolsys.swing.map.MapPanel) ArrayList(java.util.ArrayList)

Example 4 with CloseLocation

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)) {
    }
}
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)

Example 5 with CloseLocation

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Project(com.revolsys.swing.map.layer.Project) ArrayList(java.util.ArrayList) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Aggregations

CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)15 Geometry (com.revolsys.geometry.model.Geometry)9 Point (com.revolsys.geometry.model.Point)6 MapPanel (com.revolsys.swing.map.MapPanel)5 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)5 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)5 ArrayList (java.util.ArrayList)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)4 AbstractUndoableEdit (com.revolsys.swing.undo.AbstractUndoableEdit)4 MultipleUndo (com.revolsys.swing.undo.MultipleUndo)4 UndoableEdit (javax.swing.undo.UndoableEdit)4 GeometryEditor (com.revolsys.geometry.model.editor.GeometryEditor)3 LinkedHashSet (java.util.LinkedHashSet)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 LineString (com.revolsys.geometry.model.LineString)2 BaseCloseable (com.revolsys.io.BaseCloseable)2 Project (com.revolsys.swing.map.layer.Project)2 LayerRecordMenu (com.revolsys.swing.map.layer.record.LayerRecordMenu)2 DeleteVertexUndoEdit (com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit)2