root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / StylePreviewer.java @ 10679
History | View | Annotate | Download (1.78 KB)
1 |
package com.iver.cit.gvsig.gui.styling; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Font; |
5 |
import java.awt.FontMetrics; |
6 |
import java.awt.Graphics; |
7 |
import java.awt.Graphics2D; |
8 |
import java.awt.Rectangle; |
9 |
import java.awt.geom.AffineTransform; |
10 |
|
11 |
import javax.swing.JPanel; |
12 |
|
13 |
import com.iver.andami.PluginServices; |
14 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
15 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
16 |
|
17 |
public class StylePreviewer extends SymbolPreviewer{ |
18 |
private int hGap = 5, vGap = 5; |
19 |
private IStyle style;
|
20 |
|
21 |
|
22 |
public StylePreviewer() {
|
23 |
super();
|
24 |
setBackground(Color.WHITE);
|
25 |
} |
26 |
|
27 |
public IStyle getStyle() {
|
28 |
return style;
|
29 |
} |
30 |
|
31 |
public ISymbol getSymbol() {
|
32 |
throw new Error(PluginServices.getText(this, "undefined_for_StylePreviewer_use") |
33 |
+" getStyle() "+
|
34 |
PluginServices.getText(this, "instead") ); |
35 |
|
36 |
} |
37 |
|
38 |
public void setSymbol(ISymbol symbol) { |
39 |
throw new Error(PluginServices.getText(this, "undefined_for_StylePreviewer_use") |
40 |
+" setStyle(IStyle) "+
|
41 |
PluginServices.getText(this, "instead") ); |
42 |
|
43 |
} |
44 |
|
45 |
|
46 |
public void setStyle(IStyle style) { |
47 |
this.style = style;
|
48 |
repaint(); |
49 |
} |
50 |
|
51 |
public void paint(Graphics g) { |
52 |
Graphics2D g2 = (Graphics2D) g; |
53 |
g2.translate(hGap, vGap); |
54 |
Rectangle r = getBounds();
|
55 |
r = new Rectangle(0, 0, (int) (r.getWidth()-(hGap*2)), (int) (r.getHeight()-(vGap*2))); |
56 |
|
57 |
if (style != null) { |
58 |
style.drawInsideRectangle(g2, r); |
59 |
} else {
|
60 |
String noneSelected = "["+PluginServices.getText(this, "preview_not_available")+"]"; |
61 |
FontMetrics fm = g2.getFontMetrics();
|
62 |
int lineWidth = fm.stringWidth(noneSelected);
|
63 |
float scale = (float) r.getWidth() / lineWidth; |
64 |
Font f = g2.getFont();
|
65 |
float fontSize = f.getSize()*scale;
|
66 |
g2.setFont( f.deriveFont( fontSize ) ); |
67 |
|
68 |
g2.drawString(noneSelected, (r.x*scale) - (hGap/2), r.height/2+vGap*scale); |
69 |
} |
70 |
} |
71 |
} |