Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / gui / HTMLInfoPanel.java @ 40558

History | View | Annotate | Download (6.5 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 {Iver T.I.}   {Task}
49
*/
50
 
51
package org.gvsig.app.project.documents.view.toc.gui;
52

    
53
import java.awt.BorderLayout;
54
import java.awt.Dimension;
55
import java.awt.event.ItemEvent;
56
import java.awt.event.ItemListener;
57

    
58
import javax.swing.JEditorPane;
59
import javax.swing.JScrollPane;
60

    
61
import org.gvsig.andami.PluginServices;
62
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
63
import org.gvsig.utils.swing.JComboBox;
64

    
65

    
66
/**
67
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
68
 */
69
public abstract class HTMLInfoPanel extends AbstractPanel{
70
        private final String      bgColor0        = "\"#FEEDD6\""; // light salmon
71
        private final String      bgColor1        = "\"#EAEAEA\""; // light grey
72
        private final String      bgColor3        = "\"#FBFFE1\""; // light yellow
73
        private final String      bgColor4        = "\"#D6D6D6\""; // Gris
74
        private final String      bgColorBody     = "\"#FFFFFF\""; // white
75
        
76
        private JScrollPane       jScrollPane     = null;
77
        public JEditorPane        jEditorPane     = null;
78
        private JComboBox         jComboBox       = null;
79
                
80
        /**
81
         * 
82
         */
83
        public HTMLInfoPanel() {
84
                super();
85
                setLabel(PluginServices.getText(this, "info"));
86
                initialize();
87
        }
88

    
89
        /**
90
         * This method initializes this
91
         *
92
         * @return void
93
         */
94
        protected void initialize() {
95
                this.setLayout(new BorderLayout(5, 5));
96
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
97
                this.add(getJScrollPane(), BorderLayout.CENTER);                
98
                this.getJEditorPane().repaint();                
99
        }        
100
        
101
        /**
102
         * This method initializes jScrollPane
103
         *
104
         * @return javax.swing.JScrollPane
105
         */
106
        private JScrollPane getJScrollPane() {
107
                if (jScrollPane == null) {
108
                        jScrollPane = new JScrollPane();
109
                        jScrollPane.setViewportView(getJEditorPane());
110
                }
111
                return jScrollPane;
112
        }
113

    
114
        /**
115
         * This method initializes jEditorPane
116
         *
117
         * @return javax.swing.JEditorPane
118
         */
119
        private JEditorPane getJEditorPane() {
120
                if (jEditorPane == null) {
121
                        jEditorPane = new JEditorPane();
122
                        jEditorPane.setEditable(false);
123
                        jEditorPane.setContentType("text/html");
124
                }
125
                return jEditorPane;
126
        }
127
        
128
        /**
129
         * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
130
         * es impar.
131
         */
132
        private boolean           rowColor        = true;
133
        
134
        /**
135
         * Controla la alternatividad de colores en la tabla.
136
         *
137
         * @return Cadena con el color de la fila siguiente.
138
         */
139
        private String getColor() {
140
                String color = (rowColor ? bgColor0 : bgColor1);
141
                rowColor = !rowColor;
142
                return color;
143
        }
144

    
145
        /**
146
         * Obtiene una entrada de la tabla en formato HTML a partir de una propiedad,
147
         * un valor y un color.
148
         *
149
         * @param prop
150
         *          Nombre de la propiedad
151
         * @param value
152
         *          Valor
153
         * @param color
154
         *          Color
155
         *
156
         * @return Entrada HTML de la tabla
157
         */
158
        protected String setHTMLBasicProperty(String prop, String value) {
159
                String content = "<tr valign=\"top\">";
160
                if (prop != null)
161
                        content += "<td bgcolor=" + bgColor4 + "align=\"right\" width=\"33%\"><font face=\"Arial\" size=\"3\">" + prop + ":&nbsp;</font></td>";
162
                content += "<td bgcolor=" + getColor() + "align=\"left\" width=\"67%\"><font face=\"Arial\" size=\"3\">" + value + "</font></td>";
163
                content += "</tr>";
164

    
165
                return content;
166
        }
167

    
168
        /**
169
         * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
170
         *
171
         * @param title
172
         *          Nombre del titulo
173
         * @param colspan
174
         *          Numero de celdas que ocupara el titulo
175
         *
176
         * @return Entrada HTML del titulo
177
         */
178
        protected String setHTMLTitleTable(String title, int colspan) {
179
                return
180
                        "<tr valign=\"middle\" >" +
181
                        "<td bgcolor=" + bgColor3 + " align=\"center\" colspan=\"" + colspan + "\"><font face=\"Arial\" size=\"3\"><b> " + title + "</b></font></td>" +
182
                        "</tr>";
183
        }
184

    
185
        /**
186
         * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
187
         *
188
         * @param content
189
         *          Codigo HTML de las filas que componen la tabla.
190
         *
191
         * @return Entrada HTML de la tabla completa
192
         */
193
        protected String setHTMLTable(String content) {
194
                return "<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">" + content + "</table>";
195
        }
196

    
197
        /**
198
         * Genera el HTML para todo el contenido.
199
         *
200
         * @param content
201
         *          Codigo HTML que ira en el <body>...</body>.
202
         *
203
         * @return HTML completo
204
         */
205
        protected String setHTMLBody(String content) {
206
                String html = "<html>";
207
                html += "<body bgcolor=" + bgColorBody + " topmargin=\"0\" marginheight=\"0\">";
208
                html += content;
209
                html += "</body>";
210
                html += "</html>";
211
                return html;
212
        }
213
        
214
        /**
215
         * Add the HTML code t the form
216
         * @param content
217
         */
218
        protected void addHTMLToPanel(String content){
219
                this.getJEditorPane().setContentType("text/html");
220
                this.getJEditorPane().setText(content);
221
                this.getJEditorPane().setCaretPosition(0);
222
        }
223
}
224