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{ /* Data */ private ArrayList items; private FlowPane parent; private EventObserver observer; /* Constructor */ public HeaderMenu(FlowPane p_parent, EventObserver observer){ this.parent = p_parent; this.items = new ArrayList(); this.observer = observer; } public void addItem(String p_name, String p_image_uri) { ImageView menuItem = new ImageView(); menuItem.setImage(new Image(p_image_uri)); menuItem.setId("header_menu_item_"+p_name); menuItem.getStyleClass().add("header_menu_item"); menuItem.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(),"click")); } }); this.items.add(menuItem); // Add to parent parent.getChildren().add(menuItem); } }