diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index c063616bc6..9f6419d7aa 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -32,7 +32,7 @@ import java.util.Locale; public class BitSquare extends Application { private static final Logger log = LoggerFactory.getLogger(BitSquare.class); - public static String ID = ""; + public static String ID = "bitsquare"; private WalletFacade walletFacade; private MessageFacade messageFacade; diff --git a/src/main/java/io/bitsquare/crypto/CryptoFacade.java b/src/main/java/io/bitsquare/crypto/CryptoFacade.java index 18a6f5435b..13c0f82d2e 100644 --- a/src/main/java/io/bitsquare/crypto/CryptoFacade.java +++ b/src/main/java/io/bitsquare/crypto/CryptoFacade.java @@ -12,8 +12,6 @@ import java.util.UUID; /** * That facade delivers crypto functionality from the bitcoinJ library - * Code from BitcoinJ must not be used outside that facade. - * That way a change of the library will only affect that class. */ public class CryptoFacade { diff --git a/src/main/java/io/bitsquare/gui/components/BuySellSwitch.java b/src/main/java/io/bitsquare/gui/components/BuySellSwitch.java deleted file mode 100644 index 770be531f0..0000000000 --- a/src/main/java/io/bitsquare/gui/components/BuySellSwitch.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.bitsquare.gui.components; - -import javafx.event.ActionEvent; -import javafx.scene.control.ToggleButton; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; - -public class BuySellSwitch extends ToggleButton -{ - - private static Image buyIcon = new Image(BuySellSwitch.class.getResourceAsStream("/images/buy.png")); - private static Image sellIcon = new Image(BuySellSwitch.class.getResourceAsStream("/images/sell.png")); - - public BuySellSwitch(String label) - { - super(label); - - ImageView iconImageView = new ImageView(buyIcon); - //setClip(iconImageView); - setGraphic(iconImageView); - addEventHandler(ActionEvent.ACTION, e -> { - if (isSelected()) - { - - setText("SELL"); - iconImageView.setImage(sellIcon); - } - else - { - setText("BUY"); - iconImageView.setImage(buyIcon); - } - }); - } - - -} diff --git a/src/main/java/io/bitsquare/gui/components/PTableColumn.java b/src/main/java/io/bitsquare/gui/components/PTableColumn.java deleted file mode 100644 index 163c41f0a9..0000000000 --- a/src/main/java/io/bitsquare/gui/components/PTableColumn.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.bitsquare.gui.components; - -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.scene.control.TableView; - -/** - * This class allows to specify a percentage for the width of the column of a - * TableView. - * - * @author twasyl - */ -public class PTableColumn extends javafx.scene.control.TableColumn -{ - - private final DoubleProperty percentageWidth = new SimpleDoubleProperty(0); - - public PTableColumn() - { - tableViewProperty().addListener(new ChangeListener>() - { - - @Override - public void changed(ObservableValue> ov, TableView t, TableView t1) - { - if (PTableColumn.this.prefWidthProperty().isBound()) - { - PTableColumn.this.prefWidthProperty().unbind(); - } - if (percentageWidth.get() != 0) - { - PTableColumn.this.prefWidthProperty().bind(t1.widthProperty().multiply(percentageWidth)); - } - else - { - double tempPercentageWidthLeft = 1; - for (int i = 0; i < t1.getColumns().size(); i++) - { - tempPercentageWidthLeft -= ((PTableColumn) t1.getColumns().get(i)).getPercentageWidth(); - } - PTableColumn.this.prefWidthProperty().bind(t1.widthProperty().multiply(tempPercentageWidthLeft)); - } - } - }); - } - - public final DoubleProperty percentageWidthProperty() - { - return percentageWidth; - } - - public final double getPercentageWidth() - { - return this.percentageWidthProperty().get(); - } - - public final void setPercentageWidth(double value) throws IllegalArgumentException - { - if (value >= 0 && value <= 1) - this.percentageWidthProperty().set(value); - else - throw new IllegalArgumentException(String.format("The provided percentage width is not between 0.0 and 1.0. Value is: %1$s", value)); - } -} diff --git a/src/main/java/io/bitsquare/gui/msg/MsgController.java b/src/main/java/io/bitsquare/gui/msg/MsgController.java index 9a72e499fb..c687cf949a 100644 --- a/src/main/java/io/bitsquare/gui/msg/MsgController.java +++ b/src/main/java/io/bitsquare/gui/msg/MsgController.java @@ -1,65 +1,27 @@ package io.bitsquare.gui.msg; import com.google.inject.Inject; -import io.bitsquare.BitSquare; import io.bitsquare.gui.ChildController; import io.bitsquare.gui.NavigationController; -import io.bitsquare.msg.MessageFacade; -import io.bitsquare.msg.listeners.OrderBookListener; -import io.bitsquare.msg.listeners.PingPeerListener; -import javafx.beans.property.ReadOnlyObjectWrapper; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.util.Callback; -import net.tomp2p.peers.Number160; -import net.tomp2p.storage.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; import java.util.ResourceBundle; -public class MsgController implements Initializable, ChildController, OrderBookListener, PingPeerListener +public class MsgController implements Initializable, ChildController { private static final Logger log = LoggerFactory.getLogger(MsgController.class); - private MessageFacade messageFacade; - private String selectedCurrency; - private ObservableList offerList = FXCollections.observableArrayList(); - private int selectedIndex; - private String myID, otherID; - private boolean pingPending; - - @FXML - public ComboBox currencyComboBox; - @FXML - public Button sendButton; - @FXML - public TextArea chatTextArea; - @FXML - public TextField chatInputField, peerIDTextField, currencyTextField, offerDataTextField; - @FXML - public TableView offerTable; - @FXML - public TableColumn connectToPeerColumn, removeOfferColumn, offerColumn; - /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public MsgController(MessageFacade messageFacade) + public MsgController() { - this.messageFacade = messageFacade; } @@ -70,113 +32,6 @@ public class MsgController implements Initializable, ChildController, OrderBookL @Override public void initialize(URL url, ResourceBundle rb) { - myID = BitSquare.ID; - otherID = BitSquare.ID.equals("taker") ? "offerer" : "taker"; - - messageFacade.addMessageListener(this); - - peerIDTextField.setText(myID); - currencyTextField.setText("EUR"); - offerDataTextField.setText(myID + " serialized offer object"); - - selectedCurrency = currencyTextField.getText(); - - currencyComboBox.setItems(FXCollections.observableArrayList(new ArrayList<>(Arrays.asList("EUR", "USD", "CHF")))); - currencyComboBox.getSelectionModel().select(0); - - setupConnectToPeerOfferColumn(); - setupRemoveOfferColumn(); - offerTable.setItems(offerList); - offerTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Interface implementation: MessageListener - /////////////////////////////////////////////////////////////////////////////////////////// - - /* @Override - public void onMessage(Object message) - { - sendButton.setDisable(!messageFacade.isOtherPeerDefined()); - - if (message instanceof String) - chatTextArea.appendText("\n" + otherID + ": " + message); - } */ - - @Override - public void onPing() - { - sendChatMsg(MessageFacade.PONG); - } - - @Override - public void onOfferAdded(Data offerData, boolean success) - { - if (success) - getOffers(); - else - log.warn("onOfferAdded returned false"); - } - - @Override - public void onOffersReceived(Map dataMap, boolean success) - { - if (success && dataMap != null) - { - offerList.clear(); - for (Data offerData : dataMap.values()) - { - try - { - Object offerDataObject = offerData.getObject(); - if (offerDataObject instanceof OfferListItem && offerDataObject != null) - offerList.add((OfferListItem) offerDataObject); - } catch (ClassNotFoundException | IOException e) - { - e.printStackTrace(); - } - } - } - else - { - offerList.clear(); - } - } - - - @Override - public void onOfferRemoved(Data offerData, boolean success) - { - if (success) - getOffers(); - else - log.warn("onOfferRemoved failed"); - } - - /* @Override - public void onResponseFromSend(Object response) - { - String msg = (response instanceof String) ? (String) response : null; - if (msg != null) - { - chatTextArea.appendText("\n" + otherID + ": " + msg); - offerTable.getSelectionModel().select(selectedIndex); - } - } - - @Override - public void onSendFailed() - { - offerTable.getSelectionModel().clearSelection(); - } */ - - @Override - public void onPingPeerResult(boolean success) - { - /* sendButton.setDisable(!messageFacade.isOtherPeerDefined()); - if (pingPending) - sendChatMsg(MessageFacade.PING); */ } @@ -192,157 +47,17 @@ public class MsgController implements Initializable, ChildController, OrderBookL @Override public void cleanup() { - messageFacade.removeMessageListener(this); } /////////////////////////////////////////////////////////////////////////////////////////// // GUI Event handlers /////////////////////////////////////////////////////////////////////////////////////////// - @FXML - public void publishOffer(ActionEvent actionEvent) - { - /* OfferListItem offerListItem = new OfferListItem(offerDataTextField.getText(), messageFacade.getPubKeyAsHex(), currencyTextField.getText()); - try - { - messageFacade.addOffer(currencyTextField.getText(), offerListItem); - } catch (IOException e) - { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } */ - } - - @FXML - public void selectCurrency(ActionEvent actionEvent) - { - selectedCurrency = currencyComboBox.getSelectionModel().getSelectedItem().toString(); - getOffers(); - } - - @FXML - public void sendChatMsg(ActionEvent actionEvent) - { - sendChatMsg(chatInputField.getText()); - } - /////////////////////////////////////////////////////////////////////////////////////////// // Private Methods /////////////////////////////////////////////////////////////////////////////////////////// - private void inviteForChat(OfferListItem item, int index) - { - selectedIndex = index; - // messageFacade.pingPeer(item.getPubKey()); - pingPending = true; - - } - - private void sendChatMsg(String msg) - { - // messageFacade.sendMessage(msg); - - chatTextArea.appendText("\n" + myID + ": " + msg); - chatInputField.setText(""); - } - - private void getOffers() - { - messageFacade.getOffers(selectedCurrency); - } - - private void removeOffer(OfferListItem offer) - { - /* try - { - messageFacade.removeOffer(offer); - } catch (IOException e) - { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } */ - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Columns - /////////////////////////////////////////////////////////////////////////////////////////// - - private void setupRemoveOfferColumn() - { - removeOfferColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue())); - removeOfferColumn.setCellFactory(new Callback, TableCell>() - { - @Override - public TableCell call(TableColumn directionColumn) - { - return new TableCell() - { - final Button button = new Button(); - - { - button.setMinWidth(70); - } - - @Override - public void updateItem(final OfferListItem item, boolean empty) - { - super.updateItem(item, empty); - - if (item != null) - { - button.setText("Remove"); - setGraphic(button); - - button.setOnAction(event -> removeOffer(item)); - } - else - { - setGraphic(null); - } - } - }; - } - }); - } - - private void setupConnectToPeerOfferColumn() - { - connectToPeerColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue())); - connectToPeerColumn.setCellFactory(new Callback, TableCell>() - { - @Override - public TableCell call(TableColumn directionColumn) - { - return new TableCell() - { - final Button button = new Button(); - - { - button.setMinWidth(70); - } - - @Override - public void updateItem(OfferListItem item, boolean empty) - { - super.updateItem(item, empty); - - if (item != null) - { - button.setText("Chat"); - setGraphic(button); - - - button.setOnAction(event -> inviteForChat(item, getIndex())); - } - else - { - setGraphic(null); - } - } - }; - } - }); - } } diff --git a/src/main/java/io/bitsquare/gui/msg/MsgView.fxml b/src/main/java/io/bitsquare/gui/msg/MsgView.fxml index f8bf7197b2..52b05292be 100644 --- a/src/main/java/io/bitsquare/gui/msg/MsgView.fxml +++ b/src/main/java/io/bitsquare/gui/msg/MsgView.fxml @@ -1,80 +1,17 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - -