Menu

[r73]: / GraphScript / trunk / ls / ui / msg / MessagePanel.java  Maximize  Restore  History

Download this file

94 lines (82 with data), 2.2 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
package ls.ui.msg;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import ls.util.msg.ErrorHandler;
import ls.util.msg.MessageHandler;
import ls.util.msg.MessageManager;
/**
* A swing panel that can be used to display messages in a swing UI.
* It's implemented as a message and error handler.
*
* @author Lior
* @see MessageHandler
* @see ErrorHandler
* @see MessageManager
*/
public class MessagePanel extends JPanel implements MessageHandler, ErrorHandler
{
private static final long serialVersionUID = 1L;
private JEditorPane editorPane = null;
public MessagePanel()
{
super();
initComponents();
// MessageManager.registerErrorHandler(this);
// MessageManager.registerMessageHandler(this);
}
/**
* Init the UI of the panel
*/
private void initComponents()
{
this.setLayout(new BorderLayout());
editorPane = new JEditorPane();
editorPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(editorPane);
this.add(scrollPane,BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
JButton btn = new JButton("Clear");
btn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
editorPane.setText("");
}
});
buttonPanel.add(btn);
this.add(buttonPanel,BorderLayout.SOUTH);
}
/**
* Append a line of text to the message area
* @param line The line to add, must not be null
*/
private void appendLine(String line)
{
if (line == null) return;
String t = this.editorPane.getText();
t += line + '\n';
this.editorPane.setText(t);
this.editorPane.scrollToReference(line);
}
public void handleError(String errMsg)
{
appendLine("ERROR: " + errMsg);
}
public boolean handleException(Exception exn)
{
handleError(exn.getMessage());
return true;
}
public void handleMsg(String msg)
{
appendLine(msg);
}
}
MongoDB Logo MongoDB