diff --git a/src/main/java/Example.java b/src/main/java/Example.java new file mode 100644 index 0000000000000000000000000000000000000000..13a1d6603f0d2aabf606b4978bdce8fc3f67fad8 --- /dev/null +++ b/src/main/java/Example.java @@ -0,0 +1,84 @@ +import java.awt.event.*; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.*; + +@SuppressWarnings("serial") +public class Example extends JFrame { + public Example() { + super(); + OuterView theGUI = new OuterView(); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setResizable(false); + add(theGUI); + pack(); + setVisible(true); + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new Example(); + } + }); + } +} + +class OuterView extends JPanel { + private String innerValue = ""; + + public OuterView() { + super(); + InnerView innerPanel = new InnerView(); + innerPanel.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(InnerView.COMBO_CHANGED)) { + innerValue = evt.getNewValue().toString(); + System.out.println("new value from inside of OuterView: " + + innerValue); + } + } + }); + JButton button = new JButton("display OuterView's model"); + button.addActionListener(new ButtonListener()); + add(innerPanel); + add(button); + } + + private class ButtonListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent ae) { + System.out.println("button was clicked. innerValue: " + innerValue); + } + } +} + +class InnerView extends JPanel { + public static final String COMBO_CHANGED = "Combo Changed"; + // private SwingPropertyChangeSupport pcSupport = new + // SwingPropertyChangeSupport(this); + String oldValue = ""; + + public InnerView() { + super(); + String[] items = new String[] { "item 1", "item 2", "item 3" }; + JComboBox comboBox = new JComboBox(items); + comboBox.addActionListener(new ComboBoxListener()); + add(comboBox); + + } + + private class ComboBoxListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent ae) { + String text = ((JComboBox) ae.getSource()).getSelectedItem() + .toString(); + firePropertyChange(COMBO_CHANGED, oldValue, text); + oldValue = text; + System.out.println("store " + text + " in InnerView's model"); + } + } +} \ No newline at end of file diff --git a/src/main/java/fucoin/AbstractNode.java b/src/main/java/fucoin/AbstractNode.java index 437262c5c1f4f7472674e58e445abb1104136d56..9777980aa3f1880b274b162f251bf001d5cb61ef 100644 --- a/src/main/java/fucoin/AbstractNode.java +++ b/src/main/java/fucoin/AbstractNode.java @@ -68,9 +68,4 @@ public abstract class AbstractNode extends UntypedActor implements Serializable public HashMap<String, ActorRef> getKnownNeighbors() { return knownNeighbors; } - - public void log(String string) { - System.out.println(getSelf().path().name() + ": " + string); - } - } \ No newline at end of file diff --git a/src/main/java/fucoin/actions/join/ActionJoinAnswer.java b/src/main/java/fucoin/actions/join/ActionJoinAnswer.java index 49cecf1d89a416a85ed8c6749cdfa841da57d232..e20bbcc5b94d11d920a0200d6166467328dff701 100644 --- a/src/main/java/fucoin/actions/join/ActionJoinAnswer.java +++ b/src/main/java/fucoin/actions/join/ActionJoinAnswer.java @@ -29,7 +29,7 @@ public class ActionJoinAnswer extends ClientAction { protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet wallet) { - wallet.log("Addressed to " + self.path().name() + " from " + sender.path().name() + ": someNeighbors:" + someNeighbors); + wallet.addLogMsg("Addressed to " + self.path().name() + " from " + sender.path().name() + ": someNeighbors:" + someNeighbors); // your neighbours? my neighbours! for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) { diff --git a/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java b/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java index fe514e2802102260c18970ab58ce7e85f2e40324..9d0727acf966413757518c861ea2870ea7a67b22 100644 --- a/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java +++ b/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java @@ -23,7 +23,7 @@ public class ActionSearchWalletReference extends Search { @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet wallet) { - wallet.log(wallet.getKnownNeighbors() + "contains " + name + "?"); + wallet.addLogMsg(wallet.getKnownNeighbors() + "contains " + name + "?"); ttl.add(self); ActionSearchWalletReferenceAnswer answer = null; if (this.name.equals(wallet.getName())) { diff --git a/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java b/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java index 884c132f99f58f41c58ce6de15df90ca162fbfec..6cddc6da712d9731cb37569131fefda2120d7a8e 100644 --- a/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java +++ b/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java @@ -39,7 +39,7 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet wallet) { - wallet.log("ActionCommitDistributedCommittedTransfer is granted? " + granted); + wallet.addLogMsg("ActionCommitDistributedCommittedTransfer is granted? " + granted); if (granted) { Integer sourceAmount = wallet.amounts.getOrDefault(source, 0); @@ -49,21 +49,21 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { if (source.compareTo(self) == 0) { wallet.setAmount(wallet.getAmount() - amount); - wallet.logTransactionSuccess("Sent " + amount + " FUC to " + target.path().name()); + wallet.addTransactionLogMessageSuccess("Sent " + amount + " FUC to " + target.path().name()); } else if (target.compareTo(self) == 0) { wallet.setAmount(wallet.getAmount() + amount); - wallet.logTransactionSuccess("Received " + amount + " FUC from " + source.path().name()); + wallet.addTransactionLogMessageSuccess("Received " + amount + " FUC from " + source.path().name()); } } else { - wallet.log("abort transaction with id" + id); + wallet.addLogMsg("abort transaction with id" + id); if (source.compareTo(self) == 0) { - wallet.logTransactionFail("Failed to send " + amount + " FUC to " + target.path().name() + " (Commit has not been granted)"); + wallet.addTransactionLogMessageFail("Failed to send " + amount + " FUC to " + target.path().name() + " (Commit has not been granted)"); } } - wallet.log("wallet.amounts:" + wallet.amounts); + wallet.addLogMsg("wallet.amounts:" + wallet.amounts); } } diff --git a/src/main/java/fucoin/actions/transaction/ActionInvokeDistributedCommittedTransfer.java b/src/main/java/fucoin/actions/transaction/ActionInvokeDistributedCommittedTransfer.java index f3bf02db907f58dbe852398313c0bbc1e3cbbbd3..13f2ca11b0663cf70685086579966e1ae21e0ef2 100644 --- a/src/main/java/fucoin/actions/transaction/ActionInvokeDistributedCommittedTransfer.java +++ b/src/main/java/fucoin/actions/transaction/ActionInvokeDistributedCommittedTransfer.java @@ -21,7 +21,7 @@ public class ActionInvokeDistributedCommittedTransfer extends CoordinatorTransac @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, SuperVisorImpl superVisor) { - superVisor.log("invoke transaction " + source.path().name() + + superVisor.addLogMsg("invoke transaction " + source.path().name() + " sends " + amount + " to " + target.path().name()); diff --git a/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java b/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java index 6f3bd3e2817b47e8d3df213f150fa45a5efe04bf..0327d8c05394d2272c0aa16ed0bd338619969086 100644 --- a/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java +++ b/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java @@ -18,7 +18,7 @@ public class ActionInvokeSentMoney extends Transaction { @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet wallet) { - wallet.log(wallet.getKnownNeighbors() + ""); + wallet.addLogMsg(wallet.getKnownNeighbors() + ""); if (wallet.getKnownNeighbors().containsKey(name)) { wallet.getRemoteSuperVisorActor().tell( new ActionInvokeDistributedCommittedTransfer(self, wallet.getKnownNeighbors().get(name), amount), sender); diff --git a/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransferAnswer.java b/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransferAnswer.java index 3d2a0c094016678fe8d9ec18d64fed148be73eaa..658b149c89558c17b5d803c3e6edcc93e4479332 100644 --- a/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransferAnswer.java +++ b/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransferAnswer.java @@ -27,8 +27,8 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, SuperVisorImpl superVisor) { - superVisor.log("" + superVisor.getKnownNeighbors()); - superVisor.log("granted?" + granted); + superVisor.addLogMsg("" + superVisor.getKnownNeighbors()); + superVisor.addLogMsg("granted?" + granted); DistributedCommittedTransferRequest request = superVisor.getRequest(id); if (granted) { if (request == null)//unknown DistributedCommittedTransferRequest ignore @@ -37,6 +37,7 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator if (newCount == superVisor.getKnownNeighbors().size()) { ActionCommitDistributedCommittedTransfer acdct = new ActionCommitDistributedCommittedTransfer(source, target, amount, true, timestamp, id); + superVisor.addTransactionLogMessageSuccess("Transfer of " + amount + " FUC from" + source.path().name() + " to " + target.path().name()); for (ActorRef neighbor : request.getAnswers()) { neighbor.tell(acdct, self); } @@ -45,7 +46,7 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator } else { //A client wants to rollback if (request != null) { - superVisor.log("Client does not grant commit of " + amount + " FUC (" + source.path().name() + " -> " + target.path().name() + ")"); + superVisor.addTransactionLogMessageFail("Client does not grant commit of " + amount + " FUC (" + source.path().name() + " -> " + target.path().name() + ")"); ActionCommitDistributedCommittedTransfer acdct = new ActionCommitDistributedCommittedTransfer(source, target, amount, false, timestamp, id); for (ActorRef neighbor : request.getAnswers()) { neighbor.tell(acdct, self); diff --git a/src/main/java/fucoin/gui/FilteredLogModel.java b/src/main/java/fucoin/gui/FilteredLogModel.java new file mode 100644 index 0000000000000000000000000000000000000000..501c88353ca1528aefd05cc1e424172b0a500c72 --- /dev/null +++ b/src/main/java/fucoin/gui/FilteredLogModel.java @@ -0,0 +1,60 @@ +package fucoin.gui; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + + +public class FilteredLogModel extends AbstractListModel<LogMessage> { + + private List<LogMessage> log; + private List<LogMessage> filteredLog; + + private boolean filterTransactions = false; + + public FilteredLogModel() { + super(); + this. + log = new ArrayList<>(); + filteredLog = new ArrayList<>(); + } + + public void setTransactionFilter() { + filterTransactions = true; + refilter(); + } + + public void clearFilter(){ + filterTransactions = false; + refilter(); + } + + private void refilter() { + filteredLog.clear(); + for (LogMessage msg : log) { + if (!filterTransactions + || (msg.getContext() == LogMessage.Context.TRANSACTION_SUCCESS + || msg.getContext() == LogMessage.Context.TRANSACTION_FAIL)) { + filteredLog.add(msg); + + } + } + fireContentsChanged(this, 0, getSize()-1); + } + + @Override + public int getSize() { + return filteredLog.size(); + } + + @Override + public LogMessage getElementAt(int index) { + return filteredLog.get(index); + } + + + public void addElement(LogMessage message) { + log.add(message); + refilter(); + } +} diff --git a/src/main/java/fucoin/gui/LogCellRenderer.java b/src/main/java/fucoin/gui/LogCellRenderer.java index 5087daec62868bb8cfd661da6f56a049fcfd4ca0..1f787a5988f8622a589391af95d174453a279d05 100644 --- a/src/main/java/fucoin/gui/LogCellRenderer.java +++ b/src/main/java/fucoin/gui/LogCellRenderer.java @@ -28,7 +28,7 @@ public class LogCellRenderer extends DefaultListCellRenderer { } } - if(isSelected){ + if (isSelected) { setForeground(Color.WHITE); } diff --git a/src/main/java/fucoin/gui/SuperVisorGuiControl.java b/src/main/java/fucoin/gui/SuperVisorGuiControl.java index bea5e7ae5004ddbd003beb1b5fe82dbbdb3620b1..1d6919d6bf0004ee4d1ac9ea3a3f80df16b989a4 100644 --- a/src/main/java/fucoin/gui/SuperVisorGuiControl.java +++ b/src/main/java/fucoin/gui/SuperVisorGuiControl.java @@ -1,10 +1,10 @@ package fucoin.gui; -public interface SuperVisorGuiControl { +public interface SuperVisorGuiControl extends TransactionLogger { + /** * Call from SuperVisorImpl after poison pill or kill */ void onLeave(); - void log(String message); } diff --git a/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java b/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java index 81a379ae96d0230c5fb3bfe4b7296d7ce75ba7ab..91efa95707f4f852e70987b21d5929a4ee51f970 100644 --- a/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java +++ b/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java @@ -4,16 +4,20 @@ import fucoin.supervisor.SuperVisorImpl; import javax.swing.*; import java.awt.*; +import java.awt.event.ItemEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { private SuperVisorImpl superVisor; private JFrame frame; - private DefaultListModel<String> log = new DefaultListModel<>(); - private JList<String> txtLog = new JList<>(log); + private FilteredLogModel log = new FilteredLogModel(); + private JList<LogMessage> txtLog = new JList<>(log); private JScrollPane logPane = new JScrollPane(txtLog); + private JCheckBox showDebug; public SuperVisorGuiControlImpl(SuperVisorImpl sv) { superVisor = sv; @@ -31,7 +35,23 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { JTable amountListView = new JTable(superVisor.getAmountTableModel()); contentPanel.add(new JScrollPane(amountListView)); - contentPanel.add(logPane); + JPanel logPanel = new JPanel(new BorderLayout()); + + txtLog.setCellRenderer(new LogCellRenderer()); + + showDebug = new JCheckBox("Show debug messages in transaction log"); + showDebug.setSelected(true); + showDebug.addItemListener(e -> { + if (e.getStateChange() == ItemEvent.SELECTED) { + log.clearFilter(); + } else { + log.setTransactionFilter(); + } + }); + + logPanel.add(showDebug, BorderLayout.NORTH); + logPanel.add(logPane, BorderLayout.CENTER); + contentPanel.add(logPanel); frame.add(contentPanel, BorderLayout.CENTER); @@ -60,16 +80,27 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { frame.dispose(); } - @Override - public void log(String message) { - // One day, we may have a server log GUI as well.. - // Until then, we just print it to the console - //System.out.println(message); + private void log(LogMessage logMessage) { SwingUtilities.invokeLater(() -> { - log.addElement(message); + log.addElement(logMessage); // auto scroll to the bottom - txtLog.ensureIndexIsVisible(log.size() - 1); + txtLog.ensureIndexIsVisible(log.getSize() - 1); }); } + + @Override + public void addLogMsg(String msg) { + log(new LogMessage(msg)); + } + + @Override + public void addTransactionLogMessageSuccess(String message) { + log(new LogMessage(message, LogMessage.Context.TRANSACTION_SUCCESS)); + } + + @Override + public void addTransactionLogMessageFail(String message) { + log(new LogMessage(message, LogMessage.Context.TRANSACTION_FAIL)); + } } diff --git a/src/main/java/fucoin/gui/TransactionLogger.java b/src/main/java/fucoin/gui/TransactionLogger.java new file mode 100644 index 0000000000000000000000000000000000000000..4a3a00db665abdf4075f93a854a7a208afa516dd --- /dev/null +++ b/src/main/java/fucoin/gui/TransactionLogger.java @@ -0,0 +1,25 @@ +package fucoin.gui; + +/** + * All nodes implementing some kind of logging should implement this interface. + */ +public interface TransactionLogger { + + /** + * Adds a debug log message or a generic log message to the log + * @param message + */ + public void addLogMsg(String message); + + /** + * Adds a log message concerning a successful transaction + * @param message + */ + public void addTransactionLogMessageSuccess(String message); + + /** + * Adds a log message concerning a failed transaction + * @param message + */ + public void addTransactionLogMessageFail(String message); +} diff --git a/src/main/java/fucoin/gui/WalletGuiControl.java b/src/main/java/fucoin/gui/WalletGuiControl.java index 90bdbdb4e43b6d8fe346d0ebce46996304200696..301e22dcfb142234ee8053aa0e77e2b374169757 100644 --- a/src/main/java/fucoin/gui/WalletGuiControl.java +++ b/src/main/java/fucoin/gui/WalletGuiControl.java @@ -1,19 +1,13 @@ package fucoin.gui; -public interface WalletGuiControl { +public interface WalletGuiControl extends TransactionLogger { void setAddress(String address); void setAmount(int amount); void addKnownAddress(String address); - void addLogMsg(String msg); - - void addTransactionLogMessageSuccess(String message); - - void addTransactionLogMessageFail(String message); - /** * Tell the GUI, that the wallet is a remote wallet. */ diff --git a/src/main/java/fucoin/gui/WalletGuiControlImpl.java b/src/main/java/fucoin/gui/WalletGuiControlImpl.java index 2a2e008f3ba57d8e55cf49c6597acba091220366..49c69b9408d320ac404f5194b4e856c50c80c480 100644 --- a/src/main/java/fucoin/gui/WalletGuiControlImpl.java +++ b/src/main/java/fucoin/gui/WalletGuiControlImpl.java @@ -10,7 +10,7 @@ import java.util.Enumeration; public class WalletGuiControlImpl implements WalletGuiControl { - private DefaultListModel<LogMessage> log = new DefaultListModel<>(); + private FilteredLogModel log = new FilteredLogModel(); private JFrame window = new JFrame("test"); private JPanel topPanel = new JPanel(); @@ -110,12 +110,14 @@ public class WalletGuiControlImpl implements WalletGuiControl { bottomPanel.setLayout(new BorderLayout()); + log.setTransactionFilter(); + showDebug = new JCheckBox("Show debug messages in transaction log"); showDebug.addItemListener(e -> { if (e.getStateChange() == ItemEvent.SELECTED) { - txtLog.setModel(log); + log.clearFilter(); } else { - updateFilteredLog(); + log.setTransactionFilter(); } }); @@ -222,27 +224,8 @@ public class WalletGuiControlImpl implements WalletGuiControl { SwingUtilities.invokeLater(() -> { log.addElement(logMessage); - if (!showDebug.isSelected()) { - updateFilteredLog(); - } - // auto scroll to the bottom - txtLog.ensureIndexIsVisible(log.size() - 1); + txtLog.ensureIndexIsVisible(log.getSize() - 1); }); } - - private void updateFilteredLog() { - - DefaultListModel<LogMessage> filteredLog = new DefaultListModel<>(); - Enumeration<LogMessage> elements = log.elements(); - while (elements.hasMoreElements()) { - LogMessage logMessage = elements.nextElement(); - LogMessage.Context context = logMessage.getContext(); - if (context == LogMessage.Context.TRANSACTION_FAIL || context == LogMessage.Context.TRANSACTION_SUCCESS) { - filteredLog.addElement(logMessage); - } - } - - txtLog.setModel(filteredLog); - } } diff --git a/src/main/java/fucoin/supervisor/SuperVisorImpl.java b/src/main/java/fucoin/supervisor/SuperVisorImpl.java index 1252f1c9c925c5e9e4fad02fcafd3c69ae2caebd..2333a97f635ba869eae7263d7e89fb018f3c1620 100644 --- a/src/main/java/fucoin/supervisor/SuperVisorImpl.java +++ b/src/main/java/fucoin/supervisor/SuperVisorImpl.java @@ -7,6 +7,7 @@ import fucoin.actions.transaction.ActionGetAmountAnswer; import fucoin.actions.transaction.SuperVisorAction; import fucoin.gui.SuperVisorGuiControl; import fucoin.AbstractNode; +import fucoin.gui.TransactionLogger; import java.util.ArrayList; import java.util.HashMap; @@ -14,7 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -public class SuperVisorImpl extends AbstractNode { +public class SuperVisorImpl extends AbstractNode implements TransactionLogger{ private AmountTableModel amountTableModel; @@ -116,9 +117,28 @@ public class SuperVisorImpl extends AbstractNode { this.amountTableModel = amountTableModel; } - public void log(String message) { - if (this.gui != null) { - this.gui.log(message); + @Override + public void addLogMsg(String message) { + if (gui != null) { + gui.addLogMsg(message); + } else { + System.out.println(message); + } + } + + @Override + public void addTransactionLogMessageSuccess(String message) { + if (gui != null) { + gui.addTransactionLogMessageSuccess(message); + } else { + System.out.println(message); + } + } + + @Override + public void addTransactionLogMessageFail(String message) { + if (gui != null) { + gui.addTransactionLogMessageFail(message); } else { System.out.println(message); } diff --git a/src/main/java/fucoin/wallet/AbstractWallet.java b/src/main/java/fucoin/wallet/AbstractWallet.java index bc44d051ec250a68db11f9e677b683f985a4c5b8..afcbcfa713ba847c372f63c91e8a5246aa399b11 100644 --- a/src/main/java/fucoin/wallet/AbstractWallet.java +++ b/src/main/java/fucoin/wallet/AbstractWallet.java @@ -2,13 +2,14 @@ package fucoin.wallet; import akka.actor.ActorRef; import fucoin.AbstractNode; +import fucoin.gui.TransactionLogger; import java.io.Serializable; /** * */ -public abstract class AbstractWallet extends AbstractNode implements Serializable { +public abstract class AbstractWallet extends AbstractNode implements Serializable, TransactionLogger { /** * Currently amount of this wallet @@ -94,20 +95,6 @@ public abstract class AbstractWallet extends AbstractNode implements Serializabl */ public abstract void setRemoteSuperVisorActor(ActorRef remoteSuperVisorActor); - /** - * Appends a message related to a successful transaction to the log - * - * @param msg - */ - public abstract void logTransactionSuccess(String msg); - - /** - * Appends a message related to a successful transaction to the log - * - * @param msg - */ - public abstract void logTransactionFail(String msg); - /** * Sends amount FUCs to the wallet with the address adress * diff --git a/src/main/java/fucoin/wallet/WalletImpl.java b/src/main/java/fucoin/wallet/WalletImpl.java index f35d620fb87a8629bb4238682c119e208b9158b2..4a46881a00a91a438392d84a0ea2b6228e0f2edf 100644 --- a/src/main/java/fucoin/wallet/WalletImpl.java +++ b/src/main/java/fucoin/wallet/WalletImpl.java @@ -43,7 +43,7 @@ public class WalletImpl extends AbstractWallet { */ public void addAmount(int amount) { setAmount(this.getAmount() + amount); - log(" My amount is now " + this.getAmount()); + addLogMsg(" My amount is now " + this.getAmount()); } @Override @@ -54,7 +54,7 @@ public class WalletImpl extends AbstractWallet { @Override public void onReceive(Object message) { - log(getSender().path().name() + " invokes " + getSelf().path().name() + " to do " + message.getClass().getSimpleName()); + addLogMsg(getSender().path().name() + " invokes " + getSelf().path().name() + " to do " + message.getClass().getSimpleName()); if (message instanceof ActionInvokeRevive) { ((ActionInvokeRevive) message).doAction(this); } @@ -161,25 +161,13 @@ public class WalletImpl extends AbstractWallet { this.gui = gui; } - public String getPreKnownNeighbourName() { - return preKnownNeighbourName; - } - - public void setPreKnownNeighbourName(String preKnownNeighbourName) { - this.preKnownNeighbourName = preKnownNeighbourName; - } - - public boolean isActive() { - return isActive; - } - public void setActive(boolean isActive) { this.isActive = isActive; } @Override public boolean addKnownNeighbor(String key, ActorRef value) { - log(key + " is newNeighbor of " + name + "?" + !getKnownNeighbors().containsKey(key)); + addLogMsg(key + " is newNeighbor of " + name + "?" + !getKnownNeighbors().containsKey(key)); if (getKnownNeighbors().containsKey(key) || key.equals(name)) { return false; } @@ -191,38 +179,34 @@ public class WalletImpl extends AbstractWallet { return newNeighbor; } + public void send(String address, int amount) { + getSelf().tell(new ActionInvokeSentMoney(address, amount), getSelf()); + } + @Override - public void log(String msg) { + public void addLogMsg(String message) { if (gui != null) { - gui.addLogMsg(msg); + gui.addLogMsg(message); } else { - System.out.println(msg); + System.out.println(message); } } - @Override - public void logTransactionSuccess(String msg) { + public void addTransactionLogMessageSuccess(String message) { if (gui != null) { - gui.addTransactionLogMessageSuccess(msg); + gui.addTransactionLogMessageSuccess(message); } else { - System.out.println(msg); + System.out.println(message); } } - @Override - public void logTransactionFail(String msg) { + public void addTransactionLogMessageFail(String message) { if (gui != null) { - gui.addTransactionLogMessageFail(msg); + gui.addTransactionLogMessageFail(message); } else { - System.out.println(msg); + System.out.println(message); } } - - @Override - public void send(String address, int amount) { - getSelf().tell(new ActionInvokeSentMoney(address, amount), getSelf()); - } - }