Statistics
| Revision:

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

History | View | Annotate | Download (6.44 KB)

1 592 fernando
package com.iver.core;
2
3
import java.awt.BorderLayout;
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6
7
import javax.swing.JEditorPane;
8
import javax.swing.JPanel;
9
import javax.swing.JScrollPane;
10
import javax.swing.JTabbedPane;
11
12
import com.iver.andami.PluginServices;
13
import com.iver.andami.messages.MessageEvent;
14
import com.iver.andami.messages.NotificationListener;
15
import com.iver.andami.ui.mdiManager.SingletonView;
16
import com.iver.andami.ui.mdiManager.ViewInfo;
17
import com.iver.andami.ui.mdiManager.ViewListener;
18
19
/**
20
 * Frame que escucha los eventos del sistema de mensajes de la aplicaci?n y los
21
 * muestra.
22
 */
23
public class ConsolaFrame extends JPanel implements ViewListener, SingletonView, NotificationListener {
24
        private StringBuffer info = new StringBuffer();
25
        private StringBuffer warn = new StringBuffer();
26
        private StringBuffer error = new StringBuffer();
27
        private StringBuffer all = new StringBuffer();
28
        private JEditorPane textoInfos;
29
        private JEditorPane textoWarnings;
30
        private JEditorPane textoErrores;
31
        private JEditorPane textoAll;
32
33
        private final static String marcaInfo ="font size='3' color='#000000'";
34
        private final static String marcaWarning ="font size='3' color='#800000'";
35
        private final static String marcaError ="font size='3' color='#FF0000'";
36
37
    /**
38
     * Crea la consola con los mensajes producidos hasta el momento de la
39
     * creaci?n de este objeto.
40
     *
41
     */
42
    public ConsolaFrame() {
43
44
        //Las cajas de texto donde van los mensajes
45
        textoInfos = new JEditorPane();
46
        textoInfos.setEditable(false);
47
        textoWarnings = new JEditorPane();
48
        textoWarnings.setEditable(false);
49
        textoErrores = new JEditorPane();
50
        textoErrores.setEditable(false);
51
        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
59
                JScrollPane scroll = new JScrollPane(textoAll);
60
                scroll.setVerticalScrollBarPolicy(
61
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
62
                scroll.setHorizontalScrollBarPolicy(
63
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
64
//                scroll.setPreferredSize(new Dimension(500, 500));
65
//                scroll.setMinimumSize(new Dimension(10, 10));
66
                JPanel panelAll = new JPanel(new BorderLayout());
67
                panelAll.add(scroll, BorderLayout.CENTER);
68
69
                scroll = new JScrollPane(textoInfos);
70
                scroll.setVerticalScrollBarPolicy(
71
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
72
                scroll.setHorizontalScrollBarPolicy(
73
                        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
74
//                scroll.setPreferredSize(new Dimension(250, 145));
75
//                scroll.setMinimumSize(new Dimension(10, 10));
76
                JPanel panelInfos = new JPanel(new BorderLayout());
77
                panelInfos.add(scroll, BorderLayout.CENTER);
78
79
                scroll = new JScrollPane(textoWarnings);
80
                scroll.setVerticalScrollBarPolicy(
81
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
82
                scroll.setHorizontalScrollBarPolicy(
83
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
84
//                scroll.setPreferredSize(new Dimension(250, 145));
85
//                scroll.setMinimumSize(new Dimension(10, 10));
86
                JPanel panelWarnings = new JPanel(new BorderLayout());
87
                panelWarnings.add(scroll, BorderLayout.CENTER);
88
89
                scroll = new JScrollPane(textoErrores);
90
                scroll.setVerticalScrollBarPolicy(
91
                                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
92
                scroll.setHorizontalScrollBarPolicy(
93
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
94
//                scroll.setPreferredSize(new Dimension(250, 145));
95
//                scroll.setMinimumSize(new Dimension(10, 10));
96
                JPanel panelErrores = new JPanel(new BorderLayout());
97
                panelErrores.add(scroll, BorderLayout.CENTER);
98
99
        //Las pesta?as
100
        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);
105
                this.setLayout(new BorderLayout());
106
        this.add(tabs, BorderLayout.CENTER);
107
    }
108
109
        /**
110
         * M?todo de utilidad para rellenar los cuadros de texto con un array de
111
         * cadenas
112
         *
113
         * @param contenido array de cadenas que se mostrar?n en el cuadro de texto
114
         *        separadas por un retorno de carro
115
         * @param control Control en el que se pondr?n las cadenas
116
         */
117
        private void rellenar(String[] contenido, JEditorPane control, StringBuffer buffer, String marca) {
118
                String content = "";
119
                for (int i = 0; i < contenido.length; i++) {
120
                        content = content + "<"+marca+">"+contenido[i] + "</"+marca+"><br/";
121
                }
122
123
                buffer.append(content);
124
125
                control.setContentType("text/html");
126
                control.setText(content);
127
        }
128
129
        /**
130
     * @see com.iver.mdiApp.NotificationListener#errorEvent(java.lang.String)
131
     */
132
    public void errorEvent(MessageEvent e) {
133
        error.append("<"+marcaError+">" + e + "</"+marcaError+"><br/");
134
                textoErrores.setText(error.toString());
135
        all.append("<"+marcaError+">" + e + "</"+marcaError+"><br/");
136
                textoAll.setText(all.toString());
137
    }
138
139
    /**
140
     * @see com.iver.mdiApp.NotificationListener#warningEvent(java.lang.String)
141
     */
142
    public void warningEvent(MessageEvent w) {
143
                warn.append("<"+marcaWarning+">" + w + "</"+marcaWarning+"><br/");
144
                textoWarnings.setText(warn.toString());
145
                all.append("<"+marcaWarning+">" + w + "</"+marcaWarning+"><br/");
146
                textoAll.setText(all.toString());
147
    }
148
149
    /**
150
     * @see com.iver.mdiApp.NotificationListener#infoEvent(java.lang.String)
151
     */
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());
157
    }
158
159
        /**
160
         * @see com.iver.mdiApp.ui.MDIManager.View#getModel()
161
         */
162
        public Object getViewModel() {
163
                return "consola";
164
        }
165
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
        /**
175
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
176
         */
177
        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
183
                return info;
184
        }
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
}