private void initActiveAxis() { if (activeAxis == null) { for (int i = 0; i < numDimensions(); i++) { AxisType axisType = axis(i).type(); if (axisType.isXY()) continue; setActiveAxis(axisType); 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)); } }
@Override public void dimensions(final long[] dimensions) { for (int i = 0; i < dimensions.length; i++) { dimensions[i] = dimension(i); } }
@Override public RealRect getPlaneExtents() { final int xAxis = dimensionIndex(Axes.X); final int yAxis = dimensionIndex(Axes.Y); final double xMin = realMin(xAxis); final double yMin = realMin(yAxis); final double width = realMax(xAxis) - realMin(xAxis); final double height = realMax(yAxis) - realMin(yAxis); return new RealRect(xMin, yMin, width, height); }
@Override public long getLongPosition(final AxisType axis) { final int d = dimensionIndex(axis); if (d < 0) { // untracked axes are all at position 0 by default return 0; } final Long value = pos.get(axis); if (value == null) return 0; final long min = min(d); if (value < min) return min; final long max = max(d); if (value > max) return max; return value; }
if (dimensionIndex(axis) < 0) { pos.remove(axis); for (int i = 0; i < numDimensions(); i++) { final AxisType axis = axis(i).type(); if (axis.isXY()) continue; // do not track position of planar axes if (!pos.containsKey(axis)) { pos.put(axis, min(i)); if (getActiveAxis() == null) initActiveAxis();
@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 run() { synchronized (getContext()) { for (final DataView view : DefaultImageDisplay.this) { if (event.getObject() == view.getData()) { rebuild(); update(); return; } } } } });
@Override public void setPosition(final int position, final int d) { setPosition(position, axis(d).type()); }
@Override public long getLongPosition(final int d) { return getLongPosition(axis(d).type()); }
@Override public int getIntPosition(final int d) { return getIntPosition(axis(d).type()); }
@Override public void setActiveAxis(final AxisType axis) { if (dimensionIndex(axis) < 0) { throw new IllegalArgumentException("Unknown axis: " + axis); } activeAxis = axis; // notify interested parties of the change if (eventService != null) { eventService.publish(new AxisActivatedEvent(this, activeAxis)); } }
@EventHandler protected void onEvent(final DisplayDeletedEvent event) { if (event.getObject() != this) return; cleanup(); }
/** Frees resources associated with the display. */ private void cleanup() { // NB: Fixes bug #893. for (final DataView view : this) { view.dispose(); } clear(); combinedInterval.clear(); }
final ImageDisplay imageDisplay = new DefaultImageDisplay(); imageDisplay.setContext(c); imageDisplay.display(d);
@Override public void setPosition(final long position, final AxisType axis) { final int axisIndex = dimensionIndex(axis); if (axisIndex < 0) { throw new IllegalArgumentException("Invalid axis: " + axis); } // clamp new position value to [min, max] final long min = min(axisIndex); final long max = max(axisIndex); long value = position; if (value < min) value = min; if (value > max) value = max; // update position pos.put(axis, value); // notify interested parties of the change // NB: DataView.setPosition is called only in update method. if (eventService != null) { // NB: BDZ changed from publish() to publishLater(). This fixes bug #1234. // We may want to change order of events to allow publish() instead. eventService.publishLater(new AxisPositionEvent(this, axis)); } }
@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 void setPosition(final long position, final int d) { setPosition(position, axis(d).type()); }