Revision 717 trunk/libraries/libCorePlugin/src/com/iver/core/ConsolaFrame.java
ConsolaFrame.java | ||
---|---|---|
1 | 1 |
package com.iver.core; |
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 |
import java.awt.event.ActionEvent;
|
|
5 |
import java.awt.event.ActionListener;
|
|
4 |
import java.awt.event.MouseEvent;
|
|
5 |
import java.awt.event.MouseListener;
|
|
6 | 6 |
|
7 | 7 |
import javax.swing.JEditorPane; |
8 | 8 |
import javax.swing.JPanel; |
... | ... | |
13 | 13 |
import com.iver.andami.messages.MessageEvent; |
14 | 14 |
import com.iver.andami.messages.NotificationListener; |
15 | 15 |
import com.iver.andami.ui.mdiManager.SingletonView; |
16 |
import com.iver.andami.ui.mdiManager.View; |
|
16 | 17 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
17 |
import com.iver.andami.ui.mdiManager.ViewListener; |
|
18 | 18 |
|
19 | 19 |
/** |
20 | 20 |
* Frame que escucha los eventos del sistema de mensajes de la aplicaci?n y los |
21 | 21 |
* muestra. |
22 | 22 |
*/ |
23 |
public class ConsolaFrame extends JPanel implements ViewListener, SingletonView, NotificationListener {
|
|
23 |
public class ConsolaFrame extends JPanel implements View, SingletonView, NotificationListener { |
|
24 | 24 |
private StringBuffer info = new StringBuffer(); |
25 | 25 |
private StringBuffer warn = new StringBuffer(); |
26 | 26 |
private StringBuffer error = new StringBuffer(); |
... | ... | |
38 | 38 |
* Crea la consola con los mensajes producidos hasta el momento de la |
39 | 39 |
* creaci?n de este objeto. |
40 | 40 |
* |
41 |
* @param todo Array de todos los mensajes |
|
42 |
* @param infos Array de los mensajes de informaci?n |
|
43 |
* @param warns Array de los mensajes de warning |
|
44 |
* @param errors Array de los mensajes de error |
|
41 | 45 |
*/ |
42 | 46 |
public ConsolaFrame() { |
43 | 47 |
|
48 |
this.setSize(400, 325); |
|
49 |
|
|
44 | 50 |
//Las cajas de texto donde van los mensajes |
45 | 51 |
textoInfos = new JEditorPane(); |
46 | 52 |
textoInfos.setEditable(false); |
53 |
textoInfos.setContentType("text/html"); |
|
47 | 54 |
textoWarnings = new JEditorPane(); |
48 | 55 |
textoWarnings.setEditable(false); |
56 |
textoWarnings.setContentType("text/html"); |
|
49 | 57 |
textoErrores = new JEditorPane(); |
50 | 58 |
textoErrores.setEditable(false); |
59 |
textoErrores.setContentType("text/html"); |
|
51 | 60 |
textoAll = new JEditorPane(); |
52 |
textoAll.setEditable(true); |
|
53 |
Consola.ps.addPopupMenuListener("foopopup", textoAll, new ActionListener() { |
|
54 |
public void actionPerformed(ActionEvent e) { |
|
55 |
PluginServices.getMDIManager().closeAllViews(); |
|
56 |
} |
|
57 |
}); |
|
58 |
|
|
61 |
textoAll.setEditable(false); |
|
62 |
textoAll.setContentType("text/html"); |
|
63 |
|
|
59 | 64 |
JScrollPane scroll = new JScrollPane(textoAll); |
60 | 65 |
scroll.setVerticalScrollBarPolicy( |
61 | 66 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
... | ... | |
96 | 101 |
JPanel panelErrores = new JPanel(new BorderLayout()); |
97 | 102 |
panelErrores.add(scroll, BorderLayout.CENTER); |
98 | 103 |
|
104 |
// rellenar(infos, textoInfos, info, marcaInfo); |
|
105 |
// rellenar(warns, textoWarnings, warn, marcaWarning); |
|
106 |
// rellenar(errors, textoErrores, error, marcaError); |
|
107 |
// rellenarTodo(todo, textoAll); |
|
108 |
|
|
99 | 109 |
//Las pesta?as |
100 | 110 |
JTabbedPane tabs = new JTabbedPane(); |
101 |
tabs.addTab(Consola.ps.getText("todos"), panelAll);
|
|
102 |
tabs.addTab(Consola.ps.getText("info"), panelInfos);
|
|
103 |
tabs.addTab(Consola.ps.getText("warnings"), panelWarnings);
|
|
104 |
tabs.addTab(Consola.ps.getText("errores"), panelErrores);
|
|
111 |
tabs.addTab(PluginServices.getText( this ,"todos"), panelAll);
|
|
112 |
tabs.addTab(PluginServices.getText( this ,"info"), panelInfos);
|
|
113 |
tabs.addTab(PluginServices.getText( this ,"warnings"), panelWarnings);
|
|
114 |
tabs.addTab(PluginServices.getText( this ,"errores"), panelErrores);
|
|
105 | 115 |
this.setLayout(new BorderLayout()); |
106 | 116 |
this.add(tabs, BorderLayout.CENTER); |
117 |
|
|
107 | 118 |
} |
108 | 119 |
|
109 | 120 |
/** |
... | ... | |
126 | 137 |
control.setText(content); |
127 | 138 |
} |
128 | 139 |
|
140 |
/* |
|
141 |
* M?todo de utilidad para rellenar los cuadros de texto con un array de |
|
142 |
* cadenas |
|
143 |
* |
|
144 |
* @param contenido array de cadenas que se mostrar?n en el cuadro de texto |
|
145 |
* separadas por un retorno de carro |
|
146 |
* @param control Control en el que se pondr?n las cadenas |
|
147 |
* |
|
148 |
private void rellenarTodo(Message[] contenido, JEditorPane control) { |
|
149 |
HashMap marcasTipoMsg = new HashMap(); |
|
150 |
marcasTipoMsg.put(new Integer(Message.INFO), marcaInfo); |
|
151 |
marcasTipoMsg.put(new Integer(Message.WARNING), marcaWarning); |
|
152 |
marcasTipoMsg.put(new Integer(Message.ERROR), marcaError); |
|
153 |
|
|
154 |
String content = ""; |
|
155 |
for (int i = 0; i < contenido.length; i++) { |
|
156 |
String marca = (String) marcasTipoMsg.get(new Integer(contenido[i].tipo)); |
|
157 |
content = content + "<"+marca+">"+contenido[i].texto + "</"+marca+"><br/"; |
|
158 |
} |
|
159 |
|
|
160 |
all.append(content); |
|
161 |
|
|
162 |
control.setContentType("text/html"); |
|
163 |
control.setText(content); |
|
164 |
}*/ |
|
165 |
|
|
166 |
|
|
129 | 167 |
/** |
168 |
* Obtiene un string con la traza de una excepci?n a la consola |
|
169 |
* |
|
170 |
* @param t Elemento throwable |
|
171 |
*/ |
|
172 |
private static String dumpStackTrace(Throwable t) { |
|
173 |
if ( t == null ) return ""; |
|
174 |
StackTraceElement[] stes = t.getStackTrace(); |
|
175 |
String todo = "<"+marcaWarning+">" + t.getClass().getName() + ": " + t.getLocalizedMessage() + |
|
176 |
"<"+marcaWarning+">" + "<br/"; |
|
177 |
|
|
178 |
for (int i = 0; i < stes.length; i++) { |
|
179 |
todo += ("<"+marcaWarning+"> " + stes[i].toString() + "<br/"); |
|
180 |
} |
|
181 |
|
|
182 |
if (t.getCause() != null) { |
|
183 |
todo = todo + dumpStackTrace(t.getCause()); |
|
184 |
} |
|
185 |
|
|
186 |
return todo; |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
130 | 190 |
* @see com.iver.mdiApp.NotificationListener#errorEvent(java.lang.String) |
131 | 191 |
*/ |
132 | 192 |
public void errorEvent(MessageEvent e) { |
133 |
error.append("<"+marcaError+">" + e + "</"+marcaError+"><br/"); |
|
193 |
for (int i = 0; i < e.getMessages().length; i++){ |
|
194 |
String traza = dumpStackTrace(e.getExceptions()[i]); |
|
195 |
|
|
196 |
error.append("<"+marcaError+">" + e.getMessages()[i] + "</"+marcaError+"><br/" + traza); |
|
197 |
all.append("<"+marcaError+">" + e.getMessages()[i] + "</"+marcaError+"><br/" + traza); |
|
198 |
} |
|
134 | 199 |
textoErrores.setText(error.toString()); |
135 |
all.append("<"+marcaError+">" + e + "</"+marcaError+"><br/"); |
|
136 | 200 |
textoAll.setText(all.toString()); |
201 |
PluginServices.getMDIManager().addView(this); |
|
137 | 202 |
} |
138 | 203 |
|
139 | 204 |
/** |
140 | 205 |
* @see com.iver.mdiApp.NotificationListener#warningEvent(java.lang.String) |
141 | 206 |
*/ |
142 |
public void warningEvent(MessageEvent w) { |
|
143 |
warn.append("<"+marcaWarning+">" + w + "</"+marcaWarning+"><br/"); |
|
207 |
public void warningEvent(MessageEvent e) { |
|
208 |
for (int i = 0; i < e.getMessages().length; i++){ |
|
209 |
String traza = dumpStackTrace(e.getExceptions()[i]); |
|
210 |
|
|
211 |
warn.append("<"+marcaWarning+">" + e.getMessages()[i] + "</"+marcaWarning+"><br/" + traza); |
|
212 |
all.append("<"+marcaWarning+">" + e.getMessages()[i] + "</"+marcaWarning+"><br/" + traza); |
|
213 |
} |
|
144 | 214 |
textoWarnings.setText(warn.toString()); |
145 |
all.append("<"+marcaWarning+">" + w + "</"+marcaWarning+"><br/"); |
|
146 | 215 |
textoAll.setText(all.toString()); |
147 | 216 |
} |
148 | 217 |
|
149 | 218 |
/** |
150 | 219 |
* @see com.iver.mdiApp.NotificationListener#infoEvent(java.lang.String) |
151 | 220 |
*/ |
152 |
public void infoEvent(MessageEvent i) { |
|
153 |
info.append("<"+marcaInfo+">" + i + "</"+marcaInfo+"><br/"); |
|
154 |
textoInfos.setText(info.toString() ); |
|
155 |
all.append("<"+marcaInfo+">" + i + "</"+marcaInfo+"><br/"); |
|
156 |
textoAll.setText(all.toString()); |
|
221 |
public void infoEvent(MessageEvent e) { |
|
222 |
for (int i = 0; i < e.getMessages().length; i++){ |
|
223 |
String traza = dumpStackTrace(e.getExceptions()[i]); |
|
224 |
|
|
225 |
info.append("<"+marcaInfo+">" + e.getMessages()[i] + "</"+marcaInfo+"><br/" + traza); |
|
226 |
all.append("<"+marcaInfo+">" + e.getMessages()[i] + "</"+marcaInfo+"><br/" + traza); |
|
227 |
} |
|
228 |
textoInfos.setText(info.toString() ); |
|
229 |
textoAll.setText(all.toString()); |
|
230 |
|
|
157 | 231 |
} |
158 | 232 |
|
159 | 233 |
/** |
... | ... | |
163 | 237 |
return "consola"; |
164 | 238 |
} |
165 | 239 |
|
166 |
/* (non-Javadoc) |
|
167 |
* @see com.iver.andami.ui.mdiManager.View#viewActivated() |
|
168 |
*/ |
|
169 |
public void viewActivated() { |
|
170 |
// TODO Auto-generated method stub |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 | 240 |
/** |
175 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
|
241 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
|
176 | 242 |
*/ |
177 | 243 |
public ViewInfo getViewInfo() { |
178 |
ViewInfo info = new ViewInfo(ViewInfo.MODELESSDIALOG|ViewInfo.RESIZABLE|ViewInfo.MAXIMIZABLE|ViewInfo.ICONIFIABLE); |
|
179 |
info.setTitle("consola"); |
|
180 |
info.setWidth(500); |
|
181 |
info.setHeight(525); |
|
182 |
|
|
244 |
ViewInfo info = new ViewInfo(ViewInfo.ALWAYSLIVE|ViewInfo.MODELESSDIALOG|ViewInfo.RESIZABLE|ViewInfo.MAXIMIZABLE|ViewInfo.ICONIFIABLE); |
|
245 |
info.setTitle(PluginServices.getText(this, "titulo_consola")); |
|
183 | 246 |
return info; |
184 | 247 |
} |
185 |
|
|
186 |
/* (non-Javadoc) |
|
187 |
* @see com.iver.andami.ui.mdiManager.View#viewClosed() |
|
188 |
*/ |
|
189 |
public void viewClosed() { |
|
190 |
System.err.println("Me han chapao"); |
|
191 |
} |
|
192 |
|
|
193 | 248 |
} |
Also available in: Unified diff