2017-11-14 07:22:26 +00:00
|
|
|
package controller;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2017-11-15 15:13:07 +00:00
|
|
|
import Interfaces.EventObserver;
|
|
|
|
import javafx.event.EventHandler;
|
|
|
|
import javafx.scene.image.Image;
|
|
|
|
import javafx.scene.image.ImageView;
|
|
|
|
import javafx.scene.input.MouseEvent;
|
2017-11-14 07:22:26 +00:00
|
|
|
import javafx.scene.layout.FlowPane;
|
|
|
|
|
|
|
|
public class HeaderMenu{
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (1) Attributes
|
|
|
|
---------------------------------------------------------*/
|
2017-11-15 15:13:07 +00:00
|
|
|
private ArrayList<ImageView> items;
|
2017-11-19 15:30:22 +00:00
|
|
|
private FlowPane parent;
|
|
|
|
private EventObserver observer;
|
|
|
|
|
|
|
|
|
2017-11-14 07:22:26 +00:00
|
|
|
/* Constructor */
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (2) Constructor
|
|
|
|
*
|
|
|
|
* @p_parent<FlowPane> gParent element
|
|
|
|
* @observer<EventObserver> Main observer (to send event to)
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2017-11-15 15:13:07 +00:00
|
|
|
public HeaderMenu(FlowPane p_parent, EventObserver observer){
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
this.parent = p_parent;
|
|
|
|
this.items = new ArrayList<ImageView>();
|
2017-11-15 15:13:07 +00:00
|
|
|
this.observer = observer;
|
2017-11-19 15:30:22 +00:00
|
|
|
|
2017-11-14 07:22:26 +00:00
|
|
|
}
|
2017-11-15 15:13:07 +00:00
|
|
|
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (3) Add a new menu item (graphically too)
|
|
|
|
*
|
|
|
|
* @p_name<String> The new menu item's name
|
|
|
|
* @p_image_uri<String> The new menu item's image link
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2017-11-15 15:13:07 +00:00
|
|
|
public void addItem(String p_name, String p_image_uri) {
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (1) Create ImageView */
|
2017-11-15 15:13:07 +00:00
|
|
|
ImageView menuItem = new ImageView();
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (2) Set useful attributes */
|
|
|
|
menuItem.setImage(new Image(p_image_uri)); // image link
|
|
|
|
menuItem.setId("header_menu_item_"+p_name); // id
|
|
|
|
menuItem.getStyleClass().add("header_menu_item"); // css .class
|
|
|
|
|
|
|
|
/* (3) Bind event -> 'changeMainLayout' */
|
2017-11-15 15:13:07 +00:00
|
|
|
menuItem.setOnMousePressed(new EventHandler<MouseEvent>() {
|
2017-11-19 15:30:22 +00:00
|
|
|
|
2017-11-15 15:13:07 +00:00
|
|
|
@Override
|
|
|
|
public void handle(MouseEvent event) {
|
2017-11-19 15:30:22 +00:00
|
|
|
|
2017-11-19 13:44:40 +00:00
|
|
|
HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(), "changeMainLayout"));
|
2017-11-19 15:30:22 +00:00
|
|
|
|
2017-11-15 15:13:07 +00:00
|
|
|
}
|
2017-11-19 15:30:22 +00:00
|
|
|
|
2017-11-15 15:13:07 +00:00
|
|
|
});
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (4) Add item to list */
|
2017-11-15 15:13:07 +00:00
|
|
|
this.items.add(menuItem);
|
2017-11-19 15:30:22 +00:00
|
|
|
|
|
|
|
/* (5) Add gitem to gparent */
|
2017-11-15 15:13:07 +00:00
|
|
|
parent.getChildren().add(menuItem);
|
2017-11-19 15:30:22 +00:00
|
|
|
|
2017-11-14 07:22:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|