List of usage examples for javafx.scene.control TableRow TableRow
public TableRow()
From source file:investor.views.CompaniesView.java
public void InitView() { selectedRange = DataRange.THREEMONTH; selectedChart = "line"; pane = new VBox(); lineChart = LinearChartManager.linear(); lineChart.setTitle(""); table = new TableView(); try {/*from w w w. j a v a 2s . com*/ table.getItems().addAll(NetworkManager.show(DataType.SPOL)); } catch (Exception e) { System.out.println("Something went wrong when populating market indicisies view"); } table.getColumns().addAll(initColumns()); table.setRowFactory(tv -> { TableRow<Index> row = new TableRow<Index>(); row.setOnMouseClicked(event -> { if (event.getClickCount() == 2 && (!row.isEmpty())) { Index rowData = row.getItem(); selectedIndex = rowData; //System.out.println(rowData); try { lastData = NetworkManager.showMore(rowData.getSymbol(), selectedRange); System.out.println(lastData.length); if (selectedChart.equals("line")) { lineChart.getData().clear(); lineChart.setTitle(rowData.getName()); LinearChartManager.addSeries(lineChart, lastData, selectedRange); if (pointerType != null && pointerType != "hide") { OnPointerChange(); } } else { CandleChart.generateData(lastData); candleChart = new CandleChart(); CandleChart.CandleStickChart chart = candleChart.createChart(); chart.setTitle(rowData.getName()); pane.getStylesheets().add("resources/css/CandleStickChart.css"); borderPane.setCenter(chart); } } catch (Exception ex) { System.out.println("Error while downloading indicise " + ex.toString()); } } }); return row; }); //table.setItems(initRows()); table.setEditable(false); VBox vBox = (VBox) pane; borderPane = new BorderPane(); borderPane.setCenter(lineChart); borderPane.setRight(addMenuButtons()); vBox.getChildren().add(table); vBox.getChildren().add(borderPane); }
From source file:investor.views.MarketIndicisesView.java
public void InitView() { pane = new VBox(); //Stworzenie wykresu lineChart = LinearChartManager.linear(); lineChart.setTitle(""); //Poczatkowo zakres dat to 3M selectedRange = DataRange.THREEMONTH; selectedChart = "line"; //Stworzenie tabelki table = new TableView(); //Scigamy dane dla tabelki z serwera i populujemy tabelke try {//from ww w . ja va 2 s.c om table.getItems().addAll(NetworkManager.show(DataType.WSK)); } catch (Exception e) { System.out.println("Something went wrong when populating market indicisies view"); } //Dodajemy kolumny do tabelki table.getColumns().addAll(initColumns()); //Obsuga kliknicia wiersza w tabelce table.setRowFactory(tv -> { TableRow<Index> row = new TableRow<Index>(); row.setOnMouseClicked(event -> { if (event.getClickCount() == 2 && (!row.isEmpty())) { //Zapamitujemy wybrany wiersz dla widoku Index rowData = row.getItem(); selectedIndex = rowData; //System.out.println(rowData); try { //Scigamy dane z serwera dla danego wiersza i dodajemy je do wykresu lastData = NetworkManager.showMore(rowData.getSymbol(), selectedRange); System.out.println(lastData.length); if (selectedChart.equals("line")) { lineChart.getData().clear(); LinearChartManager.addSeries(lineChart, lastData, selectedRange); lineChart.setTitle(rowData.getName()); if (pointerType != null && pointerType != "hide") { OnPointerChange(); } } else { CandleChart.generateData(lastData); candleChart = new CandleChart(); CandleChart.CandleStickChart chart = candleChart.createChart(); chart.setTitle(rowData.getName()); pane.getStylesheets().add("resources/css/CandleStickChart.css"); borderPane.setCenter(chart); } } catch (Exception ex) { System.out.println("Error while downloading indicise " + ex.toString()); } } }); return row; }); //table.setItems(initRows()); table.setEditable(false); VBox vBox = (VBox) pane; //Panel dla wykresu i przyciskw konfiguracyjnych borderPane = new BorderPane(); //Po rodku wykres borderPane.setCenter(lineChart); //Na prawo przyciski konfiguracyjne borderPane.setRight(addMenuButtons()); //Dodanie do panelu widoku tabelki vBox.getChildren().add(table); //Dodanie do panelu widoku panelu z wykresem i przyciskami konfiguracyjnymi vBox.getChildren().add(borderPane); }
From source file:org.jacp.demo.components.ContactTableViewComponent.java
private Callback<TableView<Contact>, TableRow<Contact>> createRowCallback() { return new Callback<TableView<Contact>, TableRow<Contact>>() { @Override//from w ww .j a v a 2 s .c o m public TableRow<Contact> call(final TableView<Contact> arg0) { final TableRow<Contact> row = new TableRow<Contact>() { @Override public void updateItem(final Contact contact, final boolean emty) { super.updateItem(contact, emty); if (contact != null) { this.setOnMouseClicked(new EventHandler<Event>() { @Override public void handle(final Event arg0) { // send contact to TableView // component to show containing // contacts context.send(GlobalConstants.cascade( GlobalConstants.PerspectiveConstants.DEMO_PERSPECTIVE, GlobalConstants.CallbackConstants.CALLBACK_ANALYTICS), contact); context.send( GlobalConstants.cascade( GlobalConstants.PerspectiveConstants.DEMO_PERSPECTIVE, GlobalConstants.ComponentConstants.COMPONENT_DETAIL_VIEW), contact); } }); } } }; return row; } }; }
From source file:app.order.OrderController.java
public void setCheckRowColor() { //Change Color of Check Table PseudoClass nonpaye = PseudoClass.getPseudoClass("nonpaye"); PseudoClass paye = PseudoClass.getPseudoClass("paye"); PseudoClass impaye = PseudoClass.getPseudoClass("impaye"); //PseudoClass down = PseudoClass.getPseudoClass("down"); checkTable.setRowFactory(tableView -> { TableRow<Check> row = new TableRow<>(); ChangeListener<PaymentState> changeListener = (obs, oldState, newState) -> { // row.pseudoClassStateChanged(nonpaye, oldState.equals(CheckState.NONPAYE.toString())); // row.pseudoClassStateChanged(paye, oldState.equals(CheckState.PAYE.toString())); // row.pseudoClassStateChanged(impaye, oldState.equals(CheckState.IMPAYE.toString())); row.pseudoClassStateChanged(nonpaye, oldState == PaymentState.NONPAYE); row.pseudoClassStateChanged(paye, oldState == PaymentState.PAYE); row.pseudoClassStateChanged(impaye, oldState == PaymentState.IMPAYE); };//from ww w . ja v a 2s . c o m row.itemProperty().addListener((obs, oldCheck, newCheck) -> { if (oldCheck != null) { oldCheck.paymentStateProperty().removeListener(changeListener); } if (newCheck != null) { newCheck.paymentStateProperty().addListener(changeListener); // row.pseudoClassStateChanged(nonpaye, newCheck.getState().equals(CheckState.NONPAYE.toString())); // row.pseudoClassStateChanged(paye, newCheck.getState().equals(CheckState.PAYE.toString())); // row.pseudoClassStateChanged(impaye, newCheck.getState().equals(CheckState.IMPAYE.toString())); row.pseudoClassStateChanged(nonpaye, newCheck.getPaymentState() == PaymentState.NONPAYE); row.pseudoClassStateChanged(paye, newCheck.getPaymentState() == PaymentState.PAYE); row.pseudoClassStateChanged(impaye, newCheck.getPaymentState() == PaymentState.IMPAYE); } else { row.pseudoClassStateChanged(nonpaye, false); row.pseudoClassStateChanged(paye, false); row.pseudoClassStateChanged(impaye, false); } }); return row; }); }
From source file:dtv.controller.FXMLMainController.java
public void init(ObservableList<DVBChannel> serviceData, TableView<DVBChannel> table, TableColumn<DVBChannel, Integer> idx, TableColumn<DVBChannel, String> name, TableColumn<DVBChannel, String> type, TableColumn<DVBChannel, String> ppr) { table.setEditable(true);//from ww w . j a va2 s . c om idx.setCellValueFactory(cellData -> cellData.getValue().idxProperty().asObject()); name.setCellValueFactory(cellData -> cellData.getValue().nameProperty()); name.setEditable(true); type.setCellValueFactory(cellData -> cellData.getValue().typeProperty()); // nid.setCellValueFactory(cellData -> cellData.getValue().nidProperty().asObject()); ppr.setCellValueFactory(cellData -> cellData.getValue().pprProperty()); // newCol.setCellValueFactory(cellData -> cellData.getValue().neewProperty()); // Context menu table.setRowFactory(tableView -> { final TableRow<DVBChannel> row = new TableRow<>(); final ContextMenu rowMenu = new ContextMenu(); final MenuItem removeItem = new MenuItem("Delete"); removeItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final DVBChannel service = row.getItem(); serviceData.removeAll(service); } }); rowMenu.getItems().addAll(removeItem); row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty())).then(rowMenu) .otherwise((ContextMenu) null)); return row; }); ppr.setCellFactory(col -> { final TableCell<DVBChannel, String> cell = new TableCell<>(); cell.textProperty().bind(cell.itemProperty()); cell.itemProperty().addListener((obs, oldValue, newValue) -> { if (newValue != null) { final ContextMenu cellMenu = new ContextMenu(); for (String pref : Utils.prefTab) { final CheckMenuItem prefMenuItem = new CheckMenuItem(pref); if (Utils.isPreferenceOn(cell.getText(), pref)) { prefMenuItem.setSelected(true); } prefMenuItem.selectedProperty().addListener((obs1, old_val, new_val) -> { final String new_ppr; final DVBChannel service = (DVBChannel) cell.getTableRow().getItem(); if (new_val) { new_ppr = Utils.add_ppr(cell.getText(), pref); } else { new_ppr = Utils.remove_ppr(cell.getText(), pref); } service.setPpr(new_ppr); service.setModified(true); }); cellMenu.getItems().add(prefMenuItem); cell.setContextMenu(cellMenu); } } else { cell.setContextMenu(null); } }); return cell; }); // Editable service name name.setCellFactory(p -> new EditingCell()); name.setOnEditCommit(t -> { final DVBChannel service = t.getTableView().getItems().get(t.getTablePosition().getRow()); service.setName(t.getNewValue()); service.setModified(true); }); }
From source file:com.github.drbookings.ui.controller.MainController.java
private Callback<TableView<DateBean>, TableRow<DateBean>> getRowFactory() { return param -> { final TableRow<DateBean> row = new TableRow<DateBean>() { @Override/*ww w .jav a 2s .com*/ protected void updateItem(final DateBean item, final boolean empty) { super.updateItem(item, empty); getStyleClass().removeAll("now", "end-of-month"); if (empty || item == null) { } else { if (item.getDate().isEqual(LocalDate.now())) { getStyleClass().add("now"); } else if (item.getDate().equals( item.getDate().with(java.time.temporal.TemporalAdjusters.lastDayOfMonth()))) { getStyleClass().add("end-of-month"); } else { } } } }; // final PseudoClass rowContainsSelectedCell = // PseudoClass.getPseudoClass("contains-selection"); // final BooleanBinding containsSelection = // Bindings.createBooleanBinding( // () -> rowsWithSelectedCells.contains(row.getIndex()), // rowsWithSelectedCells, row.indexProperty()); // containsSelection.addListener((obs, didContainSelection, // nowContainsSelection) -> row // .pseudoClassStateChanged(rowContainsSelectedCell, // nowContainsSelection)); return row; }; }
From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java
private void setupTableWithChanges(TableView<Change> tv, Dataset tp) { tv.setEditable(true);/*from w ww.j a v a2 s .com*/ tv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); tv.getColumns().clear(); TableColumn<Change, ChangeType> colChangeType = new TableColumn<>("Type"); colChangeType.setCellFactory(ComboBoxTableCell.forTableColumn(new ChangeTypeStringConverter(), ChangeType.ADDITION, ChangeType.DELETION, ChangeType.RENAME, ChangeType.LUMP, ChangeType.SPLIT, ChangeType.COMPLEX, ChangeType.ERROR)); colChangeType.setCellValueFactory(new PropertyValueFactory<>("type")); colChangeType.setPrefWidth(100.0); colChangeType.setEditable(true); tv.getColumns().add(colChangeType); TableColumn<Change, ObservableSet<Name>> colChangeFrom = new TableColumn<>("From"); colChangeFrom.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeFrom.setCellValueFactory(new PropertyValueFactory<>("from")); colChangeFrom.setPrefWidth(200.0); colChangeFrom.setEditable(true); tv.getColumns().add(colChangeFrom); TableColumn<Change, ObservableSet<Name>> colChangeTo = new TableColumn<>("To"); colChangeTo.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeTo.setCellValueFactory(new PropertyValueFactory<>("to")); colChangeTo.setPrefWidth(200.0); colChangeTo.setEditable(true); tv.getColumns().add(colChangeTo); TableColumn<Change, String> colExplicit = new TableColumn<>("Explicit or implicit?"); colExplicit.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getDataset().isChangeImplicit(features.getValue()) ? "Implicit" : "Explicit")); tv.getColumns().add(colExplicit); ChangeFilter cf = datasetView.getProjectView().getProject().getChangeFilter(); TableColumn<Change, String> colFiltered = new TableColumn<>("Eliminated by filter?"); colFiltered.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( cf.test(features.getValue()) ? "Allowed" : "Eliminated")); tv.getColumns().add(colFiltered); TableColumn<Change, String> colNote = new TableColumn<>("Note"); colNote.setCellFactory(TextFieldTableCell.forTableColumn()); colNote.setCellValueFactory(new PropertyValueFactory<>("note")); colNote.setPrefWidth(100.0); colNote.setEditable(true); tv.getColumns().add(colNote); TableColumn<Change, String> colCitations = new TableColumn<>("Citations"); colCitations.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getCitationStream().map(citation -> citation.getCitation()).sorted() .collect(Collectors.joining("; ")))); tv.getColumns().add(colCitations); TableColumn<Change, String> colGenera = new TableColumn<>("Genera"); colGenera.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> n.getGenus()) .distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colGenera); TableColumn<Change, String> colSpecificEpithet = new TableColumn<>("Specific epithets"); colSpecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper(String .join(", ", features.getValue().getAllNames().stream().map(n -> n.getSpecificEpithet()) .filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colSpecificEpithet); // The infraspecific string. TableColumn<Change, String> colInfraspecificEpithet = new TableColumn<>("Infraspecific epithets"); colInfraspecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream() .map(n -> n.getInfraspecificEpithetsAsString()).filter(s -> s != null) .distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colInfraspecificEpithet); // The very last epithet of all TableColumn<Change, String> colTerminalEpithet = new TableColumn<>("Terminal epithet"); colTerminalEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> { List<Name.InfraspecificEpithet> infraspecificEpithets = n.getInfraspecificEpithets(); if (!infraspecificEpithets.isEmpty()) { return infraspecificEpithets.get(infraspecificEpithets.size() - 1).getValue(); } else { return n.getSpecificEpithet(); } }).filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colTerminalEpithet); // Properties TableColumn<Change, String> colProperties = new TableColumn<>("Properties"); colProperties.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getProperties().entrySet().stream() .map(entry -> entry.getKey() + ": " + entry.getValue()).sorted() .collect(Collectors.joining("; ")))); tv.getColumns().add(colProperties); fillTableWithChanges(tv, tp); // When someone selects a cell in the Table, try to select the appropriate data in the // additional data view. tv.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Change>) lcl -> { AdditionalData aData = additionalDataCombobox.getSelectionModel().getSelectedItem(); if (aData != null) { aData.onSelectChange(tv.getSelectionModel().getSelectedItems()); } }); // Create a right-click menu for table rows. changesTableView.setRowFactory(table -> { TableRow<Change> row = new TableRow<>(); row.setOnContextMenuRequested(event -> { if (row.isEmpty()) return; // We don't currently use the clicked change, since currently all options // change *all* the selected changes, but this may change in the future. Change change = row.getItem(); ContextMenu changeMenu = new ContextMenu(); Menu searchForName = new Menu("Search for name"); searchForName.getItems().addAll( change.getAllNames().stream().sorted().map(n -> createMenuItem(n.getFullName(), action -> { datasetView.getProjectView().openDetailedView(n); })).collect(Collectors.toList())); changeMenu.getItems().add(searchForName); changeMenu.getItems().add(new SeparatorMenuItem()); changeMenu.getItems().add(createMenuItem("Edit note", action -> { List<Change> changes = new ArrayList<>(changesTableView.getSelectionModel().getSelectedItems()); String combinedNotes = changes.stream().map(ch -> ch.getNote().orElse("").trim()).distinct() .collect(Collectors.joining("\n")).trim(); Optional<String> result = askUserForTextArea( "Modify the note for these " + changes.size() + " changes:", combinedNotes); if (result.isPresent()) { String note = result.get().trim(); LOGGER.info("Using 'Edit note' to set note to '" + note + "' on changes " + changes); changes.forEach(ch -> ch.noteProperty().set(note)); } })); changeMenu.getItems().add(new SeparatorMenuItem()); // Create a submenu for tags and urls. String note = change.noteProperty().get(); Menu removeTags = new Menu("Tags"); removeTags.getItems().addAll(change.getTags().stream().sorted() .map(tag -> new MenuItem(tag.getName())).collect(Collectors.toList())); Menu lookupURLs = new Menu("Lookup URL"); change.getURIs().stream().sorted().map(uri -> { return createMenuItem(uri.toString(), evt -> { try { Desktop.getDesktop().browse(uri); } catch (IOException ex) { LOGGER.warning("Could not open URL '" + uri + "': " + ex); } }); }).forEach(mi -> lookupURLs.getItems().add(mi)); changeMenu.getItems().add(lookupURLs); changeMenu.getItems().add(new SeparatorMenuItem()); changeMenu.getItems().add(createMenuItem("Prepend text to all notes", action -> { List<Change> changes = new ArrayList<>(changesTableView.getSelectionModel().getSelectedItems()); Optional<String> result = askUserForTextField( "Enter tags to prepend to notes in " + changes.size() + " changes:"); if (result.isPresent()) { String tags = result.get().trim(); changes.forEach(ch -> { String prevValue = change.getNote().orElse("").trim(); LOGGER.info("Prepending tags '" + tags + "' to previous value '" + prevValue + "' for change " + ch); ch.noteProperty().set((tags + " " + prevValue).trim()); }); } })); changeMenu.getItems().add(createMenuItem("Append text to all notes", action -> { List<Change> changes = new ArrayList<>(changesTableView.getSelectionModel().getSelectedItems()); Optional<String> result = askUserForTextField( "Enter tags to append to notes in " + changes.size() + " changes:"); if (result.isPresent()) { String tags = result.get().trim(); changes.forEach(ch -> { String prevValue = ch.getNote().orElse("").trim(); LOGGER.info("Appending tags '" + tags + "' to previous value '" + prevValue + "' for change " + ch); ch.noteProperty().setValue((prevValue + " " + tags).trim()); }); } })); changeMenu.show(datasetView.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); return row; }); LOGGER.info("setupTableWithChanges() completed"); }
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 w w w .ja va2s . 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:eu.over9000.skadi.ui.MainWindow.java
private void setupTable() { this.table = new TableView<>(); this.liveCol = new TableColumn<>("Live"); this.liveCol.setCellValueFactory(p -> p.getValue().onlineProperty()); this.liveCol.setSortType(SortType.DESCENDING); this.liveCol.setCellFactory(p -> new LiveCell()); this.nameCol = new TableColumn<>("Channel"); this.nameCol.setCellValueFactory(p -> p.getValue().nameProperty()); this.titleCol = new TableColumn<>("Status"); this.titleCol.setCellValueFactory(p -> p.getValue().titleProperty()); this.gameCol = new TableColumn<>("Game"); this.gameCol.setCellValueFactory(p -> p.getValue().gameProperty()); this.viewerCol = new TableColumn<>("Viewer"); this.viewerCol.setCellValueFactory(p -> p.getValue().viewerProperty().asObject()); this.viewerCol.setSortType(SortType.DESCENDING); this.viewerCol.setCellFactory(p -> new RightAlignedCell<>()); this.uptimeCol = new TableColumn<>("Uptime"); this.uptimeCol.setCellValueFactory((p) -> p.getValue().uptimeProperty().asObject()); this.uptimeCol.setCellFactory(p -> new UptimeCell()); this.table.setPlaceholder(new Label("no channels added/matching the filters")); this.table.getColumns().add(this.liveCol); this.table.getColumns().add(this.nameCol); this.table.getColumns().add(this.titleCol); this.table.getColumns().add(this.gameCol); this.table.getColumns().add(this.viewerCol); this.table.getColumns().add(this.uptimeCol); this.table.getSortOrder().add(this.liveCol); this.table.getSortOrder().add(this.viewerCol); this.table.getSortOrder().add(this.nameCol); this.filteredChannelList = new FilteredList<>(this.channelHandler.getChannels()); this.sortedChannelList = new SortedList<>(this.filteredChannelList); this.sortedChannelList.comparatorProperty().bind(this.table.comparatorProperty()); this.table.setItems(this.sortedChannelList); this.table.setRowFactory(tv -> { final TableRow<Channel> row = new TableRow<>(); row.setOnMouseClicked(event -> { if ((event.getButton() == MouseButton.PRIMARY) && (event.getClickCount() == 2) && !row.isEmpty()) { this.detailChannel.set(row.getItem()); if (!this.sp.getItems().contains(this.detailPane)) { this.sp.getItems().add(this.detailPane); this.doDetailSlide(true); }//from www .j a v a 2 s. c o m } }); return row; }); this.table.getSelectionModel().selectedItemProperty().addListener((obs, oldV, newV) -> { this.details.setDisable(newV == null); this.remove.setDisable(newV == null); this.chatAndStreamButton.setDisable(newV == null); this.chatAndStreamButton.resetQualities(); if ((newV == null) && this.sp.getItems().contains(this.detailPane)) { this.doDetailSlide(false); } }); }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
private void setupTableWithBinomialChanges() { changesTableView.setEditable(false); changesTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); changesTableView.setItems(potentialChanges); changesTableView.getColumns().clear(); TableColumn<PotentialChange, ChangeType> colChangeType = new TableColumn<>("Type"); colChangeType.setCellFactory(ComboBoxTableCell.forTableColumn(new ChangeTypeStringConverter(), ChangeType.ADDITION, ChangeType.DELETION, ChangeType.RENAME, ChangeType.LUMP, ChangeType.SPLIT, ChangeType.COMPLEX, ChangeType.ERROR)); colChangeType.setCellValueFactory(new PropertyValueFactory<>("type")); colChangeType.setPrefWidth(100.0);/*from w ww . jav a 2 s. c o m*/ colChangeType.setEditable(true); changesTableView.getColumns().add(colChangeType); TableColumn<PotentialChange, ObservableSet<Name>> colChangeFrom = new TableColumn<>("From"); colChangeFrom.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeFrom.setCellValueFactory(new PropertyValueFactory<>("from")); colChangeFrom.setPrefWidth(200.0); colChangeFrom.setEditable(true); changesTableView.getColumns().add(colChangeFrom); TableColumn<PotentialChange, ObservableSet<Name>> colChangeTo = new TableColumn<>("To"); colChangeTo.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeTo.setCellValueFactory(new PropertyValueFactory<>("to")); colChangeTo.setPrefWidth(200.0); colChangeTo.setEditable(true); changesTableView.getColumns().add(colChangeTo); TableColumn<PotentialChange, String> colDataset = new TableColumn<>("Dataset"); colDataset.setCellValueFactory(cvf -> { return new ReadOnlyStringWrapper(cvf.getValue().getDataset().toString()); }); colDataset.setPrefWidth(150.0); changesTableView.getColumns().add(colDataset); TableColumn<PotentialChange, SimplifiedDate> dateCol = new TableColumn<>("Date"); dateCol.setCellFactory( TextFieldTableCell.forTableColumn(new SimplifiedDate.SimplifiedDateStringConverter())); dateCol.setCellValueFactory(cvf -> new ReadOnlyObjectWrapper<>(cvf.getValue().getDataset().getDate())); dateCol.setPrefWidth(150); dateCol.setSortable(true); dateCol.setSortType(SortType.ASCENDING); changesTableView.getColumns().add(dateCol); changesTableView.getSortOrder().add(dateCol); TableColumn<PotentialChange, String> colChangeSummary = new TableColumn<>("Changes summary"); colChangeSummary.setCellValueFactory(cvf -> { Set<Change> changes = changesByPotentialChange.get(cvf.getValue()); return new ReadOnlyStringWrapper(changes.size() + ": " + changes.stream().map(ch -> ch.toString()).collect(Collectors.joining("; "))); }); colChangeSummary.setPrefWidth(200.0); changesTableView.getColumns().add(colChangeSummary); /* TableColumn<PotentialChange, String> colExplicit = new TableColumn<>("Explicit or implicit?"); colExplicit.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getDataset().isChangeImplicit(features.getValue()) ? "Implicit" : "Explicit" ) ); tv.getColumns().add(colExplicit); ChangeFilter cf = binomialChangesView.getProjectView().getProject().getChangeFilter(); TableColumn<Change, String> colFiltered = new TableColumn<>("Eliminated by filter?"); colFiltered.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( cf.test(features.getValue()) ? "Allowed" : "Eliminated" ) ); tv.getColumns().add(colFiltered); */ TableColumn<PotentialChange, String> colNote = new TableColumn<>("Note"); colNote.setCellFactory(TextFieldTableCell.forTableColumn()); colNote.setCellValueFactory(new PropertyValueFactory<>("note")); colNote.setPrefWidth(100.0); changesTableView.getColumns().add(colNote); TableColumn<PotentialChange, String> colReason = new TableColumn<>("Reason"); colReason.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(calculateReason(cvf.getValue()))); colReason.setPrefWidth(100.0); changesTableView.getColumns().add(colReason); TableColumn<PotentialChange, String> colReasonDate = new TableColumn<>("ReasonDate"); colReasonDate.setCellValueFactory(cvf -> { String result; Set<SimplifiedDate> dates = calculateReasonDate(cvf.getValue()); if (dates.size() > 1) { result = "(" + dates.size() + ") " + dates.stream().distinct().sorted() .map(sd -> sd.asYYYYmmDD("-")).collect(Collectors.joining("|")); } else if (dates.size() == 1) { result = dates.iterator().next().asYYYYmmDD("-"); } else { result = "NA"; } return new ReadOnlyStringWrapper(result); }); colReasonDate.setPrefWidth(100.0); changesTableView.getColumns().add(colReasonDate); TableColumn<PotentialChange, String> colCitations = new TableColumn<>("Citations"); colCitations.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( features.getValue().getCitationStream().map(citation -> citation.getCitation()).sorted() .collect(Collectors.joining("; ")))); changesTableView.getColumns().add(colCitations); TableColumn<PotentialChange, String> colGenera = new TableColumn<>("Genera"); colGenera.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> n.getGenus()) .distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colGenera); TableColumn<PotentialChange, String> colSpecificEpithet = new TableColumn<>("Specific epithets"); colSpecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(String .join(", ", features.getValue().getAllNames().stream().map(n -> n.getSpecificEpithet()) .filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colSpecificEpithet); // The infraspecific string. TableColumn<PotentialChange, String> colInfraspecificEpithet = new TableColumn<>("Infraspecific epithets"); colInfraspecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream() .map(n -> n.getInfraspecificEpithetsAsString()).filter(s -> s != null) .distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colInfraspecificEpithet); // The very last epithet of all TableColumn<PotentialChange, String> colTerminalEpithet = new TableColumn<>("Terminal epithet"); colTerminalEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> { List<Name.InfraspecificEpithet> infraspecificEpithets = n.getInfraspecificEpithets(); if (!infraspecificEpithets.isEmpty()) { return infraspecificEpithets.get(infraspecificEpithets.size() - 1).getValue(); } else { return n.getSpecificEpithet(); } }).filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colTerminalEpithet); TableColumn<PotentialChange, String> dateForRCol = new TableColumn<>("DateYMD"); dateForRCol.setCellValueFactory( cvf -> new ReadOnlyObjectWrapper<>(cvf.getValue().getDataset().getDate().asYYYYmmDD("-"))); changesTableView.getColumns().add(dateForRCol); // Properties TableColumn<PotentialChange, String> colProperties = new TableColumn<>("Properties"); colProperties.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( features.getValue().getProperties().entrySet().stream() .map(entry -> entry.getKey() + ": " + entry.getValue()).sorted() .collect(Collectors.joining("; ")))); changesTableView.getColumns().add(colProperties); fillTableWithBinomialChanges(); // When someone selects a cell in the Table, try to select the appropriate data in the // additional data view. changesTableView.getSelectionModel().getSelectedItems() .addListener((ListChangeListener<PotentialChange>) lcl -> { AdditionalData aData = additionalDataCombobox.getSelectionModel().getSelectedItem(); if (aData != null) { aData.onSelectChange(changesTableView.getSelectionModel().getSelectedItems()); } }); // Create a right-click menu for table rows. changesTableView.setRowFactory(table -> { TableRow<PotentialChange> row = new TableRow<>(); row.setOnContextMenuRequested(event -> { if (row.isEmpty()) return; // We don't currently use the clicked change, since currently all options // change *all* the selected changes, but this may change in the future. PotentialChange change = row.getItem(); ContextMenu changeMenu = new ContextMenu(); Menu lookupChange = new Menu("Look up change"); lookupChange.getItems().addAll(changesByPotentialChange.getOrDefault(change, new HashSet<>()) .stream() .map(ch -> createMenuItem(ch.toString() + " in " + ch.getDataset().toString(), action -> { binomialChangesView.getProjectView().openDetailedView(ch); })).collect(Collectors.toList())); changeMenu.getItems().add(lookupChange); changeMenu.getItems().add(new SeparatorMenuItem()); Menu searchForName = new Menu("Search for name"); searchForName.getItems().addAll( change.getAllNames().stream().sorted().map(n -> createMenuItem(n.getFullName(), action -> { binomialChangesView.getProjectView().openDetailedView(n); })).collect(Collectors.toList())); changeMenu.getItems().add(searchForName); changeMenu.getItems().add(new SeparatorMenuItem()); // Create a submenu for tags and urls. String note = change.noteProperty().get(); Menu removeTags = new Menu("Tags"); removeTags.getItems().addAll(change.getTags().stream().sorted() .map(tag -> new MenuItem(tag.getName())).collect(Collectors.toList())); Menu lookupURLs = new Menu("Lookup URL"); change.getURIs().stream().sorted().map(uri -> { return createMenuItem(uri.toString(), evt -> { try { Desktop.getDesktop().browse(uri); } catch (IOException ex) { LOGGER.warning("Could not open URL '" + uri + "': " + ex); } }); }).forEach(mi -> lookupURLs.getItems().add(mi)); changeMenu.getItems().add(lookupURLs); changeMenu.show(binomialChangesView.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); return row; }); LOGGER.info("setupTableWithChanges() completed"); }