2017-11-14 07:22:26 +00:00
|
|
|
package controller;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2017-11-19 11:18:26 +00:00
|
|
|
import java.util.ArrayList;
|
2017-11-14 07:22:26 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
import Classes.Category;
|
|
|
|
import Classes.SortTypes;
|
2017-11-15 13:23:49 +00:00
|
|
|
import Classes.css.user.ContextBuilder;
|
2017-11-15 17:12:46 +00:00
|
|
|
import Classes.css.user.HeaderIconStyleSheet;
|
2017-11-19 11:18:26 +00:00
|
|
|
import Classes.css.user.HeaderStyleSheet;
|
2017-11-15 17:12:46 +00:00
|
|
|
import Classes.css.user.MenuStyleSheet;
|
|
|
|
import Classes.css.user.SubMenuStyleSheet;
|
2017-11-14 08:09:25 +00:00
|
|
|
import Interfaces.Event;
|
|
|
|
import Interfaces.EventObserver;
|
2017-11-14 07:22:26 +00:00
|
|
|
import javafx.application.Application;
|
2017-12-12 12:40:22 +00:00
|
|
|
import javafx.event.EventHandler;
|
2017-11-14 07:22:26 +00:00
|
|
|
import javafx.fxml.FXMLLoader;
|
2017-12-12 12:40:22 +00:00
|
|
|
import javafx.scene.Node;
|
2017-11-14 07:22:26 +00:00
|
|
|
import javafx.scene.Scene;
|
2017-12-12 12:40:22 +00:00
|
|
|
import javafx.scene.input.MouseEvent;
|
2017-11-14 07:22:26 +00:00
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
import javafx.scene.layout.FlowPane;
|
2017-12-12 12:40:22 +00:00
|
|
|
import javafx.scene.layout.VBox;
|
|
|
|
import javafx.scene.text.Text;
|
2017-11-14 07:22:26 +00:00
|
|
|
import javafx.stage.Stage;
|
2017-11-21 07:35:37 +00:00
|
|
|
|
2017-11-21 07:34:05 +00:00
|
|
|
import model.DictionaryModel;
|
2017-11-21 07:35:37 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
import model.NewsListModel;
|
2017-11-19 13:44:40 +00:00
|
|
|
import model.NewsModel;
|
2017-11-14 07:22:26 +00:00
|
|
|
|
2017-11-14 08:09:25 +00:00
|
|
|
public class RootLayout extends Application implements EventObserver {
|
2017-11-14 07:22:26 +00:00
|
|
|
|
|
|
|
private Stage root_stage;
|
|
|
|
private Scene root_scene;
|
|
|
|
private AnchorPane root_layout;
|
2017-11-19 11:18:26 +00:00
|
|
|
private FlowPane main_container;
|
2017-11-19 13:44:40 +00:00
|
|
|
private Article articles;
|
2017-11-14 07:22:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-11-15 13:23:49 +00:00
|
|
|
public void start(Stage primary_stage) throws Exception {
|
2017-11-14 07:22:26 +00:00
|
|
|
|
|
|
|
/* (1) store primary stage + title it */
|
|
|
|
this.root_stage = primary_stage;
|
|
|
|
this.root_stage.setTitle("Inifiny Mail Client");
|
|
|
|
|
|
|
|
/* (2) Load the root layout*/
|
2017-11-14 08:09:25 +00:00
|
|
|
this.loadRootLayout();
|
2017-11-14 07:22:26 +00:00
|
|
|
|
2017-11-15 13:23:49 +00:00
|
|
|
/* (3) Load the CSS CONTEXT */
|
|
|
|
ContextBuilder.createContext();
|
|
|
|
|
2017-11-19 11:18:26 +00:00
|
|
|
/* (3) Store container */
|
|
|
|
this.main_container = (FlowPane) this.root_scene.lookup("#container");
|
2017-11-15 13:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-19 11:18:26 +00:00
|
|
|
/* (1) Create controllers' views
|
2017-11-14 07:22:26 +00:00
|
|
|
-------------------------------------*/
|
|
|
|
/* (1) Create header menu */
|
2017-11-15 15:13:07 +00:00
|
|
|
HeaderMenu hm = new HeaderMenu((FlowPane) this.root_scene.lookup("#header_menu"),this);
|
2017-11-14 07:22:26 +00:00
|
|
|
|
2017-11-15 15:13:07 +00:00
|
|
|
hm.addItem("notification", "/src/header-notif.png");
|
|
|
|
hm.addItem("mail", "/src/header-mail.png");
|
|
|
|
hm.addItem("search", "/src/header-search.png");
|
|
|
|
hm.addItem("menu", "/src/header-menu.png");
|
2017-11-14 07:22:26 +00:00
|
|
|
|
|
|
|
|
2017-11-19 11:18:26 +00:00
|
|
|
/* (2) Create container */
|
2017-11-19 13:44:40 +00:00
|
|
|
this.articles = new Article(this.main_container, this);
|
2017-11-19 11:18:26 +00:00
|
|
|
|
|
|
|
|
2017-11-15 13:23:49 +00:00
|
|
|
/* (2) CSS
|
|
|
|
-------------------------------------*/
|
|
|
|
|
|
|
|
/* (1) #header */
|
2017-11-15 17:12:46 +00:00
|
|
|
new HeaderStyleSheet( this.root_scene.lookup("#header") );
|
2017-11-15 13:23:49 +00:00
|
|
|
|
|
|
|
/* (2) #menu_container */
|
2017-11-15 17:12:46 +00:00
|
|
|
new MenuStyleSheet( this.root_scene.lookup("#menu") );
|
|
|
|
|
|
|
|
/* (3) #submenu */
|
|
|
|
new SubMenuStyleSheet( this.root_scene.lookup("#submenu") );
|
|
|
|
|
|
|
|
/* (4) #header_icon*/
|
|
|
|
new HeaderIconStyleSheet( this.root_scene.lookup("#header_icon") );
|
2017-11-15 13:23:49 +00:00
|
|
|
|
2017-11-14 07:22:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void loadRootLayout(){
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
/* (1) Load the root_disp.fxml */
|
|
|
|
FXMLLoader loader = new FXMLLoader();
|
|
|
|
|
|
|
|
loader.setLocation(getClass().getResource("/fxml/model.fxml"));
|
|
|
|
|
|
|
|
/* (2) Load the layout into the scene */
|
|
|
|
this.root_layout = (AnchorPane) loader.load();
|
|
|
|
this.root_scene = new Scene(this.root_layout);
|
|
|
|
|
|
|
|
/* (3) Add the scene to the stage */
|
|
|
|
this.root_stage.setScene(this.root_scene);
|
|
|
|
|
2017-12-12 12:40:22 +00:00
|
|
|
//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"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-14 07:22:26 +00:00
|
|
|
/* (4) Show the stage */
|
|
|
|
this.root_stage.show();
|
|
|
|
|
|
|
|
}catch(IOException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
launch(args);
|
|
|
|
}
|
2017-11-14 08:09:25 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleEvent(Event e) {
|
2017-11-15 15:13:07 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
switch(e.getEventType()){
|
2017-11-19 13:44:40 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
case "changeMainLayout":
|
|
|
|
this.handleMainLayoutChange(e.getObjectId());
|
|
|
|
break;
|
2017-11-19 13:44:40 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
case "NewsQuerySuccess":
|
|
|
|
System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé");
|
|
|
|
if(NewsListModel.getInstance().getNews().size() != 0) {
|
|
|
|
|
2017-12-12 12:40:22 +00:00
|
|
|
this.articles.clearContent();
|
|
|
|
|
2017-11-21 07:38:24 +00:00
|
|
|
// For each news
|
|
|
|
for( NewsModel news : NewsListModel.getInstance().getNews() ){
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
this.articles.addItem( news );
|
2017-11-19 13:44:40 +00:00
|
|
|
|
2017-11-21 07:38:24 +00:00
|
|
|
}catch(Exception e1){
|
|
|
|
|
|
|
|
System.out.println("Cannot fetch article data");
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
|
|
|
}
|
2017-11-19 13:44:40 +00:00
|
|
|
}
|
2017-11-21 07:38:24 +00:00
|
|
|
}
|
2017-11-19 13:44:40 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
break;
|
2017-11-19 13:44:40 +00:00
|
|
|
|
2017-11-15 21:53:52 +00:00
|
|
|
case "NewsQueryFailed":
|
|
|
|
System.out.println("une erreur est survenue");
|
|
|
|
break;
|
2017-11-21 07:34:05 +00:00
|
|
|
|
|
|
|
case "WordQuerySuccess":
|
|
|
|
System.out.println(DictionaryModel.getInstance().getTranslations().size()+" Traductions ont été trouvés");
|
|
|
|
System.out.println(DictionaryModel.getInstance().getUsages().size()+" Exemples ont été trouvés");
|
|
|
|
break;
|
2017-11-15 21:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleMainLayoutChange(String layout) {
|
2017-12-12 12:40:22 +00:00
|
|
|
FlowPane container = (FlowPane) this.root_layout.lookup("#container");
|
|
|
|
container.getChildren().clear();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
2017-11-14 08:09:25 +00:00
|
|
|
|
|
|
|
}
|
2017-11-14 07:22:26 +00:00
|
|
|
}
|