Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / core / GeneralPathXIterator.java @ 21606

History | View | Annotate | Download (6.22 KB)

1
/*
2
 * Created on 10-jun-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
/************************************************
48
 *                                                                                                *
49
 *   Modfied By:                                                                *
50
 *   Prodevelop Integraci?n de Tecnolog?as SL        *
51
 *   Conde Salvatierra de ?lava , 34-10                        *
52
 *   46004 Valencia                                                                *
53
 *   Spain                                                                                *
54
 *                                                                                                *
55
 *   +34 963 510 612                                                        *
56
 *   +34 963 510 968                                                        *
57
 *   gis@prodevelop.es                                                        *
58
 *   http://www.prodevelop.es                                        *
59
 *                                                                                                *
60
 *   gvSIG Mobile Team 2006                                         *
61
 *                                                                                          *         
62
 ************************************************/
63

    
64
package es.prodevelop.gvsig.mobile.fmap.core;
65

    
66
import java.awt.geom.AffineTransform;
67
import java.awt.geom.PathIterator;
68

    
69
/*
70
 * @(#)GeneralPathXIterator.java        1.21 03/01/23
71
 *
72
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
73
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
74
 */
75

    
76
/**
77
 * This class represents the iterator for General Paths X.
78
 * It can be used to retrieve all of the elements in a GeneralPathX.
79
 * The {@link GeneralPathX#getPathIterator}
80
 *  method is used to create a
81
 * GeneralPathXIterator for a particular GeneralPathX.
82
 * The iterator can be used to iterator the path only once.
83
 * Subsequent iterations require a new iterator.
84
 *
85
 * @see GeneralPathX
86
 *
87
 * @version 10 Feb 1997
88
 * @author        Jim Graham
89
 */
90
public class GeneralPathXIterator implements PathIterator {
91
    int typeIdx = 0;
92
    int pointIdx   = 0;
93
    GeneralPathX path;
94
    AffineTransform affine;
95

    
96
    private static final int curvesize[] = {2, 2, 4, 6, 0};
97

    
98
    /**
99
     * Constructs an iterator given a GeneralPathX.
100
     * @see GeneralPathX#getPathIterator
101
     */
102
    GeneralPathXIterator(GeneralPathX path) {
103
        this(path, null);
104
    }
105

    
106
    /**
107
     * Constructs an iterator given a GeneralPathX and an optional
108
     * AffineTransform.
109
     * @see GeneralPathX#getPathIterator
110
     */
111
    GeneralPathXIterator(GeneralPathX path, AffineTransform at) {
112
        this.path = path;
113
        this.affine = at;
114
    }
115

    
116
    /**
117
     * Return the winding rule for determining the interior of the
118
     * path.
119
     * @see PathIterator#WIND_EVEN_ODD
120
     * @see PathIterator#WIND_NON_ZERO
121
     */
122
    public int getWindingRule() {
123
        return path.getWindingRule();
124
    }
125

    
126
    /**
127
     * Tests if there are more points to read.
128
     * @return true if there are more points to read
129
     */
130
    public boolean isDone() {
131
        return (typeIdx >= path.numTypes);
132
    }
133

    
134
    /**
135
     * Moves the iterator to the next segment of the path forwards
136
     * along the primary direction of traversal as long as there are
137
     * more points in that direction.
138
     */
139
    public void next() {
140
        int type = path.pointTypes[typeIdx++];
141
        pointIdx += curvesize[type];
142
    }
143

    
144
    /**
145
     * Returns the coordinates and type of the current path segment in
146
     * the iteration.
147
     * The return value is the path segment type:
148
     * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
149
     * A float array of length 6 must be passed in and may be used to
150
     * store the coordinates of the point(s).
151
     * Each point is stored as a pair of float x,y coordinates.
152
     * SEG_MOVETO and SEG_LINETO types will return one point,
153
     * SEG_QUADTO will return two points,
154
     * SEG_CUBICTO will return 3 points
155
     * and SEG_CLOSE will not return any points.
156
     * @see PathIterator#SEG_MOVETO
157
     * @see PathIterator#SEG_LINETO
158
     * @see PathIterator#SEG_QUADTO
159
     * @see PathIterator#SEG_CUBICTO
160
     * @see PathIterator#SEG_CLOSE
161
     */
162
    public int currentSegment(float[] coords) {
163
        int type = path.pointTypes[typeIdx];
164
        int numCoords = curvesize[type];
165
        if (numCoords > 0 && affine != null) {
166
            affine.transform(path.pointCoords, pointIdx,
167
                             coords, 0,
168
                             numCoords / 2);
169
        } else {
170
            for (int i=0; i < numCoords; i++) {
171
                        coords[i] = (float) path.pointCoords[pointIdx + i];
172
                    }
173

    
174
        }
175
        return type;
176
    }
177

    
178
    /**
179
     * Returns the coordinates and type of the current path segment in
180
     * the iteration.
181
     * The return value is the path segment type:
182
     * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
183
     * A double array of length 6 must be passed in and may be used to
184
     * store the coordinates of the point(s).
185
     * Each point is stored as a pair of double x,y coordinates.
186
     * SEG_MOVETO and SEG_LINETO types will return one point,
187
     * SEG_QUADTO will return two points,
188
     * SEG_CUBICTO will return 3 points
189
     * and SEG_CLOSE will not return any points.
190
     * @see PathIterator#SEG_MOVETO
191
     * @see PathIterator#SEG_LINETO
192
     * @see PathIterator#SEG_QUADTO
193
     * @see PathIterator#SEG_CUBICTO
194
     * @see PathIterator#SEG_CLOSE
195
     */
196
    public int currentSegment(double[] coords) {
197
        int type = path.pointTypes[typeIdx];
198
        int numCoords = curvesize[type];
199
        if (numCoords > 0 && affine != null) {
200
            affine.transform(path.pointCoords, pointIdx,
201
                             coords, 0,
202
                             numCoords / 2);
203
        } else {
204
            System.arraycopy(path.pointCoords, pointIdx, coords, 0, numCoords);
205
        }
206
        return type;
207
    }
208
}