Example usage for javafx.event EventHandler EventHandler

List of usage examples for javafx.event EventHandler EventHandler

Introduction

In this page you can find the example usage for javafx.event EventHandler EventHandler.

Prototype

EventHandler

Source Link

Usage

From source file:FeeBooster.java

private GridPane rbfGrid(Transaction tx) {
    // Setup grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);/*w  w  w.  j a va2s. com*/
    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:org.sleuthkit.autopsy.imageanalyzer.gui.GroupPane.java

private MenuItem createGrpCatMenuItem(final Category cat) {
    final MenuItem menuItem = new MenuItem(cat.getDisplayName(),
            new ImageView(DrawableAttribute.CATEGORY.getIcon()));
    menuItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override/*from w w  w .  j av  a  2 s . co m*/
        public void handle(ActionEvent t) {
            selectAllFiles();
            new CategorizeAction().addTag(cat.getTagName(), "");

            grpCatSplitMenu.setText(cat.getDisplayName());
            grpCatSplitMenu.setOnAction(this);
        }
    });
    return menuItem;
}

From source file:fruitproject.FruitProject.java

public void third(final String pfname) {
    final Stage st = new Stage();
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from   ww  w.j  a v a2 s  .  co  m
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Label label1 = new Label("New Fruit");
    grid.add(label1, 1, 0);
    final TextField txtName = new TextField();
    grid.add(txtName, 1, 1);
    final TextField txtAmount = new TextField();
    grid.add(txtAmount, 1, 2);
    Button btn = new Button();
    btn.setText("OK");
    grid.add(btn, 1, 3);
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");
            addPairs.add(txtName.getText());
            addPairs.add(txtAmount.getText());
            st.close();
            second(pfname);
        }
    });

    Scene scene = new Scene(grid, 500, 500);
    st.setScene(scene);
    st.show();

}

From source file:org.sleuthkit.autopsy.imagegallery.gui.GroupPane.java

private MenuItem createGrpCatMenuItem(final Category cat) {
    final MenuItem menuItem = new MenuItem(cat.getDisplayName(),
            new ImageView(DrawableAttribute.CATEGORY.getIcon()));
    menuItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override/*from  w w  w .  j a v  a2s.c  o  m*/
        public void handle(ActionEvent t) {
            Set<Long> fileIdSet = new HashSet<>(getGrouping().fileIds());
            new CategorizeAction().addTagsToFiles(cat.getTagName(), "", fileIdSet);

            grpCatSplitMenu.setText(cat.getDisplayName());
            grpCatSplitMenu.setOnAction(this);
        }
    });
    return menuItem;
}

From source file:org.noroomattheinn.visibletesla.OverviewController.java

@Override
protected void initializeState() {
    final Vehicle v = vtVehicle.getVehicle();
    getAppropriateImages(v);//from  w w  w . j  av a 2s .c o m
    toggleChoice = this.storedToggleChoice();
    prefs.overrides.color.addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> ov, String t, String t1) {
            getAppropriateImages(v);
        }
    });
    prefs.overrides.doColor.addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
            getAppropriateImages(v);
        }
    });

    vtVehicle.vehicleState.addTracker(new Runnable() {
        @Override
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    updateVehicleState();
                }
            });
        }
    });
    vtVehicle.chargeState.addTracker(new Runnable() {
        @Override
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    updateChargePort();
                    updateRange();
                }
            });
        }
    });
    vtVehicle.streamState.addTracker(new Runnable() {
        @Override
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    updateOdometer();
                    updateShiftState();
                }
            });
        }
    });

    updateOdometer(); // Show at least an old reading to start
    vtData.produceStream(false); // Update it at some point

    updateWheelView(); // Make sure we display the right wheels from the get-go
    updateRoofView(); // Make sure we display the right roof from the get-go
    reflectVINOrFirmware();
    vinButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            cycleToggleChoice();
            reflectVINOrFirmware();
        }
    });
}

From source file:AudioPlayer3.java

