This commit is contained in:
parent
e680376c54
commit
50f1246a99
|
@ -17,102 +17,110 @@ import javafx.scene.text.Text;
|
||||||
import model.NewsModel;
|
import model.NewsModel;
|
||||||
|
|
||||||
public class Article{
|
public class Article{
|
||||||
|
|
||||||
/* Data */
|
/* Data */
|
||||||
private ArrayList<AnchorPane> items;
|
private ArrayList<AnchorPane> items;
|
||||||
private FlowPane parent;
|
private FlowPane parent;
|
||||||
private EventObserver observer;
|
private EventObserver observer;
|
||||||
|
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
public Article(FlowPane p_parent, EventObserver observer){
|
public Article(FlowPane p_parent, EventObserver observer){
|
||||||
this.parent = p_parent;
|
|
||||||
this.items = new ArrayList<AnchorPane>();
|
/* (1) Attributes
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
this.parent = p_parent;
|
||||||
|
this.items = new ArrayList<AnchorPane>();
|
||||||
this.observer = observer;
|
this.observer = observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItem(NewsModel model) throws IOException {
|
public synchronized void addItem(NewsModel model) throws IOException {
|
||||||
|
|
||||||
/* (1) Load the article_disp.fxml */
|
/* (1) Get the loaded item*/
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/article_disp.fxml") );
|
||||||
loader.setLocation(getClass().getResource("/fxml/article_disp.fxml"));
|
|
||||||
|
|
||||||
/* (2) Get the loaded item*/
|
|
||||||
AnchorPane item = (AnchorPane) loader.load();
|
AnchorPane item = (AnchorPane) loader.load();
|
||||||
|
|
||||||
/* (3) Set content */
|
/* (2) Set content */
|
||||||
this.gsetContent( model.getDescription(), item );
|
this.gsetContent( model.getDescription(), item );
|
||||||
|
|
||||||
/* (4) Set date */
|
/* (3) Set date */
|
||||||
this.gsetDate( model.getDate(), item );
|
this.gsetDate( model.getDate(), item );
|
||||||
|
|
||||||
/* (5) Set title */
|
/* (4) Set title */
|
||||||
HBox headerContainer = (HBox) item.getChildren().get(3);
|
HBox headerContainer = (HBox) item.getChildren().get(3);
|
||||||
this.gsetTitle( model.getTitle(), headerContainer );
|
this.gsetTitle( model.getTitle(), headerContainer );
|
||||||
|
|
||||||
/* (6) Set tags */
|
/* (5) Set tags */
|
||||||
this.gsetTags( model.getTags(), headerContainer );
|
this.gsetTags( model.getTags(), headerContainer );
|
||||||
|
|
||||||
/* (7) Set image */
|
/* (6) Set image */
|
||||||
this.gsetImage( model.getImageURL(), item );
|
this.gsetImage( model.getImageURL(), item );
|
||||||
|
|
||||||
/* (8) Bind event */
|
/* (7) Bind event */
|
||||||
// item.setOnMousePressed(new EventHandler<MouseEvent>() {
|
// item.setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||||
// @Override
|
// @Override
|
||||||
// public void handle(MouseEvent event) {
|
// public void handle(MouseEvent event) {
|
||||||
// Article.this.observer.handleEvent(new Classes.Event(item.getId(),"changeMainLayout"));
|
// Article.this.observer.handleEvent(new Classes.Event(item.getId(),"changeMainLayout"));
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
/* (9) Add to the controller local */
|
/* (8) Add to the controller local */
|
||||||
this.items.add(item);
|
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.prefWidthProperty().bind(this.parent.widthProperty());
|
||||||
item.maxWidthProperty().bind(this.parent.widthProperty());
|
item.maxWidthProperty().bind(this.parent.widthProperty());
|
||||||
|
|
||||||
/* (11) Add to parent (graphics) */
|
}
|
||||||
|
|
||||||
|
public void display(){
|
||||||
|
|
||||||
Platform.runLater(new Runnable(){
|
Platform.runLater(new Runnable(){
|
||||||
public void run(){
|
public void run(){
|
||||||
Article.this.parent.getChildren().add(item);
|
|
||||||
|
for( AnchorPane item : items )
|
||||||
|
Article.this.parent.getChildren().add(item);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void gsetContent(String p_content, AnchorPane p_parent){
|
public void gsetContent(String p_content, AnchorPane p_parent){
|
||||||
/* (1) Get node */
|
/* (1) Get node */
|
||||||
Text g_content = (Text) p_parent.getChildren().get(1);
|
Text g_content = (Text) p_parent.getChildren().get(1);
|
||||||
|
|
||||||
/* (2) Update content */
|
/* (2) Update content */
|
||||||
g_content.setText(p_content);
|
g_content.setText(p_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gsetDate(Date p_date, AnchorPane p_parent){
|
public void gsetDate(Date p_date, AnchorPane p_parent){
|
||||||
/* (1) Get node */
|
/* (1) Get node */
|
||||||
Text g_date = (Text) p_parent.getChildren().get(2);
|
Text g_date = (Text) p_parent.getChildren().get(2);
|
||||||
|
|
||||||
/* (2) Update content */
|
/* (2) Update content */
|
||||||
g_date.setText(p_date.toString());
|
g_date.setText(p_date.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gsetTitle(String p_title, HBox p_parent){
|
public void gsetTitle(String p_title, HBox p_parent){
|
||||||
/* (1) Get node */
|
/* (1) Get node */
|
||||||
Text g_title = (Text) p_parent.getChildren().get(0);
|
Text g_title = (Text) p_parent.getChildren().get(0);
|
||||||
|
|
||||||
/* (2) Update title */
|
/* (2) Update title */
|
||||||
g_title.setText(p_title);
|
g_title.setText(p_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gsetImage(String p_uri, AnchorPane p_parent){
|
public void gsetImage(String p_uri, AnchorPane p_parent){
|
||||||
/* (1) Get node */
|
/* (1) Get node */
|
||||||
ImageView g_image = (ImageView) p_parent.getChildren().get(0);
|
ImageView g_image = (ImageView) p_parent.getChildren().get(0);
|
||||||
|
|
||||||
/* (2) Update title */
|
/* (2) Update title */
|
||||||
try{
|
try{
|
||||||
g_image.setImage(new Image(p_uri));
|
g_image.setImage(new Image(p_uri));
|
||||||
|
@ -120,31 +128,28 @@ public class Article{
|
||||||
System.out.println("Cannot find image URL: '"+p_uri+"'");
|
System.out.println("Cannot find image URL: '"+p_uri+"'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gsetTags(ArrayList<Category> p_tags, HBox p_parent) throws IOException{
|
public void gsetTags(ArrayList<Category> p_tags, HBox p_parent) throws IOException{
|
||||||
|
|
||||||
/* (1) For each tag -> load a new one */
|
/* (1) For each tag -> load a new one */
|
||||||
for( Category tag : p_tags ){
|
for( Category tag : p_tags ){
|
||||||
|
|
||||||
/* (1.1) Create the container */
|
/* (1.1) Load the tag elements */
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/article_tag_disp.fxml") );
|
||||||
loader.setLocation(getClass().getResource("/fxml/article_tag_disp.fxml"));
|
|
||||||
|
|
||||||
/* (1.2) Load the tag elements */
|
|
||||||
FlowPane g_tag = (FlowPane) loader.load();
|
FlowPane g_tag = (FlowPane) loader.load();
|
||||||
Text g_tagText = (Text) g_tag.getChildren().get(0);
|
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());
|
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());
|
g_tag.setStyle("-fx-background-color: "+tag.getColor());
|
||||||
|
|
||||||
/* (1.5) Ajout au parent*/
|
/* (1.4) Ajout au parent*/
|
||||||
p_parent.getChildren().add(g_tag);
|
p_parent.getChildren().add(g_tag);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,9 +175,11 @@ public class RootLayout extends Application implements EventObserver {
|
||||||
this.articles.addItem( news );
|
this.articles.addItem( news );
|
||||||
}catch(Exception e1){
|
}catch(Exception e1){
|
||||||
System.out.println("Cannot fetch article data");
|
System.out.println("Cannot fetch article data");
|
||||||
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
this.articles.display();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* (3) articles.query.error -> display error ('no result') */
|
/* (3) articles.query.error -> display error ('no result') */
|
||||||
|
|
|
@ -76,8 +76,8 @@ public class NewsListModel implements Observable{
|
||||||
//on rajoute la clé d'api
|
//on rajoute la clé d'api
|
||||||
URL += "&apiKey="+this.APIKey;
|
URL += "&apiKey="+this.APIKey;
|
||||||
|
|
||||||
//création de l'appel
|
// Création de l'appel
|
||||||
ApiCall api = new ApiCall(URL,"GET",new Callback() {
|
ApiCall api = new ApiCall(URL, "GET", new Callback(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(JSONObject response) {
|
public void onSuccess(JSONObject response) {
|
||||||
|
|
Loading…
Reference in New Issue