root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / mosaic / gui / SelectLayersFromViewPanel.java @ 31496
History | View | Annotate | Download (5.71 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional 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 Iba?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 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.mosaic.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.event.ActionEvent; |
46 |
|
47 |
import javax.swing.BorderFactory; |
48 |
import javax.swing.JPanel; |
49 |
import javax.swing.JScrollPane; |
50 |
import javax.swing.JTable; |
51 |
import javax.swing.border.TitledBorder; |
52 |
|
53 |
import org.gvsig.andami.PluginServices; |
54 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
55 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
56 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
57 |
import org.gvsig.remotesensing.principalcomponents.gui.BandTableFormat; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Panel que gestiona la selecci?n de imagenes de la vista.
|
62 |
*
|
63 |
* @author aMu?oz (alejandro.munoz@uclm.es)
|
64 |
* @version 24/4/2008
|
65 |
*
|
66 |
* */
|
67 |
public class SelectLayersFromViewPanel extends JPanel{ |
68 |
|
69 |
private static final long serialVersionUID = 1L; |
70 |
private DefaultViewPanel view = null; |
71 |
private JPanel imageViewPanel = null; |
72 |
private JTable tableImagesView = null; |
73 |
private BandTableFormat mModeloTable =null; |
74 |
private JScrollPane scrollImages=null; |
75 |
private FLayer[] layers = null;; |
76 |
|
77 |
public SelectLayersFromViewPanel (DefaultViewPanel view){
|
78 |
this.view= view;
|
79 |
if(this.view!=null) |
80 |
layers= new FLayer[view.getMapControl().getMapContext().getLayers().getLayersCount()];
|
81 |
int k=view.getMapControl().getMapContext().getLayers().getLayersCount()-1; |
82 |
for(int i=0;i<view.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
83 |
layers[i]=((FLyrRasterSE)view.getMapControl().getMapContext().getLayers().getLayer(k)); |
84 |
k--; |
85 |
} |
86 |
initUI(); |
87 |
loadLayers(); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Panel con la tabla que contiene las imagenes cargadas en la vista
|
92 |
* */
|
93 |
public JPanel getImageViewPanel() { |
94 |
if(imageViewPanel==null){ |
95 |
imageViewPanel = new JPanel(); |
96 |
TitledBorder topBorder = BorderFactory.createTitledBorder("seleccion_imagenes"); |
97 |
topBorder.setTitlePosition(TitledBorder.TOP);
|
98 |
imageViewPanel.setBorder(topBorder); |
99 |
imageViewPanel.add(getScrollImages(),BorderLayout.CENTER);
|
100 |
} |
101 |
return imageViewPanel;
|
102 |
} |
103 |
|
104 |
|
105 |
/**
|
106 |
* @return array de string con los nombre de las capas raster
|
107 |
*/
|
108 |
private String[] getLayerNames() { |
109 |
int i, capasraster=0; |
110 |
String[] sNames= null; |
111 |
|
112 |
for (i = 0; i < layers.length; i++) { |
113 |
if (layers[i]instanceof FLyrRasterSE) |
114 |
capasraster++; |
115 |
} |
116 |
// Se se toman las capas raster.
|
117 |
sNames = new String[capasraster]; |
118 |
capasraster=0;
|
119 |
|
120 |
for (i = 0; i < layers.length; i++) { |
121 |
if (layers[i]instanceof FLyrRasterSE){ |
122 |
sNames[capasraster] =layers[i].getName(); |
123 |
capasraster++; |
124 |
} |
125 |
} |
126 |
return sNames;
|
127 |
} |
128 |
|
129 |
|
130 |
/**
|
131 |
* @return scroll con bandas del r?ster
|
132 |
*/
|
133 |
public JScrollPane getScrollImages() { |
134 |
if (scrollImages==null){ |
135 |
scrollImages=new JScrollPane(); |
136 |
} |
137 |
getTableImages().getColumn("").setPreferredWidth(20); |
138 |
scrollImages.setPreferredSize(new Dimension(300,100)); |
139 |
scrollImages.setViewportView(getTableImages()); |
140 |
scrollImages.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
141 |
return scrollImages;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* @return modelo de tabla
|
146 |
* @see BandTableFormat
|
147 |
*/
|
148 |
public BandTableFormat getModeloTabla() {
|
149 |
if(mModeloTable==null){ |
150 |
mModeloTable=new BandTableFormat();
|
151 |
mModeloTable.setColumnName(PluginServices.getText(this,"imagen")); |
152 |
|
153 |
} |
154 |
return mModeloTable;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* @return tabla conlas bandas de la imagen
|
159 |
*/
|
160 |
public JTable getTableImages(){ |
161 |
if (tableImagesView==null){ |
162 |
tableImagesView=new JTable(getModeloTabla()); |
163 |
} |
164 |
return tableImagesView;
|
165 |
} |
166 |
|
167 |
|
168 |
/**
|
169 |
* M?todo que inicializa la interfaz a?adiendo los paneles correspondientes
|
170 |
* */
|
171 |
private void initUI(){ |
172 |
setLayout(new BorderLayout()); |
173 |
add(getImageViewPanel(), BorderLayout.CENTER);
|
174 |
} |
175 |
|
176 |
|
177 |
/**
|
178 |
* M?todo que carga en la tabla tableImagenView las capas raster de la vista
|
179 |
* Por defeto todas se encuentran activadas
|
180 |
* */
|
181 |
private void loadLayers(){ |
182 |
String[] layersNames =getLayerNames(); |
183 |
for (int i=0;i<layersNames.length;i++) |
184 |
getModeloTabla().addRow(layersNames[i],true);
|
185 |
getTableImages().updateUI(); |
186 |
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* Medodo que devuelve un array de Strings con en nombre de las capas seleccionadas
|
191 |
* */
|
192 |
public String[] getSelectedLayers(){ |
193 |
|
194 |
String[] layersSelectedNames =new String[getModeloTabla().getNumSelected()]; |
195 |
boolean []selected= mModeloTable.getSeleccionadas(); |
196 |
String [] sImages = getLayerNames(); |
197 |
int k=0; |
198 |
for(int i=0; i< sImages.length; i++) |
199 |
if(selected[i]){
|
200 |
layersSelectedNames[k]=sImages[i]; |
201 |
k++; |
202 |
} |
203 |
return layersSelectedNames;
|
204 |
} |
205 |
|
206 |
|
207 |
public void actionPerformed(ActionEvent e) { |
208 |
} |
209 |
|
210 |
} |