List of usage examples for javafx.event EventHandler EventHandler
EventHandler
From source file:com.anavationllc.o2jb.ConfigurationApp.java
private Button getCancelBtn() { if (cancelBtn == null) { cancelBtn = new Button(msg("form.btn.cancel")); cancelBtn.setMinWidth(Button.USE_PREF_SIZE); cancelBtn.setPrefWidth(BTN_SIZE); cancelBtn.setOnAction(new EventHandler<ActionEvent>() { @Override//from w w w. j a v a 2s .co m public void handle(ActionEvent arg0) { _actionTaken = reportAction(msg("action.cancelled")); primaryStage.close(); } }); } return cancelBtn; }
From source file:be.makercafe.apps.makerbench.Main.java
/** * Creates the viewer control//from w w w . j a v a 2s . c o m * * @return */ private TreeView<String> createViewer() { TreeView<String> viewer = new TreeView<String>(setRootFolder(new File(this.pathMakerbenchHome))); viewer.setMinWidth(200.0); viewer.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); viewer.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getClickCount() == 2) { ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel() .getSelectedItem(); // System.out.println("Selected Text : " + item.getValue()); createEditor(item.getValue(), item.getPath(), null); } else if (mouseEvent.getButton() == MouseButton.SECONDARY) { ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel() .getSelectedItem(); if (item.getPath().toFile().isFile()) { viewer.getContextMenu().getItems().get(0).setDisable(true); viewer.getContextMenu().getItems().get(1).setDisable(true); viewer.getContextMenu().getItems().get(2).setDisable(true); } else { viewer.getContextMenu().getItems().get(0).setDisable(false); viewer.getContextMenu().getItems().get(1).setDisable(false); viewer.getContextMenu().getItems().get(2).setDisable(false); } } } }); viewer.setContextMenu(rootContextMenu); viewer.setEditable(false); viewer.setShowRoot(false); return viewer; }
From source file:com.danilafe.sbaccountmanager.StarboundServerAccountManager.java
private void createBannedUser(ListView<String> to_update) { Stage createBannedUser = new Stage(); createBannedUser.setTitle("Add Banned User"); createBannedUser.initModality(Modality.APPLICATION_MODAL); GridPane gp = new GridPane(); gp.setPadding(new Insets(25, 25, 25, 25)); gp.setAlignment(Pos.CENTER);//from ww w . j ava 2 s. c om gp.setVgap(10); gp.setHgap(10); Text title = new Text("Add Banned Username"); title.setFont(Font.font("Century Gothic", FontWeight.NORMAL, 20)); gp.add(title, 0, 0, 2, 1); Label newusername = new Label("Ban Username"); TextField username = new TextField(); gp.add(newusername, 0, 1); gp.add(username, 1, 1); Button finish = new Button("Finish"); HBox finish_box = new HBox(10); finish_box.setAlignment(Pos.CENTER); finish_box.getChildren().add(finish); finish.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { banned_usernames.remove(username.getText()); banned_usernames.add(username.getText()); to_update.setItems(FXCollections.observableArrayList(banned_usernames)); createBannedUser.close(); } }); gp.add(finish_box, 0, 2, 2, 1); Scene sc = new Scene(gp, 300, 175); createBannedUser.setScene(sc); createBannedUser.show(); }
From source file:Jigs_Desktop_Client.GUI.FXMLDocumentController.java
@Override public void initialize(URL url, ResourceBundle rb) { this.alert("resources/app_launch.mp3"); this.user_name.requestFocus(); this.btn_logout.setDisable(true); this.jc.setStatus(from_user, "online"); this.my_circle_list.setCellFactory(new Callback<ListView<UserStatus>, ListCell<UserStatus>>() { @Override/*w w w . j a v a2 s . c o m*/ public ListCell<UserStatus> call(ListView<UserStatus> userObj) { ListCell<UserStatus> cell = new ListCell<UserStatus>() { @Override protected void updateItem(UserStatus usrObj, boolean btnl) { super.updateItem(usrObj, btnl); if (usrObj != null) { String filename = usrObj.getStatus(); if (filename == null || filename.equals("") || filename.equals("null")) filename = "offline"; else System.out.println(filename); Image img = new Image( getClass().getResource("resources/" + filename + ".png").toExternalForm()); ImageView imv = new ImageView(img); setGraphic(imv); setText(usrObj.getUsername()); } } }; return cell; } }); this.main_panel.setBackground(Background.EMPTY); this.text_message.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent keyEvent) { if (keyEvent.getCode() == KeyCode.ENTER) { sendMessage(null); keyEvent.consume(); } } }); }
From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXSchemaRefPickerPane.java
public CFBamJavaFXSchemaRefPickerPane(ICFFormManager formManager, ICFBamJavaFXSchema argSchema, ICFBamSchemaRefObj argFocus, ICFBamSchemaDefObj argContainer, Collection<ICFBamSchemaRefObj> argDataCollection, ICFBamJavaFXSchemaRefChosen whenChosen) { super();/*from w w w . j a v a 2 s . c o m*/ final String S_ProcName = "construct-schema-focus"; if (formManager == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "formManager"); } cfFormManager = formManager; if (argSchema == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 2, "argSchema"); } if (whenChosen == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 6, "whenChosen"); } invokeWhenChosen = whenChosen; // argFocus is optional; focus may be set later during execution as // conditions of the runtime change. javafxSchema = argSchema; javaFXFocus = argFocus; javafxContainer = argContainer; setJavaFXDataCollection(argDataCollection); dataTable = new TableView<ICFBamSchemaRefObj>(); tableColumnId = new TableColumn<ICFBamSchemaRefObj, Long>("Id"); tableColumnId.setCellValueFactory( new Callback<CellDataFeatures<ICFBamSchemaRefObj, Long>, ObservableValue<Long>>() { public ObservableValue<Long> call(CellDataFeatures<ICFBamSchemaRefObj, Long> p) { ICFBamScopeObj obj = p.getValue(); if (obj == null) { return (null); } else { long value = obj.getRequiredId(); Long wrapped = new Long(value); ReadOnlyObjectWrapper<Long> observable = new ReadOnlyObjectWrapper<Long>(); observable.setValue(wrapped); return (observable); } } }); tableColumnId.setCellFactory( new Callback<TableColumn<ICFBamSchemaRefObj, Long>, TableCell<ICFBamSchemaRefObj, Long>>() { @Override public TableCell<ICFBamSchemaRefObj, Long> call(TableColumn<ICFBamSchemaRefObj, Long> arg) { return new CFInt64TableCell<ICFBamSchemaRefObj>(); } }); dataTable.getColumns().add(tableColumnId); tableColumnName = new TableColumn<ICFBamSchemaRefObj, String>("Name"); tableColumnName.setCellValueFactory( new Callback<CellDataFeatures<ICFBamSchemaRefObj, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<ICFBamSchemaRefObj, String> p) { ICFBamSchemaRefObj obj = p.getValue(); if (obj == null) { return (null); } else { String value = obj.getRequiredName(); ReadOnlyObjectWrapper<String> observable = new ReadOnlyObjectWrapper<String>(); observable.setValue(value); return (observable); } } }); tableColumnName.setCellFactory( new Callback<TableColumn<ICFBamSchemaRefObj, String>, TableCell<ICFBamSchemaRefObj, String>>() { @Override public TableCell<ICFBamSchemaRefObj, String> call(TableColumn<ICFBamSchemaRefObj, String> arg) { return new CFStringTableCell<ICFBamSchemaRefObj>(); } }); dataTable.getColumns().add(tableColumnName); tableColumnRefModelName = new TableColumn<ICFBamSchemaRefObj, String>("Ref. Model Name"); tableColumnRefModelName.setCellValueFactory( new Callback<CellDataFeatures<ICFBamSchemaRefObj, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<ICFBamSchemaRefObj, String> p) { ICFBamSchemaRefObj obj = p.getValue(); if (obj == null) { return (null); } else { String value = obj.getRequiredRefModelName(); ReadOnlyObjectWrapper<String> observable = new ReadOnlyObjectWrapper<String>(); observable.setValue(value); return (observable); } } }); tableColumnRefModelName.setCellFactory( new Callback<TableColumn<ICFBamSchemaRefObj, String>, TableCell<ICFBamSchemaRefObj, String>>() { @Override public TableCell<ICFBamSchemaRefObj, String> call(TableColumn<ICFBamSchemaRefObj, String> arg) { return new CFStringTableCell<ICFBamSchemaRefObj>(); } }); dataTable.getColumns().add(tableColumnRefModelName); tableColumnIncludeRoot = new TableColumn<ICFBamSchemaRefObj, String>("Include Root"); tableColumnIncludeRoot.setCellValueFactory( new Callback<CellDataFeatures<ICFBamSchemaRefObj, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<ICFBamSchemaRefObj, String> p) { ICFBamSchemaRefObj obj = p.getValue(); if (obj == null) { return (null); } else { String value = obj.getRequiredIncludeRoot(); ReadOnlyObjectWrapper<String> observable = new ReadOnlyObjectWrapper<String>(); observable.setValue(value); return (observable); } } }); tableColumnIncludeRoot.setCellFactory( new Callback<TableColumn<ICFBamSchemaRefObj, String>, TableCell<ICFBamSchemaRefObj, String>>() { @Override public TableCell<ICFBamSchemaRefObj, String> call(TableColumn<ICFBamSchemaRefObj, String> arg) { return new CFStringTableCell<ICFBamSchemaRefObj>(); } }); dataTable.getColumns().add(tableColumnIncludeRoot); tableColumnLookupRefSchema = new TableColumn<ICFBamSchemaRefObj, ICFBamSchemaDefObj>("Referenced Schema"); tableColumnLookupRefSchema.setCellValueFactory( new Callback<CellDataFeatures<ICFBamSchemaRefObj, ICFBamSchemaDefObj>, ObservableValue<ICFBamSchemaDefObj>>() { public ObservableValue<ICFBamSchemaDefObj> call( CellDataFeatures<ICFBamSchemaRefObj, ICFBamSchemaDefObj> p) { ICFBamSchemaRefObj obj = p.getValue(); if (obj == null) { return (null); } else { ICFBamSchemaDefObj ref = obj.getOptionalLookupRefSchema(); ReadOnlyObjectWrapper<ICFBamSchemaDefObj> observable = new ReadOnlyObjectWrapper<ICFBamSchemaDefObj>(); observable.setValue(ref); return (observable); } } }); tableColumnLookupRefSchema.setCellFactory( new Callback<TableColumn<ICFBamSchemaRefObj, ICFBamSchemaDefObj>, TableCell<ICFBamSchemaRefObj, ICFBamSchemaDefObj>>() { @Override public TableCell<ICFBamSchemaRefObj, ICFBamSchemaDefObj> call( TableColumn<ICFBamSchemaRefObj, ICFBamSchemaDefObj> arg) { return new CFReferenceTableCell<ICFBamSchemaRefObj, ICFBamSchemaDefObj>(); } }); dataTable.getColumns().add(tableColumnLookupRefSchema); dataTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ICFBamSchemaRefObj>() { @Override public void changed(ObservableValue<? extends ICFBamSchemaRefObj> observable, ICFBamSchemaRefObj oldValue, ICFBamSchemaRefObj newValue) { setJavaFXFocus(newValue); if (buttonChooseSelected != null) { if (newValue != null) { buttonChooseSelected.setDisable(false); } else { buttonChooseSelected.setDisable(true); } } } }); hboxMenu = new CFHBox(10); buttonCancel = new CFButton(); buttonCancel.setMinWidth(200); buttonCancel.setText("Cancel"); buttonCancel.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { final String S_ProcName = "handle"; try { cfFormManager.closeCurrentForm(); } catch (Throwable t) { CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t); } } }); hboxMenu.getChildren().add(buttonCancel); buttonChooseNone = new CFButton(); buttonChooseNone.setMinWidth(200); buttonChooseNone.setText("ChooseNone"); buttonChooseNone.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { final String S_ProcName = "handle"; try { ICFBamSchemaObj schemaObj = (ICFBamSchemaObj) javafxSchema.getSchema(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "schemaObj"); } invokeWhenChosen.choseSchemaRef(null); cfFormManager.closeCurrentForm(); } catch (Throwable t) { CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t); } } }); hboxMenu.getChildren().add(buttonChooseNone); buttonChooseSelected = new CFButton(); buttonChooseSelected.setMinWidth(200); buttonChooseSelected.setText("ChooseSelected"); buttonChooseSelected.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { final String S_ProcName = "handle"; try { ICFBamSchemaObj schemaObj = (ICFBamSchemaObj) javafxSchema.getSchema(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "schemaObj"); } ICFBamSchemaRefObj selectedInstance = getJavaFXFocusAsSchemaRef(); invokeWhenChosen.choseSchemaRef(selectedInstance); cfFormManager.closeCurrentForm(); } catch (Throwable t) { CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t); } } }); hboxMenu.getChildren().add(buttonChooseSelected); if (argFocus != null) { dataTable.getSelectionModel().select(argFocus); } setTop(hboxMenu); setCenter(dataTable); }
From source file:com.neuronrobotics.bowlerstudio.MainController.java
private void setToLoggedIn(final String name) { // new Exception().printStackTrace(); FxTimer.runLater(Duration.ofMillis(100), () -> { logoutGithub.disableProperty().set(false); logoutGithub.setText("Log out " + name); new Thread() { public void run() { GitHub github = ScriptingEngine.getGithub(); while (github == null) { github = ScriptingEngine.getGithub(); ThreadUtil.wait(20); }//from w ww . j a va 2 s. co m try { GHMyself myself = github.getMyself(); PagedIterable<GHGist> gists = myself.listGists(); Platform.runLater(() -> { myGists.getItems().clear(); }); ThreadUtil.wait(20); for (GHGist gist : gists) { String desc = gist.getDescription(); if (desc == null || desc.length() == 0) { desc = gist.getFiles().keySet().toArray()[0].toString(); } Menu tmpGist = new Menu(desc); MenuItem loadWebGist = new MenuItem("Show Web Gist..."); loadWebGist.setOnAction(event -> { String webURL = gist.getHtmlUrl(); try { BowlerStudio.openUrlInNewTab(new URL(webURL)); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }); MenuItem addFile = new MenuItem("Add file to Gist..."); addFile.setOnAction(event -> { new Thread() { public void run() { } }.start(); }); Platform.runLater(() -> { tmpGist.getItems().addAll(addFile, loadWebGist); }); EventHandler<Event> loadFiles = new EventHandler<Event>() { @Override public void handle(Event ev) { // for(ScriptingEngine.) new Thread() { public void run() { System.out.println("Loading files"); ArrayList<String> listofFiles = ScriptingEngine .filesInGit(gist.getGitPushUrl(), "master", null); for (String s : listofFiles) { MenuItem tmp = new MenuItem(s); tmp.setOnAction(event -> { new Thread() { public void run() { try { File fileSelected = ScriptingEngine .fileFromGit(gist.getGitPushUrl(), s); BowlerStudio.createFileTab(fileSelected); } catch (Exception e) { // TODO // Auto-generated // catch block e.printStackTrace(); } } }.start(); }); Platform.runLater(() -> { tmpGist.getItems().add(tmp); tmpGist.setOnShowing(null); }); } Platform.runLater(() -> { tmpGist.hide(); Platform.runLater(() -> { tmpGist.show(); }); }); } }.start(); } }; tmpGist.setOnShowing(loadFiles); Platform.runLater(() -> { myGists.getItems().add(tmpGist); }); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); }); }
From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java
@FXML void initialize() { assert clearLogButton != null : "fx:id=\"clearLogButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert fundsTable != null : "fx:id=\"fundsTable\" was not injected: check your FXML file 'mainlayout.fxml'."; assert logField != null : "fx:id=\"logField\" was not injected: check your FXML file 'mainlayout.fxml'."; assert buyButton != null : "fx:id=\"buyButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert sellButton != null : "fx:id=\"sellButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert showActiveOrdersButton != null : "fx:id=\"showActiveOrdersButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableLastColumn != null : "fx:id=\"tickerTableLastColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTablePairColumn != null : "fx:id=\"tickerTablePairColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTable != null : "fx:id=\"tickersTable\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableBuyColumn != null : "fx:id=\"tickersTableBuyColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableFeeColumn != null : "fx:id=\"tickersTableFeeColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableSellColumn != null : "fx:id=\"tickersTableSellColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradeAmountValue != null : "fx:id=\"tradeAmountValue\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradePriceCurrencyType != null : "fx:id=\"tradeCurrencyPriceValue\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradeCurrencyType != null : "fx:id=\"tradeCurrencyType\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradePriceValue != null : "fx:id=\"tradePriceValue\" was not injected: check your FXML file 'mainlayout.fxml'."; assert updateFundsButton != null : "fx:id=\"updateFundsButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert fundsTableCurrencyColumn != null : "fx:id=\"fundsTableCurrencyColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert fundsTableValueColumn != null : "fx:id=\"fundsTableValueColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersTable != null : "fx:id=\"fundsTableValueColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersAmountColumn != null : "fx:id=\"activeOrdersAmountColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersPairColumn != null : "fx:id=\"activeOrdersPairColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersRateColumn != null : "fx:id=\"activeOrdersRateColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersTimeColumn != null : "fx:id=\"activeOrdersTimeColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersTypeColumn != null : "fx:id=\"activeOrdersTypeColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersCancelColumn != null : "fx:id=\"activeOrdersCancelColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; //Holder for all main API methods of exchange app = new App(); //Loading configs loadExchangeConfig();//from www . j a v a 2s . c o m //Populate choiceboxes at the trading section tradeCurrencyType.setItems(FXCollections.observableArrayList(currencies)); tradeCurrencyType.setValue(currencies.get(0)); tradePriceCurrencyType.setItems(FXCollections.observableArrayList(currencies)); tradePriceCurrencyType.setValue(currencies.get(0)); //Active Orders table activeOrdersAmountColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, Double>("amount")); activeOrdersPairColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, String>("pair")); activeOrdersRateColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, Double>("rate")); activeOrdersTimeColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ActiveOrder, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call( TableColumn.CellDataFeatures<ActiveOrder, String> activeOrderStringCellDataFeatures) { ActiveOrder activeOrder = activeOrderStringCellDataFeatures.getValue(); DateFormat dateFormat = DateFormat.getDateTimeInstance(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(activeOrder.getTimestamp() * 1000); return new SimpleStringProperty(dateFormat.format(calendar.getTime())); } }); activeOrdersTypeColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, String>("type")); activeOrdersTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); activeOrdersCancelColumn .setCellFactory(new Callback<TableColumn<ActiveOrder, Boolean>, TableCell<ActiveOrder, Boolean>>() { @Override public TableCell<ActiveOrder, Boolean> call( TableColumn<ActiveOrder, Boolean> activeOrderBooleanTableColumn) { return new ButtonCell<>(activeOrdersTable); } }); activeOrdersCancelColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ActiveOrder, Boolean>, ObservableValue<Boolean>>() { @Override public ObservableValue<Boolean> call( TableColumn.CellDataFeatures<ActiveOrder, Boolean> activeOrderBooleanCellDataFeatures) { return new SimpleBooleanProperty(true); } }); //Tickers Table MenuItem showOrdersBook = new MenuItem("Show Orders Book"); MenuItem showPublicTrades = new MenuItem("Show Public Trades"); ContextMenu contextMenu = new ContextMenu(showOrdersBook, showPublicTrades); tickersTable.setItems(tickers); tickersTable.setContextMenu(contextMenu); tickersTableBuyColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("buy")); tickersTableFeeColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("fee")); tickersTableSellColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("sell")); tickersTableLastColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("last")); tickersTablePairColumn.setCellValueFactory(new PropertyValueFactory<Ticker, String>("pair")); tickersTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tickersTable.setRowFactory(new Callback<TableView<Ticker>, TableRow<Ticker>>() { @Override public TableRow<Ticker> call(TableView<Ticker> tickerTableView) { return new TableRow<Ticker>() { @Override protected void updateItem(Ticker ticker, boolean b) { super.updateItem(ticker, b); if (!b) { if (tickersData.containsKey(ticker.getPair())) { if (ticker.getLast() < tickersData.get(ticker.getPair()).getLast()) { setStyle("-fx-control-inner-background: rgba(186, 0, 0, 0.5);"); } else if (ticker.getLast() == tickersData.get(ticker.getPair()).getLast()) { setStyle("-fx-control-inner-background: rgba(215, 193, 44, 0.5);"); } else { setStyle("-fx-control-inner-background: rgba(0, 147, 0, 0.5);"); } } } } }; } }); //Menu item to show Orders Book showOrdersBook.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { Ticker selectedTicker = tickersTable.getSelectionModel().getSelectedItem(); Parent root; try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(PATH_TO_ORDERS_BOOK_LAYOUT), resources); root = (Parent) fxmlLoader.load(); OrdersBookController ordersBookController = fxmlLoader.getController(); ordersBookController.injectPair(selectedTicker.getPair()); Stage stage = new Stage(); stage.setTitle("Orders Book for " + selectedTicker.getPair().replace("_", "/").toUpperCase()); stage.setScene(new Scene(root)); stage.setResizable(false); stage.show(); } catch (IOException e) { e.printStackTrace(); } } }); //Menu item to show Public Trades showPublicTrades.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { Ticker selectedTicker = tickersTable.getSelectionModel().getSelectedItem(); Parent root; try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(PATH_TO_TRADES_LAYOUT), resources); root = (Parent) fxmlLoader.load(); PublicTradesController publicTradesController = fxmlLoader.getController(); publicTradesController.injectPair(selectedTicker.getPair()); Stage stage = new Stage(); stage.setTitle("Public Trades for " + selectedTicker.getPair().replace("_", "/").toUpperCase()); stage.setScene(new Scene(root)); stage.setResizable(false); stage.show(); } catch (IOException e) { e.printStackTrace(); } } }); //Funds Table fundsTableCurrencyColumn.setCellValueFactory(new PropertyValueFactory<Fund, String>("currency")); fundsTableValueColumn.setCellValueFactory(new PropertyValueFactory<Fund, Double>("value")); fundsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); fundsTable.setItems(fundsData); //Task to load tickers data from server final javafx.concurrent.Service loadTickersService = new javafx.concurrent.Service() { @Override protected Task createTask() { Task<JSONObject> loadTickers = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { String[] pairsArray = new String[pairs.size()]; pairsArray = pairs.toArray(pairsArray); return App.getPairInfo(pairsArray); } }; loadTickers.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n"); } }); loadTickers.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); //ugly hack to store old values //dump old values to tickersData //TODO think about better solution if (tickers.size() != 0) { for (Ticker x : tickers) { tickersData.put(x.getPair(), x); } } tickers.clear(); for (Iterator iterator = jsonObject.keys(); iterator.hasNext();) { String key = (String) iterator.next(); JSONObject data = jsonObject.getJSONObject(key); Ticker ticker = new Ticker(); ticker.setPair(key); ticker.setUpdated(data.optLong("updated")); ticker.setAvg(data.optDouble("avg")); ticker.setBuy(data.optDouble("buy")); ticker.setSell(data.optDouble("sell")); ticker.setHigh(data.optDouble("high")); ticker.setLast(data.optDouble("last")); ticker.setLow(data.optDouble("low")); ticker.setVol(data.optDouble("vol")); ticker.setVolCur(data.optDouble("vol_cur")); tickers.add(ticker); } } }); return loadTickers; } }; //Update tickers every 15 seconds //TODO better solution is required Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { loadTickersService.restart(); } }), new KeyFrame(Duration.seconds(15))); timeline.setCycleCount(Timeline.INDEFINITE); timeline.playFromStart(); }
From source file:com.core.meka.SOMController.java
private void initListeners() { entradas_text.textProperty().addListener(new ChangeListener<String>() { @Override// w w w. j a v a2s . c om public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { if (!newValue.matches("\\d*")) { entradas_text.setText(newValue.replaceAll("[^\\d]", "")); } } }); epocas_text.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { if (!newValue.matches("\\d*")) { epocas_text.setText(newValue.replaceAll("[^\\d]", "")); } } }); neuronas_text.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { if (!newValue.matches("\\d*")) { neuronas_text.setText(newValue.replaceAll("[^\\d]", "")); } } }); pesos_check.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!newValue) { pesos_label.setVisible(true); pesos_text.setVisible(true); } else { pesos_label.setVisible(false); pesos_text.setVisible(false); } } }); base.setOnKeyReleased(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode().equals(KeyCode.ESCAPE)) { Util.closeWindow(ac); } } }); cargar_patrones_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { try { String patrones = cargarArrayDesdeArchivo(); patrones_train_text.setText(patrones); } catch (IOException ex) { Logger.getLogger(SOMController.class.getName()).log(Level.SEVERE, null, ex); result_text.setText("Excepcion capturada, verifique la pila: \n" + ex.getMessage()); } } }); cargar_pesos_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { try { String patrones = cargarArrayDesdeArchivo(); pesos_text.setText(patrones); } catch (IOException ex) { Logger.getLogger(SOMController.class.getName()).log(Level.SEVERE, null, ex); result_text.setText("Excepcion capturada, verifique la pila: \n" + ex.getMessage()); } } }); patrones_test_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { try { String patrones = cargarArrayDesdeArchivo(); patrones_test_text.setText(patrones); } catch (IOException ex) { Logger.getLogger(SOMController.class.getName()).log(Level.SEVERE, null, ex); result_text.setText("Excepcion capturada, verifique la pila: \n" + ex.getMessage()); } } }); nueva_simulacion_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { borrar(neuronas_text, epocas_text, entradas_text); borrar(patrones_train_text, pesos_text); } }); ejecutar_entrenamiento_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { tab.getSelectionModel().select(train_tab); train(); } }); ejecutar_test_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { test(); } }); guardar_patrones_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String patrones = formatArray(patrones_train_text.getText()); tab.getSelectionModel().selectFirst(); try { guardarArrayAArchivo(patrones.replaceAll(";", ";\n"), result_text); } catch (IOException ex) { result_text.setText("Excepcion capturada:\n" + ex.getMessage().replaceAll("\\)", "\\)\n") + result_text.getText()); Logger.getLogger(SOMController.class.getName()).log(Level.SEVERE, null, ex); } } }); guardar_pesos_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String patrones = formatArray(pesos_text.getText()); tab.getSelectionModel().selectFirst(); try { guardarArrayAArchivo(patrones.replaceAll(";", ";\n"), result_text); } catch (IOException ex) { result_text.setText("Excepcion capturada:\n" + ex.getMessage().replaceAll("\\)", "\\)\n") + result_text.getText()); Logger.getLogger(SOMController.class.getName()).log(Level.SEVERE, null, ex); } } }); guardar_patrones_test_menuitem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String patrones = formatArray(patrones_test_text.getText()); tab.getSelectionModel().selectFirst(); try { guardarArrayAArchivo(patrones.replaceAll(";", ";\n"), result_text); } catch (IOException ex) { result_text.setText("Excepcion capturada:\n" + ex.getMessage().replaceAll("\\)", "\\)\n") + result_text.getText()); Logger.getLogger(SOMController.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:com.danilafe.sbaccountmanager.StarboundServerAccountManager.java
private void createBannedIP(ListView<String> to_update) { Stage createBannedIP = new Stage(); createBannedIP.setTitle("Add Banned IP"); createBannedIP.initModality(Modality.APPLICATION_MODAL); GridPane gp = new GridPane(); gp.setPadding(new Insets(25, 25, 25, 25)); gp.setAlignment(Pos.CENTER);//from ww w . j av a 2 s. co m gp.setVgap(10); gp.setHgap(10); Text title = new Text("Add Banned IP"); title.setFont(Font.font("Century Gothic", FontWeight.NORMAL, 20)); gp.add(title, 0, 0, 2, 1); Label newusername = new Label("Ban IP"); TextField username = new TextField(); gp.add(newusername, 0, 1); gp.add(username, 1, 1); Button finish = new Button("Finish"); HBox finish_box = new HBox(10); finish_box.setAlignment(Pos.CENTER); finish_box.getChildren().add(finish); finish.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { banned_ips.remove(username.getText()); banned_ips.add(username.getText()); to_update.setItems(FXCollections.observableArrayList(banned_ips)); createBannedIP.close(); } }); gp.add(finish_box, 0, 2, 2, 1); Scene sc = new Scene(gp, 300, 175); createBannedIP.setScene(sc); createBannedIP.show(); }
From source file:be.makercafe.apps.makerbench.Main.java
/** * Creates the menubar//from ww w . j a v a 2 s.c o m * * @return */ private MenuBar createMenuBar() { MenuBar bar = new MenuBar(); Menu projectMenu = new Menu("Project"); MenuItem openProject = new MenuItem("Open..."); openProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { directoryChooser.setTitle("Please choose a project folder"); File file = directoryChooser.showDialog(stage); viewer.setRoot(setRootFolder(file)); } }); Menu newProject = new Menu("New"); MenuItem newFolder = new MenuItem("Folder..."); newFolder.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { TextInputDialog dialog = new TextInputDialog("my_project_folder"); dialog.setTitle("New folder"); dialog.setHeaderText("Create a new folder"); dialog.setContentText("Folder name:"); Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { String homeDir = System.getProperty("user.home"); System.out.println("Folder name: " + result.get()); System.out.println("User home: " + homeDir); } } }); newProject.getItems().add(newFolder); MenuItem importProject = new MenuItem("Import"); importProject.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCombination.CONTROL_DOWN)); importProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Import"); } }); MenuItem deleteProject = new MenuItem("Delete"); deleteProject.setAccelerator(new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN)); deleteProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Delete"); } }); projectMenu.getItems().addAll(openProject, newProject, importProject, deleteProject); Menu helpMenu = new Menu("Help"); MenuItem aboutItem = new MenuItem("About"); aboutItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Information Dialog"); alert.setHeaderText("About makerbench"); alert.setContentText( "Makerbench is an open source IDE for designing and manufacturing objects and code.\nWritten by Luc De pauw\n\nUses opensource libraries from the next projects:\n-RichtextFX by Tomas Mikula\n-JCSG by Michael Hoffer\n-ControlsFX by FXexperience.com"); alert.showAndWait(); } }); helpMenu.getItems().add(aboutItem); bar.getMenus().addAll(projectMenu, helpMenu); return bar; }