Search in sources :

Example 16 with GridPane

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

the class BarChartSample method start.

@Override
public void start(Stage stage) {
    stage.setTitle("Country statistics with jOOQ and JavaFX");
    Label error = new Label("");
    error.setPadding(new Insets(10.0));
    // Create two charts, plotting a specific metric, each.
    BarChart<String, Number> chart1 = chart(COUNTRIES.GDP_PER_CAPITA, "GDP per Capita", "USD");
    BarChart<String, Number> chart2 = chart(COUNTRIES.GOVT_DEBT, "Government Debt", "% of GDP");
    TableView<CountriesRecord> table = table(COUNTRIES);
    Runnable refresh = () -> {
        table.getItems().clear();
        table.getItems().addAll(ctx().fetch(COUNTRIES).sortAsc(COUNTRIES.YEAR).sortAsc(COUNTRIES.CODE));
        chartRefresh(chart1);
        chartRefresh(chart2);
        error.setText("");
        selected = ctx().newRecord(COUNTRIES);
    };
    refresh.run();
    table.getSelectionModel().getSelectedItems().addListener((Change<? extends CountriesRecord> c) -> {
        if (c.getList().isEmpty())
            selected = ctx().newRecord(COUNTRIES);
        else
            for (CountriesRecord record : c.getList()) selected = record;
    });
    GridPane editPane = new GridPane();
    int i = 0;
    for (Field<?> field : COUNTRIES.fields()) {
        Label label = new Label(field.getName());
        TextField textField = new TextField();
        textField.textProperty().addListener((o, oldV, newV) -> {
            selected.set((Field) field, newV);
        });
        table.getSelectionModel().getSelectedItems().addListener((Change<? extends CountriesRecord> c) -> {
            if (c.getList().isEmpty())
                textField.setText("");
            else
                for (CountriesRecord record : c.getList()) textField.setText(record.get(field, String.class));
        });
        editPane.addRow(i++, label, textField);
    }
    Button saveButton = new Button("Save");
    saveButton.setOnAction(event -> {
        try {
            if (selected.store() > 0)
                refresh.run();
        } catch (DataAccessException e) {
            e.printStackTrace();
            error.setText(e.sqlStateClass() + ": " + e.getCause().getMessage());
        }
    });
    Button deleteButton = new Button("Delete");
    deleteButton.setOnAction(event -> {
        try {
            if (selected.delete() > 0)
                refresh.run();
        } catch (DataAccessException e) {
            e.printStackTrace();
            error.setText(e.sqlStateClass() + ": " + e.getCause().getMessage());
        }
    });
    GridPane buttonPane = new GridPane();
    buttonPane.addRow(0, saveButton, deleteButton);
    editPane.addRow(i++, new Label(""), buttonPane);
    GridPane chartPane = new GridPane();
    chartPane.addColumn(0, chart1, chart2);
    grow(chartPane);
    GridPane display = new GridPane();
    display.addRow(0, chartPane, table, editPane);
    grow(display);
    GridPane displayAndStatus = new GridPane();
    displayAndStatus.addColumn(0, display, error);
    displayAndStatus.setGridLinesVisible(true);
    grow(displayAndStatus);
    Scene scene = new Scene(displayAndStatus, 1000, 800);
    stage.setScene(scene);
    stage.show();
}
Also used : Insets(javafx.geometry.Insets) GridPane(javafx.scene.layout.GridPane) CountriesRecord(org.jooq.generated.tables.records.CountriesRecord) Label(javafx.scene.control.Label) Change(javafx.collections.ListChangeListener.Change) Scene(javafx.scene.Scene) Button(javafx.scene.control.Button) TextField(javafx.scene.control.TextField) DataAccessException(org.jooq.exception.DataAccessException)

Example 17 with GridPane

use of javafx.scene.layout.GridPane in project DistributedFractalNetwork by Budder21.

the class ExportImageTool method exportImage.

/**
	 * This method is where the actual menus and user interaction happens. First, a window appears allowing the user to specify the
	 * resolution of the image. After that, the user chooses a directory and a file name and exports it as an image.
	 * When the image is done rendering and saving, a final menu will pop up informing the user that the image was succesfully
	 * exported
	 * @param fractal the fractal to be exported as an image
	 */
