Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / geometryadapters / PointAdapter.java @ 29596

History | View | Annotate | Download (4 KB)

1 21300 vcaballero
/* 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 29596 jpiera
package org.gvsig.app.project.documents.layout.geometryadapters;
42 21300 vcaballero
43
import java.awt.Graphics2D;
44
import java.awt.geom.AffineTransform;
45 29038 vcaballero
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47 21300 vcaballero
48 29333 jmvivo
import org.gvsig.compat.print.PrintAttributes;
49 21300 vcaballero
import org.gvsig.fmap.geom.Geometry;
50 27419 jpiera
import org.gvsig.fmap.geom.GeometryLocator;
51
import org.gvsig.fmap.geom.GeometryManager;
52
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
53
import org.gvsig.fmap.geom.exception.CreateGeometryException;
54 21300 vcaballero
import org.gvsig.fmap.geom.primitive.GeneralPathX;
55
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
56 27419 jpiera
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
58 21300 vcaballero
59
60
61
62
/**
63
 * DOCUMENT ME!
64
 *
65
 * @author Vicente Caballero Navarro
66
 */
67
public class PointAdapter extends PolyLineAdapter {
68 27419 jpiera
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
69
        private static final Logger logger = LoggerFactory.getLogger(PointAdapter.class);
70 29038 vcaballero
71
        public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
72
        }
73
        public void obtainShape(Point2D p) {
74
        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 1);
75
        elShape.moveTo(p.getX(), p.getY());
76
        setGPX(elShape);
77
    }
78
79 27419 jpiera
        /**
80 21300 vcaballero
     * DOCUMENT ME!
81
     *
82
     * @param g DOCUMENT ME!
83
     * @param at DOCUMENT ME!
84
     * @param symbol DOCUMENT ME!
85
     */
86
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
87 28846 vcaballero
        symbol.draw(g,at,getGeometry(at), null);
88 21300 vcaballero
    }
89 29333 jmvivo
    public void print(Graphics2D g, AffineTransform at, ISymbol symbol,
90
                        PrintAttributes properties) {
91 28846 vcaballero
               symbol.print(g,at,getGeometry(at), properties);
92 23069 vcaballero
    }
93 21300 vcaballero
    /**
94
     * DOCUMENT ME!
95
     *
96
     * @return DOCUMENT ME!
97
     */
98 28846 vcaballero
    public Geometry getGeometry(AffineTransform at) {
99
            GeneralPathX point;
100
                try {
101
                        point = new GeneralPathX(geomManager.createPoint(getGPX().getCurrentPoint().getX(),getGPX().getCurrentPoint().getX(), SUBTYPES.GEOM2D));
102
                        point.transform(at);
103
104
                        return geomManager.createPoint(point.getCurrentPoint().getX(),point.getCurrentPoint().getY(), SUBTYPES.GEOM2D);
105 27419 jpiera
                } catch (CreateGeometryException e) {
106 28846 vcaballero
                        logger.error("Error creating a curve", e);
107 27419 jpiera
                }
108 28846 vcaballero
            return null;
109 21300 vcaballero
    }
110 29038 vcaballero
111
    public Rectangle2D getBounds2D(){
112
        Rectangle2D r=getGeometry(new AffineTransform()).getBounds2D();
113
        double w=r.getWidth();
114
        double h=r.getHeight();
115
        double x=r.getX();
116
        double y=r.getY();
117
        boolean modified=false;
118
        if (r.getWidth()<0.5) {
119
         modified=true;
120
         w=1;
121
         x=x-0.25;
122
        }
123
        if(r.getHeight()<0.5) {
124
         modified=true;
125
         h=1;
126
//         y=y-0.5;
127
        }
128 29333 jmvivo
        if (modified) {
129
                        return new Rectangle2D.Double(x,y,w,h);
130
                }
131 29038 vcaballero
        return r;
132
   }
133 21300 vcaballero
}