11package nl .tudelft .pl2016gr2 .gui .view ;
22
3+ import javafx .beans .value .ChangeListener ;
4+ import javafx .beans .value .ObservableValue ;
35import javafx .fxml .FXML ;
46import javafx .fxml .FXMLLoader ;
57import javafx .fxml .Initializable ;
8+ import javafx .scene .Scene ;
69import javafx .scene .control .SplitPane ;
10+ import javafx .scene .input .KeyEvent ;
711import javafx .scene .input .MouseEvent ;
812import javafx .scene .layout .AnchorPane ;
913import javafx .scene .layout .Pane ;
1014import javafx .scene .layout .Region ;
15+ import javafx .scene .paint .Color ;
16+ import javafx .scene .shape .Circle ;
17+ import javafx .scene .shape .Rectangle ;
1118import net .sourceforge .olduvai .treejuxtaposer .drawer .Tree ;
1219import nl .tudelft .pl2016gr2 .core .GraphFactory ;
1320import nl .tudelft .pl2016gr2 .core .InputStreamGraphFactory ;
1421import nl .tudelft .pl2016gr2 .core .InputStreamTreeFactory ;
1522import nl .tudelft .pl2016gr2 .core .TreeFactory ;
23+ import nl .tudelft .pl2016gr2 .gui .model .LineageColor ;
1624import nl .tudelft .pl2016gr2 .gui .model .PhylogeneticTreeRoot ;
1725import nl .tudelft .pl2016gr2 .gui .view .graph .DrawComparedGraphs ;
1826import nl .tudelft .pl2016gr2 .gui .view .selection .SelectionManager ;
2836import java .net .URL ;
2937import java .util .ArrayList ;
3038import java .util .List ;
39+ import java .util .Locale ;
3140import java .util .ResourceBundle ;
3241import java .util .logging .Level ;
3342import java .util .logging .Logger ;
@@ -47,6 +56,15 @@ public class RootLayoutController implements
4756 private Pane selectionDescriptionPane ;
4857 @ FXML
4958 private SplitPane mainPane ;
59+ @ FXML
60+ private LegendController graphLegendController ;
61+ @ FXML
62+ private LegendController treeLegendController ;
63+
64+ @ FXML
65+ private Pane searchPane ;
66+ @ FXML
67+ private SearchPaneController searchPaneController ;
5068
5169 @ TestId (id = "treeManager" )
5270 private TreeManager treeManager ;
@@ -65,6 +83,7 @@ public class RootLayoutController implements
6583 @ Override
6684 public void initialize (URL location , ResourceBundle resources ) {
6785 initializeSelectionManager ();
86+ initializeLegend ();
6887 treeManager = TreeManager .loadView (selectionManager );
6988 drawGraphs = DrawComparedGraphs .loadView (selectionManager );
7089 mainPane .getItems ().add (treeManager .getTreePane ());
@@ -73,6 +92,18 @@ public void initialize(URL location, ResourceBundle resources) {
7392 mainPane .getItems ().add (graphRegion );
7493 graphRegion .prefHeightProperty ().bind (mainPane .heightProperty ());
7594 mainPane .setDividerPosition (0 , 0.35 );
95+
96+ rootPane .sceneProperty ().addListener (new ChangeListener <Scene >() {
97+ @ Override
98+ public void changed (ObservableValue <? extends Scene > observable , Scene oldValue ,
99+ Scene newValue ) {
100+ if (newValue != null ) {
101+ initializeSearchPaneController ();
102+ // fire this only once when scene is set.
103+ rootPane .sceneProperty ().removeListener (this );
104+ }
105+ }
106+ });
76107 }
77108
78109 /**
@@ -144,6 +175,60 @@ private void initializeSelectionManager() {
144175 });
145176 }
146177
178+ @ SuppressWarnings ("checkstyle:methodlength" )
179+ private void initializeLegend () {
180+ graphLegendController .initializeData (
181+ "Legend" ,
182+ -5.0 , 5.0 ,
183+ new LegendController .LegendItem (
184+ "This element represent a bubble." ,
185+ "Bubble" ,
186+ new Rectangle (20 , 20 , Color .ALICEBLUE )),
187+ new LegendController .LegendItem (
188+ "This element represents a sequence." ,
189+ "Different sequence" ,
190+ new Circle (10 , Color .rgb (0 , 73 , 73 ))),
191+ new LegendController .LegendItem (
192+ "This element represents a sequence." ,
193+ "Equal sequence" ,
194+ new Circle (10 , Color .rgb (146 , 0 , 0 ))));
195+
196+
197+ List <LegendController .LegendItem > treeLegendItems = new ArrayList <>();
198+ for (LineageColor color : LineageColor .values ()) {
199+ treeLegendItems .add (new LegendController .LegendItem (
200+ String .format ("Lineage color %s" , color .name ()),
201+ color .name (),
202+ new Rectangle (20 , 5 , color .getColor ())
203+ ));
204+ }
205+
206+ treeLegendController .initializeData (
207+ "Legend" ,
208+ 10.0 , 5.0 ,
209+ treeLegendItems .toArray (new LegendController .LegendItem [treeLegendItems .size ()]));
210+
211+ }
212+
213+ private void initializeSearchPaneController () {
214+ String os = System .getProperty ("os.name" , "generic" ).toLowerCase (Locale .ENGLISH );
215+ boolean isOSx = os .contains ("mac" ) || os .contains ("darwin" );
216+
217+ rootPane .getScene ().addEventFilter (KeyEvent .KEY_PRESSED , keyEvent -> {
218+ System .out .println ("KEYEVENT" );
219+ switch (keyEvent .getCode ()) {
220+ case F :
221+ if (keyEvent .isControlDown () || isOSx && keyEvent .isMetaDown ()) {
222+ searchPane .setVisible (!searchPane .isVisible ());
223+ keyEvent .consume ();
224+ }
225+ break ;
226+ default :
227+ }
228+ });
229+ searchPaneController .setSelectionManager (selectionManager );
230+ }
231+
147232 @ Override
148233 public void filesLoaded (InputStream treeFile , InputStream graphFile , InputStream metadataFile ) {
149234 try {
@@ -154,10 +239,12 @@ public void filesLoaded(InputStream treeFile, InputStream graphFile, InputStream
154239
155240 SequenceGraph graph = graphFactory .getGraph ();
156241 Tree tree = treeFactory .getTree ();
242+ List <Annotation > annotations = new AnnotationReader (metadataFile ).read ();
157243
158244 if (graph != null && tree != null ) {
159245 loadGraph (graph );
160- loadTree (tree , new AnnotationReader (metadataFile ).read ());
246+ loadTree (tree , annotations );
247+ searchPaneController .setData (annotations );
161248 } else {
162249 Logger .getLogger (RootLayoutController .class .getName ()).log (
163250 Level .SEVERE ,
0 commit comments