public void exportImage(RenderManager fractal) {
    Dimension initRes = fractal.getScreenResolution();
    Dialog<Pair<String, String>> dialog = new Dialog<>();
    dialog.setTitle("Export Fractal");
    dialog.setHeaderText("Step 1");
    dialog.setContentText("Choose a resolution:");
    ButtonType loginButtonType = new ButtonType("Continue", ButtonData.OK_DONE);
    dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 150, 10, 10));
    TextField widthField = new TextField("1600");
    widthField.textProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            if (!newValue.matches("\\d*")) {
                widthField.setText(newValue.replaceAll("[^\\d]", ""));
            }
        }
    });
    TextField heightField = new TextField("1600");
    heightField.textProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            if (!newValue.matches("\\d*")) {
                heightField.setText(newValue.replaceAll("[^\\d]", ""));
            }
        }
    });
    grid.add(new Label("Width:"), 0, 0);
    grid.add(widthField, 1, 0);
    grid.add(new Label("Height:"), 0, 1);
    grid.add(heightField, 1, 1);
    dialog.getDialogPane().setContent(grid);
    dialog.setResultConverter(dialogButton -> {
        if (dialogButton == loginButtonType)
            return new Pair<String, String>(widthField.getText(), heightField.getText());
        return null;
    });
    Optional<Pair<String, String>> result = dialog.showAndWait();
    int width = 0;
    int height = 0;
    try {
        width = Integer.valueOf(result.get().getKey());
        height = Integer.valueOf(result.get().getValue());
    } catch (NumberFormatException e) {
        AlertMenu aMenu = new AlertMenu("INVALID INPUT: Must be an integer.", "INVALID INPUT: Must be an integer.");
        exportImage(fractal);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Export Fractal");
    alert.setHeaderText("Step 2");
    alert.setContentText("Choose a directory:");
    ButtonType buttonTypeOne = new ButtonType("Choose");
    ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
    alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);
    Optional<ButtonType> result2 = alert.showAndWait();
    if (result2.get() == buttonTypeOne) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("My Fractal.png");
        fileChooser.setTitle("Select File Destination");
        FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Images (*.png, *.jpg)", "*.png", "*.jpg");
        fileChooser.getExtensionFilters().add(filter);
        File file = fileChooser.showSaveDialog(null);
        String formatName = file.getName().substring(file.getName().indexOf(".") + 1);
        if (file != null) {
            try {
                file.createNewFile();
                fractal.setScreenResolution(new Dimension(width, height));
                ImageIO.write(fractal.getImage(), formatName, file);
                Alert alert2 = new Alert(AlertType.INFORMATION);
                alert2.setTitle("Export Fractal");
                alert2.setHeaderText(null);
                alert2.setContentText("Image Succesfully Saved.");
                alert2.showAndWait();
                fractal.setScreenResolution(initRes);
            } catch (Exception e) {
                fractal.setScreenResolution(initRes);
            }
        }
    } else {
        return;
    }
}
Also used : Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) Dialog(javafx.scene.control.Dialog) FileChooser(javafx.stage.FileChooser) TextField(javafx.scene.control.TextField) ButtonType(javafx.scene.control.ButtonType) Pair(javafx.util.Pair) GridPane(javafx.scene.layout.GridPane) Dimension(java.awt.Dimension) Alert(javafx.scene.control.Alert) File(java.io.File)

Example 18 with GridPane

use of javafx.scene.layout.GridPane in project DistributedFractalNetwork by Budder21.

the class OpacityBox method display.

