2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: Logger.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:50 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.cluster.gui.impl.dialogs; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.BorderLayout; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Container; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JTextArea; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.border.EmptyBorder; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
public class Logger extends JDialog { |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
private JTextArea log = new JTextArea(10, 30); |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>Logger</code> with specified parent frame, title |
2 |
26 Feb 07 |
jari |
* and dialog listener. |
2 |
26 Feb 07 |
jari |
41 |
*/ |
2 |
26 Feb 07 |
jari |
42 |
public Logger(Frame parent, String title, DialogListener listener) { |
2 |
26 Feb 07 |
jari |
43 |
super(parent, title); |
2 |
26 Feb 07 |
jari |
44 |
JPanel logPanel = createLogPanel(); |
2 |
26 Feb 07 |
jari |
45 |
JPanel btnsPanel = createBtnsPanel(listener); |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
Container content = getContentPane(); |
2 |
26 Feb 07 |
jari |
48 |
content.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
49 |
content.add(logPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 |
2 |
26 Feb 07 |
jari |
50 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
51 |
content.add(btnsPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
52 |
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 8, 4, 8), 0, 0)); |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
55 |
pack(); |
2 |
26 Feb 07 |
jari |
56 |
} |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
60 |
*/ |
2 |
26 Feb 07 |
jari |
61 |
public void show() { |
2 |
26 Feb 07 |
jari |
62 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
63 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
64 |
super.show(); |
2 |
26 Feb 07 |
jari |
65 |
} |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
/** |
2 |
26 Feb 07 |
jari |
* Appends a specified string to the end of log. |
2 |
26 Feb 07 |
jari |
69 |
*/ |
2 |
26 Feb 07 |
jari |
70 |
public void append(String text) { |
2 |
26 Feb 07 |
jari |
71 |
log.append(text); |
2 |
26 Feb 07 |
jari |
72 |
log.setCaretPosition(log.getDocument().getLength()); |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a log panel. |
2 |
26 Feb 07 |
jari |
77 |
*/ |
2 |
26 Feb 07 |
jari |
78 |
private JPanel createLogPanel() { |
2 |
26 Feb 07 |
jari |
79 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
panel.setBorder(new EmptyBorder(10, 10, 10, 10)); |
2 |
26 Feb 07 |
jari |
82 |
log.setTabSize(3); |
2 |
26 Feb 07 |
jari |
83 |
log.setEditable(false); |
2 |
26 Feb 07 |
jari |
84 |
log.setAutoscrolls(true); |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
JScrollPane scroll = new JScrollPane(log); |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
89 |
panel.add(new JLabel(GUIFactory.getIcon("dialog_banner2.gif")), gbc); |
2 |
26 Feb 07 |
jari |
90 |
gbc.gridy = 1; |
2 |
26 Feb 07 |
jari |
91 |
gbc.weightx = 1.0; |
2 |
26 Feb 07 |
jari |
92 |
gbc.weighty = 1.0; |
2 |
26 Feb 07 |
jari |
93 |
gbc.fill = GridBagConstraints.BOTH; |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
panel.add(scroll, gbc); |
2 |
26 Feb 07 |
jari |
96 |
return panel; |
2 |
26 Feb 07 |
jari |
97 |
} |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
99 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a panel with cancel button. |
2 |
26 Feb 07 |
jari |
101 |
*/ |
2 |
26 Feb 07 |
jari |
102 |
private JPanel createBtnsPanel(ActionListener listener) { |
2 |
26 Feb 07 |
jari |
103 |
JPanel panel = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
104 |
JButton cancelButton = new JButton(" Cancel "); |
2 |
26 Feb 07 |
jari |
105 |
cancelButton.setMargin(new java.awt.Insets(5,5,5,5)); |
2 |
26 Feb 07 |
jari |
106 |
cancelButton.setActionCommand("cancel-command"); |
2 |
26 Feb 07 |
jari |
107 |
cancelButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
108 |
cancelButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
109 |
cancelButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
110 |
panel.add(cancelButton, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
111 |
getRootPane().setDefaultButton(cancelButton); |
2 |
26 Feb 07 |
jari |
112 |
return panel; |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
} |