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

Remove synchronization on ViewerState from SourceGroup.

This needs to be done differently. No synchronization for now.
parent 169947b4
Branches
Tags
No related merge requests found
......@@ -258,7 +258,7 @@ public class ViewerPanel extends JPanel implements OverlayRenderer, TransformLis
final int numGroups = 10;
final ArrayList< SourceGroup > groups = new ArrayList<>( numGroups );
for ( int i = 0; i < numGroups; ++i )
groups.add( new SourceGroup( "group " + Integer.toString( i + 1 ), null ) );
groups.add( new SourceGroup( "group " + Integer.toString( i + 1 ) ) );
state = new ViewerState( sources, groups, numTimepoints );
for ( int i = Math.min( numGroups, sources.size() ) - 1; i >= 0; --i )
state.getSourceGroups().get( i ).addSource( i );
......
......@@ -41,8 +41,6 @@ import bdv.viewer.DisplayMode;
*/
public class SourceGroup
{
final ViewerState owner;
protected final TreeSet< Integer > sourceIds;
protected String name;
......@@ -58,43 +56,35 @@ public class SourceGroup
*/
protected boolean isCurrent;
public SourceGroup( final String name, final ViewerState owner )
public SourceGroup( final String name )
{
this.owner = owner;
sourceIds = new TreeSet<>();
this.name = name;
isActive = true;
isCurrent = false;
}
public SourceGroup( final SourceGroup g, final ViewerState owner )
protected SourceGroup( final SourceGroup g )
{
this.owner = owner;
sourceIds = new TreeSet<>( g.sourceIds );
name = g.name;
isActive = g.isActive;
isCurrent = g.isCurrent;
}
public SourceGroup copy( final ViewerState owner )
public SourceGroup copy()
{
return new SourceGroup( this, owner );
return new SourceGroup( this );
}
public void addSource( final int sourceId )
{
synchronized ( owner )
{
sourceIds.add( sourceId );
}
sourceIds.add( sourceId );
}
public void removeSource( final int sourceId )
{
synchronized ( owner )
{
sourceIds.remove( sourceId );
}
sourceIds.remove( sourceId );
}
public SortedSet< Integer > getSourceIds()
......@@ -127,10 +117,7 @@ public class SourceGroup
*/
public void setActive( final boolean isActive )
{
synchronized ( owner )
{
this.isActive = isActive;
}
this.isActive = isActive;
}
/**
......@@ -148,10 +135,6 @@ public class SourceGroup
*/
public void setCurrent( final boolean isCurrent )
{
synchronized ( owner )
{
this.isCurrent = isCurrent;
}
this.isCurrent = isCurrent;
}
}
......@@ -113,6 +113,11 @@ public class ViewerState
*/
private int currentTimepoint;
public ViewerState( final List< SourceAndConverter< ? > > sources, final int numTimePoints )
{
this( sources, null, numTimePoints );
}
/**
*
* @param sources
......@@ -126,9 +131,7 @@ public class ViewerState
for ( final SourceAndConverter< ? > source : sources )
this.sources.add( SourceState.create( source, this ) );
unmodifiableSources = Collections.unmodifiableList( this.sources );
groups = new ArrayList<>( sourceGroups.size() );
for ( final SourceGroup g : sourceGroups )
groups.add( g.copy( this ) );
groups = ( sourceGroups == null ) ? new ArrayList<>() : new ArrayList<>( sourceGroups );
unmodifiableGroups = Collections.unmodifiableList( this.groups );
this.numTimepoints = numTimePoints;
......@@ -152,7 +155,7 @@ public class ViewerState
unmodifiableSources = Collections.unmodifiableList( sources );
groups = new ArrayList<>( s.groups.size() );
for ( final SourceGroup group : s.groups )
this.groups.add( group.copy( this ) );
groups.add( group.copy() );
unmodifiableGroups = Collections.unmodifiableList( groups );
numTimepoints = s.numTimepoints;
viewerTransform = s.viewerTransform.copy();
......@@ -453,23 +456,19 @@ public class ViewerState
public synchronized void addGroup( final SourceGroup group )
{
if ( group.owner == this )
if ( !groups.contains( group ) )
{
groups.add( group );
else
groups.add( group.copy( this ) );
if ( currentGroup < 0 )
currentGroup = 0;
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++;
}
final int i = groups.indexOf( group );
if ( i >= 0 )
removeGroup( i );
}
protected void removeGroup( final int index )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment