Statistics
| Revision:

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

History | View | Annotate | Download (3.05 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

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

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

    
64
        public String getClassName() {
65
                return getClass().getName();
66
        }
67

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

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

    
85
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
86

    
87
                FPoint2D p = (FPoint2D) shp;
88
                double radian_half_sharpeness = Math.toRadians(getSharpness()*.5); //
89

    
90
                double size = getSize();
91
                double halfHeight = size * Math.tan(radian_half_sharpeness);
92
                double theta = getRotation();
93

    
94
                g.setColor(getColor());
95

    
96
                g.setStroke(new BasicStroke());
97

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

    
105
                try {
106
                        g.translate(p.getX(), p.getY());
107
                } catch (NullPointerException npEx) {
108
                        return;
109
                }
110
                g.rotate(theta);
111

    
112
                g.fill(gp);
113
                g.rotate(-theta);
114
                g.translate(-p.getX(), -p.getY());
115

    
116
        }
117
}