protected Dataset getDataset(final DataView view) { final Data data = view.getData(); return data instanceof Dataset ? (Dataset) data : null; }
@Override public void removeOverlay(final ImageDisplay display, final Overlay overlay) { final ArrayList<DataView> overlayViews = new ArrayList<>(); final List<DataView> views = display; for (final DataView view : views) { final Data data = view.getData(); if (data == overlay) overlayViews.add(view); } for (final DataView view : overlayViews) { display.remove(view); view.dispose(); } display.update(); }
@Override public List<Overlay> getOverlays(final ImageDisplay display, final boolean selectedOnly) { final ArrayList<Overlay> overlays = new ArrayList<>(); for (final DataView view : display) { if (selectedOnly && !view.isSelected()) { // ignore non-selected objects continue; } final Data data = view.getData(); if (!(data instanceof Overlay)) continue; // ignore non-overlays final Overlay overlay = (Overlay) data; overlays.add(overlay); } return overlays; }
@Override public DataView createDataView(final Data data) { for (final DataView dataView : getDataViews()) { if (dataView.isCompatible(data)) { dataView.initialize(data); return dataView; } } throw new IllegalArgumentException("No data view found for data: " + data); }
@Override public void update() { // NB - this combinedinterval.update() call rebuilds the interval. We have // found cases where this is necessary to avoid situations where the we try // to access a no longer existing axis. As an example of this try running // legacy command Type > 8-bit Color on Clowns. Without this line, when you // run the command, an exception is thrown. // TODO - is this a performance issue? combinedInterval.update(); for (final DataView view : this) { for (int i = 0; i < numDimensions(); i++) { AxisType axis = axis(i).type(); if (axis.isXY()) continue; final int axisNum = view.getData().dimensionIndex(axis); if (axisNum < 0) continue; final long p = getLongPosition(axis); Data data = view.getData(); double size = data.realMax(axisNum) - data.realMin(axisNum) + 1; if (p < size) { view.setPosition(p, axis); } } view.update(); } super.update(); }
@Override public boolean isVisible(final DataView view) { for (int i = 0; i < numDimensions(); i++) { final AxisType axis = axis(i).type(); if (axis.isXY()) continue; final long value = getLongPosition(axis); final int index = view.getData().dimensionIndex(axis); if (index < 0) { // verify that the display's position matches the view's value if (value != view.getLongPosition(axis)) return false; } else { // verify that the display's position matches the data's range final double min = index < 0 ? 0 : view.getData().realMin(index); final double max = index < 0 ? 0 : view.getData().realMax(index); if (value < min || value > max) { // dimensional position is outside the data's range return false; } } } return true; }
@Override public void valueChanged(final ListSelectionEvent listSelectionEvent) { if (selecting) return; selecting = true; final ImageDisplay display = imageDisplayService.getActiveImageDisplay(); if (display == null) return; final JList<?> list = (JList<?>) listSelectionEvent.getSource(); final List<?> selectionValues = list.getSelectedValuesList(); overlayService.getOverlayInfo().deselectAll(); for (final Object overlayInfoObj : selectionValues) { final OverlayInfo overlayInfo = (OverlayInfo) overlayInfoObj; overlayInfo.setSelected(true); } for (final DataView overlayView : display) { overlayView.setSelected(false); for (final Object overlayInfoObj : selectionValues) { final OverlayInfo overlayInfo = (OverlayInfo) overlayInfoObj; if (overlayInfo.getOverlay() == overlayView.getData()) { overlayInfo.setSelected(true); overlayView.setSelected(true); break; } } } selecting = false; } };
@Override public Overlay getActiveOverlay(final ImageDisplay disp) { for (final DataView view : disp) { if (view.isSelected() && view instanceof OverlayView) { return ((OverlayView) view).getData(); } } return null; }
/** Frees resources associated with the display. */ private void cleanup() { // NB: Fixes bug #893. for (final DataView view : this) { view.dispose(); } clear(); combinedInterval.clear(); }
final Position pos = view.getPlanePosition();
@SuppressWarnings("unused") private Overlay getActiveOverlay() { final ImageDisplay activeDisplay = imageDisplayService.getActiveImageDisplay(); if (activeDisplay == null) return null; final List<DataView> views = activeDisplay; for (DataView view : views) { if (view.isSelected() && (view instanceof OverlayView)) return ((OverlayView) view).getData(); } return null; }
@Override public void figureRemoved(final FigureEvent e) { final ImageDisplay d = getDisplay(); if (d.isVisible(overlayView)) { DataView view = getDataView(); // TODO : replace next two lines with call to OverlayService to // removeOverlay(d, getDataView().getData()); d.remove(view); view.dispose(); // end TODO replace dispose(); d.update(); } } });
@Override public List<Dataset> getDatasets(final ImageDisplay display) { final ArrayList<Dataset> datasets = new ArrayList<>(); if (display != null) { for (final DataView view : display) { final Data data = view.getData(); if (!(data instanceof Dataset)) continue; final Dataset dataset = (Dataset) data; datasets.add(dataset); } } return datasets; }
double yMax = Double.NEGATIVE_INFINITY; for (final DataView view : display) { if (!view.isSelected()) continue; final Data data = view.getData(); final double min0 = data.realMin(0); final double max0 = data.realMax(0);
@Override public boolean isDisplaying(final Object o) { if (super.isDisplaying(o)) return true; // check for wrapped Data objects for (final DataView view : this) { if (o == view.getData()) return true; } return false; }
@Override public List<ImageDisplay> getDisplays(final Overlay o) { final ArrayList<ImageDisplay> containers = new ArrayList<>(); final List<Display<?>> displays = displayService.getDisplays(); for (final Display<?> display : displays) { if (!(display instanceof ImageDisplay)) continue; final ImageDisplay imageDisplay = (ImageDisplay) display; for (final DataView view : imageDisplay) { final Data data = view.getData(); if (!(data instanceof Overlay)) continue; final Overlay overlay = (Overlay) data; if (overlay == o) containers.add(imageDisplay); } } return containers; }
/** * Removes the {@link #IMP_KEY} entry from the {@link Dataset} attached to * the given {@link ImageDisplay} - if any. */ private void clearImagePlusKey(final ImageDisplay display) { Data data = display.getActiveView().getData(); if (Dataset.class.isAssignableFrom(data.getClass())) { ((Dataset)data).getProperties().remove(IMP_KEY); } }
@EventHandler protected void onEvent(final DataUpdatedEvent event) { for (final DataView view : this) { if (event.getObject() == view.getData()) { // BDZ removed 2013-03-15: update() updates all views. Addresses #1220. // view.update(); update(); return; } } }
/** * If the display is still nameless, tries to name it after the given * {@link DataView}. */ private void updateName(final DataView dataView) { if (getName() != null) return; // display already has a name final String dataName = dataView.getData().getName(); if (dataName != null && !dataName.isEmpty()) { setName(createName(dataName)); } }