75 lines
1.8 KiB
Java
75 lines
1.8 KiB
Java
package controller;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import Interfaces.EventObserver;
|
|
import javafx.event.EventHandler;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.ImageView;
|
|
import javafx.scene.input.MouseEvent;
|
|
import javafx.scene.layout.FlowPane;
|
|
|
|
public class HeaderMenu{
|
|
|
|
/* (1) Attributes
|
|
---------------------------------------------------------*/
|
|
private ArrayList<ImageView> items;
|
|
private FlowPane parent;
|
|
private EventObserver observer;
|
|
|
|
|
|
/* Constructor */
|
|
|
|
/* (2) Constructor
|
|
*
|
|
* @p_parent<FlowPane> gParent element
|
|
* @observer<EventObserver> Main observer (to send event to)
|
|
*
|
|
---------------------------------------------------------*/
|
|
public HeaderMenu(FlowPane p_parent, EventObserver observer){
|
|
|
|
this.parent = p_parent;
|
|
this.items = new ArrayList<ImageView>();
|
|
this.observer = observer;
|
|
|
|
}
|
|
|
|
|
|
/* (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
|
|
*
|
|
---------------------------------------------------------*/
|
|
public void addItem(String p_name, String p_image_uri) {
|
|
|
|
/* (1) Create ImageView */
|
|
ImageView menuItem = new ImageView();
|
|
|
|
/* (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' */
|
|
menuItem.setOnMousePressed(new EventHandler<MouseEvent>() {
|
|
|
|
@Override
|
|
public void handle(MouseEvent event) {
|
|
|
|
HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(), "changeMainLayout"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/* (4) Add item to list */
|
|
this.items.add(menuItem);
|
|
|
|
/* (5) Add gitem to gparent */
|
|
parent.getChildren().add(menuItem);
|
|
|
|
}
|
|
|
|
}
|