Search in sources :

Example 31 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method getPasteRecordGeometry.

protected Geometry getPasteRecordGeometry(final LayerRecord record, final boolean alert) {
    try {
        if (record == null) {
            return null;
        } else {
            final RecordDefinition recordDefinition = getRecordDefinition();
            final FieldDefinition geometryField = recordDefinition.getGeometryField();
            if (geometryField != null) {
                final MapPanel parentComponent = getMapPanel();
                Geometry geometry = null;
                DataType geometryDataType = null;
                Class<?> layerGeometryClass = null;
                final GeometryFactory geometryFactory = getGeometryFactory();
                geometryDataType = geometryField.getDataType();
                layerGeometryClass = geometryDataType.getJavaClass();
                RecordReader reader = ClipboardUtil.getContents(RecordReaderTransferable.DATA_OBJECT_READER_FLAVOR);
                if (reader == null) {
                    final String string = ClipboardUtil.getContents(DataFlavor.stringFlavor);
                    if (Property.hasValue(string)) {
                        try {
                            geometry = geometryFactory.geometry(string);
                            geometry = geometryFactory.geometry(layerGeometryClass, geometry);
                            if (geometry != null) {
                                return geometry;
                            }
                        } catch (final Throwable e) {
                        }
                        final Resource resource = new ByteArrayResource("t.csv", string);
                        reader = RecordReader.newRecordReader(resource);
                    } else {
                        return null;
                    }
                }
                if (reader != null) {
                    try {
                        for (final Record sourceRecord : reader) {
                            if (geometry == null) {
                                final Geometry sourceGeometry = sourceRecord.getGeometry();
                                if (sourceGeometry == null) {
                                    if (alert) {
                                        JOptionPane.showMessageDialog(parentComponent, "Clipboard does not contain a record with a geometry.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                                    }
                                    return null;
                                }
                                geometry = geometryFactory.geometry(layerGeometryClass, sourceGeometry);
                                if (geometry == null) {
                                    if (alert) {
                                        JOptionPane.showMessageDialog(parentComponent, "Clipboard should contain a record with a " + geometryDataType + " not a " + sourceGeometry.getGeometryType() + ".", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                                    }
                                    return null;
                                }
                            } else {
                                if (alert) {
                                    JOptionPane.showMessageDialog(parentComponent, "Clipboard contains more than one record. Copy a single record.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                                }
                                return null;
                            }
                        }
                    } finally {
                        FileUtil.closeSilent(reader);
                    }
                    if (geometry == null) {
                        if (alert) {
                            JOptionPane.showMessageDialog(parentComponent, "Clipboard does not contain a record with a geometry.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                        }
                    } else if (geometry.isEmpty()) {
                        if (alert) {
                            JOptionPane.showMessageDialog(parentComponent, "Clipboard contains an empty geometry.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                        }
                        return null;
                    } else {
                        return geometry;
                    }
                }
            }
            return null;
        }
    } catch (final Throwable t) {
        return null;
    }
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordReader(com.revolsys.record.io.RecordReader) ListRecordReader(com.revolsys.record.io.ListRecordReader) ByteArrayResource(com.revolsys.spring.resource.ByteArrayResource) Resource(com.revolsys.spring.resource.Resource) LineString(com.revolsys.geometry.model.LineString) ByteArrayResource(com.revolsys.spring.resource.ByteArrayResource) RecordDefinition(com.revolsys.record.schema.RecordDefinition) Geometry(com.revolsys.geometry.model.Geometry) DataType(com.revolsys.datatype.DataType) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record)

Example 32 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class SvgMarker method postSetMarkerType.

@Override
protected void postSetMarkerType() {
    final String markerType = getMarkerType();
    this.symbol = SymbolLibrary.findSymbol(markerType);
    final Resource resource = new ClassPathResource(markerType + ".svg");
    try {
        final String uri = resource.getUriString();
        this.document = SvgUtil.newDocument(uri);
        this.transcoderInput = new TranscoderInput(this.document);
        this.transcoderInput.setURI(uri);
        this.icon = new SvgIcon(this.document, 16, 16);
    } catch (final Throwable e) {
        this.document = null;
        Logs.error(this, "Cannot open :" + resource, e);
    }
}
Also used : TranscoderInput(org.apache.batik.transcoder.TranscoderInput) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Resource(com.revolsys.spring.resource.Resource) ClassPathResource(com.revolsys.spring.resource.ClassPathResource)

Example 33 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class SymbolLibrary method initialize.

private static void initialize() {
    synchronized (SYMBOL_LIBRARIES) {
        if (!initialized) {
            initialized = true;
            ShapeMarker.init();
            try {
                final ClassLoader classLoader = MapObjectFactoryRegistry.class.getClassLoader();
                final String resourceName = "META-INF/" + SymbolLibrary.class.getName() + ".json";
                final Enumeration<URL> resources = classLoader.getResources(resourceName);
                while (resources.hasMoreElements()) {
                    final URL url = resources.nextElement();
                    try {
                        final Resource resource = Resource.getResource(url);
                        final SymbolLibrary symbolLibrary = MapObjectFactory.toObject(resource);
                        addSymbolLibrary(symbolLibrary);
                    } catch (final Throwable e) {
                        Logs.error(MapObjectFactoryRegistry.class, "Unable to read resource" + url, e);
                    }
                }
            } catch (final Throwable e) {
                Logs.error(MapObjectFactoryRegistry.class, "Unable to read resources", e);
            }
        }
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource) MapObjectFactoryRegistry(com.revolsys.io.map.MapObjectFactoryRegistry) URL(java.net.URL)

Example 34 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class LayerGroup method loadLayer.

protected Layer loadLayer(final File file) {
    final Resource oldResource = Resource.setBaseResource(new PathResource(file.getParentFile()));
    try {
        final Map<String, Object> properties = Json.toMap(file);
        final Layer layer = MapObjectFactory.toObject(properties);
        if (layer != null) {
            addLayer(layer);
        }
        return layer;
    } catch (final Throwable t) {
        Logs.error(this, "Cannot load layer from " + file, t);
        return null;
    } finally {
        Resource.setBaseResource(oldResource);
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) FileRecordLayer(com.revolsys.swing.map.layer.record.FileRecordLayer) TriangulatedIrregularNetworkLayer(com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer) PointCloudLayer(com.revolsys.swing.map.layer.pointcloud.PointCloudLayer) GriddedElevationModelLayer(com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)

Example 35 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class LayerGroup method loadLayers.

@SuppressWarnings("unchecked")
protected void loadLayers(final Project rootProject, final Map<String, ? extends Object> config) {
    final List<String> layerFiles = (List<String>) config.remove("layers");
    setProperties(config);
    if (layerFiles != null) {
        for (String fileName : layerFiles) {
            if (fileName.endsWith(".rgmap")) {
                final Resource childResource = Resource.getBaseResource(fileName);
                if (!importProject(rootProject, childResource, false)) {
                    Logs.error(LayerGroup.class, "Project not found: " + childResource);
                }
            } else {
                if (!fileName.endsWith("rgobject")) {
                    fileName += "/rgLayerGroup.rgobject";
                }
                final Resource childResource = Resource.getBaseResource(fileName);
                if (childResource.exists()) {
                    final Object object = MapObjectFactory.toObject(childResource);
                    if (object instanceof Layer) {
                        final Layer layer = (Layer) object;
                        addLayer(layer);
                    } else if (object != null) {
                        Logs.error(this, "Unexpected object type " + object.getClass() + " in " + childResource);
                    }
                } else {
                    Logs.error(LayerGroup.class, "Layer not found: " + childResource);
                }
            }
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) List(java.util.List) ArrayList(java.util.ArrayList) FileRecordLayer(com.revolsys.swing.map.layer.record.FileRecordLayer) TriangulatedIrregularNetworkLayer(com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer) PointCloudLayer(com.revolsys.swing.map.layer.pointcloud.PointCloudLayer) GriddedElevationModelLayer(com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)

Aggregations

Resource (com.revolsys.spring.resource.Resource)78 PathResource (com.revolsys.spring.resource.PathResource)23 MapEx (com.revolsys.collection.map.MapEx)9 File (java.io.File)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)6 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 Writer (java.io.Writer)5 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 DataType (com.revolsys.datatype.DataType)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 RecordReader (com.revolsys.record.io.RecordReader)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 Blob (java.sql.Blob)3