private Node createControlPanel() {
    final HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER);//from  w  w w  .  j  a v  a2 s  .c  om
    hbox.setFillHeight(false);

    final Button playPauseButton = createPlayPauseButton();

    final Button seekStartButton = new Button();
    seekStartButton.setId("seekStartButton");
    seekStartButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            seekAndUpdatePosition(Duration.ZERO);
        }
    });

    final Button seekEndButton = new Button();
    seekEndButton.setId("seekEndButton");
    seekEndButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
            final Duration totalDuration = mediaPlayer.getTotalDuration();
            final Duration oneSecond = Duration.seconds(1);
            seekAndUpdatePosition(totalDuration.subtract(oneSecond));
        }
    });

    hbox.getChildren().addAll(seekStartButton, playPauseButton, seekEndButton);
    return hbox;
}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.GroupPane.java

private MenuItem createGrpTagMenuItem(final TagName tn) {
    final MenuItem menuItem = new MenuItem(tn.getDisplayName(),
            new ImageView(DrawableAttribute.TAGS.getIcon()));
    menuItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override//from   www .ja va  2 s. co m
        public void handle(ActionEvent t) {
            selectAllFiles();
            AddDrawableTagAction.getInstance().addTag(tn, "");

            grpTagSplitMenu.setText(tn.getDisplayName());
            grpTagSplitMenu.setOnAction(this);
        }
    });
    return menuItem;
}

From source file:retsys.client.controller.PurchaseOrderConfirmController.java

