Search in sources :

Example 11 with MapPanel

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;
    }
}
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 12 with MapPanel

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;
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) Layer(com.revolsys.swing.map.layer.Layer)

Example 13 with MapPanel

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;
                    }
                }
            }
        }
    }
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JLabel(javax.swing.JLabel)

Example 14 with MapPanel

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);
            }
        }
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) MapPanel(com.revolsys.swing.map.MapPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) RectangularMapTile(com.revolsys.gis.grid.RectangularMapTile) RectangularMapGrid(com.revolsys.gis.grid.RectangularMapGrid)

Example 15 with MapPanel

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);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Vertex(com.revolsys.geometry.model.vertex.Vertex) MapPanel(com.revolsys.swing.map.MapPanel) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) GeoreferencedImage(com.revolsys.raster.GeoreferencedImage) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Aggregations

MapPanel (com.revolsys.swing.map.MapPanel)32 Point (com.revolsys.geometry.model.Point)6 Viewport2D (com.revolsys.swing.map.Viewport2D)6 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 LineString (com.revolsys.geometry.model.LineString)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)4 ArrayList (java.util.ArrayList)4 DataType (com.revolsys.datatype.DataType)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 Project (com.revolsys.swing.map.layer.Project)3 Set (java.util.Set)3 TreeMap (java.util.TreeMap)3 JLabel (javax.swing.JLabel)3 Geometry (com.revolsys.geometry.model.Geometry)2 RectangularMapGrid (com.revolsys.gis.grid.RectangularMapGrid)2 EnableCheck (com.revolsys.swing.action.enablecheck.EnableCheck)2 TabbedValuePanel (com.revolsys.swing.component.TabbedValuePanel)2 Layer (com.revolsys.swing.map.layer.Layer)2