package model; import Interfaces.Event; import Interfaces.EventObserver; import javafx.event.EventHandler; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; public class HeaderMenuItem extends ImageView{ private final String name; private EventObserver parentHandler; /* Constructor * * @param p_name The name of the menu item * @param p_image_uri The URI of the image * */ public HeaderMenuItem(String p_name, String p_image_uri, EventObserver parent){ this.name = p_name; this.parentHandler = parent; this.setImage(new Image(p_image_uri)); this.setId("header_menu_item_"+p_name); this.getStyleClass().add("header_menu_item"); this.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { HeaderMenuItem.this.sendEvent(new Classes.Event(HeaderMenuItem.this.getId(),"click")); } }); } public void sendEvent(Event e) { this.parentHandler.handleEvent(e); } public String getName(){ return this.name; } }