public static double display(ArrowButton button) {
    //TODO this isn't working correctly
    Slider opacityLevel = new Slider(0, 1, (Double) button.getData());
    Label opacityCaption = new Label("Opacity Level:");
    Label opacityValue = new Label(Double.toString(opacityLevel.getValue()));
    Stage window = new Stage();
    window.setTitle("Opacity Picker");
    window.setMinWidth(450);
    window.setMinHeight(100);
    window.initModality(Modality.APPLICATION_MODAL);
    Group root = new Group();
    Scene scene = new Scene(root);
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(10);
    grid.setHgap(70);
    scene.setRoot(grid);
    GridPane.setConstraints(opacityCaption, 0, 1);
    grid.getChildren().add(opacityCaption);
    opacityLevel.valueProperty().addListener(new ChangeListener<Number>() {

        public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
            System.out.println(new_val.doubleValue());
            opacityValue.setText(String.format("%.2f", new_val));
        }
    });
    GridPane.setConstraints(opacityLevel, 1, 1);
    grid.getChildren().add(opacityLevel);
    GridPane.setConstraints(opacityValue, 2, 1);
    grid.getChildren().add(opacityValue);
    Button b = new Button("Submit");
    b.setOnAction(e -> {
        window.close();
    });
    GridPane.setConstraints(b, 2, 2);
    grid.getChildren().add(b);
    window.setOnCloseRequest(e -> {
    });
    window.setScene(scene);
    window.show();
    return opacityLevel.getValue();
}
Also used : Group(javafx.scene.Group) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Slider(javafx.scene.control.Slider) Button(javafx.scene.control.Button) Label(javafx.scene.control.Label) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene)

Example 19 with GridPane

use of javafx.scene.layout.GridPane in project POL-POM-5 by PlayOnLinux.

the class WinePrefixContainerInputTab method populate.

private void populate() {
    final VBox inputPane = new VBox();
    final Text title = new TextWithStyle(tr("Input settings"), TITLE_CSS_CLASS);
    inputPane.getStyleClass().add(CONFIGURATION_PANE_CSS_CLASS);
    inputPane.getChildren().add(title);
    final GridPane inputContentPane = new GridPane();
    inputContentPane.getStyleClass().add("grid");
    final ComboBox<MouseWarpOverride> mouseWarpOverrideComboBox = new ComboBox<>();
    mouseWarpOverrideComboBox.setValue(container.getMouseWarpOverride());
    addItems(mouseWarpOverrideComboBox, MouseWarpOverride.class);
    inputContentPane.add(new TextWithStyle(tr("Mouse Warp Override"), CAPTION_TITLE_CSS_CLASS), 0, 0);
    inputContentPane.add(mouseWarpOverrideComboBox, 1, 0);
    inputContentPane.getColumnConstraints().addAll(new ColumnConstraintsWithPercentage(30), new ColumnConstraintsWithPercentage(70));
    inputPane.getChildren().addAll(inputContentPane);
    this.setContent(inputPane);
    lockableElements.add(mouseWarpOverrideComboBox);
}
Also used : TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) ColumnConstraintsWithPercentage(org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage) GridPane(javafx.scene.layout.GridPane) ComboBox(javafx.scene.control.ComboBox) MouseWarpOverride(org.phoenicis.containers.wine.parameters.MouseWarpOverride) Text(javafx.scene.text.Text) VBox(javafx.scene.layout.VBox)

Example 20 with GridPane

use of javafx.scene.layout.GridPane in project POL-POM-5 by PlayOnLinux.

the class WinePrefixContainerWineToolsTab method populate.

