Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / SelectImageListener.java @ 31496

History | View | Annotate | Download (4.08 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.view.toolListeners;
42

    
43
import java.awt.geom.Point2D;
44

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

    
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
 * FIXME: Si esta deprecated deberiamos indicar que hemos de usar en su lugar.
70
 * 
71
 */
72
public class SelectImageListener extends SelectImageListenerImpl {
73

    
74
        //FLyrRaster                         layer = null;
75

    
76
        /**
77
         * Extent of the layer selected.
78
         */
79
        Envelope extentLayer = null;
80

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

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

    
97
                Point2D pointSelect = event.getPoint();
98

    
99
                if (PluginServices.getMainFrame() != null) {
100
                        PluginServices.getMainFrame().enableControls();
101
                }
102

    
103
                ViewPort vp = mapCtrl.getMapContext().getViewPort();
104

    
105
                wcPoint = vp.toMapPoint((int)pointSelect.getX(), (int)pointSelect.getY());
106

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

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

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