Statistics
| Revision:

root / trunk / libraries / libCorePlugin / src / com / iver / core / ConsolaFrame.java @ 35160

History | View | Annotate | Download (9.96 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
        public static final int WIDTH = 500;
78
        public static final int HEIGHT = 270;
79

    
80
    /**
81
     * Crea la consola con los mensajes producidos hasta el momento de la
82
     * creaci?n de este objeto.
83
     *
84
     * @param todo Array de todos los mensajes
85
     * @param infos Array de los mensajes de informaci?n
86
     * @param warns Array de los mensajes de warning
87
     * @param errors Array de los mensajes de error
88
     */
89
    public ConsolaFrame() {
90

    
91
                this.setSize(WIDTH,HEIGHT);
92

    
93
        //Las cajas de texto donde van los mensajes
94
        textoInfos = new JEditorPane();
95
        textoInfos.setEditable(false);
96
                textoInfos.setContentType("text/html");
97
        textoWarnings = new JEditorPane();
98
        textoWarnings.setEditable(false);
99
                textoWarnings.setContentType("text/html");
100
        textoErrores = new JEditorPane();
101
        textoErrores.setEditable(false);
102
                textoErrores.setContentType("text/html");
103
        textoAll = new JEditorPane();
104
        textoAll.setEditable(false);
105
                textoAll.setContentType("text/html");
106

    
107
                JScrollPane scroll = new JScrollPane(textoAll);
108
                scroll.setVerticalScrollBarPolicy(
109
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
110
                scroll.setHorizontalScrollBarPolicy(
111
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
112
//                scroll.setPreferredSize(new Dimension(500, 500));
113
//                scroll.setMinimumSize(new Dimension(10, 10));
114
                JPanel panelAll = new JPanel(new BorderLayout());
115
                panelAll.add(scroll, BorderLayout.CENTER);
116
                
117
                scroll = new JScrollPane(textoInfos);
118
                scroll.setVerticalScrollBarPolicy(
119
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
120
                scroll.setHorizontalScrollBarPolicy(
121
                        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
122
//                scroll.setPreferredSize(new Dimension(250, 145));
123
//                scroll.setMinimumSize(new Dimension(10, 10));
124
                JPanel panelInfos = new JPanel(new BorderLayout());
125
                panelInfos.add(scroll, BorderLayout.CENTER);
126
                
127
                scroll = new JScrollPane(textoWarnings);
128
                scroll.setVerticalScrollBarPolicy(
129
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
130
                scroll.setHorizontalScrollBarPolicy(
131
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
132
//                scroll.setPreferredSize(new Dimension(250, 145));
133
//                scroll.setMinimumSize(new Dimension(10, 10));
134
                JPanel panelWarnings = new JPanel(new BorderLayout());
135
                panelWarnings.add(scroll, BorderLayout.CENTER);
136
                
137
                scroll = new JScrollPane(textoErrores);
138
                scroll.setVerticalScrollBarPolicy(
139
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
140
                scroll.setHorizontalScrollBarPolicy(
141
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
142
//                scroll.setPreferredSize(new Dimension(250, 145));
143
//                scroll.setMinimumSize(new Dimension(10, 10));
144
                panelErrores = new JPanel(new BorderLayout());
145
                panelErrores.add(scroll, BorderLayout.CENTER);
146

    
147
//        rellenar(infos, textoInfos, info, marcaInfo);
148
  //      rellenar(warns, textoWarnings, warn, marcaWarning);
149
    //    rellenar(errors, textoErrores, error, marcaError);
150
      //  rellenarTodo(todo, textoAll);
151

    
152
        //Las pesta?as
153
        tabs = new JTabbedPane();
154
        tabs.addTab(PluginServices.getText( this ,"todos"), panelAll);
155
        tabs.addTab(PluginServices.getText( this ,"info"), panelInfos);
156
        tabs.addTab(PluginServices.getText( this ,"warnings"), panelWarnings);
157
        tabs.addTab(PluginServices.getText( this ,"errores"), panelErrores);
158
                this.setLayout(new BorderLayout());
159
        this.add(tabs, BorderLayout.CENTER);
160
        
161
    }
162

    
163
        /**
164
         * M?todo de utilidad para rellenar los cuadros de texto con un array de
165
         * cadenas
166
         *
167
         * @param contenido array de cadenas que se mostrar?n en el cuadro de texto
168
         *        separadas por un retorno de carro
169
         * @param control Control en el que se pondr?n las cadenas
170
         */
171
        private void rellenar(String[] contenido, JEditorPane control, StringBuffer buffer, String marca) {
172
                String content = "";
173
                for (int i = 0; i < contenido.length; i++) {
174
                        content = content + "<"+marca+">"+contenido[i] + "</"+marca+"><br/";
175
                }
176
                        
177
                buffer.append(content);
178

    
179
                control.setContentType("text/html");
180
                control.setText(content);
181
        }
182

    
183
        /*
184
         * M?todo de utilidad para rellenar los cuadros de texto con un array de
185
         * cadenas
186
         *
187
         * @param contenido array de cadenas que se mostrar?n en el cuadro de texto
188
         *        separadas por un retorno de carro
189
         * @param control Control en el que se pondr?n las cadenas
190
         *
191
        private void rellenarTodo(Message[] contenido, JEditorPane control) {
192
                HashMap marcasTipoMsg = new HashMap();
193
                marcasTipoMsg.put(new Integer(Message.INFO), marcaInfo);
194
                marcasTipoMsg.put(new Integer(Message.WARNING), marcaWarning);
195
                marcasTipoMsg.put(new Integer(Message.ERROR), marcaError);
196

197
                String content = "";
198
                for (int i = 0; i < contenido.length; i++) {
199
                        String marca = (String) marcasTipoMsg.get(new Integer(contenido[i].tipo));
200
                        content = content + "<"+marca+">"+contenido[i].texto + "</"+marca+"><br/";
201
                }
202

203
                all.append(content);
204

205
                control.setContentType("text/html");
206
                control.setText(content);
207
        }*/
208

    
209

    
210
        /**
211
         * Obtiene un string con la traza de una excepci?n a la consola
212
         *
213
         * @param t Elemento throwable
214
         */
215
        private static String dumpStackTrace(Throwable t) {
216
                if ( t == null ) return "";
217
                StackTraceElement[] stes = t.getStackTrace();
218
                String todo = "<"+marcaWarning+">" + t.getClass().getName() + ": " + t.getLocalizedMessage() +
219
                        "<"+marcaWarning+">" + "<br/";
220

    
221
                for (int i = 0; i < stes.length; i++) {
222
                        todo += ("<"+marcaWarning+">&nbsp;&nbsp;&nbsp;&nbsp;" + stes[i].toString() + "<br/");
223
                }
224

    
225
                if (t.getCause() != null) {
226
                        todo = todo + dumpStackTrace(t.getCause());
227
                }
228
        
229
                return todo;
230
        }
231

    
232
    /**
233
     * @see com.iver.mdiApp.NotificationListener#errorEvent(java.lang.String)
234
     */
235
    public void errorEvent(MessageEvent e) {
236
            for (int i = 0; i < e.getMessages().length; i++){
237
                    String traza = dumpStackTrace(e.getExceptions()[i]);
238

    
239
                        error.append("<"+marcaError+">" + e.getMessages()[i] + "</"+marcaError+"><br/" + traza);
240
                        all.append("<"+marcaError+">" + e.getMessages()[i] + "</"+marcaError+"><br/" + traza);
241
            }
242
                textoErrores.setText(error.toString());
243
                textoAll.setText(all.toString());
244
                tabs.setSelectedComponent(panelErrores);
245
    }
246

    
247
    /**
248
     * @see com.iver.mdiApp.NotificationListener#warningEvent(java.lang.String)
249
     */
250
    public void warningEvent(MessageEvent e) {
251
                for (int i = 0; i < e.getMessages().length; i++){
252
                        String traza = dumpStackTrace(e.getExceptions()[i]);
253

    
254
                        warn.append("<"+marcaWarning+">" + e.getMessages()[i] + "</"+marcaWarning+"><br/" + traza);
255
                        all.append("<"+marcaWarning+">" + e.getMessages()[i] + "</"+marcaWarning+"><br/" + traza);
256
                }
257
                textoWarnings.setText(warn.toString());
258
                textoAll.setText(all.toString());
259
    }
260

    
261
    /**
262
     * @see com.iver.mdiApp.NotificationListener#infoEvent(java.lang.String)
263
     */
264
    public void infoEvent(MessageEvent e) {
265
                for (int i = 0; i < e.getMessages().length; i++){
266
                        String traza = dumpStackTrace(e.getExceptions()[i]);
267
                        
268
                        info.append("<"+marcaInfo+">" + e.getMessages()[i] + "</"+marcaInfo+"><br/" + traza);
269
                        all.append("<"+marcaInfo+">" + e.getMessages()[i] + "</"+marcaInfo+"><br/" + traza);
270
                }
271
                textoInfos.setText(info.toString() );
272
                textoAll.setText(all.toString());
273

    
274
    }
275

    
276
        /**
277
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#getModel()
278
         */
279
        public Object getWindowModel() {
280
                return "consola";
281
        }
282

    
283
        /**
284
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
285
         */
286
        public WindowInfo getWindowInfo() {
287
                WindowInfo info = new WindowInfo(WindowInfo.MODELESSDIALOG|WindowInfo.RESIZABLE|WindowInfo.MAXIMIZABLE|WindowInfo.ICONIFIABLE);
288
                info.setTitle(PluginServices.getText(this, "titulo_consola"));
289
                return info;
290
        }
291

    
292
        public Object getWindowProfile() {
293
                return WindowInfo.PROPERTIES_PROFILE;
294
        }
295
        
296
}
297

    
298
// [eiel-gestion-excepciones]