Search in sources :

Example 11 with GridPane

use of javafx.scene.layout.GridPane in project trex-stateless-gui by cisco-system-traffic-generator.

the class StatsTableGenerator method generateXStatPane.

public GridPane generateXStatPane(boolean full, Port port, boolean notempty, String filter, boolean resetCounters) {
    if (full) {
        statXTable.getChildren().clear();
        Util.optimizeMemory();
    }
    Map<String, Long> xstatsList = port.getXstats();
    Map<String, Long> xstatsListPinned = port.getXstatsPinned();
    String pinnedChar = "✖";
    String notPinnedChar = "✚";
    /*String pinnedChar = "☑";
        String notPinnedChar = "☐";*/
    rowIndex = 0;
    addHeaderCell(statXTable, "xstats-header0", "Counter", 0, WIDTH_COL_0 * 1.5);
    addHeaderCell(statXTable, "xstats-header1", "Value", 1, WIDTH_COL_1);
    addHeaderCell(statXTable, "xstats-header2", "Pin", 2, WIDTH_COL_PIN);
    rowIndex = 1;
    odd = true;
    xstatsListPinned.forEach((k, v) -> {
        if (v != null) {
            if (resetCounters) {
                fixCounter(port.getIndex(), k, v);
            }
            Node check = new Label(pinnedChar);
            GridPane.setHalignment(check, HPos.CENTER);
            addXstatRow(statXTable, (event) -> xstatsListPinned.remove(k, v), "xstat-red", "xstat-green", new Tooltip("Click '" + pinnedChar + "' to un-pin the counter."), "xstats-val-0-" + rowIndex, k, WIDTH_COL_0 * 1.5, 0, "xstats-val-1-" + rowIndex, String.valueOf(v - getShadowCounter(port.getIndex(), k)), WIDTH_COL_1, 1, "xstats-val-2-" + rowIndex, pinnedChar, WIDTH_COL_PIN, 2);
        }
    });
    xstatsList.forEach((k, v) -> {
        if (v != null && (!notempty || (notempty && (v - getShadowCounter(port.getIndex(), k) != 0))) && xstatsListPinned.get(k) == null) {
            if ((filter == null || filter.trim().length() == 0) || k.contains(filter)) {
                if (resetCounters) {
                    fixCounter(port.getIndex(), k, v);
                }
                Node check = new Label(notPinnedChar);
                GridPane.setHalignment(check, HPos.CENTER);
                addXstatRow(statXTable, (event) -> xstatsListPinned.put(k, v), "xstat-green", "xstat-red", new Tooltip("Click '" + notPinnedChar + "' to pin the counter.\nPinned counter is always visible."), "xstats-val-0-" + rowIndex, k, WIDTH_COL_0 * 1.5, 0, "xstats-val-1-" + rowIndex, String.valueOf(v - getShadowCounter(port.getIndex(), k)), WIDTH_COL_1, 1, "xstats-val-2-" + rowIndex, notPinnedChar, WIDTH_COL_PIN, 2);
            }
        }
    });
    GridPane gp = new GridPane();
    gp.setGridLinesVisible(false);
    gp.add(statXTable, 1, 1, 1, 2);
    return gp;
}
Also used : GridPane(javafx.scene.layout.GridPane) Node(javafx.scene.Node) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label)

Example 12 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 13 with GridPane

use of javafx.scene.layout.GridPane in project JFoenix by jfoenixadmin.

the class JFXMasonryPane method layoutChildren.

/***************************************************************************
	 *                                                                         *
	 * Override/Inherited methods                                              *
	 *                                                                         *
	 **************************************************************************/
/**
	 * {@inheritDoc}
	 */
