Search in sources :

Example 21 with StringConverter

use of javafx.util.StringConverter in project bitsquare by bitsquare.

the class TradesChartsView method createCharts.

///////////////////////////////////////////////////////////////////////////////////////////
// Chart
///////////////////////////////////////////////////////////////////////////////////////////
private void createCharts() {
    priceSeries = new XYChart.Series<>();
    priceAxisX = new NumberAxis(0, model.maxTicks + 1, 1);
    priceAxisX.setTickUnit(1);
    priceAxisX.setMinorTickCount(0);
    priceAxisX.setForceZeroInRange(false);
    priceAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    priceAxisY = new NumberAxis();
    priceAxisY.setForceZeroInRange(false);
    priceAxisY.setAutoRanging(true);
    priceAxisY.setTickLabelFormatter(new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
                final double value = MathUtils.scaleDownByPowerOf10((double) object, 8);
                return formatter.formatRoundedDoubleWithPrecision(value, 8);
            } else
                return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), MathUtils.doubleToLong((double) object)));
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    priceChart = new CandleStickChart(priceAxisX, priceAxisY, new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
                final double value = MathUtils.scaleDownByPowerOf10((long) object, 8);
                return formatter.formatRoundedDoubleWithPrecision(value, 8);
            } else {
                return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), (long) object));
            }
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    priceChart.setMinHeight(198);
    priceChart.setPrefHeight(198);
    priceChart.setMaxHeight(300);
    priceChart.setLegendVisible(false);
    priceChart.setData(FXCollections.observableArrayList(priceSeries));
    volumeSeries = new XYChart.Series<>();
    volumeAxisX = new NumberAxis(0, model.maxTicks + 1, 1);
    volumeAxisX.setTickUnit(1);
    volumeAxisX.setMinorTickCount(0);
    volumeAxisX.setForceZeroInRange(false);
    volumeAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    volumeAxisY = new NumberAxis();
    volumeAxisY.setForceZeroInRange(true);
    volumeAxisY.setAutoRanging(true);
    volumeAxisY.setLabel("Volume in BTC");
    volumeAxisY.setTickLabelFormatter(new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            return formatter.formatCoin(Coin.valueOf(MathUtils.doubleToLong((double) object)));
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    volumeChart = new VolumeChart(volumeAxisX, volumeAxisY, new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            return formatter.formatCoinWithCode(Coin.valueOf((long) object));
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    volumeChart.setData(FXCollections.observableArrayList(volumeSeries));
    volumeChart.setMinHeight(148);
    volumeChart.setPrefHeight(148);
    volumeChart.setMaxHeight(200);
    volumeChart.setLegendVisible(false);
}
Also used : VolumeChart(io.bitsquare.gui.main.market.trades.charts.volume.VolumeChart) NumberAxis(javafx.scene.chart.NumberAxis) XYChart(javafx.scene.chart.XYChart) StringConverter(javafx.util.StringConverter) CandleStickChart(io.bitsquare.gui.main.market.trades.charts.price.CandleStickChart)

Example 22 with StringConverter

use of javafx.util.StringConverter in project bitsquare by bitsquare.

the class TradesChartsView method getTimeAxisStringConverter.

@NotNull
private StringConverter<Number> getTimeAxisStringConverter() {
    return new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            long index = MathUtils.doubleToLong((double) object);
            long time = model.getTimeFromTickIndex(index);
            if (model.tickUnit.ordinal() <= TradesChartsViewModel.TickUnit.DAY.ordinal())
                return index % 4 == 0 ? formatter.formatDate(new Date(time)) : "";
            else
                return index % 3 == 0 ? formatter.formatTime(new Date(time)) : "";
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    };
}
Also used : StringConverter(javafx.util.StringConverter) Date(java.util.Date) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with StringConverter

use of javafx.util.StringConverter in project bitsquare by bitsquare.

the class OfferBookChartView method activate.

