You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
771 B
27 lines
771 B
5 years ago
|
package xyz.wbsite.dbtool.javafx.tool;
|
||
|
|
||
|
import javafx.event.ActionEvent;
|
||
|
import javafx.event.EventHandler;
|
||
|
import javafx.scene.control.ContextMenu;
|
||
|
import javafx.scene.control.MenuItem;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class ContextMenuBuilder {
|
||
|
private List<MenuItem> menuItemList = new ArrayList<>();
|
||
|
|
||
|
public ContextMenuBuilder add(String text, EventHandler<ActionEvent> eventHandler) {
|
||
|
MenuItem menuItem = new MenuItem(text);
|
||
|
menuItem.setOnAction(eventHandler);
|
||
|
menuItemList.add(menuItem);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public ContextMenu build() {
|
||
|
MenuItem[] menuItems = new MenuItem[menuItemList.size()];
|
||
|
menuItemList.toArray(menuItems);
|
||
|
return new ContextMenu(menuItems);
|
||
|
}
|
||
|
}
|