Search in sources :

Example 1 with OverlayView

use of net.imagej.display.OverlayView in project imagej-ui-swing by imagej.

the class JHotDrawImageCanvas method onEvent.

/**
 * When a tool creates an overlay, add the overlay/figure combo to an
 * {@link OverlayFigureView}.
 */
@EventHandler
protected void onEvent(final FigureCreatedEvent event) {
    final ImageDisplay display = event.getDisplay();
    // not this canvas's display
    if (display != getDisplay())
        return;
    final OverlayView overlay = event.getView();
    for (int i = 0; i < display.numDimensions(); i++) {
        final AxisType axisType = display.axis(i).type();
        if (axisType.isXY())
            continue;
        if (overlay.getData().dimensionIndex(axisType) < 0) {
            overlay.setPosition(display.getLongPosition(axisType), axisType);
        }
    }
    if (drawingView.getSelectedFigures().contains(event.getFigure())) {
        overlay.setSelected(true);
    }
    final OverlayFigureView figureView = new OverlayFigureView(displayViewer, overlay, event.getFigure());
    figureViews.add(figureView);
    display.add(overlay);
    display.update();
}
Also used : AxisType(net.imagej.axis.AxisType) ImageDisplay(net.imagej.display.ImageDisplay) OverlayView(net.imagej.display.OverlayView) Point(java.awt.Point) EventHandler(org.scijava.event.EventHandler)

Example 2 with OverlayView

use of net.imagej.display.OverlayView in project imagej-ui-swing by imagej.

the class JHotDrawService method linkOverlay.

/**
 * Links a new {@link Overlay} and {@link OverlayView}, created by the given
 * {@link JHotDrawAdapter}, to the specified JHotDraw {@link Figure} of a
 * particular {@link ImageDisplay}.
 */
public <F extends Figure> void linkOverlay(final F figure, final JHotDrawAdapter<F> adapter, final ImageDisplay display) {
    final Overlay overlay = adapter.createNewOverlay();
    final DataView view = imageDisplayService.createDataView(overlay);
    if (!(view instanceof OverlayView)) {
        throw new IllegalStateException("Unexpected data view: " + view);
    }
    final OverlayView overlayView = (OverlayView) view;
    adapter.updateOverlay(figure, overlayView);
    eventService.publish(new FigureCreatedEvent(overlayView, figure, display));
}
Also used : DataView(net.imagej.display.DataView) Overlay(net.imagej.overlay.Overlay) OverlayView(net.imagej.display.OverlayView)

Example 3 with OverlayView

use of net.imagej.display.OverlayView in project imagej-plugins-commands by imagej.

the class RemoveOverlay method run.

// -- run() method --
@Override
public void run() {
    final ArrayList<DataView> views = new ArrayList<DataView>(display);
    for (final DataView view : views) {
        if (view.isSelected()) {
            if (view instanceof OverlayView) {
                OverlayView overlayView = (OverlayView) view;
                oService.removeOverlay(overlayView.getData());
            }
        }
    }
}
Also used : DataView(net.imagej.display.DataView) ArrayList(java.util.ArrayList) OverlayView(net.imagej.display.OverlayView)

Example 4 with OverlayView

use of net.imagej.display.OverlayView in project imagej-plugins-commands by imagej.

the class SelectView method run.

@Override
public void run() {
    // first deselect all overlay views
    for (final DataView view : display) {
        if (view instanceof OverlayView) {
            view.setSelected(false);
        }
    }
    for (final DataView view : display) {
        // skip all views other than overlay views
        if (!(view instanceof OverlayView))
            continue;
        // else we have an OverlayView
        OverlayView overlayView = (OverlayView) view;
        if (viewIsInCurrentDisplayedPlane(display, view)) {
            if (viewFillsDisplay(overlayView, display)) {
                view.setSelected(true);
                return;
            }
        }
    }
    // if here no overlay was found on currently viewed plane that selects
    // everything. so create one that does.
    DataView dataView = makeOverlayView(display);
    display.add(dataView);
    dataView.setSelected(true);
}
Also used : DataView(net.imagej.display.DataView) OverlayView(net.imagej.display.OverlayView)

Example 5 with OverlayView

use of net.imagej.display.OverlayView in project imagej-ui-swing by imagej.

the class JHotDrawImageCanvas method rebuild.

// -- Internal methods --
void rebuild() {
    for (final DataView dataView : getDisplay()) {
        FigureView figureView = getFigureView(dataView);
        if (figureView == null) {
            if (dataView instanceof DatasetView) {
                figureView = new DatasetFigureView(this.displayViewer, (DatasetView) dataView);
            } else if (dataView instanceof OverlayView) {
                figureView = new OverlayFigureView(this.displayViewer, (OverlayView) dataView);
            } else {
                log.error("Don't know how to make a figure view for " + dataView.getClass().getName());
                continue;
            }
            figureViews.add(figureView);
        }
    }
    int idx = 0;
    while (idx < figureViews.size()) {
        final FigureView figureView = figureViews.get(idx);
        if (!getDisplay().contains(figureView.getDataView())) {
            figureViews.remove(idx);
            figureView.dispose();
        } else {
            idx++;
        }
    }
}
Also used : DataView(net.imagej.display.DataView) DatasetView(net.imagej.display.DatasetView) OverlayView(net.imagej.display.OverlayView) Point(java.awt.Point)

Aggregations

OverlayView (net.imagej.display.OverlayView)6 DataView (net.imagej.display.DataView)5 Point (java.awt.Point)2 ImageDisplay (net.imagej.display.ImageDisplay)2 ArrayList (java.util.ArrayList)1 AxisType (net.imagej.axis.AxisType)1 DatasetView (net.imagej.display.DatasetView)1 Overlay (net.imagej.overlay.Overlay)1 EventHandler (org.scijava.event.EventHandler)1