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

Fixed GUI lock explained in #17

parent 367694d4
No related branches found
No related tags found
1 merge request!5Configuration system
...@@ -63,7 +63,7 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { ...@@ -63,7 +63,7 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction {
} }
} }
wallet.addLogMsg("wallet.amounts:" + wallet.amounts); //wallet.addLogMsg("wallet.amounts:" + wallet.amounts);
} }
} }
...@@ -27,7 +27,7 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator ...@@ -27,7 +27,7 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator
@Override @Override
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, SuperVisorImpl superVisor) { UntypedActorContext context, SuperVisorImpl superVisor) {
superVisor.addLogMsg("" + superVisor.getKnownNeighbors()); //superVisor.addLogMsg("" + superVisor.getKnownNeighbors());
superVisor.addLogMsg("granted?" + granted); superVisor.addLogMsg("granted?" + granted);
DistributedCommittedTransferRequest request = superVisor.getRequest(id); DistributedCommittedTransferRequest request = superVisor.getRequest(id);
if (granted) { if (granted) {
......
...@@ -2,6 +2,7 @@ package fucoin.gui; ...@@ -2,6 +2,7 @@ package fucoin.gui;
import javax.swing.*; import javax.swing.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -66,4 +67,10 @@ public class FilteredLogModel extends AbstractListModel<LogMessage> { ...@@ -66,4 +67,10 @@ public class FilteredLogModel extends AbstractListModel<LogMessage> {
fireIntervalAdded(this, index, index); fireIntervalAdded(this, index, index);
} }
} }
public void emptyLog() {
log.removeAll(log);
filteredLog.removeAll(filteredLog);
refilter();
}
} }
...@@ -7,4 +7,6 @@ public interface SuperVisorGuiControl extends TransactionLogger { ...@@ -7,4 +7,6 @@ public interface SuperVisorGuiControl extends TransactionLogger {
*/ */
void onLeave(); void onLeave();
public void updateTable(String address, String name, int amount);
} }
package fucoin.gui; package fucoin.gui;
import fucoin.supervisor.AmountTableModel;
import fucoin.supervisor.SuperVisorImpl; import fucoin.supervisor.SuperVisorImpl;
import javax.swing.*; import javax.swing.*;
...@@ -12,12 +13,12 @@ import java.awt.event.WindowEvent; ...@@ -12,12 +13,12 @@ import java.awt.event.WindowEvent;
public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
private SuperVisorImpl superVisor; private SuperVisorImpl superVisor;
private JFrame frame;
private FilteredLogModel log = new FilteredLogModel(); private AmountTableModel amountTableModel;
private JList<LogMessage> txtLog = new JList<>(log);
private JScrollPane logPane = new JScrollPane(txtLog); private SuperVisorThreadGUI threadGUI;
private JCheckBox showDebug;
private boolean logActive = false;
public SuperVisorGuiControlImpl(SuperVisorImpl sv) { public SuperVisorGuiControlImpl(SuperVisorImpl sv) {
superVisor = sv; superVisor = sv;
...@@ -25,69 +26,32 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { ...@@ -25,69 +26,32 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
} }
private void init() { private void init() {
//Show AWT window for runtime information
frame = new JFrame("Server"); amountTableModel = new AmountTableModel();
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new GridLayout(2, 1)); threadGUI = new SuperVisorThreadGUI(this);
threadGUI.init();
//Init Amount Table and SuperVisorImpl
}
JTable amountListView = new JTable(superVisor.getAmountTableModel());
superVisor.getAmountTableModel().addTableModelListener(e -> SwingUtilities.invokeLater(() -> frame.setTitle("Server (" + superVisor.getAmountTableModel().getRowCount() + " Wallets)"))); public void guiTerminated() {
contentPanel.add(new JScrollPane(amountListView)); superVisor.exit();
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);
//Exit Button and shutdown supervisor
JButton exitBtn = new JButton("Stop Supervisor");
exitBtn.addActionListener(e -> {
superVisor.exit();
frame.setVisible(false);
frame.dispose();
});
frame.add(exitBtn, BorderLayout.PAGE_END);
frame.setSize(800, 600);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
superVisor.exit();
}
});
} }
@Override @Override
public void onLeave() { public void onLeave() {
frame.dispose(); threadGUI.dispose();
} }
private void log(LogMessage logMessage) { @Override
SwingUtilities.invokeLater(() -> { public void updateTable(String address, String name, int amount) {
log.addElement(logMessage); this.amountTableModel.updateTable(address, name, amount);
}
// auto scroll to the bottom private void log(LogMessage logMessage) {
txtLog.ensureIndexIsVisible(log.getSize() - 1); if (logActive) {
}); threadGUI.log(logMessage);
}
} }
@Override @Override
...@@ -104,4 +68,24 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { ...@@ -104,4 +68,24 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
public void addTransactionLogMessageFail(String message) { public void addTransactionLogMessageFail(String message) {
log(new LogMessage(message, LogMessage.Context.TRANSACTION_FAIL)); log(new LogMessage(message, LogMessage.Context.TRANSACTION_FAIL));
} }
public AmountTableModel getAmountTableModel() {
return amountTableModel;
}
public void setAmountTableModel(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel;
}
public void activateLogging() {
this.logActive = true;
}
public void disableLogging() {
this.logActive = false;
}
public boolean isLogActive() {
return logActive;
}
} }
package fucoin.gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
*
*/
public class SuperVisorThreadGUI {
private JFrame frame;
private FilteredLogModel log = new FilteredLogModel();
private JList<LogMessage> txtLog = new JList<>(log);
private JScrollPane logPane = new JScrollPane(txtLog);
private JCheckBox showDebug;
private JCheckBox activateLogging;
private SuperVisorGuiControlImpl superVisorGuiControl;
public SuperVisorThreadGUI(SuperVisorGuiControlImpl superVisorGuiControl) {
this.superVisorGuiControl = superVisorGuiControl;
}
public void init() {
new Thread(() -> {
//Show AWT window for runtime information
frame = new JFrame("Server");
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new GridLayout(2, 1));
JTable amountListView = new JTable(superVisorGuiControl.getAmountTableModel());
superVisorGuiControl.getAmountTableModel().addTableModelListener(e -> SwingUtilities.invokeLater(() -> frame.setTitle("Server (" + superVisorGuiControl.getAmountTableModel().getRowCount() + " Wallets)")));
contentPanel.add(new JScrollPane(amountListView));
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();
}
});
activateLogging = new JCheckBox("Activate logging");
activateLogging.setSelected(superVisorGuiControl.isLogActive());
activateLogging.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
superVisorGuiControl.activateLogging();
log.emptyLog();
} else {
superVisorGuiControl.disableLogging();
}
});
JPanel configPanel = new JPanel();
configPanel.add(activateLogging);
configPanel.add(showDebug);
//logPanel.add(activateLogging, BorderLayout.NORTH);
logPanel.add(configPanel, BorderLayout.NORTH);
logPanel.add(logPane, BorderLayout.CENTER);
contentPanel.add(logPanel);
frame.add(contentPanel, BorderLayout.CENTER);
//Exit Button and shutdown supervisor
JButton exitBtn = new JButton("Stop Supervisor");
exitBtn.addActionListener(e -> {
superVisorGuiControl.guiTerminated();
frame.setVisible(false);
frame.dispose();
});
if (!superVisorGuiControl.isLogActive()) {
this.log(new LogMessage("Logging is currently disabled."));
}
frame.add(exitBtn, BorderLayout.PAGE_END);
frame.setSize(800, 600);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
superVisorGuiControl.guiTerminated();
}
});
}).start();
}
public void dispose() {
frame.dispose();
}
public void log(LogMessage logMessage) {
SwingUtilities.invokeLater(() -> {
log.addElement(logMessage);
// auto scroll to the bottom
txtLog.ensureIndexIsVisible(log.getSize() - 1);
});
}
}
package fucoin.supervisor; package fucoin.supervisor;
import javax.swing.*;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import java.util.Vector; import java.util.Vector;
......
...@@ -9,34 +9,29 @@ import fucoin.gui.SuperVisorGuiControl; ...@@ -9,34 +9,29 @@ import fucoin.gui.SuperVisorGuiControl;
import fucoin.AbstractNode; import fucoin.AbstractNode;
import fucoin.gui.TransactionLogger; import fucoin.gui.TransactionLogger;
import javax.swing.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import static akka.dispatch.Futures.future; public class SuperVisorImpl extends AbstractNode implements TransactionLogger {
public class SuperVisorImpl extends AbstractNode implements TransactionLogger{ //private AmountTableModel amountTableModel;
private AmountTableModel amountTableModel;
private Map<Long, DistributedCommittedTransferRequest> requestQueue; private Map<Long, DistributedCommittedTransferRequest> requestQueue;
private SuperVisorGuiControl gui; private SuperVisorGuiControl gui;
public SuperVisorImpl() { public SuperVisorImpl() {
this.amountTableModel = new AmountTableModel();
} }
public void setGuiControl(SuperVisorGuiControl gui) { public void setGuiControl(SuperVisorGuiControl gui) {
this.gui = gui; this.gui = gui;
} }
public SuperVisorImpl(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel;
}
@Override @Override
public void onReceive(Object msg) { public void onReceive(Object msg) {
...@@ -44,7 +39,7 @@ public class SuperVisorImpl extends AbstractNode implements TransactionLogger{ ...@@ -44,7 +39,7 @@ public class SuperVisorImpl extends AbstractNode implements TransactionLogger{
// ClientAction for some reason // ClientAction for some reason
if (msg instanceof ActionGetAmountAnswer) { if (msg instanceof ActionGetAmountAnswer) {
ActionGetAmountAnswer answer = (ActionGetAmountAnswer) msg; ActionGetAmountAnswer answer = (ActionGetAmountAnswer) msg;
amountTableModel.updateTable(answer.address, answer.name, answer.amount); SwingUtilities.invokeLater(() -> gui.updateTable(answer.address, answer.name, answer.amount));
} /* TODO: Whats happened here?? Why we can invoke doAction of abstract class? */ else if (msg instanceof SuperVisorAction) { } /* TODO: Whats happened here?? Why we can invoke doAction of abstract class? */ else if (msg instanceof SuperVisorAction) {
((Action) msg).doAction(this); ((Action) msg).doAction(this);
} }
...@@ -111,14 +106,6 @@ public class SuperVisorImpl extends AbstractNode implements TransactionLogger{ ...@@ -111,14 +106,6 @@ public class SuperVisorImpl extends AbstractNode implements TransactionLogger{
requestQueue.remove(request.getId()); requestQueue.remove(request.getId());
} }
public AmountTableModel getAmountTableModel() {
return amountTableModel;
}
public void setAmountTableModel(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel;
}
@Override @Override
public void addLogMsg(String message) { public void addLogMsg(String message) {
if (gui != null) { if (gui != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment