Search in sources :

Example 6 with ObservableValue

use of javafx.beans.value.ObservableValue in project Retrospector by NonlinearFruit.

the class SearchTabController method initSearchTab.

private void initSearchTab() {
    searchEditMedia.setDisable(true);
    searchDeleteMedia.setDisable(true);
    // Table Double Click
    searchTable.setRowFactory(tv -> {
        TableRow<Media> row = new TableRow<>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {
                setMedia(row.getItem());
                setTab(TAB.MEDIA);
            }
        });
        return row;
    });
    // Table data setup
    searchTableData = DataManager.getMedia();
    FilteredList<Media> mediaFiltered = new FilteredList(searchTableData, x -> true);
    SortedList<Media> mediaSortable = new SortedList<>(mediaFiltered);
    searchTable.setItems(mediaSortable);
    mediaSortable.comparatorProperty().bind(searchTable.comparatorProperty());
    // Link to data properties
    searchTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
    searchCreatorColumn.setCellValueFactory(new PropertyValueFactory<>("Creator"));
    searchSeasonColumn.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
    searchEpisodeColumn.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
    searchCategoryColumn.setCellValueFactory(new PropertyValueFactory<>("Category"));
    // Values for special columns
    searchNumberColumn.setSortable(false);
    searchNumberColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + searchTable.getItems().indexOf(p.getValue())));
    searchReviewsColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, Integer>, ObservableValue<Integer>>() {

        @Override
        public ObservableValue<Integer> call(TableColumn.CellDataFeatures<Media, Integer> p) {
            return new ReadOnlyObjectWrapper(p.getValue().getReviews().size());
        }
    });
    searchMeanRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {

        @Override
        public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
            return new ReadOnlyObjectWrapper(p.getValue().getAverageRating());
        }
    });
    searchCurrentRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {

        @Override
        public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
            return new ReadOnlyObjectWrapper(p.getValue().getCurrentRating());
        }
    });
    // Comparators for string columns
    searchTitleColumn.setComparator(new NaturalOrderComparator());
    searchCreatorColumn.setComparator(new NaturalOrderComparator());
    searchSeasonColumn.setComparator(new NaturalOrderComparator());
    searchEpisodeColumn.setComparator(new NaturalOrderComparator());
    searchCategoryColumn.setComparator(new NaturalOrderComparator());
    searchTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
        setMedia(neo);
    });
    searchBox.textProperty().addListener((observa, old, neo) -> {
        String query = neo;
        if (query == null || query.equals(""))
            mediaFiltered.setPredicate(x -> true);
        else {
            String[] queries = query.split(":");
            mediaFiltered.setPredicate(x -> QueryProcessor.isMatchForMedia(query, x));
        }
        updateStats();
    });
    // Buttons
    searchNewMedia.setOnAction(e -> {
        Media neo = new Media();
        neo.setId(DataManager.createDB(neo));
        setMedia(neo);
        setTab(TAB.MEDIA);
    });
    searchQuickEntry.setOnAction(e -> {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("QuickEntry.fxml"));
            Parent root1 = (Parent) fxmlLoader.load();
            QuickEntryController qec = fxmlLoader.getController();
            qec.setup(currentTab);
            Stage stage = new Stage();
            stage.setTitle("Quick Entry");
            stage.setScene(new Scene(root1));
            stage.show();
        } catch (Exception ex) {
        }
    });
    searchStandardEntry.setOnAction(e -> {
        Media neo = new Media();
        neo.setId(DataManager.createDB(neo));
        setMedia(neo);
        setTab(TAB.MEDIA);
    });
    searchBackup.setOnAction(e -> DataManager.makeBackup());
    searchCheatsheet.setOnAction(e -> {
        new Cheatsheet().start(new Stage());
    });
    searchEditMedia.setOnAction(e -> {
        setTab(TAB.MEDIA);
    });
    searchDeleteMedia.setOnAction(e -> {
        if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
            DataManager.deleteDB(getMedia());
            updateSearchTab();
        }
    });
    // Init stuff
    updateStats();
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) URL(java.net.URL) ButtonType(javafx.scene.control.ButtonType) Factoid(retrospector.model.Factoid) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Media(retrospector.model.Media) Application(javafx.application.Application) BigDecimal(java.math.BigDecimal) Parent(javafx.scene.Parent) ResourceBundle(java.util.ResourceBundle) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) FXMLLoader(javafx.fxml.FXMLLoader) QuickEntryController(retrospector.fxml.QuickEntryController) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) SortedList(javafx.collections.transformation.SortedList) Alert(javafx.scene.control.Alert) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) Review(retrospector.model.Review) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) TableRow(javafx.scene.control.TableRow) FilteredList(javafx.collections.transformation.FilteredList) TAB(retrospector.fxml.CoreController.TAB) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) List(java.util.List) Stage(javafx.stage.Stage) MenuButton(javafx.scene.control.MenuButton) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) DataManager(retrospector.model.DataManager) QuickEntryController(retrospector.fxml.QuickEntryController) Parent(javafx.scene.Parent) SortedList(javafx.collections.transformation.SortedList) ObservableValue(javafx.beans.value.ObservableValue) FXMLLoader(javafx.fxml.FXMLLoader) FilteredList(javafx.collections.transformation.FilteredList) Stage(javafx.stage.Stage) Media(retrospector.model.Media) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) TableRow(javafx.scene.control.TableRow) Alert(javafx.scene.control.Alert) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper)

Example 7 with ObservableValue

use of javafx.beans.value.ObservableValue in project Gargoyle by callakrsos.

the class ColumnExample3Con method initialize.

@FXML
public void initialize() {
    tableView.setEditable(true);
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드1");
        hashMap.put("commCodeNm", "데이터 1");
        tableView.getItems().add(hashMap);
    }
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드1");
        hashMap.put("commCodeNm", "데이터 223492342309842402394823049238420942384029343809248420934809428409238409238423094823049");
        tableView.getItems().add(hashMap);
    }
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드3");
        hashMap.put("commCodeNm", "데이터 3");
        tableView.getItems().add(hashMap);
    }
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드4");
        hashMap.put("commCodeNm", "데이터 4");
        tableView.getItems().add(hashMap);
    }
    colCode.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Map<String, String>, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<Map<String, String>, String> param) {
            return new SimpleStringProperty(param.getValue().get("commCode"));
        }
    });
    colCodeNm.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Map<String, String>, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<Map<String, String>, String> param) {
            return new SimpleStringProperty(param.getValue().get("commCodeNm"));
        }
    });
}
Also used : CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Map(java.util.Map) HashMap(java.util.HashMap) FXML(javafx.fxml.FXML)

Example 8 with ObservableValue

use of javafx.beans.value.ObservableValue in project bitsquare by bitsquare.

the class OfferBookChartView method getOfferTable.

private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(Offer.Direction direction) {
    TableView<OfferListItem> tableView = new TableView<>();
    tableView.setMinHeight(109);
    tableView.setPrefHeight(121);
    //530
    tableView.setMinWidth(480);
    // price
    TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
    priceColumn.textProperty().bind(priceColumnLabel);
    //130
    priceColumn.setMinWidth(115);
    //130
    priceColumn.setMaxWidth(115);
    priceColumn.setSortable(false);
    priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    priceColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText(formatter.formatPrice(offer.getPrice()));
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        if (offerListItem.offer.getPrice() == null) {
                            this.offer = offerListItem.offer;
                            model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
                            setText("N/A");
                        } else {
                            setText(formatter.formatPrice(offerListItem.offer.getPrice()));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                    }
                }
            };
        }
    });
    // volume
    TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
    //125
    volumeColumn.setMinWidth(115);
    volumeColumn.setSortable(false);
    volumeColumn.textProperty().bind(volumeColumnLabel);
    volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    volumeColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText(formatter.formatVolume(offer.getOfferVolume()));
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        this.offer = offerListItem.offer;
                        if (offer.getPrice() == null) {
                            this.offer = offerListItem.offer;
                            model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
                            setText("N/A");
                        } else {
                            setText(formatter.formatVolume(offer.getOfferVolume()));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                    }
                }
            };
        }
    });
    // amount
    TableColumn<OfferListItem, OfferListItem> amountColumn = new TableColumn<>("Amount in BTC");
    //125
    amountColumn.setMinWidth(115);
    amountColumn.setSortable(false);
    amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    amountColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty)
                        setText(formatter.formatCoin(offerListItem.offer.getAmount()));
                    else
                        setText("");
                }
            };
        }
    });
    // accumulated
    TableColumn<OfferListItem, OfferListItem> accumulatedColumn = new TableColumn<>("Sum in BTC");
    //130
    accumulatedColumn.setMinWidth(100);
    accumulatedColumn.setSortable(false);
    accumulatedColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    accumulatedColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty)
                        setText(formatter.formatRoundedDoubleWithPrecision(offerListItem.accumulated, 4));
                    else
                        setText("");
                }
            };
        }
    });
    if (direction == Offer.Direction.BUY) {
        tableView.getColumns().add(accumulatedColumn);
        tableView.getColumns().add(volumeColumn);
        tableView.getColumns().add(amountColumn);
        tableView.getColumns().add(priceColumn);
    } else {
        tableView.getColumns().add(priceColumn);
        tableView.getColumns().add(amountColumn);
        tableView.getColumns().add(volumeColumn);
        tableView.getColumns().add(accumulatedColumn);
    }
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new Label("Currently there are no offers available");
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    Label titleLabel = new Label();
    titleLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-alignment: center");
    UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
    boolean isSellOffer = direction == Offer.Direction.SELL;
    Button button = new Button();
    ImageView iconView = new ImageView();
    iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
    button.setGraphic(iconView);
    button.setGraphicTextGap(10);
    button.setText(isSellOffer ? "I want to buy bitcoin" : "I want to sell bitcoin");
    button.setMinHeight(40);
    button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
    button.setOnAction(e -> {
        if (isSellOffer) {
            model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
            navigation.navigateTo(MainView.class, BuyOfferView.class);
        } else {
            model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
            navigation.navigateTo(MainView.class, SellOfferView.class);
        }
    });
    VBox vBox = new VBox();
    vBox.setSpacing(10);
    vBox.setFillWidth(true);
    vBox.setMinHeight(190);
    vBox.getChildren().addAll(titleLabel, tableView, button);
    button.prefWidthProperty().bind(vBox.widthProperty());
    return new Tuple4<>(tableView, vBox, button, titleLabel);
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) Tuple4(io.bitsquare.common.util.Tuple4) Offer(io.bitsquare.trade.offer.Offer) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) ImageView(javafx.scene.image.ImageView) VBox(javafx.scene.layout.VBox)

