initial commit. gui prototype v 0.1

This commit is contained in:
Manfred Karrer 2014-04-11 11:38:31 +02:00
parent bc09937785
commit 24137c7021
18 changed files with 1296 additions and 1296 deletions

View File

@ -1,51 +1,51 @@
package io.bitsquare;
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.bitsquare.di.BitSquareModule;
import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.setup.ISetup;
import io.bitsquare.setup.MockSetup;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class BitSquare extends Application
{
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage)
{
Injector injector = Guice.createInjector(new BitSquareModule());
ISetup setup = injector.getInstance(MockSetup.class);
setup.applyPersistedData();
stage.setTitle("BitSquare");
GuiceFXMLLoader loader = new GuiceFXMLLoader(injector);
try
{
Parent mainView = loader.load(BitSquare.class.getResourceAsStream("/io/bitsquare/gui/MainView.fxml"));
Scene scene = new Scene(mainView, 800, 600);
scene.getStylesheets().setAll(getClass().getResource("/io/bitsquare/gui/global.css").toExternalForm());
stage.setScene(scene);
stage.show();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
package io.bitsquare;
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.bitsquare.di.BitSquareModule;
import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.setup.ISetup;
import io.bitsquare.setup.MockSetup;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class BitSquare extends Application
{
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage)
{
Injector injector = Guice.createInjector(new BitSquareModule());
ISetup setup = injector.getInstance(MockSetup.class);
setup.applyPersistedData();
stage.setTitle("BitSquare");
GuiceFXMLLoader loader = new GuiceFXMLLoader(injector);
try
{
Parent mainView = loader.load(BitSquare.class.getResourceAsStream("/io/bitsquare/gui/MainView.fxml"));
Scene scene = new Scene(mainView, 800, 600);
scene.getStylesheets().setAll(getClass().getResource("/io/bitsquare/gui/global.css").toExternalForm());
stage.setScene(scene);
stage.show();
} catch (IOException e)
{
e.printStackTrace();
}
}
}

View File

@ -1,26 +1,26 @@
package io.bitsquare.gui.funds;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class FundsController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}
package io.bitsquare.gui.funds;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class FundsController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}

View File

@ -1,6 +1,6 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.funds.FundsController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Wallet"/>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.funds.FundsController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Wallet"/>
</Pane>

View File

@ -1,28 +1,28 @@
package io.bitsquare.gui.history;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class HistoryController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}
package io.bitsquare.gui.history;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class HistoryController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}

View File

@ -1,6 +1,6 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.history.HistoryController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Histroy"/>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.history.HistoryController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Histroy"/>
</Pane>

View File

@ -1,32 +1,32 @@
package io.bitsquare.gui.home;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.Pane;
import java.net.URL;
import java.util.ResourceBundle;
public class HomeController implements Initializable, IChildController
{
private INavigationController navigationController;
@FXML
public Pane rootContainer;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}
package io.bitsquare.gui.home;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.Pane;
import java.net.URL;
import java.util.ResourceBundle;
public class HomeController implements Initializable, IChildController
{
private INavigationController navigationController;
@FXML
public Pane rootContainer;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}

View File

@ -1,4 +1,4 @@
<?import javafx.scene.layout.VBox?>
<VBox fx:id="rootContainer" fx:controller="io.bitsquare.gui.home.HomeController" spacing="10"
xmlns:fx="http://javafx.com/fxml">
<?import javafx.scene.layout.VBox?>
<VBox fx:id="rootContainer" fx:controller="io.bitsquare.gui.home.HomeController" spacing="10"
xmlns:fx="http://javafx.com/fxml">
</VBox>

View File

@ -1,27 +1,27 @@
package io.bitsquare.gui.msg;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class MsgController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}
package io.bitsquare.gui.msg;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class MsgController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}

View File

@ -1,6 +1,6 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.msg.MsgController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Msg"/>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.msg.MsgController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Msg"/>
</Pane>

View File

@ -1,30 +1,30 @@
package io.bitsquare.gui.orders;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class OrdersController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}
package io.bitsquare.gui.orders;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class OrdersController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}

View File

@ -1,6 +1,6 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.orders.OrdersController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Orders"/>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.orders.OrdersController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Orders"/>
</Pane>

View File

@ -1,30 +1,30 @@
package io.bitsquare.gui.settings;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class SettingsController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}
package io.bitsquare.gui.settings;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class SettingsController implements Initializable, IChildController
{
private INavigationController navigationController;
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
}

View File

@ -1,6 +1,6 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.settings.SettingsController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Settings"/>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane fx:controller="io.bitsquare.gui.settings.SettingsController"
xmlns:fx="http://javafx.com/fxml">
<Label text="Settings"/>
</Pane>

View File

@ -1,89 +1,89 @@
package io.bitsquare.gui.trade;
import io.bitsquare.BitSquare;
import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.trade.orderbook.OrderBookController;
import io.bitsquare.trade.Direction;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.Pane;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
public class TradeController implements Initializable, INavigationController, IChildController
{
@FXML
private TabPane tabPane;
private IChildController childController;
private boolean orderbookCreated;
private INavigationController navigationController;
private OrderBookController orderBookController;
@Override
public IChildController navigateToView(String fxmlView, String title)
{
if (fxmlView.equals(INavigationController.TRADE__ORDER_BOOK) && orderbookCreated)
{
tabPane.getSelectionModel().select(0);
return null;
}
FXMLLoader loader = new GuiceFXMLLoader();
try
{
Pane view = loader.load(BitSquare.class.getResourceAsStream(fxmlView));
childController = loader.getController();
childController.setNavigationController(this);
if (childController instanceof OrderBookController)
orderBookController = (OrderBookController) childController;
Tab tab = new Tab(title);
tab.setContent(view);
tabPane.getTabs().add(tab);
if (fxmlView.equals(INavigationController.TRADE__ORDER_BOOK))
{
tab.setClosable(false);
orderbookCreated = true;
}
tabPane.getSelectionModel().select(tabPane.getTabs().size() - 1);
return childController;
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
navigateToView(INavigationController.TRADE__ORDER_BOOK, "Orderbook");
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
public void setDirection(Direction direction)
{
tabPane.getSelectionModel().select(0);
orderBookController.setDirection(direction);
}
}
package io.bitsquare.gui.trade;
import io.bitsquare.BitSquare;
import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.trade.orderbook.OrderBookController;
import io.bitsquare.trade.Direction;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.Pane;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
public class TradeController implements Initializable, INavigationController, IChildController
{
@FXML
private TabPane tabPane;
private IChildController childController;
private boolean orderbookCreated;
private INavigationController navigationController;
private OrderBookController orderBookController;
@Override
public IChildController navigateToView(String fxmlView, String title)
{
if (fxmlView.equals(INavigationController.TRADE__ORDER_BOOK) && orderbookCreated)
{
tabPane.getSelectionModel().select(0);
return null;
}
FXMLLoader loader = new GuiceFXMLLoader();
try
{
Pane view = loader.load(BitSquare.class.getResourceAsStream(fxmlView));
childController = loader.getController();
childController.setNavigationController(this);
if (childController instanceof OrderBookController)
orderBookController = (OrderBookController) childController;
Tab tab = new Tab(title);
tab.setContent(view);
tabPane.getTabs().add(tab);
if (fxmlView.equals(INavigationController.TRADE__ORDER_BOOK))
{
tab.setClosable(false);
orderbookCreated = true;
}
tabPane.getSelectionModel().select(tabPane.getTabs().size() - 1);
return childController;
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
navigateToView(INavigationController.TRADE__ORDER_BOOK, "Orderbook");
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
public void setDirection(Direction direction)
{
tabPane.getSelectionModel().select(0);
orderBookController.setDirection(direction);
}
}

View File

@ -1,271 +1,271 @@
package io.bitsquare.gui.trade.offer;
import com.google.inject.Inject;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.util.Converter;
import io.bitsquare.gui.util.Formatter;
import io.bitsquare.settings.OrderBookFilterSettings;
import io.bitsquare.settings.Settings;
import io.bitsquare.trade.Direction;
import io.bitsquare.trade.Offer;
import io.bitsquare.trade.OfferConstraints;
import io.bitsquare.trade.TradingFacade;
import io.bitsquare.trade.orderbook.MockOrderBook;
import io.bitsquare.trade.orderbook.OrderBookFilter;
import io.bitsquare.user.User;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.ArrayList;
import java.util.Currency;
import java.util.ResourceBundle;
import java.util.UUID;
public class CreateOfferController implements Initializable, IChildController
{
private static final Logger log = LoggerFactory.getLogger(CreateOfferController.class);
private INavigationController navigationController;
private TradingFacade tradingFacade;
private OrderBookFilterSettings orderBookFilterSettings;
private Settings settings;
private User user;
private double filterPaneItemOffset;
private Direction direction;
@FXML
public AnchorPane holderPane;
@FXML
public Pane detailsPane;
@FXML
public Label buyLabel;
@FXML
public TextField volume;
@FXML
public ImageView directionImageView;
@FXML
public TextField amount;
@FXML
public TextField price;
@FXML
public TextField minAmount;
@FXML
public Button placeOfferButton;
@Inject
public CreateOfferController(TradingFacade tradingFacade, OrderBookFilterSettings orderBookFilterSettings, Settings settings, User user)
{
this.tradingFacade = tradingFacade;
this.orderBookFilterSettings = orderBookFilterSettings;
this.settings = settings;
this.user = user;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
createFilterPane();
amount.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
setVolume();
}
});
price.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
setVolume();
}
});
placeOfferButton.setOnAction(e -> {
// TODO not impl yet. use mocks
OfferConstraints offerConstraints = new MockOrderBook(settings).getRandomOfferConstraints();
Offer offer = new Offer(UUID.randomUUID(),
direction,
Converter.convertToDouble(price.getText()),
Converter.convertToDouble(amount.getText()),
Converter.convertToDouble(minAmount.getText()),
settings.getCurrency(),
user,
offerConstraints);
tradingFacade.placeNewOffer(offer);
TabPane tabPane = ((TabPane) (holderPane.getParent().getParent()));
tabPane.getTabs().remove(tabPane.getSelectionModel().getSelectedItem());
navigationController.navigateToView(INavigationController.TRADE__ORDER_BOOK, "Orderbook");
});
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
public void setOrderBookFilter(OrderBookFilter orderBookFilter)
{
direction = orderBookFilter.getDirection();
amount.setText(Formatter.formatPrice(orderBookFilter.getAmount()));
minAmount.setText(Formatter.formatPrice(orderBookFilter.getAmount()));
price.setText(Formatter.formatPrice(orderBookFilter.getPrice()));
configDirection();
}
private void configDirection()
{
String iconPath;
String buyLabelText;
if (direction == Direction.BUY)
{
iconPath = "/images/buy.png";
buyLabelText = "BUY";
}
else
{
iconPath = "/images/sell.png";
buyLabelText = "SELL";
}
Image icon = new Image(getClass().getResourceAsStream(iconPath));
directionImageView.setImage(icon);
buyLabel.setText(buyLabelText);
}
private void createFilterPane()
{
filterPaneItemOffset = 30;
ArrayList<Currency> currencies = orderBookFilterSettings.getCurrencies();
Currency currency = orderBookFilterSettings.getCurrency();
ComboBox currencyComboBox = createCurrencyItem("Currency: ", currency, currencies);
currencyComboBox.valueProperty().addListener(new ChangeListener<Currency>()
{
@Override
public void changed(ObservableValue ov, Currency oldValue, Currency newValue)
{
orderBookFilterSettings.setCurrency(newValue);
}
});
Label bankLabel = createFilterItem("Bank transfer types: ", "SEPA, OKPAY");
Label countriesLabel = createFilterItem("Countries: ", "DE, GB, AT");
Label languagesLabel = createFilterItem("Languages: ", "DE, EN");
Label arbitratorsLabel = createFilterItem("Arbitrators: ", "Paysty, BitRated");
Label identityLabel = createFilterItem("Identity verifications: ", "Passport, Google+, Facebook, Skype");
TextField collateralLabel = createCollateralItem("Collateral (%): ", 10);
}
private ComboBox createCurrencyItem(String labelText, Currency currency, ArrayList<Currency> currencies)
{
final Separator separator = new Separator();
separator.setPrefWidth(380);
separator.setLayoutY(0 + filterPaneItemOffset);
separator.setLayoutX(0);
final Label label = new Label(labelText);
label.setLayoutY(10 + filterPaneItemOffset);
ObservableList<Currency> options = FXCollections.observableArrayList(currencies);
final ComboBox comboBox = new ComboBox(options);
comboBox.setLayoutX(70);
comboBox.setLayoutY(5 + filterPaneItemOffset);
comboBox.setValue(currency);
detailsPane.getChildren().addAll(separator, label, comboBox);
filterPaneItemOffset += 40;
return comboBox;
}
private Label createFilterItem(String labelText, String valueText)
{
final Separator separator = new Separator();
separator.setPrefWidth(380);
separator.setLayoutY(0 + filterPaneItemOffset);
separator.setLayoutX(0);
final Label label = new Label(labelText + valueText);
label.setLayoutY(10 + filterPaneItemOffset);
label.setPrefWidth(310);
Tooltip tooltip = new Tooltip(valueText);
label.setTooltip(tooltip);
final Button edit = new Button("Edit");
edit.setPrefWidth(50);
edit.setLayoutX(330);
edit.setLayoutY(5 + filterPaneItemOffset);
detailsPane.getChildren().addAll(separator, label, edit);
filterPaneItemOffset += 40;
return label;
}
private TextField createCollateralItem(String labelText, double collateral)
{
final Separator separator = new Separator();
separator.setPrefWidth(380);
separator.setLayoutY(0 + filterPaneItemOffset);
separator.setLayoutX(0);
final Label label = new Label(labelText);
label.setLayoutY(10 + filterPaneItemOffset);
label.setPrefWidth(310);
final TextField collateralValue = new TextField(Double.toString(collateral));
collateralValue.setLayoutX(90);
collateralValue.setLayoutY(5 + filterPaneItemOffset);
collateralValue.setPrefWidth(50);
detailsPane.getChildren().addAll(separator, label, collateralValue);
filterPaneItemOffset += 40;
return collateralValue;
}
private double textInputToNumber(String oldValue, String newValue)
{
//TODO use regex.... or better custom textfield component
double d = 0.0;
if (!newValue.equals(""))
{
d = Converter.convertToDouble(newValue);
if (d == Double.NEGATIVE_INFINITY)
{
amount.setText(oldValue);
d = Converter.convertToDouble(oldValue);
}
}
return d;
}
private void setVolume()
{
double a = textInputToNumber(amount.getText(), amount.getText());
double p = textInputToNumber(price.getText(), price.getText());
volume.setText(Formatter.formatPrice(a * p));
}
}
package io.bitsquare.gui.trade.offer;
import com.google.inject.Inject;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.util.Converter;
import io.bitsquare.gui.util.Formatter;
import io.bitsquare.settings.OrderBookFilterSettings;
import io.bitsquare.settings.Settings;
import io.bitsquare.trade.Direction;
import io.bitsquare.trade.Offer;
import io.bitsquare.trade.OfferConstraints;
import io.bitsquare.trade.TradingFacade;
import io.bitsquare.trade.orderbook.MockOrderBook;
import io.bitsquare.trade.orderbook.OrderBookFilter;
import io.bitsquare.user.User;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.ArrayList;
import java.util.Currency;
import java.util.ResourceBundle;
import java.util.UUID;
public class CreateOfferController implements Initializable, IChildController
{
private static final Logger log = LoggerFactory.getLogger(CreateOfferController.class);
private INavigationController navigationController;
private TradingFacade tradingFacade;
private OrderBookFilterSettings orderBookFilterSettings;
private Settings settings;
private User user;
private double filterPaneItemOffset;
private Direction direction;
@FXML
public AnchorPane holderPane;
@FXML
public Pane detailsPane;
@FXML
public Label buyLabel;
@FXML
public TextField volume;
@FXML
public ImageView directionImageView;
@FXML
public TextField amount;
@FXML
public TextField price;
@FXML
public TextField minAmount;
@FXML
public Button placeOfferButton;
@Inject
public CreateOfferController(TradingFacade tradingFacade, OrderBookFilterSettings orderBookFilterSettings, Settings settings, User user)
{
this.tradingFacade = tradingFacade;
this.orderBookFilterSettings = orderBookFilterSettings;
this.settings = settings;
this.user = user;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
createFilterPane();
amount.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
setVolume();
}
});
price.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
setVolume();
}
});
placeOfferButton.setOnAction(e -> {
// TODO not impl yet. use mocks
OfferConstraints offerConstraints = new MockOrderBook(settings).getRandomOfferConstraints();
Offer offer = new Offer(UUID.randomUUID(),
direction,
Converter.convertToDouble(price.getText()),
Converter.convertToDouble(amount.getText()),
Converter.convertToDouble(minAmount.getText()),
settings.getCurrency(),
user,
offerConstraints);
tradingFacade.placeNewOffer(offer);
TabPane tabPane = ((TabPane) (holderPane.getParent().getParent()));
tabPane.getTabs().remove(tabPane.getSelectionModel().getSelectedItem());
navigationController.navigateToView(INavigationController.TRADE__ORDER_BOOK, "Orderbook");
});
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
public void setOrderBookFilter(OrderBookFilter orderBookFilter)
{
direction = orderBookFilter.getDirection();
amount.setText(Formatter.formatPrice(orderBookFilter.getAmount()));
minAmount.setText(Formatter.formatPrice(orderBookFilter.getAmount()));
price.setText(Formatter.formatPrice(orderBookFilter.getPrice()));
configDirection();
}
private void configDirection()
{
String iconPath;
String buyLabelText;
if (direction == Direction.BUY)
{
iconPath = "/images/buy.png";
buyLabelText = "BUY";
}
else
{
iconPath = "/images/sell.png";
buyLabelText = "SELL";
}
Image icon = new Image(getClass().getResourceAsStream(iconPath));
directionImageView.setImage(icon);
buyLabel.setText(buyLabelText);
}
private void createFilterPane()
{
filterPaneItemOffset = 30;
ArrayList<Currency> currencies = orderBookFilterSettings.getCurrencies();
Currency currency = orderBookFilterSettings.getCurrency();
ComboBox currencyComboBox = createCurrencyItem("Currency: ", currency, currencies);
currencyComboBox.valueProperty().addListener(new ChangeListener<Currency>()
{
@Override
public void changed(ObservableValue ov, Currency oldValue, Currency newValue)
{
orderBookFilterSettings.setCurrency(newValue);
}
});
Label bankLabel = createFilterItem("Bank transfer types: ", "SEPA, OKPAY");
Label countriesLabel = createFilterItem("Countries: ", "DE, GB, AT");
Label languagesLabel = createFilterItem("Languages: ", "DE, EN");
Label arbitratorsLabel = createFilterItem("Arbitrators: ", "Paysty, BitRated");
Label identityLabel = createFilterItem("Identity verifications: ", "Passport, Google+, Facebook, Skype");
TextField collateralLabel = createCollateralItem("Collateral (%): ", 10);
}
private ComboBox createCurrencyItem(String labelText, Currency currency, ArrayList<Currency> currencies)
{
final Separator separator = new Separator();
separator.setPrefWidth(380);
separator.setLayoutY(0 + filterPaneItemOffset);
separator.setLayoutX(0);
final Label label = new Label(labelText);
label.setLayoutY(10 + filterPaneItemOffset);
ObservableList<Currency> options = FXCollections.observableArrayList(currencies);
final ComboBox comboBox = new ComboBox(options);
comboBox.setLayoutX(70);
comboBox.setLayoutY(5 + filterPaneItemOffset);
comboBox.setValue(currency);
detailsPane.getChildren().addAll(separator, label, comboBox);
filterPaneItemOffset += 40;
return comboBox;
}
private Label createFilterItem(String labelText, String valueText)
{
final Separator separator = new Separator();
separator.setPrefWidth(380);
separator.setLayoutY(0 + filterPaneItemOffset);
separator.setLayoutX(0);
final Label label = new Label(labelText + valueText);
label.setLayoutY(10 + filterPaneItemOffset);
label.setPrefWidth(310);
Tooltip tooltip = new Tooltip(valueText);
label.setTooltip(tooltip);
final Button edit = new Button("Edit");
edit.setPrefWidth(50);
edit.setLayoutX(330);
edit.setLayoutY(5 + filterPaneItemOffset);
detailsPane.getChildren().addAll(separator, label, edit);
filterPaneItemOffset += 40;
return label;
}
private TextField createCollateralItem(String labelText, double collateral)
{
final Separator separator = new Separator();
separator.setPrefWidth(380);
separator.setLayoutY(0 + filterPaneItemOffset);
separator.setLayoutX(0);
final Label label = new Label(labelText);
label.setLayoutY(10 + filterPaneItemOffset);
label.setPrefWidth(310);
final TextField collateralValue = new TextField(Double.toString(collateral));
collateralValue.setLayoutX(90);
collateralValue.setLayoutY(5 + filterPaneItemOffset);
collateralValue.setPrefWidth(50);
detailsPane.getChildren().addAll(separator, label, collateralValue);
filterPaneItemOffset += 40;
return collateralValue;
}
private double textInputToNumber(String oldValue, String newValue)
{
//TODO use regex.... or better custom textfield component
double d = 0.0;
if (!newValue.equals(""))
{
d = Converter.convertToDouble(newValue);
if (d == Double.NEGATIVE_INFINITY)
{
amount.setText(oldValue);
d = Converter.convertToDouble(oldValue);
}
}
return d;
}
private void setVolume()
{
double a = textInputToNumber(amount.getText(), amount.getText());
double p = textInputToNumber(price.getText(), price.getText());
volume.setText(Formatter.formatPrice(a * p));
}
}

View File

@ -1,242 +1,242 @@
package io.bitsquare.gui.trade.orderbook;
import com.google.inject.Inject;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.trade.offer.CreateOfferController;
import io.bitsquare.gui.trade.tradeprocess.TradeProcessController;
import io.bitsquare.gui.util.Converter;
import io.bitsquare.gui.util.Formatter;
import io.bitsquare.gui.util.Icons;
import io.bitsquare.settings.Settings;
import io.bitsquare.trade.Direction;
import io.bitsquare.trade.orderbook.IOrderBook;
import io.bitsquare.trade.orderbook.MockOrderBook;
import io.bitsquare.trade.orderbook.OrderBookFilter;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Arrays;
import java.util.ResourceBundle;
public class OrderBookController implements Initializable, IChildController
{
private INavigationController navigationController;
private IOrderBook orderBook;
private Settings settings;
private OrderBookListItem selectedOrderBookListItem;
private final OrderBookFilter orderBookFilter;
private Button createOfferButton;
private Image buyIcon = Icons.getIconImage(Icons.BUY);
private Image sellIcon = Icons.getIconImage(Icons.SELL);
@FXML
public AnchorPane holderPane;
@FXML
public HBox topHBox;
@FXML
private Button tradeButton;
@FXML
public TextField volume, amount, price;
@FXML
public Pane filterPane;
@FXML
public TableView<OrderBookListItem> orderBookTable;
@FXML
public TableColumn priceColumn, amountColumn, volumeColumn;
@FXML
private ImageView tradeButtonImageView;
@Inject
public OrderBookController(IOrderBook orderBook, OrderBookFilter orderBookFilter, Settings settings)
{
this.orderBook = orderBook;
this.orderBookFilter = orderBookFilter;
this.settings = settings;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
orderBookFilter.getCurrencyProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
updateOfferList();
}
});
createFilterPane();
updateOfferList();
amount.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
orderBookFilter.setAmount(textInputToNumber(oldValue, newValue));
updateOfferList();
updateVolume();
}
});
price.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
orderBookFilter.setPrice(textInputToNumber(oldValue, newValue));
updateOfferList();
updateVolume();
}
});
orderBookTable.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
selectedOrderBookListItem = orderBookTable.getSelectionModel().getSelectedItem();
tradeButton.setDisable(selectedOrderBookListItem == null);
});
tradeButton.setOnAction(e -> openTradeTab(selectedOrderBookListItem));
tradeButton.setDisable(true);
tradeButton.setDefaultButton(true);
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
public void setDirection(Direction direction)
{
orderBookTable.getSelectionModel().clearSelection();
tradeButton.setDisable(true);
price.setText("");
String title;
Image icon;
if (direction == Direction.SELL)
{
title = "SELL";
icon = sellIcon;
}
else
{
title = "BUY";
icon = buyIcon;
}
tradeButton.setText(title);
tradeButtonImageView.setImage(icon);
orderBookFilter.setDirection(direction);
updateOfferList();
}
private void openTradeTab(OrderBookListItem orderBookListItem)
{
String title = orderBookListItem.getOffer().getDirection() == Direction.BUY ? "Trade: Sell Bitcoin" : "Trade: Buy Bitcoin";
TradeProcessController tradeProcessController = (TradeProcessController) navigationController.navigateToView(INavigationController.TRADE__PROCESS, title);
double requestedAmount = orderBookListItem.getOffer().getAmount();
if (!amount.getText().equals(""))
requestedAmount = Converter.convertToDouble(amount.getText());
tradeProcessController.initView(orderBookListItem.getOffer(), requestedAmount);
}
private void displayCreateOfferButton()
{
if (createOfferButton == null)
{
createOfferButton = new Button("Create new offer");
holderPane.setBottomAnchor(createOfferButton, 375.0);
holderPane.setLeftAnchor(createOfferButton, 200.0);
holderPane.getChildren().add(createOfferButton);
createOfferButton.setOnAction(e -> {
IChildController nextController = navigationController.navigateToView(INavigationController.TRADE__CREATE_OFFER, "Create offer");
((CreateOfferController) nextController).setOrderBookFilter(orderBookFilter);
});
}
createOfferButton.setVisible(true);
holderPane.setBottomAnchor(orderBookTable, 410.0);
}
private void updateOfferList()
{
ObservableList offers = orderBook.getFilteredList(orderBookFilter);
orderBookTable.setItems(offers);
orderBookTable.getSortOrder().add(priceColumn);
priceColumn.setSortType((orderBookFilter.getDirection() == Direction.BUY) ? TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
if (offers.size() == 0)
{
displayCreateOfferButton();
}
else if (createOfferButton != null)
{
createOfferButton.setVisible(false);
holderPane.setBottomAnchor(orderBookTable, 10.0);
}
}
private void createFilterPane()
{
MockOrderBook mockOrderBook = new MockOrderBook(settings);
orderBookFilter.setOfferConstraints(mockOrderBook.getRandomOfferConstraints());
OrderBookFilterTextItemBuilder.build(filterPane, "Bank transfer types: ", orderBookFilter.getOfferConstraints().getBankTransferTypes(), settings.getAllBankTransferTypes());
OrderBookFilterTextItemBuilder.build(filterPane, "Countries: ", orderBookFilter.getOfferConstraints().getCountries(), settings.getAllCountries());
OrderBookFilterTextItemBuilder.build(filterPane, "Languages: ", orderBookFilter.getOfferConstraints().getLanguages(), settings.getAllLanguages());
OrderBookFilterTextItemBuilder.build(filterPane, "Collateral: ", Arrays.asList(String.valueOf(orderBookFilter.getOfferConstraints().getCollateral())), settings.getAllCollaterals());
OrderBookFilterTextItemBuilder.build(filterPane, "Arbitrator: ", Arrays.asList(orderBookFilter.getOfferConstraints().getArbitrator()), settings.getAllArbitrators());
}
private double textInputToNumber(String oldValue, String newValue)
{
//TODO use regex.... or custom textfield component
double d = 0.0;
if (!newValue.equals(""))
{
try
{
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Settings.getLocale());
d = decimalFormat.parse(newValue).doubleValue();
} catch (ParseException e)
{
amount.setText(oldValue);
d = Converter.convertToDouble(oldValue);
}
}
return d;
}
private void updateVolume()
{
double a = textInputToNumber(amount.getText(), amount.getText());
double p = textInputToNumber(price.getText(), price.getText());
volume.setText(Formatter.formatPrice(a * p));
}
}
package io.bitsquare.gui.trade.orderbook;
import com.google.inject.Inject;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.trade.offer.CreateOfferController;
import io.bitsquare.gui.trade.tradeprocess.TradeProcessController;
import io.bitsquare.gui.util.Converter;
import io.bitsquare.gui.util.Formatter;
import io.bitsquare.gui.util.Icons;
import io.bitsquare.settings.Settings;
import io.bitsquare.trade.Direction;
import io.bitsquare.trade.orderbook.IOrderBook;
import io.bitsquare.trade.orderbook.MockOrderBook;
import io.bitsquare.trade.orderbook.OrderBookFilter;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Arrays;
import java.util.ResourceBundle;
public class OrderBookController implements Initializable, IChildController
{
private INavigationController navigationController;
private IOrderBook orderBook;
private Settings settings;
private OrderBookListItem selectedOrderBookListItem;
private final OrderBookFilter orderBookFilter;
private Button createOfferButton;
private Image buyIcon = Icons.getIconImage(Icons.BUY);
private Image sellIcon = Icons.getIconImage(Icons.SELL);
@FXML
public AnchorPane holderPane;
@FXML
public HBox topHBox;
@FXML
private Button tradeButton;
@FXML
public TextField volume, amount, price;
@FXML
public Pane filterPane;
@FXML
public TableView<OrderBookListItem> orderBookTable;
@FXML
public TableColumn priceColumn, amountColumn, volumeColumn;
@FXML
private ImageView tradeButtonImageView;
@Inject
public OrderBookController(IOrderBook orderBook, OrderBookFilter orderBookFilter, Settings settings)
{
this.orderBook = orderBook;
this.orderBookFilter = orderBookFilter;
this.settings = settings;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
orderBookFilter.getCurrencyProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
updateOfferList();
}
});
createFilterPane();
updateOfferList();
amount.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
orderBookFilter.setAmount(textInputToNumber(oldValue, newValue));
updateOfferList();
updateVolume();
}
});
price.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
{
orderBookFilter.setPrice(textInputToNumber(oldValue, newValue));
updateOfferList();
updateVolume();
}
});
orderBookTable.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
selectedOrderBookListItem = orderBookTable.getSelectionModel().getSelectedItem();
tradeButton.setDisable(selectedOrderBookListItem == null);
});
tradeButton.setOnAction(e -> openTradeTab(selectedOrderBookListItem));
tradeButton.setDisable(true);
tradeButton.setDefaultButton(true);
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
public void setDirection(Direction direction)
{
orderBookTable.getSelectionModel().clearSelection();
tradeButton.setDisable(true);
price.setText("");
String title;
Image icon;
if (direction == Direction.SELL)
{
title = "SELL";
icon = sellIcon;
}
else
{
title = "BUY";
icon = buyIcon;
}
tradeButton.setText(title);
tradeButtonImageView.setImage(icon);
orderBookFilter.setDirection(direction);
updateOfferList();
}
private void openTradeTab(OrderBookListItem orderBookListItem)
{
String title = orderBookListItem.getOffer().getDirection() == Direction.BUY ? "Trade: Sell Bitcoin" : "Trade: Buy Bitcoin";
TradeProcessController tradeProcessController = (TradeProcessController) navigationController.navigateToView(INavigationController.TRADE__PROCESS, title);
double requestedAmount = orderBookListItem.getOffer().getAmount();
if (!amount.getText().equals(""))
requestedAmount = Converter.convertToDouble(amount.getText());
tradeProcessController.initView(orderBookListItem.getOffer(), requestedAmount);
}
private void displayCreateOfferButton()
{
if (createOfferButton == null)
{
createOfferButton = new Button("Create new offer");
holderPane.setBottomAnchor(createOfferButton, 375.0);
holderPane.setLeftAnchor(createOfferButton, 200.0);
holderPane.getChildren().add(createOfferButton);
createOfferButton.setOnAction(e -> {
IChildController nextController = navigationController.navigateToView(INavigationController.TRADE__CREATE_OFFER, "Create offer");
((CreateOfferController) nextController).setOrderBookFilter(orderBookFilter);
});
}
createOfferButton.setVisible(true);
holderPane.setBottomAnchor(orderBookTable, 410.0);
}
private void updateOfferList()
{
ObservableList offers = orderBook.getFilteredList(orderBookFilter);
orderBookTable.setItems(offers);
orderBookTable.getSortOrder().add(priceColumn);
priceColumn.setSortType((orderBookFilter.getDirection() == Direction.BUY) ? TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
if (offers.size() == 0)
{
displayCreateOfferButton();
}
else if (createOfferButton != null)
{
createOfferButton.setVisible(false);
holderPane.setBottomAnchor(orderBookTable, 10.0);
}
}
private void createFilterPane()
{
MockOrderBook mockOrderBook = new MockOrderBook(settings);
orderBookFilter.setOfferConstraints(mockOrderBook.getRandomOfferConstraints());
OrderBookFilterTextItemBuilder.build(filterPane, "Bank transfer types: ", orderBookFilter.getOfferConstraints().getBankTransferTypes(), settings.getAllBankTransferTypes());
OrderBookFilterTextItemBuilder.build(filterPane, "Countries: ", orderBookFilter.getOfferConstraints().getCountries(), settings.getAllCountries());
OrderBookFilterTextItemBuilder.build(filterPane, "Languages: ", orderBookFilter.getOfferConstraints().getLanguages(), settings.getAllLanguages());
OrderBookFilterTextItemBuilder.build(filterPane, "Collateral: ", Arrays.asList(String.valueOf(orderBookFilter.getOfferConstraints().getCollateral())), settings.getAllCollaterals());
OrderBookFilterTextItemBuilder.build(filterPane, "Arbitrator: ", Arrays.asList(orderBookFilter.getOfferConstraints().getArbitrator()), settings.getAllArbitrators());
}
private double textInputToNumber(String oldValue, String newValue)
{
//TODO use regex.... or custom textfield component
double d = 0.0;
if (!newValue.equals(""))
{
try
{
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Settings.getLocale());
d = decimalFormat.parse(newValue).doubleValue();
} catch (ParseException e)
{
amount.setText(oldValue);
d = Converter.convertToDouble(oldValue);
}
}
return d;
}
private void updateVolume()
{
double a = textInputToNumber(amount.getText(), amount.getText());
double p = textInputToNumber(price.getText(), price.getText());
volume.setText(Formatter.formatPrice(a * p));
}
}

View File

@ -1,436 +1,436 @@
package io.bitsquare.gui.trade.tradeprocess;
import com.google.inject.Inject;
import io.bitsquare.btc.BtcFormatter;
import io.bitsquare.btc.Fees;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.components.VSpacer;
import io.bitsquare.gui.components.processbar.ProcessStepBar;
import io.bitsquare.gui.components.processbar.ProcessStepItem;
import io.bitsquare.gui.util.Colors;
import io.bitsquare.gui.util.Converter;
import io.bitsquare.gui.util.Formatter;
import io.bitsquare.gui.util.Utils;
import io.bitsquare.trade.*;
import io.bitsquare.user.User;
import javafx.animation.AnimationTimer;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import org.controlsfx.dialog.Dialogs;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class TradeProcessController implements Initializable, IChildController
{
private TradingFacade tradingFacade;
private Offer offer;
private Trade trade;
private Contract contract;
private INavigationController navigationController;
private List<ProcessStepItem> processStepItems = new ArrayList();
private double requestedAmount;
private VBox vBox;
private TitledPane offerDetailsTitlePane, contractTitlePane;
private ProcessStepBar<String> processStepBar;
private Button nextButton;
private TextField amountTextField;
private Label offererPubKeyLabel, offererAccountPrimaryID, offererAccountSecondaryIDLabel,
offererAccountHolderNameLabel, feedbackLabel, infoLabel, totalLabel, volumeLabel, totalToPayLabel,
totalToReceiveLabel, collateralLabel1, collateralLabel2, amountLabel;
private Pane progressPane;
private ProgressBar progressBar;
private ProgressIndicator progressIndicator;
@FXML
public AnchorPane rootContainer;
@Inject
public TradeProcessController(TradingFacade tradingFacade)
{
this.tradingFacade = tradingFacade;
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
public void initView(Offer offer, double requestedAmount)
{
this.offer = offer;
this.requestedAmount = requestedAmount;
trade = tradingFacade.createNewTrade(offer);
trade.setRequestedAmount(requestedAmount);
contract = tradingFacade.createNewContract(trade);
processStepItems.add(new ProcessStepItem(takerIsSelling() ? "Sell BTC" : "Buy BTC", Colors.BLUE));
processStepItems.add(new ProcessStepItem("Bank transfer", Colors.BLUE));
processStepItems.add(new ProcessStepItem("Completed", Colors.BLUE));
processStepBar = new ProcessStepBar(processStepItems);
buildStep1();
}
private void trade()
{
double requestedAmount = Converter.convertToDouble(amountTextField.getText());
if (requestedAmount <= offer.getAmount() && requestedAmount >= offer.getMinAmount())
{
amountTextField.setEditable(false);
trade.setRequestedAmount(requestedAmount);
vBox.getChildren().remove(nextButton);
AnchorPane.setTopAnchor(contractTitlePane, 350.0);
progressBar = new ProgressBar();
progressBar.setProgress(0.0);
progressBar.setPrefWidth(200);
progressBar.relocate(10, 10);
progressIndicator = new ProgressIndicator();
progressIndicator.setProgress(-1.0);
progressIndicator.setPrefSize(20, 20);
progressIndicator.relocate(220, 10);
feedbackLabel = new Label();
feedbackLabel.setPadding(new Insets(-10, 0, 0, 0));
feedbackLabel.setId("feedback-text");
feedbackLabel.relocate(10, 50);
progressPane = new Pane();
progressPane.getChildren().addAll(progressBar, progressIndicator, feedbackLabel);
vBox.getChildren().add(progressPane);
sendTakeOfferRequest();
}
else
{
Dialogs.create()
.title("Your input is not valid")
.message("The requested amount you entered is outside of the range of the offered amount.")
.nativeTitleBar()
.lightweight()
.showError();
}
}
// Payment Process
private void sendTakeOfferRequest()
{
tradingFacade.sendTakeOfferRequest(trade);
feedbackLabel.setText("Request take offer confirmation from peer.");
Utils.setTimeout(500, (AnimationTimer animationTimer) -> {
onTakeOfferRequestConfirmed();
progressBar.setProgress(1.0 / 3.0);
return null;
});
}
private void onTakeOfferRequestConfirmed()
{
tradingFacade.payOfferFee(trade);
feedbackLabel.setText("Request offer fee payment confirmation from peer.");
Utils.setTimeout(500, (AnimationTimer animationTimer) -> {
onOfferFeePaymentConfirmed();
progressBar.setProgress(2.0 / 3.0);
return null;
});
}
private void onOfferFeePaymentConfirmed()
{
tradingFacade.requestOffererDetailData();
feedbackLabel.setText("Request detail data from peer.");
Utils.setTimeout(500, (AnimationTimer animationTimer) -> {
onUserDetailsReceived();
progressBar.setProgress(1.0);
return null;
});
}
private void onUserDetailsReceived()
{
tradingFacade.signContract(contract);
tradingFacade.payToDepositTx(trade);
buildWaitBankTransfer();
}
private void buildWaitBankTransfer()
{
processStepBar.next();
vBox.getChildren().remove(progressPane);
vBox.getChildren().remove(offerDetailsTitlePane);
vBox.getChildren().remove(nextButton);
rootContainer.getChildren().remove(contractTitlePane);
infoLabel = new Label("Wait for Bank transfer.");
vBox.getChildren().addAll(infoLabel);
Utils.setTimeout(2000, (AnimationTimer animationTimer) -> {
onBankTransferInited();
return null;
});
}
private void onBankTransferInited()
{
infoLabel.setText("Bank transfer has been inited.\nCheck your bank account and continue when you have received the money.\n");
nextButton.setText("Money received on Bank account");
nextButton.setOnAction(e -> releaseBTC());
vBox.getChildren().add(nextButton);
}
private void releaseBTC()
{
processStepBar.next();
tradingFacade.releaseBTC(trade);
vBox.getChildren().remove(infoLabel);
nextButton.setText("Close");
nextButton.setOnAction(e -> close());
GridPane summaryGridPane = new GridPane();
int row = 0;
summaryGridPane.setVgap(5);
summaryGridPane.setHgap(5);
summaryGridPane.setPadding(new Insets(5, 5, 5, 5));
addLabel(summaryGridPane, "You have payed:", getTotalToPay(), ++row);
addLabel(summaryGridPane, "You have received:\n ", getTotalToReceive(), ++row);
TitledPane summaryTitlePane = new TitledPane("Trade summary:", summaryGridPane);
summaryTitlePane.setCollapsible(false);
vBox.getChildren().add(2, summaryTitlePane);
}
private void close()
{
TabPane tabPane = ((TabPane) (rootContainer.getParent().getParent()));
tabPane.getTabs().remove(tabPane.getSelectionModel().getSelectedItem());
navigationController.navigateToView(INavigationController.TRADE__ORDER_BOOK, "Orderbook");
}
private void buildStep1()
{
OfferConstraints offerConstraints = offer.getOfferConstraints();
User taker = contract.getTaker();
User offerer = contract.getOfferer();
GridPane offerDetailsGridPane = new GridPane();
int row = 0;
offerDetailsGridPane.setVgap(5);
offerDetailsGridPane.setHgap(5);
offerDetailsGridPane.setPadding(new Insets(5, 5, 5, 5));
amountTextField = addInputField(offerDetailsGridPane, "Amount (BTC):", Formatter.formatAmount(getAmount()), ++row);
amountTextField.textProperty().addListener(e -> {
setTotal();
setVolume();
setCollateral();
totalToPayLabel.setText(getTotalToPay());
totalToReceiveLabel.setText(getTotalToReceive());
amountLabel.setText(amountTextField.getText());
});
offerDetailsGridPane.add(new Label("(" + offer.getAmount() + "BTC - " + offer.getMinAmount() + "BTC)"), 2, row);
addLabel(offerDetailsGridPane, "Price:", Formatter.formatPriceWithCurrencyPair(offer.getPrice(), offer.getCurrency()), ++row);
totalLabel = addLabel(offerDetailsGridPane, "Total:", "", ++row);
setTotal();
collateralLabel1 = addLabel(offerDetailsGridPane, "Collateral:", Formatter.formatCollateral(offer.getOfferConstraints().getCollateral(), getAmount()), ++row);
addLabel(offerDetailsGridPane, "Offer fee:", Formatter.formatSatoshis(Fees.OFFER_CREATION_FEE, true), ++row);
addVSpacer(offerDetailsGridPane, ++row);
totalToPayLabel = addLabel(offerDetailsGridPane, "You pay:", getTotalToPay(), ++row);
totalToReceiveLabel = addLabel(offerDetailsGridPane, "You receive:\n ", getTotalToReceive(), ++row);
offerDetailsTitlePane = new TitledPane(takerIsSelling() ? "Sell Bitcoin" : "Buy Bitcoin", offerDetailsGridPane);
offerDetailsTitlePane.setCollapsible(false);
nextButton = new Button(processStepItems.get(0).getLabel());
nextButton.setDefaultButton(true);
nextButton.setOnAction(e -> trade());
GridPane contractGridPane = new GridPane();
contractGridPane.setVgap(5);
contractGridPane.setHgap(5);
contractGridPane.setPadding(new Insets(5, 5, 5, 5));
row = 0;
addHeaderLabel(contractGridPane, "Offer details:", row);
addLabel(contractGridPane, "Offer ID:", offer.getUid().toString(), ++row);
addLabel(contractGridPane, "Offer type:", Formatter.formatDirection((offer.getDirection() == Direction.BUY ? Direction.SELL : Direction.BUY), false), ++row);
amountLabel = addLabel(contractGridPane, "Amount:", Formatter.formatAmount(getAmount()), ++row);
volumeLabel = addLabel(contractGridPane, "Volume:", "", ++row);
setVolume();
addLabel(contractGridPane, "Price:", Formatter.formatPriceWithCurrencyPair(offer.getPrice(), offer.getCurrency()), ++row);
collateralLabel2 = addLabel(contractGridPane, "Collateral:", "", ++row);
setCollateral();
addLabel(contractGridPane, "Language:", Formatter.formatList(offerConstraints.getLanguages()), ++row);
addLabel(contractGridPane, "Arbitrator:", offerConstraints.getArbitrator(), ++row);
// addLabel(contractGridPane, "Identity verification:", Formatter.formatList(offerConstraints.getIdentityVerifications()), ++row);
addLabel(contractGridPane, "Bank transfer reference ID:", "Purchase xyz 01.04.2014", ++row);
addVSpacer(contractGridPane, ++row);
addHeaderLabel(contractGridPane, "Offerer data:", ++row);
addLabel(contractGridPane, "Account ID:", offerer.getAccountID(), ++row);
addLabel(contractGridPane, "Messaging ID:", offerer.getMessageID(), ++row);
addLabel(contractGridPane, "Country:", offerer.getCountry(), ++row);
offererPubKeyLabel = addLabel(contractGridPane, "Payment public key:", contract.getOffererPubKey(), ++row);
addLabel(contractGridPane, "Bank transfer type:", offerer.getBankDetails().getBankTransferType(), ++row);
offererAccountPrimaryID = addLabel(contractGridPane, "Bank account IBAN:", offerer.getBankDetails().getAccountPrimaryID(), ++row);
offererAccountSecondaryIDLabel = addLabel(contractGridPane, "Bank account BIC:", offerer.getBankDetails().getAccountSecondaryID(), ++row);
offererAccountHolderNameLabel = addLabel(contractGridPane, "Bank account holder:", offerer.getBankDetails().getAccountHolderName(), ++row);
addVSpacer(contractGridPane, ++row);
addHeaderLabel(contractGridPane, "Offer taker data:", ++row);
addLabel(contractGridPane, "Account ID:", taker.getAccountID(), ++row);
addLabel(contractGridPane, "Messaging ID:", taker.getMessageID(), ++row);
addLabel(contractGridPane, "Country:", taker.getCountry(), ++row);
addLabel(contractGridPane, "Payment public key:", contract.getTakerPubKey(), ++row);
addLabel(contractGridPane, "Bank transfer type:", taker.getBankDetails().getBankTransferType(), ++row);
addLabel(contractGridPane, "Bank account IBAN:", taker.getBankDetails().getAccountPrimaryID(), ++row);
addLabel(contractGridPane, "Bank account BIC:", taker.getBankDetails().getAccountSecondaryID(), ++row);
addLabel(contractGridPane, "Bank account holder:", taker.getBankDetails().getAccountHolderName(), ++row);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(contractGridPane);
contractTitlePane = new TitledPane("Contract", scrollPane);
contractTitlePane.setCollapsible(false);
AnchorPane.setLeftAnchor(contractTitlePane, 10.0);
AnchorPane.setRightAnchor(contractTitlePane, 10.0);
AnchorPane.setTopAnchor(contractTitlePane, 324.0);
AnchorPane.setBottomAnchor(contractTitlePane, 10.0);
vBox = new VBox();
AnchorPane.setLeftAnchor(vBox, 10.0);
AnchorPane.setRightAnchor(vBox, 10.0);
AnchorPane.setTopAnchor(vBox, 10.0);
vBox.setSpacing(10);
vBox.getChildren().addAll(processStepBar, new VSpacer(5), offerDetailsTitlePane, nextButton);
rootContainer.getChildren().addAll(vBox, contractTitlePane);
}
private Label addLabel(GridPane gridPane, String title, String value, int row)
{
gridPane.add(new Label(title), 0, row);
Label valueLabel = new Label(value);
gridPane.add(valueLabel, 1, row);
return valueLabel;
}
private void addHeaderLabel(GridPane gridPane, String title, int row)
{
Label headerLabel = new Label(title);
headerLabel.setId("form-header-text");
gridPane.add(headerLabel, 0, row);
}
private TextField addInputField(GridPane gridPane, String title, String value, int row)
{
gridPane.add(new Label(title), 0, row);
TextField textField = new TextField(value);
gridPane.add(textField, 1, row);
return textField;
}
private void addVSpacer(GridPane gridPane, int row)
{
gridPane.add(new VSpacer(10), 0, row);
}
private void setTotal()
{
totalLabel.setText(Formatter.formatVolume(getVolume()));
}
private void setVolume()
{
totalLabel.setText(Formatter.formatVolume(getVolume(), offer.getCurrency()));
}
private boolean takerIsSelling()
{
return offer.getDirection() == Direction.BUY;
}
private double getVolume()
{
return offer.getPrice() * Converter.convertToDouble(amountTextField.getText());
}
private double getAmount()
{
return requestedAmount > 0 ? requestedAmount : offer.getAmount();
}
private String getTotalToPay()
{
String result = "";
if (takerIsSelling())
{
double btcValue = Converter.convertToDouble(amountTextField.getText()) + BtcFormatter.satoshiToBTC(Fees.OFFER_CREATION_FEE) +
offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true);
}
else
{
double btcValue = BtcFormatter.satoshiToBTC(Fees.OFFER_CREATION_FEE) + offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true) + "\n" + Formatter.formatVolume(getVolume(), offer.getCurrency());
}
return result;
}
private String getTotalToReceive()
{
String result = "";
if (takerIsSelling())
{
double btcValue = offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true) + "\n" + Formatter.formatVolume(getVolume(), offer.getCurrency());
}
else
{
double btcValue = Converter.convertToDouble(amountTextField.getText()) +
offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true);
}
return result;
}
public void setCollateral()
{
String value = Formatter.formatCollateral(offer.getOfferConstraints().getCollateral(), Converter.convertToDouble(amountTextField.getText()));
collateralLabel1.setText(value);
collateralLabel2.setText(value);
}
}
package io.bitsquare.gui.trade.tradeprocess;
import com.google.inject.Inject;
import io.bitsquare.btc.BtcFormatter;
import io.bitsquare.btc.Fees;
import io.bitsquare.gui.IChildController;
import io.bitsquare.gui.INavigationController;
import io.bitsquare.gui.components.VSpacer;
import io.bitsquare.gui.components.processbar.ProcessStepBar;
import io.bitsquare.gui.components.processbar.ProcessStepItem;
import io.bitsquare.gui.util.Colors;
import io.bitsquare.gui.util.Converter;
import io.bitsquare.gui.util.Formatter;
import io.bitsquare.gui.util.Utils;
import io.bitsquare.trade.*;
import io.bitsquare.user.User;
import javafx.animation.AnimationTimer;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import org.controlsfx.dialog.Dialogs;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class TradeProcessController implements Initializable, IChildController
{
private TradingFacade tradingFacade;
private Offer offer;
private Trade trade;
private Contract contract;
private INavigationController navigationController;
private List<ProcessStepItem> processStepItems = new ArrayList();
private double requestedAmount;
private VBox vBox;
private TitledPane offerDetailsTitlePane, contractTitlePane;
private ProcessStepBar<String> processStepBar;
private Button nextButton;
private TextField amountTextField;
private Label offererPubKeyLabel, offererAccountPrimaryID, offererAccountSecondaryIDLabel,
offererAccountHolderNameLabel, feedbackLabel, infoLabel, totalLabel, volumeLabel, totalToPayLabel,
totalToReceiveLabel, collateralLabel1, collateralLabel2, amountLabel;
private Pane progressPane;
private ProgressBar progressBar;
private ProgressIndicator progressIndicator;
@FXML
public AnchorPane rootContainer;
@Inject
public TradeProcessController(TradingFacade tradingFacade)
{
this.tradingFacade = tradingFacade;
}
@Override
public void setNavigationController(INavigationController navigationController)
{
this.navigationController = navigationController;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
public void initView(Offer offer, double requestedAmount)
{
this.offer = offer;
this.requestedAmount = requestedAmount;
trade = tradingFacade.createNewTrade(offer);
trade.setRequestedAmount(requestedAmount);
contract = tradingFacade.createNewContract(trade);
processStepItems.add(new ProcessStepItem(takerIsSelling() ? "Sell BTC" : "Buy BTC", Colors.BLUE));
processStepItems.add(new ProcessStepItem("Bank transfer", Colors.BLUE));
processStepItems.add(new ProcessStepItem("Completed", Colors.BLUE));
processStepBar = new ProcessStepBar(processStepItems);
buildStep1();
}
private void trade()
{
double requestedAmount = Converter.convertToDouble(amountTextField.getText());
if (requestedAmount <= offer.getAmount() && requestedAmount >= offer.getMinAmount())
{
amountTextField.setEditable(false);
trade.setRequestedAmount(requestedAmount);
vBox.getChildren().remove(nextButton);
AnchorPane.setTopAnchor(contractTitlePane, 350.0);
progressBar = new ProgressBar();
progressBar.setProgress(0.0);
progressBar.setPrefWidth(200);
progressBar.relocate(10, 10);
progressIndicator = new ProgressIndicator();
progressIndicator.setProgress(-1.0);
progressIndicator.setPrefSize(20, 20);
progressIndicator.relocate(220, 10);
feedbackLabel = new Label();
feedbackLabel.setPadding(new Insets(-10, 0, 0, 0));
feedbackLabel.setId("feedback-text");
feedbackLabel.relocate(10, 50);
progressPane = new Pane();
progressPane.getChildren().addAll(progressBar, progressIndicator, feedbackLabel);
vBox.getChildren().add(progressPane);
sendTakeOfferRequest();
}
else
{
Dialogs.create()
.title("Your input is not valid")
.message("The requested amount you entered is outside of the range of the offered amount.")
.nativeTitleBar()
.lightweight()
.showError();
}
}
// Payment Process
private void sendTakeOfferRequest()
{
tradingFacade.sendTakeOfferRequest(trade);
feedbackLabel.setText("Request take offer confirmation from peer.");
Utils.setTimeout(500, (AnimationTimer animationTimer) -> {
onTakeOfferRequestConfirmed();
progressBar.setProgress(1.0 / 3.0);
return null;
});
}
private void onTakeOfferRequestConfirmed()
{
tradingFacade.payOfferFee(trade);
feedbackLabel.setText("Request offer fee payment confirmation from peer.");
Utils.setTimeout(500, (AnimationTimer animationTimer) -> {
onOfferFeePaymentConfirmed();
progressBar.setProgress(2.0 / 3.0);
return null;
});
}
private void onOfferFeePaymentConfirmed()
{
tradingFacade.requestOffererDetailData();
feedbackLabel.setText("Request detail data from peer.");
Utils.setTimeout(500, (AnimationTimer animationTimer) -> {
onUserDetailsReceived();
progressBar.setProgress(1.0);
return null;
});
}
private void onUserDetailsReceived()
{
tradingFacade.signContract(contract);
tradingFacade.payToDepositTx(trade);
buildWaitBankTransfer();
}
private void buildWaitBankTransfer()
{
processStepBar.next();
vBox.getChildren().remove(progressPane);
vBox.getChildren().remove(offerDetailsTitlePane);
vBox.getChildren().remove(nextButton);
rootContainer.getChildren().remove(contractTitlePane);
infoLabel = new Label("Wait for Bank transfer.");
vBox.getChildren().addAll(infoLabel);
Utils.setTimeout(2000, (AnimationTimer animationTimer) -> {
onBankTransferInited();
return null;
});
}
private void onBankTransferInited()
{
infoLabel.setText("Bank transfer has been inited.\nCheck your bank account and continue when you have received the money.\n");
nextButton.setText("Money received on Bank account");
nextButton.setOnAction(e -> releaseBTC());
vBox.getChildren().add(nextButton);
}
private void releaseBTC()
{
processStepBar.next();
tradingFacade.releaseBTC(trade);
vBox.getChildren().remove(infoLabel);
nextButton.setText("Close");
nextButton.setOnAction(e -> close());
GridPane summaryGridPane = new GridPane();
int row = 0;
summaryGridPane.setVgap(5);
summaryGridPane.setHgap(5);
summaryGridPane.setPadding(new Insets(5, 5, 5, 5));
addLabel(summaryGridPane, "You have payed:", getTotalToPay(), ++row);
addLabel(summaryGridPane, "You have received:\n ", getTotalToReceive(), ++row);
TitledPane summaryTitlePane = new TitledPane("Trade summary:", summaryGridPane);
summaryTitlePane.setCollapsible(false);
vBox.getChildren().add(2, summaryTitlePane);
}
private void close()
{
TabPane tabPane = ((TabPane) (rootContainer.getParent().getParent()));
tabPane.getTabs().remove(tabPane.getSelectionModel().getSelectedItem());
navigationController.navigateToView(INavigationController.TRADE__ORDER_BOOK, "Orderbook");
}
private void buildStep1()
{
OfferConstraints offerConstraints = offer.getOfferConstraints();
User taker = contract.getTaker();
User offerer = contract.getOfferer();
GridPane offerDetailsGridPane = new GridPane();
int row = 0;
offerDetailsGridPane.setVgap(5);
offerDetailsGridPane.setHgap(5);
offerDetailsGridPane.setPadding(new Insets(5, 5, 5, 5));
amountTextField = addInputField(offerDetailsGridPane, "Amount (BTC):", Formatter.formatAmount(getAmount()), ++row);
amountTextField.textProperty().addListener(e -> {
setTotal();
setVolume();
setCollateral();
totalToPayLabel.setText(getTotalToPay());
totalToReceiveLabel.setText(getTotalToReceive());
amountLabel.setText(amountTextField.getText());
});
offerDetailsGridPane.add(new Label("(" + offer.getAmount() + "BTC - " + offer.getMinAmount() + "BTC)"), 2, row);
addLabel(offerDetailsGridPane, "Price:", Formatter.formatPriceWithCurrencyPair(offer.getPrice(), offer.getCurrency()), ++row);
totalLabel = addLabel(offerDetailsGridPane, "Total:", "", ++row);
setTotal();
collateralLabel1 = addLabel(offerDetailsGridPane, "Collateral:", Formatter.formatCollateral(offer.getOfferConstraints().getCollateral(), getAmount()), ++row);
addLabel(offerDetailsGridPane, "Offer fee:", Formatter.formatSatoshis(Fees.OFFER_CREATION_FEE, true), ++row);
addVSpacer(offerDetailsGridPane, ++row);
totalToPayLabel = addLabel(offerDetailsGridPane, "You pay:", getTotalToPay(), ++row);
totalToReceiveLabel = addLabel(offerDetailsGridPane, "You receive:\n ", getTotalToReceive(), ++row);
offerDetailsTitlePane = new TitledPane(takerIsSelling() ? "Sell Bitcoin" : "Buy Bitcoin", offerDetailsGridPane);
offerDetailsTitlePane.setCollapsible(false);
nextButton = new Button(processStepItems.get(0).getLabel());
nextButton.setDefaultButton(true);
nextButton.setOnAction(e -> trade());
GridPane contractGridPane = new GridPane();
contractGridPane.setVgap(5);
contractGridPane.setHgap(5);
contractGridPane.setPadding(new Insets(5, 5, 5, 5));
row = 0;
addHeaderLabel(contractGridPane, "Offer details:", row);
addLabel(contractGridPane, "Offer ID:", offer.getUid().toString(), ++row);
addLabel(contractGridPane, "Offer type:", Formatter.formatDirection((offer.getDirection() == Direction.BUY ? Direction.SELL : Direction.BUY), false), ++row);
amountLabel = addLabel(contractGridPane, "Amount:", Formatter.formatAmount(getAmount()), ++row);
volumeLabel = addLabel(contractGridPane, "Volume:", "", ++row);
setVolume();
addLabel(contractGridPane, "Price:", Formatter.formatPriceWithCurrencyPair(offer.getPrice(), offer.getCurrency()), ++row);
collateralLabel2 = addLabel(contractGridPane, "Collateral:", "", ++row);
setCollateral();
addLabel(contractGridPane, "Language:", Formatter.formatList(offerConstraints.getLanguages()), ++row);
addLabel(contractGridPane, "Arbitrator:", offerConstraints.getArbitrator(), ++row);
// addLabel(contractGridPane, "Identity verification:", Formatter.formatList(offerConstraints.getIdentityVerifications()), ++row);
addLabel(contractGridPane, "Bank transfer reference ID:", "Purchase xyz 01.04.2014", ++row);
addVSpacer(contractGridPane, ++row);
addHeaderLabel(contractGridPane, "Offerer data:", ++row);
addLabel(contractGridPane, "Account ID:", offerer.getAccountID(), ++row);
addLabel(contractGridPane, "Messaging ID:", offerer.getMessageID(), ++row);
addLabel(contractGridPane, "Country:", offerer.getCountry(), ++row);
offererPubKeyLabel = addLabel(contractGridPane, "Payment public key:", contract.getOffererPubKey(), ++row);
addLabel(contractGridPane, "Bank transfer type:", offerer.getBankDetails().getBankTransferType(), ++row);
offererAccountPrimaryID = addLabel(contractGridPane, "Bank account IBAN:", offerer.getBankDetails().getAccountPrimaryID(), ++row);
offererAccountSecondaryIDLabel = addLabel(contractGridPane, "Bank account BIC:", offerer.getBankDetails().getAccountSecondaryID(), ++row);
offererAccountHolderNameLabel = addLabel(contractGridPane, "Bank account holder:", offerer.getBankDetails().getAccountHolderName(), ++row);
addVSpacer(contractGridPane, ++row);
addHeaderLabel(contractGridPane, "Offer taker data:", ++row);
addLabel(contractGridPane, "Account ID:", taker.getAccountID(), ++row);
addLabel(contractGridPane, "Messaging ID:", taker.getMessageID(), ++row);
addLabel(contractGridPane, "Country:", taker.getCountry(), ++row);
addLabel(contractGridPane, "Payment public key:", contract.getTakerPubKey(), ++row);
addLabel(contractGridPane, "Bank transfer type:", taker.getBankDetails().getBankTransferType(), ++row);
addLabel(contractGridPane, "Bank account IBAN:", taker.getBankDetails().getAccountPrimaryID(), ++row);
addLabel(contractGridPane, "Bank account BIC:", taker.getBankDetails().getAccountSecondaryID(), ++row);
addLabel(contractGridPane, "Bank account holder:", taker.getBankDetails().getAccountHolderName(), ++row);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(contractGridPane);
contractTitlePane = new TitledPane("Contract", scrollPane);
contractTitlePane.setCollapsible(false);
AnchorPane.setLeftAnchor(contractTitlePane, 10.0);
AnchorPane.setRightAnchor(contractTitlePane, 10.0);
AnchorPane.setTopAnchor(contractTitlePane, 324.0);
AnchorPane.setBottomAnchor(contractTitlePane, 10.0);
vBox = new VBox();
AnchorPane.setLeftAnchor(vBox, 10.0);
AnchorPane.setRightAnchor(vBox, 10.0);
AnchorPane.setTopAnchor(vBox, 10.0);
vBox.setSpacing(10);
vBox.getChildren().addAll(processStepBar, new VSpacer(5), offerDetailsTitlePane, nextButton);
rootContainer.getChildren().addAll(vBox, contractTitlePane);
}
private Label addLabel(GridPane gridPane, String title, String value, int row)
{
gridPane.add(new Label(title), 0, row);
Label valueLabel = new Label(value);
gridPane.add(valueLabel, 1, row);
return valueLabel;
}
private void addHeaderLabel(GridPane gridPane, String title, int row)
{
Label headerLabel = new Label(title);
headerLabel.setId("form-header-text");
gridPane.add(headerLabel, 0, row);
}
private TextField addInputField(GridPane gridPane, String title, String value, int row)
{
gridPane.add(new Label(title), 0, row);
TextField textField = new TextField(value);
gridPane.add(textField, 1, row);
return textField;
}
private void addVSpacer(GridPane gridPane, int row)
{
gridPane.add(new VSpacer(10), 0, row);
}
private void setTotal()
{
totalLabel.setText(Formatter.formatVolume(getVolume()));
}
private void setVolume()
{
totalLabel.setText(Formatter.formatVolume(getVolume(), offer.getCurrency()));
}
private boolean takerIsSelling()
{
return offer.getDirection() == Direction.BUY;
}
private double getVolume()
{
return offer.getPrice() * Converter.convertToDouble(amountTextField.getText());
}
private double getAmount()
{
return requestedAmount > 0 ? requestedAmount : offer.getAmount();
}
private String getTotalToPay()
{
String result = "";
if (takerIsSelling())
{
double btcValue = Converter.convertToDouble(amountTextField.getText()) + BtcFormatter.satoshiToBTC(Fees.OFFER_CREATION_FEE) +
offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true);
}
else
{
double btcValue = BtcFormatter.satoshiToBTC(Fees.OFFER_CREATION_FEE) + offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true) + "\n" + Formatter.formatVolume(getVolume(), offer.getCurrency());
}
return result;
}
private String getTotalToReceive()
{
String result = "";
if (takerIsSelling())
{
double btcValue = offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true) + "\n" + Formatter.formatVolume(getVolume(), offer.getCurrency());
}
else
{
double btcValue = Converter.convertToDouble(amountTextField.getText()) +
offer.getOfferConstraints().getCollateral() * Converter.convertToDouble(amountTextField.getText());
result = Formatter.formatAmount(btcValue, true, true);
}
return result;
}
public void setCollateral()
{
String value = Formatter.formatCollateral(offer.getOfferConstraints().getCollateral(), Converter.convertToDouble(amountTextField.getText()));
collateralLabel1.setText(value);
collateralLabel2.setText(value);
}
}

View File

@ -1,6 +1,6 @@
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Manfred Karrer
Build-Jdk: 1.8.0
Main-Class: io.bitsquare.BitSquare
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Manfred Karrer
Build-Jdk: 1.8.0
Main-Class: io.bitsquare.BitSquare