Search in sources :

Example 1 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class LayerRecordForm method addToolBar.

protected ToolBar addToolBar(final AbstractRecordLayer layer) {
    this.toolBar = new ToolBar();
    add(this.toolBar, BorderLayout.NORTH);
    final RecordDefinition recordDefinition = getRecordDefinition();
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    final boolean hasGeometry = geometryField != null;
    final EnableCheck editable = new ObjectPropertyEnableCheck(this, "editable");
    if (layer != null) {
        final MenuFactory menuFactory = MenuFactory.findMenu(layer);
        if (menuFactory != null) {
            this.toolBar.addButtonTitleIcon("menu", "Layer Menu", "menu", () -> menuFactory.showMenu(layer, this, 10, 10));
        }
    }
    final EnableCheck deletableEnableCheck = editable.and(new ObjectPropertyEnableCheck(this, "deletable"));
    this.toolBar.addButton("record", "Delete Record", "table_row_delete", deletableEnableCheck, this::deleteRecord);
    // Cut, Copy Paste
    this.toolBar.addButton("dnd", "Copy Record", "page_copy", (EnableCheck) null, this::dataTransferCopy);
    if (hasGeometry) {
        this.toolBar.addButton("dnd", "Copy Geometry", "geometry_copy", (EnableCheck) null, this::copyGeometry);
    }
    this.toolBar.addButton("dnd", "Paste Record", "paste_plain", editable, this::dataTransferPaste);
    if (hasGeometry) {
        this.toolBar.addButton("dnd", "Paste Geometry", "geometry_paste", editable, this::pasteGeometry);
    }
    final EnableCheck canUndo = new ObjectPropertyEnableCheck(this.undoManager, "canUndo");
    final EnableCheck canRedo = new ObjectPropertyEnableCheck(this.undoManager, "canRedo");
    final EnableCheck modifiedOrDeleted = new ObjectPropertyEnableCheck(this, "modifiedOrDeleted");
    this.toolBar.addButton("changes", "Revert Record", "arrow_revert", modifiedOrDeleted, this::revertChanges);
    this.toolBar.addButton("changes", "Revert Empty Fields", "field_empty_revert", new ObjectPropertyEnableCheck(this, "hasModifiedEmptyFields"), this::revertEmptyFields);
    this.toolBar.addButton("changes", "Undo", "arrow_undo", canUndo, this.undoManager::undo);
    this.toolBar.addButton("changes", "Redo", "arrow_redo", canRedo, this.undoManager::redo);
    if (hasGeometry) {
        this.toolBar.addButtonTitleIcon("zoom", "Zoom to Record", "magnifier_zoom_selected", () -> {
            final LayerRecord record = getRecord();
            layer.zoomToRecord(record);
        });
        this.toolBar.addButtonTitleIcon("zoom", "Pan to Record", "pan_selected", () -> {
            final LayerRecord record = getRecord();
            final MapPanel mapPanel = layer.getMapPanel();
            if (mapPanel != null) {
                mapPanel.panToRecord(record);
            }
        });
    }
    // Geometry manipulation
    if (hasGeometry) {
        final DataType geometryDataType = geometryField.getDataType();
        if (geometryDataType == DataTypes.LINE_STRING || geometryDataType == DataTypes.MULTI_LINE_STRING) {
            if (DirectionalFields.getProperty(recordDefinition).hasDirectionalFields()) {
                this.toolBar.addButton("geometry", FLIP_RECORD_NAME, FLIP_RECORD_ICON, editable, this::flipRecordOrientation);
                this.toolBar.addButton("geometry", FLIP_LINE_ORIENTATION_NAME, FLIP_LINE_ORIENTATION_ICON, editable, this::flipLineOrientation);
                this.toolBar.addButton("geometry", FLIP_FIELDS_NAME, FLIP_FIELDS_ICON, editable, this::flipFields);
            } else {
                this.toolBar.addButton("geometry", "Flip Line Orientation", "flip_line", editable, this::flipLineOrientation);
            }
        }
    }
    return this.toolBar;
}
Also used : ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) MapPanel(com.revolsys.swing.map.MapPanel) MenuFactory(com.revolsys.swing.menu.MenuFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ToolBar(com.revolsys.swing.toolbar.ToolBar) DataType(com.revolsys.datatype.DataType) EnableCheck(com.revolsys.swing.action.enablecheck.EnableCheck) ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 2 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class MeasureOverlay method updateMouseOverLocations.

private boolean updateMouseOverLocations() {
    final MapPanel map = getMap();
    if (this.mouseOverLocations.isEmpty()) {
        map.clearToolTipText();
        return false;
    } else {
        final Map<String, Set<CloseLocation>> vertexLocations = new TreeMap<>();
        final Map<String, Set<CloseLocation>> segmentLocations = new TreeMap<>();
        for (final CloseLocation location : this.mouseOverLocations) {
            if (location.getVertexId() == null) {
                Maps.addToSet(segmentLocations, "Measure", location);
            } else {
                Maps.addToSet(vertexLocations, "Measure", location);
            }
        }
        final StringBuilder text = new StringBuilder("<html>");
        appendLocations(text, "Move Vertices", vertexLocations);
        appendLocations(text, "Insert Vertices", segmentLocations);
        text.append("</html>");
        final Point2D eventPoint = getEventPosition();
        map.setToolTipText(eventPoint, text);
        if (vertexLocations.isEmpty()) {
            setMapCursor(CURSOR_LINE_ADD_NODE);
        } else {
            setMapCursor(CURSOR_NODE_EDIT);
        }
    }
    return true;
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) Set(java.util.Set) Point2D(java.awt.geom.Point2D) LineString(com.revolsys.geometry.model.LineString) TreeMap(java.util.TreeMap)

Example 3 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class ZoomOverlay method panFinish.

public boolean panFinish(final MouseEvent event) {
    if (event.getButton() == this.panButton) {
        if (clearOverlayAction(ACTION_PAN) && this.panX1 != -1) {
            this.panImage = null;
            if (this.panX1 != this.panX2 || this.panY1 != this.panY2) {
                final java.awt.Point point = event.getPoint();
                final Viewport2D viewport = getViewport();
                final Point fromPoint = viewport.toModelPoint(this.panX1, this.panY1);
                final Point toPoint = viewport.toModelPoint(point);
                final double deltaX = fromPoint.getX() - toPoint.getX();
                final double deltaY = fromPoint.getY() - toPoint.getY();
                final BoundingBox boundingBox = viewport.getBoundingBox();
                final BoundingBox newBoundingBox = boundingBox.move(deltaX, deltaY);
                final MapPanel map = getMap();
                map.setBoundingBox(newBoundingBox);
            }
            panClear();
            repaint();
            return true;
        }
    }
    return false;
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 4 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class ZoomOverlay method zoomBoxFinish.

protected boolean zoomBoxFinish(final MouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON1 && clearOverlayAction(ACTION_ZOOM_BOX)) {
        final Viewport2D viewport = getViewport();
        // Convert first point to envelope top left in map coords.
        final int minX = Math.min(this.zoomBoxX1, this.zoomBoxX2);
        final int minY = Math.min(this.zoomBoxY1, this.zoomBoxY2);
        final Point topLeft = viewport.toModelPoint(minX, minY);
        // Convert second point to envelope bottom right in map coords.
        final int maxX = Math.max(this.zoomBoxX1, this.zoomBoxX2);
        final int maxY = Math.max(this.zoomBoxY1, this.zoomBoxY2);
        final Point bottomRight = viewport.toModelPoint(maxX, maxY);
        final MapPanel map = getMap();
        final GeometryFactory geometryFactory = map.getGeometryFactory();
        final BoundingBox boundingBox = geometryFactory.newBoundingBox(topLeft.getX(), topLeft.getY(), bottomRight.getX(), bottomRight.getY());
        if (boundingBox.isEmpty()) {
            Toolkit.getDefaultToolkit().beep();
        } else {
            map.setBoundingBox(boundingBox);
        }
        zoomBoxClear();
        if (SwingUtil.isShiftDown(event) && isMouseInMap()) {
            setOverlayAction(ACTION_ZOOM_BOX);
        }
        return true;
    }
    return false;
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 5 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class ZoomOverlay method mouseWheelMoved.

@Override
public void mouseWheelMoved(final MouseWheelEvent event) {
    if (canOverrideOverlayAction(ACTION_ZOOM)) {
        if (Math.abs(event.getWheelRotation()) == 1 && event.getModifiersEx() == 0) {
            int numSteps = 1;
            if (event.getUnitsToScroll() < 0) {
                numSteps = -1;
            }
            if (SwingUtil.isScrollReversed()) {
                numSteps = -numSteps;
            }
            if (!isWheelForwardsZoomIn()) {
                numSteps = -numSteps;
            }
            final int x = event.getX();
            final int y = event.getY();
            final Viewport2D viewport = getViewport();
            final Point mapPoint = viewport.toModelPoint(x, y);
            final MapPanel map = getMap();
            map.zoom(mapPoint, numSteps);
            event.consume();
        }
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

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