2017-11-14 07:22:26 +00:00
|
|
|
package controller;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2017-11-15 15:13:07 +00:00
|
|
|
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 */
|
2017-11-15 15:13:07 +00:00
|
|
|
private ArrayList<ImageView> items;
|
2017-11-14 08:09:25 +00:00
|
|
|
private FlowPane parent;
|
2017-11-15 15:13:07 +00:00
|
|
|
private EventObserver observer;
|
2017-11-14 07:22:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Constructor */
|
2017-11-15 15:13:07 +00:00
|
|
|
public HeaderMenu(FlowPane p_parent, EventObserver observer){
|
2017-11-14 08:09:25 +00:00
|
|
|
this.parent = p_parent;
|
2017-11-15 15:13:07 +00:00
|
|
|
this.items = new ArrayList<ImageView>();
|
|
|
|
this.observer = observer;
|
2017-11-14 07:22:26 +00:00
|
|
|
}
|
2017-11-15 15:13:07 +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) {
|
|
|
|
HeaderMenu.this.observer.handleEvent(new Classes.Event(menuItem.getId(),"click"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.items.add(menuItem);
|
2017-11-14 08:09:25 +00:00
|
|
|
// Add to parent
|
2017-11-15 15:13:07 +00:00
|
|
|
parent.getChildren().add(menuItem);
|
2017-11-14 07:22:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|