Revision 8949 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/gt2/FLiteShape.java

View differences:

FLiteShape.java
2 2
 * Created on 12-may-2005
3 3
 *
4 4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
5
 *
6 6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
7
 *
8 8
 * This program is free software; you can redistribute it and/or
9 9
 * modify it under the terms of the GNU General Public License
10 10
 * as published by the Free Software Foundation; either version 2
11 11
 * of the License, or (at your option) any later version.
12
 *  
12
 *
13 13
 * This program is distributed in the hope that it will be useful,
14 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
 * GNU General Public License for more details.
17
 * 
17
 *
18 18
 * You should have received a copy of the GNU General Public License
19 19
 * along with this program; if not, write to the Free Software
20 20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
21
 *
22 22
 * For more information, contact:
23 23
 *
24 24
 *  Generalitat Valenciana
......
30 30
 *      +34 963862235
31 31
 *   gvsig@gva.es
32 32
 *      www.gvsig.gva.es
33
 * 
33
 *
34 34
 *    or
35
 * 
35
 *
36 36
 *   IVER T.I. S.A
37 37
 *   Salamanca 50
38 38
 *   46005 Valencia
39 39
 *   Spain
40
 * 
40
 *
41 41
 *   +34 963163400
42 42
 *   dac@iver.es
43 43
 */
......
63 63
import com.iver.cit.gvsig.fmap.core.AbstractHandler;
64 64
import com.iver.cit.gvsig.fmap.core.FShape;
65 65
import com.iver.cit.gvsig.fmap.core.Handler;
66
import com.iver.cit.gvsig.fmap.core.IFinalHandler;
66 67
import com.iver.cit.gvsig.fmap.core.gt2.factory.FactoryFinder;
67 68
import com.vividsolutions.jts.geom.Coordinate;
68 69
import com.vividsolutions.jts.geom.Geometry;
......
92 93
    private AffineTransform affineTransform = null;
93 94
    private boolean generalize = false;
94 95
    private double maxDistance = 1;
95
    
96

  
96 97
    // cached iterators
97 98
    private LineIterator lineIterator = new LineIterator();
98 99
    private GeomCollectionIterator collIterator = new GeomCollectionIterator();
......
100 101
    private float xScale;
101 102

  
102 103
    private float yScale;
103
    
104

  
104 105
    private GeometryFactory geomFac;
105 106

  
106 107
    private MathTransform mathTransform;
107 108

  
108 109
    private static final AffineTransform IDENTITY = new AffineTransform();
109
    
