47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
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<String> The name of the menu item
|
|
* @param p_image_uri<String> 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<MouseEvent>() {
|
|
@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;
|
|
}
|
|
|
|
}
|