Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / SelectImageListener.java @ 24759

History | View | Annotate | Download (4 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 com.iver.cit.gvsig.project.documents.view.toolListeners;
42

    
43
import java.awt.geom.Point2D;
44

    
45
import org.gvsig.fmap.dal.exception.ReadException;
46
import org.gvsig.fmap.geom.primitive.Envelope;
47
import org.gvsig.fmap.mapcontext.ViewPort;
48
import org.gvsig.fmap.mapcontext.layers.FLayer;
49
import org.gvsig.fmap.mapcontext.layers.FLayers;
50
import org.gvsig.fmap.mapcontrol.MapControl;
51
import org.gvsig.fmap.mapcontrol.tools.SelectImageListenerImpl;
52
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
53

    
54
import com.iver.andami.PluginServices;
55

    
56

    
57
/**
58
 * <p>Listener to select the upper layer with raster data that has information in the associated <code>MapControl</code> object, down
59
 *  the position selected by a single click of any button of the mouse.</p>
60
 *
61
 * <p>The layer selected will be set as <i>active</i>, and the available controls for managing the data will be updated, enabling and
62
 *  disabling the necessary.</p>
63
 *
64
 * <p>The status of the other layers will be changed to <i>not active</i>.</p>
65
 *
66
 * @deprecated
67
 * @author Nacho Brodin <brodin_ign@gva.es>
68
 */
69
public class SelectImageListener extends SelectImageListenerImpl {
70

    
71
        //FLyrRaster                         layer = null;
72

    
73
        /**
74
         * Extent of the layer selected.
75
         */
76
        Envelope extentLayer = null;
77

    
78
        /**
79
         * <p>Creates a new <code>SelectImageListener</code> object.</p>
80
         *
81
         * @param mapCtrl the <code>MapControl</code> where are stored the layers
82
         */
83
        public SelectImageListener(MapControl mapCtrl) {
84
                super(mapCtrl);
85
        }
86

    
87
        /*
88
         *  (non-Javadoc)
89
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
90
         */
91
        public void point(PointEvent event) {
92
                super.point(event);
93

    
94
                Point2D pointSelect = event.getPoint();
95

    
96
                if (PluginServices.getMainFrame() != null) {
97
                        PluginServices.getMainFrame().enableControls();
98
                }
99

    
100
                ViewPort vp = mapCtrl.getMapContext().getViewPort();
101

    
102
                wcPoint = vp.toMapPoint((int)pointSelect.getX(), (int)pointSelect.getY());
103

    
104
                FLayers layers = mapCtrl.getMapContext().getLayers();
105
                for(int i=0;i<layers.getLayersCount();i++) {
106
                        layers.getLayer(i).setActive(false);
107
                }
108

    
109
                for(int i=layers.getLayersCount()-1;i>=0;i--){
110
                        if (select(layers.getLayer(i))) {
111
                                break;
112
                        }
113
                }
114
        }
115

    
116
        /**
117
         * Determines if the <code>layer</code> is selected at a position starting by the end.
118
         *
119
         * @param layer kind of layer
120
         * @param pos number of positions starting by the end
121
         *
122
         * @return <code>true</code> if the <code>layer</code> is selected at a position starting by the end, otherwise <code>false</code>
123
         */
124
        private boolean select(FLayer layer){
125
                if (layer instanceof FLayers){
126
                        FLayers laux=(FLayers)layer;
127
                        for (int j=laux.getLayersCount()-1;j>=0;j--){
128
                                if (select(laux.getLayer(j))){
129
                                        return true;
130
                                }
131
                        }
132
                }else{
133
                        try{
134
                                extentLayer = layer.getFullEnvelope();
135
                        }catch(ReadException exc){
136
                                exc.printStackTrace();
137
                        }
138
                }
139
                return false;
140
        }
141
}