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;
}
}
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);
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
}
}
}
Aggregations