List of usage examples for javafx.scene.layout GridPane add
public void add(Node child, int columnIndex, int rowIndex)
From source file:FeeBooster.java
private GridPane cpfpGrid(Transaction tx) { // Setup Grid GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);//from ww w. j av a 2 s .co m grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); int gridheight = 0; // Add outputs to table Label outputHdrLbl = new Label("Outputs"); grid.add(outputHdrLbl, 1, gridheight); gridheight++; ToggleGroup outputGroup = new ToggleGroup(); for (int i = 0; i < tx.getOutputs().size(); i++) { // Add output to table TxOutput out = tx.getOutputs().get(i); Text outputTxt = new Text("Amount " + out.getValue() + " Satoshis\nAddress: " + out.getAddress()); outputTxt.setUserData(i); grid.add(outputTxt, 0, gridheight); // Add radio button to table RadioButton radio = new RadioButton(); radio.setUserData(i); radio.setToggleGroup(outputGroup); radio.setSelected(true); grid.add(radio, 1, gridheight); gridheight++; } // Fee Text fee = new Text("Fee to Pay: " + tx.getFee() + " Satoshis"); grid.add(fee, 0, gridheight); // Recommended fee from bitcoinfees.21.co JSONObject apiResult = Utils.getFromAnAPI("http://bitcoinfees.21.co/api/v1/fees/recommended", "GET"); int fastestFee = apiResult.getInt("fastestFee"); long recommendedFee = fastestFee * tx.getSize() + fastestFee * 300; Text recFeeTxt = new Text("Recommended Fee: " + recommendedFee + " Satoshis"); grid.add(recFeeTxt, 1, gridheight); gridheight += 2; // Instructions Text instructions = new Text("Choose an output to spend from. Set the total transaction fee below."); grid.add(instructions, 0, gridheight, 3, 1); gridheight++; // Fee spinner Spinner feeSpin = new Spinner((double) tx.getFee(), (double) tx.getTotalAmt(), (double) tx.getFee()); feeSpin.setEditable(true); grid.add(feeSpin, 0, gridheight); feeSpin.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { double oldVal = (double) oldValue; double newVal = (double) newValue; Double step = newVal - oldVal; tx.setFee(tx.getFee() + step.longValue()); fee.setText("Fee to Pay: " + tx.getFee() + " Satoshis"); } }); // Set to recommended fee button Button recFeeBtn = new Button("Set fee to recommended"); grid.add(recFeeBtn, 1, gridheight); gridheight++; recFeeBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { long prevFee = tx.getFee(); long step = recommendedFee - prevFee; feeSpin.increment((int) step); } }); // Output address Label recvAddr = new Label("Address to pay to"); grid.add(recvAddr, 0, gridheight); TextField outAddr = new TextField(); grid.add(outAddr, 1, gridheight); gridheight++; // Next Button Button nextBtn = new Button("Next"); nextBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { if (sceneCursor == scenes.size() - 1) { // Referenced output int output = (int) outputGroup.getSelectedToggle().getUserData(); TxOutput refout = tx.getOutputs().get(output); // Create output for CPFP transaction TxOutput out = null; long outval = refout.getValue() - ((Double) feeSpin.getValue()).longValue(); if (Utils.validateAddress(outAddr.getText())) { byte[] decodedAddr = Utils.base58Decode(outAddr.getText()); boolean isP2SH = decodedAddr[0] == 0x00; byte[] hash160 = Arrays.copyOfRange(decodedAddr, 1, decodedAddr.length - 4); if (isP2SH) { byte[] script = new byte[hash160.length + 3]; script[0] = (byte) 0xa9; script[1] = (byte) 0x14; System.arraycopy(hash160, 0, script, 2, hash160.length); script[script.length - 1] = (byte) 0x87; out = new TxOutput(outval, script); } else { byte[] script = new byte[hash160.length + 5]; script[0] = (byte) 0x76; script[1] = (byte) 0xa9; script[2] = (byte) 0x14; System.arraycopy(hash160, 0, script, 3, hash160.length); script[script.length - 2] = (byte) 0x88; script[script.length - 1] = (byte) 0xac; out = new TxOutput(outval, script); } } else { Alert alert = new Alert(Alert.AlertType.ERROR, "Invalid Address"); alert.showAndWait(); return; } // Create CPFP Transaction Transaction cpfpTx = new Transaction(); TxInput in = new TxInput(tx.getHash(), output, new byte[] { (0x00) }, 0xffffffff); cpfpTx.addOutput(out); cpfpTx.addInput(in); // Create Scene Scene scene = new Scene(unsignedTxGrid(cpfpTx), 900, 500); scenes.add(scene); sceneCursor++; stage.setScene(scene); } else { sceneCursor++; stage.setScene(scenes.get(sceneCursor)); } } }); HBox btnHbox = new HBox(10); // Back Button Button backBtn = new Button("Back"); backBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { sceneCursor--; stage.setScene(scenes.get(sceneCursor)); } }); btnHbox.getChildren().add(backBtn); btnHbox.getChildren().add(nextBtn); // Cancel Button Button cancelBtn = new Button("Cancel"); cancelBtn.setOnAction(cancelEvent); btnHbox.getChildren().add(cancelBtn); grid.add(btnHbox, 1, gridheight); return grid; }
From source file:FeeBooster.java
private GridPane rbfGrid(Transaction tx) { // Setup grid GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);/*from www.j a v a 2s. co m*/ grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); int inGridHeight = 0; int outGridHeight = 0; // Add inputs to table Label inputHdrLbl = new Label("Inputs"); grid.add(inputHdrLbl, 0, inGridHeight); inGridHeight++; for (int i = 0; i < tx.getInputs().size(); i++) { // Add input to table TxInput in = tx.getInputs().get(i); Text inputTxt = new Text("Txid: " + in.getTxid() + "\nIndex: " + in.getVout()); grid.add(inputTxt, 0, inGridHeight); inGridHeight++; } // Add outputs to table Label outputHdrLbl = new Label("Outputs"); grid.add(outputHdrLbl, 1, outGridHeight); outGridHeight++; ToggleGroup outputGroup = new ToggleGroup(); for (int i = 0; i < tx.getOutputs().size(); i++) { // Add output to table TxOutput out = tx.getOutputs().get(i); Text outputTxt = new Text("Amount " + out.getValue() + " Satoshis\nAddress: " + out.getAddress()); outputTxt.setUserData(i); grid.add(outputTxt, 1, outGridHeight); // Add radio button to table RadioButton radio = new RadioButton(); radio.setUserData(i); radio.setToggleGroup(outputGroup); radio.setSelected(true); grid.add(radio, 2, outGridHeight); outGridHeight++; } // Set gridheight int gridheight = (inGridHeight < outGridHeight) ? outGridHeight : inGridHeight; gridheight++; // Fee Text fee = new Text("Fee Paid: " + tx.getFee() + " Satoshis"); grid.add(fee, 0, gridheight); // Recommended fee from bitcoinfees.21.co JSONObject apiResult = Utils.getFromAnAPI("http://bitcoinfees.21.co/api/v1/fees/recommended", "GET"); int fastestFee = apiResult.getInt("fastestFee"); long recommendedFee = fastestFee * tx.getSize(); Text recFeeTxt = new Text("Recommended Fee: " + recommendedFee + " Satoshis"); grid.add(recFeeTxt, 1, gridheight); gridheight += 2; // Instructions Text instructions = new Text( "Choose an output to deduct an additional fee from. Then increase the fee below."); grid.add(instructions, 0, gridheight, 3, 1); gridheight++; // Fee spinner Spinner feeSpin = new Spinner((double) tx.getFee(), (double) tx.getTotalAmt(), (double) tx.getFee()); feeSpin.setEditable(true); grid.add(feeSpin, 0, gridheight); feeSpin.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { double oldVal = (double) oldValue; double newVal = (double) newValue; Double step = newVal - oldVal; tx.setFee(tx.getFee() + step.longValue()); fee.setText("Fee Paid: " + tx.getFee() + " Satoshis"); int output = (int) outputGroup.getSelectedToggle().getUserData(); TxOutput out = tx.getOutputs().get(output); out.decreaseValueBy(step.longValue()); for (int i = 0; i < grid.getChildren().size(); i++) { Node child = grid.getChildren().get(i); if (grid.getRowIndex(child) == output + 1 && grid.getColumnIndex(child) == 1) { ((Text) child) .setText("Amount " + out.getValue() + " Satoshis\nAddress: " + out.getAddress()); } } } }); // Set to recommended fee button Button recFeeBtn = new Button("Set fee to recommended"); grid.add(recFeeBtn, 1, gridheight); gridheight++; recFeeBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { long prevFee = tx.getFee(); long step = recommendedFee - prevFee; feeSpin.increment((int) step); } }); // Next Button Button nextBtn = new Button("Next"); grid.add(nextBtn, 1, gridheight); nextBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { if (sceneCursor == scenes.size() - 1) { Scene scene = new Scene(unsignedTxGrid(tx), 900, 500); scenes.add(scene); sceneCursor++; stage.setScene(scene); } else { sceneCursor++; stage.setScene(scenes.get(sceneCursor)); } } }); HBox btnHbox = new HBox(10); // Back Button Button backBtn = new Button("Back"); backBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { sceneCursor--; stage.setScene(scenes.get(sceneCursor)); } }); btnHbox.getChildren().add(backBtn); btnHbox.getChildren().add(nextBtn); // Cancel Button Button cancelBtn = new Button("Cancel"); cancelBtn.setOnAction(cancelEvent); btnHbox.getChildren().add(cancelBtn); grid.add(btnHbox, 1, gridheight); return grid; }
From source file:de.perdian.apps.tagtiger.fx.handlers.batchupdate.UpdateFileNamesFromTagsActionEventHandler.java
private Parent createLegendPane() { GridPane legendPane = new GridPane(); legendPane.setPadding(new Insets(5, 5, 5, 5)); int columnCount = 3; int currentRow = 0; int currentColumn = 0; for (UpdateFileNamesPlaceholder placeholder : UpdateFileNamesPlaceholder.values()) { StringBuilder placeholderText = new StringBuilder(); placeholderText.append("${").append(placeholder.getPlaceholder()).append("}: "); placeholderText.append(placeholder.resolveLocalization(this.getLocalization())); Label placeholderLabel = new Label(placeholderText.toString()); placeholderLabel.setMaxWidth(Double.MAX_VALUE); placeholderLabel.setPadding(new Insets(3, 3, 3, 3)); placeholderLabel.setAlignment(Pos.TOP_LEFT); legendPane.add(placeholderLabel, currentColumn, currentRow); GridPane.setFillWidth(placeholderLabel, Boolean.TRUE); GridPane.setHgrow(placeholderLabel, Priority.ALWAYS); currentColumn++;/* w ww . jav a 2s . c om*/ if (currentColumn >= columnCount) { currentRow++; currentColumn = 0; } } TitledPane legendTitlePane = new TitledPane(this.getLocalization().legend(), legendPane); legendTitlePane.setCollapsible(false); return legendTitlePane; }
From source file:FeeBooster.java
private GridPane unsignedTxGrid(Transaction tx) { // Setup Grid GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);//from ww w . ja v a2 s . co m grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); // Instructions Text Text instructions = new Text("Below is the unsiged version of the fee boosted transaction. You can sign " + "this here or copy this transaction and sign it in your wallet"); grid.add(instructions, 0, 0); // Put unsigned transaction in text area byte[] unsignedTxBytes = Transaction.serialize(tx, true); TextArea unsignedTxTxt = new TextArea(Utils.bytesToHex(unsignedTxBytes)); unsignedTxTxt.setWrapText(true); grid.add(unsignedTxTxt, 0, 1); // Radio buttons for sign here or sign elsewhere /*VBox signRadioVbox = new VBox(); ToggleGroup signRadioGroup = new ToggleGroup(); RadioButton signHereRadio = new RadioButton("Sign Here"); signHereRadio.setToggleGroup(signRadioGroup); signRadioVbox.getChildren().add(signHereRadio); RadioButton signWalletRadio = new RadioButton("Sign in my wallet"); signWalletRadio.setToggleGroup(signRadioGroup); signWalletRadio.setSelected(true); signRadioVbox.getChildren().add(signWalletRadio); grid.add(signRadioVbox, 0, 3); */ // Add Next Button Button nextBtn = new Button("Next"); nextBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //if(signHereRadio.isSelected()) // stage.setScene(new Scene(signTxGrid(tx), 800, 500)); //else if(signWalletRadio.isSelected()) if (sceneCursor == scenes.size() - 1) { Scene scene = new Scene(broadcastTxGrid(tx), 900, 500); scenes.add(scene); sceneCursor++; stage.setScene(scene); } else { sceneCursor++; stage.setScene(scenes.get(sceneCursor)); } } }); HBox btnHbox = new HBox(10); // Back Button Button backBtn = new Button("Back"); backBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { sceneCursor--; stage.setScene(scenes.get(sceneCursor)); } }); btnHbox.getChildren().add(backBtn); btnHbox.getChildren().add(nextBtn); // Cancel Button Button cancelBtn = new Button("Cancel"); cancelBtn.setOnAction(cancelEvent); btnHbox.getChildren().add(cancelBtn); grid.add(btnHbox, 0, 2); return grid; }
From source file:Main.java
@Override public void start(final Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 400, 300, Color.WHITE); GridPane gridpane = new GridPane(); ComboBox<Color> cmb = new ComboBox<Color>(); cmb.getItems().addAll(Color.RED, Color.GREEN, Color.BLUE); cmb.setCellFactory(new Callback<ListView<Color>, ListCell<Color>>() { @Override//from w ww . ja v a2s . co m public ListCell<Color> call(ListView<Color> p) { return new ListCell<Color>() { private final Rectangle rectangle; { setContentDisplay(ContentDisplay.GRAPHIC_ONLY); rectangle = new Rectangle(10, 10); } @Override protected void updateItem(Color item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setGraphic(null); } else { rectangle.setFill(item); setGraphic(rectangle); } } }; } }); gridpane.add(cmb, 2, 0); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(final Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 400, 300, Color.WHITE); GridPane gridpane = new GridPane(); ComboBox<Color> cmb = new ComboBox<Color>(); cmb.getItems().addAll(Color.RED, Color.GREEN, Color.BLUE); cmb.setCellFactory(new Callback<ListView<Color>, ListCell<Color>>() { @Override//from w w w . j a va2 s . c om public ListCell<Color> call(ListView<Color> p) { return new ListCell<Color>() { private final Rectangle rectangle; { setContentDisplay(ContentDisplay.GRAPHIC_ONLY); rectangle = new Rectangle(10, 10); } @Override protected void updateItem(Color item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setGraphic(null); } else { rectangle.setFill(item); setGraphic(rectangle); } } }; } }); gridpane.add(cmb, 2, 0); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:main.Content.java
public void showGanttOverview() { GridPane gridPane = new GridPane(); boolean isTempEmpty = false; if (temp.isEmpty() || temp == null) { temp = data;//from w w w.j ava 2 s . c om for (int i = 0; i < temp.size(); i++) System.out.println("Emri: " + temp.get(i).getName()); isTempEmpty = true; } IntervalCategoryDataset dataSet = IntervalBuilder.buildDataSet(temp, isTempEmpty); GanttChartBuilder ganttChartBuilder = new GanttChartBuilder("Gantt", "X", "Y"); ChartPanel panel = ganttChartBuilder.buildChartPanel(dataSet); SwingNode wrapperNode = new SwingNode(); wrapperNode.setContent(panel); gridPane.add(wrapperNode, 0, 0); tabRootLayout.getTabs().get(1).setContent(gridPane); }
From source file:acmi.l2.clientmod.l2smr.Controller.java
private void onException(String text, Throwable ex) { ex.printStackTrace();/* w w w.j a v a 2 s .c o m*/ Platform.runLater(() -> { if (SHOW_STACKTRACE) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText(null); alert.setContentText(text); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); String exceptionText = sw.toString(); Label label = new Label("Exception stacktrace:"); TextArea textArea = new TextArea(exceptionText); textArea.setEditable(false); textArea.setWrapText(true); textArea.setMaxWidth(Double.MAX_VALUE); textArea.setMaxHeight(Double.MAX_VALUE); GridPane.setVgrow(textArea, Priority.ALWAYS); GridPane.setHgrow(textArea, Priority.ALWAYS); GridPane expContent = new GridPane(); expContent.setMaxWidth(Double.MAX_VALUE); expContent.add(label, 0, 0); expContent.add(textArea, 0, 1); alert.getDialogPane().setExpandableContent(expContent); alert.showAndWait(); } else { //noinspection ThrowableResultOfMethodCallIgnored Throwable t = getTop(ex); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle(t.getClass().getSimpleName()); alert.setHeaderText(text); alert.setContentText(t.getMessage()); alert.showAndWait(); } }); }
From source file:de.ifsr.adam.ImageGenerator.java
/** * Puts the charts in chartList into GridPanes as specified by chartsPerColumn and chartsPerRow. * * @param chartList The ArrayList with the charts. * @param chartsPerColumn Number of charts that are in one column. * @param chartsPerRow Number of charts that are in one row. * @return The list of GridPanes that were generated. *//*from w w w. j av a 2 s.co m*/ private ArrayList<GridPane> makeLayout(ArrayList<Chart> chartList, Integer chartsPerColumn, Integer chartsPerRow) { ArrayList<GridPane> gridPaneList = new ArrayList<>(); GridPane gridPane = new GridPane(); int rowIndex = 0, columnIndex = 0; Iterator<Chart> iter = chartList.iterator(); //int i = 0;//TODO: Remove while (iter.hasNext()) { //System.out.println("Run: "+ i + " columnIndex: " + columnIndex + " rowIndex: " + rowIndex);//TODO: Remove //i++;//TODO: Remove Chart chart = iter.next(); calculateChartSize(chart, chartsPerColumn, chartsPerRow); gridPane.add(chart, columnIndex, rowIndex); columnIndex++; //Case: Row is full go to next row if (columnIndex >= chartsPerRow) { columnIndex = 0; rowIndex++; } //Case: Page is full start a new GridPane if (rowIndex >= chartsPerColumn) { //The Layout for the gridPane gridPane.setHgap(imageWidth * 0.10); gridPane.setAlignment(Pos.CENTER); gridPane.setPrefWidth(imageWidth); gridPane.setPrefHeight(imageHeight); gridPaneList.add(gridPane); gridPane = new GridPane(); rowIndex = 0; } } //This needs to be check, or the last page can be empty if (rowIndex != 0 || columnIndex != 0) { gridPaneList.add(gridPane); } return gridPaneList; }
From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java
private void insertConfigItemsIntoGrid(final GridPane gp, final List<Triple<String, Node, String>> formItems) { for (int i = 0; i < formItems.size(); i++) { final String title = formItems.get(i).getLeft(); final Node inputElement = formItems.get(i).getMiddle(); final String description = formItems.get(i).getRight(); // Put text flow object into cell. If a Text instance is used only, it will grab the whole cell size and center the text // (horizontally and vertically). Therefore, the table cell alignment does not work. final TextFlow titleText = new TextFlow(new Text(title)); titleText.setStyle("-fx-font-weight: bold;"); final TextFlow fieldName = new TextFlow(titleText); fieldName.autosize();// w w w . j a va 2 s. c o m fieldName.setMinWidth(fieldName.getWidth()); gp.add(fieldName, 0, i); final Text descriptionText = new Text(description); final VBox vbox = new VBox(inputElement, new TextFlow(descriptionText)); gp.add(vbox, 1, i); } }