Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / AbstractPrimitive.java @ 44617

History | View | Annotate | Download (3.63 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.jts.primitive;
24

    
25
import java.awt.geom.PathIterator;
26
import java.util.ArrayList;
27
import java.util.List;
28

    
29
import com.vividsolutions.jts.geom.Coordinate;
30

    
31
import org.gvsig.fmap.geom.handler.Handler;
32
import org.gvsig.fmap.geom.jts.AbstractGeometry;
33
import org.gvsig.fmap.geom.jts.UnmovableHandler;
34
import org.gvsig.fmap.geom.primitive.Primitive;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

    
38

    
39
/**
40
 * @author fdiaz
41
 *
42
 */
43
public abstract class AbstractPrimitive extends AbstractGeometry implements Primitive{
44

    
45
    /**
46
     *
47
     */
48
    private static final long serialVersionUID = -8143412151139464535L;
49

    
50
    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPrimitive.class);
51

    
52

    
53
    /**
54
     *
55
     * @param type
56
     * @param subtype
57
     */
58
    protected AbstractPrimitive(int type, int subtype) {
59
        super(type, subtype);
60
    }
61

    
62
    @Override
63
    public Handler[] getHandlers(int type) {
64
        List<Handler> handlers = new ArrayList<>();
65
        Handler handler;
66
            Coordinate[] coordinates = getJTS().getCoordinates();
67
        for (Coordinate coordinate : coordinates) {
68
            handler = new UnmovableHandler(coordinate.x, coordinate.y);
69
            handlers.add(handler);
70
        }
71

    
72
            PathIterator pi = getPathIterator(null);
73

    
74
            double coords[] = new double[6];
75
            while (!pi.isDone()) {
76
                switch (pi.currentSegment(coords)) {
77
                case PathIterator.SEG_MOVETO:
78
                    handler = new UnmovableHandler(coords[0], coords[1]);
79
                    handlers.add(handler);
80
                    break;
81
                case PathIterator.SEG_LINETO:
82
                    handler = new UnmovableHandler(coords[0], coords[1]);
83
                    handlers.add(handler);
84
                    break;
85
                case PathIterator.SEG_QUADTO:
86
                    handler = new UnmovableHandler(coords[0], coords[1]);
87
                    handlers.add(handler);
88
                    handler = new UnmovableHandler(coords[2], coords[3]);
89
                    handlers.add(handler);
90
                    break;
91
                case PathIterator.SEG_CUBICTO:
92
                    handler = new UnmovableHandler(coords[0], coords[1]);
93
                    handlers.add(handler);
94
                    handler = new UnmovableHandler(coords[2], coords[3]);
95
                    handlers.add(handler);
96
                    handler = new UnmovableHandler(coords[4], coords[5]);
97
                    handlers.add(handler);
98
                    break;
99
                case PathIterator.SEG_CLOSE:
100
                    break;
101
                }
102
                pi.next();
103
            }
104
        return handlers.toArray(new Handler[handlers.size()]);
105
    }
106
}