Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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);
});
}
}