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