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