private void populate() {
    final VBox toolsPane = new VBox();
    final Text title = new TextWithStyle(tr("Wine tools"), TITLE_CSS_CLASS);
    toolsPane.getStyleClass().add(CONFIGURATION_PANE_CSS_CLASS);
    toolsPane.getChildren().add(title);
    final GridPane toolsContentPane = new GridPane();
    toolsContentPane.getStyleClass().add("grid");
    Button configureWine = new Button(tr("Configure Wine"));
    configureWine.getStyleClass().addAll("wineToolButton", "configureWine");
    configureWine.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.runInPrefix(container, "winecfg", this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(configureWine, HPos.CENTER);
    Button registryEditor = new Button(tr("Registry Editor"));
    registryEditor.getStyleClass().addAll("wineToolButton", "registryEditor");
    registryEditor.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.runInPrefix(container, "regedit", this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(registryEditor, HPos.CENTER);
    Button rebootWindows = new Button(tr("Windows reboot"));
    rebootWindows.getStyleClass().addAll("wineToolButton", "rebootWindows");
    rebootWindows.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.runInPrefix(container, "wineboot", this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(rebootWindows, HPos.CENTER);
    Button repairVirtualDrive = new Button(tr("Repair virtual drive"));
    repairVirtualDrive.getStyleClass().addAll("wineToolButton", "repairVirtualDrive");
    repairVirtualDrive.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.repairPrefix(container, this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(repairVirtualDrive, HPos.CENTER);
    Button commandPrompt = new Button(tr("Command prompt"));
    commandPrompt.getStyleClass().addAll("wineToolButton", "commandPrompt");
    commandPrompt.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.runInPrefix(container, "wineconsole", this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(commandPrompt, HPos.CENTER);
    Button taskManager = new Button(tr("Task manager"));
    taskManager.getStyleClass().addAll("wineToolButton", "taskManager");
    taskManager.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.runInPrefix(container, "taskmgr", this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(taskManager, HPos.CENTER);
    Button killProcesses = new Button(tr("Kill processes"));
    killProcesses.getStyleClass().addAll("wineToolButton", "killProcesses");
    killProcesses.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.killProcesses(container, this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(killProcesses, HPos.CENTER);
    Button uninstallWine = new Button(tr("Wine uninstaller"));
    uninstallWine.getStyleClass().addAll("wineToolButton", "uninstallWine");
    uninstallWine.setOnMouseClicked(event -> {
        this.lockAll();
        winePrefixContainerController.runInPrefix(container, "uninstaller", this::unlockAll, e -> Platform.runLater(() -> new ErrorMessage("Error", e).show()));
    });
    GridPane.setHalignment(uninstallWine, HPos.CENTER);
    this.lockableElements.addAll(Arrays.asList(configureWine, registryEditor, rebootWindows, repairVirtualDrive, commandPrompt, taskManager, uninstallWine));
    toolsContentPane.add(configureWine, 0, 0);
    toolsContentPane.add(wineToolCaption(tr("Configure Wine")), 0, 1);
    toolsContentPane.add(registryEditor, 1, 0);
    toolsContentPane.add(wineToolCaption(tr("Registry Editor")), 1, 1);
    toolsContentPane.add(rebootWindows, 2, 0);
    toolsContentPane.add(wineToolCaption(tr("Windows reboot")), 2, 1);
    toolsContentPane.add(repairVirtualDrive, 3, 0);
    toolsContentPane.add(wineToolCaption(tr("Repair virtual drive")), 3, 1);
    toolsContentPane.add(commandPrompt, 0, 3);
    toolsContentPane.add(wineToolCaption(tr("Command prompt")), 0, 4);
    toolsContentPane.add(taskManager, 1, 3);
    toolsContentPane.add(wineToolCaption(tr("Task manager")), 1, 4);
    toolsContentPane.add(killProcesses, 2, 3);
    toolsContentPane.add(wineToolCaption(tr("Kill processes")), 2, 4);
    toolsContentPane.add(uninstallWine, 3, 3);
    toolsContentPane.add(wineToolCaption(tr("Wine uninstaller")), 3, 4);
    toolsPane.getChildren().addAll(toolsContentPane);
    toolsContentPane.getColumnConstraints().addAll(new ColumnConstraintsWithPercentage(25), new ColumnConstraintsWithPercentage(25), new ColumnConstraintsWithPercentage(25), new ColumnConstraintsWithPercentage(25));
    this.setContent(toolsPane);
}
Also used : TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) ColumnConstraintsWithPercentage(org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage) GridPane(javafx.scene.layout.GridPane) Button(javafx.scene.control.Button) Text(javafx.scene.text.Text) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) VBox(javafx.scene.layout.VBox)

Aggregations

GridPane (javafx.scene.layout.GridPane)34 Label (javafx.scene.control.Label)22 Insets (javafx.geometry.Insets)13 Button (javafx.scene.control.Button)9 TextField (javafx.scene.control.TextField)9 Scene (javafx.scene.Scene)7 TextWithStyle (org.phoenicis.javafx.views.common.TextWithStyle)7 Dialog (javafx.scene.control.Dialog)6 VBox (javafx.scene.layout.VBox)6 Text (javafx.scene.text.Text)5 Stage (javafx.stage.Stage)5 Pair (javafx.util.Pair)5 ButtonType (javafx.scene.control.ButtonType)4 Region (javafx.scene.layout.Region)4 JFXButton (com.jfoenix.controls.JFXButton)3 MaterialDesignIconView (de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Node (javafx.scene.Node)3 ScrollPane (javafx.scene.control.ScrollPane)3