Search in sources :

Example 16 with MapPanel

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

the class SelectRecordsOverlay method selectBoxFinish.

private boolean selectBoxFinish(final MouseEvent event) {
    if (event.getButton() == this.selectBoxButton && this.selectBoxX1 != -1) {
        if (clearOverlayAction(ACTION_SELECT_RECORDS)) {
            final MapPanel map = getMap();
            final GeometryFactory geometryFactory = map.getGeometryFactory();
            BoundingBox boundingBox = geometryFactory.newBoundingBox(this.selectBoxX1, this.selectBoxY1, this.selectBoxX2, this.selectBoxY2);
            final Viewport2D viewport = getViewport();
            final double minSize = viewport.getModelUnitsPerViewUnit() * 10;
            final double width = boundingBox.getWidth();
            double deltaX = 0;
            if (width < minSize) {
                deltaX = (minSize - width) / 2;
            }
            final double height = boundingBox.getWidth();
            double deltaY = 0;
            if (height < minSize) {
                deltaY = (minSize - height) / 2;
            }
            boundingBox = boundingBox.expand(deltaX, deltaY);
            if (!boundingBox.isEmpty()) {
                doSelectRecords(event, boundingBox);
            }
            selectBoxClear();
            if (isMouseInMap()) {
                setSelectCursor(event);
            }
            event.consume();
            repaint();
            return true;
        }
    }
    return false;
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) Viewport2D(com.revolsys.swing.map.Viewport2D) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 17 with MapPanel

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

the class SinglePage method print.

@Override
public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex) throws PrinterException {
    if (pageIndex == 0) {
        setGraphics((Graphics2D) graphics);
        final int translateX = (int) pageFormat.getImageableX();
        final int translateY = (int) pageFormat.getImageableY();
        graphics.translate(translateX - 1, translateY - 1);
        final Project project = getProject();
        final MapPanel mapPanel = project.getMapPanel();
        final Layer baseMapLayer = mapPanel.getBaseMapLayer();
        render(baseMapLayer);
        render(project);
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE;
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) MapPanel(com.revolsys.swing.map.MapPanel) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) Layer(com.revolsys.swing.map.layer.Layer)

Example 18 with MapPanel

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

the class MeasureOverlay method modeMeasureMove.

protected boolean modeMeasureMove(final MouseEvent event) {
    if (isOverlayAction(MEASURE)) {
        final MapPanel map = getMap();
        final CloseLocation location = map.findCloseLocation(null, null, this.measureGeometry);
        final List<CloseLocation> locations = new ArrayList<>();
        if (location != null) {
            locations.add(location);
        }
        final boolean hasMouseOver = setMouseOverLocations(locations);
        // TODO make work with multi-part
        if (!hasMouseOver) {
            modeMeasureUpdateXorGeometry();
        }
        return true;
    }
    return false;
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) ArrayList(java.util.ArrayList)

Example 19 with MapPanel

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

the class ZoomOverlay method panStart.

public boolean panStart(final MouseEvent event, final boolean drag) {
    if (this.panX1 == -1) {
        boolean pan = false;
        final int button = event.getButton();
        if (button == MouseEvent.BUTTON2) {
            pan = true;
            this.panButton = MouseEvent.BUTTON2;
        } else if (!drag && button == MouseEvent.BUTTON1 && !hasOverlayAction()) {
            if (event.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
                pan = true;
                this.panButton = MouseEvent.BUTTON1;
            }
        }
        if (pan) {
            if (setOverlayAction(ACTION_PAN)) {
                final Viewport2D viewport = getViewport();
                final int width = viewport.getViewWidthPixels();
                final int height = viewport.getViewHeightPixels();
                if (width > 0 && height > 0) {
                    final JComponent parent = (JComponent) getParent();
                    this.panImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                    final Graphics2D graphics = (Graphics2D) this.panImage.getGraphics();
                    try {
                        final Insets insets = parent.getInsets();
                        graphics.translate(-insets.left, -insets.top);
                        graphics.setColor(Color.WHITE);
                        graphics.fillRect(insets.left, insets.top, width, height);
                        parent.paintComponents(graphics);
                    } finally {
                        graphics.dispose();
                    }
                    this.panX1 = this.panX2 = event.getX();
                    this.panY1 = this.panY2 = event.getY();
                    final MapPanel map = getMap();
                    map.setVisibleOverlay(this);
                }
                return true;
            }
        }
        return false;
    } else {
        return true;
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) Insets(java.awt.Insets) JComponent(javax.swing.JComponent) Point(com.revolsys.geometry.model.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 20 with MapPanel

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

the class ZoomOverlay method mouseClicked.

@Override
public void mouseClicked(final MouseEvent event) {
    if (canOverrideOverlayAction(ACTION_ZOOM)) {
        final int button = event.getButton();
        // Double click
        if (event.getClickCount() == 2) {
            final int x = event.getX();
            final int y = event.getY();
            int numSteps = 0;
            if (button == MouseEvent.BUTTON1 && !hasOverlayAction() || button == MouseEvent.BUTTON2) {
                // Left or middle button, zoom in
                numSteps = -1;
            } else if (button == MouseEvent.BUTTON3) {
                // Right mouse button, zoom out
                numSteps = 1;
            }
            if (numSteps != 0) {
                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