Skip to content
Snippets Groups Projects
Commit 345c69b5 authored by Simon Könnecke's avatar Simon Könnecke
Browse files

#13 moved supervisor form to gui package, + typos

parent 9c09dff0
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
package fucoin.gui;
public interface SuperVisorGuiControl {
/**
* Call from SuperVisorImpl after poison pill or kill
*/
void onLeave();
}
package fucoin.gui;
import fucoin.supervisor.SuperVisorImpl;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
private SuperVisorImpl superVisor;
private JFrame frame;
public SuperVisorGuiControlImpl(SuperVisorImpl sv) {
superVisor = sv;
init();
}
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:"));
//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);
//Call update on supervisor
JButton updateBtn = new JButton("Update");
updateBtn.addActionListener(e -> superVisor.updateValues());
frame.add(updateBtn);
//Exit Button and shutdown supervisor
JButton exitBtn = new JButton("exit");
exitBtn.addActionListener(e -> {
superVisor.exit();
frame.setVisible(false);
frame.dispose();
});
frame.add(exitBtn);
frame.setSize(200, 400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
superVisor.exit();
}
});
}
@Override
public void onLeave() {
frame.dispose();
}
}
package fucoin.gui; package fucoin.gui;
public interface WalletController { public interface WalletControl {
void leave(); void leave();
void send(String address, int amount); void send(String address, int amount);
......
...@@ -3,11 +3,11 @@ package fucoin.gui; ...@@ -3,11 +3,11 @@ package fucoin.gui;
import fucoin.wallet.WalletImpl; import fucoin.wallet.WalletImpl;
public class WalletControllerImpl implements WalletController { public class WalletControlImpl implements WalletControl {
private WalletImpl wallet; private WalletImpl wallet;
public WalletControllerImpl(WalletImpl wallet) { public WalletControlImpl(WalletImpl wallet) {
this.wallet = wallet; this.wallet = wallet;
} }
......
package fucoin.gui; package fucoin.gui;
public interface WalletGuiController { public interface WalletGuiControl {
void setAddress(String address); void setAddress(String address);
void setAmount(int amount); void setAmount(int amount);
......
...@@ -5,7 +5,7 @@ import java.awt.*; ...@@ -5,7 +5,7 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.Enumeration; import java.util.Enumeration;
public class WalletGuiControllerImpl implements WalletGuiController { public class WalletGuiControlImpl implements WalletGuiControl {
private DefaultListModel<LogMessage> log = new DefaultListModel<>(); private DefaultListModel<LogMessage> log = new DefaultListModel<>();
...@@ -30,7 +30,7 @@ public class WalletGuiControllerImpl implements WalletGuiController { ...@@ -30,7 +30,7 @@ public class WalletGuiControllerImpl implements WalletGuiController {
private JScrollPane logPane = new JScrollPane(txtLog); private JScrollPane logPane = new JScrollPane(txtLog);
private JCheckBox showDebug; private JCheckBox showDebug;
public WalletGuiControllerImpl(WalletController walletControle) { public WalletGuiControlImpl(WalletControl walletControl) {
window.setSize(400, 600); window.setSize(400, 600);
window.setLayout(new GridLayout(3, 1)); window.setLayout(new GridLayout(3, 1));
...@@ -102,7 +102,7 @@ public class WalletGuiControllerImpl implements WalletGuiController { ...@@ -102,7 +102,7 @@ public class WalletGuiControllerImpl implements WalletGuiController {
window.setVisible(true); window.setVisible(true);
btnSend.addActionListener(e -> { btnSend.addActionListener(e -> {
walletControle.send(txtSendTo.getSelectedItem().toString(), walletControl.send(txtSendTo.getSelectedItem().toString(),
Integer.parseInt(txtSendAmount.getText())); Integer.parseInt(txtSendAmount.getText()));
}); });
...@@ -117,7 +117,7 @@ public class WalletGuiControllerImpl implements WalletGuiController { ...@@ -117,7 +117,7 @@ public class WalletGuiControllerImpl implements WalletGuiController {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
System.out.println("window closing"); System.out.println("window closing");
walletControle.leave(); walletControl.leave();
super.windowClosing(e); super.windowClosing(e);
} }
...@@ -125,7 +125,7 @@ public class WalletGuiControllerImpl implements WalletGuiController { ...@@ -125,7 +125,7 @@ public class WalletGuiControllerImpl implements WalletGuiController {
@Override @Override
public void windowClosed(WindowEvent e) { public void windowClosed(WindowEvent e) {
System.out.println("window closing"); System.out.println("window closing");
walletControle.leave(); walletControl.leave();
super.windowClosing(e); super.windowClosing(e);
} }
}); });
......
package fucoin.supervisor; package fucoin.supervisor;
import akka.japi.Creator; import akka.japi.Creator;
import fucoin.gui.SuperVisorGuiControl;
import fucoin.gui.SuperVisorGuiControlImpl;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
...@@ -13,36 +15,9 @@ public class SuperVisorCreator implements Creator<SuperVisorImpl> { ...@@ -13,36 +15,9 @@ public class SuperVisorCreator implements Creator<SuperVisorImpl> {
@Override @Override
public SuperVisorImpl create() throws Exception { public SuperVisorImpl create() throws Exception {
//Show AWT window for runtime information SuperVisorImpl sv = new SuperVisorImpl();
JFrame frame = new JFrame("Server"); SuperVisorGuiControl superVisorGuiControl = new SuperVisorGuiControlImpl(sv);
frame.setLayout(new GridLayout(3, 2)); sv.setGuiControl(superVisorGuiControl);
frame.add(new Label("All Amounts:"));
//Init Amount Table and SuperVisorImpl
AmountTableModel amountTableModel = new AmountTableModel();
SuperVisorImpl sv = new SuperVisorImpl(amountTableModel);
JTable amountListView = new JTable(amountTableModel);
Label averageAmountLbl = new Label("Average Amounts:");
frame.add(new JScrollPane(amountListView));
frame.add(new Label("Average Amounts:"));
frame.add(averageAmountLbl);
//Call update on supervisor
JButton updateBtn = new JButton("Update");
updateBtn.addActionListener(e -> sv.updateValues());
frame.add(updateBtn);
//Exit Button and shutdown supervisor
JButton exitBtn = new JButton("exit");
exitBtn.addActionListener(e -> {
sv.exit();
frame.setVisible(false);
});
frame.add(exitBtn);
frame.setSize(200, 400);
frame.setVisible(true);
return sv; return sv;
} }
......
package fucoin.supervisor; package fucoin.supervisor;
import akka.actor.Props; import akka.actor.Props;
import fucoin.wallet.AbstractNode;
import fucoin.actions.Action; import fucoin.actions.Action;
import fucoin.actions.persist.ActionInvokeUpdate; import fucoin.actions.persist.ActionInvokeUpdate;
import fucoin.actions.transaction.ActionGetAmountAnswer; import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.actions.transaction.SuperVisorAction; import fucoin.actions.transaction.SuperVisorAction;
import fucoin.gui.SuperVisorGuiControl;
import fucoin.wallet.AbstractNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -14,8 +15,21 @@ import java.util.Map; ...@@ -14,8 +15,21 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class SuperVisorImpl extends AbstractNode { public class SuperVisorImpl extends AbstractNode {
private AmountTableModel amountTableModel; private AmountTableModel amountTableModel;
private Map<Long, DistributedCommittedTransferRequest> requestQueue;
private SuperVisorGuiControl gui;
public SuperVisorImpl() {
this.amountTableModel = new AmountTableModel();
}
public void setGuiControl(SuperVisorGuiControl gui) {
this.gui = gui;
}
public SuperVisorImpl(AmountTableModel amountTableModel) { public SuperVisorImpl(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel; this.amountTableModel = amountTableModel;
} }
...@@ -28,14 +42,11 @@ public class SuperVisorImpl extends AbstractNode { ...@@ -28,14 +42,11 @@ public class SuperVisorImpl extends AbstractNode {
if (msg instanceof ActionGetAmountAnswer) { if (msg instanceof ActionGetAmountAnswer) {
ActionGetAmountAnswer answer = (ActionGetAmountAnswer) msg; ActionGetAmountAnswer answer = (ActionGetAmountAnswer) msg;
amountTableModel.updateTable(answer.address, answer.name, answer.amount); amountTableModel.updateTable(answer.address, answer.name, answer.amount);
} /* TODO: Whats happened here?? Why we can invoke doAction of abstract class? */ } /* TODO: Whats happened here?? Why we can invoke doAction of abstract class? */ else if (msg instanceof SuperVisorAction) {
else if (msg instanceof SuperVisorAction) {
((Action) msg).doAction(this); ((Action) msg).doAction(this);
} }
} }
private Map<Long, DistributedCommittedTransferRequest> requestQueue;
public static Props props() { public static Props props() {
return Props.create(new SuperVisorCreator()); return Props.create(new SuperVisorCreator());
} }
...@@ -46,6 +57,9 @@ public class SuperVisorImpl extends AbstractNode { ...@@ -46,6 +57,9 @@ public class SuperVisorImpl extends AbstractNode {
public void exit() { public void exit() {
getContext().stop(getSelf()); getContext().stop(getSelf());
if (gui != null) {
gui.onLeave();
}
} }
@Override @Override
...@@ -94,4 +108,12 @@ public class SuperVisorImpl extends AbstractNode { ...@@ -94,4 +108,12 @@ public class SuperVisorImpl extends AbstractNode {
public void deleteRequest(DistributedCommittedTransferRequest request) { public void deleteRequest(DistributedCommittedTransferRequest request) {
requestQueue.remove(request.getId()); requestQueue.remove(request.getId());
} }
public AmountTableModel getAmountTableModel() {
return amountTableModel;
}
public void setAmountTableModel(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel;
}
} }
package fucoin.wallet; package fucoin.wallet;
import fucoin.gui.WalletController; import fucoin.gui.WalletControl;
public interface Wallet extends WalletController { public interface Wallet extends WalletControl {
//Vector<WalletPointer> join(); //Vector<WalletPointer> join();
void storeOrUpdate(WalletImpl w); void storeOrUpdate(WalletImpl w);
......
...@@ -2,8 +2,7 @@ package fucoin.wallet; ...@@ -2,8 +2,7 @@ package fucoin.wallet;
import akka.actor.ActorRef; import akka.actor.ActorRef;
import akka.japi.Creator; import akka.japi.Creator;
import fucoin.gui.WalletGuiController; import fucoin.gui.WalletGuiControlImpl;
import fucoin.gui.WalletGuiControllerImpl;
public class WalletCreator implements Creator<AbstractWallet> { public class WalletCreator implements Creator<AbstractWallet> {
private ActorRef preKnownNeighbour; private ActorRef preKnownNeighbour;
...@@ -25,7 +24,7 @@ public class WalletCreator implements Creator<AbstractWallet> { ...@@ -25,7 +24,7 @@ public class WalletCreator implements Creator<AbstractWallet> {
WalletImpl wallet = new WalletImpl(preKnownNeighbour, preKnownNeighbourName, WalletImpl wallet = new WalletImpl(preKnownNeighbour, preKnownNeighbourName,
walletName, remoteSuperVisorActor); walletName, remoteSuperVisorActor);
WalletGuiControllerImpl gui = new WalletGuiControllerImpl(wallet); WalletGuiControlImpl gui = new WalletGuiControlImpl(wallet);
wallet.setGui(gui); wallet.setGui(gui);
return wallet; return wallet;
} }
......
...@@ -9,14 +9,14 @@ import fucoin.actions.persist.ActionInvokeLeave; ...@@ -9,14 +9,14 @@ import fucoin.actions.persist.ActionInvokeLeave;
import fucoin.actions.persist.ActionInvokeRevive; import fucoin.actions.persist.ActionInvokeRevive;
import fucoin.actions.transaction.ActionGetAmountAnswer; import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.actions.transaction.ActionInvokeSentMoney; import fucoin.actions.transaction.ActionInvokeSentMoney;
import fucoin.gui.WalletController; import fucoin.gui.WalletControl;
import fucoin.gui.WalletGuiController; import fucoin.gui.WalletGuiControl;
public class WalletImpl extends AbstractWallet implements WalletController { public class WalletImpl extends AbstractWallet implements WalletControl {
private ActorRef preKnownNeighbour; private ActorRef preKnownNeighbour;
private ActorRef remoteSuperVisorActor; private ActorRef remoteSuperVisorActor;
private WalletGuiController gui; private WalletGuiControl gui;
private String preKnownNeighbourName; private String preKnownNeighbourName;
private boolean isActive; private boolean isActive;
...@@ -134,11 +134,11 @@ public class WalletImpl extends AbstractWallet implements WalletController { ...@@ -134,11 +134,11 @@ public class WalletImpl extends AbstractWallet implements WalletController {
this.remoteSuperVisorActor = remoteSuperVisorActor; this.remoteSuperVisorActor = remoteSuperVisorActor;
} }
public WalletGuiController getGui() { public WalletGuiControl getGui() {
return gui; return gui;
} }
public void setGui(WalletGuiController gui) { public void setGui(WalletGuiControl gui) {
this.gui = gui; this.gui = gui;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment