svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / styles / PointLabelPositioneer.java @ 22254
History | View | Annotate | Download (2.97 KB)
1 |
package org.gvsig.symbology.fmap.styles; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Font; |
5 |
import java.awt.Graphics2D; |
6 |
import java.awt.Rectangle; |
7 |
import java.awt.RenderingHints; |
8 |
|
9 |
import com.iver.cit.gvsig.fmap.core.FShape; |
10 |
import com.iver.cit.gvsig.fmap.core.styles.AbstractStyle; |
11 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
12 |
import com.iver.utiles.XMLEntity; |
13 |
|
14 |
|
15 |
/**
|
16 |
* Specifies the point position for a label
|
17 |
*
|
18 |
*
|
19 |
*/
|
20 |
public class PointLabelPositioneer extends AbstractStyle { |
21 |
private byte[] preferenceVector = new byte[8]; |
22 |
private static final Color[] colorVector = new Color[] { |
23 |
new Color(140, 140, 140), // gray |
24 |
new Color(140, 245, 130), // green |
25 |
new Color(130, 170, 245), // light blue |
26 |
new Color(100, 100, 255), // dark blue |
27 |
}; |
28 |
|
29 |
public static final byte FORBIDDEN = 0; |
30 |
public static final byte PREFERENCE_HIGH = 1; |
31 |
public static final byte PREFERENCE_NORMAL = 2; |
32 |
public static final byte PREFERENCE_LOW = 3; |
33 |
/**
|
34 |
* Constructor method
|
35 |
*
|
36 |
*/
|
37 |
public PointLabelPositioneer() {}
|
38 |
|
39 |
/**
|
40 |
* Constructor method
|
41 |
*
|
42 |
* @param preferenceVector
|
43 |
* @param description
|
44 |
*/
|
45 |
public PointLabelPositioneer(byte[] preferenceVector, String description) { |
46 |
this.preferenceVector = preferenceVector;
|
47 |
setDescription(description); |
48 |
} |
49 |
|
50 |
public void drawInsideRectangle(Graphics2D g, Rectangle r) { |
51 |
int size = Math.min(r.width, r.height) / 3; |
52 |
int j = -1; |
53 |
final int fontSize = (int) (size * 0.8); |
54 |
final Font font = new Font("Arial", Font.PLAIN, fontSize); |
55 |
RenderingHints old = g.getRenderingHints();
|
56 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
57 |
for (int i = 0; i < 9; i++) { |
58 |
if (i == 4) continue; |
59 |
j++; |
60 |
int value = Math.abs(preferenceVector[j] % colorVector.length); |
61 |
int col = i % 3; |
62 |
int row = i / 3; |
63 |
|
64 |
g.setColor(colorVector[value]); |
65 |
g.fillRect(size * col, size*row, size, size); |
66 |
g.setColor(Color.BLACK);
|
67 |
g.drawRect(size * col, size*row, size, size); |
68 |
g.setFont(font); |
69 |
g.drawString(String.valueOf(value),
|
70 |
(float) ((size/2) - (fontSize/4)) + size * col, |
71 |
(float) (size * 0.8) + size*row); |
72 |
} |
73 |
g.setRenderingHints(old); |
74 |
} |
75 |
|
76 |
public boolean isSuitableFor(ISymbol symbol) { |
77 |
return symbol.getSymbolType() == FShape.POINT;
|
78 |
} |
79 |
|
80 |
public String getClassName() { |
81 |
return getClass().getName();
|
82 |
} |
83 |
|
84 |
public XMLEntity getXMLEntity() {
|
85 |
XMLEntity xml = new XMLEntity();
|
86 |
xml.putProperty("className", getClassName());
|
87 |
xml.putProperty("desc", getDescription());
|
88 |
StringBuffer sb = new StringBuffer(); |
89 |
for (int i = 0; i < preferenceVector.length; i++) { |
90 |
sb.append(preferenceVector[i]+" ,");
|
91 |
} |
92 |
String s = sb.substring(0, sb.length()-2); |
93 |
xml.putProperty("preferenceVector", s);
|
94 |
return xml;
|
95 |
} |
96 |
|
97 |
public void setXMLEntity(XMLEntity xml) { |
98 |
setDescription(xml.getStringProperty("desc"));
|
99 |
preferenceVector = xml.getByteArrayProperty("preferenceVector");
|
100 |
} |
101 |
|
102 |
public void drawOutline(Graphics2D g, Rectangle r) { |
103 |
drawInsideRectangle(g, r); |
104 |
} |
105 |
|
106 |
public byte[] getPreferenceVector() { |
107 |
return preferenceVector;
|
108 |
} |
109 |
} |