1 package com.github.celldynamics.quimp;
2
3 import java.awt.Color;
4 import java.awt.Frame;
5 import java.awt.GridLayout;
6 import java.awt.Panel;
7 import java.awt.TextArea;
8 import java.awt.event.WindowEvent;
9 import java.awt.event.WindowListener;
10 import java.util.ArrayList;
11
12 import javax.swing.JScrollPane;
13
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 import com.github.celldynamics.quimp.filesystem.IQuimpSerialize;
18
19
20
21
22
23
24
25
26
27
28
29
30 public class HistoryLogger implements WindowListener {
31
32 private static final Logger LOGGER = LoggerFactory.getLogger(HistoryLogger.class.getName());
33 private Frame historyWnd;
34 private ArrayList<String> history;
35 private TextArea info;
36 private int id;
37
38
39
40
41 public HistoryLogger() {
42 id = 1;
43 historyWnd = new Frame("History");
44 Panel p = new Panel();
45 p.setLayout(new GridLayout(1, 1));
46 Panel tp = new Panel();
47 tp.setLayout(new GridLayout(1, 1));
48 info = new TextArea(10, 60);
49 info.setEditable(false);
50 info.setBackground(Color.WHITE);
51 tp.add(info);
52
53 JScrollPane infoPanel = new JScrollPane(tp);
54 p.add(infoPanel);
55 historyWnd.add(p);
56 historyWnd.pack();
57 historyWnd.addWindowListener(this);
58
59 history = new ArrayList<String>();
60
61 }
62
63
64
65
66 public void openHistory() {
67 historyWnd.setVisible(true);
68 }
69
70
71
72
73 public void closeHistory() {
74 historyWnd.setVisible(false);
75 }
76
77
78
79
80
81
82
83
84
85
86 public void addEntry(String m, BOAState bs) {
87
88 if (historyWnd.isVisible()) {
89 if (bs == null) {
90 return;
91 }
92 LogEntryimp/HistoryLogger.html#LogEntry">LogEntry en = new LogEntry(id++, m, bs);
93 Serializer<LogEntry> s = new Serializer<>(en, QuimP.TOOL_VERSION);
94
95 String jsontmp = s.toString();
96 history.add(jsontmp);
97 info.append(jsontmp + '\n');
98 LOGGER.debug(jsontmp);
99 en = null;
100 }
101
102 }
103
104
105
106
107
108
109 public boolean isOpened() {
110 return historyWnd.isVisible();
111 }
112
113
114
115
116
117
118 @Override
119 public void windowOpened(WindowEvent e) {
120 }
121
122
123
124
125
126
127 @Override
128 public void windowClosing(WindowEvent e) {
129 LOGGER.debug("History windowClosing");
130 historyWnd.setVisible(false);
131 info.setText("");
132 id = 1;
133 history.clear();
134 historyWnd.dispose();
135
136 }
137
138
139
140
141
142
143 @Override
144 public void windowClosed(WindowEvent e) {
145 LOGGER.debug("History windowClosed");
146 historyWnd.setVisible(false);
147 info.setText("");
148 id = 1;
149 history.clear();
150 historyWnd.dispose();
151
152 }
153
154
155
156
157
158
159 @Override
160 public void windowIconified(WindowEvent e) {
161
162 }
163
164
165
166
167
168
169 @Override
170 public void windowDeiconified(WindowEvent e) {
171
172 }
173
174
175
176
177
178
179 @Override
180 public void windowActivated(WindowEvent e) {
181 }
182
183
184
185
186
187
188 @Override
189 public void windowDeactivated(WindowEvent e) {
190 }
191
192 }
193
194
195
196
197
198
199
200 class LogEntry implements IQuimpSerialize {
201 public int id;
202 public String action;
203
204 public int frame;
205 public BOAState.SegParam segParam;
206 public String fileName;
207 public SnakePluginList snakePluginList;
208
209
210
211
212
213
214
215
216
217
218 public LogEntry(int counter, String action, BOAState bs) {
219
220 super();
221 this.id = counter;
222 this.action = action;
223 this.frame = bs.boap.frame;
224 this.segParam = bs.segParam;
225 this.fileName = bs.boap.getFileName();
226 this.snakePluginList = bs.snakePluginList;
227
228 }
229
230 @Override
231 public void beforeSerialize() {
232 snakePluginList.beforeSerialize();
233 }
234
235 @Override
236 public void afterSerialize() throws Exception {
237 }
238 }