This commit is contained in:
xdrm-brackets 2017-11-28 08:26:58 +01:00
parent e680376c54
commit 50f1246a99
3 changed files with 69 additions and 62 deletions

View File

@ -26,37 +26,37 @@ public class Article{
/* Constructor */
public Article(FlowPane p_parent, EventObserver observer){
/* (1) Attributes
---------------------------------------------------------*/
this.parent = p_parent;
this.items = new ArrayList<AnchorPane>();
this.observer = observer;
}
public void addItem(NewsModel model) throws IOException {
public synchronized void addItem(NewsModel model) 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*/
/* (1) Get the loaded item*/
FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/article_disp.fxml") );
AnchorPane item = (AnchorPane) loader.load();
/* (3) Set content */
/* (2) Set content */
this.gsetContent( model.getDescription(), item );
/* (4) Set date */
/* (3) Set date */
this.gsetDate( model.getDate(), item );
/* (5) Set title */
/* (4) Set title */
HBox headerContainer = (HBox) item.getChildren().get(3);
this.gsetTitle( model.getTitle(), headerContainer );
/* (6) Set tags */
/* (5) Set tags */
this.gsetTags( model.getTags(), headerContainer );
/* (7) Set image */
/* (6) Set image */
this.gsetImage( model.getImageURL(), item );
/* (8) Bind event */
/* (7) Bind event */
// item.setOnMousePressed(new EventHandler<MouseEvent>() {
// @Override
// public void handle(MouseEvent event) {
@ -64,19 +64,27 @@ public class Article{
// }
// });
/* (9) Add to the controller local */
/* (8) Add to the controller local */
this.items.add(item);
/* (10) On bind au width du parent */
/* (9) On bind au width du parent */
item.prefWidthProperty().bind(this.parent.widthProperty());
item.maxWidthProperty().bind(this.parent.widthProperty());
/* (11) Add to parent (graphics) */
}
public void display(){
Platform.runLater(new Runnable(){
public void run(){
for( AnchorPane item : items )
Article.this.parent.getChildren().add(item);
}
});
}
@ -127,21 +135,18 @@ public class Article{
/* (1) For each tag -> load a new one */
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 */
/* (1.1) Load the tag elements */
FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/article_tag_disp.fxml") );
FlowPane g_tag = (FlowPane) loader.load();
Text g_tagText = (Text) g_tag.getChildren().get(0);
/* (1.3) Update the tag name */
/* (1.2) Update the tag name */
g_tagText.setText(tag.getLabel());
/* (1.4) Set the custom color */
/* (1.3) Set the custom color */
g_tag.setStyle("-fx-background-color: "+tag.getColor());
/* (1.5) Ajout au parent*/
/* (1.4) Ajout au parent*/
p_parent.getChildren().add(g_tag);
}

View File

@ -175,9 +175,11 @@ public class RootLayout extends Application implements EventObserver {
this.articles.addItem( news );
}catch(Exception e1){
System.out.println("Cannot fetch article data");
e1.printStackTrace();
}
}
this.articles.display();
break;
/* (3) articles.query.error -> display error ('no result') */

View File

@ -76,7 +76,7 @@ public class NewsListModel implements Observable{
//on rajoute la clé d'api
URL += "&apiKey="+this.APIKey;
//création de l'appel
// Création de l'appel
ApiCall api = new ApiCall(URL, "GET", new Callback(){
@Override