Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / geometryadapters / PointAdapter.java @ 36648

History | View | Annotate | Download (4.85 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

    
24
import java.awt.Graphics2D;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28

    
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

    
32
import org.gvsig.compat.print.PrintAttributes;
33
import org.gvsig.fmap.geom.Geometry;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.exception.CreateGeometryException;
38
import org.gvsig.fmap.geom.primitive.GeneralPathX;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

    
44
/**
45
 * DOCUMENT ME!
46
 * 
47
 * @author Vicente Caballero Navarro
48
 */
49
public class PointAdapter extends PolyLineAdapter {
50

    
51
    public static final String PERSISTENCE_DEFINITION_NAME = "PointAdapter";
52
    private static final GeometryManager geomManager = GeometryLocator
53
        .getGeometryManager();
54
    private static final Logger logger = LoggerFactory
55
        .getLogger(PointAdapter.class);
56

    
57
    public PointAdapter() {
58
        super();
59
    }
60

    
61
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
62

    
63
    }
64

    
65
    public void obtainShape(Point2D p) {
66
        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 1);
67
        elShape.moveTo(p.getX(), p.getY());
68
        setGPX(elShape);
69
    }
70

    
71
    /**
72
     * DOCUMENT ME!
73
     * 
74
     * @param g
75
     *            DOCUMENT ME!
76
     * @param at
77
     *            DOCUMENT ME!
78
     * @param symbol
79
     *            DOCUMENT ME!
80
     */
81
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
82
        symbol.draw(g, at, getGeometry(at), null, null);
83
    }
84

    
85
    public void print(Graphics2D g, AffineTransform at, ISymbol symbol,
86
        PrintAttributes properties) {
87
        symbol.print(g, at, getGeometry(at), properties);
88
    }
89

    
90
    /**
91
     * DOCUMENT ME!
92
     * 
93
     * @return DOCUMENT ME!
94
     */
95
    public Geometry getGeometry(AffineTransform at) {
96
        GeneralPathX point;
97
        try {
98
            point =
99
                new GeneralPathX(geomManager.createPoint(
100
                    getGPX().getCurrentPoint().getX(),
101
                    getGPX().getCurrentPoint().getY(), SUBTYPES.GEOM2D)
102
                    .getPathIterator(null));
103
            point.transform(at);
104

    
105
            return geomManager.createPoint(point.getCurrentPoint().getX(),
106
                point.getCurrentPoint().getY(), SUBTYPES.GEOM2D);
107
        } catch (CreateGeometryException e) {
108
            logger.error("Error creating a curve", e);
109
        }
110
        return null;
111
    }
112

    
113
    public Rectangle2D getBounds2D() {
114
        Rectangle2D r = getGeometry(new AffineTransform()).getBounds2D();
115
        double w = r.getWidth();
116
        double h = r.getHeight();
117
        double x = r.getX();
118
        double y = r.getY();
119
        boolean modified = false;
120
        if (r.getWidth() < 0.5) {
121
            modified = true;
122
            w = 1;
123
            x = x - 0.25;
124
        }
125
        if (r.getHeight() < 0.5) {
126
            modified = true;
127
            h = 1;
128
            // y=y-0.5;
129
        }
130
        if (modified) {
131
            return new Rectangle2D.Double(x, y, w, h);
132
        }
133
        return r;
134
    }
135

    
136
    public static void registerPersistent() {
137
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
138
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
139
            DynStruct definition =
140
                manager.addDefinition(PointAdapter.class,
141
                    PERSISTENCE_DEFINITION_NAME,
142
                    "Point Adapter persistence definition", null, null);
143

    
144
            definition.extend(manager
145
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
146
        }
147
    }
148
}