Search in sources :

Example 11 with Viewport2D

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

the class SaveAsPdf method save.

public static void save() {
    final Project project = Project.get();
    final String directory = "/Users/paustin/Downloads/";
    final File file = new File(directory, project.getName() + ".pdf");
    try {
        final PDDocument document = new PDDocument();
        final Viewport2D viewport = project.getViewport();
        BoundingBox boundingBox = viewport.getBoundingBox();
        final int width = viewport.getViewWidthPixels();
        final int height = viewport.getViewHeightPixels();
        final int srid = boundingBox.getCoordinateSystemId();
        if (srid == 3857) {
            boundingBox = boundingBox.convert(boundingBox.getGeometryFactory().getGeographicGeometryFactory());
        }
        final PDRectangle pageSize = new PDRectangle(width, height);
        final PDPage page = new PDPage(pageSize);
        try (PdfViewport pdfViewport = new PdfViewport(document, page, project, width, height, boundingBox)) {
            final LayerRenderer<? extends Layer> renderer = project.getRenderer();
            renderer.render(pdfViewport);
        }
        document.addPage(page);
        final PDDocumentCatalog catalog = document.getDocumentCatalog();
        final PDMetadata metadata = new PDMetadata(document);
        catalog.setMetadata(metadata);
        // jempbox version
        final XMPMetadata xmp = new XMPMetadata();
        final XMPSchemaDublinCore xmpSchema = new XMPSchemaDublinCore(xmp);
        xmp.addSchema(xmpSchema);
        xmpSchema.setAbout("");
        metadata.importXMPMetadata(xmp);
        document.save(file);
    } catch (final Throwable e) {
        Logs.error(SaveAsPdf.class, "Unable to create PDF " + file, e);
    }
}
Also used : XMPSchemaDublinCore(org.apache.jempbox.xmp.XMPSchemaDublinCore) PDPage(org.apache.pdfbox.pdmodel.PDPage) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog) Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) XMPMetadata(org.apache.jempbox.xmp.XMPMetadata) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) BoundingBox(com.revolsys.geometry.model.BoundingBox) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) File(java.io.File)

Example 12 with Viewport2D

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

the class ZoomOverlay method panStart.

public boolean panStart(final MouseEvent event, final boolean drag) {
    if (this.panX1 == -1) {
        boolean pan = false;
        final int button = event.getButton();
        if (button == MouseEvent.BUTTON2) {
            pan = true;
            this.panButton = MouseEvent.BUTTON2;
        } else if (!drag && button == MouseEvent.BUTTON1 && !hasOverlayAction()) {
            if (event.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
                pan = true;
                this.panButton = MouseEvent.BUTTON1;
            }
        }
        if (pan) {
            if (setOverlayAction(ACTION_PAN)) {
                final Viewport2D viewport = getViewport();
                final int width = viewport.getViewWidthPixels();
                final int height = viewport.getViewHeightPixels();
                if (width > 0 && height > 0) {
                    final JComponent parent = (JComponent) getParent();
                    this.panImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                    final Graphics2D graphics = (Graphics2D) this.panImage.getGraphics();
                    try {
                        final Insets insets = parent.getInsets();
                        graphics.translate(-insets.left, -insets.top);
                        graphics.setColor(Color.WHITE);
                        graphics.fillRect(insets.left, insets.top, width, height);
                        parent.paintComponents(graphics);
                    } finally {
                        graphics.dispose();
                    }
                    this.panX1 = this.panX2 = event.getX();
                    this.panY1 = this.panY2 = event.getY();
                    final MapPanel map = getMap();
                    map.setVisibleOverlay(this);
                }
                return true;
            }
        }
        return false;
    } else {
        return true;
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) Insets(java.awt.Insets) JComponent(javax.swing.JComponent) Point(com.revolsys.geometry.model.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 13 with Viewport2D

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

the class ZoomOverlay method mouseClicked.

@Override
public void mouseClicked(final MouseEvent event) {
    if (canOverrideOverlayAction(ACTION_ZOOM)) {
        final int button = event.getButton();
        // Double click
        if (event.getClickCount() == 2) {
            final int x = event.getX();
            final int y = event.getY();
            int numSteps = 0;
            if (button == MouseEvent.BUTTON1 && !hasOverlayAction() || button == MouseEvent.BUTTON2) {
                // Left or middle button, zoom in
                numSteps = -1;
            } else if (button == MouseEvent.BUTTON3) {
                // Right mouse button, zoom out
                numSteps = 1;
            }
            if (numSteps != 0) {
                final Viewport2D viewport = getViewport();
                final Point mapPoint = viewport.toModelPoint(x, y);
                final MapPanel map = getMap();
                map.zoom(mapPoint, numSteps);
                event.consume();
            }
        }
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 14 with Viewport2D

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

the class SelectRecordsOverlay method refreshImageSelected.

private GeoreferencedImage refreshImageSelected() {
    final Viewport2D viewport = getViewport();
    if (viewport != null) {
        final int width = viewport.getViewWidthPixels();
        final int height = viewport.getViewHeightPixels();
        if (width > 0 && height > 0) {
            try (final ImageViewport imageViewport = new ImageViewport(viewport, BufferedImage.TYPE_INT_ARGB_PRE);
                BaseCloseable transformCloseable = imageViewport.setUseModelCoordinates(true)) {
                final Graphics2D graphics = imageViewport.getGraphics();
                final Project project = getProject();
                refreshImageRenderer(imageViewport, project);
                refreshImageSelectedAndHighlighted(imageViewport, graphics, project);
                return imageViewport.getGeoreferencedImage();
            }
        }
    }
    return null;
}
Also used : Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) BaseCloseable(com.revolsys.io.BaseCloseable) ImageViewport(com.revolsys.swing.map.ImageViewport) Point(com.revolsys.geometry.model.Point) Graphics2D(java.awt.Graphics2D)

Example 15 with Viewport2D

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

the class SelectRecordsOverlay method paintSelectBox.

protected void paintSelectBox(final Graphics2D graphics2d) {
    if (this.selectBoxX1 != -1) {
        final Viewport2D viewport = getViewport();
        final Point2D from = viewport.toViewPoint(this.selectBoxX1, this.selectBoxY1);
        final Point2D to = viewport.toViewPoint(this.selectBoxX2, this.selectBoxY2);
        final double x1 = from.getX();
        final double x2 = to.getX();
        final int x = (int) Math.min(x1, x2);
        final int width = (int) Math.abs(x1 - x2);
        final double y1 = from.getY();
        final double y2 = to.getY();
        final int y = (int) Math.min(y1, y2);
        final int height = (int) Math.abs(y1 - y2);
        graphics2d.setColor(COLOR_BOX);
        graphics2d.setStroke(BOX_STROKE);
        graphics2d.drawRect(x, y, width, height);
        graphics2d.setPaint(COLOR_BOX_TRANSPARENT);
        graphics2d.fillRect(x, y, width, height);
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) Point2D(java.awt.geom.Point2D) Point(com.revolsys.geometry.model.Point)

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