11package fiji .plugin .trackmate .features ;
22
33import static fiji .plugin .trackmate .visualization .trackscheme .TrackScheme .TRACK_SCHEME_ICON ;
4- import fiji .plugin .trackmate .Model ;
5- import fiji .plugin .trackmate .Spot ;
6- import fiji .plugin .trackmate .TrackModel ;
7- import fiji .plugin .trackmate .util .ExportableChartPanel ;
84
95import java .awt .Shape ;
106import java .awt .geom .Ellipse2D ;
2622import org .jfree .chart .renderer .InterpolatePaintScale ;
2723import org .jgrapht .graph .DefaultWeightedEdge ;
2824
29- public abstract class AbstractFeatureGrapher {
30-
31- protected static final Shape DEFAULT_SHAPE = new Ellipse2D .Double (-3 , -3 , 6 , 6 );
25+ import fiji .plugin .trackmate .Model ;
26+ import fiji .plugin .trackmate .Spot ;
27+ import fiji .plugin .trackmate .TrackMateOptionUtils ;
28+ import fiji .plugin .trackmate .TrackModel ;
29+ import fiji .plugin .trackmate .util .ExportableChartPanel ;
30+
31+ public abstract class AbstractFeatureGrapher
32+ {
33+
34+ protected static final Shape DEFAULT_SHAPE = new Ellipse2D .Double ( -3 , -3 , 6 , 6 );
35+
36+ protected final InterpolatePaintScale paints = TrackMateOptionUtils .getOptions ().getPaintScale ();
3237
33- protected final InterpolatePaintScale paints = InterpolatePaintScale .Jet ;
3438 protected final String xFeature ;
35- protected final Set <String > yFeatures ;
39+
40+ protected final Set < String > yFeatures ;
41+
3642 protected final Model model ;
3743
38- public AbstractFeatureGrapher (final String xFeature , final Set <String > yFeatures ,final Model model ) {
44+ public AbstractFeatureGrapher ( final String xFeature , final Set < String > yFeatures , final Model model )
45+ {
3946 this .xFeature = xFeature ;
4047 this .yFeatures = yFeatures ;
4148 this .model = model ;
4249 }
43-
50+
4451 /**
4552 * Draw and render the graph.
4653 */
@@ -49,99 +56,111 @@ public AbstractFeatureGrapher(final String xFeature, final Set<String> yFeatures
4956 /*
5057 * UTILS
5158 */
52-
59+
5360 /**
54- * Render and display a frame containing all the char panels, grouped by dimension
61+ * Render and display a frame containing all the char panels, grouped by
62+ * dimension
5563 */
56- protected final void renderCharts (final List <ExportableChartPanel > chartPanels ) {
64+ protected final void renderCharts ( final List < ExportableChartPanel > chartPanels )
65+ {
5766 // The Panel
58- JPanel panel = new JPanel ();
59- BoxLayout panelLayout = new BoxLayout (panel , BoxLayout .Y_AXIS );
60- panel .setLayout (panelLayout );
61- for (ExportableChartPanel chartPanel : chartPanels ) {
62- panel .add (chartPanel );
63- panel .add (Box .createVerticalStrut (5 ));
67+ final JPanel panel = new JPanel ();
68+ final BoxLayout panelLayout = new BoxLayout ( panel , BoxLayout .Y_AXIS );
69+ panel .setLayout ( panelLayout );
70+ for ( final ExportableChartPanel chartPanel : chartPanels )
71+ {
72+ panel .add ( chartPanel );
73+ panel .add ( Box .createVerticalStrut ( 5 ) );
6474 }
65-
75+
6676 // Scroll pane
67- JScrollPane scrollPane = new JScrollPane ();
68- scrollPane .setHorizontalScrollBarPolicy (ScrollPaneConstants .HORIZONTAL_SCROLLBAR_NEVER );
69- scrollPane .setViewportView (panel );
77+ final JScrollPane scrollPane = new JScrollPane ();
78+ scrollPane .setHorizontalScrollBarPolicy ( ScrollPaneConstants .HORIZONTAL_SCROLLBAR_NEVER );
79+ scrollPane .setViewportView ( panel );
7080
7181 // The frame
72- JFrame frame = new JFrame ();
73- frame .setTitle ("Feature plot for Track scheme" );
74- frame .setIconImage (TRACK_SCHEME_ICON .getImage ());
75- frame .getContentPane ().add (scrollPane );
82+ final JFrame frame = new JFrame ();
83+ frame .setTitle ( "Feature plot for Track scheme" );
84+ frame .setIconImage ( TRACK_SCHEME_ICON .getImage () );
85+ frame .getContentPane ().add ( scrollPane );
7686 frame .validate ();
77- frame .setSize (new java .awt .Dimension (520 , 320 ) );
78- frame .setVisible (true );
87+ frame .setSize ( new java .awt .Dimension ( 520 , 320 ) );
88+ frame .setVisible ( true );
7989 }
8090
81-
8291 /**
83- * @return the unique mapped values in the given map, for the collection of keys given.
92+ * @return the unique mapped values in the given map, for the collection of
93+ * keys given.
8494 */
85- protected final <K , V > Set <V > getUniqueValues (Iterable <K > keys , Map <K ,V > map ) {
86- HashSet <V > mapping = new HashSet <>();
87- for (K key : keys ) {
88- mapping .add (map .get (key ));
89- }
95+ protected final < K , V > Set < V > getUniqueValues ( final Iterable < K > keys , final Map < K , V > map )
96+ {
97+ final HashSet < V > mapping = new HashSet <>();
98+ for ( final K key : keys )
99+ mapping .add ( map .get ( key ) );
100+
90101 return mapping ;
91102 }
92103
93104 /**
94- * @return the collection of keys amongst the given ones,
95- * that point to the target value in the given map.
96- * @param targetValue the common value to search
97- * @param keys the keys to inspect
98- * @param map the map to search in
105+ * @return the collection of keys amongst the given ones, that point to the
106+ * target value in the given map.
107+ * @param targetValue
108+ * the common value to search
109+ * @param keys
110+ * the keys to inspect
111+ * @param map
112+ * the map to search in
99113 */
100- protected final <K , V > List <K > getCommonKeys (final V targetValue , final Iterable <K > keys , final Map <K ,V > map ) {
101- ArrayList <K > foundKeys = new ArrayList <>();
102- for (K key : keys ) {
103- if (map .get (key ).equals (targetValue )) {
104- foundKeys .add (key );
105- }
114+ protected final < K , V > List < K > getCommonKeys ( final V targetValue , final Iterable < K > keys , final Map < K , V > map )
115+ {
116+ final ArrayList < K > foundKeys = new ArrayList <>();
117+ for ( final K key : keys )
118+ {
119+ if ( map .get ( key ).equals ( targetValue ) )
120+ foundKeys .add ( key );
121+
106122 }
107123 return foundKeys ;
108124 }
109-
125+
110126 /**
111127 * @return a suitable plot title built from the given target features
112128 */
113-
114- protected final String buildPlotTitle (final Iterable <String > lYFeatures , final Map <String , String > featureNames ) {
115- StringBuilder sb = new StringBuilder ("Plot of " );
116- Iterator <String > it = lYFeatures .iterator ();
117- sb .append (featureNames .get (it .next ()) );
118- while (it .hasNext ()) {
119- sb .append (", " );
120- sb .append (featureNames .get (it .next ()));
129+
130+ protected final String buildPlotTitle ( final Iterable < String > lYFeatures , final Map < String , String > featureNames )
131+ {
132+ final StringBuilder sb = new StringBuilder ( "Plot of " );
133+ final Iterator < String > it = lYFeatures .iterator ();
134+ sb .append ( featureNames .get ( it .next () ) );
135+ while ( it .hasNext () )
136+ {
137+ sb .append ( ", " );
138+ sb .append ( featureNames .get ( it .next () ) );
121139 }
122- sb .append (" vs " );
123- sb .append (featureNames .get (xFeature ) );
124- sb .append ("." );
140+ sb .append ( " vs " );
141+ sb .append ( featureNames .get ( xFeature ) );
142+ sb .append ( "." );
125143 return sb .toString ();
126144 }
127145
128146 /**
129- * @return the list of links that have their source and target in the given spot list.
147+ * @return the list of links that have their source and target in the given
148+ * spot list.
130149 */
131- protected final List <DefaultWeightedEdge > getInsideEdges (final Collection <Spot > spots ) {
132- int nspots = spots .size ();
133- ArrayList <DefaultWeightedEdge > edges = new ArrayList <>(nspots );
134- TrackModel trackModel = model .getTrackModel ();
135- for (DefaultWeightedEdge edge : trackModel .edgeSet ()) {
136- Spot source = trackModel .getEdgeSource (edge );
137- Spot target = trackModel .getEdgeTarget (edge );
138- if (spots .contains (source ) && spots .contains (target )) {
139- edges .add (edge );
140- }
150+ protected final List < DefaultWeightedEdge > getInsideEdges ( final Collection < Spot > spots )
151+ {
152+ final int nspots = spots .size ();
153+ final ArrayList < DefaultWeightedEdge > edges = new ArrayList <>( nspots );
154+ final TrackModel trackModel = model .getTrackModel ();
155+ for ( final DefaultWeightedEdge edge : trackModel .edgeSet () )
156+ {
157+ final Spot source = trackModel .getEdgeSource ( edge );
158+ final Spot target = trackModel .getEdgeTarget ( edge );
159+ if ( spots .contains ( source ) && spots .contains ( target ) )
160+ edges .add ( edge );
161+
141162 }
142163 return edges ;
143164 }
144-
145-
146165
147166}
0 commit comments