1
1
package bdv .fx .viewer ;
2
2
3
+ import java .util .ArrayList ;
4
+ import java .util .Collection ;
3
5
import java .util .Collections ;
4
- import java .util .HashMap ;
5
6
import java .util .List ;
6
- import java .util .Map ;
7
7
import java .util .function .Function ;
8
- import java .util .stream .Collectors ;
8
+
9
+ import org .janelia .saalfeldlab .fx .ObservableWithListenersList ;
10
+ import org .janelia .saalfeldlab .paintera .data .axisorder .AxisOrder ;
9
11
10
12
import bdv .util .MipmapTransforms ;
11
13
import bdv .viewer .Source ;
12
14
import bdv .viewer .SourceAndConverter ;
13
- import javafx .beans .property .IntegerProperty ;
14
- import javafx .beans .property .ReadOnlyIntegerProperty ;
15
- import javafx .beans .property .SimpleIntegerProperty ;
16
- import javafx .collections .FXCollections ;
17
- import javafx .collections .ListChangeListener ;
18
- import javafx .collections .ObservableList ;
19
- import javafx .collections .ObservableMap ;
20
15
import net .imglib2 .realtransform .AffineTransform3D ;
21
- import org .janelia .saalfeldlab .paintera .data .axisorder .AxisOrder ;
22
16
23
- public class ViewerState
17
+ public class ViewerState extends ObservableWithListenersList
24
18
{
25
19
26
20
private final AffineTransform3D viewerTransform = new AffineTransform3D ();
27
21
28
- protected final IntegerProperty timepoint = new SimpleIntegerProperty ( 0 );
22
+ private final List < SourceAndConverter <?>> sourcesAndConverters = new ArrayList <>( );
29
23
30
- protected final IntegerProperty numTimepoints = new SimpleIntegerProperty ( 1 ) ;
24
+ private final Function < Source <?>, AxisOrder > axisOrder ;
31
25
32
- protected final ObservableList < SourceAndConverter <?>> sourcesAndConverters = FXCollections . observableArrayList () ;
26
+ private final int numTimepoints ;
33
27
34
- private final Function < Source <?>, AxisOrder > axisOrder ;
28
+ private int timepoint ;
35
29
36
- protected final ObservableMap <Source <?>, SourceAndConverter <?>> sources = asMap (
37
- sourcesAndConverters ,
38
- SourceAndConverter ::getSpimSource
39
- );
30
+ public ViewerState (final Function <Source <?>, AxisOrder > axisOrder , final int numTimepoints )
31
+ {
32
+ this .axisOrder = axisOrder ;
33
+ this .numTimepoints = numTimepoints ;
34
+ }
40
35
41
- protected synchronized void setViewerTransform (final AffineTransform3D to )
36
+ protected void setViewerTransform (final AffineTransform3D to )
42
37
{
43
- this .viewerTransform .set (to );
38
+ synchronized (this )
39
+ {
40
+ this .viewerTransform .set (to );
41
+ }
42
+ stateChanged ();
44
43
}
45
44
46
45
public synchronized void getViewerTransform (final AffineTransform3D to )
47
46
{
48
47
to .set (this .viewerTransform );
49
48
}
50
49
51
- public ReadOnlyIntegerProperty timepointProperty ()
50
+ public void setTimepoint (final int timepoint )
51
+ {
52
+ synchronized (this )
53
+ {
54
+ this .timepoint = timepoint ;
55
+ }
56
+ stateChanged ();
57
+ }
58
+
59
+ public synchronized int getTimepoint ()
52
60
{
53
61
return this .timepoint ;
54
62
}
55
63
56
- public List <SourceAndConverter <?>> getSources ()
64
+ public synchronized List <SourceAndConverter <?>> getSources ()
57
65
{
58
66
return Collections .unmodifiableList (sourcesAndConverters );
59
67
}
60
68
69
+ public void setSources (final Collection <? extends SourceAndConverter <?>> newSources )
70
+ {
71
+ synchronized (this )
72
+ {
73
+ this .sourcesAndConverters .clear ();
74
+ this .sourcesAndConverters .addAll (newSources );
75
+ }
76
+ stateChanged ();
77
+ }
78
+
61
79
public synchronized int getBestMipMapLevel (final AffineTransform3D screenScaleTransform , final Source <?> source ,
62
80
final int timepoint )
63
81
{
@@ -70,54 +88,25 @@ public synchronized int getBestMipMapLevel(final AffineTransform3D screenScaleTr
70
88
71
89
public synchronized int getBestMipMapLevel (final AffineTransform3D screenScaleTransform , final Source <?> source )
72
90
{
73
- return getBestMipMapLevel (screenScaleTransform , source , timepoint . get () );
91
+ return getBestMipMapLevel (screenScaleTransform , source , timepoint );
74
92
}
75
93
76
94
public synchronized int getBestMipMapLevel (final AffineTransform3D screenScaleTransform , final int sourceIndex )
77
95
{
78
96
return getBestMipMapLevel (screenScaleTransform , sourcesAndConverters .get (sourceIndex ).getSpimSource ());
79
97
}
80
98
81
- public ViewerState (final Function <Source <?>, AxisOrder > axisOrder )
82
- {
83
- this .axisOrder = axisOrder ;
84
- }
85
-
86
99
public synchronized ViewerState copy ()
87
100
{
88
- final ViewerState state = new ViewerState (this .axisOrder );
89
- state .viewerTransform .set (viewerTransform );
90
- state .timepoint .set (timepoint .get ());
91
- state .numTimepoints .set (numTimepoints .get ());
92
- state .sourcesAndConverters .setAll (sourcesAndConverters );
101
+ final ViewerState state = new ViewerState (this .axisOrder , this .numTimepoints );
102
+ state .setViewerTransform (this .viewerTransform );
103
+ state .setTimepoint (this .timepoint );
104
+ state .setSources (this .sourcesAndConverters );
93
105
return state ;
94
106
}
95
107
96
- public static <S , T > ObservableList <T > mapObservableList (final ObservableList <? extends S > source , final
97
- Function <S , T > mapping )
98
- {
99
- final ObservableList <T > target = FXCollections .observableArrayList ();
100
- source .addListener ((ListChangeListener <? super S >) change -> target .setAll (source .stream ().map (mapping )
101
- .collect (
102
- Collectors .toList ())));
103
- return target ;
104
- }
105
-
106
- public static <S , T > ObservableMap <T , S > asMap (final ObservableList <? extends S > source , final Function <S , T >
107
- generateKeyFromValue )
108
- {
109
- final ObservableMap <T , S > target = FXCollections .observableHashMap ();
110
- source .addListener ((ListChangeListener <? super S >) change -> {
111
- final Map <T , S > tmp = new HashMap <>();
112
- source .forEach (s -> tmp .put (generateKeyFromValue .apply (s ), s ));
113
- target .putAll (tmp );
114
- });
115
- return target ;
116
- }
117
-
118
- public AxisOrder axisOrder (final Source <?> source )
108
+ public synchronized AxisOrder axisOrder (final Source <?> source )
119
109
{
120
110
return this .axisOrder .apply (source );
121
111
}
122
-
123
112
}
0 commit comments