List of usage examples for javafx.scene.layout GridPane getColumnIndex
public static Integer getColumnIndex(Node child)
From source file:FeeBooster.java
private GridPane rbfGrid(Transaction tx) { // Setup grid GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);/*from w w w.jav a 2 s . c om*/ 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.ks.idnadrev.information.chart.ChartDataEditor.java
protected void onColumnsChanged(ListChangeListener.Change<? extends SimpleStringProperty> c) { while (c.next()) { List<? extends SimpleStringProperty> added = c.getAddedSubList(); List<? extends SimpleStringProperty> removed = c.getRemoved(); for (SimpleStringProperty column : added) { int columnIndex = columnHeaders.indexOf(column); addColumnConstraint();// ww w .j av a 2 s . c o m TextField title = new TextField(); title.textProperty().bindBidirectional(column); title.getStyleClass().add("editorViewLabel"); MenuItem deleteColumnItem = new MenuItem(Localized.get("column.delete")); deleteColumnItem.setOnAction(e -> { columnHeaders.remove(column); }); title.setContextMenu(new ContextMenu(deleteColumnItem)); headers.add(title); dataContainer.add(title, columnIndex + COLUMN_OFFSET, 0); for (int i = 0; i < rows.size(); i++) { ChartRow chartRow = rows.get(i); SimpleStringProperty value = chartRow.getValue(columnIndex); TextField editor = createValueEditor(chartRow, i, columnIndex); editor.textProperty().bindBidirectional(value); } } for (SimpleStringProperty column : removed) { Optional<Integer> first = dataContainer.getChildren().stream() .filter(n -> GridPane.getRowIndex(n) == 0).map(n -> (TextField) n) .filter(t -> t.getText().equals(column.getValue())).map(t -> GridPane.getColumnIndex(t)) .findFirst(); if (first.isPresent()) { int columnIndex = first.get(); rows.forEach(r -> { SimpleStringProperty value = r.getValue(columnIndex); value.set(""); value.unbind(); }); List<Node> childrenToRemove = dataContainer.getChildren().stream() .filter(n -> GridPane.getColumnIndex(n) == columnIndex).collect(Collectors.toList()); dataContainer.getChildren().removeAll(childrenToRemove); dataContainer.getColumnConstraints().remove(dataContainer.getColumnConstraints().size() - 1); } } sortGridPane(); } }