svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / rendering / strategies / SelectedZoomVisitor.java @ 40559
History | View | Annotate | Download (3.18 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.mapcontext.rendering.strategies; |
25 |
|
26 |
import org.gvsig.fmap.dal.DataSet; |
27 |
import org.gvsig.fmap.dal.feature.Feature; |
28 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
29 |
import org.gvsig.fmap.geom.primitive.Envelope; |
30 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
31 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
32 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
33 |
import org.gvsig.tools.exception.BaseException; |
34 |
import org.gvsig.tools.visitor.NotSupportedOperationException; |
35 |
import org.gvsig.tools.visitor.Visitable; |
36 |
import org.gvsig.tools.visitor.Visitor; |
37 |
|
38 |
|
39 |
/**
|
40 |
* Visitor de zoom a lo seleccionado.
|
41 |
*
|
42 |
* @author Vicente Caballero Navarro
|
43 |
*/
|
44 |
public class SelectedZoomVisitor implements LayersVisitor, Visitor { |
45 |
private Envelope rectangle = null; |
46 |
|
47 |
/**
|
48 |
* Devuelve el Extent de los shapes seleccionados, y si no hay ning?n shape
|
49 |
* seleccionado devuelve null.
|
50 |
*
|
51 |
* @return Extent de los shapes seleccionados.
|
52 |
*/
|
53 |
public Envelope getSelectBound() {
|
54 |
return rectangle;
|
55 |
} |
56 |
|
57 |
public String getProcessDescription() { |
58 |
return "Defining rectangle to zoom from selected geometries"; |
59 |
} |
60 |
|
61 |
public void visit(Feature feature) throws BaseException { |
62 |
if (rectangle == null) { |
63 |
rectangle = (feature.getDefaultGeometry()).getEnvelope(); |
64 |
} else {
|
65 |
rectangle.add((feature.getDefaultGeometry()) |
66 |
.getEnvelope()); |
67 |
} |
68 |
} |
69 |
|
70 |
public void visit(FeatureReference featureRefence) throws BaseException { |
71 |
this.visit(featureRefence.getFeature());
|
72 |
} |
73 |
|
74 |
public void visit(Object obj) throws BaseException { |
75 |
if (obj instanceof FeatureReference) { |
76 |
this.visit((FeatureReference) obj);
|
77 |
return;
|
78 |
} |
79 |
if (obj instanceof Feature) { |
80 |
this.visit((Feature) obj);
|
81 |
return;
|
82 |
} |
83 |
if (obj instanceof FLayer) { |
84 |
this.visit((FLayer) obj);
|
85 |
return;
|
86 |
} |
87 |
|
88 |
throw new NotSupportedOperationException(this, obj); |
89 |
} |
90 |
|
91 |
public void visit(FLayer layer) throws BaseException { |
92 |
if (!(layer instanceof SingleLayer)) { |
93 |
return;
|
94 |
} else if (!layer.isActive()) { |
95 |
return;
|
96 |
} |
97 |
DataSet selection = ((SingleLayer) layer).getDataStore() |
98 |
.getSelection(); |
99 |
|
100 |
if (selection instanceof Visitable) { |
101 |
((Visitable) selection).accept(this);
|
102 |
} |
103 |
} |
104 |
|
105 |
|
106 |
} |