public class BasicViewerState extends Object implements ViewerState
ViewerState
to
expose query and modification methods. ViewerStateChangeListener
s can
be registered and will be notified about various state changes
.
This class is not thread-safe.
Constructor and Description |
---|
BasicViewerState()
Create an empty state without any sources or groups.
|
BasicViewerState(ViewerState other)
Create a copy of the given
ViewerState (except for (@link
#changeListeners()}, which are not copied). |
Modifier and Type | Method and Description |
---|---|
boolean |
addGroup(SourceGroup group)
Add
group to the state. |
boolean |
addGroups(Collection<? extends SourceGroup> collection)
Add all groups in
collection to the state. |
boolean |
addSource(SourceAndConverter<?> source)
Add
source to the state. |
boolean |
addSources(Collection<? extends SourceAndConverter<?>> collection)
Add all sources in
collection to the state. |
boolean |
addSourcesToGroup(Collection<? extends SourceAndConverter<?>> collection,
SourceGroup group)
Add all sources in
collection to group . |
boolean |
addSourceToGroup(SourceAndConverter<?> source,
SourceGroup group)
Add
source to group . |
org.scijava.listeners.Listeners<ViewerStateChangeListener> |
changeListeners()
ViewerStateChangeListener s can be added/removed here. |
void |
clearGroups()
Remove all groups from the state.
|
void |
clearSources()
Remove all sources from the state.
|
boolean |
containsGroup(SourceGroup group)
Check whether the state contains the
group . |
boolean |
containsSource(SourceAndConverter<?> source)
Check whether the state contains the
source . |
Set<SourceGroup> |
getActiveGroups()
Get the set of active groups.
|
Set<SourceAndConverter<?>> |
getActiveSources()
Get the set of active sources.
|
SourceGroup |
getCurrentGroup()
Get the current group.
|
SourceAndConverter<?> |
getCurrentSource()
Get the current source.
|
int |
getCurrentTimepoint()
Get the current timepoint.
|
DisplayMode |
getDisplayMode()
Get the current
DisplayMode . |
String |
getGroupName(SourceGroup group)
Get the name of a
group . |
List<SourceGroup> |
getGroups()
Get the list of groups.
|
Interpolation |
getInterpolation()
Get the interpolation method.
|
int |
getNumTimepoints()
Get the number of timepoints.
|
List<SourceAndConverter<?>> |
getSources()
Get the list of sources.
|
Set<SourceAndConverter<?>> |
getSourcesInGroup(SourceGroup group)
Get the set sources in
group . |
void |
getViewerTransform(AffineTransform3D t)
Get the viewer transform.
|
Set<SourceAndConverter<?>> |
getVisibleAndPresentSources()
Get the set of visible sources that also provide image data for the
current timepoint.
|
Set<SourceAndConverter<?>> |
getVisibleSources()
Get the set of visible sources.
|
Comparator<SourceGroup> |
groupOrder()
Returns a
Comparator that compares groups according to the order
in which they occur in the groups list. |
boolean |
isCurrentGroup(SourceGroup group)
Returns
true if group is the current group. |
boolean |
isCurrentSource(SourceAndConverter<?> source)
Returns
true if source is the current source. |
boolean |
isGroupActive(SourceGroup group)
Check whether the given
group is active. |
boolean |
isSourceActive(SourceAndConverter<?> source)
Check whether the given
source is active. |
boolean |
isSourceVisible(SourceAndConverter<?> source)
Check whether the given
source is visible. |
boolean |
isSourceVisibleAndPresent(SourceAndConverter<?> source)
Check whether the given
source is both visible and provides image
data for the current timepoint. |
boolean |
removeGroup(SourceGroup group)
Remove
group from the state. |
boolean |
removeGroups(Collection<? extends SourceGroup> collection)
Remove all groups in
collection from the state. |
boolean |
removeSource(SourceAndConverter<?> source)
Remove
source from the state. |
boolean |
removeSourceFromGroup(SourceAndConverter<?> source,
SourceGroup group)
Remove
source from group . |
boolean |
removeSources(Collection<? extends SourceAndConverter<?>> collection)
Remove all sources in
collection from the state. |
boolean |
removeSourcesFromGroup(Collection<? extends SourceAndConverter<?>> collection,
SourceGroup group)
Remove all sources in
collection from group . |
void |
set(ViewerState other)
Set this
ViewerState to other . |
boolean |
setCurrentGroup(SourceGroup group)
Make
group the current group. |
boolean |
setCurrentSource(SourceAndConverter<?> source)
Make
source the current source. |
void |
setCurrentTimepoint(int t)
Set the current timepoint (optional operation).
|
void |
setDisplayMode(DisplayMode mode)
Set the
DisplayMode (optional operation). |
boolean |
setGroupActive(SourceGroup group,
boolean active)
Set
group active or inactive. |
void |
setGroupName(SourceGroup group,
String name)
Set the
name of a group . |
boolean |
setGroupsActive(Collection<? extends SourceGroup> collection,
boolean active)
Set all groups in
collection active or inactive. |
void |
setInterpolation(Interpolation i)
Set the interpolation method (optional operation).
|
void |
setNumTimepoints(int n)
Set the number of timepoints (optional operation).
|
boolean |
setSourceActive(SourceAndConverter<?> source,
boolean active)
Set
source active or inactive. |
boolean |
setSourcesActive(Collection<? extends SourceAndConverter<?>> collection,
boolean active)
Set all sources in
collection active or inactive. |
void |
setViewerTransform(AffineTransform3D t)
Set the viewer transform (optional operation).
|
ViewerState |
snapshot()
Get a snapshot of this ViewerState.
|
Comparator<SourceAndConverter<?>> |
sourceOrder()
Returns a
Comparator that compares sources according to the order
in which they occur in the sources list. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getViewerTransform
public BasicViewerState()
Interpolation.NEARESTNEIGHBOR
. Display mode is
initialized as DisplayMode.SINGLE
.public BasicViewerState(ViewerState other)
ViewerState
(except for (@link
#changeListeners()}, which are not copied).public void set(ViewerState other)
ViewerState
to other
.
No ViewerStateChange
events are fired.public org.scijava.listeners.Listeners<ViewerStateChangeListener> changeListeners()
ViewerStateChangeListener
s can be added/removed here.changeListeners
in interface ViewerState
public ViewerState snapshot()
snapshot
in interface ViewerState
public Interpolation getInterpolation()
ViewerState
getInterpolation
in interface ViewerState
public void setInterpolation(Interpolation i)
ViewerState
setInterpolation
in interface ViewerState
public DisplayMode getDisplayMode()
ViewerState
DisplayMode
.
DisplayMode.SINGLE
only the current source is visible.DisplayMode.GROUP
the sources in the current group are visible.DisplayMode.FUSED
all active sources are visible.DisplayMode.FUSEDROUP
the sources in all active groups are visible.getDisplayMode
in interface ViewerState
public void setDisplayMode(DisplayMode mode)
ViewerState
DisplayMode
(optional operation).setDisplayMode
in interface ViewerState
public int getNumTimepoints()
ViewerState
getNumTimepoints
in interface ViewerState
public void setNumTimepoints(int n)
ViewerState
If ViewerState.getCurrentTimepoint()
current timepoint} is
>= n
, it will be adjusted to n-1
.
setNumTimepoints
in interface ViewerState
public int getCurrentTimepoint()
ViewerState
getCurrentTimepoint
in interface ViewerState
public void setCurrentTimepoint(int t)
ViewerState
setCurrentTimepoint
in interface ViewerState
public void getViewerTransform(AffineTransform3D t)
ViewerState
getViewerTransform
in interface ViewerState
t
- is set to the viewer transformpublic void setViewerTransform(AffineTransform3D t)
ViewerState
setViewerTransform
in interface ViewerState
public List<SourceAndConverter<?>> getSources()
List
reflects changes to
the viewer state. It is unmodifiable and not thread-safe.getSources
in interface ViewerState
public SourceAndConverter<?> getCurrentSource()
null
if there is no current
source)getCurrentSource
in interface ViewerState
public boolean isCurrentSource(SourceAndConverter<?> source)
true
if source
is the current source. Equivalent
to (getCurrentSource() == source)
.isCurrentSource
in interface ViewerState
source
- the source. Passing null
checks whether no source is current.true
if source
is the current sourcepublic boolean setCurrentSource(SourceAndConverter<?> source)
source
the current source. Returns true
, if current
source changes as a result of the call. Returns false
, if
source
is already the current source.setCurrentSource
in interface ViewerState
source
- the source to make current. Passing null
clears the current
source.true
, if current source changed as a result of the callIllegalArgumentException
- if source
is not contained in the state (and not
null
).public Set<SourceAndConverter<?>> getActiveSources()
Set
reflects changes
to the viewer state. It is unmodifiable and not thread-safe.getActiveSources
in interface ViewerState
public boolean isSourceActive(SourceAndConverter<?> source)
source
is active.isSourceActive
in interface ViewerState
true
, if source
is activeNullPointerException
- if source == null
IllegalArgumentException
- if source
is not contained in the state (and not
null
).public boolean setSourceActive(SourceAndConverter<?> source, boolean active)
source
active or inactive.
Returns true
, if source activity changes as a result of the call.
Returns false
, if source
is already in the desired
active
state.
setSourceActive
in interface ViewerState
true
, if source activity changed as a result of the callNullPointerException
- if source == null
IllegalArgumentException
- if source
is not contained in the state (and not
null
).public boolean setSourcesActive(Collection<? extends SourceAndConverter<?>> collection, boolean active)
collection
active or inactive.
Returns true
, if source activity changes as a result of the call.
Returns false
, if all sources were already in the desired
active
state.
setSourcesActive
in interface ViewerState
true
, if source activity changed as a result of the callNullPointerException
- if collection == null
or any element of collection
is
null
.IllegalArgumentException
- if any element of collection
is not contained in the state.public boolean isSourceVisible(SourceAndConverter<?> source)
source
is visible.
Whether a source is visible depends on the display mode
:
DisplayMode.SINGLE
only the current source is visible.DisplayMode.GROUP
the sources in the current group are visible.DisplayMode.FUSED
all active sources are visible.DisplayMode.FUSEDROUP
the sources in all active groups are visible.isSourceVisible
in interface ViewerState
true
, if source
is visibleNullPointerException
- if source == null
IllegalArgumentException
- if source
is not contained in the state (and not
null
).public boolean isSourceVisibleAndPresent(SourceAndConverter<?> source)
source
is both visible and provides image
data for the current timepoint.
Whether a source is visible depends on the display mode
:
DisplayMode.SINGLE
only the current source is visible.DisplayMode.GROUP
the sources in the current group are visible.DisplayMode.FUSED
all active sources are visible.DisplayMode.FUSEDROUP
the sources in all active groups are visible.present
, i.e., provide image data for the current timepoint
.isSourceVisibleAndPresent
in interface ViewerState
true
, if source
is both visible and presentNullPointerException
- if source == null
IllegalArgumentException
- if source
is not contained in the state (and not
null
).public Set<SourceAndConverter<?>> getVisibleSources()
The returned Set
is a copy. Changes to the set will not be
reflected in the viewer state, and vice versa.
Whether a source is visible depends on the display mode
:
DisplayMode.SINGLE
only the current source is visible.DisplayMode.GROUP
the sources in the current group are visible.DisplayMode.FUSED
all active sources are visible.DisplayMode.FUSEDROUP
the sources in all active groups are visible.getVisibleSources
in interface ViewerState
public Set<SourceAndConverter<?>> getVisibleAndPresentSources()
The returned Set
is a copy. Changes to the set will not be
reflected in the viewer state, and vice versa.
Whether a source is visible depends on the display mode
:
DisplayMode.SINGLE
only the current source is visible.DisplayMode.GROUP
the sources in the current group are visible.DisplayMode.FUSED
all active sources are visible.DisplayMode.FUSEDROUP
the sources in all active groups are visible.present
, i.e., provide image data for the current timepoint
.getVisibleAndPresentSources
in interface ViewerState
public boolean containsSource(SourceAndConverter<?> source)
source
.containsSource
in interface ViewerState
true
, if source
is in the list of sources.NullPointerException
- if source == null
public boolean addSource(SourceAndConverter<?> source)
source
to the state. Returns true
, if the source is
added. Returns false
, if the source is already present.
If source
is added and no other source was current, then
source
is made current
addSource
in interface ViewerState
true
, if list of sources changed as a result of the call.NullPointerException
- if source == null
public boolean addSources(Collection<? extends SourceAndConverter<?>> collection)
collection
to the state. Returns true
,
if at least one source was added. Returns false
, if all sources
were already present.
If any sources are added and no other source was current, then the first added sources will be made current.
addSources
in interface ViewerState
true
, if list of sources changed as a result of the call.NullPointerException
- if collection == null
or any element of collection
is
null
.public boolean removeSource(SourceAndConverter<?> source)
source
from the state.
Returns true
, if source
was removed from the state.
Returns false
, if source
was not contained in state.
The source
is also removed from any groups that contained it. If
source
was current, then the first source in the list of sources
is made current (if it exists).
removeSource
in interface ViewerState
true
, if list of sources changed as a result of the callNullPointerException
- if source == null
public boolean removeSources(Collection<? extends SourceAndConverter<?>> collection)
collection
from the state. Returns
true
, if at least one source was removed. Returns false
,
if none of the sources was present.
Removed sources are also removed from any groups containing them. If the current source was removed, then the first source in the remaining list of sources is made current (if it exists).
removeSources
in interface ViewerState
true
, if list of sources changed as a result of the call.NullPointerException
- if collection == null
or any element of collection
is
null
.public void clearSources()
clearSources
in interface ViewerState
public Comparator<SourceAndConverter<?>> sourceOrder()
Comparator
that compares sources according to the order
in which they occur in the sources list. (Sources that do not occur in
the list are ordered before any source in the list).sourceOrder
in interface ViewerState
public List<SourceGroup> getGroups()
List
reflects changes to the
viewer state. It is unmodifiable and not thread-safe.getGroups
in interface ViewerState
public SourceGroup getCurrentGroup()
null
if there is no current
group)getCurrentGroup
in interface ViewerState
public boolean isCurrentGroup(SourceGroup group)
true
if group
is the current group. Equivalent to
(getCurrentGroup() == group)
.isCurrentGroup
in interface ViewerState
true
if group
is the current grouppublic boolean setCurrentGroup(SourceGroup group)
group
the current group. Returns true
, if current
group changes as a result of the call. Returns false
, if
group
is already the current group.setCurrentGroup
in interface ViewerState
group
- the group to make currenttrue
, if current group changed as a result of the call.IllegalArgumentException
- if group
is not contained in the state (and not
null
).public Set<SourceGroup> getActiveGroups()
Set
reflects changes
to the viewer state. It is unmodifiable and not thread-safe.getActiveGroups
in interface ViewerState
public boolean isGroupActive(SourceGroup group)
group
is active.isGroupActive
in interface ViewerState
true
, if group
is activeNullPointerException
- if group == null
IllegalArgumentException
- if group
is not contained in the state (and not
null
).public boolean setGroupActive(SourceGroup group, boolean active)
group
active or inactive.
Returns true
, if group activity changes as a result of the call.
Returns false
, if group
is already in the desired
active
state.
setGroupActive
in interface ViewerState
true
, if group activity changed as a result of the callNullPointerException
- if group == null
IllegalArgumentException
- if group
is not contained in the state (and not
null
).public boolean setGroupsActive(Collection<? extends SourceGroup> collection, boolean active)
collection
active or inactive.
Returns true
, if group activity changes as a result of the call.
Returns false
, if all groups were already in the desired
active
state.
setGroupsActive
in interface ViewerState
true
, if group activity changed as a result of the callNullPointerException
- if collection == null
or any element of collection
is
null
.IllegalArgumentException
- if any element of collection
is not contained in the state.public String getGroupName(SourceGroup group)
group
.getGroupName
in interface ViewerState
null
NullPointerException
- if group == null
IllegalArgumentException
- if group
is not contained in the state (and not
null
).public void setGroupName(SourceGroup group, String name)
name
of a group
.setGroupName
in interface ViewerState
NullPointerException
- if group == null
IllegalArgumentException
- if group
is not contained in the state (and not
null
).public boolean containsGroup(SourceGroup group)
group
.containsGroup
in interface ViewerState
true
, if group
is in the list of groups.NullPointerException
- if group == null
public boolean addGroup(SourceGroup group)
group
to the state. Returns true
, if the group is
added. Returns false
, if the group is already present.
If group
is added and no other group was current, then
group
is made current
addGroup
in interface ViewerState
true
, if list of groups changed as a result of the call.NullPointerException
- if group == null
public boolean addGroups(Collection<? extends SourceGroup> collection)
collection
to the state. Returns true
,
if at least one group was added. Returns false
, if all groups
were already present.
If any groups are added and no other group was current, then the first added groups will be made current.
addGroups
in interface ViewerState
true
, if list of groups changed as a result of the call.NullPointerException
- if collection == null
or any element of collection
is
null
.public boolean removeGroup(SourceGroup group)
group
from the state.
Returns true
, if group
was removed from the state.
Returns false
, if group
was not contained in state.
If group
was current, then the first group in the list of groups
is made current (if it exists).
removeGroup
in interface ViewerState
true
, if list of groups changed as a result of the callNullPointerException
- if group == null
public boolean removeGroups(Collection<? extends SourceGroup> collection)
collection
from the state. Returns
true
, if at least one group was removed. Returns false
,
if none of the groups was present.
If the current group was removed, then the first group in the remaining list of groups is made current (if it exists).
removeGroups
in interface ViewerState
true
, if list of groups changed as a result of the call.NullPointerException
- if collection == null
or any element of collection
is
null
.public boolean addSourceToGroup(SourceAndConverter<?> source, SourceGroup group)
source
to group
.
Returns true
, if source
was added to group
.
Returns false
, if source
was already contained in
group
. or either of source
and group
is not valid
(not in the BDV sources/groups list).
addSourceToGroup
in interface ViewerState
true
, if set of sources in group
changed as a
result of the callNullPointerException
- if source == null
or group == null
IllegalArgumentException
- if either of source
and group
is not contained in the
state (and not null
).public boolean addSourcesToGroup(Collection<? extends SourceAndConverter<?>> collection, SourceGroup group)
collection
to group
.
Returns true
, if at least one source was added to group
.
Returns false
, if all sources were already contained in
group
.
addSourcesToGroup
in interface ViewerState
true
, if set of sources in group
changed as a
result of the callNullPointerException
- if group == null
or collection == null
or any element
of collection
is null
.IllegalArgumentException
- if group
or any element of collection
is is not
contained in the state (and not null
).public boolean removeSourceFromGroup(SourceAndConverter<?> source, SourceGroup group)
source
from group
.
Returns true
, if source
was removed from group
.
Returns false
, if source
was not contained in
group
,
removeSourceFromGroup
in interface ViewerState
true
, if set of sources in group
changed as a
result of the callNullPointerException
- if source == null
or group == null
IllegalArgumentException
- if either of source
and group
is not contained in the
state (and not null
).public boolean removeSourcesFromGroup(Collection<? extends SourceAndConverter<?>> collection, SourceGroup group)
collection
from group
.
Returns true
, if at least one source was removed from
group
. Returns false
, if none of the sources were
contained in group
.
removeSourcesFromGroup
in interface ViewerState
true
, if set of sources in group
changed as a
result of the callNullPointerException
- if group == null
or collection == null
or any element
of collection
is null
.IllegalArgumentException
- if group
or any element of collection
is is not
contained in the state (and not null
).public Set<SourceAndConverter<?>> getSourcesInGroup(SourceGroup group)
group
. The returned Set
reflects
changes to the viewer state. It is unmodifiable and not thread-safe.getSourcesInGroup
in interface ViewerState
group
NullPointerException
- if group == null
IllegalArgumentException
- if group
is not contained in the state (and not
null
).public void clearGroups()
clearGroups
in interface ViewerState
public Comparator<SourceGroup> groupOrder()
Comparator
that compares groups according to the order
in which they occur in the groups list. (Groups that do not occur in the
list are ordered before any group in the list).groupOrder
in interface ViewerState
Copyright © 2015–2021 Fiji. All rights reserved.