svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libCorePlugin / src / com / iver / core / ConsolaFrame.java @ 9167
History | View | Annotate | Download (9.78 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.core; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
|
45 |
import javax.swing.JEditorPane; |
46 |
import javax.swing.JPanel; |
47 |
import javax.swing.JScrollPane; |
48 |
import javax.swing.JTabbedPane; |
49 |
|
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.andami.messages.MessageEvent; |
52 |
import com.iver.andami.messages.NotificationListener; |
53 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
54 |
import com.iver.andami.ui.mdiManager.IWindow; |
55 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
56 |
|
57 |
/**
|
58 |
* Frame que escucha los eventos del sistema de mensajes de la aplicaci?n y los
|
59 |
* muestra.
|
60 |
*/
|
61 |
public class ConsolaFrame extends JPanel implements IWindow, SingletonWindow,NotificationListener { |
62 |
private StringBuffer info = new StringBuffer(); |
63 |
private StringBuffer warn = new StringBuffer(); |
64 |
private StringBuffer error = new StringBuffer(); |
65 |
private StringBuffer all = new StringBuffer(); |
66 |
private JEditorPane textoInfos; |
67 |
private JEditorPane textoWarnings; |
68 |
private JEditorPane textoErrores; |
69 |
private JEditorPane textoAll; |
70 |
|
71 |
private final static String marcaInfo ="font size='3' color='#000000'"; |
72 |
private final static String marcaWarning ="font size='3' color='#800000'"; |
73 |
private final static String marcaError ="font size='3' color='#FF0000'"; |
74 |
private JTabbedPane tabs; |
75 |
private JPanel panelErrores; |
76 |
|
77 |
/**
|
78 |
* Crea la consola con los mensajes producidos hasta el momento de la
|
79 |
* creaci?n de este objeto.
|
80 |
*
|
81 |
* @param todo Array de todos los mensajes
|
82 |
* @param infos Array de los mensajes de informaci?n
|
83 |
* @param warns Array de los mensajes de warning
|
84 |
* @param errors Array de los mensajes de error
|
85 |
*/
|
86 |
public ConsolaFrame() {
|
87 |
|
88 |
this.setSize(400, 325); |
89 |
|
90 |
//Las cajas de texto donde van los mensajes
|
91 |
textoInfos = new JEditorPane(); |
92 |
textoInfos.setEditable(false);
|
93 |
textoInfos.setContentType("text/html");
|
94 |
textoWarnings = new JEditorPane(); |
95 |
textoWarnings.setEditable(false);
|
96 |
textoWarnings.setContentType("text/html");
|
97 |
textoErrores = new JEditorPane(); |
98 |
textoErrores.setEditable(false);
|
99 |
textoErrores.setContentType("text/html");
|
100 |
textoAll = new JEditorPane(); |
101 |
textoAll.setEditable(false);
|
102 |
textoAll.setContentType("text/html");
|
103 |
|
104 |
JScrollPane scroll = new JScrollPane(textoAll); |
105 |
scroll.setVerticalScrollBarPolicy( |
106 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
107 |
scroll.setHorizontalScrollBarPolicy( |
108 |
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
109 |
// scroll.setPreferredSize(new Dimension(500, 500));
|
110 |
// scroll.setMinimumSize(new Dimension(10, 10));
|
111 |
JPanel panelAll = new JPanel(new BorderLayout()); |
112 |
panelAll.add(scroll, BorderLayout.CENTER);
|
113 |
|
114 |
scroll = new JScrollPane(textoInfos); |
115 |
scroll.setVerticalScrollBarPolicy( |
116 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
117 |
scroll.setHorizontalScrollBarPolicy( |
118 |
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
119 |
// scroll.setPreferredSize(new Dimension(250, 145));
|
120 |
// scroll.setMinimumSize(new Dimension(10, 10));
|
121 |
JPanel panelInfos = new JPanel(new BorderLayout()); |
122 |
panelInfos.add(scroll, BorderLayout.CENTER);
|
123 |
|
124 |
scroll = new JScrollPane(textoWarnings); |
125 |
scroll.setVerticalScrollBarPolicy( |
126 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
127 |
scroll.setHorizontalScrollBarPolicy( |
128 |
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
129 |
// scroll.setPreferredSize(new Dimension(250, 145));
|
130 |
// scroll.setMinimumSize(new Dimension(10, 10));
|
131 |
JPanel panelWarnings = new JPanel(new BorderLayout()); |
132 |
panelWarnings.add(scroll, BorderLayout.CENTER);
|
133 |
|
134 |
scroll = new JScrollPane(textoErrores); |
135 |
scroll.setVerticalScrollBarPolicy( |
136 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
137 |
scroll.setHorizontalScrollBarPolicy( |
138 |
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
139 |
// scroll.setPreferredSize(new Dimension(250, 145));
|
140 |
// scroll.setMinimumSize(new Dimension(10, 10));
|
141 |
panelErrores = new JPanel(new BorderLayout()); |
142 |
panelErrores.add(scroll, BorderLayout.CENTER);
|
143 |
|
144 |
// rellenar(infos, textoInfos, info, marcaInfo);
|
145 |
// rellenar(warns, textoWarnings, warn, marcaWarning);
|
146 |
// rellenar(errors, textoErrores, error, marcaError);
|
147 |
// rellenarTodo(todo, textoAll);
|
148 |
|
149 |
//Las pesta?as
|
150 |
tabs = new JTabbedPane(); |
151 |
tabs.addTab(PluginServices.getText( this ,"todos"), panelAll); |
152 |
tabs.addTab(PluginServices.getText( this ,"info"), panelInfos); |
153 |
tabs.addTab(PluginServices.getText( this ,"warnings"), panelWarnings); |
154 |
tabs.addTab(PluginServices.getText( this ,"errores"), panelErrores); |
155 |
this.setLayout(new BorderLayout()); |
156 |
this.add(tabs, BorderLayout.CENTER); |
157 |
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* M?todo de utilidad para rellenar los cuadros de texto con un array de
|
162 |
* cadenas
|
163 |
*
|
164 |
* @param contenido array de cadenas que se mostrar?n en el cuadro de texto
|
165 |
* separadas por un retorno de carro
|
166 |
* @param control Control en el que se pondr?n las cadenas
|
167 |
*/
|
168 |
private void rellenar(String[] contenido, JEditorPane control, StringBuffer buffer, String marca) { |
169 |
String content = ""; |
170 |
for (int i = 0; i < contenido.length; i++) { |
171 |
content = content + "<"+marca+">"+contenido[i] + "</"+marca+"><br/"; |
172 |
} |
173 |
|
174 |
buffer.append(content); |
175 |
|
176 |
control.setContentType("text/html");
|
177 |
control.setText(content); |
178 |
} |
179 |
|
180 |
/*
|
181 |
* M?todo de utilidad para rellenar los cuadros de texto con un array de
|
182 |
* cadenas
|
183 |
*
|
184 |
* @param contenido array de cadenas que se mostrar?n en el cuadro de texto
|
185 |
* separadas por un retorno de carro
|
186 |
* @param control Control en el que se pondr?n las cadenas
|
187 |
*
|
188 |
private void rellenarTodo(Message[] contenido, JEditorPane control) {
|
189 |
HashMap marcasTipoMsg = new HashMap();
|
190 |
marcasTipoMsg.put(new Integer(Message.INFO), marcaInfo);
|
191 |
marcasTipoMsg.put(new Integer(Message.WARNING), marcaWarning);
|
192 |
marcasTipoMsg.put(new Integer(Message.ERROR), marcaError);
|
193 |
|
194 |
String content = "";
|
195 |
for (int i = 0; i < contenido.length; i++) {
|
196 |
String marca = (String) marcasTipoMsg.get(new Integer(contenido[i].tipo));
|
197 |
content = content + "<"+marca+">"+contenido[i].texto + "</"+marca+"><br/";
|
198 |
}
|
199 |
|
200 |
all.append(content);
|
201 |
|
202 |
control.setContentType("text/html");
|
203 |
control.setText(content);
|
204 |
}*/
|
205 |
|
206 |
|
207 |
/**
|
208 |
* Obtiene un string con la traza de una excepci?n a la consola
|
209 |
*
|
210 |
* @param t Elemento throwable
|
211 |
*/
|
212 |
private static String dumpStackTrace(Throwable t) { |
213 |
if ( t == null ) return ""; |
214 |
StackTraceElement[] stes = t.getStackTrace(); |
215 |
String todo = "<"+marcaWarning+">" + t.getClass().getName() + ": " + t.getLocalizedMessage() + |
216 |
"<"+marcaWarning+">" + "<br/"; |
217 |
|
218 |
for (int i = 0; i < stes.length; i++) { |
219 |
todo += ("<"+marcaWarning+"> " + stes[i].toString() + "<br/"); |
220 |
} |
221 |
|
222 |
if (t.getCause() != null) { |
223 |
todo = todo + dumpStackTrace(t.getCause()); |
224 |
} |
225 |
|
226 |
return todo;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* @see com.iver.mdiApp.NotificationListener#errorEvent(java.lang.String)
|
231 |
*/
|
232 |
public void errorEvent(MessageEvent e) { |
233 |
for (int i = 0; i < e.getMessages().length; i++){ |
234 |
String traza = dumpStackTrace(e.getExceptions()[i]);
|
235 |
|
236 |
error.append("<"+marcaError+">" + e.getMessages()[i] + "</"+marcaError+"><br/" + traza); |
237 |
all.append("<"+marcaError+">" + e.getMessages()[i] + "</"+marcaError+"><br/" + traza); |
238 |
} |
239 |
textoErrores.setText(error.toString()); |
240 |
textoAll.setText(all.toString()); |
241 |
tabs.setSelectedComponent(panelErrores); |
242 |
} |
243 |
|
244 |
/**
|
245 |
* @see com.iver.mdiApp.NotificationListener#warningEvent(java.lang.String)
|
246 |
*/
|
247 |
public void warningEvent(MessageEvent e) { |
248 |
for (int i = 0; i < e.getMessages().length; i++){ |
249 |
String traza = dumpStackTrace(e.getExceptions()[i]);
|
250 |
|
251 |
warn.append("<"+marcaWarning+">" + e.getMessages()[i] + "</"+marcaWarning+"><br/" + traza); |
252 |
all.append("<"+marcaWarning+">" + e.getMessages()[i] + "</"+marcaWarning+"><br/" + traza); |
253 |
} |
254 |
textoWarnings.setText(warn.toString()); |
255 |
textoAll.setText(all.toString()); |
256 |
} |
257 |
|
258 |
/**
|
259 |
* @see com.iver.mdiApp.NotificationListener#infoEvent(java.lang.String)
|
260 |
*/
|
261 |
public void infoEvent(MessageEvent e) { |
262 |
for (int i = 0; i < e.getMessages().length; i++){ |
263 |
String traza = dumpStackTrace(e.getExceptions()[i]);
|
264 |
|
265 |
info.append("<"+marcaInfo+">" + e.getMessages()[i] + "</"+marcaInfo+"><br/" + traza); |
266 |
all.append("<"+marcaInfo+">" + e.getMessages()[i] + "</"+marcaInfo+"><br/" + traza); |
267 |
} |
268 |
textoInfos.setText(info.toString() ); |
269 |
textoAll.setText(all.toString()); |
270 |
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getModel()
|
275 |
*/
|
276 |
public Object getWindowModel() { |
277 |
return "consola"; |
278 |
} |
279 |
|
280 |
/**
|
281 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
282 |
*/
|
283 |
public WindowInfo getWindowInfo() {
|
284 |
WindowInfo info = new WindowInfo(WindowInfo.MODELESSDIALOG|WindowInfo.RESIZABLE|WindowInfo.MAXIMIZABLE|WindowInfo.ICONIFIABLE);
|
285 |
info.setTitle(PluginServices.getText(this, "titulo_consola")); |
286 |
return info;
|
287 |
} |
288 |
|
289 |
|
290 |
} |