diff --git a/src/main/java/fucoin/actions/join/ActionJoin.java b/src/main/java/fucoin/actions/join/ActionJoin.java index ba31e58344a8a26fb4162f6c6dd63d8357e55746..d3d44bc779fb73bec2d1c430ef54e181645050f4 100644 --- a/src/main/java/fucoin/actions/join/ActionJoin.java +++ b/src/main/java/fucoin/actions/join/ActionJoin.java @@ -15,6 +15,5 @@ public class ActionJoin extends ClientAction { aja.someNeighbors.putAll(node.getKnownNeighbors()); System.out.println("Answer to " + sender.path().name()); sender.tell(aja, self); - //node.addKnownNeighbor(sender.path().name(), sender); } } diff --git a/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransfer.java b/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransfer.java index 078318970b6f9ab0c92e5d932c2e51452916c6ae..7e7de88bf5a58168b49d67a333dedd266fe90cb7 100644 --- a/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransfer.java +++ b/src/main/java/fucoin/actions/transaction/ActionPrepareDistributedCommittedTransfer.java @@ -32,12 +32,6 @@ public class ActionPrepareDistributedCommittedTransfer extends Transaction { //sender have enough money && wallet.amounts.getOrDefault(source, 0) >= amount)); - if (granted) { - wallet.log("I do grant transaction."); - } else { - wallet.log("I do not grant."); - } - sender.tell(new ActionPrepareDistributedCommittedTransferAnswer(source, target, amount, timestamp, granted, id), self); } diff --git a/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java b/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java index 992a851db10c0378acf31ea26f6b93ed48b756d4..81a379ae96d0230c5fb3bfe4b7296d7ce75ba7ab 100644 --- a/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java +++ b/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java @@ -11,6 +11,10 @@ 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 JScrollPane logPane = new JScrollPane(txtLog); + public SuperVisorGuiControlImpl(SuperVisorImpl sv) { superVisor = sv; init(); @@ -19,31 +23,27 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { private void init() { //Show AWT window for runtime information frame = new JFrame("Server"); - frame.setLayout(new GridLayout(3, 2)); - frame.add(new Label("All Amounts:")); + JPanel contentPanel = new JPanel(); + contentPanel.setLayout(new GridLayout(2, 1)); //Init Amount Table and SuperVisorImpl JTable amountListView = new JTable(superVisor.getAmountTableModel()); - Label averageAmountLbl = new Label("Average Amounts:"); - frame.add(new JScrollPane(amountListView)); - frame.add(new Label("Average Amounts:")); - frame.add(averageAmountLbl); + contentPanel.add(new JScrollPane(amountListView)); + + contentPanel.add(logPane); - //Call update on supervisor - JButton updateBtn = new JButton("Update"); - updateBtn.addActionListener(e -> superVisor.updateValues()); - frame.add(updateBtn); + frame.add(contentPanel, BorderLayout.CENTER); //Exit Button and shutdown supervisor - JButton exitBtn = new JButton("exit"); + JButton exitBtn = new JButton("Stop Supervisor"); exitBtn.addActionListener(e -> { superVisor.exit(); frame.setVisible(false); frame.dispose(); }); - frame.add(exitBtn); - frame.setSize(200, 400); + frame.add(exitBtn, BorderLayout.PAGE_END); + frame.setSize(800, 600); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @@ -64,6 +64,12 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { 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); + //System.out.println(message); + SwingUtilities.invokeLater(() -> { + log.addElement(message); + + // auto scroll to the bottom + txtLog.ensureIndexIsVisible(log.size() - 1); + }); } } diff --git a/src/main/java/fucoin/wallet/WalletImpl.java b/src/main/java/fucoin/wallet/WalletImpl.java index c0fdf2cda5ec1256b53f7f95f6bc03411e67ec7b..1dfaf2c2b9ec10ae6e8725d5daf8d97d7e5a22e9 100644 --- a/src/main/java/fucoin/wallet/WalletImpl.java +++ b/src/main/java/fucoin/wallet/WalletImpl.java @@ -36,12 +36,10 @@ public class WalletImpl extends AbstractWallet { this.remoteSuperVisorActor = remoteSuperVisorActor; if(remoteSuperVisorActor == null){ - String path = JOptionPane.showInputDialog(null, "Enter a supervisor address: "); + String path = JOptionPane.showInputDialog(null, "Enter a neighbour node address: "); System.out.println(path); ActorSelection selection = getContext().actorSelection(path); - //this.setRemoteSuperVisorActor(selection.anchor()); selection.tell(new ActionJoin(), self()); - //selection.tell("Hallo!", self()); } } @@ -73,10 +71,6 @@ public class WalletImpl extends AbstractWallet { ((ClientAction) message).doAction(this); } - /*if (message instanceof ActionJoin){ - ((ActionJoin) message).doAction(this); - }*/ - } @Override