Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / SelectedZoomVisitor.java @ 38557

History | View | Annotate | Download (3.43 KB)

1 30011 cordinyana
/* 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.fmap.mapcontext;
42
43
import org.gvsig.fmap.dal.DataSet;
44
import org.gvsig.fmap.dal.feature.Feature;
45
import org.gvsig.fmap.dal.feature.FeatureReference;
46
import org.gvsig.fmap.geom.primitive.Envelope;
47
import org.gvsig.fmap.mapcontext.layers.FLayer;
48
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor;
49
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
50
import org.gvsig.tools.exception.BaseException;
51
import org.gvsig.tools.visitor.NotSupportedOperationException;
52
import org.gvsig.tools.visitor.Visitable;
53
import org.gvsig.tools.visitor.Visitor;
54
55
56
/**
57
 * Visitor de zoom a lo seleccionado.
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class SelectedZoomVisitor implements LayersVisitor, Visitor {
62
        private Envelope rectangle = null;
63
64
        /**
65
         * Devuelve el Extent de los shapes seleccionados, y si no hay ning?n shape
66
         * seleccionado devuelve null.
67
         *
68
         * @return Extent de los shapes seleccionados.
69
         */
70
        public Envelope getSelectBound() {
71
                return rectangle;
72
        }
73
74
        public String getProcessDescription() {
75
                return "Defining rectangle to zoom from selected geometries";
76
        }
77
78
        public void visit(Feature feature) throws BaseException {
79
                if (rectangle == null) {
80
                        rectangle = (feature.getDefaultGeometry()).getEnvelope();
81
                } else {
82
                        rectangle.add((feature.getDefaultGeometry())
83
                                        .getEnvelope());
84
                }
85
        }
86
87
        public void visit(FeatureReference featureRefence) throws BaseException {
88
                this.visit(featureRefence.getFeature());
89
        }
90
91
        public void visit(Object obj) throws BaseException {
92
                if (obj instanceof FeatureReference) {
93
                        this.visit((FeatureReference) obj);
94
                        return;
95
                }
96
                if (obj instanceof Feature) {
97
                        this.visit((Feature) obj);
98
                        return;
99
                }
100
                if (obj instanceof FLayer) {
101
                        this.visit((FLayer) obj);
102
                        return;
103
                }
104
105
                throw new NotSupportedOperationException(this, obj);
106
        }
107
108
        public void visit(FLayer layer) throws BaseException {
109
                if (!(layer instanceof SingleLayer)) {
110
                        return;
111
                } else if (!layer.isActive()) {
112
                        return;
113
                }
114
                DataSet selection = ((SingleLayer) layer).getDataStore()
115
                                .getSelection();
116
117
                if (selection instanceof Visitable) {
118
                        ((Visitable) selection).accept(this);
119
                }
120
        }
121
122
123
}