@Override
protected void activate() {
    // root.getParent() is null at initialize
    tabPaneSelectionModel = GUIUtil.getParentOfType(root, TabPane.class).getSelectionModel();
    selectedTabIndexListener = (observable, oldValue, newValue) -> model.setSelectedTabIndex((int) newValue);
    model.setSelectedTabIndex(tabPaneSelectionModel.getSelectedIndex());
    tabPaneSelectionModel.selectedIndexProperty().addListener(selectedTabIndexListener);
    currencyComboBox.setItems(model.getCurrencyListItems());
    currencyComboBox.setVisibleRowCount(25);
    if (model.getSelectedCurrencyListItem().isPresent())
        currencyComboBox.getSelectionModel().select(model.getSelectedCurrencyListItem().get());
    currencyComboBox.setOnAction(e -> {
        CurrencyListItem selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            model.onSetTradeCurrency(selectedItem.tradeCurrency);
            updateChartData();
        }
    });
    model.currencyListItems.addListener(currencyListItemsListener);
    model.getOfferBookListItems().addListener(changeListener);
    tradeCurrencySubscriber = EasyBind.subscribe(model.selectedTradeCurrencyProperty, tradeCurrency -> {
        String code = tradeCurrency.getCode();
        areaChart.setTitle("Offer book for " + formatter.getCurrencyNameAndCurrencyPair(code));
        volumeColumnLabel.set("Amount in " + code);
        xAxis.setTickLabelFormatter(new StringConverter<Number>() {

            @Override
            public String toString(Number object) {
                final double doubleValue = (double) object;
                if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
                    final String withPrecision3 = formatter.formatRoundedDoubleWithPrecision(doubleValue, 3);
                    if (withPrecision3.equals("0.000"))
                        return formatter.formatRoundedDoubleWithPrecision(doubleValue, 8);
                    else
                        return withPrecision3;
                } else {
                    return formatter.formatRoundedDoubleWithPrecision(doubleValue, 2);
                }
            }

            @Override
            public Number fromString(String string) {
                return null;
            }
        });
        if (CurrencyUtil.isCryptoCurrency(code)) {
            if (bottomHBox.getChildren().size() == 2 && bottomHBox.getChildren().get(0).getUserData().equals("BUY")) {
                bottomHBox.getChildren().get(0).toFront();
                reverseTableColumns();
            }
            buyOfferHeaderLabel.setText("Offers to sell " + code + " for BTC");
            buyOfferButton.setText("I want to buy " + code + " (sell BTC)");
            sellOfferHeaderLabel.setText("Offers to buy " + code + " with BTC");
            sellOfferButton.setText("I want to sell " + code + " (buy BTC)");
            priceColumnLabel.set("Price in BTC");
        } else {
            if (bottomHBox.getChildren().size() == 2 && bottomHBox.getChildren().get(0).getUserData().equals("SELL")) {
                bottomHBox.getChildren().get(0).toFront();
                reverseTableColumns();
            }
            buyOfferHeaderLabel.setText("Offers to buy BTC with " + code);
            buyOfferButton.setText("I want to sell BTC for " + code);
            sellOfferHeaderLabel.setText("Offers to sell BTC for " + code);
            sellOfferButton.setText("I want to buy BTC with " + code);
            priceColumnLabel.set("Price in " + code);
        }
        xAxis.setLabel(formatter.getPriceWithCurrencyCode(code));
        seriesBuy.setName(buyOfferHeaderLabel.getText() + "   ");
        seriesSell.setName(sellOfferHeaderLabel.getText());
    });
    buyOfferTableView.setItems(model.getTopBuyOfferList());
    sellOfferTableView.setItems(model.getTopSellOfferList());
    buyTableRowSelectionListener = (observable, oldValue, newValue) -> {
        model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
        navigation.navigateTo(MainView.class, SellOfferView.class);
    };
    sellTableRowSelectionListener = (observable, oldValue, newValue) -> {
        model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
        navigation.navigateTo(MainView.class, BuyOfferView.class);
    };
    buyOfferTableView.getSelectionModel().selectedItemProperty().addListener(buyTableRowSelectionListener);
    sellOfferTableView.getSelectionModel().selectedItemProperty().addListener(sellTableRowSelectionListener);
    updateChartData();
}
Also used : Pos(javafx.geometry.Pos) MainView(io.bitsquare.gui.main.MainView) javafx.scene.control(javafx.scene.control) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) OfferBookListItem(io.bitsquare.gui.main.offer.offerbook.OfferBookListItem) GUIUtil(io.bitsquare.gui.util.GUIUtil) Inject(javax.inject.Inject) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Navigation(io.bitsquare.gui.Navigation) Callback(javafx.util.Callback) BSFormatter(io.bitsquare.gui.util.BSFormatter) HBox(javafx.scene.layout.HBox) Logger(org.slf4j.Logger) CurrencyListItem(io.bitsquare.gui.util.CurrencyListItem) UserThread(io.bitsquare.common.UserThread) StringConverter(javafx.util.StringConverter) Subscription(org.fxmisc.easybind.Subscription) ActivatableViewAndModel(io.bitsquare.gui.common.view.ActivatableViewAndModel) BuyOfferView(io.bitsquare.gui.main.offer.BuyOfferView) Priority(javafx.scene.layout.Priority) Offer(io.bitsquare.trade.offer.Offer) EasyBind(org.fxmisc.easybind.EasyBind) Tuple4(io.bitsquare.common.util.Tuple4) ImageView(javafx.scene.image.ImageView) SellOfferView(io.bitsquare.gui.main.offer.SellOfferView) AreaChart(javafx.scene.chart.AreaChart) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) FxmlView(io.bitsquare.gui.common.view.FxmlView) CurrencyUtil(io.bitsquare.locale.CurrencyUtil) StringProperty(javafx.beans.property.StringProperty) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) CurrencyListItem(io.bitsquare.gui.util.CurrencyListItem) StringConverter(javafx.util.StringConverter)

Example 24 with StringConverter

use of javafx.util.StringConverter in project Gargoyle by callakrsos.

the class FxTableViewUtil method getDisplayText.

/**
	 * 테이블컬럼에서 화면에 보여주는 텍스트를 리턴한다.
	 * @작성자 : KYJ
	 * @작성일 : 2017. 3. 31. 
	 * @param tc
	 * @param row
	 * @return
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object getDisplayText(TableColumn<?, ?> tc, int row) {
    Callback cellFactory = tc.getCellFactory();
    if (cellFactory != null) /*&& cellObservableValue != null*/
    {
        //			Object value = cellObservableValue.getValue();
        Object call = cellFactory.call(tc);
        if (call != null && call instanceof TableCell) {
            TableCell cell = (TableCell) call;
            StringConverter converter = null;
            if (cell instanceof TextFieldTableCell) {
                TextFieldTableCell txtCell = (TextFieldTableCell) cell;
                converter = txtCell.getConverter();
            } else //					} 
            if (cell instanceof ComboBoxTableCell) {
                ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
                converter = txtCell.getConverter();
            } else //					else if (cell instanceof HyperlinkTableCell) {
            //						HyperlinkTableCell txtCell = (HyperlinkTableCell) cell;
            //						converter = txtCell.getConverter();
            //					}
            /* else 기본값. */
            {
                try {
                    Method m = cell.getClass().getMethod("converterProperty");
                    if (m != null) {
                        Object object = m.invoke(cell);
                        if (object != null && object instanceof ObjectProperty) {
                            ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
                            converter = convert.get();
                        }
                    }
                } catch (Exception e) {
                // Nothing...
                }
            }
            if (converter != null) {
                Object cellData = tc.getCellData(row);
                return converter.toString(cellData);
            }
        }
        return call;
    }
    return tc.getCellData(row);
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) Callback(javafx.util.Callback) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableCell(javafx.scene.control.TableCell) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Method(java.lang.reflect.Method) StringConverter(javafx.util.StringConverter) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell)

Example 25 with StringConverter

use of javafx.util.StringConverter in project bitsquare by bitsquare.

