JavaFX/controller/MainMenu.java

48 lines
1.1 KiB
Java
Raw Normal View History

2017-12-12 07:58: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;
import javafx.scene.layout.FlowPane;
public class MainMenu{
/* Data */
private ArrayList<ImageView> items;
private FlowPane parent;
private EventObserver observer;
/* Constructor */
public MainMenu(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) {
MainMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(), "changeMainLayout"));
}
});
this.items.add(menuItem);
// Add to parent
parent.getChildren().add(menuItem);
}
}