@Override
protected void layoutChildren() {
    performingLayout = true;
    if (!valid) {
        int col, row;
        col = (int) Math.floor(this.getWidth() / (getCellWidth() + 2 * getHSpacing()));
        col = getLimitColumn() != -1 && col > getLimitColumn() ? getLimitColumn() : col;
        if (matrix != null && col == matrix[0].length) {
            performingLayout = false;
            return;
        }
        //(int) Math.floor(this.getHeight() / (cellH + 2*vSpacing));
        row = 100;
        row = getLimitRow() != -1 && row > getLimitRow() ? getLimitRow() : row;
        matrix = new int[row][col];
        double minWidth = -1;
        double minHeight = -1;
        List<BoundingBox> newBoxes;
        List<Region> childs = new ArrayList<>();
        for (int i = 0; i < getChildren().size(); i++) if (getChildren().get(i) instanceof Region)
            childs.add((Region) getChildren().get(i));
        newBoxes = layoutMode.get().fillGrid(matrix, childs, getCellWidth(), getCellHeight(), row, col, getHSpacing(), getVSpacing());
        if (newBoxes == null) {
            performingLayout = false;
            return;
        }
        for (int i = 0; i < getChildren().size() && i < newBoxes.size(); i++) {
            Region block = (Region) getChildren().get(i);
            if (!(block instanceof GridPane)) {
                double blockX, blockY, blockWidth, blockHeight;
                if (newBoxes.get(i) != null) {
                    blockX = newBoxes.get(i).getMinY() * getCellWidth() + ((newBoxes.get(i).getMinY() + 1) * 2 - 1) * getHSpacing();
                    blockY = newBoxes.get(i).getMinX() * getCellHeight() + ((newBoxes.get(i).getMinX() + 1) * 2 - 1) * getVSpacing();
                    blockWidth = newBoxes.get(i).getWidth() * getCellWidth() + (newBoxes.get(i).getWidth() - 1) * 2 * getHSpacing();
                    blockHeight = newBoxes.get(i).getHeight() * getCellHeight() + (newBoxes.get(i).getHeight() - 1) * 2 * getVSpacing();
                } else {
                    blockX = block.getLayoutX();
                    blockY = block.getLayoutY();
                    blockWidth = -1;
                    blockHeight = -1;
                }
                if (animationMap == null) {
                    // init static children
                    block.setLayoutX(blockX);
                    block.setLayoutY(blockY);
                    block.setPrefSize(blockWidth, blockHeight);
                    block.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
                } else {
                    if (oldBoxes == null || i >= oldBoxes.size()) {
                        // handle new children
                        block.setOpacity(0);
                        block.setLayoutX(blockX);
                        block.setLayoutY(blockY);
                        block.setPrefSize(blockWidth, blockHeight);
                        block.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
                    }
                    if (newBoxes.get(i) != null) {
                        // handle children repositioning
                        animationMap.put(block, new CachedTransition(block, new Timeline(new KeyFrame(Duration.millis(2000), new KeyValue(block.opacityProperty(), 1, Interpolator.LINEAR), new KeyValue(block.layoutXProperty(), blockX, Interpolator.LINEAR), new KeyValue(block.layoutYProperty(), blockY, Interpolator.LINEAR)))) {

                            {
                                setCycleDuration(Duration.seconds(0.320));
                                setDelay(Duration.seconds(0));
                                setOnFinished((finish) -> {
                                    block.setLayoutX(blockX);
                                    block.setLayoutY(blockY);
                                    block.setOpacity(1);
                                });
                            }
                        });
                    } else {
                        // handle children is being hidden ( cause it can't fit in the pane )
                        animationMap.put(block, new CachedTransition(block, new Timeline(new KeyFrame(Duration.millis(2000), new KeyValue(block.opacityProperty(), 0, Interpolator.LINEAR), new KeyValue(block.layoutXProperty(), blockX, Interpolator.LINEAR), new KeyValue(block.layoutYProperty(), blockY, Interpolator.LINEAR)))) {

                            {
                                setCycleDuration(Duration.seconds(0.320));
                                setDelay(Duration.seconds(0));
                                setOnFinished((finish) -> {
                                    block.setLayoutX(blockX);
                                    block.setLayoutY(blockY);
                                    block.setOpacity(0);
                                });
                            }
                        });
                    }
                }
                if (newBoxes.get(i) != null) {
                    if (blockX + blockWidth > minWidth)
                        minWidth = blockX + blockWidth;
                    if (blockY + blockHeight > minHeight)
                        minHeight = blockY + blockHeight;
                }
            }
        }
        this.setMinSize(minWidth, minHeight);
        if (animationMap == null)
            animationMap = new HashMap<>();
        trans.stop();
        ParallelTransition newTransition = new ParallelTransition();
        newTransition.getChildren().addAll(animationMap.values());
        newTransition.play();
        trans = newTransition;
        oldBoxes = newBoxes;
        // FOR DEGBBUGING
        //						root.getChildren().clear();		
        //						for(int y = 0; y < matrix.length; y++){
        //							for(int x = 0; x < matrix[0].length; x++){
        //			
        //								// Create a new TextField in each Iteration
        //								Label tf = new Label();
        //								tf.setStyle(matrix[y][x] == 0 ? colors[0] : colors[matrix[y][x]%4+1]);
        //								tf.setMinWidth(getCellWidth());
        //								tf.setMinHeight(getCellHeight());
        //								tf.setAlignment(Pos.CENTER);
        //								tf.setText(matrix[y][x] + "");
        //								// Iterate the Index using the loops
        //								root.setRowIndex(tf,y);
        //								root.setColumnIndex(tf,x);    
        //								root.setMargin(tf, new Insets(getVSpacing(),getHSpacing(),getVSpacing(),getHSpacing()));
        //								root.getChildren().add(tf);
        //							}
        //						}
        valid = true;
    }
    // FOR DEGBBUGING
    //				if(!getChildren().contains(root)) getChildren().add(root);
    //				root.resizeRelocate(0, 0, this.getWidth(), this.getHeight());
    performingLayout = false;
}
Also used : javafx.beans.property(javafx.beans.property) Change(javafx.collections.ListChangeListener.Change) BoundingBox(javafx.geometry.BoundingBox) Node(javafx.scene.Node) javafx.animation(javafx.animation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CachedTransition(com.jfoenix.transitions.CachedTransition) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) ChangeListener(javafx.beans.value.ChangeListener) GridPane(javafx.scene.layout.GridPane) Pane(javafx.scene.layout.Pane) GridPane(javafx.scene.layout.GridPane) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BoundingBox(javafx.geometry.BoundingBox) Region(javafx.scene.layout.Region) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 14 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 15 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)

Aggregations

GridPane (javafx.scene.layout.GridPane)28 Label (javafx.scene.control.Label)19 Insets (javafx.geometry.Insets)8 Button (javafx.scene.control.Button)7 TextWithStyle (org.phoenicis.javafx.views.common.TextWithStyle)7 Dialog (javafx.scene.control.Dialog)6 TextField (javafx.scene.control.TextField)6 VBox (javafx.scene.layout.VBox)6 Scene (javafx.scene.Scene)5 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 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Node (javafx.scene.Node)3 ColumnConstraintsWithPercentage (org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage)3 File (java.io.File)2 ResourceBundle (java.util.ResourceBundle)2