Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / geometryadapters / PointAdapter.java @ 34228

History | View | Annotate | Download (4.93 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 org.gvsig.app.project.documents.layout.geometryadapters;
42

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

    
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

    
51
import org.gvsig.compat.print.PrintAttributes;
52
import org.gvsig.fmap.geom.Geometry;
53
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
54
import org.gvsig.fmap.geom.GeometryLocator;
55
import org.gvsig.fmap.geom.GeometryManager;
56
import org.gvsig.fmap.geom.exception.CreateGeometryException;
57
import org.gvsig.fmap.geom.primitive.GeneralPathX;
58
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
59
import org.gvsig.tools.ToolsLocator;
60
import org.gvsig.tools.dynobject.DynStruct;
61
import org.gvsig.tools.persistence.PersistenceManager;
62

    
63

    
64

    
65

    
66
/**
67
 * DOCUMENT ME!
68
 *
69
 * @author Vicente Caballero Navarro
70
 */
71
public class PointAdapter extends PolyLineAdapter {
72
    public static final String PERSISTENCE_DEFINITION_NAME = "PointAdapter";
73
    private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
74
        private static final Logger logger = LoggerFactory.getLogger(PointAdapter.class);
75
        
76
        public PointAdapter() {
77
        super();       
78
    }
79

    
80
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
81
            
82
        }
83
        
84
        public void obtainShape(Point2D p) {
85
        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 1);
86
        elShape.moveTo(p.getX(), p.getY());
87
        setGPX(elShape);
88
    }
89

    
90
        /**
91
     * DOCUMENT ME!
92
     *
93
     * @param g DOCUMENT ME!
94
     * @param at DOCUMENT ME!
95
     * @param symbol DOCUMENT ME!
96
     */
97
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
98
        symbol.draw(g,at,getGeometry(at), null, null);
99
    }
100
    public void print(Graphics2D g, AffineTransform at, ISymbol symbol,
101
                        PrintAttributes properties) {
102
               symbol.print(g,at,getGeometry(at), properties);
103
    }
104
    /**
105
     * DOCUMENT ME!
106
     *
107
     * @return DOCUMENT ME!
108
     */
109
    public Geometry getGeometry(AffineTransform at) {
110
            GeneralPathX point;
111
                try {
112
                        point = new GeneralPathX(geomManager.createPoint(getGPX()
113
                                        .getCurrentPoint().getX(), getGPX().getCurrentPoint()
114
                                        .getY(), SUBTYPES.GEOM2D).getPathIterator(null));
115
                        point.transform(at);
116

    
117
                        return geomManager.createPoint(point.getCurrentPoint().getX(),point.getCurrentPoint().getY(), SUBTYPES.GEOM2D);
118
                } catch (CreateGeometryException e) {
119
                        logger.error("Error creating a curve", e);
120
                }
121
            return null;
122
    }
123

    
124
    public Rectangle2D getBounds2D(){
125
        Rectangle2D r=getGeometry(new AffineTransform()).getBounds2D();
126
        double w=r.getWidth();
127
        double h=r.getHeight();
128
        double x=r.getX();
129
        double y=r.getY();
130
        boolean modified=false;
131
        if (r.getWidth()<0.5) {
132
         modified=true;
133
         w=1;
134
         x=x-0.25;
135
        }
136
        if(r.getHeight()<0.5) {
137
         modified=true;
138
         h=1;
139
//         y=y-0.5;
140
        }
141
        if (modified) {
142
                        return new Rectangle2D.Double(x,y,w,h);
143
                }
144
        return r;
145
   }
146
    
147
    public static void registerPersistent() {
148
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
149
        if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) {
150
            DynStruct definition = manager.addDefinition(
151
                PointAdapter.class,
152
                PERSISTENCE_DEFINITION_NAME,
153
                "Point Adapter persistence definition",
154
                null, 
155
                null
156
            );      
157

    
158
            definition.extend(manager.getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));         
159
        }         
160
    }   
161
}