1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail/im me at jeti@jabber.org |
---|
21 | */ |
---|
22 | |
---|
23 | package nu.fw.jeti.ui; |
---|
24 | import java.awt.BorderLayout; |
---|
25 | import java.awt.event.ActionEvent; |
---|
26 | import java.awt.event.ActionListener; |
---|
27 | import java.awt.event.KeyEvent; |
---|
28 | import java.util.Iterator; |
---|
29 | import java.util.List; |
---|
30 | |
---|
31 | import javax.swing.*; |
---|
32 | |
---|
33 | import nu.fw.jeti.jabber.Backend; |
---|
34 | import nu.fw.jeti.jabber.elements.Packet; |
---|
35 | import nu.fw.jeti.util.I18N; |
---|
36 | import nu.fw.jeti.util.Log; |
---|
37 | import nu.fw.jeti.util.Utils; |
---|
38 | |
---|
39 | /** |
---|
40 | * @author E.S. de Boer |
---|
41 | */ |
---|
42 | |
---|
43 | public class LogWindow extends JFrame |
---|
44 | { |
---|
45 | |
---|
46 | private JPanel jPanel1 = new JPanel(); |
---|
47 | private JButton btnClose = new JButton(); |
---|
48 | private JButton btnRefresh = new JButton(); |
---|
49 | private JTabbedPane jTabbedPane1 = new JTabbedPane(); |
---|
50 | private JTextArea txtXML = new JTextArea(); |
---|
51 | private JScrollPane jScrollPane1 = new JScrollPane(); |
---|
52 | private JTextArea txtXMLErrors = new JTextArea(); |
---|
53 | private JScrollPane jScrollPane2 = new JScrollPane(); |
---|
54 | private JTextArea txtErrors = new JTextArea(); |
---|
55 | private JScrollPane jScrollPane3 = new JScrollPane(); |
---|
56 | private int xml; |
---|
57 | private int xmlErrors; |
---|
58 | private int errors; |
---|
59 | private Backend backend; |
---|
60 | |
---|
61 | public LogWindow(Backend backend) |
---|
62 | { |
---|
63 | this.backend = backend; |
---|
64 | try |
---|
65 | { |
---|
66 | jbInit(); |
---|
67 | } |
---|
68 | catch (Exception e) |
---|
69 | { |
---|
70 | e.printStackTrace(); |
---|
71 | } |
---|
72 | txtXML.setText(I18N.gettext("main.log.Please_wait_loading_log")); |
---|
73 | Thread t= new Thread() |
---|
74 | { |
---|
75 | public void run() |
---|
76 | { |
---|
77 | //try{ |
---|
78 | StringBuffer buffer = new StringBuffer(); |
---|
79 | List temp = Log.getXML(); |
---|
80 | for (Iterator i = temp.iterator(); i.hasNext();) |
---|
81 | { |
---|
82 | buffer.append(i.next()); |
---|
83 | buffer.append("\n"); |
---|
84 | // sleep(2); |
---|
85 | } |
---|
86 | txtXML.setText(buffer.toString()); |
---|
87 | buffer = new StringBuffer(); |
---|
88 | xml = temp.size(); |
---|
89 | temp = Log.getXMLErrors(); |
---|
90 | for (Iterator i = temp.iterator(); i.hasNext();) |
---|
91 | { |
---|
92 | buffer.append(i.next()); |
---|
93 | buffer.append("\n"); |
---|
94 | // sleep(2); |
---|
95 | } |
---|
96 | txtXMLErrors.setText(buffer.toString()); |
---|
97 | xmlErrors = temp.size(); |
---|
98 | temp = Log.getErrors(); |
---|
99 | buffer = new StringBuffer(); |
---|
100 | for (Iterator i = temp.iterator(); i.hasNext();) |
---|
101 | { |
---|
102 | buffer.append(i.next()); |
---|
103 | buffer.append("\n"); |
---|
104 | // sleep(2); |
---|
105 | } |
---|
106 | txtErrors.setText(buffer.toString()); |
---|
107 | errors = temp.size(); |
---|
108 | //}catch(InterruptedException e){} |
---|
109 | } |
---|
110 | }; |
---|
111 | t.setPriority(Thread.NORM_PRIORITY); |
---|
112 | t.start(); |
---|
113 | } |
---|
114 | |
---|
115 | private void jbInit() throws Exception |
---|
116 | { |
---|
117 | jTabbedPane1.setBorder(null); |
---|
118 | //setIconImage(nu.fw.jeti.images.StatusIcons.getImageIcon("jeti").getImage()); |
---|
119 | setTitle(I18N.gettext("main.log.JETI_Log")); |
---|
120 | btnClose.setText(I18N.gettext("Close")); |
---|
121 | Action cancelAction = new AbstractAction(I18N.gettext("Close")) |
---|
122 | { |
---|
123 | public void actionPerformed(ActionEvent e) |
---|
124 | { |
---|
125 | dispose(); |
---|
126 | } |
---|
127 | }; |
---|
128 | Utils.addCancelButton(this, btnClose, cancelAction); |
---|
129 | //btnRefresh.setText(I18N.gettext("main.log.Refresh")); |
---|
130 | I18N.setTextAndMnemonic("main.log.Refresh",btnRefresh); |
---|
131 | btnRefresh.addActionListener(new java.awt.event.ActionListener() |
---|
132 | { |
---|
133 | public void actionPerformed(ActionEvent e) |
---|
134 | { |
---|
135 | btnRefresh_actionPerformed(e); |
---|
136 | } |
---|
137 | }); |
---|
138 | JButton btnClear = new JButton(); |
---|
139 | I18N.setTextAndMnemonic("main.log.Clear_Log",btnClear); |
---|
140 | btnClear.addActionListener(new java.awt.event.ActionListener() |
---|
141 | { |
---|
142 | public void actionPerformed(ActionEvent e) |
---|
143 | { |
---|
144 | Log.clear(); |
---|
145 | xml=0; |
---|
146 | txtXML.setText(""); |
---|
147 | btnRefresh_actionPerformed(e); |
---|
148 | } |
---|
149 | }); |
---|
150 | //JButton btnSend = new JButton(I18N.gettext("main.log.Send_XML")); |
---|
151 | JButton btnSend = new JButton(); |
---|
152 | I18N.setTextAndMnemonic("main.log.Send_XML",btnSend); |
---|
153 | this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
---|
154 | this.getContentPane().add(jPanel1, BorderLayout.SOUTH); |
---|
155 | //jPanel1.add(btnSend); |
---|
156 | jPanel1.add(btnClear, null); |
---|
157 | jPanel1.add(btnRefresh, null); |
---|
158 | jPanel1.add(btnClose, null); |
---|
159 | //send xml window |
---|
160 | JPanel pnlSendXML = new JPanel(new BorderLayout()); |
---|
161 | pnlSendXML.add(new JLabel(I18N.gettext("main.log.Send_XML_to_the_Jabber_server,_use_this_at_your_own_risk")), BorderLayout.NORTH); |
---|
162 | final JTextArea txtXMLSend = new JTextArea(); |
---|
163 | //txtXMLSend. |
---|
164 | pnlSendXML.add(new JScrollPane(txtXMLSend),BorderLayout.CENTER); |
---|
165 | btnSend.addActionListener(new ActionListener() |
---|
166 | { |
---|
167 | public void actionPerformed(ActionEvent e) |
---|
168 | { |
---|
169 | if(txtXMLSend.getText().indexOf("password")!=-1) |
---|
170 | { |
---|
171 | JOptionPane.showMessageDialog(LogWindow.this,I18N.gettext("main.log.For_security_reasons_it_is_not_possible_to_change_passwords,_please_use_the_jeti_functions_for_that")); |
---|
172 | } |
---|
173 | else if(txtXMLSend.getText().indexOf("remove")!=-1) |
---|
174 | { |
---|
175 | JOptionPane.showMessageDialog(LogWindow.this,I18N.gettext("main.log.For_security_reasons_it_is_not_possible_to_remove_accounts,_please_use_the_jeti_functions_for_that")); |
---|
176 | } |
---|
177 | else if(!txtXMLSend.getText().equals("")) |
---|
178 | { |
---|
179 | backend.send(new Packet() |
---|
180 | { |
---|
181 | public void appendToXML(StringBuffer xml) |
---|
182 | { |
---|
183 | xml.append(txtXMLSend.getText()); |
---|
184 | txtXMLSend.setText(""); |
---|
185 | } |
---|
186 | }); |
---|
187 | } |
---|
188 | } |
---|
189 | }); |
---|
190 | pnlSendXML.add(btnSend,BorderLayout.SOUTH); |
---|
191 | getContentPane().add(jTabbedPane1, BorderLayout.CENTER); |
---|
192 | //TODO mnemonics on tab |
---|
193 | jTabbedPane1.add(jScrollPane1, I18N.gettext("main.log.XML")); |
---|
194 | jTabbedPane1.add(jScrollPane2, I18N.gettext("main.log.XML_Errors")); |
---|
195 | jTabbedPane1.add(jScrollPane3, I18N.gettext("main.log.Errors")); |
---|
196 | jTabbedPane1.add(pnlSendXML, I18N.gettext("main.log.Send_XML")); |
---|
197 | jScrollPane3.getViewport().add(txtErrors, null); |
---|
198 | jScrollPane2.getViewport().add(txtXMLErrors, null); |
---|
199 | jScrollPane1.getViewport().add(txtXML, null); |
---|
200 | setSize(400, 400); |
---|
201 | setLocationRelativeTo(null); |
---|
202 | } |
---|
203 | |
---|
204 | void btnRefresh_actionPerformed(ActionEvent e) |
---|
205 | { |
---|
206 | Thread t = new Thread() |
---|
207 | { |
---|
208 | public void run() |
---|
209 | { |
---|
210 | List temp = Log.getXML(); |
---|
211 | StringBuffer buffer = new StringBuffer(); |
---|
212 | for (Iterator i = temp.listIterator(xml); i.hasNext();) |
---|
213 | { |
---|
214 | buffer.append(i.next()); |
---|
215 | buffer.append("\n"); |
---|
216 | } |
---|
217 | xml = temp.size(); |
---|
218 | txtXML.append(buffer.toString()); |
---|
219 | temp = Log.getXMLErrors(); |
---|
220 | for (Iterator i = temp.listIterator(xmlErrors); i.hasNext();) |
---|
221 | { |
---|
222 | txtXMLErrors.append((String) i.next() + "\n"); |
---|
223 | } |
---|
224 | xmlErrors = temp.size(); |
---|
225 | temp = Log.getErrors(); |
---|
226 | for (Iterator i = temp.listIterator(errors); i.hasNext();) |
---|
227 | { |
---|
228 | txtErrors.append((String) i.next() + "\n"); |
---|
229 | } |
---|
230 | errors = temp.size(); |
---|
231 | } |
---|
232 | }; |
---|
233 | t.setPriority(Thread.NORM_PRIORITY); |
---|
234 | t.start(); |
---|
235 | } |
---|
236 | } |
---|
237 | /* |
---|
238 | * Overrides for emacs |
---|
239 | * Local variables: |
---|
240 | * tab-width: 4 |
---|
241 | * End: |
---|
242 | */ |
---|