root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / FPreviewSymbol.java @ 7304
History | View | Annotate | Download (4.22 KB)
1 |
/*
|
---|---|
2 |
* Created on 28-abr-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
48 |
|
49 |
import java.awt.Color; |
50 |
import java.awt.FontMetrics; |
51 |
import java.awt.Graphics; |
52 |
import java.awt.Graphics2D; |
53 |
import java.awt.Rectangle; |
54 |
import java.awt.RenderingHints; |
55 |
import java.awt.geom.AffineTransform; |
56 |
|
57 |
import javax.swing.JComponent; |
58 |
|
59 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
60 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
61 |
|
62 |
|
63 |
/**
|
64 |
* @author fjp
|
65 |
*
|
66 |
* To change the template for this generated type comment go to
|
67 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
68 |
*/
|
69 |
public class FPreviewSymbol extends JComponent { |
70 |
|
71 |
private FSymbol m_FSymbol;
|
72 |
private String m_Str; |
73 |
private boolean m_bUseFSymbol; |
74 |
|
75 |
|
76 |
/**
|
77 |
*
|
78 |
*/
|
79 |
public FPreviewSymbol() {
|
80 |
super();
|
81 |
initialize(); |
82 |
// this.setDoubleBuffered(true);
|
83 |
this.setBackground(Color.WHITE); |
84 |
this.setForeground(Color.BLACK); |
85 |
} |
86 |
|
87 |
|
88 |
/**
|
89 |
* This method initializes this
|
90 |
*
|
91 |
* @return void
|
92 |
*/
|
93 |
private void initialize() { |
94 |
this.setSize(70, 52); |
95 |
|
96 |
} |
97 |
protected void paintComponent(Graphics g) { |
98 |
super.paintComponent(g);
|
99 |
if (m_FSymbol == null) |
100 |
{ |
101 |
return;
|
102 |
} |
103 |
// Seg?n el tipo de s?mbolo, creamos un shape u otro y utilizamos
|
104 |
// la funci?n com?n de dibujado de shape sobre un graphics con un simbolo
|
105 |
|
106 |
Graphics2D g2 = (Graphics2D) g; |
107 |
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
108 |
|
109 |
|
110 |
g.setClip(0,0,getWidth(), getHeight()); |
111 |
Rectangle r = g.getClipBounds(); //getClipRect(); |
112 |
// g.clipRect(r.x, r.y, r.width, r.height);
|
113 |
// g.setColor(Color.WHITE);
|
114 |
// g2.fillRect(0, 0,getWidth(), getHeight());
|
115 |
if (m_bUseFSymbol)
|
116 |
{ |
117 |
AffineTransform mT2 = AffineTransform.getScaleInstance(0.8, 0.8); |
118 |
mT2.concatenate(AffineTransform.getTranslateInstance(r.width * 0.1, r.height * 0.1 )); |
119 |
|
120 |
FGraphicUtilities.DrawSymbol((Graphics2D)g,mT2,r,m_FSymbol);
|
121 |
} |
122 |
else
|
123 |
{ |
124 |
FontMetrics metrics = g2.getFontMetrics();
|
125 |
int width = metrics.stringWidth(m_Str );
|
126 |
//int height = metrics.getMaxAscent();
|
127 |
// g2.setFont(theSymbol.m_Font);
|
128 |
|
129 |
g2.drawString(m_Str, (float) r.getCenterX()-width/2, (float) r.getCenterY() +3); |
130 |
} |
131 |
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* @param symbol
|
136 |
*/
|
137 |
public void setSymbol(FSymbol symbol) { |
138 |
// Lo clonamos para que si viene en coordenadas de mundo real
|
139 |
// (m_bUseSize = true), dibujarlo con un tama?o fijo en pixels.
|
140 |
|
141 |
FSymbol cloneSym = symbol.fastCloneSymbol(); |
142 |
if (!cloneSym.isSizeInPixels())
|
143 |
{ |
144 |
cloneSym.setSizeInPixels(true);
|
145 |
cloneSym.setSize(10); // pixels |
146 |
} |
147 |
|
148 |
m_FSymbol = cloneSym; |
149 |
m_bUseFSymbol = true;
|
150 |
|
151 |
repaint(); |
152 |
} |
153 |
|
154 |
public void setTextDescrip(String str) |
155 |
{ |
156 |
m_bUseFSymbol = false;
|
157 |
m_Str = str; |
158 |
} |
159 |
|
160 |
/* (non-Javadoc)
|
161 |
* @see java.awt.Component#isShowing()
|
162 |
*/
|
163 |
public boolean isShowing() { |
164 |
// TODO Auto-generated method stub
|
165 |
return true; // super.isShowing(); |
166 |
} |
167 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|