Skip to content

Commit 7708d2f

Browse files
Merge pull request #368 from stefanhahmann/access-grapher-context-chooser
Access grapher context chooser in GrapherSidePanel from outside
2 parents 876c975 + 33df8e0 commit 7708d2f

10 files changed

Lines changed: 103 additions & 100 deletions

src/main/java/org/mastodon/mamut/views/grapher/DataDisplayFrameSupplier.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/main/java/org/mastodon/mamut/views/grapher/GrapherGuiState.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,10 +38,11 @@
3838
import org.mastodon.model.HasLabel;
3939
import org.mastodon.spatial.HasTimepoint;
4040
import org.mastodon.views.grapher.datagraph.ScreenTransform;
41-
import org.mastodon.views.grapher.display.DataDisplayFrame;
4241
import org.mastodon.views.grapher.display.FeatureGraphConfig;
4342
import org.mastodon.views.grapher.display.FeatureSpecPair;
4443
import org.mastodon.views.grapher.display.GrapherSidePanel;
44+
import org.mastodon.views.grapher.display.Plotable;
45+
import org.mastodon.views.grapher.display.ScreenTransformState;
4546

4647
public class GrapherGuiState
4748
{
@@ -100,40 +101,39 @@ private GrapherGuiState()
100101
*/
101102
public static final String GRAPHER_SHOW_EDGES_KEY = "GrapherShowEdges";
102103

103-
static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > void
104-
writeGuiState( final DataDisplayFrameSupplier< V, E > frameProvider, final Map< String, Object > guiState )
104+
public static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > void
105+
writeGuiState( final ScreenTransformState screenTransformState, final FeatureGraphConfig config,
106+
final Map< String, Object > guiState )
105107
{
106-
DataDisplayFrame< V, E > frame = frameProvider.getFrame();
107108
// Transform.
108-
final ScreenTransform transform = frame.getDataDisplayPanel().getScreenTransform().get();
109+
final ScreenTransform transform = screenTransformState.get();
109110
guiState.put( GRAPHER_TRANSFORM_KEY, transform );
110111
// Feature graph config.
111-
writeFeatureGraphConfig( frame, guiState );
112+
writeFeatureGraphConfig( config, guiState );
112113
}
113114

114-
static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > void
115-
loadGuiState( final DataDisplayFrameSupplier< V, E > frameSupplier, final Map< String, Object > guiState,
116-
final FeatureGraphConfig defaultConfig )
115+
public static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > void
116+
loadGuiState( final Map< String, Object > guiState, final ScreenTransformState screenTransformState,
117+
final GrapherSidePanel<V, E> sidePanel, final FeatureGraphConfig defaultConfig,
118+
final Plotable plotable )
117119
{
118-
DataDisplayFrame< V, E > frame = frameSupplier.getFrame();
119-
120120
// Read Screen Transform.
121121
final ScreenTransform screenTransform = ( ScreenTransform ) guiState.get( GRAPHER_TRANSFORM_KEY );
122122
if ( null != screenTransform )
123-
frame.getDataDisplayPanel().getScreenTransform().set( screenTransform );
123+
screenTransformState.set( screenTransform );
124124

125125
// Read Feature graph config.
126-
FeatureGraphConfig config = loadFeatureGraphConfig( frame, guiState, defaultConfig );
127-
frame.getVertexSidePanel().setGraphConfig( config );
126+
FeatureGraphConfig config = loadFeatureGraphConfig( sidePanel, guiState, defaultConfig );
127+
sidePanel.setGraphConfig( config );
128128

129129
// Plot with loaded transform and config.
130-
frame.plot( screenTransform );
130+
if ( plotable != null )
131+
plotable.plot( screenTransform );
131132
}
132133

133134
private static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > void
134-
writeFeatureGraphConfig( final DataDisplayFrame< V, E > frame, final Map< String, Object > guiState )
135+
writeFeatureGraphConfig( final FeatureGraphConfig config, final Map< String, Object > guiState )
135136
{
136-
FeatureGraphConfig config = frame.getVertexSidePanel().getGraphConfig();
137137
// X-axis feature.
138138
FeatureSpecPair featureSpecPairX = config.getXFeature();
139139
guiState.put( GRAPHER_X_AXIS_FEATURE_IS_EDGE_KEY, featureSpecPairX.isEdgeFeature() );
@@ -150,11 +150,12 @@ private GrapherGuiState()
150150
guiState.put( GRAPHER_SHOW_EDGES_KEY, config.drawConnected() );
151151
}
152152

153-
private static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > FeatureGraphConfig
154-
loadFeatureGraphConfig( final DataDisplayFrame< V, E > frame, final Map< String, Object > guiState,
155-
final FeatureGraphConfig defaultConfig )
153+
public static < V extends Vertex< E > & HasTimepoint & HasLabel & Ref< V >, E extends Edge< V > & Ref< E > > FeatureGraphConfig
154+
loadFeatureGraphConfig(
155+
final GrapherSidePanel<V, E> sidePanel, final Map< String, Object > guiState,
156+
final FeatureGraphConfig defaultConfig
157+
)
156158
{
157-
GrapherSidePanel sidePanel = frame.getVertexSidePanel();
158159
FeatureSpecPair featureSpecPairX = loadFeatureSpecPair( guiState, sidePanel, GRAPHER_X_AXIS_FEATURE_IS_EDGE_KEY,
159160
GRAPHER_X_AXIS_FEATURE_SPEC_KEY, GRAPHER_X_AXIS_FEATURE_PROJECTION_KEY, GRAPHER_X_AXIS_INCOMING_EDGE_KEY );
160161
FeatureSpecPair featureSpecPairY = loadFeatureSpecPair( guiState, sidePanel, GRAPHER_Y_AXIS_FEATURE_IS_EDGE_KEY,
@@ -165,7 +166,7 @@ private GrapherGuiState()
165166
return new FeatureGraphConfig( featureSpecPairX, featureSpecPairY, FeatureGraphConfig.GraphDataItemsSource.CONTEXT, showEdges );
166167
}
167168

168-
private static FeatureSpecPair loadFeatureSpecPair( final Map< String, Object > guiState, final GrapherSidePanel sidePanel,
169+
private static < V extends Vertex< E >, E extends Edge< V > > FeatureSpecPair loadFeatureSpecPair( final Map< String, Object > guiState, final GrapherSidePanel<V, E> sidePanel,
169170
final String edgeKey, final String featureSpecKey, final String projectionKey, final String incomingEdgeKey )
170171
{
171172
Boolean isEdgeFeature = ( Boolean ) guiState.get( edgeKey );

src/main/java/org/mastodon/mamut/views/grapher/GrapherInitializer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.mastodon.ui.coloring.ColorBarOverlay;
7272
import org.mastodon.ui.coloring.ColoringModel;
7373
import org.mastodon.ui.coloring.GraphColorGeneratorAdapter;
74+
import org.mastodon.ui.commandfinder.CommandFinder;
7475
import org.mastodon.views.context.ContextChooser;
7576
import org.mastodon.views.grapher.datagraph.DataContextListener;
7677
import org.mastodon.views.grapher.datagraph.DataEdge;
@@ -275,6 +276,23 @@ void addSearchPanel( final Actions viewActions )
275276
frame.getSettingsPanel().add( searchPanel );
276277
}
277278

279+
void addCommandFinder(final Actions viewActions, final String[] keyConfigContexts)
280+
{
281+
final CommandFinder cf = CommandFinder.build()
282+
.context( appModel.getContext() )
283+
.inputTriggerConfig( appModel.getKeymap().getConfig() )
284+
.keyConfigContexts( keyConfigContexts )
285+
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
286+
.register( viewActions )
287+
.register( appModel.getModelActions() )
288+
.register( appModel.getProjectActions() )
289+
.register( appModel.getPlugins().getPluginActions() )
290+
.modificationListeners( appModel.getKeymap().updateListeners() )
291+
.parent( frame )
292+
.installOn( viewActions );
293+
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );
294+
}
295+
278296
private void
279297
registerColoring(
280298
final TriFunction< ViewMenuBuilder.JMenuHandle, GraphColorGeneratorAdapter< V, E, DataVertex, DataEdge >,

src/main/java/org/mastodon/mamut/views/grapher/MamutBranchViewGrapher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import java.util.function.BiConsumer;
5858

5959
public class MamutBranchViewGrapher extends MamutBranchView< DataGraph< BranchSpot, BranchLink >, DataVertex, DataEdge >
60-
implements HasColoringModel, HasColorBarOverlay, DataDisplayFrameSupplier< BranchSpot, BranchLink >
60+
implements HasColoringModel, HasColorBarOverlay
6161
{
6262

6363
private final GrapherInitializer< BranchSpot, BranchLink > grapherInitializer;
@@ -82,6 +82,7 @@ public class MamutBranchViewGrapher extends MamutBranchView< DataGraph< BranchSp
8282
setFrame( grapherInitializer.getFrame() ); // this creates viewActions and viewBehaviours thus must be called before installActions
8383
grapherInitializer.installActions( viewActions, viewBehaviours );
8484
grapherInitializer.addSearchPanel( viewActions );
85+
grapherInitializer.addCommandFinder( viewActions, keyConfigContexts );
8586

8687
TriFunction< JMenuHandle, GraphColorGeneratorAdapter< BranchSpot, BranchLink, DataVertex, DataEdge >,
8788
DataDisplayPanel< BranchSpot, BranchLink >, ColoringModel > colorModelRegistration =

src/main/java/org/mastodon/mamut/views/grapher/MamutBranchViewGrapherFactory.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -31,8 +31,11 @@
3131
import java.util.Map;
3232

3333
import org.mastodon.mamut.ProjectModel;
34+
import org.mastodon.mamut.model.branch.BranchLink;
35+
import org.mastodon.mamut.model.branch.BranchSpot;
3436
import org.mastodon.mamut.views.AbstractMamutViewFactory;
3537
import org.mastodon.mamut.views.MamutViewFactory;
38+
import org.mastodon.views.grapher.display.DataDisplayFrame;
3639
import org.scijava.Priority;
3740
import org.scijava.plugin.Plugin;
3841

@@ -51,15 +54,19 @@ public MamutBranchViewGrapher create( final ProjectModel projectModel )
5154
public Map< String, Object > getGuiState( final MamutBranchViewGrapher view )
5255
{
5356
final Map< String, Object > guiState = super.getGuiState( view );
54-
GrapherGuiState.writeGuiState( view, guiState );
57+
DataDisplayFrame< BranchSpot, BranchLink > frame = view.getFrame();
58+
GrapherGuiState.writeGuiState( frame.getDataDisplayPanel().getScreenTransform(), frame.getVertexSidePanel().getGraphConfig(),
59+
guiState );
5560
return guiState;
5661
}
5762

5863
@Override
5964
public void restoreGuiState( final MamutBranchViewGrapher view, final Map< String, Object > guiState )
6065
{
6166
super.restoreGuiState( view, guiState );
62-
GrapherGuiState.loadGuiState( view, guiState, MamutBranchViewGrapher.getFeatureGraphConfig() );
67+
DataDisplayFrame< BranchSpot, BranchLink > frame = view.getFrame();
68+
GrapherGuiState.loadGuiState( guiState, frame.getDataDisplayPanel().getScreenTransform(), frame.getVertexSidePanel(),
69+
MamutBranchViewGrapher.getFeatureGraphConfig(), view.getFrame() );
6370
}
6471

6572
@Override

src/main/java/org/mastodon/mamut/views/grapher/MamutViewGrapher.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
import net.imglib2.loops.LoopBuilder;
6060

6161
public class MamutViewGrapher extends MamutView< DataGraph< Spot, Link >, DataVertex, DataEdge >
62-
implements HasContextChooser< Spot >, HasColoringModel, HasColorBarOverlay, DataDisplayFrameSupplier< Spot, Link >
62+
implements HasContextChooser< Spot >, HasColoringModel, HasColorBarOverlay
6363
{
6464

6565
private final GrapherInitializer< Spot, Link > grapherInitializer;
@@ -83,6 +83,7 @@ public class MamutViewGrapher extends MamutView< DataGraph< Spot, Link >, DataVe
8383
setFrame( grapherInitializer.getFrame() ); // this creates viewActions and viewBehaviours thus must be called before installActions
8484
grapherInitializer.installActions( viewActions, viewBehaviours );
8585
grapherInitializer.addSearchPanel( viewActions );
86+
grapherInitializer.addCommandFinder( viewActions, keyConfigContexts );
8687

8788
final TriFunction< ViewMenuBuilder.JMenuHandle, GraphColorGeneratorAdapter< Spot, Link, DataVertex, DataEdge >,
8889
DataDisplayPanel< Spot, Link >, ColoringModel > colorModelRegistration = ( menuHandle, coloringAdaptor,
@@ -95,20 +96,6 @@ public class MamutViewGrapher extends MamutView< DataGraph< Spot, Link >, DataVe
9596
grapherInitializer.addMenusAndRegisterColors( colorModelRegistration, colorBarRegistration, tagSetMenuRegistration,
9697
keyConfigContexts );
9798
grapherInitializer.layout();
98-
99-
final CommandFinder cf = CommandFinder.build()
100-
.context( appModel.getContext() )
101-
.inputTriggerConfig( appModel.getKeymap().getConfig() )
102-
.keyConfigContexts( keyConfigContexts )
103-
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
104-
.register( viewActions )
105-
.register( appModel.getModelActions() )
106-
.register( appModel.getProjectActions() )
107-
.register( appModel.getPlugins().getPluginActions() )
108-
.modificationListeners( appModel.getKeymap().updateListeners() )
109-
.parent( frame )
110-
.installOn( viewActions );
111-
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );
11299
}
113100

114101
static FeatureGraphConfig getFeatureGraphConfig()

src/main/java/org/mastodon/mamut/views/grapher/MamutViewGrapherFactory.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -31,9 +31,12 @@
3131
import java.util.Map;
3232

3333
import org.mastodon.mamut.ProjectModel;
34+
import org.mastodon.mamut.model.Link;
35+
import org.mastodon.mamut.model.Spot;
3436
import org.mastodon.mamut.views.AbstractMamutViewFactory;
3537
import org.mastodon.mamut.views.MamutViewFactory;
3638
import org.mastodon.ui.coloring.ColorBarOverlay.Position;
39+
import org.mastodon.views.grapher.display.DataDisplayFrame;
3740
import org.scijava.Priority;
3841
import org.scijava.plugin.Plugin;
3942

@@ -82,7 +85,9 @@ public MamutViewGrapher create( final ProjectModel projectModel )
8285
public Map< String, Object > getGuiState( final MamutViewGrapher view )
8386
{
8487
final Map< String, Object > guiState = super.getGuiState( view );
85-
GrapherGuiState.writeGuiState( view, guiState );
88+
DataDisplayFrame< Spot, Link > frame = view.getFrame();
89+
GrapherGuiState.writeGuiState( frame.getDataDisplayPanel().getScreenTransform(), frame.getVertexSidePanel().getGraphConfig(),
90+
guiState );
8691
return guiState;
8792
}
8893

@@ -91,7 +96,9 @@ public Map< String, Object > getGuiState( final MamutViewGrapher view )
9196
public void restoreGuiState( final MamutViewGrapher view, final Map< String, Object > guiState )
9297
{
9398
super.restoreGuiState( view, guiState );
94-
GrapherGuiState.loadGuiState( view, guiState, MamutViewGrapher.getFeatureGraphConfig() );
99+
DataDisplayFrame< Spot, Link > frame = view.getFrame();
100+
GrapherGuiState.loadGuiState( guiState, frame.getDataDisplayPanel().getScreenTransform(), frame.getVertexSidePanel(),
101+
MamutViewGrapher.getFeatureGraphConfig(), view.getFrame() );
95102
}
96103

97104
@Override

src/main/java/org/mastodon/views/grapher/display/DataDisplayFrame.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@
6363
import org.mastodon.views.grapher.datagraph.ScreenTransform;
6464
import org.scijava.ui.behaviour.MouseAndKeyHandler;
6565

66-
public class DataDisplayFrame< V extends Vertex< E > & HasTimepoint & HasLabel, E extends Edge< V > > extends ViewFrame
66+
public class DataDisplayFrame< V extends Vertex< E > & HasTimepoint & HasLabel, E extends Edge< V > > extends ViewFrame implements Plotable
6767
{
6868
private static final long serialVersionUID = 1L;
6969

7070
private final DataDisplayPanel< V, E > dataDisplayPanel;
7171

72-
private final GrapherSidePanel sidePanel;
72+
private final GrapherSidePanel<V, E> sidePanel;
7373

7474
private final FeatureModel featureModel;
7575

@@ -116,7 +116,7 @@ public DataDisplayFrame(
116116
* Side panel.
117117
*/
118118

119-
sidePanel = new GrapherSidePanel( nSources, contextChooser );
119+
sidePanel = new GrapherSidePanel<>( nSources, contextChooser );
120120
sidePanel.getBtnPlot().addActionListener( e -> plot( false ) );
121121

122122
final FeatureModelListener featureModelListener = () -> sidePanel.setFeatures(
@@ -183,7 +183,7 @@ public DataDisplayPanel< V, E > getDataDisplayPanel()
183183
return dataDisplayPanel;
184184
}
185185

186-
public GrapherSidePanel getVertexSidePanel()
186+
public GrapherSidePanel<V, E> getVertexSidePanel()
187187
{
188188
return sidePanel;
189189
}
@@ -194,8 +194,10 @@ public GrapherSidePanel getVertexSidePanel()
194194
*/
195195
public void plot( boolean keepCurrentScreenTransform )
196196
{
197-
dataDisplayPanel.plot( sidePanel.getGraphConfig(), featureModel,
198-
keepCurrentScreenTransform ? dataDisplayPanel.getScreenTransform().get() : null );
197+
if ( keepCurrentScreenTransform )
198+
plot( dataDisplayPanel.getScreenTransform().get() );
199+
else
200+
plot( null );
199201
}
200202

201203
public void plot( final ScreenTransform transform )

0 commit comments

Comments
 (0)