Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / ConsolaFrame.java @ 29630

History | View | Annotate | Download (9.85 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 org.gvsig.coreplugin;
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 org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.messages.MessageEvent;
52
import org.gvsig.andami.messages.NotificationListener;
53
import org.gvsig.andami.ui.mdiManager.IWindow;
54
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
55
import org.gvsig.andami.ui.mdiManager.WindowInfo;
56

    
57

    
58
/**
59
 * Frame que escucha los eventos del sistema de mensajes de la aplicaci?n y los
60
 * muestra.
61
 */
62
public class ConsolaFrame extends JPanel implements IWindow, SingletonWindow,NotificationListener {
63
        private StringBuffer info = new StringBuffer();
64
        private StringBuffer warn = new StringBuffer();
65
        private StringBuffer error = new StringBuffer();
66
        private StringBuffer all = new StringBuffer();
67
        private JEditorPane textoInfos;
68
        private JEditorPane textoWarnings;
69
        private JEditorPane textoErrores;
70
        private JEditorPane textoAll;
71

    
72
        private final static String marcaInfo ="font size='3' color='#000000'";
73
        private final static String marcaWarning ="font size='3' color='#800000'";
74
        private final static String marcaError ="font size='3' color='#FF0000'";
75
        private JTabbedPane tabs;
76
        private JPanel panelErrores;
77

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

    
89
                this.setSize(400, 325);
90

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

    
105
                JScrollPane scroll = new JScrollPane(textoAll);
106
                scroll.setVerticalScrollBarPolicy(
107
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
108
                scroll.setHorizontalScrollBarPolicy(
109
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
110
//                scroll.setPreferredSize(new Dimension(500, 500));
111
//                scroll.setMinimumSize(new Dimension(10, 10));
112
                JPanel panelAll = new JPanel(new BorderLayout());
113
                panelAll.add(scroll, BorderLayout.CENTER);
114

    
115
                scroll = new JScrollPane(textoInfos);
116
                scroll.setVerticalScrollBarPolicy(
117
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
118
                scroll.setHorizontalScrollBarPolicy(
119
                        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
120
//                scroll.setPreferredSize(new Dimension(250, 145));
121
//                scroll.setMinimumSize(new Dimension(10, 10));
122
                JPanel panelInfos = new JPanel(new BorderLayout());
123
                panelInfos.add(scroll, BorderLayout.CENTER);
124

    
125
                scroll = new JScrollPane(textoWarnings);
126
                scroll.setVerticalScrollBarPolicy(
127
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
128
                scroll.setHorizontalScrollBarPolicy(
129
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
130
//                scroll.setPreferredSize(new Dimension(250, 145));
131
//                scroll.setMinimumSize(new Dimension(10, 10));
132
                JPanel panelWarnings = new JPanel(new BorderLayout());
133
                panelWarnings.add(scroll, BorderLayout.CENTER);
134

    
135
                scroll = new JScrollPane(textoErrores);
136
                scroll.setVerticalScrollBarPolicy(
137
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
138
                scroll.setHorizontalScrollBarPolicy(
139
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
140
//                scroll.setPreferredSize(new Dimension(250, 145));
141
//                scroll.setMinimumSize(new Dimension(10, 10));
142
                panelErrores = new JPanel(new BorderLayout());
143
                panelErrores.add(scroll, BorderLayout.CENTER);
144

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

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

    
159
    }
160

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

    
175
                buffer.append(content);
176

    
177
                control.setContentType("text/html");
178
                control.setText(content);
179
        }
180

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

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

201
                all.append(content);
202

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

    
207

    
208
        /**
209
         * Obtiene un string con la traza de una excepci?n a la consola
210
         *
211
         * @param t Elemento throwable
212
         */
213
        private static String dumpStackTrace(Throwable t) {
214
                if ( t == null ) {
215
                        return "";
216
                }
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 org.gvsig.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
}