Example 9 with ObservableValue

use of javafx.beans.value.ObservableValue in project Gargoyle by callakrsos.

the class WebViewExam method start.

/***********************************************************************************/
/* 이벤트 구현 */
@Override
public void start(Stage primaryStage) throws Exception {
    WebView view = new WebView();
    WebEngine engine = view.getEngine();
    engine.setJavaScriptEnabled(true);
    engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {

        @Override
        public WebEngine call(PopupFeatures p) {
            Stage stage = new Stage(StageStyle.UTILITY);
            WebView wv2 = new WebView();
            VBox vBox = new VBox(5);
            vBox.getChildren().add(wv2);
            vBox.getChildren().add(new Button("업로딩"));
            wv2.getEngine().setJavaScriptEnabled(true);
            stage.setScene(new Scene(vBox));
            stage.show();
            return wv2.getEngine();
        }
    });
    engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == Worker.State.SUCCEEDED) {
                primaryStage.setTitle(engine.getLocation());
            }
        }
    });
    engine.setConfirmHandler(new Callback<String, Boolean>() {

        @Override
        public Boolean call(String param) {
            System.out.println("confirm handler : " + param);
            return true;
        }
    });
    engine.setOnAlert((WebEvent<String> wEvent) -> {
        System.out.println("Alert Event  -  Message:  " + wEvent.getData());
    });
    engine.load("http://localhost:15501/MemoWebapp/SmartEditor2.html");
    primaryStage.setScene(new Scene(new BorderPane(view), 1200, 700));
    primaryStage.show();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) PopupFeatures(javafx.scene.web.PopupFeatures) ObservableValue(javafx.beans.value.ObservableValue) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Button(javafx.scene.control.Button) State(javafx.concurrent.Worker.State) Stage(javafx.stage.Stage) WebView(javafx.scene.web.WebView) WebEvent(javafx.scene.web.WebEvent) VBox(javafx.scene.layout.VBox)

Example 10 with ObservableValue

use of javafx.beans.value.ObservableValue in project Board-Instrumentation-Framework by intel.

the class SteelGaugeRadialWidget method Create.

@Override
public boolean Create(GridPane pane, DataManager dataMgr) {
    SetParent(pane);
    _ParentGridPane = pane;
    if (false == SetupGauge()) {
        return false;
    }
    _Gauge.setValue(_InitialValue);
    ConfigureDimentions();
    ConfigureAlignment();
    SetupTaskAction();
    SetupPeekaboo(dataMgr);
    pane.add(_Gauge, getColumn(), getRow(), getColumnSpan(), getRowSpan());
    dataMgr.AddListener(getMinionID(), getNamespace(), new ChangeListener() {

        @Override
        public void changed(ObservableValue o, Object oldVal, Object newVal) {
            if (IsPaused()) {
                return;
            }
            double newDialValue = 0;
            double oldDialValue = 0;
            String strVal = newVal.toString();
            try {
                newDialValue = Double.parseDouble(strVal);
            // oldDialValue = Double.parseDouble(oldVal.toString());
            } catch (Exception ex) {
                LOGGER.severe("Invalid data for Gauge received: " + strVal);
                return;
            }
            _Gauge.setValue(newDialValue);
        }
    });
    return ApplyCSS();
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener)

Aggregations

ObservableValue (javafx.beans.value.ObservableValue)85 ChangeListener (javafx.beans.value.ChangeListener)53 FXML (javafx.fxml.FXML)13 Scene (javafx.scene.Scene)13 ImageView (javafx.scene.image.ImageView)13 KeyEvent (javafx.scene.input.KeyEvent)11 ArrayList (java.util.ArrayList)10 Label (javafx.scene.control.Label)10 TableColumn (javafx.scene.control.TableColumn)10 TableView (javafx.scene.control.TableView)10 ActionEvent (javafx.event.ActionEvent)9 MouseEvent (javafx.scene.input.MouseEvent)9 TextField (javafx.scene.control.TextField)8 Color (javafx.scene.paint.Color)8 ObservableList (javafx.collections.ObservableList)7 MenuItem (javafx.scene.control.MenuItem)7 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)7 List (java.util.List)6 Set (java.util.Set)6 Platform (javafx.application.Platform)6