Search in sources :

Example 1 with RowConstraints

use of javafx.scene.layout.RowConstraints 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 RowConstraints

use of javafx.scene.layout.RowConstraints in project aima-java by aimacode.

the class NQueensViewCtrl method update.

/** Updates the view. */
public void update(NQueensBoard board) {
    int size = board.getSize();
    if (queens.length != size * size) {
        gridPane.getChildren().clear();
        gridPane.getColumnConstraints().clear();
        gridPane.getRowConstraints().clear();
        queens = new Polygon[size * size];
        RowConstraints c1 = new RowConstraints();
        c1.setPercentHeight(100.0 / size);
        ColumnConstraints c2 = new ColumnConstraints();
        c2.setPercentWidth(100.0 / size);
        for (int i = 0; i < board.getSize(); i++) {
            gridPane.getRowConstraints().add(c1);
            gridPane.getColumnConstraints().add(c2);
        }
        for (int i = 0; i < queens.length; i++) {
            StackPane field = new StackPane();
            queens[i] = createQueen();
            field.getChildren().add(queens[i]);
            int col = i % size;
            int row = i / size;
            field.setBackground(new Background(new BackgroundFill((col % 2 == row % 2) ? Color.WHITE : Color.LIGHTGRAY, null, null)));
            gridPane.add(field, col, row);
        }
    }
    double scale = 0.2 * gridPane.getWidth() / gridPane.getColumnConstraints().size();
    for (int i = 0; i < queens.length; i++) {
        Polygon queen = queens[i];
        queen.setScaleX(scale);
        queen.setScaleY(scale);
        XYLocation loc = new XYLocation(i % size, i / size);
        if (board.queenExistsAt(loc)) {
            queen.setVisible(true);
            queen.setFill(board.isSquareUnderAttack(loc) ? Color.RED : Color.BLACK);
        } else {
            queen.setVisible(false);
        }
    }
}
Also used : Background(javafx.scene.layout.Background) XYLocation(aima.core.util.datastructure.XYLocation) ColumnConstraints(javafx.scene.layout.ColumnConstraints) BackgroundFill(javafx.scene.layout.BackgroundFill) Polygon(javafx.scene.shape.Polygon) StackPane(javafx.scene.layout.StackPane) RowConstraints(javafx.scene.layout.RowConstraints)

Example 3 with RowConstraints

use of javafx.scene.layout.RowConstraints in project ParadoxosModManager by ThibautSF.

the class OnlineVersionChecker method showUpdateWindow.

/**
 * Generate a javafx alert and confirmation window to inform about a new version (and ask what he want to do)
 *
 * @param changelog the content of the scrollable textarea
 */
private void showUpdateWindow(String changelog) {
    dialog = new Stage();
    dialog.setTitle("Paradoxos Mod Manager - Update Available");
    dialog.setResizable(false);
    GridPane expContent = new GridPane();
    Scene scene = new Scene(expContent, 575, 420);
    Text contentText = new Text(String.format("A new version of %s is available online !\nLocal : %s\nOnline : %s\n", ModManager.APP_NAME, VERSION, lastestOnlineVersionNumber));
    RowConstraints row1 = new RowConstraints();
    row1.setPercentHeight(0);
    RowConstraints row2 = new RowConstraints();
    row2.setPrefHeight(scene.getHeight() - 80);
    RowConstraints row3 = new RowConstraints();
    row3.setMinHeight(50);
    row3.setPrefHeight(50);
    row3.setMaxHeight(50);
    RowConstraints row4 = new RowConstraints();
    row4.setPercentHeight(0);
    expContent.getRowConstraints().addAll(row1, row2, row3, row4);
    expContent.setVgap(10);
    ColumnConstraints col1 = new ColumnConstraints();
    col1.setPercentWidth(0);
    ColumnConstraints col2 = new ColumnConstraints();
    col2.setPercentWidth(100);
    ColumnConstraints col3 = new ColumnConstraints();
    col3.setPercentWidth(0);
    expContent.getColumnConstraints().addAll(col1, col2, col3);
    expContent.setHgap(10);
    // expContent.setGridLinesVisible(true);
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.autosize();
    VBox content = new VBox();
    expContent.add(content, 1, 1);
    content.getChildren().add(contentText);
    if (changelog.length() > 0 && !changelog.equals("No changelog available")) {
        Label label = new Label("CHANGELOG:");
        TextArea textArea = new TextArea(changelog);
        textArea.setEditable(false);
        textArea.setWrapText(true);
        textArea.setMaxWidth(Double.MAX_VALUE);
        textArea.setMaxHeight(Double.MAX_VALUE);
        VBox.setVgrow(textArea, Priority.ALWAYS);
        content.getChildren().addAll(label, textArea);
    }
    HBox buttons = new HBox(10);
    Button buttonWebAll = new Button("All versions\n(with source)");
    Button buttonWebDownload = new Button("Get Update\n(autoinstall)");
    Button buttonCancel = new Button("Continue\n(Stay " + VERSION + ")");
    buttonWebAll.setOnAction((e) -> {
        goURL(URL_APP_RELEASES);
    });
    buttonWebDownload.setOnAction((e) -> {
        startDownload(dialog);
    });
    buttonCancel.setOnAction((e) -> {
        dialog.close();
    });
    buttons.getChildren().addAll(buttonWebAll, buttonWebDownload, buttonCancel);
    buttons.setAlignment(Pos.BOTTOM_RIGHT);
    expContent.add(buttons, 1, 2);
    dialog.setScene(scene);
    dialog.showAndWait();
}
Also used : HBox(javafx.scene.layout.HBox) GridPane(javafx.scene.layout.GridPane) TextArea(javafx.scene.control.TextArea) Button(javafx.scene.control.Button) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Label(javafx.scene.control.Label) Stage(javafx.stage.Stage) Text(javafx.scene.text.Text) Scene(javafx.scene.Scene) VBox(javafx.scene.layout.VBox) RowConstraints(javafx.scene.layout.RowConstraints)

Example 4 with RowConstraints

use of javafx.scene.layout.RowConstraints in project jabref by JabRef.

the class EntryEditorTab method setupPanel.

private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, boolean compressed, String title) {
    setupKeyBindings(panel.getInputMap(JComponent.WHEN_FOCUSED), panel.getActionMap());
    panel.setName(title);
    editors.clear();
    List<Label> labels = new ArrayList<>();
    for (String fieldName : fields) {
        // TODO: Reenable/migrate this
        // Store the editor for later reference:
        /*
            FieldEditor fieldEditor;
            int defaultHeight;
            int wHeight = (int) (50.0 * InternalBibtexFields.getFieldWeight(field));
            if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) {
                fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
                        true);
                defaultHeight = 0;
            } else if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
                fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
                        false);
                defaultHeight = 0;
            } else {
                fieldEditor = new TextArea(field, null, getPrompt(field));
                //parent.addSearchListener((TextArea) fieldEditor);
                defaultHeight = fieldEditor.getPane().getPreferredSize().height;
            }
            
            Optional<JComponent> extra = parent.getExtra(fieldEditor);
            
            // Add autocompleter listener, if required for this field:
            /*
            AutoCompleter<String> autoCompleter = bPanel.getAutoCompleters().get(field);
            AutoCompleteListener autoCompleteListener = null;
            if (autoCompleter != null) {
                autoCompleteListener = new AutoCompleteListener(autoCompleter);
            }
            setupJTextComponent(fieldEditor.getTextComponent(), autoCompleteListener);
            fieldEditor.setAutoCompleteListener(autoCompleteListener);
            */
        FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext(), entry.getType());
        fieldEditor.bindToEntry(entry);
        editors.put(fieldName, fieldEditor);
        /*
            // TODO: Reenable this
            if (i == 0) {
                activeField = fieldEditor;
            }
            */
        /*
            // TODO: Reenable this
            if (!compressed) {
                fieldEditor.getPane().setPreferredSize(new Dimension(100, Math.max(defaultHeight, wHeight)));
            }
            */
        /*
            // TODO: Reenable content selector
            if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(editor.getFieldName()).isEmpty()) {
                FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false,
                        ", ");
                contentSelectors.add(ws);
                controls.add(ws, BorderLayout.NORTH);
            }
            //} else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) {
            //return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction);
             */
        labels.add(new FieldNameLabel(fieldName));
    }
    GridPane gridPane = new GridPane();
    gridPane.setPrefSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
    gridPane.setMaxSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
    gridPane.getStyleClass().add("editorPane");
    ColumnConstraints columnExpand = new ColumnConstraints();
    columnExpand.setHgrow(Priority.ALWAYS);
    ColumnConstraints columnDoNotContract = new ColumnConstraints();
    columnDoNotContract.setMinWidth(Region.USE_PREF_SIZE);
    int rows;
    if (compressed) {
        rows = (int) Math.ceil((double) fields.size() / 2);
        addColumn(gridPane, 0, labels.subList(0, rows));
        addColumn(gridPane, 3, labels.subList(rows, labels.size()));
        addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode).limit(rows));
        addColumn(gridPane, 4, editors.values().stream().map(FieldEditorFX::getNode).skip(rows));
        gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand, new ColumnConstraints(10), columnDoNotContract, columnExpand);
    } else {
        rows = fields.size();
        addColumn(gridPane, 0, labels);
        addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode));
        gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand);
    }
    RowConstraints rowExpand = new RowConstraints();
    rowExpand.setVgrow(Priority.ALWAYS);
    if (rows == 0) {
        rowExpand.setPercentHeight(100);
    } else {
        rowExpand.setPercentHeight(100 / rows);
    }
    for (int i = 0; i < rows; i++) {
        gridPane.getRowConstraints().add(rowExpand);
    }
    return gridPane;
}
Also used : FXDialogService(org.jabref.gui.FXDialogService) FieldNameLabel(org.jabref.gui.fieldeditors.FieldNameLabel) GridPane(javafx.scene.layout.GridPane) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ArrayList(java.util.ArrayList) FieldNameLabel(org.jabref.gui.fieldeditors.FieldNameLabel) Label(javafx.scene.control.Label) FieldEditorFX(org.jabref.gui.fieldeditors.FieldEditorFX) RowConstraints(javafx.scene.layout.RowConstraints)

Example 5 with RowConstraints

use of javafx.scene.layout.RowConstraints in project CSCI-6461-Simulator by lkstc112233.

the class NewMain method start.

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Virtual Machine");
    machine = new MachineWrapper(new Machine());
    mapping = new HashMap<>();
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    for (int j = 0; j < 3; ++j) {
        ColumnConstraints cc = new ColumnConstraints();
        cc.setPercentWidth(100 / 3.);
        grid.getColumnConstraints().add(cc);
    }
    for (int j = 0; j < 6; ++j) {
        RowConstraints cc = new RowConstraints();
        cc.setPercentHeight(100 / 6.);
        grid.getRowConstraints().add(cc);
    }
    grid.setHgap(50);
    grid.setVgap(10);
    grid.setPadding(new Insets(50, 50, 50, 50));
    Scene scene = new Scene(grid, 800, 600);
    primaryStage.setScene(scene);
    grid.add(getBox(grid, "Tick: ", machine.getTickProperty().asString()), 0, 0);
    grid.add(getBox(grid, "PC: ", machine.getProgramCounterProperty()), 0, 1);
    grid.add(getBox(grid, "BUS: ", machine.getBusProperty()), 0, 2);
    grid.add(getBox(grid, "MAR: ", machine.getMemoryAddressRegisterProperty()), 0, 3);
    grid.add(getBox(grid, "MBR: ", machine.getMemoryBufferRegisterProperty()), 0, 4);
    grid.add(getBox(grid, "IR: ", machine.getInstructionRegisterProperty()), 0, 5);
    grid.add(getBox(grid, "GPRF: ", machine.getGeneralPurposeRegisterFileProperty()), 1, 0, 1, 2);
    grid.add(getBox(grid, "IRF: ", machine.getIndexRegisterFileProperty()), 1, 2, 1, 2);
    grid.add(getBox(grid, "Control Unit: ", machine.getControlUnitProperty()), 1, 4);
    grid.add(getScrollBox(grid, "Memory: ", machine.getMemoryProperty()), 2, 0, 1, 6);
    automaticTick = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            machine.tick();
        }
    }));
    automaticTick.setCycleCount(Timeline.INDEFINITE);
    HBox buttons = new HBox();
    buttons.setSpacing(10);
    grid.add(buttons, 0, 6, 3, 1);
    Button btn = new Button("Tick");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            machine.tick();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Auto tick on/off");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            if (Status.RUNNING == automaticTick.getStatus())
                automaticTick.pause();
            else
                automaticTick.play();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Show magic panel");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            getControlPanel().show();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Show front panel");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            getFrontPanel().show();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Show screen panel");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            getScreenPanel().show();
        }
    });
    buttons.getChildren().add(btn);
    scene.getStylesheets().add("/res/css/background.css");
    primaryStage.show();
}
Also used : HBox(javafx.scene.layout.HBox) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ActionEvent(javafx.event.ActionEvent) MachineWrapper(increment.simulator.userInterface.MachineWrapper) Scene(javafx.scene.Scene) Machine(increment.simulator.Machine) RowConstraints(javafx.scene.layout.RowConstraints) Timeline(javafx.animation.Timeline) Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame)

Aggregations

ColumnConstraints (javafx.scene.layout.ColumnConstraints)8 RowConstraints (javafx.scene.layout.RowConstraints)8 GridPane (javafx.scene.layout.GridPane)6 Button (javafx.scene.control.Button)4 Insets (javafx.geometry.Insets)3 Scene (javafx.scene.Scene)3 Label (javafx.scene.control.Label)3 HBox (javafx.scene.layout.HBox)3 ActionEvent (javafx.event.ActionEvent)2 BorderPane (javafx.scene.layout.BorderPane)2 Stage (javafx.stage.Stage)2 XYLocation (aima.core.util.datastructure.XYLocation)1 Machine (increment.simulator.Machine)1 MachineWrapper (increment.simulator.userInterface.MachineWrapper)1 ArrayList (java.util.ArrayList)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 RadioButton (javafx.scene.control.RadioButton)1 Separator (javafx.scene.control.Separator)1 TextArea (javafx.scene.control.TextArea)1