From d681cea7614e9efb802e2f1bd565c3f04c948d27 Mon Sep 17 00:00:00 2001
From: David Bohn <david@cancrisoft.net>
Date: Tue, 14 Jun 2016 15:59:31 +0200
Subject: [PATCH] Prettified server GUI

---
 .../java/fucoin/actions/join/ActionJoin.java  |  1 -
 ...onPrepareDistributedCommittedTransfer.java |  6 ----
 .../fucoin/gui/SuperVisorGuiControlImpl.java  | 34 +++++++++++--------
 src/main/java/fucoin/wallet/WalletImpl.java   |  8 +----
 4 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/src/main/java/fucoin/actions/join/ActionJoin.java b/src/main/java/fucoin/actions/join/ActionJoin.java
index ba31e58..d3d44bc 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 0783189..7e7de88 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 992a851..81a379a 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 c0fdf2c..1dfaf2c 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
-- 
GitLab