Class AbstractDataViewer
- All Implemented Interfaces:
DataViewer, EventPublisher
DataViewer interface.
Custom data viewer classes should extend this class, rather than directly
implement DataViewer.
Warning: Support for custom data viewers is experimental. Future updates may require you to update such code for compatibility.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDataViewer(DisplaySettings initialDisplaySettings) Construct the abstract viewer implementation. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancompareAndSetDisplayPosition(Coords oldPosition, Coords newPosition) Set the display position only if the current position is the expected one.final booleancompareAndSetDisplayPosition(Coords oldPosition, Coords newPosition, boolean forceRedisplay) ImplementscompareAndSetDisplayPosition.final booleancompareAndSetDisplaySettings(DisplaySettings oldSettings, DisplaySettings newSettings) ImplementscompareAndSetDisplaySettings.protected voiddispose()Must be called by implementation to release resources.final DatastoreDeprecated.final CoordsImplementsgetDisplayPosition.final DisplaySettingsImplementsgetDisplaySettings.protected abstract CoordshandleDisplayPosition(Coords position) protected abstract DisplaySettingshandleDisplaySettings(DisplaySettings requestedSettings) Arrange to apply new display settings.protected final voidPost an event on the viewer event bus.final voidregisterForEvents(Object recipient) Register an object to receive events on the viewer event bus.final voidsetDisplayedImageTo(Coords coords) Deprecated.user code should callsetDisplayPositionfinal voidsetDisplayPosition(Coords position) Display the images at the specified coordinates in the data provider.final voidsetDisplayPosition(Coords position, boolean forceRedisplay) ImplementssetDisplayPosition.final voidsetDisplaySettings(DisplaySettings settings) ImplementssetDisplaySettings.final voidunregisterForEvents(Object recipient) Unregister an object from the viewer event bus.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataViewer
addListener, getDataProvider, getDisplayedImages, getName, isClosed, isVisible, removeListener
-
Constructor Details
-
AbstractDataViewer
Construct the abstract viewer implementation.- Parameters:
initialDisplaySettings- initial display settings
-
-
Method Details
-
registerForEvents
Description copied from interface:DataViewerRegister an object to receive events on the viewer event bus.Objects registered by this method will receive viewer events through their methods bearing a
com.google.common.eventbus.Subscribeannotation. See Guava Event Bus documentation for how this works.Events that can be subscribed to include:
DisplaySettingsChangedEvent(on an arbitrary thread)DisplayPositionChangedEvent(on an arbitrary thread)- TODO DisplayPositionRenderedEvent (on the EDT)
- TODO DataViewerClosedEvent (on the EDT)
- Specified by:
registerForEventsin interfaceDataViewer- Specified by:
registerForEventsin interfaceEventPublisher- Parameters:
recipient- the object to register- See Also:
-
unregisterForEvents
Description copied from interface:EventPublisherUnregister an object from the viewer event bus.- Specified by:
unregisterForEventsin interfaceDataViewer- Specified by:
unregisterForEventsin interfaceEventPublisher- Parameters:
recipient- the object to unregister- See Also:
-
postEvent
Post an event on the viewer event bus.Implementations should call this method to post required notification events.
Some standard viewer events require that they be posted on the Swing/AWT event dispatch thread. Make sure you are on the right thread when posting such events.
Viewers are required to post the following events:
DisplaySettingsChangedEvent(posted by this abstract class)DisplayPositionChangedEvent(posted by this abstract class)
- Parameters:
event- the event to post
-
setDisplaySettings
ImplementssetDisplaySettings.Set the display settings.
This method is a good way to set all of the display settings at once, for example to restore a saved set of settings. For changing just part of the settings (for example, in response to the user setting a UI control), see
DataViewer.compareAndSetDisplaySettings(DisplaySettings, DisplaySettings).This method can be called from any thread. There may be a delay before the new settings are actually reflected in the viewer user interface. However,
DataViewer.getDisplaySettings()will always reflect the most recent settings, even if they have not yet been applied to the UI.Implementations must override
handleNewDisplaySettingsin order to respond to new display settings.- Specified by:
setDisplaySettingsin interfaceDataViewer- Parameters:
settings- the new display settings
-
getDisplaySettings
ImplementsgetDisplaySettings.Get the current display settings.
This method can be called from any thread. The return value will be consistent with the most recent call to
DataViewer.setDisplaySettings(DisplaySettings)orcompareAndSetDisplaySettings.- Specified by:
getDisplaySettingsin interfaceDataViewer- Returns:
- the current display settings
-
compareAndSetDisplaySettings
public final boolean compareAndSetDisplaySettings(DisplaySettings oldSettings, DisplaySettings newSettings) ImplementscompareAndSetDisplaySettings.Set the display settings only if the current settings match the expected one.
This method will allow you to make changes to the display settings in a way that is safe if multiple threads are trying to make changes. For example, the following code will set the zoom. If another thread has makes a change to another part of the display settings at the same time (using the same method), all changes will be correctly reflected.
DataViewer viewer = ...; do { DisplaySettings oldSettings = viewer.getDisplaySettings(); DisplaySettings newSettings = oldSettings.copy(). zoom(2.0).build(); } while (!viewer.compareAndSetDisplaySettings(oldSettings, newSettings));Implementations must override
handleNewDisplaySettingsin order to respond to new display settings.- Specified by:
compareAndSetDisplaySettingsin interfaceDataViewer- Parameters:
oldSettings- apply the new settings only if the current settings match thisnewSettings- the new settings- Returns:
- whether the new settings were applied
-
handleDisplaySettings
Arrange to apply new display settings.Override this method to apply new display settings.
This method is called in a thread-synchronized context, so you should avoid time-consuming actions. It is safe to call
getDisplaySettingsand compare its return value withrequestedSettings. However, callingsetDisplaySettingswill result in infinite recursion; if you need to adjustrequestedSettingsbefore accepting it, do so by returning a modified copy from this method. This returned settings is what subsequent calls togetDisplaySettingswill return.Typically, the implementation should record all information needed to make the changes and arrange to apply the changes at a later time (usually on the Swing/AWT event dispatch thread).
- Parameters:
requestedSettings- the new display settings requested- Returns:
- adjusted display settings that will actually apply
-
setDisplayPosition
ImplementssetDisplayPosition.Display the images at the specified coordinates in the data provider.
The exact interpretation of the position may depend on the viewer implementation: for example, a 3D viewer might ignore the Z slice coordinate passed to this method and instead display a whole volume. If the passed position does not uniquely specify a set of images to display, then the viewer might choose an arbitrary subset of the passed coordinates.
This method can be called from any thread. There may be a delay before the new position is actually reflected in the viewer user interface. However,
DataViewer.getDisplayPosition()will always reflect the most recent position, even if it has not been applied to the UI.Implementations must override
handleNewDisplayPositionin order to respond to new display positions.- Specified by:
setDisplayPositionin interfaceDataViewer- Parameters:
position- the coordinates of the images to displayforceRedisplay- if true, assume the image(s) at the position may have changed even if the position does not differ from the current one- See Also:
-
setDisplayPosition
Description copied from interface:DataViewerDisplay the images at the specified coordinates in the data provider.See
DataViewer.setDisplayPosition(Coords, boolean)for details. This method does not force a redisplay ifpositionis the same as the current display position.- Specified by:
setDisplayPositionin interfaceDataViewer- Parameters:
position- the coordinates of the images to display
-
getDisplayPosition
ImplementsgetDisplayPosition.Get the coordinates for the currently displayed images.
This method can be called from any thread. The return value will be consistent with the most recent call to
DataViewer.setDisplayPosition(Coords)orcompareAndSetDisplayPosition.- Specified by:
getDisplayPositionin interfaceDataViewer- Returns:
- the current coordinates displayed
-
compareAndSetDisplayPosition
public final boolean compareAndSetDisplayPosition(Coords oldPosition, Coords newPosition, boolean forceRedisplay) ImplementscompareAndSetDisplayPosition.Set the display position only if the current position is the expected one.
This method will allow you to set the display position based on the current position in a way that is safe if multiple threads are trying to make changes. For example, the following code will scroll to the next channel. If the display position is being changed by another thread (perhaps the time points are being animated, or new time points are being added), all changes will be correctly reflected.
DataViewer viewer = ...; do { Coords oldPos = viewer.getDisplayPosition(); Coords newPos = oldPos.copy(). channel((oldPos.getChannel() + 1) % nChannels).build(); } while (!viewer.compareAndSetDisplayPosition(oldPos, newPos));- Specified by:
compareAndSetDisplayPositionin interfaceDataViewer- Parameters:
oldPosition- apply the new position only if the current position matches this onenewPosition- the new display positionforceRedisplay- if true, assume the image(s) at the position may have changed even if the position does not differ from the current one- Returns:
- whether the new position was applied
-
compareAndSetDisplayPosition
Description copied from interface:DataViewerSet the display position only if the current position is the expected one.See
DataViewer.compareAndSetDisplayPosition(Coords, Coords, boolean)for details.This method will not force a redisplay if
newPositionis the same as the current display position.- Specified by:
compareAndSetDisplayPositionin interfaceDataViewer- Parameters:
oldPosition- Original display positionnewPosition- New display position- Returns:
- ??
-
handleDisplayPosition
-
dispose
protected void dispose()Must be called by implementation to release resources.This is not a "close" method because the
DataViewerinterface may apply to viewers that are not windows (e.g. an embeddable component).This method should be called at an appropriate time to release non-memory resources used by
AbstractDataViewer. -
setDisplayedImageTo
Deprecated.user code should callsetDisplayPositionImplementssetDisplayedImageToby callingsetDisplayPosition.Obsolete equivalent of
DataViewer.setDisplayPosition(Coords).- Specified by:
setDisplayedImageToin interfaceDataViewer- Parameters:
coords- Coords of image to be displayed.
-
getDatastore
Deprecated.user code should callgetDataProviderImplementsgetDatastoreby callinggetDataProvider.- Specified by:
getDatastorein interfaceDataViewer- Returns:
- the datastore backing this viewer, or
nullif this viewer is backed by a data provider that is not a datastore
-
getDataProvider