Merge branch 'master' of https://git.xdrm.io/MTI/javafx-p1
This commit is contained in:
commit
46950b211d
|
@ -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){
|
||||
|
|
|
@ -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<MouseEvent>() {
|
||||
@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<String,String> headers = new HashMap<String,String>();
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue