Search in sources :

Example 1 with ToolBar

use of javafx.scene.control.ToolBar in project aima-java by aimacode.

the class ConnectFourApp method createRootPane.

@Override
public Pane createRootPane() {
    model = new ConnectFourModel();
    BorderPane root = new BorderPane();
    ToolBar toolBar = new ToolBar();
    toolBar.setStyle("-fx-background-color: rgb(0, 0, 200)");
    clearBtn = new Button("Clear");
    clearBtn.setOnAction(ev -> model.initGame());
    strategyCombo = new ComboBox<>();
    strategyCombo.getItems().addAll("Iterative Deepening Alpha-Beta", "Advanced Alpha-Beta");
    strategyCombo.getSelectionModel().select(0);
    timeCombo = new ComboBox<>();
    timeCombo.getItems().addAll("2sec", "4sec", "6sec", "8sec");
    timeCombo.getSelectionModel().select(1);
    proposeBtn = new Button("Propose Move");
    proposeBtn.setOnAction(ev -> model.proposeMove((timeCombo.getSelectionModel().getSelectedIndex() + 1) * 2, strategyCombo.getSelectionModel().getSelectedIndex()));
    toolBar.getItems().addAll(clearBtn, new Separator(), strategyCombo, timeCombo, proposeBtn);
    root.setTop(toolBar);
    final int rows = model.getRows();
    final int cols = model.getCols();
    BorderPane boardPane = new BorderPane();
    ColumnConstraints colCons = new ColumnConstraints();
    colCons.setPercentWidth(100.0 / cols);
    GridPane btnPane = new GridPane();
    GridPane diskPane = new GridPane();
    btnPane.setHgap(10);
    btnPane.setPadding(new Insets(10, 10, 0, 10));
    btnPane.setStyle("-fx-background-color: rgb(0, 50, 255)");
    diskPane.setPadding(new Insets(10, 10, 10, 10));
    diskPane.setStyle("-fx-background-color: rgb(0, 50, 255)");
    colBtns = new Button[cols];
    for (int i = 0; i < cols; i++) {
        Button colBtn = new Button("" + (i + 1));
        colBtn.setId("" + (i + 1));
        colBtn.setMaxWidth(Double.MAX_VALUE);
        colBtn.setOnAction(ev -> {
            String id = ((Button) ev.getSource()).getId();
            int col = Integer.parseInt(id);
            model.makeMove(col - 1);
        });
        colBtns[i] = colBtn;
        btnPane.add(colBtn, i, 0);
        GridPane.setHalignment(colBtn, HPos.CENTER);
        btnPane.getColumnConstraints().add(colCons);
        diskPane.getColumnConstraints().add(colCons);
    }
    boardPane.setTop(btnPane);
    diskPane.setMinSize(0, 0);
    diskPane.setPrefSize(cols * 100, rows * 100);
    RowConstraints rowCons = new RowConstraints();
    rowCons.setPercentHeight(100.0 / rows);
    for (int i = 0; i < rows; i++) diskPane.getRowConstraints().add(rowCons);
    disks = new Circle[rows * cols];
    for (int i = 0; i < rows * cols; i++) {
        Circle disk = new Circle(30);
        disk.radiusProperty().bind(Bindings.min(Bindings.divide(diskPane.widthProperty(), cols * 3), Bindings.divide(diskPane.heightProperty(), rows * 3)));
        disks[i] = disk;
        diskPane.add(disk, i % cols, i / cols);
        GridPane.setHalignment(disk, HPos.CENTER);
    }
    boardPane.setCenter(diskPane);
    root.setCenter(boardPane);
    statusBar = new Label();
    statusBar.setMaxWidth(Double.MAX_VALUE);
    statusBar.setStyle("-fx-background-color: rgb(0, 0, 200); -fx-font-size: 20");
    root.setBottom(statusBar);
    model.addObserver(this::update);
    return root;
}
Also used : Circle(javafx.scene.shape.Circle) BorderPane(javafx.scene.layout.BorderPane) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Label(javafx.scene.control.Label) RowConstraints(javafx.scene.layout.RowConstraints) Button(javafx.scene.control.Button) ToolBar(javafx.scene.control.ToolBar) Separator(javafx.scene.control.Separator)

