Search in sources :

Example 11 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method paintComponent.

@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
    super.paintComponent(viewport, graphics);
    final GeoreferencedImageLayer layer = this.layer;
    final GeoreferencedImage image = this.image;
    final BoundingBox moveImageBoundingBox = this.moveImageBoundingBox;
    if (layer != null && layer.isVisible() && layer.isExists() && image != null) {
        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
            final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory();
            final boolean showOriginalImage = layer.isShowOriginalImage();
            final BoundingBox imageBoundingBox = getImageBoundingBox();
            BoundingBox boundingBox = imageBoundingBox;
            BoundingBox outlineBoundingBox = boundingBox;
            if (moveImageBoundingBox != null) {
                if (showOriginalImage) {
                    boundingBox = moveImageBoundingBox;
                }
                outlineBoundingBox = moveImageBoundingBox;
            }
            final GeoreferencedImage cachedImage = getCachedImage(boundingBox);
            GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, cachedImage, false, layer.getOpacity() / 255.0, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, imageBoundingBox);
            if (outlineBoundingBox != null && !outlineBoundingBox.isEmpty()) {
                final Polygon imageBoundary = outlineBoundingBox.convert(getViewportGeometryFactory()).toPolygon(1);
                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
                viewport.drawGeometryOutline(imageBoundary, STYLE_BOX_OUTLINE);
                MarkerStyleRenderer.renderMarkerVertices(viewport, graphics, imageBoundary, STYLE_BOX_CORNER);
                final List<MappedLocation> tiePoints = image.getTiePoints();
                final int tiePointCount = tiePoints.size();
                final GeometryFactory viewGeometryFactory = getGeometryFactory();
                if (tiePointCount > 0) {
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            try (BaseCloseable transformCloseable1 = viewport.setUseModelCoordinates(graphics, true)) {
                                TIE_POINT_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                            }
                        }
                    }
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            TIE_POINT_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                        }
                    }
                }
                if (!showOriginalImage) {
                    final double width = image.getImageWidth() - 1;
                    final double height = image.getImageHeight() - 1;
                    final double[] targetCoordinates = MappedLocation.toModelCoordinates(image, boundingBox, true, 0, height, width, height, width, 0, 0, 0, 0, height);
                    final LineString line = viewGeometryFactory.lineString(2, targetCoordinates);
                    GeometryStyleRenderer.renderLineString(viewport, graphics, line, STYLE_IMAGE_LINE);
                }
            }
            final MappedLocation moveTiePoint = getMoveTiePoint();
            if (moveTiePoint != null) {
                final LineString line = moveTiePoint.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                Vertex vertex;
                if (this.moveTiePointSource) {
                    vertex = line.getVertex(0);
                } else {
                    vertex = line.getToVertex(0);
                }
                TIE_POINT_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
            }
        }
    }
    drawXorGeometry(graphics);
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BufferedGeoreferencedImage(com.revolsys.raster.BufferedGeoreferencedImage) GeoreferencedImage(com.revolsys.raster.GeoreferencedImage) MappedLocation(com.revolsys.raster.MappedLocation) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon)

Example 12 with BaseCloseable

use of com.revolsys.io.BaseCloseable 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 13 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class MapPanel method setBoundingBox.

public synchronized void setBoundingBox(final BoundingBox boundingBox) {
    Invoke.later(() -> {
        if (this.settingBoundingBox.isFalse()) {
            try (BaseCloseable settingBoundingBox = this.settingBoundingBox.closeable(true)) {
                final BoundingBox oldBoundingBox = getBoundingBox();
                final double oldUnitsPerPixel = getUnitsPerPixel();
                final boolean zoomPreviousEnabled = isZoomPreviousEnabled();
                final boolean zoomNextEnabled = isZoomNextEnabled();
                final BoundingBox resizedBoundingBox = this.viewport.setBoundingBox(boundingBox);
                if (this.project != null) {
                    this.project.setViewBoundingBox(resizedBoundingBox);
                    // setScale(this.viewport.getScale());
                    synchronized (this.zoomHistory) {
                        if (this.updateZoomHistory.isTrue() && !this.viewport.isComponentResizing()) {
                            BoundingBox currentBoundingBox = null;
                            if (this.zoomHistoryIndex > -1) {
                                currentBoundingBox = this.zoomHistory.get(this.zoomHistoryIndex);
                                if (!currentBoundingBox.equals(resizedBoundingBox)) {
                                    while (this.zoomHistory.size() > this.zoomHistoryIndex + 1) {
                                        this.zoomHistory.removeLast();
                                    }
                                    for (int i = this.zoomHistory.size() - 1; i > this.zoomHistoryIndex; i++) {
                                        this.zoomHistory.remove(i);
                                    }
                                    this.zoomHistory.add(resizedBoundingBox);
                                    this.zoomHistoryIndex = this.zoomHistory.size() - 1;
                                    if (this.zoomHistory.size() > 50) {
                                        this.zoomHistory.removeFirst();
                                        this.zoomHistoryIndex--;
                                    }
                                }
                            } else {
                                this.zoomHistory.add(resizedBoundingBox);
                                this.zoomHistoryIndex = 0;
                            }
                        }
                    }
                    firePropertyChange("unitsPerPixel", oldUnitsPerPixel, getUnitsPerPixel());
                    firePropertyChange("boundingBox", oldBoundingBox, resizedBoundingBox);
                    firePropertyChange("zoomPreviousEnabled", zoomPreviousEnabled, isZoomPreviousEnabled());
                    firePropertyChange("zoomNextEnabled", zoomNextEnabled, isZoomNextEnabled());
                    repaint();
                }
            }
        }
    });
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 14 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class MarkerStyleRenderer method renderMarker.

public static void renderMarker(final Viewport2D viewport, final Geometry geometry, final MarkerStyle style) {
    try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
        @SuppressWarnings("deprecation") final Graphics2D graphics = viewport.getGraphics();
        if (graphics != null && geometry != null) {
            if ("vertices".equals(style.getMarkerPlacementType())) {
                renderMarkerVertices(viewport, graphics, geometry, style);
            } else if ("segments".equals(style.getMarkerPlacementType())) {
                renderMarkerSegments(viewport, graphics, geometry, style);
            } else {
                for (int i = 0; i < geometry.getGeometryCount(); i++) {
                    final Geometry part = geometry.getGeometry(i);
                    if (part instanceof Point) {
                        final Point point = (Point) part;
                        renderMarker(viewport, graphics, point, style, 0);
                    } else if (part instanceof LineString) {
                        final LineString line = (LineString) part;
                        renderMarker(viewport, graphics, line, style);
                    } else if (part instanceof Polygon) {
                        final Polygon polygon = (Polygon) part;
                        renderMarker(viewport, graphics, polygon, style);
                    }
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BaseCloseable(com.revolsys.io.BaseCloseable) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) Graphics2D(java.awt.Graphics2D)

Example 15 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class TextMarker method render.

@Override
public void render(final Viewport2D viewport, final Graphics2D graphics, final MarkerStyle style, final double modelX, final double modelY, double orientation) {
    try (BaseCloseable transformCloseable = new CloseableAffineTransform(graphics)) {
        Viewport2D.setUseModelCoordinates(viewport, graphics, false);
        final Quantity<Length> markerHeight = style.getMarkerHeight();
        final double mapHeight = Viewport2D.toDisplayValue(viewport, markerHeight);
        final String orientationType = style.getMarkerOrientationType();
        if ("none".equals(orientationType)) {
            orientation = 0;
        }
        final int fontSize = (int) mapHeight;
        if (this.font == null || this.font.getSize() != fontSize) {
            this.font = Fonts.newFont(this.textFaceName, 0, fontSize);
        }
        final FontRenderContext fontRenderContext = graphics.getFontRenderContext();
        final GlyphVector glyphVector = this.font.createGlyphVector(fontRenderContext, this.text);
        final Shape shape = glyphVector.getOutline();
        final GeneralPath newShape = new GeneralPath(shape);
        final Rectangle2D bounds = newShape.getBounds2D();
        final double shapeWidth = bounds.getWidth();
        final double shapeHeight = bounds.getHeight();
        Viewport2D.translateModelToViewCoordinates(viewport, graphics, modelX, modelY);
        final double markerOrientation = style.getMarkerOrientation();
        orientation = -orientation + markerOrientation;
        if (orientation != 0) {
            graphics.rotate(Math.toRadians(orientation));
        }
        final Quantity<Length> deltaX = style.getMarkerDx();
        final Quantity<Length> deltaY = style.getMarkerDy();
        double dx = Viewport2D.toDisplayValue(viewport, deltaX);
        double dy = Viewport2D.toDisplayValue(viewport, deltaY);
        dy -= bounds.getY();
        final String verticalAlignment = style.getMarkerVerticalAlignment();
        if ("bottom".equals(verticalAlignment)) {
            dy -= shapeHeight;
        } else if ("auto".equals(verticalAlignment) || "middle".equals(verticalAlignment)) {
            dy -= shapeHeight / 2.0;
        }
        final String horizontalAlignment = style.getMarkerHorizontalAlignment();
        if ("right".equals(horizontalAlignment)) {
            dx -= shapeWidth;
        } else if ("auto".equals(horizontalAlignment) || "center".equals(horizontalAlignment)) {
            dx -= shapeWidth / 2;
        }
        graphics.translate(dx, dy);
        if (style.setMarkerFillStyle(viewport, graphics)) {
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
            graphics.setFont(this.font);
            graphics.drawString(this.text, 0, 0);
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) GlyphVector(java.awt.font.GlyphVector) Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) Length(javax.measure.quantity.Length) CloseableAffineTransform(com.revolsys.awt.CloseableAffineTransform) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext)

Aggregations

BaseCloseable (com.revolsys.io.BaseCloseable)46 Point (com.revolsys.geometry.model.Point)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Geometry (com.revolsys.geometry.model.Geometry)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Polygon (com.revolsys.geometry.model.Polygon)6 Record (com.revolsys.record.Record)5 LineString (com.revolsys.geometry.model.LineString)4 Identifier (com.revolsys.identifier.Identifier)4 RecordReader (com.revolsys.record.io.RecordReader)4 Graphics2D (java.awt.Graphics2D)4 ArrayList (java.util.ArrayList)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ArrayRecord (com.revolsys.record.ArrayRecord)2 RecordStore (com.revolsys.record.schema.RecordStore)2 Resource (com.revolsys.spring.resource.Resource)2 MapPanel (com.revolsys.swing.map.MapPanel)2