Skip to content
Snippets Groups Projects
Commit e3f50fbc authored by Tobias Pietzsch's avatar Tobias Pietzsch
Browse files

ViewerPanel.add/removeGroup() methods

parent d6888704
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ import static bdv.viewer.VisibilityAndGrouping.Event.CURRENT_SOURCE_CHANGED; ...@@ -33,6 +33,7 @@ import static bdv.viewer.VisibilityAndGrouping.Event.CURRENT_SOURCE_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.DISPLAY_MODE_CHANGED; import static bdv.viewer.VisibilityAndGrouping.Event.DISPLAY_MODE_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.GROUP_ACTIVITY_CHANGED; import static bdv.viewer.VisibilityAndGrouping.Event.GROUP_ACTIVITY_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.GROUP_NAME_CHANGED; import static bdv.viewer.VisibilityAndGrouping.Event.GROUP_NAME_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.NUM_GROUPS_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.NUM_SOURCES_CHANGED; import static bdv.viewer.VisibilityAndGrouping.Event.NUM_SOURCES_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.SOURCE_ACTVITY_CHANGED; import static bdv.viewer.VisibilityAndGrouping.Event.SOURCE_ACTVITY_CHANGED;
import static bdv.viewer.VisibilityAndGrouping.Event.VISIBILITY_CHANGED; import static bdv.viewer.VisibilityAndGrouping.Event.VISIBILITY_CHANGED;
...@@ -358,6 +359,26 @@ public class ViewerPanel extends JPanel implements OverlayRenderer, TransformLis ...@@ -358,6 +359,26 @@ public class ViewerPanel extends JPanel implements OverlayRenderer, TransformLis
requestRepaint(); requestRepaint();
} }
public void addGroup( final SourceGroup group )
{
synchronized ( visibilityAndGrouping )
{
state.addGroup( group );
visibilityAndGrouping.update( NUM_GROUPS_CHANGED );
}
requestRepaint();
}
public void removeGroup( final SourceGroup group )
{
synchronized ( visibilityAndGrouping )
{
state.removeGroup( group );
visibilityAndGrouping.update( NUM_GROUPS_CHANGED );
}
requestRepaint();
}
/** /**
* Set {@code gPos} to the display coordinates at gPos transformed into the * Set {@code gPos} to the display coordinates at gPos transformed into the
* global coordinate system. * global coordinate system.
......
...@@ -80,6 +80,8 @@ public class VisibilityAndGrouping ...@@ -80,6 +80,8 @@ public class VisibilityAndGrouping
public static final int NUM_SOURCES_CHANGED = 8; public static final int NUM_SOURCES_CHANGED = 8;
public static final int NUM_GROUPS_CHANGED = 9;
public final int id; public final int id;
public final VisibilityAndGrouping visibilityAndGrouping; public final VisibilityAndGrouping visibilityAndGrouping;
......
...@@ -136,7 +136,7 @@ public class ViewerState ...@@ -136,7 +136,7 @@ public class ViewerState
interpolation = NEARESTNEIGHBOR; interpolation = NEARESTNEIGHBOR;
displayMode = SINGLE; displayMode = SINGLE;
currentSource = sources.isEmpty() ? -1 : 0; currentSource = sources.isEmpty() ? -1 : 0;
currentGroup = 0; currentGroup = groups.isEmpty() ? -1 : 0;
currentTimepoint = 0; currentTimepoint = 0;
} }
...@@ -247,6 +247,16 @@ public class ViewerState ...@@ -247,6 +247,16 @@ public class ViewerState
} }
} }
/**
* Make the given group current.
*/
public synchronized void setCurrentGroup( final SourceGroup group )
{
final int i = getGroupIndex( group );
if ( i >= 0 )
setCurrentGroup( i );
}
/** /**
* Get the interpolation method. * Get the interpolation method.
* *
...@@ -441,6 +451,38 @@ public class ViewerState ...@@ -441,6 +451,38 @@ public class ViewerState
} }
} }
public synchronized void addGroup( final SourceGroup group )
{
if ( group.owner == this )
groups.add( group );
else
groups.add( group.copy( this ) );
if ( currentGroup < 0 )
currentGroup = 0;
}
public synchronized void removeGroup( final SourceGroup group )
{
for ( int i = 0; i < groups.size(); )
{
if ( groups.get( i ) == group )
removeGroup( i );
else
i++;
}
}
protected void removeGroup( final int index )
{
groups.remove( index );
if ( groups.isEmpty() )
currentGroup = -1;
else if ( currentGroup == index )
currentGroup = 0;
else if ( currentGroup > index )
--currentGroup;
}
public synchronized boolean isSourceVisible( final int index ) public synchronized boolean isSourceVisible( final int index )
{ {
switch ( displayMode ) switch ( displayMode )
...@@ -573,4 +615,13 @@ public class ViewerState ...@@ -573,4 +615,13 @@ public class ViewerState
} }
return -1; return -1;
} }
/**
* Get index of (first) {@link SourceGroup} that matches the given
* {@code group} or {@code -1} if not found.
*/
private int getGroupIndex( final SourceGroup group )
{
return groups.indexOf( group );
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment