add default id

This commit is contained in:
Manfred Karrer 2014-06-11 11:14:58 +02:00
parent acfc79040b
commit 64f88a9ea2
13 changed files with 14 additions and 503 deletions

View file

@ -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;

View file

@ -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
{

View file

@ -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);
}
});
}
}

View file

@ -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<S, T> extends javafx.scene.control.TableColumn<S, T>
{
private final DoubleProperty percentageWidth = new SimpleDoubleProperty(0);
public PTableColumn()
{
tableViewProperty().addListener(new ChangeListener<TableView<S>>()
{
@Override
public void changed(ObservableValue<? extends TableView<S>> ov, TableView<S> t, TableView<S> 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));
}
}

View file

@ -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<OfferListItem> 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<String, OfferListItem> 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<Number160, Data> 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<TableColumn<String, OfferListItem>, TableCell<String, OfferListItem>>()
{
@Override
public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> directionColumn)
{
return new TableCell<String, OfferListItem>()
{
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<TableColumn<String, OfferListItem>, TableCell<String, OfferListItem>>()
{
@Override
public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> directionColumn)
{
return new TableCell<String, OfferListItem>()
{
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);
}
}
};
}
});
}
}

View file

@ -1,80 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:controller="io.bitsquare.gui.msg.MsgController" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0"
AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="Offer list" AnchorPane.leftAnchor="10" AnchorPane.topAnchor="15.0">
<font>
<Font name="System Bold" size="18.0"/>
</font>
</Label>
<ComboBox fx:id="currencyComboBox" onAction="#selectCurrency" prefWidth="100" AnchorPane.rightAnchor="405" AnchorPane.topAnchor="10.0"/>
<TableView fx:id="offerTable" prefHeight="200.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="405"
AnchorPane.topAnchor="40.0">
<columns>
<TableColumn text="Offer" fx:id="offerColumn" minWidth="120">
<cellValueFactory>
<PropertyValueFactory property="offer"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Peer PubKey" fx:id="pubKeyColumn" minWidth="80" prefWidth="80">
<cellValueFactory>
<PropertyValueFactory property="pubKey"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="" fx:id="removeOfferColumn" minWidth="80" sortable="false"/>
<TableColumn text="" fx:id="connectToPeerColumn" minWidth="80" sortable="false"/>
</columns>
</TableView>
<Label text="Chat with peer" AnchorPane.bottomAnchor="210.0" AnchorPane.leftAnchor="10.0">
<font>
<Font name="System Bold" size="18.0"/>
</font>
</Label>
<TextArea fx:id="chatTextArea" editable="false" prefHeight="160.0" AnchorPane.bottomAnchor="45.0" AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0"/>
<TextField fx:id="chatInputField" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="120.0"/>
<Button fx:id="sendButton" onAction="#sendChatMsg" disable="true" defaultButton="true" prefWidth="100.0" text="Send" AnchorPane.bottomAnchor="10.0"
AnchorPane.rightAnchor="10"/>
<GridPane hgap="5.0" prefWidth="385.0" vgap="5.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="40.0">
<VBox spacing="20" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label layoutX="418.0" text="Add new Offer" AnchorPane.topAnchor="10.0" GridPane.columnSpan="2" GridPane.halignment="LEFT"
GridPane.rowIndex="0">
<font>
<Font name="System Bold" size="18.0"/>
</font>
</Label>
<Label text="Peer ID:" GridPane.rowIndex="1"/>
<Label text="Currency:" GridPane.rowIndex="2"/>
<Label text="Offer data:" GridPane.rowIndex="3"/>
<TextField fx:id="peerIDTextField" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<TextField fx:id="currencyTextField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<TextField fx:id="offerDataTextField" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Button onAction="#publishOffer" text="Add Offer" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label id="headline-label" text="Message"/>
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0"/>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="ALWAYS"/>
</rowConstraints>
</GridPane>
</VBox>
</children>
</AnchorPane>

View file

@ -1,40 +0,0 @@
package io.bitsquare.gui.msg;
import java.io.Serializable;
/**
* Wrapper for observable properties used by orderbook table view
*/
public class OfferListItem implements Serializable
{
private static final long serialVersionUID = 7914481258209700131L;
private String _offer;
private String pubKey;
private String currency;
public OfferListItem(String offer, String pubKey, String currency)
{
_offer = offer;
this.pubKey = pubKey;
this.currency = currency;
}
public String getOffer()
{
return _offer;
}
public String getPubKey()
{
return pubKey;
}
public String getCurrency()
{
return currency;
}
}

View file

@ -38,7 +38,6 @@ public class TradeMessage implements Serializable
private String offererPubKey;
private String preparedOffererDepositTxAsHex;
private String payoutTxAsHex;
public TradeMessage(TradeMessageType type, String offerUID)

View file

@ -1,5 +1,6 @@
package io.bitsquare.trade.payment.process;
//TODO not used but let it for reference until all use cases are impl.
public class BuyOffererPaymentProcess extends PaymentProcess
{
public BuyOffererPaymentProcess()

View file

@ -1,5 +1,6 @@
package io.bitsquare.trade.payment.process;
//TODO not used but let it for reference until all use cases are impl.
public class BuyTakerPaymentProcess extends PaymentProcess
{

View file

@ -7,6 +7,7 @@ import io.bitsquare.msg.MessageFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//TODO not used but let it for reference until all use cases are impl.
public class PaymentProcess
{
private static final Logger log = LoggerFactory.getLogger(PaymentProcess.class);

View file

@ -1,5 +1,6 @@
package io.bitsquare.trade.payment.process;
//TODO not used but let it for reference until all use cases are impl.
public class SellOffererPaymentProcess extends PaymentProcess
{
public SellOffererPaymentProcess()

View file

@ -1,5 +1,6 @@
package io.bitsquare.trade.payment.process;
//TODO not used but let it for reference until all use cases are impl.
public class SellTakerPaymentProcess extends PaymentProcess
{
public SellTakerPaymentProcess()