JavaFX/model/HeaderMenuItem.java

47 lines
1.1 KiB
Java
Raw Normal View History

2017-11-14 07:22:26 +00:00
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;
2017-11-14 07:22:26 +00:00
public class HeaderMenuItem extends ImageView{
2017-11-14 07:22:26 +00:00
private final String name;
private EventObserver parentHandler;
2017-11-14 07:22:26 +00:00
/* 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"));
}
});
2017-11-14 07:22:26 +00:00
}
public void sendEvent(Event e) {
this.parentHandler.handleEvent(e);
2017-11-14 07:22:26 +00:00
}
public String getName(){
return this.name;
2017-11-14 07:22:26 +00:00
}
}