Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / selectionByTheme / MySelectionByThemeListener.java @ 5669

History | View | Annotate | Download (5.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 com.iver.cit.gvsig.gui.selectionByTheme;
42

    
43
import com.iver.andami.messages.NotificationManager;
44
import com.iver.cit.gvsig.fmap.DriverException;
45
import com.iver.cit.gvsig.fmap.layers.FBitSet;
46
import com.iver.cit.gvsig.fmap.layers.FLayer;
47
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
48
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
49
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
50
import com.iver.cit.gvsig.fmap.operations.strategies.QueryByThemeVisitor;
51
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
52

    
53
/**
54
 * DOCUMENT ME!
55
 * 
56
 * @author Fernando Gonz?lez Cort?s
57
 */
58
public class MySelectionByThemeListener implements SelectionByThemeListener {
59
        /**
60
         * @see com.iver.cit.gvsig.gui.selectionByTheme.SelectionByThemeListener#newSet(int,
61
         *      int, int)
62
         */
63
        public void newSet(FLayer[] toSelect, FLayer selectionLayer, int action) {
64
                long t1 = System.currentTimeMillis();
65
                if (selectionLayer instanceof FLyrVect) {
66
                        try {
67
                                Selectable selected = ((FLyrVect) selectionLayer)
68
                                                .getRecordset();
69
                                for (int i = 0; i < toSelect.length; i++) {
70
                                        if (toSelect[i] instanceof FLyrVect) {
71
                                                Selectable capa = ((FLyrVect) toSelect[i])
72
                                                                .getRecordset();
73
                                                QueryByThemeVisitor visitor = new QueryByThemeVisitor(
74
                                                                toSelect[i], selectionLayer, action);
75
                                                capa.clearSelection();
76

    
77
                                                ((VectorialData) selectionLayer).process(visitor,
78
                                                                selected.getSelection());
79
                                                capa.setSelection(visitor.getBitset());
80
                                        }
81
                                }
82
                        } catch (DriverException e) {
83
                                NotificationManager.addError("Error leyendo las capas", e);
84
                        } catch (VisitException e) {
85
                                NotificationManager.addError("Error leyendo las capas", e);
86
                        }
87

    
88
                }
89
                long t2 = System.currentTimeMillis();
90
                System.out
91
                                .println("Tiempo de consulta: " + (t2 - t1) + " milisegundos");
92
                // doSelection(toSelect, selectionLayer, action, false);
93
        }
94

    
95
        /**
96
         * @see com.iver.cit.gvsig.gui.selectionByTheme.SelectionByThemeListener#addToSet(int,
97
         *      int, int)
98
         */
99
        public void addToSet(FLayer[] toSelect, FLayer selectionLayer, int action) {
100
                if (selectionLayer instanceof FLyrVect) {
101
                        try {
102
                                Selectable selected = ((FLyrVect) selectionLayer)
103
                                                .getRecordset();
104
                                for (int i = 0; i < toSelect.length; i++) {
105
                                        if (toSelect[i] instanceof FLyrVect) {
106
                                                Selectable capa = ((FLyrVect) toSelect[i])
107
                                                                .getRecordset();
108
                                                QueryByThemeVisitor visitor = new QueryByThemeVisitor(
109
                                                                toSelect[i], selectionLayer, action);
110
                                                FBitSet selection = capa.getSelection();
111
                                                ((VectorialData) selectionLayer).process(visitor,
112
                                                                selected.getSelection());
113
                                                selection.or(visitor.getBitset());
114
                                                capa.setSelection(selection);
115
                                        }
116
                                }
117
                        } catch (DriverException e) {
118
                                NotificationManager.addError("Error leyendo las capas", e);
119
                        } catch (VisitException e) {
120
                                NotificationManager.addError("Error leyendo las capas", e);
121
                        }
122
                }
123
        }
124

    
125
        /**
126
         * @see com.iver.cit.gvsig.gui.selectionByTheme.SelectionByThemeListener#fromSet(int,
127
         *      int, int)
128
         */
129
        public void fromSet(FLayer[] toSelect, FLayer selectionLayer, int action) {
130
                if (selectionLayer instanceof FLyrVect) {
131
                        try {
132
                                Selectable selected = ((FLyrVect) selectionLayer)
133
                                                .getRecordset();
134
                                for (int i = 0; i < toSelect.length; i++) {
135
                                        if (toSelect[i] instanceof FLyrVect) {
136
                                                Selectable capa = ((FLyrVect) toSelect[i])
137
                                                                .getRecordset();
138

    
139
                                                QueryByThemeVisitor visitor = new QueryByThemeVisitor(
140
                                                                toSelect[i], selectionLayer, action);
141
                                                FBitSet selection = capa.getSelection();
142
                                                ((VectorialData) selectionLayer).process(visitor,
143
                                                                selected.getSelection());
144
                                                selection.and(visitor.getBitset());
145
                                                capa.setSelection(selection);
146
                                        }
147
                                }
148
                        } catch (DriverException e) {
149
                                NotificationManager.addError("Error leyendo las capas", e);
150
                        } catch (VisitException e) {
151
                                NotificationManager.addError("Error leyendo las capas", e);
152
                        }
153

    
154
                }
155
        }
156
}