/**
 * Initializes the controller class.//from  www  .jav a2s .  c om
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    po_date.setValue(LocalDate.now());

    loc_of_material.setCellValueFactory(new PropertyValueFactory<POItem, String>("location"));
    material_name.setCellValueFactory(new PropertyValueFactory<POItem, String>("name"));
    brand_name.setCellValueFactory(new PropertyValueFactory<POItem, String>("brand"));
    model_code.setCellValueFactory(new PropertyValueFactory<POItem, String>("model"));
    quantity.setCellValueFactory(new PropertyValueFactory<POItem, Integer>("quantity"));
    confirm.setCellValueFactory(new PropertyValueFactory<POItem, Boolean>("confirm"));
    confirm.setCellFactory(CheckBoxTableCell.forTableColumn(confirm));
    billNo.setCellValueFactory(new PropertyValueFactory<POItem, String>("billNo"));
    billNo.setCellFactory(TextFieldTableCell.forTableColumn());
    supervisor.setCellValueFactory(new PropertyValueFactory<POItem, String>("supervisor"));
    supervisor.setCellFactory(TextFieldTableCell.forTableColumn());
    receivedDate.setCellValueFactory(new PropertyValueFactory<POItem, LocalDate>("receivedDate"));
    receivedDate.setCellFactory(new Callback<TableColumn<POItem, LocalDate>, TableCell<POItem, LocalDate>>() {

        @Override
        public TableCell<POItem, LocalDate> call(TableColumn<POItem, LocalDate> param) {
            TableCell<POItem, LocalDate> cell = new TableCell<POItem, LocalDate>() {

                @Override
                protected void updateItem(LocalDate item, boolean empty) {
                    super.updateItem(item, empty); //To change body of generated methods, choose Tools | Templates.
                    if (empty || item == null) {
                        setText(null);
                        setGraphic(null);
                    } else {
                        setText(formatter.format(item));
                    }
                }

                @Override
                public void startEdit() {
                    super.startEdit();
                    System.out.println("start edit");
                    DatePicker dateControl = null;
                    if (this.getItem() != null) {
                        dateControl = new DatePicker(this.getItem());
                    } else {
                        dateControl = new DatePicker();
                    }

                    dateControl.valueProperty().addListener(new ChangeListener<LocalDate>() {

                        @Override
                        public void changed(ObservableValue<? extends LocalDate> observable, LocalDate oldValue,
                                LocalDate newValue) {
                            if (newValue == null) {
                                cancelEdit();
                            } else {
                                commitEdit(newValue);
                            }
                        }
                    });
                    this.setGraphic(dateControl);
                }

                @Override
                public void cancelEdit() {
                    super.cancelEdit();
                    System.out.println("cancel edit");
                    setGraphic(null);
                    if (this.getItem() != null) {
                        setText(formatter.format(this.getItem()));
                    } else {
                        setText(null);
                    }
                }

                @Override
                public void commitEdit(LocalDate newValue) {
                    super.commitEdit(newValue);
                    System.out.println("commit edit");
                    setGraphic(null);
                    setText(formatter.format(newValue));
                }
            };

            return cell;
        }
    });

    poDetail.getColumns().setAll(loc_of_material, material_name, brand_name, model_code, quantity, confirm,
            receivedDate, billNo, supervisor);
    AutoCompletionBinding<PurchaseOrder> bindForTxt_name = TextFields.bindAutoCompletion(project,
            new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<PurchaseOrder>>() {

                @Override
                public Collection<PurchaseOrder> call(AutoCompletionBinding.ISuggestionRequest param) {
                    List<PurchaseOrder> list = null;
                    try {
                        LovHandler lovHandler = new LovHandler("purchaseorders", "name");
                        String response = lovHandler.getSuggestions(param.getUserText());
                        list = (List<PurchaseOrder>) new JsonHelper().convertJsonStringToObject(response,
                                new TypeReference<List<PurchaseOrder>>() {
                                });
                    } catch (IOException ex) {
                        Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    return list;
                }
            }, new StringConverter<PurchaseOrder>() {

                @Override
                public String toString(PurchaseOrder object) {
                    System.out.println("here..." + object);

                    String strDate = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format(
                            LocalDateTime.ofInstant(object.getDate().toInstant(), ZoneId.systemDefault()));
                    return "Project:" + object.getProject().getName() + " PO Date:" + strDate + " PO No.:"
                            + object.getId();
                }

                @Override
                public PurchaseOrder fromString(String string) {
                    throw new UnsupportedOperationException();
                }
            });

    bindForTxt_name
            .setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<PurchaseOrder>>() {

                @Override
                public void handle(AutoCompletionBinding.AutoCompletionEvent<PurchaseOrder> event) {
                    populateData(event.getCompletion());
                }
            });

    AutoCompletionBinding<Vendor> bindForVendor = TextFields.bindAutoCompletion(vendor,
            new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Vendor>>() {

                @Override
                public Collection<Vendor> call(AutoCompletionBinding.ISuggestionRequest param) {
                    List<Vendor> list = null;
                    try {
                        LovHandler lovHandler = new LovHandler("vendors", "name");
                        String response = lovHandler.getSuggestions(param.getUserText());
                        list = (List<Vendor>) new JsonHelper().convertJsonStringToObject(response,
                                new TypeReference<List<Vendor>>() {
                                });
                    } catch (IOException ex) {
                        Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    return list;
                }
            }, new StringConverter<Vendor>() {

                @Override
                public String toString(Vendor object) {
                    return object.getName() + " (ID:" + object.getId() + ")";
                }

                @Override
                public Vendor fromString(String string) {
                    throw new UnsupportedOperationException();
                }
            });
}

From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java

private TableColumn<CSVRow, String> createColumn(int index) {
    TableColumn<CSVRow, String> col = new TableColumn<>((index + 1) + "");
    col.setSortable(false);//from   w ww .  j ava  2s.c  o m
    col.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<CSVRow, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(TableColumn.CellDataFeatures<CSVRow, String> param) {
                    adjustColumns(param.getValue().getColumns());
                    return param.getValue().getColumns().get(index);
                }
            });
    col.setCellFactory(TextFieldTableCell.forTableColumn());
    col.setOnEditCommit(new EventHandler<CellEditEvent<CSVRow, String>>() {
        @Override
        public void handle(CellEditEvent<CSVRow, String> event) {
            adjustColumns(event.getRowValue().getColumns());
            event.getRowValue().getColumns().get(index).set(event.getNewValue());
            setNotSaved();
        }
    });
    col.setEditable(true);
    return col;
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.GroupPane.java

private MenuItem createGrpTagMenuItem(final TagName tn) {
    final MenuItem menuItem = new MenuItem(tn.getDisplayName(),
            new ImageView(DrawableAttribute.TAGS.getIcon()));
    menuItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override//from  w w  w  .j  a  v a2s  .  co m
        public void handle(ActionEvent t) {
            Set<Long> fileIdSet = new HashSet<>(getGrouping().fileIds());
            AddDrawableTagAction.getInstance().addTagsToFiles(tn, "", fileIdSet);

            grpTagSplitMenu.setText(tn.getDisplayName());
            grpTagSplitMenu.setOnAction(this);
        }
    });
    return menuItem;
}