the class PreferencesView method initializeDisplayCurrencies.

///////////////////////////////////////////////////////////////////////////////////////////
// Initialize
///////////////////////////////////////////////////////////////////////////////////////////
private void initializeDisplayCurrencies() {
    TitledGroupBg titledGroupBg = addTitledGroupBg(root, gridRow, 3, "Currencies in market price feed list");
    GridPane.setColumnSpan(titledGroupBg, 4);
    preferredTradeCurrencyComboBox = addLabelComboBox(root, gridRow, "Preferred currency:", Layout.FIRST_ROW_DISTANCE).second;
    preferredTradeCurrencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency tradeCurrency) {
            // http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
            return tradeCurrency.getDisplayPrefix() + tradeCurrency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, ListView> fiatTuple = addLabelListView(root, ++gridRow, "Display national currencies:");
    GridPane.setValignment(fiatTuple.first, VPos.TOP);
    fiatCurrenciesListView = fiatTuple.second;
    fiatCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
    fiatCurrenciesListView.setMaxHeight(6 * Layout.LIST_ROW_HEIGHT + 2);
    Label placeholder = new Label("There are no national currencies selected");
    placeholder.setWrapText(true);
    fiatCurrenciesListView.setPlaceholder(placeholder);
    fiatCurrenciesListView.setCellFactory(new Callback<ListView<FiatCurrency>, ListCell<FiatCurrency>>() {

        @Override
        public ListCell<FiatCurrency> call(ListView<FiatCurrency> list) {
            return new ListCell<FiatCurrency>() {

                final Label label = new Label();

                final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);

                final Button removeButton = new Button("", icon);

                final AnchorPane pane = new AnchorPane(label, removeButton);

                {
                    label.setLayoutY(5);
                    removeButton.setId("icon-button");
                    AnchorPane.setRightAnchor(removeButton, 0d);
                }

                @Override
                public void updateItem(final FiatCurrency item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(item.getNameAndCode());
                        removeButton.setOnAction(e -> {
                            if (item.equals(preferences.getPreferredTradeCurrency())) {
                                new Popup().warning("You cannot remove your selected preferred display currency").show();
                            } else {
                                preferences.removeFiatCurrency(item);
                                if (!allFiatCurrencies.contains(item))
                                    allFiatCurrencies.add(item);
                            }
                        });
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                        removeButton.setOnAction(null);
                    }
                }
            };
        }
    });
    Tuple2<Label, ListView> cryptoCurrenciesTuple = addLabelListView(root, gridRow, "Display altcoins:");
    GridPane.setValignment(cryptoCurrenciesTuple.first, VPos.TOP);
    GridPane.setMargin(cryptoCurrenciesTuple.first, new Insets(0, 0, 0, 20));
    cryptoCurrenciesListView = cryptoCurrenciesTuple.second;
    GridPane.setColumnIndex(cryptoCurrenciesTuple.first, 2);
    GridPane.setColumnIndex(cryptoCurrenciesListView, 3);
    cryptoCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
    cryptoCurrenciesListView.setMaxHeight(6 * Layout.LIST_ROW_HEIGHT + 2);
    placeholder = new Label("There are no altcoins selected");
    placeholder.setWrapText(true);
    cryptoCurrenciesListView.setPlaceholder(placeholder);
    cryptoCurrenciesListView.setCellFactory(new Callback<ListView<CryptoCurrency>, ListCell<CryptoCurrency>>() {

        @Override
        public ListCell<CryptoCurrency> call(ListView<CryptoCurrency> list) {
            return new ListCell<CryptoCurrency>() {

                final Label label = new Label();

                final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);

                final Button removeButton = new Button("", icon);

                final AnchorPane pane = new AnchorPane(label, removeButton);

                {
                    label.setLayoutY(5);
                    removeButton.setId("icon-button");
                    AnchorPane.setRightAnchor(removeButton, 0d);
                }

                @Override
                public void updateItem(final CryptoCurrency item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(item.getNameAndCode());
                        removeButton.setOnAction(e -> {
                            if (item.equals(preferences.getPreferredTradeCurrency())) {
                                new Popup().warning("You cannot remove your selected preferred display currency").show();
                            } else {
                                preferences.removeCryptoCurrency(item);
                                if (!allCryptoCurrencies.contains(item))
                                    allCryptoCurrencies.add(item);
                            }
                        });
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                        removeButton.setOnAction(null);
                    }
                }
            };
        }
    });
    fiatCurrenciesComboBox = addLabelComboBox(root, ++gridRow).second;
    fiatCurrenciesComboBox.setPromptText("Add national currency");
    fiatCurrenciesComboBox.setConverter(new StringConverter<FiatCurrency>() {

        @Override
        public String toString(FiatCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public FiatCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, ComboBox> labelComboBoxTuple2 = addLabelComboBox(root, gridRow);
    cryptoCurrenciesComboBox = labelComboBoxTuple2.second;
    GridPane.setColumnIndex(cryptoCurrenciesComboBox, 3);
    cryptoCurrenciesComboBox.setPromptText("Add altcoin");
    cryptoCurrenciesComboBox.setConverter(new StringConverter<CryptoCurrency>() {

        @Override
        public String toString(CryptoCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public CryptoCurrency fromString(String s) {
            return null;
        }
    });
}
Also used : Popup(io.bitsquare.gui.main.overlays.popups.Popup) Arrays(java.util.Arrays) io.bitsquare.locale(io.bitsquare.locale) javafx.scene.control(javafx.scene.control) FXCollections(javafx.collections.FXCollections) Tuple2(io.bitsquare.common.util.Tuple2) Inject(javax.inject.Inject) Insets(javafx.geometry.Insets) Layout(io.bitsquare.gui.util.Layout) VPos(javafx.geometry.VPos) Callback(javafx.util.Callback) GridPane(javafx.scene.layout.GridPane) BSFormatter(io.bitsquare.gui.util.BSFormatter) Activatable(io.bitsquare.gui.common.model.Activatable) InputTextField(io.bitsquare.gui.components.InputTextField) BlockChainExplorer(io.bitsquare.user.BlockChainExplorer) UserThread(io.bitsquare.common.UserThread) ImageUtil(io.bitsquare.gui.util.ImageUtil) StringConverter(javafx.util.StringConverter) ActivatableViewAndModel(io.bitsquare.gui.common.view.ActivatableViewAndModel) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Preferences(io.bitsquare.user.Preferences) FormBuilder(io.bitsquare.gui.util.FormBuilder) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) ObservableList(javafx.collections.ObservableList) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) NotNull(org.jetbrains.annotations.NotNull) TitledGroupBg(io.bitsquare.gui.components.TitledGroupBg) Insets(javafx.geometry.Insets) Popup(io.bitsquare.gui.main.overlays.popups.Popup) ImageView(javafx.scene.image.ImageView) AnchorPane(javafx.scene.layout.AnchorPane) TitledGroupBg(io.bitsquare.gui.components.TitledGroupBg)

Aggregations

StringConverter (javafx.util.StringConverter)33 Label (javafx.scene.control.Label)14 Callback (javafx.util.Callback)14 FXCollections (javafx.collections.FXCollections)12 Insets (javafx.geometry.Insets)12 Button (javafx.scene.control.Button)11 ImageView (javafx.scene.image.ImageView)11 Inject (javax.inject.Inject)11 ChangeListener (javafx.beans.value.ChangeListener)10 ObservableList (javafx.collections.ObservableList)10 ComboBox (javafx.scene.control.ComboBox)10 Priority (javafx.scene.layout.Priority)9 Arrays (java.util.Arrays)8 List (java.util.List)8 ListChangeListener (javafx.collections.ListChangeListener)8 GridPane (javafx.scene.layout.GridPane)8 HBox (javafx.scene.layout.HBox)8 Consumer (java.util.function.Consumer)7 Res (bisq.core.locale.Res)6 VPos (javafx.geometry.VPos)6