Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libUI / src / org / gvsig / gui / beans / swing / JTextPreview.java @ 9033

History | View | Annotate | Download (3.5 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 9033 2006-11-28 09:30:12Z ppiqueras $
45
* $Log$
46
* Revision 1.2  2006-11-28 09:30:12  ppiqueras
47
* Cambiado PluginServices.getText(..., ...) por Messages.getText(...)
48
*
49
* Revision 1.1  2006/09/18 08:00:34  jaume
50
* *** empty log message ***
51
*
52
*
53
*/
54
package org.gvsig.gui.beans.swing;
55

    
56
import java.awt.Font;
57
import java.util.Enumeration;
58

    
59
import javax.swing.JEditorPane;
60
import javax.swing.UIManager;
61
import javax.swing.plaf.FontUIResource;
62

    
63
import org.gvsig.gui.beans.Messages;
64

    
65
public class JTextPreview extends JEditorPane {
66
        private String text = null;
67
        private Font font = null;
68
        private final String template=
69
        "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3082{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}{\\f1\\fswiss\\fcharset0 #FONT#;}}\r\n" +
70
        "{\\*\\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" +
71
        "}";
72

    
73

    
74
        public JTextPreview() {
75
                super();
76
                setEditable(false);
77
        }
78

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

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

    
112
        public void setFont(Font font) {
113
                this.font = font;
114
                setText(text);
115
        }
116

    
117
        public void setEditable(boolean b) {
118
                // avoided
119
        }
120
}