Statistics
| Revision:

root / 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 @ 36685

History | View | Annotate | Download (3.37 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.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.exception.CreateGeometryException;
34
import org.gvsig.fmap.geom.primitive.Point;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.persistence.PersistenceManager;
38

    
39
/**
40
 * DOCUMENT ME!
41
 * 
42
 * @author Vicente Caballero Navarro
43
 */
44
public class PointAdapter extends PolyLineAdapter {
45

    
46
    public static final String PERSISTENCE_DEFINITION_NAME = "PointAdapter";
47
    private static final Logger logger = LoggerFactory
48
        .getLogger(PointAdapter.class);
49

    
50
    public PointAdapter() {
51
        super();
52
    }
53

    
54
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
55

    
56
    }
57

    
58
    public void obtainShape(Point2D p) {
59
        try {
60
            Point point = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);   
61
            setGeometry(point);
62
        } catch (CreateGeometryException e) {
63
            logger.error("Error creating a point", e);
64
        }       
65
    }
66

    
67
    public Rectangle2D getBounds2D() {
68
        Rectangle2D r = getGeometry(new AffineTransform()).getBounds2D();
69
        double w = r.getWidth();
70
        double h = r.getHeight();
71
        double x = r.getX();
72
        double y = r.getY();
73
        boolean modified = false;
74
        if (r.getWidth() < 0.5) {
75
            modified = true;
76
            w = 1;
77
            x = x - 0.25;
78
        }
79
        if (r.getHeight() < 0.5) {
80
            modified = true;
81
            h = 1;
82
            // y=y-0.5;
83
        }
84
        if (modified) {
85
            return new Rectangle2D.Double(x, y, w, h);
86
        }
87
        return r;
88
    }
89

    
90
    public static void registerPersistent() {
91
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
92
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
93
            DynStruct definition =
94
                manager.addDefinition(PointAdapter.class,
95
                    PERSISTENCE_DEFINITION_NAME,
96
                    "Point Adapter persistence definition", null, null);
97

    
98
            definition.extend(manager
99
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
100
        }
101
    }
102
}