Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / ArrowMarkerSymbol.java @ 13881

History | View | Annotate | Download (3.19 KB)

1
/*
2
 * Created on 25-oct-2006 by azabala
3
 *
4
 */
5
package com.iver.cit.gvsig.fmap.core.symbols;
6

    
7
import java.awt.BasicStroke;
8
import java.awt.Graphics2D;
9
import java.awt.Shape;
10
import java.awt.geom.AffineTransform;
11

    
12
import com.iver.cit.gvsig.fmap.MapContext;
13
import com.iver.cit.gvsig.fmap.core.CartographicSupport;
14
import com.iver.cit.gvsig.fmap.core.FPoint2D;
15
import com.iver.cit.gvsig.fmap.core.FShape;
16
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
17
import com.iver.utiles.StringUtilities;
18
import com.iver.utiles.XMLEntity;
19

    
20

    
21
/**
22
 * @author alzabord
23
 */
24
public class ArrowMarkerSymbol extends AbstractMarkerSymbol implements CartographicSupport {
25
        private ArrowMarkerSymbol symSel;
26
        private double sharpeness;
27

    
28

    
29
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
30
                // TODO Auto-generated method stub
31
                throw new Error("Not yet implemented!");
32
        }
33

    
34
        public ISymbol getSymbolForSelection() {
35
                if (symSel == null) {
36
                        symSel = new ArrowMarkerSymbol();
37
                        symSel.setColor(MapContext.getSelectionColor());
38

    
39
                }
40

    
41
                return symSel;
42
        }
43

    
44
        public int getSymbolType() {
45
                return FShape.POINT;
46
        }
47

    
48
        public XMLEntity getXMLEntity() {
49
                XMLEntity xml = new XMLEntity();
50
                xml.putProperty("className", getClassName());
51
                xml.putProperty("isShapeVisible", isShapeVisible());
52
                xml.putProperty("desc", getDescription());
53
                xml.putProperty("size", getSize());
54
                xml.putProperty("unit", getUnit());
55
                xml.putProperty("referenceSystem", getReferenceSystem());
56
                xml.putProperty("sharpness", getSharpness());
57
                xml.putProperty("color", StringUtilities.color2String(getColor()));
58
                return xml;
59
        }
60

    
61
        public void setXMLEntity(XMLEntity xml) {
62
                setDescription(xml.getStringProperty("desc"));
63
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
64
                setSize(xml.getDoubleProperty("size"));
65
                setUnit(xml.getIntProperty("unit"));
66
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
67
                setSharpness(xml.getDoubleProperty("sharpness"));
68
                setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
69
        }
70

    
71
        public String getClassName() {
72
                return getClass().getName();
73
        }
74

    
75
        /**
76
         * To get the sharpeness attribute.It will determine the final form of the arrow
77
         * @return
78
         */
79
        public double getSharpness() {
80
                return sharpeness;
81
        }
82

    
83
        /**
84
         * To set the sharpeness.It will determine the final form of the arrow
85
         * @param sharpeness, the value of the arrow's edge angle IN RADIANS
86
         * @see #getSharpeness()
87
         */
88
        public void setSharpness(double sharpeness) {
89
                this.sharpeness = sharpeness;
90
        }
91

    
92
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
93

    
94
                FPoint2D p = (FPoint2D) shp;
95
                double radian_half_sharpeness = Math.toRadians(getSharpness()*.5); //
96

    
97
                double size = getSize();
98
                double halfHeight = size * Math.tan(radian_half_sharpeness);
99
                double theta = getRotation();
100

    
101
                g.setColor(getColor());
102

    
103
                g.setStroke(new BasicStroke());
104

    
105
                if (p == null) return;
106
                GeneralPathX gp = new GeneralPathX();
107
                gp.moveTo(0, 0);
108
                gp.lineTo(size, -halfHeight);
109
                gp.lineTo(size, halfHeight);
110
                gp.closePath();
111

    
112
                try {
113
                        g.translate(p.getX(), p.getY());
114
                } catch (NullPointerException npEx) {
115
                        return;
116
                }
117
                g.rotate(theta);
118

    
119
                g.fill(gp);
120
                g.rotate(-theta);
121
                g.translate(-p.getX(), -p.getY());
122

    
123
        }
124
}