Example 2 with ToolBar

use of javafx.scene.control.ToolBar in project aima-java by aimacode.

the class SimulationPaneBuilder method getResultFor.

/**
	 * Adds a toolbar, a state view, and a status label to the provided pane and returns
	 * a controller class instance. The toolbar contains combo boxes to control parameter settings
	 * and buttons for simulation control. The controller class instance handles user events and provides
	 * access to user settings (parameter settings, simulation speed, status text, ...).
	 */
public SimulationPaneCtrl getResultFor(BorderPane pane) {
    List<ComboBox<String>> combos = new ArrayList<>();
    parameters.add(createSimSpeedParam());
    for (Parameter param : parameters) {
        ComboBox<String> combo = new ComboBox<>();
        combo.setId(param.getName());
        combo.getItems().addAll(param.getValueNames());
        combo.getSelectionModel().select(param.getDefaultValueIndex());
        combos.add(combo);
    }
    Button simBtn = new Button();
    Node[] tools = new Node[combos.size() + 2];
    for (int i = 0; i < combos.size() - 1; i++) tools[i] = combos.get(i);
    tools[combos.size() - 1] = new Separator();
    tools[combos.size() + 0] = combos.get(combos.size() - 1);
    tools[combos.size() + 1] = simBtn;
    ToolBar toolBar = new ToolBar(tools);
    Label statusLabel = new Label();
    statusLabel.setMaxWidth(Double.MAX_VALUE);
    statusLabel.setAlignment(Pos.CENTER);
    statusLabel.setFont(Font.font(16));
    pane.setTop(toolBar);
    if (stateView.isPresent()) {
        if (stateView.get() instanceof Canvas) {
            // make canvas resizable
            Canvas canvas = (Canvas) stateView.get();
            Pane canvasPane = new Pane();
            canvasPane.getChildren().add(canvas);
            canvas.widthProperty().bind(canvasPane.widthProperty());
            canvas.heightProperty().bind(canvasPane.heightProperty());
            pane.setCenter(canvasPane);
            pane.setStyle("-fx-background-color: white");
        } else
            pane.setCenter(stateView.get());
    }
    pane.setBottom(statusLabel);
    if (!initMethod.isPresent())
        throw new IllegalStateException("No initialization method defined.");
    if (!simMethod.isPresent())
        throw new IllegalStateException("No simulation method defined.");
    return new SimulationPaneCtrl(parameters, combos, initMethod.get(), simMethod.get(), simBtn, statusLabel);
}
Also used : ComboBox(javafx.scene.control.ComboBox) Node(javafx.scene.Node) Canvas(javafx.scene.canvas.Canvas) ArrayList(java.util.ArrayList) Label(javafx.scene.control.Label) BorderPane(javafx.scene.layout.BorderPane) Pane(javafx.scene.layout.Pane) Button(javafx.scene.control.Button) ToolBar(javafx.scene.control.ToolBar) Separator(javafx.scene.control.Separator)

Example 3 with ToolBar

use of javafx.scene.control.ToolBar in project jgnash by ccavanaugh.

the class MainView method start.

