Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / adapter / PolyLineAdapter.java @ 28367

History | View | Annotate | Download (4.41 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.core.adapter;
42

    
43
import java.awt.Color;
44
import java.awt.Graphics2D;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47

    
48
import javax.print.attribute.PrintRequestAttributeSet;
49

    
50
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
51
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
52
import com.iver.cit.gvsig.fmap.core.FShape;
53
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
54
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
55
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
56
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
57

    
58

    
59
/**
60
 * DOCUMENT ME!
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64
public class PolyLineAdapter extends GeometryAdapter {
65
    private Point2D pointPosition = new Point2D.Double();
66
    private AffineTransform identity = new AffineTransform();
67

    
68
    /**
69
     * DOCUMENT ME!
70
     *
71
     * @param p DOCUMENT ME!
72
     */
73
    public void obtainShape(Point2D p) {
74
        Point2D[] points = getPoints();
75
        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
76
                points.length);
77

    
78
        if (points.length > 0) {
79
            elShape.moveTo(((Point2D) points[0]).getX(),
80
                ((Point2D) points[0]).getY());
81
        }
82

    
83
        for (int i = 0; i < points.length; i++) {
84
            elShape.lineTo(((Point2D) points[i]).getX(),
85
                ((Point2D) points[i]).getY());
86
        }
87

    
88
        if (points.length > 0) {
89
            elShape.lineTo(p.getX(), p.getY());
90
        }
91

    
92
        setGPX(elShape);
93
    }
94

    
95
    /**
96
     * DOCUMENT ME!
97
     *
98
     * @return DOCUMENT ME!
99
     */
100
    public FShape getShape(AffineTransform at) {
101
             GeneralPathX polyLine = new GeneralPathX(new FPolyline2D(getGPX()));
102
         polyLine.transform(at);
103

    
104
        return new FPolyline2D(polyLine);
105
    }
106

    
107
    /**
108
     * DOCUMENT ME!
109
     *
110
     * @param g DOCUMENT ME!
111
     * @param at DOCUMENT ME!
112
     * @param symbol DOCUMENT ME!
113
     */
114
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
115
            FShape shapeAux =getShape(at);
116
            symbol.draw(g,at,shapeAux, null);
117
            // FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
118
    }
119
    public void print(Graphics2D g, AffineTransform at, ISymbol symbol,PrintRequestAttributeSet properties) {
120
            FShape shapeAux =getShape(at);
121
            symbol.print(g,at,shapeAux, properties);
122
                // FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
123
    }
124
    /**
125
     * DOCUMENT ME!
126
     *
127
     * @param g DOCUMENT ME!
128
     * @param at DOCUMENT ME!
129
     * @param andLastPoint DOCUMENT ME!
130
     */
131
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
132
        if (andLastPoint) {
133
            obtainShape(pointPosition);
134
        }
135

    
136
        FShape shapeAux=getShape(at);
137
        //ISymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
138
        ILineSymbol symbol = SymbologyFactory.createDefaultLineSymbol();
139
        symbol.setLineColor(Color.RED);
140
        symbol.draw(g, identity, shapeAux, null);
141
        // FGraphicUtilities.DrawShape(g, identity, shapeAux,
142
        //     new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red));
143
    }
144

    
145
    /**
146
     * DOCUMENT ME!
147
     *
148
     * @param p DOCUMENT ME!
149
     */
150
    public void pointPosition(Point2D p) {
151
        pointPosition = p;
152
    }
153
}