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();
}
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));
}
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());
}
}
}
}
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);
}
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++;
}
}
}
Aggregations