110
	class PointHandler extends AbstractHandler {
110

  
111
	class PointHandler extends AbstractHandler implements IFinalHandler{
111 112
		/**
112 113
		 * Crea un nuevo PointHandler.
113 114
		 *
......
129 130
		 *
130 131
		 * @return DOCUMENT ME!
131 132
		 */
132
		public void move(double x, double y) {    			
133
		public void move(double x, double y) {
133 134
			c.x+=x;
134 135
			c.y+=y;
135 136
			geometry.geometryChanged();
......
144 145
			geometry.geometryChanged();
145 146
		}
146 147
	}
147
    
148 148

  
149

  
149 150
    /**
150 151
     * Creates a new LiteShape object.
151 152
     *
......
154 155
     * @param generalize - set to true if the geometry need to be generalized
155 156
     *        during rendering
156 157
     * @param maxDistance - distance used in the generalization process
157
     * @throws TransformException 
158
     * @throws FactoryException 
158
     * @throws TransformException
159
     * @throws FactoryException
159 160
     */
160 161
    public FLiteShape(Geometry geom, AffineTransform at, MathTransform mathTransform, boolean generalize,
161 162
        double maxDistance) throws TransformException, FactoryException {
......
171 172
     * @param generalize - set to true if the geometry need to be generalized
172 173
     *        during rendering
173 174
     * @param maxDistance - distance used in the generalization process
174
     * @throws TransformException 
175
     * @throws FactoryException 
175
     * @throws TransformException
176
     * @throws FactoryException
176 177
     */
177 178
    public FLiteShape(Geometry geom, AffineTransform at, MathTransform mathTransform, boolean generalize) throws TransformException, FactoryException {
178 179
        if( geom!=null)
......
200 201
     * @param generalize - set to true if the geometry need to be generalized
201 202
     *        during rendering
202 203
     * @param maxDistance - distance used in the generalization process
203
     * @throws TransformException 
204
     * @throws TransformException
204 205
     */
205 206
    public FLiteShape(Geometry geom, AffineTransform at, boolean generalize,
206 207
        double maxDistance){
207 208
        this(geom, at, generalize);
208 209
        this.maxDistance = maxDistance;
209 210
    }
210
    
211

  
211 212
    public FLiteShape(Geometry geom)
212 213
    {
213 214
        this(geom, null, false);
......
221 222
     * @param generalize - set to true if the geometry need to be generalized
222 223
     *        during rendering
223 224
     * @param maxDistance - distance used in the generalization process
224
     * @throws TransformException 
225
     * @throws TransformException
225 226
     */
226 227
    public FLiteShape(Geometry geom, AffineTransform at, boolean generalize){
227 228
        if( geom!=null)
......
245 246
                (affineTransform.getScaleY() * affineTransform.getScaleY())
246 247
                + (affineTransform.getShearY() * affineTransform.getShearY()));
247 248
    }
248
    
249

  
249 250
    private void transformGeometry(Geometry geometry) throws TransformException, FactoryException {
250
        
251

  
251 252
        if( mathTransform==null || mathTransform.isIdentity() ){
252 253
            if( !affineTransform.isIdentity() ){
253 254
                MathTransformFactory factory=FactoryFinder.getMathTransformFactory(null);
......
259 260
            factory.createConcatenatedTransform(mathTransform, factory.createAffineTransform(new GeneralMatrix(affineTransform)));
260 261
            affineTransform=IDENTITY;
261 262
        }
262
        
263

  
263 264
        if( mathTransform==null || mathTransform.isIdentity() )
264 265
            return;
265
        
266
        
266

  
267

  
267 268
        CoordinateSequenceTransformer transformer=new InPlaceCoordinateSequenceTransformer();
268 269
        if (geometry instanceof GeometryCollection) {
269 270
            GeometryCollection collection=(GeometryCollection)geometry;
......
272 273
            }
273 274
        }else if (geometry instanceof Point) {
274 275
            transformer.transform(((Point)geometry).getCoordinateSequence(), mathTransform);
275
        }else if (geometry instanceof Polygon) {     
276
        }else if (geometry instanceof Polygon) {
276 277
            Polygon polygon=(Polygon) geometry;
277 278
            transformGeometry(polygon.getExteriorRing());
278 279
            for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
......
280 281
            }
281 282
        } else if (geometry instanceof LineString) {
282 283
            transformer.transform(((LineString)geometry).getCoordinateSequence(), mathTransform);
283
        } 
284
        }
284 285
    }
285 286

  
286 287
    private GeometryFactory getGeometryFactory() {
......
296 297
     * object instead of creating it again and again during rendering
297 298
     *
298 299
     * @param g
299
     * @throws TransformException 
300
     * @throws FactoryException 
300
     * @throws TransformException
301
     * @throws FactoryException
301 302
     */
302 303
    public void setGeometry(Geometry g) throws TransformException, FactoryException {
303 304
        if( g!=null){
......
316 317
        } catch (FactoryException e) {
317 318
            // TODO Auto-generated catch block
318 319
            e.printStackTrace();
319
        }        
320
        }
320 321
        xScale = (float) Math.sqrt(
321 322
            (affineTransform.getScaleX() * affineTransform.getScaleX())
322 323
            + (affineTransform.getShearX() * affineTransform.getShearX()));
323 324
        yScale = (float) Math.sqrt(
324 325
            (affineTransform.getScaleY() * affineTransform.getScaleY())
325 326
            + (affineTransform.getShearY() * affineTransform.getShearY()));
326
        
327

  
327 328
    }
328 329

  
329 330
    /**
330 331
     * Tests if the interior of the <code>Shape</code> entirely contains the
331 332
     * specified <code>Rectangle2D</code>. This method might conservatively
332 333
     * return <code>false</code> when:
333
     * 
334
     *
334 335
     * <ul>
335 336
     * <li>
336 337
     * the <code>intersect</code> method returns <code>true</code> and
......
341 342
     * expensive.
342 343
     * </li>
343 344
     * </ul>
344
     * 
345
     *
345 346
     * This means that this method might return <code>false</code> even though
346 347
     * the <code>Shape</code> contains the <code>Rectangle2D</code>. The
347 348
     * <code>Area</code> class can be used to perform more accurate
......
405 406
     * rectangular area must lie within the <code>Shape</code> for the entire
406 407
     * rectanglar area to be considered contained within the
407 408
     * <code>Shape</code>.
408
     * 
409
     *
409 410
     * <p>
410 411
     * This method might conservatively return <code>false</code> when:
411
     * 
412
     *
412 413
     * <ul>
413 414
     * <li>
414 415
     * the <code>intersect</code> method returns <code>true</code> and
......
418 419
     * entirely contains the rectangular area are prohibitively expensive.
419 420
     * </li>
420 421
     * </ul>
421
     * 
422
     *
422 423
     * This means that this method might return <code>false</code> even though
423 424
     * the <code>Shape</code> contains the rectangular area. The
424 425
     * <code>Area</code> class can be used to perform more accurate
......
574 575
     * boundary and provides access to the geometry of the <code>Shape</code>
575 576
     * outline.  If an optional {@link AffineTransform} is specified, the
576 577
     * coordinates returned in the iteration are transformed accordingly.
577
     * 
578
     *
578 579
     * <p>
579 580
     * Each call to this method returns a fresh <code>PathIterator</code>
580 581
     * object that traverses the geometry of the <code>Shape</code> object
581 582
     * independently from any other <code>PathIterator</code> objects in use
582 583
     * at the same time.
583 584
     * </p>
584
     * 
585
     *
585 586
     * <p>
586 587
     * It is recommended, but not guaranteed, that objects implementing the
587 588
     * <code>Shape</code> interface isolate iterations that are in process
588 589
     * from any changes that might occur to the original object's geometry
589 590
     * during such iterations.
590 591
     * </p>
591
     * 
592
     *
592 593
     * <p>
593 594
     * Before using a particular implementation of the <code>Shape</code>
594 595
     * interface in more than one thread simultaneously, refer to its
......
619 620
            pi = new PointIterator((Point) geometry, combined);
620 621
        }
621 622

  
622
        if (this.geometry instanceof Polygon) {             
623
        if (this.geometry instanceof Polygon) {
623 624

  
624 625
            pi = new PolygonIterator((Polygon) geometry, combined, generalize,
625 626
                    maxDistance);
......
635 636
            if(combined == affineTransform)
636 637
                lineIterator.init((LineString) geometry, combined, generalize,
637 638
                        (float) maxDistance, xScale, yScale);
638
            else 
639
            else
639 640
                lineIterator.init((LineString) geometry, combined, generalize,
640 641
                        (float) maxDistance);
641 642
            pi = lineIterator;
......
651 652
     * Returns an iterator object that iterates along the <code>Shape</code>
652 653
     * boundary and provides access to a flattened view of the
653 654
     * <code>Shape</code> outline geometry.
654
     * 
655
     *
655 656
     * <p>
656 657
     * Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by
657 658
     * the iterator.
658 659
     * </p>
659
     * 
660
     *
660 661
     * <p>
661 662
     * If an optional <code>AffineTransform</code> is specified, the
662 663
     * coordinates returned in the iteration are transformed accordingly.
663 664
     * </p>
664
     * 
665
     *
665 666
     * <p>
666 667
     * The amount of subdivision of the curved segments is controlled by the
667 668
     * <code>flatness</code> parameter, which specifies the maximum distance
......
671 672
     * flattening parameters to be treated as larger values.  This limit, if
672 673
     * there is one, is defined by the particular implementation that is used.
673 674
     * </p>
674
     * 
675
     *
675 676
     * <p>
676 677
     * Each call to this method returns a fresh <code>PathIterator</code>
677 678
     * object that traverses the <code>Shape</code> object geometry
678 679
     * independently from any other <code>PathIterator</code> objects in use
679 680
     * at the same time.
680 681
     * </p>
681
     * 
682
     *
682 683
     * <p>
683 684
     * It is recommended, but not guaranteed, that objects implementing the
684 685
     * <code>Shape</code> interface isolate iterations that are in process
685 686
     * from any changes that might occur to the original object's geometry
686 687
     * during such iterations.
687 688
     * </p>
688
     * 
689
     *
689 690
     * <p>
690 691
     * Before using a particular implementation of this interface in more than
691 692
     * one thread simultaneously, refer to its documentation to verify that it
......
710 711
     * Tests if the interior of the <code>Shape</code> intersects the interior
711 712
     * of a specified <code>Rectangle2D</code>. This method might
712 713
     * conservatively return <code>true</code> when:
713
     * 
714
     *
714 715
     * <ul>
715 716
     * <li>
716 717
     * there is a high probability that the <code>Rectangle2D</code> and the
......
721 722
     * prohibitively expensive.
722 723
     * </li>
723 724
     * </ul>
724
     * 
725
     *
725 726
     * This means that this method might return <code>true</code> even though
726 727
     * the <code>Rectangle2D</code> does not intersect the <code>Shape</code>.
727 728
     *
......
746 747
     * of a specified rectangular area. The rectangular area is considered to
747 748
     * intersect the <code>Shape</code> if any point is contained in both the
748 749
     * interior of the <code>Shape</code> and the specified rectangular area.
749
     * 
750
     *
750 751
     * <p>
751 752
     * This method might conservatively return <code>true</code> when:
752
     * 
753
     *
753 754
     * <ul>
754 755
     * <li>
755 756
     * there is a high probability that the rectangular area and the
......
760 761
     * prohibitively expensive.
761 762
     * </li>
762 763
     * </ul>
763
     * 
764
     *
764 765
     * This means that this method might return <code>true</code> even though
765 766
     * the rectangular area does not intersect the <code>Shape</code>. The
766 767
     * {@link java.awt.geom.Area Area} class can be used to perform more
......
819 820

  
820 821
        return geometry.getFactory().createPolygon(lr, null);
821 822
    }
822
    
823

  
823 824
    /**
824 825
     * Returns the affine transform for this lite shape
825 826
     * @return
......
849 850
        if (geometry instanceof MultiLineString)
850 851
            type = FShape.LINE;
851 852

  
852
        
853

  
853 854
        return type;
854 855
    }
855 856

  
......
873 874
            pointCoords[i] = pt.getX();
874 875
            pointCoords[i+1] = pt.getY();
875 876
        } */
876
        
877

  
877 878
    }
878 879

  
879 880
	public Handler[] getStretchingHandlers() {

Also available in: Unified diff