public void start(final Stage stage, @Nullable final File dataFile, final char[] password, @Nullable final String host, final int port) throws Exception {
    ThemeManager.restoreLastUsedTheme();
    primaryStage = stage;
    busyPane = new BusyPane();
    final FXMLLoader fxmlLoader = new FXMLLoader(MenuBarController.class.getResource("MainMenuBar.fxml"), resources);
    menuBar = fxmlLoader.load();
    final ToolBar mainToolBar = FXMLLoader.load(MainToolBarController.class.getResource("MainToolBar.fxml"), resources);
    tabViewPane = new TabViewPane();
    final VBox top = new VBox();
    top.getChildren().addAll(menuBar, mainToolBar);
    top.setFillWidth(true);
    statusBar = new StatusBar();
    final BorderPane borderPane = new BorderPane();
    borderPane.setTop(top);
    borderPane.setCenter(tabViewPane);
    borderPane.setBottom(statusBar);
    final StackPane stackPane = new StackPane();
    stackPane.getChildren().addAll(borderPane, busyPane);
    final Scene scene = new Scene(stackPane, 640, 480);
    scene.getStylesheets().add(DEFAULT_CSS);
    scene.getRoot().styleProperty().bind(ThemeManager.styleProperty());
    stage.setTitle(title);
    stage.getIcons().add(StaticUIMethods.getApplicationIcon());
    stage.setScene(scene);
    stage.setResizable(true);
    // enforce a min width to prevent it from disappearing with a bad click and drag
    stage.setMinWidth(640);
    stage.setMinHeight(480);
    installHandlers();
    MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM);
    StageUtils.addBoundsListener(stage, MainView.class);
    stage.show();
    Engine.addLogHandler(statusBarLogHandler);
    EngineFactory.addLogHandler(statusBarLogHandler);
    YahooParser.addLogHandler(statusBarLogHandler);
    UpdateFactory.addLogHandler(statusBarLogHandler);
    // listen to my own logger
    logger.addHandler(statusBarLogHandler);
    stage.toFront();
    stage.requestFocus();
    if (host != null) {
        // connect to a remote server instead of loading a local file
        new Thread(() -> {
            try {
                Thread.sleep(BootEngineTask.FORCED_DELAY);
                backgroundExecutor.execute(() -> JavaFXUtils.runLater(() -> BootEngineTask.initiateBoot(null, password, true, host, port)));
            } catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }).start();
    } else if (dataFile != null) {
        // Load the specified file, this overrides the last open file
        new Thread(() -> {
            try {
                Thread.sleep(BootEngineTask.FORCED_DELAY);
                backgroundExecutor.execute(() -> JavaFXUtils.runLater(() -> BootEngineTask.initiateBoot(dataFile.getAbsolutePath(), password, false, null, 0)));
            } catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }).start();
    } else if (Options.openLastProperty().get()) {
        // Load the last open file if enabled
        new Thread(() -> {
            try {
                Thread.sleep(BootEngineTask.FORCED_DELAY);
                backgroundExecutor.execute(() -> JavaFXUtils.runLater(BootEngineTask::openLast));
            } catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }).start();
    }
    loadPlugins();
    checkForLatestRelease();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) StatusBar(jgnash.uifx.control.StatusBar) TabViewPane(jgnash.uifx.control.TabViewPane) BusyPane(jgnash.uifx.control.BusyPane) BootEngineTask(jgnash.uifx.tasks.BootEngineTask) ToolBar(javafx.scene.control.ToolBar) VBox(javafx.scene.layout.VBox) StackPane(javafx.scene.layout.StackPane)

Aggregations

ToolBar (javafx.scene.control.ToolBar)3 BorderPane (javafx.scene.layout.BorderPane)3 Button (javafx.scene.control.Button)2 Label (javafx.scene.control.Label)2 Separator (javafx.scene.control.Separator)2 ArrayList (java.util.ArrayList)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Insets (javafx.geometry.Insets)1 Node (javafx.scene.Node)1 Scene (javafx.scene.Scene)1 Canvas (javafx.scene.canvas.Canvas)1 ComboBox (javafx.scene.control.ComboBox)1 ColumnConstraints (javafx.scene.layout.ColumnConstraints)1 GridPane (javafx.scene.layout.GridPane)1 Pane (javafx.scene.layout.Pane)1 RowConstraints (javafx.scene.layout.RowConstraints)1 StackPane (javafx.scene.layout.StackPane)1 VBox (javafx.scene.layout.VBox)1 Circle (javafx.scene.shape.Circle)1 BusyPane (jgnash.uifx.control.BusyPane)1