Statistics
| Revision:

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

History | View | Annotate | Download (4.05 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.GeometryLocator;
54
import org.gvsig.fmap.geom.GeometryManager;
55
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
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

    
60

    
61

    
62

    
63
/**
64
 * DOCUMENT ME!
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class PointAdapter extends PolyLineAdapter {
69
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
70
        private static final Logger logger = LoggerFactory.getLogger(PointAdapter.class);
71

    
72
        public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
73
        }
74
        public void obtainShape(Point2D p) {
75
        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 1);
76
        elShape.moveTo(p.getX(), p.getY());
77
        setGPX(elShape);
78
    }
79

    
80
        /**
81
     * DOCUMENT ME!
82
     *
83
     * @param g DOCUMENT ME!
84
     * @param at DOCUMENT ME!
85
     * @param symbol DOCUMENT ME!
86
     */
87
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
88
        symbol.draw(g,at,getGeometry(at), null, null);
89
    }
90
    public void print(Graphics2D g, AffineTransform at, ISymbol symbol,
91
                        PrintAttributes properties) {
92
               symbol.print(g,at,getGeometry(at), properties);
93
    }
94
    /**
95
     * DOCUMENT ME!
96
     *
97
     * @return DOCUMENT ME!
98
     */
99
    public Geometry getGeometry(AffineTransform at) {
100
            GeneralPathX point;
101
                try {
102
                        point = new GeneralPathX(geomManager.createPoint(getGPX()
103
                                        .getCurrentPoint().getX(), getGPX().getCurrentPoint()
104
                                        .getY(), SUBTYPES.GEOM2D).getPathIterator(null));
105
                        point.transform(at);
106

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

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