From 3521f2e2a935ca8b27d9c832a0844897db022cec Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 16 Nov 2017 16:44:31 +0100 Subject: [PATCH 1/4] Created card layout --- fxml/model.fxml | 79 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/fxml/model.fxml b/fxml/model.fxml index b7e8479..49f9cfe 100644 --- a/fxml/model.fxml +++ b/fxml/model.fxml @@ -52,6 +52,83 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7de525b0c7a894498ea9d4c8bcc391af1af9e1b8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 18 Nov 2017 14:28:49 +0100 Subject: [PATCH 2/4] Fix sub-menu css 'left' (-3px) --- Classes/css/user/SubMenuStyleSheet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/css/user/SubMenuStyleSheet.java b/Classes/css/user/SubMenuStyleSheet.java index c0f27f7..16bdd8e 100644 --- a/Classes/css/user/SubMenuStyleSheet.java +++ b/Classes/css/user/SubMenuStyleSheet.java @@ -12,7 +12,7 @@ public class SubMenuStyleSheet{ /* (1) Set rules */ Ruleset.load(target) .add("top", Context.getInt("header-height")) - .add("left", Context.getInt("menu-width")) + .add("left", Context.getInt("menu-width")-3) .add("bottom", 0) .add("min-width", Context.getInt("submenu-width")) From fee05db7f4711167ab1d20c8cfb82067852de1a3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 19 Nov 2017 12:18:26 +0100 Subject: [PATCH 3/4] Ajout article programmatique [ok] + modeles articles, tags [ok] + lien entre les 2 [ok] + [todo] rounded corners --- Classes/TagType.java | 17 +++ Classes/css/user/ArticleStylesheet.java | 142 ++++++++++++++++++++++++ Classes/css/user/ContextBuilder.java | 2 + controller/Article.java | 134 ++++++++++++++++++++++ controller/RootLayout.java | 28 +++-- fxml/article_disp.fxml | 62 +++++++++++ fxml/article_tag_disp.fxml | 26 +++++ fxml/header_menu_disp.fxml | 16 --- fxml/model.fxml | 128 +++++++++------------ fxml/root_disp.fxml | 16 --- 10 files changed, 456 insertions(+), 115 deletions(-) create mode 100644 Classes/TagType.java create mode 100644 Classes/css/user/ArticleStylesheet.java create mode 100644 controller/Article.java create mode 100644 fxml/article_disp.fxml create mode 100644 fxml/article_tag_disp.fxml delete mode 100644 fxml/header_menu_disp.fxml delete mode 100644 fxml/root_disp.fxml diff --git a/Classes/TagType.java b/Classes/TagType.java new file mode 100644 index 0000000..7f7a9d8 --- /dev/null +++ b/Classes/TagType.java @@ -0,0 +1,17 @@ +package Classes; + +public enum TagType { + science("science", "#f14405"), + nature("nature", "#16c668"), + economics("economics", "#d1991b"), + politics("politics", "#6825f4"), + technology("technology", "#1e7ebe"); + + protected String color; + protected String label; + TagType(String label, String color){ this.label = label; this.color = color; } + + public String getLabel(){ return this.label; } + public String getColor(){ return this.color; } + +} \ No newline at end of file diff --git a/Classes/css/user/ArticleStylesheet.java b/Classes/css/user/ArticleStylesheet.java new file mode 100644 index 0000000..7303694 --- /dev/null +++ b/Classes/css/user/ArticleStylesheet.java @@ -0,0 +1,142 @@ +package Classes.css.user; + +import java.util.ArrayList; + +import Classes.css.core.Context; +import Classes.css.core.Ruleset; +import javafx.scene.Node; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.text.Text; + +public class ArticleStylesheet{ + + /* Builds all necessary CSS/layout rules */ + public ArticleStylesheet(Node target) throws Exception{ + + /* (1) Useful cast */ + AnchorPane _target = (AnchorPane) target; + HBox _hc = (HBox) _target.getChildren().get(3); + + /* (2) Set rules for parent */ + Ruleset.load(_target) + + .add("min-width", Context.getInt("article-width")) + .add("max-width", Context.getInt("article-width")) + + .add("min-height", Context.getInt("article-height")) + .add("max-height", Context.getInt("article-height")) + + .add("pref-width", Context.getString("article-width")) + .add("pref-height", Context.getString("article-height")) + + // border + .add("border-insets", "10") + .add("border-radius", "3") + .add("border-color", "#ddd") + + // bg + .add("background-insets", "10") + .add("background-radius", "3") + .add("background-color", "#fff") + .apply(); + + /* (2) Get children ruleset: picture, content, date, header_container */ + this.Picture( (ImageView) _target.getChildren().get(0) ).apply(); + this.Content( (Text) _target.getChildren().get(1) ).apply(); + this.RelativeDate( (Text) _target.getChildren().get(2) ).apply(); + this.HeaderContainer( (HBox) _target.getChildren().get(3) ).apply(); + + /* (3) Header container children: title, tag1, tag2, ... */ + this.HeaderTitle( (Text) _hc.getChildren().get(0) ).apply(); + + for( int i = 0 ; i < _hc.getChildren().size()-1 ; i++ ){ + + Pane _tmp = (Pane) _hc.getChildren().get(i+1); + this.HeaderTag(_tmp).apply(); + this.HeaderTextTag( (Text) _tmp.getChildren().get(0) ).apply(); + + } + + } + + + + + /* Picture of article */ + private Ruleset Picture(ImageView target) throws Exception{ + + return Ruleset.load(target) + .add("top", 20) + .add("left", 20) + .add("bottom", 20); + + } + + /* Article content */ + private Ruleset Content(Text target) throws Exception{ + + return Ruleset.load(target) + .add("top", 50) + .add("left", 96) + .add("fill", "#808080") + .add("font-family", "Lato Regular") + .add("font-size", "12"); + + } + + /* Header Container */ + private Ruleset HeaderContainer(HBox target) throws Exception{ + + return Ruleset.load(target) + .add("top", 20) + .add("left", 96) + .add("pref-height", "21") + .add("pref-width", "200"); + + } + + /* Relative date of article */ + private Ruleset RelativeDate(Text target) throws Exception{ + + return Ruleset.load(target) + .add("top", 20) + .add("right", 20) + .add("fill", "#757575") + .add("font-family", "Lato Bold") + .add("font-size", "12"); + } + + /* Header Title */ + private Ruleset HeaderTitle(Text target) throws Exception{ + + return Ruleset.load(target) + .add("font-family", "Lato Bold") + .add("font-size", "17"); + + } + + /* Header Tag */ + private Ruleset HeaderTag(Pane target) throws Exception{ + + return Ruleset.load(target) + .add("pref-width", 55) + .add("pref-height", 20) + .add("background-color", "#f8b02c") + .add("background-radius", "3"); + + } + + /* Header Tag Text */ + private Ruleset HeaderTextTag(Text target) throws Exception{ + + return Ruleset.load(target) + .add("fill", "#fff") + .add("font-family", "Lato Regular") + .add("font-size", "14"); + + } + +} diff --git a/Classes/css/user/ContextBuilder.java b/Classes/css/user/ContextBuilder.java index 059b9a7..85111b0 100644 --- a/Classes/css/user/ContextBuilder.java +++ b/Classes/css/user/ContextBuilder.java @@ -14,6 +14,8 @@ public class ContextBuilder{ Context.bind("header-height", 50); Context.bind("menu-width", 237); Context.bind("submenu-width", 200); + Context.bind("article-width", 800); + Context.bind("article-height", 96); /* (3) Colors */ Context.bind("main-color", 63, 81, 181); diff --git a/controller/Article.java b/controller/Article.java new file mode 100644 index 0000000..41d7f09 --- /dev/null +++ b/controller/Article.java @@ -0,0 +1,134 @@ +package controller; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; + +import Classes.TagType; +import Interfaces.EventObserver; +import javafx.event.EventHandler; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Paint; +import javafx.scene.text.Text; + +public class Article{ + + /* Data */ + private ArrayList items; + private FlowPane parent; + private EventObserver observer; + + + /* Constructor */ + public Article(FlowPane p_parent, EventObserver observer){ + this.parent = p_parent; + this.items = new ArrayList(); + this.observer = observer; + } + + public void addItem(String p_title, String p_content, Date p_publ, ArrayList p_tags) throws IOException { + + /* (1) Load the article_disp.fxml */ + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(getClass().getResource("/fxml/article_disp.fxml")); + + /* (2) Get the loaded item*/ + AnchorPane item = (AnchorPane) loader.load(); + + /* (3) Set content */ + this.gsetContent( p_content, item ); + + /* (4) Set date */ + this.gsetDate( p_publ.toString(), item ); + + /* (5) Set title */ + HBox headerContainer = (HBox) item.getChildren().get(3); + this.gsetTitle( p_title, headerContainer ); + + /* (6) Set tags */ + this.gsetTags( p_tags, headerContainer ); + + /* (7) Bind event */ + item.setOnMousePressed(new EventHandler() { + @Override + public void handle(MouseEvent event) { + Article.this.observer.handleEvent(new Classes.Event(item.getId(),"changeMainLayout")); + } + }); + + /* (8) Add to the controller local */ + this.items.add(item); + + /* (9) On bind au width du parent */ + item.prefWidthProperty().bind(this.parent.widthProperty()); + item.maxWidthProperty().bind(this.parent.widthProperty()); + + /* (10) Add to parent (graphics) */ + this.parent.getChildren().add(item); + } + + + + public void gsetContent(String p_content, AnchorPane p_parent){ + /* (1) Get node */ + Text g_content = (Text) p_parent.getChildren().get(1); + + /* (2) Update content */ + g_content.setText(p_content); + } + + + public void gsetDate(String p_date, AnchorPane p_parent){ + /* (1) Get node */ + Text g_date = (Text) p_parent.getChildren().get(2); + + /* (2) Update content */ + g_date.setText(p_date); + + } + + + public void gsetTitle(String p_title, HBox p_parent){ + /* (1) Get node */ + Text g_title = (Text) p_parent.getChildren().get(0); + + /* (2) Update title */ + g_title.setText(p_title); + } + + + public void gsetTags(ArrayList p_tags, HBox p_parent) throws IOException{ + + /* (1) For each tag -> load a new one */ + for( TagType tag : p_tags ){ + + /* (1.1) Create the container */ + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(getClass().getResource("/fxml/article_tag_disp.fxml")); + + /* (1.2) Load the tag elements */ + Pane g_tag = (Pane) loader.load(); + Text g_tagText = (Text) g_tag.getChildren().get(0); + + /* (1.3) Update the tag name */ + g_tagText.setText(tag.getLabel()); + + /* (1.4) Set the custom color */ + g_tag.setStyle("-fx-background-color: "+tag.getColor()); + + /* (1.5) Ajout au parent*/ + p_parent.getChildren().add(g_tag); + + } + } + +} diff --git a/controller/RootLayout.java b/controller/RootLayout.java index b2d6ece..2efc8e2 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -1,30 +1,25 @@ package controller; import java.io.IOException; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.Date; -import org.json.JSONObject; - -import Classes.ApiCall; import Classes.Category; -import Classes.Languages; import Classes.SortTypes; +import Classes.TagType; import Classes.css.user.ContextBuilder; -import Classes.css.user.HeaderStyleSheet; import Classes.css.user.HeaderIconStyleSheet; +import Classes.css.user.HeaderStyleSheet; import Classes.css.user.MenuStyleSheet; import Classes.css.user.SubMenuStyleSheet; -import Interfaces.Callback; import Interfaces.Event; import Interfaces.EventObserver; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; -import javafx.scene.control.MenuBar; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; -import model.LangModel; import model.NewsListModel; public class RootLayout extends Application implements EventObserver { @@ -32,6 +27,7 @@ public class RootLayout extends Application implements EventObserver { private Stage root_stage; private Scene root_scene; private AnchorPane root_layout; + private FlowPane main_container; @@ -48,9 +44,12 @@ public class RootLayout extends Application implements EventObserver { /* (3) Load the CSS CONTEXT */ ContextBuilder.createContext(); + /* (3) Store container */ + this.main_container = (FlowPane) this.root_scene.lookup("#container"); - /* (1) HEADER + + /* (1) Create controllers' views -------------------------------------*/ /* (1) Create header menu */ HeaderMenu hm = new HeaderMenu((FlowPane) this.root_scene.lookup("#header_menu"),this); @@ -61,6 +60,15 @@ public class RootLayout extends Application implements EventObserver { hm.addItem("menu", "/src/header-menu.png"); + /* (2) Create container */ + Article artCtl = new Article(this.main_container, this); + ArrayList tags = new ArrayList(); + tags.add(TagType.science); tags.add(TagType.economics); + + artCtl.addItem("Article 1", "blabla bloblo blibli", new Date(12), tags); + + + /* (2) CSS -------------------------------------*/ diff --git a/fxml/article_disp.fxml b/fxml/article_disp.fxml new file mode 100644 index 0000000..d8a01d0 --- /dev/null +++ b/fxml/article_disp.fxml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fxml/article_tag_disp.fxml b/fxml/article_tag_disp.fxml new file mode 100644 index 0000000..02adbaa --- /dev/null +++ b/fxml/article_tag_disp.fxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fxml/header_menu_disp.fxml b/fxml/header_menu_disp.fxml deleted file mode 100644 index 9e78237..0000000 --- a/fxml/header_menu_disp.fxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/fxml/model.fxml b/fxml/model.fxml index 49f9cfe..695c627 100644 --- a/fxml/model.fxml +++ b/fxml/model.fxml @@ -1,10 +1,12 @@ + + @@ -52,80 +54,60 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fxml/root_disp.fxml b/fxml/root_disp.fxml deleted file mode 100644 index 348ddc7..0000000 --- a/fxml/root_disp.fxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - From 217d64e44ed9932e1fec4117cdd7a4922ad1c2f1 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 19 Nov 2017 14:44:40 +0100 Subject: [PATCH 4/4] Article fetch [ok] --- Classes/Category.java | 22 +++++++++++- Classes/TagType.java | 17 --------- controller/Article.java | 74 ++++++++++++++++++++++---------------- controller/HeaderMenu.java | 2 +- controller/RootLayout.java | 34 ++++++++++++------ model/NewsListModel.java | 4 ++- model/NewsModel.java | 14 ++++++++ 7 files changed, 105 insertions(+), 62 deletions(-) delete mode 100644 Classes/TagType.java diff --git a/Classes/Category.java b/Classes/Category.java index d5a2cf8..f910b19 100644 --- a/Classes/Category.java +++ b/Classes/Category.java @@ -1,5 +1,25 @@ package Classes; public enum Category { - business, entertainment, gaming, general, healthAndMedical, music, politics, scienceAndNature, sport, technology, all +// business, entertainment, gaming, general, healthAndMedical, music, politics, scienceAndNature, sport, technology, all + + all("all", "black"), + business("business", "red"), + entertainment("entertainment", "skyblue"), + gaming("gaming", "green"), + health("health", "yellow"), + music("music", "purple"), + sport("sport", "brown"), + science("science", "#f14405"), + nature("nature", "#16c668"), + economics("economics", "#d1991b"), + politics("politics", "#6825f4"), + technology("technology", "#1e7ebe"); + + protected String color; + protected String label; + Category(String label, String color){ this.label = label; this.color = color; } + + public String getLabel(){ return this.label; } + public String getColor(){ return this.color; } } diff --git a/Classes/TagType.java b/Classes/TagType.java deleted file mode 100644 index 7f7a9d8..0000000 --- a/Classes/TagType.java +++ /dev/null @@ -1,17 +0,0 @@ -package Classes; - -public enum TagType { - science("science", "#f14405"), - nature("nature", "#16c668"), - economics("economics", "#d1991b"), - politics("politics", "#6825f4"), - technology("technology", "#1e7ebe"); - - protected String color; - protected String label; - TagType(String label, String color){ this.label = label; this.color = color; } - - public String getLabel(){ return this.label; } - public String getColor(){ return this.color; } - -} \ No newline at end of file diff --git a/controller/Article.java b/controller/Article.java index 41d7f09..45fcb57 100644 --- a/controller/Article.java +++ b/controller/Article.java @@ -4,21 +4,17 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Date; -import Classes.TagType; +import Classes.Category; import Interfaces.EventObserver; -import javafx.event.EventHandler; +import javafx.application.Platform; import javafx.fxml.FXMLLoader; -import javafx.geometry.Insets; -import javafx.scene.input.MouseEvent; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; -import javafx.scene.layout.CornerRadii; import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.paint.Paint; import javafx.scene.text.Text; +import model.NewsModel; public class Article{ @@ -35,7 +31,7 @@ public class Article{ this.observer = observer; } - public void addItem(String p_title, String p_content, Date p_publ, ArrayList p_tags) throws IOException { + public void addItem(NewsModel model) throws IOException { /* (1) Load the article_disp.fxml */ FXMLLoader loader = new FXMLLoader(); @@ -45,35 +41,42 @@ public class Article{ AnchorPane item = (AnchorPane) loader.load(); /* (3) Set content */ - this.gsetContent( p_content, item ); + this.gsetContent( model.getDescription(), item ); /* (4) Set date */ - this.gsetDate( p_publ.toString(), item ); + this.gsetDate( model.getDate(), item ); /* (5) Set title */ HBox headerContainer = (HBox) item.getChildren().get(3); - this.gsetTitle( p_title, headerContainer ); + this.gsetTitle( model.getTitle(), headerContainer ); /* (6) Set tags */ - this.gsetTags( p_tags, headerContainer ); + this.gsetTags( model.getTags(), headerContainer ); - /* (7) Bind event */ - item.setOnMousePressed(new EventHandler() { - @Override - public void handle(MouseEvent event) { - Article.this.observer.handleEvent(new Classes.Event(item.getId(),"changeMainLayout")); - } - }); + /* (7) Set image */ + this.gsetImage( model.getImageURL(), item ); - /* (8) Add to the controller local */ + /* (8) Bind event */ +// item.setOnMousePressed(new EventHandler() { +// @Override +// public void handle(MouseEvent event) { +// Article.this.observer.handleEvent(new Classes.Event(item.getId(),"changeMainLayout")); +// } +// }); + + /* (9) Add to the controller local */ this.items.add(item); - /* (9) On bind au width du parent */ + /* (10) On bind au width du parent */ item.prefWidthProperty().bind(this.parent.widthProperty()); item.maxWidthProperty().bind(this.parent.widthProperty()); - /* (10) Add to parent (graphics) */ - this.parent.getChildren().add(item); + /* (11) Add to parent (graphics) */ + Platform.runLater(new Runnable(){ + public void run(){ + Article.this.parent.getChildren().add(item); + } + }); } @@ -87,12 +90,12 @@ public class Article{ } - public void gsetDate(String p_date, AnchorPane p_parent){ + public void gsetDate(Date p_date, AnchorPane p_parent){ /* (1) Get node */ Text g_date = (Text) p_parent.getChildren().get(2); /* (2) Update content */ - g_date.setText(p_date); + g_date.setText(p_date.toString()); } @@ -104,20 +107,29 @@ public class Article{ /* (2) Update title */ g_title.setText(p_title); } + + + public void gsetImage(String p_uri, AnchorPane p_parent){ + /* (1) Get node */ + ImageView g_image = (ImageView) p_parent.getChildren().get(0); + + /* (2) Update title */ + g_image.setImage(new Image(p_uri)); + } - public void gsetTags(ArrayList p_tags, HBox p_parent) throws IOException{ + public void gsetTags(ArrayList p_tags, HBox p_parent) throws IOException{ /* (1) For each tag -> load a new one */ - for( TagType tag : p_tags ){ + for( Category tag : p_tags ){ /* (1.1) Create the container */ FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/fxml/article_tag_disp.fxml")); /* (1.2) Load the tag elements */ - Pane g_tag = (Pane) loader.load(); - Text g_tagText = (Text) g_tag.getChildren().get(0); + FlowPane g_tag = (FlowPane) loader.load(); + Text g_tagText = (Text) g_tag.getChildren().get(0); /* (1.3) Update the tag name */ g_tagText.setText(tag.getLabel()); diff --git a/controller/HeaderMenu.java b/controller/HeaderMenu.java index 1565e01..2a2cc75 100644 --- a/controller/HeaderMenu.java +++ b/controller/HeaderMenu.java @@ -35,7 +35,7 @@ public class HeaderMenu{ menuItem.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { - HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(),"changeMainLayout")); + HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(), "changeMainLayout")); } }); diff --git a/controller/RootLayout.java b/controller/RootLayout.java index 2efc8e2..673734b 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -2,11 +2,9 @@ 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; @@ -21,6 +19,7 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; import model.NewsListModel; +import model.NewsModel; public class RootLayout extends Application implements EventObserver { @@ -28,7 +27,7 @@ public class RootLayout extends Application implements EventObserver { private Scene root_scene; private AnchorPane root_layout; private FlowPane main_container; - + private Article articles; @Override @@ -61,12 +60,7 @@ public class RootLayout extends Application implements EventObserver { /* (2) Create container */ - Article artCtl = new Article(this.main_container, this); - ArrayList tags = new ArrayList(); - tags.add(TagType.science); tags.add(TagType.economics); - - artCtl.addItem("Article 1", "blabla bloblo blibli", new Date(12), tags); - + this.articles = new Article(this.main_container, this); /* (2) CSS @@ -141,16 +135,34 @@ public class RootLayout extends Application implements EventObserver { 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()); + + // For each news + for( NewsModel news : NewsListModel.getInstance().getNews() ){ + + try{ + + this.articles.addItem( news ); + + }catch(Exception e1){ + + System.out.println("Cannot fetch article data"); + e1.printStackTrace(); + + } + } + 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; diff --git a/model/NewsListModel.java b/model/NewsListModel.java index 8fccc2e..5e3aa39 100644 --- a/model/NewsListModel.java +++ b/model/NewsListModel.java @@ -149,12 +149,14 @@ public class NewsListModel implements Observable{ for(int i = 0;i tags; private Date date; + public NewsModel(){ + this.tags = new ArrayList(); + } + public NewsModel addTag(Category tag) { + this.tags.add(tag); + return this; + } public String getAuthor() { return author; @@ -40,6 +51,9 @@ public class NewsModel { public String getNewsURL() { return newsURL; } + public ArrayList getTags() { + return tags; + } public NewsModel setNewsURL(String newsURL) { this.newsURL = newsURL; return this;