svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / swing / JTextPreview.java @ 44455
History | View | Annotate | Download (3.53 KB)
1 | 40561 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40561 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40561 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40561 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40561 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /* CVS MESSAGES:
|
||
25 | *
|
||
26 | * $Id: JTextPreview.java 13655 2007-09-12 16:28:55Z bsanchez $
|
||
27 | * $Log$
|
||
28 | * Revision 1.2 2007-09-12 16:28:23 bsanchez
|
||
29 | * *** empty log message ***
|
||
30 | *
|
||
31 | * Revision 1.1 2007/08/20 08:34:46 evercher
|
||
32 | * He fusionado LibUI con LibUIComponents
|
||
33 | *
|
||
34 | * Revision 1.2 2006/11/28 09:30:12 ppiqueras
|
||
35 | * Cambiado PluginServices.getText(..., ...) por Messages.getText(...)
|
||
36 | *
|
||
37 | * Revision 1.1 2006/09/18 08:00:34 jaume
|
||
38 | * *** empty log message ***
|
||
39 | *
|
||
40 | *
|
||
41 | */
|
||
42 | package org.gvsig.gui.beans.swing; |
||
43 | |||
44 | import java.awt.Font; |
||
45 | import java.util.Enumeration; |
||
46 | |||
47 | import javax.swing.JEditorPane; |
||
48 | import javax.swing.UIManager; |
||
49 | import javax.swing.plaf.FontUIResource; |
||
50 | |||
51 | import org.gvsig.gui.beans.Messages; |
||
52 | |||
53 | public class JTextPreview extends JEditorPane { |
||
54 | private static final long serialVersionUID = -3848260639539532634L; |
||
55 | private String text = null; |
||
56 | private Font font = null; |
||
57 | private final String template= |
||
58 | "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3082{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}{\\f1\\fswiss\\fcharset0 #FONT#;}}\r\n" +
|
||
59 | "{\\*\\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" +
|
||
60 | "}";
|
||
61 | |||
62 | |||
63 | public JTextPreview() {
|
||
64 | super();
|
||
65 | setEditable(false);
|
||
66 | } |
||
67 | |||
68 | public void setText(String text) { |
||
69 | if (text == null) |
||
70 | text = Messages.getText("text_preview_text");
|
||
71 | setContentType("text/rtf");
|
||
72 | this.text = text;
|
||
73 | if (font == null) { |
||
74 | Enumeration keys = UIManager.getDefaults().keys(); |
||
75 | while (keys.hasMoreElements()) {
|
||
76 | Object key = keys.nextElement();
|
||
77 | Object value = UIManager.get (key); |
||
78 | if (value instanceof FontUIResource) { |
||
79 | FontUIResource fur = (FontUIResource) value; |
||
80 | String fontName = fur.getFontName();
|
||
81 | font = new Font(fontName, Font.PLAIN, 10); |
||
82 | break;
|
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | |||
87 | String theText =
|
||
88 | template.replaceAll("#FONT#", font.getName()).
|
||
89 | replaceAll("#BOLD#", (font.isBold())? "\\b": ""). |
||
90 | replaceAll("#END_BOLD#", (font.isBold())? "\\b0": ""). |
||
91 | replaceAll("#ITALIC#", (font.isItalic())? "\\i": ""). |
||
92 | replaceAll("#END_ITALIC#", (font.isItalic())? "\\i0": ""). |
||
93 | replaceAll("#UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": ""). |
||
94 | replaceAll("#END_UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": ""). |
||
95 | replaceAll("#FONT_SIZE#", "\\\\fs"+font.getSize()*2). |
||
96 | replaceAll("#NONE#", ((font.isBold() || font.isItalic() /*||font.isUnderlined()*/)? "none":"")). |
||
97 | replaceAll("#TEXT#", text);
|
||
98 | super.setText(theText);
|
||
99 | } |
||
100 | |||
101 | public void setFont(Font font) { |
||
102 | this.font = font;
|
||
103 | setText(text); |
||
104 | } |
||
105 | |||
106 | public void setEditable(boolean b) { |
||
107 | // avoided
|
||
108 | } |
||
109 | } |