From c547cf90d98044d5c9f22b8d8e810708389f1654 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Tue, 12 Dec 2017 13:40:22 +0100 Subject: [PATCH] =?UTF-8?q?impl=C3=A9mentation=20du=20switch=20de=20contex?= =?UTF-8?q?te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/Article.java | 10 ++++++ controller/RootLayout.java | 73 ++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/controller/Article.java b/controller/Article.java index 45fcb57..6e76cf1 100644 --- a/controller/Article.java +++ b/controller/Article.java @@ -7,7 +7,9 @@ import java.util.Date; import Classes.Category; import Interfaces.EventObserver; import javafx.application.Platform; +import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; @@ -79,6 +81,14 @@ public class Article{ }); } + public void clearContent() { + Platform.runLater(new Runnable(){ + public void run(){ + Article.this.parent.getChildren().clear(); + } + }); + } + public void gsetContent(String p_content, AnchorPane p_parent){ diff --git a/controller/RootLayout.java b/controller/RootLayout.java index 8669df1..c7e4b57 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -13,14 +13,18 @@ import Classes.css.user.SubMenuStyleSheet; import Interfaces.Event; import Interfaces.EventObserver; import javafx.application.Application; +import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.Scene; +import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.FlowPane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; import javafx.stage.Stage; import model.DictionaryModel; -import model.LangModel; import model.NewsListModel; import model.NewsModel; @@ -100,6 +104,17 @@ public class RootLayout extends Application implements EventObserver { /* (3) Add the scene to the stage */ 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()) { + c.setOnMousePressed(new EventHandler() { + @Override + public void handle(MouseEvent event) { + RootLayout.this.handleEvent(new Classes.Event(c.getId(), "changeMainLayout")); + } + }); + } + /* (4) Show the stage */ this.root_stage.show(); @@ -116,27 +131,6 @@ public class RootLayout extends Application implements EventObserver { @Override public void handleEvent(Event e) { - /* - HashMap headers = new HashMap(); - headers.put("Referer", "http://www.wordreference.com"); - - ApiCall call = new ApiCall("http://api.wordreference.com/1/json/enfr/grin","GET",new Callback() { - - @Override - public void onSuccess(JSONObject response) { - System.out.println(response.toString()); - - } - - @Override - public void onError() { - System.out.println("APICall error"); - - } - - }); - call.addHeaders(headers); - call.send();*/ switch(e.getEventType()){ @@ -147,9 +141,9 @@ public class RootLayout extends Application implements EventObserver { case "NewsQuerySuccess": System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé"); if(NewsListModel.getInstance().getNews().size() != 0) { - System.out.println("Le titre du premier article est: "+NewsListModel.getInstance().getNews().get(0).getTitle()); - System.out.println("La description du premier article est: "+NewsListModel.getInstance().getNews().get(0).getDescription()); + this.articles.clearContent(); + // For each news for( NewsModel news : NewsListModel.getInstance().getNews() ){ @@ -181,14 +175,31 @@ public class RootLayout extends Application implements EventObserver { } public void handleMainLayoutChange(String layout) { + FlowPane container = (FlowPane) this.root_layout.lookup("#container"); + container.getChildren().clear(); - NewsListModel.getInstance().addObserver("MainClass", this); - NewsListModel.getInstance().setCategory(Category.gaming); - NewsListModel.getInstance().setSortType(SortTypes.relevancy); - NewsListModel.getInstance().query("the evil within"); - DictionaryModel.getInstance().addObserver("MainClass", this); - DictionaryModel.getInstance().query("maison"); - + switch(layout) { + case "dictionary" : + DictionaryModel.getInstance().addObserver("MainClass", this); + DictionaryModel.getInstance().query("maison"); + container.getChildren().add(new Text("dictionnaire")); + break; + case "exercises" : + container.getChildren().add(new Text("exercises")); + break; + case "translator" : + container.getChildren().add(new Text("translator")); + break; + case "magazines" : + + NewsListModel.getInstance().addObserver("MainClass", this); + NewsListModel.getInstance().setCategory(Category.gaming); + NewsListModel.getInstance().setSortType(SortTypes.relevancy); + NewsListModel.getInstance().query("the evil within"); + + break; + + } } }