Skip to content
Snippets Groups Projects
Unverified Commit d681cea7 authored by David Bohn's avatar David Bohn
Browse files

Prettified server GUI

parent e7eba789
Branches
No related tags found
1 merge request!3Preliminary result of the software
...@@ -15,6 +15,5 @@ public class ActionJoin extends ClientAction { ...@@ -15,6 +15,5 @@ public class ActionJoin extends ClientAction {
aja.someNeighbors.putAll(node.getKnownNeighbors()); aja.someNeighbors.putAll(node.getKnownNeighbors());
System.out.println("Answer to " + sender.path().name()); System.out.println("Answer to " + sender.path().name());
sender.tell(aja, self); sender.tell(aja, self);
//node.addKnownNeighbor(sender.path().name(), sender);
} }
} }
...@@ -32,12 +32,6 @@ public class ActionPrepareDistributedCommittedTransfer extends Transaction { ...@@ -32,12 +32,6 @@ public class ActionPrepareDistributedCommittedTransfer extends Transaction {
//sender have enough money //sender have enough money
&& wallet.amounts.getOrDefault(source, 0) >= amount)); && 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); sender.tell(new ActionPrepareDistributedCommittedTransferAnswer(source, target, amount, timestamp, granted, id), self);
} }
......
...@@ -11,6 +11,10 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { ...@@ -11,6 +11,10 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
private SuperVisorImpl superVisor; private SuperVisorImpl superVisor;
private JFrame frame; 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) { public SuperVisorGuiControlImpl(SuperVisorImpl sv) {
superVisor = sv; superVisor = sv;
init(); init();
...@@ -19,31 +23,27 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { ...@@ -19,31 +23,27 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
private void init() { private void init() {
//Show AWT window for runtime information //Show AWT window for runtime information
frame = new JFrame("Server"); frame = new JFrame("Server");
frame.setLayout(new GridLayout(3, 2)); JPanel contentPanel = new JPanel();
frame.add(new Label("All Amounts:")); contentPanel.setLayout(new GridLayout(2, 1));
//Init Amount Table and SuperVisorImpl //Init Amount Table and SuperVisorImpl
JTable amountListView = new JTable(superVisor.getAmountTableModel()); JTable amountListView = new JTable(superVisor.getAmountTableModel());
Label averageAmountLbl = new Label("Average Amounts:"); contentPanel.add(new JScrollPane(amountListView));
frame.add(new JScrollPane(amountListView));
frame.add(new Label("Average Amounts:")); contentPanel.add(logPane);
frame.add(averageAmountLbl);
//Call update on supervisor frame.add(contentPanel, BorderLayout.CENTER);
JButton updateBtn = new JButton("Update");
updateBtn.addActionListener(e -> superVisor.updateValues());
frame.add(updateBtn);
//Exit Button and shutdown supervisor //Exit Button and shutdown supervisor
JButton exitBtn = new JButton("exit"); JButton exitBtn = new JButton("Stop Supervisor");
exitBtn.addActionListener(e -> { exitBtn.addActionListener(e -> {
superVisor.exit(); superVisor.exit();
frame.setVisible(false); frame.setVisible(false);
frame.dispose(); frame.dispose();
}); });
frame.add(exitBtn); frame.add(exitBtn, BorderLayout.PAGE_END);
frame.setSize(200, 400); frame.setSize(800, 600);
frame.setVisible(true); frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
...@@ -64,6 +64,12 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { ...@@ -64,6 +64,12 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
public void log(String message) { public void log(String message) {
// One day, we may have a server log GUI as well.. // One day, we may have a server log GUI as well..
// Until then, we just print it to the console // 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);
});
} }
} }
...@@ -36,12 +36,10 @@ public class WalletImpl extends AbstractWallet { ...@@ -36,12 +36,10 @@ public class WalletImpl extends AbstractWallet {
this.remoteSuperVisorActor = remoteSuperVisorActor; this.remoteSuperVisorActor = remoteSuperVisorActor;
if(remoteSuperVisorActor == null){ 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); System.out.println(path);
ActorSelection selection = getContext().actorSelection(path); ActorSelection selection = getContext().actorSelection(path);
//this.setRemoteSuperVisorActor(selection.anchor());
selection.tell(new ActionJoin(), self()); selection.tell(new ActionJoin(), self());
//selection.tell("Hallo!", self());
} }
} }
...@@ -73,10 +71,6 @@ public class WalletImpl extends AbstractWallet { ...@@ -73,10 +71,6 @@ public class WalletImpl extends AbstractWallet {
((ClientAction) message).doAction(this); ((ClientAction) message).doAction(this);
} }
/*if (message instanceof ActionJoin){
((ActionJoin) message).doAction(this);
}*/
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment