Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / swing / JTextPreview.java @ 13136

History | View | Annotate | Download (3.58 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

    
42
/* CVS MESSAGES:
43
*
44
* $Id: JTextPreview.java 13136 2007-08-20 08:38:34Z evercher $
45
* $Log$
46
* Revision 1.1  2007-08-20 08:34:46  evercher
47
* He fusionado LibUI con LibUIComponents
48
*
49
* Revision 1.2  2006/11/28 09:30:12  ppiqueras
50
* Cambiado PluginServices.getText(..., ...) por Messages.getText(...)
51
*
52
* Revision 1.1  2006/09/18 08:00:34  jaume
53
* *** empty log message ***
54
*
55
*
56
*/
57
package org.gvsig.gui.beans.swing;
58

    
59
import java.awt.Font;
60
import java.util.Enumeration;
61

    
62
import javax.swing.JEditorPane;
63
import javax.swing.UIManager;
64
import javax.swing.plaf.FontUIResource;
65

    
66
import org.gvsig.gui.beans.Messages;
67

    
68
public class JTextPreview extends JEditorPane {
69
        private String text = null;
70
        private Font font = null;
71
        private final String template=
72
        "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3082{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}{\\f1\\fswiss\\fcharset0 #FONT#;}}\r\n" +
73
        "{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard#BOLD##ITALIC##UNDERLINED#f0#FONT_SIZE# #TEXT##END_UNDERLINED##NONE##END_BOLD##END_ITALIC#\\f1\\par\r\n" +
74
        "}";
75

    
76

    
77
        public JTextPreview() {
78
                super();
79
                setEditable(false);
80
        }
81

    
82
        public void setText(String text) {
83
                if (text == null)
84
                        text = Messages.getText("text_preview_text");
85
                setContentType("text/rtf");
86
                this.text = text;
87
                if (font == null) {
88
                        Enumeration keys = UIManager.getDefaults().keys();
89
                        while (keys.hasMoreElements()) {
90
                                Object key = keys.nextElement();
91
                                Object value = UIManager.get (key);
92
                                if (value instanceof FontUIResource) {
93
                                        FontUIResource fur = (FontUIResource) value;
94
                                        String fontName = fur.getFontName();
95
                                        font = new Font(fontName, Font.PLAIN, 10);
96
                                        break;
97
                                }
98
                        }
99
                }
100

    
101
                String theText =
102
                        template.replaceAll("#FONT#", font.getName()).
103
                                         replaceAll("#BOLD#", (font.isBold())? "\\b": "").
104
                                         replaceAll("#END_BOLD#", (font.isBold())? "\\b0": "").
105
                                         replaceAll("#ITALIC#", (font.isItalic())? "\\i": "").
106
                                         replaceAll("#END_ITALIC#", (font.isItalic())? "\\i0": "").
107
                                         replaceAll("#UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": "").
108
                                         replaceAll("#END_UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": "").
109
                                         replaceAll("#FONT_SIZE#", "\\\\fs"+font.getSize()*2).
110
                                         replaceAll("#NONE#", ((font.isBold() || font.isItalic() /*||font.isUnderlined()*/)? "none":"")).
111
                                         replaceAll("#TEXT#", text);
112
                super.setText(theText);
113
        }
114

    
115
        public void setFont(Font font) {
116
                this.font = font;
117
                setText(text);
118
        }
119

    
120
        public void setEditable(boolean b) {
121
                // avoided
122
        }
123
}