Search in sources :

Example 1 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class GriddedElevationModelLayer method zoomToLayer.

@Override
public void zoomToLayer() {
    final Project project = getProject();
    final GeometryFactory geometryFactory = project.getGeometryFactory();
    final BoundingBox layerBoundingBox = getBoundingBox();
    final BoundingBox boundingBox = // 
    layerBoundingBox.convert(geometryFactory).expandPercent(// 
    0.1).clipToCoordinateSystem();
    project.setViewBoundingBox(boundingBox);
}
Also used : Project(com.revolsys.swing.map.layer.Project) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 2 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class FileDropTargetListener method drop.

@Override
@SuppressWarnings("unchecked")
public void drop(final DropTargetDropEvent event) {
    try {
        final Transferable tr = event.getTransferable();
        final List<File> files = new ArrayList<>();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            event.acceptDrop(DnDConstants.ACTION_COPY);
            files.addAll((List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor));
        } else {
            final DataFlavor[] flavors = tr.getTransferDataFlavors();
            boolean handled = false;
            for (final DataFlavor flavor : flavors) {
                if (flavor.isRepresentationClassReader()) {
                    event.acceptDrop(DnDConstants.ACTION_COPY);
                    final BufferedReader reader = new BufferedReader(flavor.getReaderForText(tr));
                    handled = true;
                    String fileName = null;
                    while ((fileName = reader.readLine()) != null) {
                        try {
                            // kde seems to append a 0 char to the end of the reader
                            if (!ZERO_CHAR_STRING.equals(fileName)) {
                                final URI uri = new URI(fileName);
                                if (uri.isAbsolute()) {
                                    final File file = new File(uri);
                                    files.add(file);
                                }
                            }
                        } catch (final URISyntaxException e) {
                            LOG.error("Drag and Drop file " + fileName + " not valid", e);
                        }
                    }
                }
            }
            if (!handled) {
                event.rejectDrop();
                return;
            }
        }
        final Project project = Project.get();
        Invoke.background("Open Files", () -> project.openFiles(files));
        event.getDropTargetContext().dropComplete(true);
    } catch (final Throwable e) {
        LOG.error("Unable to drop", e);
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DataFlavor(java.awt.datatransfer.DataFlavor) Project(com.revolsys.swing.map.layer.Project) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 3 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class AbstractOverlay method getSnapLayers.

protected List<AbstractRecordLayer> getSnapLayers() {
    final Project project = getProject();
    final MapPanel map = getMap();
    final double scale = map.getScale();
    return AbstractRecordLayer.getVisibleLayers(project, scale);
}
Also used : Project(com.revolsys.swing.map.layer.Project) MapPanel(com.revolsys.swing.map.MapPanel)

Example 4 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class LayerRendererOverlaySwingWorker method handleBackground.

@Override
protected Void handleBackground() {
    try {
        final Layer layer = this.overlay.getLayer();
        if (layer != null) {
            final Project project = this.overlay.getProject();
            final int imageWidth = this.referencedImage.getImageWidth();
            final int imageHeight = this.referencedImage.getImageHeight();
            if (imageWidth > 0 && imageHeight > 0 && project != null) {
                final BoundingBox boundingBox = this.referencedImage.getBoundingBox();
                try (final ImageViewport viewport = new ImageViewport(project, imageWidth, imageHeight, boundingBox)) {
                    if (layer != null && layer.isExists() && layer.isVisible()) {
                        final LayerRenderer<Layer> renderer = layer.getRenderer();
                        if (renderer != null) {
                            renderer.render(viewport, this);
                        }
                    }
                    if (!isCancelled()) {
                        final BufferedImage image = viewport.getImage();
                        this.referencedImage.setRenderedImage(image);
                    }
                }
            }
        }
        return null;
    } catch (final Throwable t) {
        if (!isCancelled()) {
            Logs.error(this, "Unable to paint", t);
        }
        return null;
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) ImageViewport(com.revolsys.swing.map.ImageViewport) BoundingBox(com.revolsys.geometry.model.BoundingBox) Layer(com.revolsys.swing.map.layer.Layer) BufferedImage(java.awt.image.BufferedImage)

Example 5 with Project

use of com.revolsys.swing.map.layer.Project 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

Project (com.revolsys.swing.map.layer.Project)28 BoundingBox (com.revolsys.geometry.model.BoundingBox)14 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Viewport2D (com.revolsys.swing.map.Viewport2D)4 MapPanel (com.revolsys.swing.map.MapPanel)3 Point (com.revolsys.geometry.model.Point)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ImageViewport (com.revolsys.swing.map.ImageViewport)2 Layer (com.revolsys.swing.map.layer.Layer)2 LayerGroup (com.revolsys.swing.map.layer.LayerGroup)2 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)2 PageFormat (java.awt.print.PageFormat)2 PrinterException (java.awt.print.PrinterException)2 PrinterJob (java.awt.print.PrinterJob)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Geometry (com.revolsys.geometry.model.Geometry)1 LineString (com.revolsys.geometry.model.LineString)1 RectangularMapGrid (com.revolsys.gis.grid.RectangularMapGrid)1 RectangularMapTile (com.revolsys.gis.grid.RectangularMapTile)1