Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / LabelClassPreview.java @ 39569

History | View | Annotate | Download (4.45 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.FontMetrics;
48
import java.awt.Graphics;
49
import java.awt.Graphics2D;
50
import java.awt.Rectangle;
51
import java.awt.font.FontRenderContext;
52
import java.awt.font.GlyphVector;
53
import java.awt.geom.AffineTransform;
54

    
55
import javax.swing.JPanel;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle;
59
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
60
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass;
61

    
62
public class LabelClassPreview extends JPanel {
63
        private static final long serialVersionUID = 3788548343944220354L;
64
        private Dimension sz = new Dimension(100, 200);
65
        private LabelClass labelClass;
66

    
67
        @Override
68
        public Dimension getPreferredSize() {
69
                Dimension sz = labelClass == null ? this.sz : labelClass.getBounds().getSize();
70
                int w = sz.width;
71
                int h = sz.height;
72

    
73
                if (w>300) {
74
                        w = 300;
75
                }
76

    
77
                if (h>200) {
78
                        h = 200;
79
                }
80
                sz.setSize(w, h);
81
                return sz;
82
        }
83

    
84
        @Override
85
        protected void paintComponent(Graphics g) {
86
                if (labelClass == null)
87
                        return;
88
                Rectangle r = getBounds();
89
                r.setLocation(0, 0);
90
                g.setColor(Color.white);
91
                ((Graphics2D) g).fill(r);
92
                ((Graphics2D) g).setStroke(new BasicStroke(2));
93
                g.setColor(Color.black);
94
                ((Graphics2D) g).draw(r);
95
                ILabelStyle sty = labelClass.getLabelStyle();
96
                String cad;
97
                if (sty != null) {
98
                        int fc = sty.getFieldCount();
99
                        String[] texts = new String[fc];
100
                        for (int i = 0; i < texts.length; i++) {
101
                                texts[i] = PluginServices.getText(this, "text_field") + " "+(i+1);
102
                        }
103
                        labelClass.setTexts(texts);
104
                } else {
105
                        labelClass.setTexts(new String[] {PluginServices.getText(this, "text_field")});
106
                }
107

    
108
//                try {
109
//                        labelClass.drawInsideRectangle((Graphics2D) g, r);
110
                        ITextSymbol sym = labelClass.getTextSymbol();
111
                        Font myFont = new Font(sym.getFont().getName(),sym.getFont().getStyle(),35);
112
                        AffineTransform saveAT = ((Graphics2D)g).getTransform();
113
                        
114
//                        AffineTransform tx = new AffineTransform();
115
//                        tx.setToTranslation(0, -r.getCenterY());
116
                        saveAT.translate(0, r.getCenterY());
117
                        ((Graphics2D) g).setTransform(saveAT);
118
                        FontRenderContext frc = new FontRenderContext(
119
                                        saveAT, false, true);;
120
                        g.setFont(myFont);
121
                        String text = PluginServices.getText(this, "text_field");
122
                        
123
                        if (sym.isDrawWithHalo()) {
124
                                BasicStroke haloStroke = new BasicStroke(sym.getHaloWidth());
125
                                char[] charText = new char[text.length()];
126
                                text.getChars(0, charText.length, charText, 0);
127
                                GlyphVector glyph = myFont.layoutGlyphVector(frc, charText, 0, charText.length, Font.LAYOUT_NO_LIMIT_CONTEXT);
128
                                g.setColor(sym.getHaloColor());
129
                                ((Graphics2D) g).setStroke(haloStroke);
130
                                ((Graphics2D) g).draw(glyph.getOutline());
131
                        }
132
                        g.setColor(sym.getTextColor());
133
                        g.drawString(PluginServices.getText(this, "text_field"), 0, 0);
134
//                } catch (SymbolDrawingException e) {
135
//                        SymbologyFactory
136
//                                        .getWarningSymbol(
137
//                                                        PluginServices.getText(this,
138
//                                                                        "cant_draw_preview"),
139
//                                                        SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
140
//                                                        SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
141
//                }
142
        }
143

    
144
        public void setLabelClass(LabelClass labelClass) {
145
                this.labelClass = labelClass;
146
        }
147
}