use of com.revolsys.swing.map.MapPanel 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.swing.map.MapPanel in project com.revolsys.open by revolsys.
the class AbstractLayerTreeNode method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(Component renderer, final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
renderer = super.getTreeCellRendererComponent(renderer, tree, value, selected, expanded, leaf, row, hasFocus);
if (isUserObjectInitialized()) {
final Layer layer = getLayer();
final MapPanel map = layer.getMapPanel();
if (map != null) {
final double scale = map.getScale();
if (layer.getRenderer() != null && !layer.isVisible(scale)) {
renderer.setForeground(WebColors.Gray);
}
}
}
return renderer;
}
use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.
the class Project method saveChangesWithPrompt.
public boolean saveChangesWithPrompt(final int optionType) {
if (isReadOnly()) {
return true;
} else {
final List<Layer> layersWithChanges = new ArrayList<>();
addChangedLayers(this, layersWithChanges);
if (layersWithChanges.isEmpty()) {
return true;
} else {
final MapPanel mapPanel = getMapPanel();
final JLabel message = new JLabel("<html><body><p><b>The following layers have un-saved changes.</b></p>" + "<p><b>Do you want to save the changes before continuing?</b></p><ul><li>" + Strings.toString("</li>\n<li>", layersWithChanges) + "</li></ul></body></html>");
final int option = JOptionPane.showConfirmDialog(mapPanel, message, "Save Changes", optionType, JOptionPane.WARNING_MESSAGE);
if (option == JOptionPane.CANCEL_OPTION) {
return false;
} else if (option == JOptionPane.NO_OPTION) {
return true;
} else {
for (final Iterator<Layer> iterator = layersWithChanges.iterator(); iterator.hasNext(); ) {
final Layer layer = iterator.next();
if (layer.saveChanges()) {
iterator.remove();
}
}
if (layersWithChanges.isEmpty()) {
return true;
} else {
final JLabel message2 = new JLabel("<html><body><p><b>The following layers could not be saved.</b></p>" + "<p><b>Do you want to ignore these changes and continue?</b></p><ul><li>" + Strings.toString("</li>\n<li>", layersWithChanges) + "</li></ul></body></html>");
final int option2 = JOptionPane.showConfirmDialog(mapPanel, message2, "Ignore Changes", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (option2 == JOptionPane.CANCEL_OPTION) {
return false;
} else {
return true;
}
}
}
}
}
}
use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.
the class GridLayer method zoomToSheet.
public void zoomToSheet(final String mapsheet) {
final Project project = getProject();
if (project != null) {
if (Property.hasValue(mapsheet)) {
final MapPanel map = getMapPanel();
final RectangularMapGrid grid = getGrid();
final String gridName = grid.getName();
try {
final RectangularMapTile mapTile = grid.getTileByName(mapsheet);
final BoundingBox boundingBox = mapTile.getBoundingBox();
project.setViewBoundingBox(boundingBox);
} catch (final Throwable e) {
final String message = "Invalid mapsheet " + mapsheet + " for " + gridName;
JOptionPane.showMessageDialog(map, message);
} finally {
final String preferenceName = CaseConverter.toCapitalizedWords(gridName) + "Mapsheet";
PreferencesUtil.setString(getClass(), preferenceName, mapsheet);
}
}
}
}
use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.
the class SelectRecordsOverlay method paintComponent.
@Override
public void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
final GeoreferencedImage imageSelected = this.imageSelected.getResource();
if (imageSelected != null) {
GeoreferencedImageLayerRenderer.render(viewport, graphics, imageSelected, false);
}
final GeometryFactory viewportGeometryFactory = getViewportGeometryFactory2d();
final MapPanel map = getMap();
final List<LayerRecord> closeSelectedRecords = map.getCloseSelectedRecords();
if (!closeSelectedRecords.isEmpty()) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
for (final LayerRecord record : closeSelectedRecords) {
final Geometry geometry = record.getGeometry();
if (record.isHighlighted()) {
this.highlightVertexRenderer.paintSelected(viewport, graphics, viewportGeometryFactory, geometry);
} else {
this.selectVertexRenderer.paintSelected(viewport, graphics, viewportGeometryFactory, geometry);
}
}
}
}
final List<CloseLocation> closeSelectedLocations = map.getCloseSelectedLocations();
if (Property.hasValue(closeSelectedLocations)) {
for (final CloseLocation location : closeSelectedLocations) {
final Vertex vertex = location.getVertex();
CLOSE_VERTEX_STYLE_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
}
}
paintSelectBox(graphics);
}
Aggregations