svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / legendmanager / panels / FPreviewSymbol.java @ 813
History | View | Annotate | Download (2.97 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 |
package com.iver.cit.gvsig.gui.legendmanager.panels; |
8 |
|
9 |
import java.awt.Color; |
10 |
import java.awt.FontMetrics; |
11 |
import java.awt.Graphics; |
12 |
import java.awt.Graphics2D; |
13 |
import java.awt.Rectangle; |
14 |
import java.awt.RenderingHints; |
15 |
import java.awt.geom.AffineTransform; |
16 |
|
17 |
import javax.swing.JComponent; |
18 |
|
19 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
20 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
21 |
|
22 |
|
23 |
/**
|
24 |
* @author fjp
|
25 |
*
|
26 |
* To change the template for this generated type comment go to
|
27 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
28 |
*/
|
29 |
public class FPreviewSymbol extends JComponent { |
30 |
|
31 |
private FSymbol m_FSymbol;
|
32 |
private String m_Str; |
33 |
private boolean m_bUseFSymbol; |
34 |
|
35 |
|
36 |
/**
|
37 |
*
|
38 |
*/
|
39 |
public FPreviewSymbol() {
|
40 |
super();
|
41 |
initialize(); |
42 |
// this.setDoubleBuffered(true);
|
43 |
this.setBackground(Color.WHITE); |
44 |
this.setForeground(Color.BLACK); |
45 |
} |
46 |
|
47 |
|
48 |
/**
|
49 |
* This method initializes this
|
50 |
*
|
51 |
* @return void
|
52 |
*/
|
53 |
private void initialize() { |
54 |
this.setSize(70, 52); |
55 |
|
56 |
} |
57 |
protected void paintComponent(Graphics g) { |
58 |
super.paintComponent(g);
|
59 |
if (m_FSymbol == null) |
60 |
{ |
61 |
return;
|
62 |
} |
63 |
// Seg?n el tipo de s?mbolo, creamos un shape u otro y utilizamos
|
64 |
// la funci?n com?n de dibujado de shape sobre un graphics con un simbolo
|
65 |
|
66 |
Graphics2D g2 = (Graphics2D) g; |
67 |
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
68 |
|
69 |
|
70 |
g.setClip(0,0,getWidth(), getHeight()); |
71 |
Rectangle r = g.getClipBounds(); //getClipRect(); |
72 |
// g.clipRect(r.x, r.y, r.width, r.height);
|
73 |
// g.setColor(Color.WHITE);
|
74 |
// g2.fillRect(0, 0,getWidth(), getHeight());
|
75 |
if (m_bUseFSymbol)
|
76 |
{ |
77 |
AffineTransform mT2 = AffineTransform.getScaleInstance(0.8, 0.8); |
78 |
mT2.concatenate(AffineTransform.getTranslateInstance(r.width * 0.1, r.height * 0.1 )); |
79 |
|
80 |
FGraphicUtilities.DrawSymbol((Graphics2D)g,mT2,r,m_FSymbol);
|
81 |
} |
82 |
else
|
83 |
{ |
84 |
FontMetrics metrics = g2.getFontMetrics();
|
85 |
int width = metrics.stringWidth(m_Str );
|
86 |
int height = metrics.getMaxAscent();
|
87 |
// g2.setFont(theSymbol.m_Font);
|
88 |
|
89 |
g2.drawString(m_Str, (float) r.getCenterX()-width/2, (float) r.getCenterY() +3); |
90 |
} |
91 |
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* @param symbol
|
96 |
*/
|
97 |
public void setSymbol(FSymbol symbol) { |
98 |
// Lo clonamos para que si viene en coordenadas de mundo real
|
99 |
// (m_bUseSize = true), dibujarlo con un tama?o fijo en pixels.
|
100 |
|
101 |
FSymbol cloneSym = symbol.cloneSymbol(); |
102 |
cloneSym.setSizeInPixels(false);
|
103 |
cloneSym.setSize(10); // pixels |
104 |
|
105 |
m_FSymbol = cloneSym; |
106 |
m_bUseFSymbol = true;
|
107 |
|
108 |
repaint(); |
109 |
} |
110 |
|
111 |
public void setTextDescrip(String str) |
112 |
{ |
113 |
m_bUseFSymbol = false;
|
114 |
m_Str = str; |
115 |
} |
116 |
|
117 |
/* (non-Javadoc)
|
118 |
* @see java.awt.Component#isShowing()
|
119 |
*/
|
120 |
public boolean isShowing() { |
121 |
// TODO Auto-generated method stub
|
122 |
return true; // super.isShowing(); |
123 |
} |
124 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|