JavaFX/controller/HeaderMenu.java

48 lines
1.1 KiB
Java

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<ImageView> items;
private FlowPane parent;
private EventObserver observer;
/* Constructor */
public HeaderMenu(FlowPane p_parent, EventObserver observer){
this.parent = p_parent;
this.items = new ArrayList<ImageView>();
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<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(), "changeMainLayout"));
}
});
this.items.add(menuItem);
// Add to parent
parent.getChildren().add(menuItem);
}
}