Statistics
| Revision:

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

History | View | Annotate | Download (3.1 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.geom.AffineTransform;
10

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

    
20

    
21
/**
22
 * @author jaume dominguez faus - jaume.dominguez@iver.es
23
 */
24
public class ArrowMarkerSymbol extends AbstractMarkerSymbol implements CartographicSupport {
25
        private ArrowMarkerSymbol symSel;
26
        private double sharpeness;
27

    
28

    
29
        
30
        public ISymbol getSymbolForSelection() {
31
                if (symSel == null) {
32
                        symSel = new ArrowMarkerSymbol();
33
                        symSel.setColor(MapContext.getSelectionColor());
34

    
35
                }
36

    
37
                return symSel;
38
        }
39

    
40
        public int getSymbolType() {
41
                return FShape.POINT;
42
        }
43

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

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

    
67
        public String getClassName() {
68
                return getClass().getName();
69
        }
70

    
71
        /**
72
         * To get the sharpeness attribute.It will determine the final form of the arrow
73
         * @return
74
         */
75
        public double getSharpness() {
76
                return sharpeness;
77
        }
78

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

    
88
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
89

    
90
                FPoint2D p = (FPoint2D) shp;
91
                double radian_half_sharpeness = Math.toRadians(getSharpness()*.5); //
92

    
93
                double size = getSize();
94
                double halfHeight = size * Math.tan(radian_half_sharpeness);
95
                double theta = getRotation();
96

    
97
                g.setColor(getColor());
98

    
99
                g.setStroke(new BasicStroke());
100

    
101
                if (p == null) return;
102
                GeneralPathX gp = new GeneralPathX();
103
                gp.moveTo(0, 0);
104
                gp.lineTo(size, -halfHeight);
105
                gp.lineTo(size, halfHeight);
106
                gp.closePath();
107

    
108
                try {
109
                        g.translate(p.getX(), p.getY());
110
                } catch (NullPointerException npEx) {
111
                        return;
112
                }
113
                g.rotate(theta);
114

    
115
                g.fill(gp);
116
                g.rotate(-theta);
117
                g.translate(-p.getX(), -p.getY());
118

    
119
        }
120
}