From bab2d19601472b50cddc8aa1c1bf01b4fd16e4c1 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 19 Dec 2017 18:09:03 +0100 Subject: [PATCH] Added 'exercise' + menu :hover --- controller/RootLayout.java | 46 ++++++++++++++++++++++++--------- css/menu.css | 4 +++ fxml/exercise_disp.fxml | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 fxml/exercise_disp.fxml diff --git a/controller/RootLayout.java b/controller/RootLayout.java index 29c6f2d..bea0101 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -39,6 +39,7 @@ public class RootLayout extends Application implements EventObserver { private Scene root_scene; private AnchorPane root_layout; private FlowPane main_container; + private VBox main_menu; private Article articles; private Traduction dico; @@ -153,8 +154,8 @@ public class RootLayout extends Application implements EventObserver { this.root_stage.setScene(this.root_scene); //bind events on click fot the menu - VBox menuRoot = (VBox) this.root_layout.lookup("#menu"); - for (Node c : menuRoot.getChildren()) { + this.main_menu = (VBox) this.root_layout.lookup("#menu"); + for (Node c : this.main_menu.getChildren()) { c.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { @@ -257,24 +258,45 @@ public class RootLayout extends Application implements EventObserver { public void handleMainLayoutChange(String layout) { this.main_container.getChildren().clear(); + FXMLLoader loader; + + /* Un-select all menu items but re-select the chosen one */ + for( Node n : this.main_menu.getChildren() ){ + n.getStyleClass().clear(); + n.getStyleClass().add("menu_item"); + + if( n.getId() == layout ) + n.getStyleClass().add("active"); + } switch(layout) { case "dictionary" : - this.main_container.getChildren().add(new Text("dictionary")); - break; - case "exercises" : /* (1) Load the root_disp.fxml */ - FXMLLoader loader = new FXMLLoader(); + loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/fxml/vocabulary_disp.fxml")); /* (2) Load the layout into the scene */ - try { - this.main_container.getChildren().add((AnchorPane) loader.load()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + try { + this.main_container.getChildren().add((AnchorPane) loader.load()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + case "exercises" : + /* (1) Load the root_disp.fxml */ + loader = new FXMLLoader(); + + loader.setLocation(getClass().getResource("/fxml/exercise_disp.fxml")); + + /* (2) Load the layout into the scene */ + try { + this.main_container.getChildren().add((AnchorPane) loader.load()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } break; case "translator" : this.root_layout.lookup("#submenu").setVisible(false); diff --git a/css/menu.css b/css/menu.css index c6b193d..b4223bf 100644 --- a/css/menu.css +++ b/css/menu.css @@ -36,6 +36,10 @@ -fx-border-color: #eeeeee; } +.menu_item.active{ + -fx-background-color: #eeeeee; +} + #menu{ -fx-background-color: #ffffff; diff --git a/fxml/exercise_disp.fxml b/fxml/exercise_disp.fxml new file mode 100644 index 0000000..b5abe7d --- /dev/null +++ b/fxml/exercise_disp.fxml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + +