Search in sources :

Example 1 with ColumnConstraints

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

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

use of javafx.scene.layout.ColumnConstraints in project jOOQ by jOOQ.

the class BarChartSample method grow.

private void grow(GridPane pane) {
    ColumnConstraints col = new ColumnConstraints();
    col.setFillWidth(true);
    col.setHgrow(Priority.ALWAYS);
    pane.getColumnConstraints().add(col);
    RowConstraints row = new RowConstraints();
    row.setFillHeight(true);
    row.setVgrow(Priority.ALWAYS);
    pane.getRowConstraints().add(row);
}
Also used : ColumnConstraints(javafx.scene.layout.ColumnConstraints) RowConstraints(javafx.scene.layout.RowConstraints)

Example 4 with ColumnConstraints

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

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

the class VacuumEnvironmentViewCtrl method initialize.

@Override
public void initialize(Environment env) {
    if (env instanceof VacuumEnvironment) {
        this.locations = ((VacuumEnvironment) env).getLocations();
        envStateView.getChildren().clear();
        envStateView.getColumnConstraints().clear();
        ColumnConstraints colCons = new ColumnConstraints();
        colCons.setPercentWidth(100.0 / locations.size());
        int i = 0;
        for (String loc : locations) {
            BorderPane pane = new BorderPane();
            pane.setTop(new Label(loc));
            pane.setStyle("-fx-background-color: white");
            envStateView.add(pane, i++, 0);
            envStateView.getColumnConstraints().add(colCons);
        }
    }
    super.initialize(env);
}
Also used : BorderPane(javafx.scene.layout.BorderPane) VacuumEnvironment(aima.core.environment.vacuum.VacuumEnvironment) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Label(javafx.scene.control.Label)

Aggregations

ColumnConstraints (javafx.scene.layout.ColumnConstraints)7 RowConstraints (javafx.scene.layout.RowConstraints)5 Label (javafx.scene.control.Label)3 GridPane (javafx.scene.layout.GridPane)3 BorderPane (javafx.scene.layout.BorderPane)2 VacuumEnvironment (aima.core.environment.vacuum.VacuumEnvironment)1 XYLocation (aima.core.util.datastructure.XYLocation)1 BusyAnimation (io.bitsquare.gui.components.BusyAnimation)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 ArrayList (java.util.ArrayList)1 Insets (javafx.geometry.Insets)1 Button (javafx.scene.control.Button)1 Separator (javafx.scene.control.Separator)1 ToolBar (javafx.scene.control.ToolBar)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 HBox (javafx.scene.layout.HBox)1 StackPane (javafx.scene.layout.StackPane)1 Circle (javafx.scene.shape.Circle)1 Polygon (javafx.scene.shape.Polygon)1