root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / swing / JTextPreview.java @ 13655
History | View | Annotate | Download (3.73 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 13655 2007-09-12 16:28:55Z bsanchez $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-09-12 16:28:23 bsanchez
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1 2007/08/20 08:34:46 evercher
|
50 |
* He fusionado LibUI con LibUIComponents
|
51 |
*
|
52 |
* Revision 1.2 2006/11/28 09:30:12 ppiqueras
|
53 |
* Cambiado PluginServices.getText(..., ...) por Messages.getText(...)
|
54 |
*
|
55 |
* Revision 1.1 2006/09/18 08:00:34 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
package org.gvsig.gui.beans.swing; |
61 |
|
62 |
import java.awt.Font; |
63 |
import java.util.Enumeration; |
64 |
|
65 |
import javax.swing.JEditorPane; |
66 |
import javax.swing.UIManager; |
67 |
import javax.swing.plaf.FontUIResource; |
68 |
|
69 |
import org.gvsig.gui.beans.Messages; |
70 |
|
71 |
public class JTextPreview extends JEditorPane { |
72 |
private static final long serialVersionUID = -3848260639539532634L; |
73 |
private String text = null; |
74 |
private Font font = null; |
75 |
private final String template= |
76 |
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3082{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}{\\f1\\fswiss\\fcharset0 #FONT#;}}\r\n" +
|
77 |
"{\\*\\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" +
|
78 |
"}";
|
79 |
|
80 |
|
81 |
public JTextPreview() {
|
82 |
super();
|
83 |
setEditable(false);
|
84 |
} |
85 |
|
86 |
public void setText(String text) { |
87 |
if (text == null) |
88 |
text = Messages.getText("text_preview_text");
|
89 |
setContentType("text/rtf");
|
90 |
this.text = text;
|
91 |
if (font == null) { |
92 |
Enumeration keys = UIManager.getDefaults().keys(); |
93 |
while (keys.hasMoreElements()) {
|
94 |
Object key = keys.nextElement();
|
95 |
Object value = UIManager.get (key); |
96 |
if (value instanceof FontUIResource) { |
97 |
FontUIResource fur = (FontUIResource) value; |
98 |
String fontName = fur.getFontName();
|
99 |
font = new Font(fontName, Font.PLAIN, 10); |
100 |
break;
|
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
String theText =
|
106 |
template.replaceAll("#FONT#", font.getName()).
|
107 |
replaceAll("#BOLD#", (font.isBold())? "\\b": ""). |
108 |
replaceAll("#END_BOLD#", (font.isBold())? "\\b0": ""). |
109 |
replaceAll("#ITALIC#", (font.isItalic())? "\\i": ""). |
110 |
replaceAll("#END_ITALIC#", (font.isItalic())? "\\i0": ""). |
111 |
replaceAll("#UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": ""). |
112 |
replaceAll("#END_UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": ""). |
113 |
replaceAll("#FONT_SIZE#", "\\\\fs"+font.getSize()*2). |
114 |
replaceAll("#NONE#", ((font.isBold() || font.isItalic() /*||font.isUnderlined()*/)? "none":"")). |
115 |
replaceAll("#TEXT#", text);
|
116 |
super.setText(theText);
|
117 |
} |
118 |
|
119 |
public void setFont(Font font) { |
120 |
this.font = font;
|
121 |
setText(text); |
122 |
} |
123 |
|
124 |
public void setEditable(boolean b) { |
125 |
// avoided
|
126 |
} |
127 |
} |