Menu

[r1]: / src / EventPanel.java  Maximize  Restore  History

Download this file

296 lines (260 with data), 10.4 kB

  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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
public class EventPanel extends JPanel implements ActionListener, MouseListener {
public static final Font STANDARD_FONT = new Font("Monospaced", Font.PLAIN, 12);
public static final Color NORMAL_BACKGROUND = Color.WHITE;
public static final Color SELECTED_BACKGROUND = new Color(210, 230, 250);
public static final Color SEPARATOR_COLOR = new Color(200, 200, 200);
private Component parent;
private Event event;
private JPanel topPanel;
private JPanel topButtonPanel;
private JLabel captionLabel;
private JButton snapshotButton;
private JButton subEventsButton;
private JButton expandButton;
private JTextArea detailsArea;
private JLabel imageLabel;
private JPanel expandPanel;
private boolean expanded;
private boolean selected;
private boolean canExpand;
public EventPanel(Event evt, Component parent) {
this.event = evt;
this.parent = parent;
this.canExpand = false;
captionLabel = new JLabel();
captionLabel.setFont(STANDARD_FONT);
captionLabel.setOpaque(true);
snapshotButton = new JButton("SNAPSHOT");
snapshotButton.setFont(STANDARD_FONT);
snapshotButton.addActionListener(this);
subEventsButton = new JButton("SUBEVENTS");
subEventsButton.setFont(STANDARD_FONT);
subEventsButton.addActionListener(this);
expandButton = new JButton("+");
expandButton.setFont(STANDARD_FONT);
expandButton.addActionListener(this);
topButtonPanel = new JPanel();
detailsArea = new JTextArea();
detailsArea.setLineWrap(true);
detailsArea.setWrapStyleWord(true);
detailsArea.setEditable(false);
detailsArea.setFont(STANDARD_FONT);
imageLabel = new JLabel();
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
topPanel.add(captionLabel, BorderLayout.CENTER);
topPanel.add(topButtonPanel, BorderLayout.EAST);
if (event.hasAttachment("snapshot")) {
topButtonPanel.add(snapshotButton);
}
expandPanel = new JPanel();
expandPanel.setLayout(new BoxLayout(expandPanel, BoxLayout.PAGE_AXIS));
String details = null;
if (event.getDetails() != null && !event.getDetails().equals("")) {
details = event.getDetails();
} else if (event.hasAttachment("diff")) {
details = event.getAttachment("diff").getTextData();
}
if (details != null) {
detailsArea.setText(details);
expandPanel.add(detailsArea);
canExpand = true;
}
if (event.hasAttachment("image")) {
Attachment image = event.getAttachment("image");
imageLabel.setIcon(new ImageIcon(image.getImageData()));
expandPanel.add(imageLabel);
canExpand = true;
}
java.util.List<Event> subEvents = event.getSubEvents();
if (subEvents != null && subEvents.size() > 0) {
topButtonPanel.add(subEventsButton);
}
captionLabel.addMouseListener(this);
detailsArea.addMouseListener(this);
addMouseListener(this);
setAlignmentX(Component.CENTER_ALIGNMENT);
setLayout(new BorderLayout());
add(topPanel, BorderLayout.NORTH);
if (canExpand && isAlwaysExpanded()) {
expanded = true;
add(expandPanel, BorderLayout.CENTER);
} else if (canExpand) {
expanded = false;
topButtonPanel.add(expandButton);
}
setSelected(false);
// for layout debugging
//topPanel.setBorder(BorderFactory.createLineBorder(Color.RED));
//detailsArea.setBorder(BorderFactory.createLineBorder(Color.BLUE));
if (expanded) {
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,1,0, SEPARATOR_COLOR),
BorderFactory.createEmptyBorder(5,2,5,2)));
} else {
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,1,0, SEPARATOR_COLOR),
BorderFactory.createEmptyBorder(0,2,0,2)));
}
refreshLabel();
refreshSize();
}
public Event getEvent() {
return event;
}
private boolean isAlwaysExpanded() {
if (event.hasTag("comment")) {
return true;
} else {
return false;
}
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean status) {
selected = status;
if (status) {
setBackground(SELECTED_BACKGROUND);
topPanel.setBackground(SELECTED_BACKGROUND);
topButtonPanel.setBackground(SELECTED_BACKGROUND);
captionLabel.setBackground(SELECTED_BACKGROUND);
detailsArea.setBackground(SELECTED_BACKGROUND);
imageLabel.setBackground(SELECTED_BACKGROUND);
expandPanel.setBackground(SELECTED_BACKGROUND);
} else {
setBackground(NORMAL_BACKGROUND);
topPanel.setBackground(NORMAL_BACKGROUND);
topButtonPanel.setBackground(NORMAL_BACKGROUND);
captionLabel.setBackground(NORMAL_BACKGROUND);
detailsArea.setBackground(NORMAL_BACKGROUND);
imageLabel.setBackground(NORMAL_BACKGROUND);
expandPanel.setBackground(NORMAL_BACKGROUND);
}
invalidate();
repaint();
}
public String getLabel() {
StringBuffer label = new StringBuffer();
label.append(event.getFormattedTimestamp());
label.append(": ");
for (String tag : event.getTags()) {
if (!tag.equals("text")) {
label.append("[");
label.append(tag.toUpperCase());
label.append("] ");
}
}
//if (event.hasAttachment("snapshot")) {
//label.append("[*] ");
//}
if (event.hasProperty("path")) {
label.append(event.getProperty("path"));
} else if (!expanded) {
label.append(event.getDetailPreview());
}
//return label.toString();
String desc = label.toString();
if (desc.length() > 80) {
desc = desc.substring(0,76) + " ...";
}
return desc;
}
public void refreshLabel() {
captionLabel.setText(getLabel());
}
public void refreshSize() {
if (expanded) {
setMaximumSize(new Dimension(Short.MAX_VALUE,
topPanel.getPreferredSize().height +
expandPanel.getPreferredSize().height));
} else {
setMaximumSize(new Dimension(Short.MAX_VALUE,
topPanel.getPreferredSize().height));
setPreferredSize(null);
}
}
public void showSubEvents() {
java.util.List<Event> subEvents = event.getSubEvents();
if (subEvents != null && subEvents.size() > 0) {
JPanel subEventsPanel = new JPanel();
subEventsPanel.setLayout(new BoxLayout(subEventsPanel, BoxLayout.PAGE_AXIS));
subEventsPanel.setBackground(NORMAL_BACKGROUND);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(new JScrollPane(subEventsPanel), BorderLayout.CENTER);
JDialog popupDialog = new JDialog();
popupDialog.setTitle(getLabel());
popupDialog.getContentPane().add(mainPanel);
popupDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
popupDialog.setSize(800,500);
popupDialog.setLocationRelativeTo(null);
popupDialog.setVisible(true);
for (Event e : subEvents) {
subEventsPanel.add(new EventPanel(e, popupDialog));
}
subEventsPanel.add(Box.createVerticalGlue());
}
}
public void showSnapshot() {
String path = event.getProperty("path");
String fulltext = (event.hasAttachment("snapshot") ?
event.getAttachment("snapshot").getTextData() : null);
if (path != null && fulltext != null) {
JTextArea textArea = new JTextArea();
textArea.setText(fulltext);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setFont(STANDARD_FONT);
textArea.setSelectionStart(0);
textArea.setSelectionEnd(0);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(new JScrollPane(textArea), BorderLayout.CENTER);
JDialog popupDialog = new JDialog();
popupDialog.setTitle(path);
popupDialog.getContentPane().add(mainPanel);
popupDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
popupDialog.setSize(700,500);
popupDialog.setLocationRelativeTo(null);
popupDialog.setVisible(true);
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == expandButton) {
if (!expanded) {
expandButton.setText("-");
add(expandPanel, BorderLayout.CENTER);
expanded = true;
} else {
expandButton.setText("+");
remove(expandPanel);
expanded = false;
}
refreshLabel();
refreshSize();
} else if (e.getSource() == snapshotButton) {
showSnapshot();
} else if (e.getSource() == subEventsButton) {
showSubEvents();
}
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
showSnapshot();
}
setSelected(!selected);
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
}
MongoDB Logo MongoDB