Search in sources :

Example 6 with Viewport2D

use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method setLayer.

public void setLayer(final GeoreferencedImageLayer layer) {
    final GeoreferencedImageLayer oldLayer = this.layer;
    if (oldLayer != layer) {
        clear();
        this.layer = layer;
        final Viewport2D viewport = getViewport();
        setGeometryFactory(viewport.getGeometryFactory());
        setEnabled(layer != null);
        if (layer != null) {
            this.image = layer.getImage();
            setImageBoundingBox(layer.getBoundingBox());
        }
        if (oldLayer != null) {
            oldLayer.setEditable(false);
        }
    }
    firePropertyChange("layer", oldLayer, layer);
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)

Example 7 with Viewport2D

use of com.revolsys.swing.map.Viewport2D 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 8 with Viewport2D

use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.

the class SelectRecordsOverlay method selectBoxFinish.

private boolean selectBoxFinish(final MouseEvent event) {
    if (event.getButton() == this.selectBoxButton && this.selectBoxX1 != -1) {
        if (clearOverlayAction(ACTION_SELECT_RECORDS)) {
            final MapPanel map = getMap();
            final GeometryFactory geometryFactory = map.getGeometryFactory();
            BoundingBox boundingBox = geometryFactory.newBoundingBox(this.selectBoxX1, this.selectBoxY1, this.selectBoxX2, this.selectBoxY2);
            final Viewport2D viewport = getViewport();
            final double minSize = viewport.getModelUnitsPerViewUnit() * 10;
            final double width = boundingBox.getWidth();
            double deltaX = 0;
            if (width < minSize) {
                deltaX = (minSize - width) / 2;
            }
            final double height = boundingBox.getWidth();
            double deltaY = 0;
            if (height < minSize) {
                deltaY = (minSize - height) / 2;
            }
            boundingBox = boundingBox.expand(deltaX, deltaY);
            if (!boundingBox.isEmpty()) {
                doSelectRecords(event, boundingBox);
            }
            selectBoxClear();
            if (isMouseInMap()) {
                setSelectCursor(event);
            }
            event.consume();
            repaint();
            return true;
        }
    }
    return false;
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) Viewport2D(com.revolsys.swing.map.Viewport2D) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 9 with Viewport2D

use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.

the class Print method actionPerformed.

@Override
public void actionPerformed(final ActionEvent event) {
    final Project project = Project.get();
    final Viewport2D viewport = project.getViewport();
    final PrinterJob job = PrinterJob.getPrinterJob();
    final PageFormat format = job.defaultPage();
    format.setOrientation(PageFormat.PORTRAIT);
    final Paper paper = format.getPaper();
    paper.setImageableArea(29, 29, format.getWidth() - 58, format.getHeight() - 58);
    format.setPaper(paper);
    if (this.printService != null) {
        try {
            job.setPrintService(this.printService);
        } catch (final PrinterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    final BoundingBox boundingBox = viewport.getBoundingBox();
    final MapPageable pageable = new MapPageable(project, boundingBox, format, 20000, 300, 200);
    job.setPageable(pageable);
    final boolean doPrint = job.printDialog();
    if (doPrint) {
        this.printService = job.getPrintService();
        Invoke.background("Print", () -> {
            try {
                job.print();
            } catch (final Exception e) {
                Logs.error(this, "Unable to print", e);
            }
        });
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) PageFormat(java.awt.print.PageFormat) BoundingBox(com.revolsys.geometry.model.BoundingBox) Paper(java.awt.print.Paper) PrinterException(java.awt.print.PrinterException) PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 10 with Viewport2D

use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.

the class SinglePage method print.

public static void print() {
    final Project project = Project.get();
    final Viewport2D viewport = project.getViewport();
    final int viewWidth = viewport.getViewWidthPixels();
    final int viewHeight = viewport.getViewHeightPixels();
    final BoundingBox boundingBox = viewport.getBoundingBox();
    final double scaleForVisible = viewport.getScaleForVisible();
    final PrinterJob job = PrinterJob.getPrinterJob();
    job.setJobName(project.getName());
    final PageFormat format = job.defaultPage();
    final PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    if (boundingBox.getAspectRatio() > 1) {
        format.setOrientation(PageFormat.LANDSCAPE);
    // printAttributes.add(OrientationRequested.LANDSCAPE);
    } else {
        format.setOrientation(PageFormat.PORTRAIT);
    // printAttributes.add(OrientationRequested.PORTRAIT);
    }
    final SinglePage pageable = new SinglePage(project, boundingBox, viewWidth, viewHeight, scaleForVisible);
    job.setPageable(pageable);
    final boolean doPrint = job.printDialog();
    if (doPrint) {
        Invoke.background("Print", () -> {
            try {
                job.print();
            } catch (final PrinterAbortException e) {
            } catch (final Exception e) {
                Logs.error(SinglePage.class, "Unable to print", e);
            }
        });
    }
}
Also used : PrinterAbortException(java.awt.print.PrinterAbortException) PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) GraphicsViewport2D(com.revolsys.swing.map.GraphicsViewport2D) PageFormat(java.awt.print.PageFormat) PrinterAbortException(java.awt.print.PrinterAbortException) BoundingBox(com.revolsys.geometry.model.BoundingBox) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

Viewport2D (com.revolsys.swing.map.Viewport2D)17 Point (com.revolsys.geometry.model.Point)10 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 MapPanel (com.revolsys.swing.map.MapPanel)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 Project (com.revolsys.swing.map.layer.Project)5 ComponentViewport2D (com.revolsys.swing.map.ComponentViewport2D)3 Graphics2D (java.awt.Graphics2D)3 LineSegment (com.revolsys.geometry.model.segment.LineSegment)2 BaseCloseable (com.revolsys.io.BaseCloseable)2 ImageViewport (com.revolsys.swing.map.ImageViewport)2 BufferedImage (java.awt.image.BufferedImage)2 PageFormat (java.awt.print.PageFormat)2 PrinterException (java.awt.print.PrinterException)2 PrinterJob (java.awt.print.PrinterJob)2 WebColors (com.revolsys.awt.WebColors)1 Maps (com.revolsys.collection.map.Maps)1 DataType (com.revolsys.datatype.DataType)1 DataTypes (com.revolsys.datatype.DataTypes)1 Geometry (com.revolsys.geometry.model.Geometry)1