root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / LabelClassPreview.java @ 24219
History | View | Annotate | Download (3.43 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.symbology.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 |
|
51 |
import javax.swing.JPanel; |
52 |
|
53 |
import com.iver.andami.PluginServices; |
54 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
55 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
56 |
|
57 |
public class LabelClassPreview extends JPanel { |
58 |
private static final long serialVersionUID = 3788548343944220354L; |
59 |
private Dimension sz = new Dimension(100, 200); |
60 |
private LabelClass labelClass;
|
61 |
|
62 |
@Override
|
63 |
public Dimension getPreferredSize() { |
64 |
Dimension sz = labelClass == null ? this.sz : labelClass.getBounds().getSize(); |
65 |
int w = sz.width;
|
66 |
int h = sz.height;
|
67 |
|
68 |
if (w>300) { |
69 |
w = 300;
|
70 |
} |
71 |
|
72 |
if (h>200) { |
73 |
h = 200;
|
74 |
} |
75 |
sz.setSize(w, h); |
76 |
return sz;
|
77 |
} |
78 |
|
79 |
@Override
|
80 |
protected void paintComponent(Graphics g) { |
81 |
if (labelClass == null) |
82 |
return;
|
83 |
Rectangle r = getBounds();
|
84 |
r.setLocation(0, 0); |
85 |
g.setColor(Color.white);
|
86 |
((Graphics2D) g).fill(r);
|
87 |
((Graphics2D) g).setStroke(new BasicStroke(2)); |
88 |
g.setColor(Color.black);
|
89 |
((Graphics2D) g).draw(r);
|
90 |
ILabelStyle sty = labelClass.getLabelStyle(); |
91 |
String cad;
|
92 |
if (sty != null) { |
93 |
int fc = sty.getFieldCount();
|
94 |
String[] texts = new String[fc]; |
95 |
for (int i = 0; i < texts.length; i++) { |
96 |
texts[i] = PluginServices.getText(this, "text_field") + " "+(i+1); |
97 |
} |
98 |
labelClass.setTexts(texts); |
99 |
} else {
|
100 |
labelClass.setTexts(new String[] {PluginServices.getText(this, "text_field")}); |
101 |
} |
102 |
|
103 |
// try {
|
104 |
// labelClass.drawInsideRectangle((Graphics2D) g, r);
|
105 |
Font myFont = new Font(labelClass.getTextSymbol().getFont().getName(),labelClass.getTextSymbol().getFont().getStyle(),35); |
106 |
g.setFont(myFont); |
107 |
g.drawString(PluginServices.getText(this, "text_field"), 0, (int)r.getCenterY()); |
108 |
// } catch (SymbolDrawingException e) {
|
109 |
// SymbologyFactory
|
110 |
// .getWarningSymbol(
|
111 |
// PluginServices.getText(this,
|
112 |
// "cant_draw_preview"),
|
113 |
// SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
|
114 |
// SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
|
115 |
// }
|
116 |
} |
117 |
|
118 |
public void setLabelClass(LabelClass labelClass) { |
119 |
this.labelClass = labelClass;
|
120 |
} |
121 |
} |