JavaFX/controller/HeaderMenu.java

48 lines
1.1 KiB
Java
Raw Permalink Normal View History

2017-11-14 07:22:26 +00:00
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;
2017-11-14 07:22:26 +00:00
import javafx.scene.layout.FlowPane;
public class HeaderMenu{
/* Data */
private ArrayList<ImageView> items;
private FlowPane parent;
private EventObserver observer;
2017-11-14 07:22:26 +00:00
/* Constructor */
public HeaderMenu(FlowPane p_parent, EventObserver observer){
this.parent = p_parent;
this.items = new ArrayList<ImageView>();
this.observer = observer;
2017-11-14 07:22:26 +00:00
}
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<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
2017-11-19 13:44:40 +00:00
HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(), "changeMainLayout"));
}
});
this.items.add(menuItem);
// Add to parent
parent.getChildren().add(menuItem);
2017-11-14 07:22:26 +00:00
}
}