169 lines
4.4 KiB
Java
169 lines
4.4 KiB
Java
package controller;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
|
|
import Classes.Category;
|
|
import Classes.SortTypes;
|
|
import Classes.TagType;
|
|
import Classes.css.user.ContextBuilder;
|
|
import Classes.css.user.HeaderIconStyleSheet;
|
|
import Classes.css.user.HeaderStyleSheet;
|
|
import Classes.css.user.MenuStyleSheet;
|
|
import Classes.css.user.SubMenuStyleSheet;
|
|
import Interfaces.Event;
|
|
import Interfaces.EventObserver;
|
|
import javafx.application.Application;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.layout.FlowPane;
|
|
import javafx.stage.Stage;
|
|
import model.NewsListModel;
|
|
|
|
public class RootLayout extends Application implements EventObserver {
|
|
|
|
private Stage root_stage;
|
|
private Scene root_scene;
|
|
private AnchorPane root_layout;
|
|
private FlowPane main_container;
|
|
|
|
|
|
|
|
@Override
|
|
public void start(Stage primary_stage) throws Exception {
|
|
|
|
/* (1) store primary stage + title it */
|
|
this.root_stage = primary_stage;
|
|
this.root_stage.setTitle("Inifiny Mail Client");
|
|
|
|
/* (2) Load the root layout*/
|
|
this.loadRootLayout();
|
|
|
|
/* (3) Load the CSS CONTEXT */
|
|
ContextBuilder.createContext();
|
|
|
|
/* (3) Store container */
|
|
this.main_container = (FlowPane) this.root_scene.lookup("#container");
|
|
|
|
|
|
|
|
/* (1) Create controllers' views
|
|
-------------------------------------*/
|
|
/* (1) Create header menu */
|
|
HeaderMenu hm = new HeaderMenu((FlowPane) this.root_scene.lookup("#header_menu"),this);
|
|
|
|
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");
|
|
|
|
|
|
/* (2) Create container */
|
|
Article artCtl = new Article(this.main_container, this);
|
|
ArrayList<TagType> tags = new ArrayList<TagType>();
|
|
tags.add(TagType.science); tags.add(TagType.economics);
|
|
|
|
artCtl.addItem("Article 1", "blabla bloblo blibli", new Date(12), tags);
|
|
|
|
|
|
|
|
/* (2) CSS
|
|
-------------------------------------*/
|
|
|
|
/* (1) #header */
|
|
new HeaderStyleSheet( this.root_scene.lookup("#header") );
|
|
|
|
/* (2) #menu_container */
|
|
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") );
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
/* (4) Show the stage */
|
|
this.root_stage.show();
|
|
|
|
}catch(IOException e){
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
launch(args);
|
|
}
|
|
|
|
@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()){
|
|
case "changeMainLayout":
|
|
this.handleMainLayoutChange(e.getObjectId());
|
|
break;
|
|
case "NewsQuerySuccess":
|
|
System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé");
|
|
if(NewsListModel.getInstance().getNews().size() != 0) {
|
|
System.out.println("La description du premier article est: "+NewsListModel.getInstance().getNews().get(0).getDescription());
|
|
}
|
|
|
|
break;
|
|
case "NewsQueryFailed":
|
|
System.out.println("une erreur est survenue");
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public void handleMainLayoutChange(String layout) {
|
|
NewsListModel.getInstance().addObserver("MainClass", this);
|
|
NewsListModel.getInstance().setCategory(Category.business);
|
|
NewsListModel.getInstance().setSortType(SortTypes.publishedAt);
|
|
NewsListModel.getInstance().query("bitcoin");
|
|
|
|
}
|
|
}
|