svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / layerproperties / LabelClassPreview.java @ 40911
History | View | Annotate | Download (4.39 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 |
package org.gvsig.labeling.gui.layerproperties; |
42 |
|
43 |
import java.awt.BasicStroke; |
44 |
import java.awt.Color; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.Font; |
47 |
import java.awt.Graphics; |
48 |
import java.awt.Graphics2D; |
49 |
import java.awt.Rectangle; |
50 |
import java.awt.font.FontRenderContext; |
51 |
import java.awt.font.GlyphVector; |
52 |
import java.awt.geom.AffineTransform; |
53 |
|
54 |
import javax.swing.JPanel; |
55 |
|
56 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
57 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
58 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle; |
59 |
import org.gvsig.i18n.Messages; |
60 |
|
61 |
public class LabelClassPreview extends JPanel { |
62 |
private static final long serialVersionUID = 3788548343944220354L; |
63 |
private Dimension sz = new Dimension(100, 200); |
64 |
private ILabelClass labelClass;
|
65 |
|
66 |
@Override
|
67 |
public Dimension getPreferredSize() { |
68 |
Dimension sz = labelClass == null ? this.sz : labelClass.getBounds().getSize(); |
69 |
int w = sz.width;
|
70 |
int h = sz.height;
|
71 |
|
72 |
if (w>300) { |
73 |
w = 300;
|
74 |
} |
75 |
|
76 |
if (h>200) { |
77 |
h = 200;
|
78 |
} |
79 |
sz.setSize(w, h); |
80 |
return sz;
|
81 |
} |
82 |
|
83 |
@Override
|
84 |
protected void paintComponent(Graphics g) { |
85 |
if (labelClass == null) |
86 |
return;
|
87 |
Rectangle r = getBounds();
|
88 |
r.setLocation(0, 0); |
89 |
g.setColor(Color.white);
|
90 |
((Graphics2D) g).fill(r);
|
91 |
((Graphics2D) g).setStroke(new BasicStroke(2)); |
92 |
g.setColor(Color.black);
|
93 |
((Graphics2D) g).draw(r);
|
94 |
ILabelStyle sty = labelClass.getLabelStyle(); |
95 |
String cad;
|
96 |
if (sty != null) { |
97 |
int fc = sty.getFieldCount();
|
98 |
String[] texts = new String[fc]; |
99 |
for (int i = 0; i < texts.length; i++) { |
100 |
texts[i] = Messages.getText("text_field") + " "+(i+1); |
101 |
} |
102 |
labelClass.setTexts(texts); |
103 |
} else {
|
104 |
labelClass.setTexts(new String[] {Messages.getText("text_field")}); |
105 |
} |
106 |
|
107 |
// try {
|
108 |
// labelClass.drawInsideRectangle((Graphics2D) g, r);
|
109 |
ITextSymbol sym = labelClass.getTextSymbol(); |
110 |
Font myFont = new Font(sym.getFont().getName(),sym.getFont().getStyle(),35); |
111 |
AffineTransform saveAT = ((Graphics2D)g).getTransform(); |
112 |
|
113 |
// AffineTransform tx = new AffineTransform();
|
114 |
// tx.setToTranslation(0, -r.getCenterY());
|
115 |
saveAT.translate(0, r.getCenterY());
|
116 |
((Graphics2D) g).setTransform(saveAT);
|
117 |
FontRenderContext frc = new FontRenderContext( |
118 |
saveAT, false, true);; |
119 |
g.setFont(myFont); |
120 |
String text = Messages.getText("text_field"); |
121 |
|
122 |
if (sym.isDrawWithHalo()) {
|
123 |
BasicStroke haloStroke = new BasicStroke(sym.getHaloWidth()); |
124 |
char[] charText = new char[text.length()]; |
125 |
text.getChars(0, charText.length, charText, 0); |
126 |
GlyphVector glyph = myFont.layoutGlyphVector(frc, charText, 0, charText.length, Font.LAYOUT_NO_LIMIT_CONTEXT); |
127 |
g.setColor(sym.getHaloColor()); |
128 |
((Graphics2D) g).setStroke(haloStroke);
|
129 |
((Graphics2D) g).draw(glyph.getOutline());
|
130 |
} |
131 |
g.setColor(sym.getTextColor()); |
132 |
g.drawString(Messages.getText("text_field"), 0, 0); |
133 |
// } catch (SymbolDrawingException e) {
|
134 |
// SymbologyFactory
|
135 |
// .getWarningSymbol(
|
136 |
// PluginServices.getText(this,
|
137 |
// "cant_draw_preview"),
|
138 |
// SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
|
139 |
// SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
|
140 |
// }
|
141 |
} |
142 |
|
143 |
public void setLabelClass(ILabelClass labelClass) { |
144 |
this.labelClass = labelClass;
|
145 |
} |
146 |
} |