List of usage examples for javafx.event EventHandler EventHandler
EventHandler
From source file:retsys.client.controller.ProjectController.java
/** * Initializes the controller class./*w w w .ja va 2 s. c o m*/ */ @Override public void initialize(URL url, ResourceBundle rb) { AutoCompletionBinding<Project> txt_name = TextFields.bindAutoCompletion(name, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Project>>() { @Override public Collection<Project> call(AutoCompletionBinding.ISuggestionRequest param) { List<Project> list = null; HttpHelper helper = new HttpHelper(); try { LovHandler lovHandler = new LovHandler("projects", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Project>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Project>>() { }); } catch (IOException ex) { Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Project>() { @Override public String toString(Project object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Project fromString(String string) { throw new UnsupportedOperationException("Not supported yet."); } }); //event handler for setting other Client fields with values from selected Client object //fires after autocompletion txt_name.setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<Project>>() { @Override public void handle(AutoCompletionBinding.AutoCompletionEvent<Project> event) { Project project = event.getCompletion(); //fill other item related fields id.setText(splitId(name.getText()) + ""); name.setText(project.getName()); projectDesc.setText(project.getProjectDesc()); remarks.setText(project.getRemarks()); client.setText(project.getClient().getName() + " (ID:" + project.getClient().getId() + ")"); populateAuditValues(project); } }); TextFields.bindAutoCompletion(client, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Client>>() { @Override public Collection<Client> call(AutoCompletionBinding.ISuggestionRequest param) { List<Client> list = null; HttpHelper helper = new HttpHelper(); try { LovHandler lovHandler = new LovHandler("clients", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Client>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Client>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Client>() { @Override public String toString(Client object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Client fromString(String string) { throw new UnsupportedOperationException("Not supported yet."); } }); }
From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java
public LookupFieldSkin(LookupField<T> control) { super(control, new LookupFieldBehavior<>(control)); this.lookupField = control; // move focus in to the textfield lookupField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override/*from ww w .j a va2 s. c o m*/ public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) { if (hasFocus) { Platform.runLater(new Runnable() { @Override public void run() { textField.requestFocus(); } }); } } }); initialize(); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) { if (!hasFocus) { validate(); } } }); lookupField.addEventFilter(InputEvent.ANY, new EventHandler<InputEvent>() { @Override public void handle(InputEvent t) { if (textField == null) { return; } // When the user hits the enter or F4 keys, we respond before // ever giving the event to the TextField. if (t instanceof KeyEvent) { KeyEvent ke = (KeyEvent) t; if ((ke.getCode() == KeyCode.F10 || ke.getCode() == KeyCode.ESCAPE || ke.getCode() == KeyCode.ENTER) && !ke.isControlDown()) { // RT-23275: The TextField fires F10 and ESCAPE key events // up to the parent, which are then fired back at the // TextField, and this ends up in an infinite loop until // the stack overflows. So, here we consume these two // events and stop them from going any further. t.consume(); return; } } } }); textField.promptTextProperty().bind(lookupField.promptTextProperty()); getSkinnable().requestLayout(); registerChangeListener(control.showingSuggestionProperty(), PROP_SHOWING_SUGGESTION); registerChangeListener(control.showingLookupDialogProperty(), PROP_SHOWING_LOOKUP_WINDOW); registerChangeListener(control.resettingDisplayTextProperty(), PROP_RESETTING_DISPLAY_TEXT); }
From source file:ch.unibas.fittingwizard.presentation.fitting.FittingParameterPage.java
@Override protected void fillButtonBar() { Button backButton = ButtonFactory.createButtonBarButton("Go back to molecule list", new EventHandler<ActionEvent>() { @Override//from w w w.j a va 2 s .com public void handle(ActionEvent actionEvent) { logger.info("Going back to molecule list."); navigateTo(MoleculeListPage.class); } }); addButtonToButtonBar(backButton); Button startButton = ButtonFactory.createButtonBarButton("Start fitting", new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { logger.info("Starting fit."); MoleculeQueryService queryService = moleculeRepository.getQueryServiceForAllMolecules(); File initalCharges = getInitalCharges(queryService); if (initalCharges != null) { navigateTo(RunningFitPage.class, createFittingParameter(initalCharges, queryService.getMoleculeIds())); } } }); addButtonToButtonBar(startButton); }
From source file:ch.unibas.fittingwizard.presentation.base.progress.ProgressPage.java
@Override protected void fillButtonBar() { Button cancelButton = ButtonFactory.createButtonBarButton("Cancel", new EventHandler<ActionEvent>() { @Override//from w ww. j a v a 2 s . com public void handle(ActionEvent actionEvent) { logger.info("Canceling task"); if (task != null) if (!task.isCancelled()) task.cancel(); else goBack(); } }); addButtonToButtonBar(cancelButton); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = SceneBuilder.create().width(400).height(500) .root(GroupBuilder.create()/*from www .j a v a 2s.co m*/ .children(ellipse, HBoxBuilder.create().layoutX(60).layoutY(420).spacing(10) .children(startButton = ButtonBuilder.create().text("Start") .onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { anim.playFromStart(); } }).build(), pauseButton = ButtonBuilder.create().text("Pause") .onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { anim.pause(); } }).build(), resumeButton = ButtonBuilder.create().text("Resume") .onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { anim.play(); } }).build(), stopButton = ButtonBuilder.create().text("Stop") .onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { anim.stop(); } }).build()) .build()) .build()) .build(); startButton.disableProperty().bind(anim.statusProperty().isNotEqualTo(Animation.Status.STOPPED)); pauseButton.disableProperty().bind(anim.statusProperty().isNotEqualTo(Animation.Status.RUNNING)); resumeButton.disableProperty().bind(anim.statusProperty().isNotEqualTo(Animation.Status.PAUSED)); stopButton.disableProperty().bind(anim.statusProperty().isEqualTo(Animation.Status.STOPPED)); stage.setScene(scene); stage.setTitle("Metronome using PathTransition"); stage.show(); }
From source file:FeeBooster.java
@Override public void start(Stage primaryStage) throws Exception { // Setup the stage stage = primaryStage;/* www . ja v a 2s. c o m*/ primaryStage.setTitle("Bitcoin Transaction Fee Booster"); // Setup intro gridpane GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); // Intro Text Text scenetitle = new Text( "Welcome to the fee booster. \n\nWhat type of transaction would you like to boost the fee of?"); grid.add(scenetitle, 0, 0, 2, 3); // radio button selections VBox boostRadioVbox = new VBox(); ToggleGroup boostTypeGroup = new ToggleGroup(); RadioButton rbfRadio = new RadioButton("A transaction you sent"); rbfRadio.setToggleGroup(boostTypeGroup); boostRadioVbox.getChildren().add(rbfRadio); RadioButton cpfpRadio = new RadioButton("A transaction you received"); cpfpRadio.setToggleGroup(boostTypeGroup); rbfRadio.setSelected(true); boostRadioVbox.getChildren().add(cpfpRadio); grid.add(boostRadioVbox, 0, 3); // Instructions Text Text instruct = new Text("Please enter the raw hex or transaction id of your transaction below:"); grid.add(instruct, 0, 4); // Textbox for hex of transaction TextArea txHexTxt = new TextArea(); txHexTxt.setWrapText(true); grid.add(txHexTxt, 0, 5, 5, 1); // Next Button Button nextBtn = new Button("Next"); nextBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { // Create Transaction Transaction tx = new Transaction(); // Check if txid boolean isTxid = txHexTxt.getText().length() == 64 && txHexTxt.getText().matches("[0-9A-Fa-f]+"); if (isTxid) tx.setHash(txHexTxt.getText()); // Determine which page to go to if (Transaction.deserializeStr(txHexTxt.getText(), tx) || isTxid) { // Get the fee JSONObject apiResult = Utils .getFromAnAPI("https://api.blockcypher.com/v1/btc/main/txs/" + tx.getHash(), "GET"); // Get the fee tx.setFee(apiResult.getInt("fees")); tx.setTotalAmtPre(tx.getFee() + tx.getOutAmt()); // Get info if txid if (isTxid) { } Scene scene = null; if (rbfRadio.isSelected()) if (sceneCursor == scenes.size() - 1 || !rbf) { scene = new Scene(rbfGrid(tx), 900, 500); if (!rbf) { scenes.clear(); scenes.add(stage.getScene()); } rbf = true; } if (cpfpRadio.isSelected()) if (sceneCursor == scenes.size() - 1 || rbf) { scene = new Scene(cpfpGrid(tx), 900, 500); if (rbf) { scenes.clear(); scenes.add(stage.getScene()); } rbf = false; } if (sceneCursor != scenes.size() - 1) scene = scenes.get(sceneCursor + 1); else scenes.add(scene); sceneCursor++; stage.setScene(scene); } else { Alert alert = new Alert(Alert.AlertType.ERROR, "Please enter a valid transaction"); alert.showAndWait(); } } }); HBox btnHbox = new HBox(10); btnHbox.getChildren().add(nextBtn); // Cancel Button Button cancelBtn = new Button("Cancel"); cancelBtn.setOnAction(cancelEvent); btnHbox.getChildren().add(cancelBtn); grid.add(btnHbox, 2, 7); // Display everything Scene scene = new Scene(grid, 900, 500); scenes.add(scene); primaryStage.setScene(scene); primaryStage.show(); }
From source file:com.panemu.tiwulfx.form.BaseControl.java
public BaseControl(String propertyName, E control) { this.inputControl = control; this.propertyName = propertyName; HBox.setHgrow(control, Priority.ALWAYS); setAlignment(Pos.CENTER_LEFT);//from w w w . j ava 2 s.c o m control.setMaxWidth(Double.MAX_VALUE); control.setMinHeight(USE_PREF_SIZE); getChildren().add(control); getChildren().add(imagePlaceHolder); required.addListener(imageListener); valid.addListener(imageListener); this.getStyleClass().add("form-control"); value = new SimpleObjectProperty<>(); bindValuePropertyWithControl(control); bindEditablePropertyWithControl(control); addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getEventType() == MouseEvent.MOUSE_MOVED && !isValid() && !getPopup().isShowing()) { Point2D p = BaseControl.this.localToScene(0.0, 0.0); getPopup().show(BaseControl.this, p.getX() + getScene().getX() + getScene().getWindow().getX(), p.getY() + getScene().getY() + getScene().getWindow().getY() + getInputComponent().getHeight() - 1); } else if (event.getEventType() == MouseEvent.MOUSE_EXITED && getPopup().isShowing()) { getPopup().hide(); } } }); getInputComponent().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { if (!isValid() && getPopup().isShowing()) { getPopup().hide(); } } }); }
From source file:com.QuarkLabs.BTCeClientJavaFX.OrdersBookController.java
@FXML void initialize() { assert asksTable != null : "fx:id=\"asksTable\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert asksTablePriceColumn != null : "fx:id=\"asksTablePriceColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert asksTableVolumeColumn != null : "fx:id=\"asksTableVolumeColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert bidsTable != null : "fx:id=\"bidsTable\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert bidsTablePriceColumn != null : "fx:id=\"bidsTablePriceColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert bidsTableVolumeColumn != null : "fx:id=\"bidsTableVolumeColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; asksTable.setItems(asks);/* ww w .j a v a 2s . com*/ bidsTable.setItems(bids); asksTablePriceColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("price")); asksTableVolumeColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("volume")); asksTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); bidsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); bidsTablePriceColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("price")); bidsTableVolumeColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("volume")); Task<JSONObject> loadOrdersBook = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { return App.getOrdersBook(pair); } }; loadOrdersBook.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); JSONArray asksArray = jsonObject.optJSONArray("asks"); JSONArray bidsArray = jsonObject.optJSONArray("bids"); for (int i = 0; i < asksArray.length(); i++) { JSONArray item = asksArray.optJSONArray(i); OrdersBookEntry ordersBookEntry = new OrdersBookEntry(); ordersBookEntry.setPrice(item.optDouble(0)); ordersBookEntry.setVolume(item.optDouble(1)); asks.add(ordersBookEntry); } for (int i = 0; i < bidsArray.length(); i++) { JSONArray item = bidsArray.optJSONArray(i); OrdersBookEntry ordersBookEntry = new OrdersBookEntry(); ordersBookEntry.setPrice(item.optDouble(0)); ordersBookEntry.setVolume(item.optDouble(1)); bids.add(ordersBookEntry); } } }); Thread thread = new Thread(loadOrdersBook); thread.start(); }
From source file:com.panemu.tiwulfx.form.BaseListControl.java
public BaseListControl(String propertyName, E control) { this.inputControl = control; this.propertyName = propertyName; HBox.setHgrow(control, Priority.ALWAYS); setAlignment(Pos.CENTER_LEFT);//w w w . j a va 2 s. c o m control.setMaxWidth(Double.MAX_VALUE); control.setMinHeight(USE_PREF_SIZE); getChildren().add(control); getChildren().add(imagePlaceHolder); required.addListener(imageListener); valid.addListener(imageListener); this.getStyleClass().add("form-control"); value = new SimpleListProperty<>(); bindValuePropertyWithControl(control); bindEditablePropertyWithControl(control); addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getEventType() == MouseEvent.MOUSE_MOVED && !isValid() && !getPopup().isShowing()) { Point2D p = BaseListControl.this.localToScene(0.0, 0.0); getPopup().show(BaseListControl.this, p.getX() + getScene().getX() + getScene().getWindow().getX(), p.getY() + getScene().getY() + getScene().getWindow().getY() + getInputComponent().getHeight() - 1); } else if (event.getEventType() == MouseEvent.MOUSE_EXITED && getPopup().isShowing()) { getPopup().hide(); } } }); getInputComponent().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { if (!isValid() && getPopup().isShowing()) { getPopup().hide(); } } }); }
From source file:Main.java
WizardPage(String title) { getChildren().add(// w w w .j av a2 s. com LabelBuilder.create().text(title).style("-fx-font-weight: bold; -fx-padding: 0 0 5 0;").build()); setId(title); setSpacing(5); setStyle( "-fx-padding:10; -fx-background-color: honeydew; -fx-border-color: derive(honeydew, -30%); -fx-border-width: 3;"); Region spring = new Region(); VBox.setVgrow(spring, Priority.ALWAYS); getChildren().addAll(getContent(), spring, getButtons()); priorButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { priorPage(); } }); nextButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { nextPage(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { getWizard().cancel(); } }); finishButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { getWizard().finish(); } }); }