svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FLyrRasterAdjustPropertiesTocMenuEntry.java @ 8745
History | View | Annotate | Download (7.71 KB)
1 |
/*
|
---|---|
2 |
* Created on 23-mar-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
*/
|
23 |
package com.iver.cit.gvsig.gui.toc; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.util.ArrayList; |
27 |
|
28 |
import javax.swing.JMenuItem; |
29 |
|
30 |
import org.cresques.filter.RasterFilterStackManager; |
31 |
import org.cresques.io.GeoRasterFile; |
32 |
import org.cresques.ui.raster.BandSetupPanel; |
33 |
import org.cresques.ui.raster.FilterRasterDialogPanel; |
34 |
import org.cresques.ui.raster.InfoPanel; |
35 |
import org.cresques.ui.raster.RasterTransparencyPanel; |
36 |
|
37 |
import com.iver.andami.PluginServices; |
38 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
39 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
40 |
import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
41 |
import com.iver.cit.gvsig.gui.panels.IRasterPropertiesRegistrable; |
42 |
import com.iver.cit.gvsig.gui.panels.PropertiesRasterDialog; |
43 |
|
44 |
|
45 |
/**
|
46 |
* Entrada en del men? contextual del TOC correspondiente al cuadro de
|
47 |
* propiedades del raster
|
48 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
49 |
*
|
50 |
*/
|
51 |
public class FLyrRasterAdjustPropertiesTocMenuEntry extends TocMenuEntry { |
52 |
private JMenuItem properties; |
53 |
private FLayer lyr = null; |
54 |
private PropertiesRasterDialog propsDialog = null; |
55 |
private BandSetupPanel bandSetup = null; |
56 |
private ArrayList listeners = new ArrayList(); |
57 |
private RasterFilterStackManager stackManager = null; |
58 |
private BrightnessContrastTocMenuEntry bcMenuEntry = null; |
59 |
|
60 |
|
61 |
public void initialize(FPopupMenu m) { |
62 |
super.initialize(m);
|
63 |
|
64 |
if (isTocItemBranch()) {
|
65 |
lyr = getNodeLayer(); |
66 |
// Opcciones para capas raster
|
67 |
if ((lyr instanceof FLyrRaster)) { |
68 |
properties = new JMenuItem(PluginServices.getText(this, "propiedades_raster")); |
69 |
getMenu().add( properties ); |
70 |
properties.setFont(FPopupMenu.theFont); |
71 |
getMenu().setEnabled(true);
|
72 |
//getMenu().addSeparator();
|
73 |
//Cambio color
|
74 |
properties.addActionListener(this);
|
75 |
stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
|
76 |
if(bcMenuEntry == null) |
77 |
bcMenuEntry = new BrightnessContrastTocMenuEntry();
|
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Obtiene la instancia del cuadro de propiedades
|
84 |
* @return PropertiesRasterDialog
|
85 |
*/
|
86 |
public PropertiesRasterDialog getPropertiesDialog(){
|
87 |
return propsDialog;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Los objetos que quieren que se ejecute su listerner deben ser
|
92 |
* registrados a traves de este m?todo. Cuando se ejecute el actionPerformed
|
93 |
* se buscar? todos los objetos registrados y ejecutar? el actionPerformed de
|
94 |
* cada uno,
|
95 |
* @param obj Objeto a registrar
|
96 |
*/
|
97 |
public void register(Object obj){ |
98 |
if(obj instanceof IRasterPropertiesRegistrable) |
99 |
listeners.add(obj); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Obtiene el gestor de la pila de filtros
|
104 |
* @return RasterFilterStackManager
|
105 |
*/
|
106 |
public RasterFilterStackManager getStackManager() {
|
107 |
return stackManager;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* Gestiona la apertura del dialogo de propiedades de raster cuando se pulsa
|
112 |
* la opci?n asignando a este las propiedades iniciales.
|
113 |
*/
|
114 |
public void actionPerformed(ActionEvent e) { |
115 |
lyr = getNodeLayer(); |
116 |
|
117 |
if(lyr instanceof FLyrRaster){ |
118 |
stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
|
119 |
propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), stackManager.getTransparencyRGB());
|
120 |
|
121 |
//A?adimos los paneles de las ventanas registradas
|
122 |
for(int i=0;i<listeners.size();i++){ |
123 |
if(listeners.get(i) instanceof IRasterPropertiesRegistrable){ |
124 |
((IRasterPropertiesRegistrable)listeners.get(i)).setStackManager(stackManager); |
125 |
((IRasterPropertiesRegistrable)listeners.get(i)).addTabPanel(this);
|
126 |
} |
127 |
} |
128 |
|
129 |
FilterRasterDialogPanel filterPanel = ((FilterRasterDialogPanel)propsDialog.getContentPane()); |
130 |
|
131 |
int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency(); |
132 |
|
133 |
bandSetup = (BandSetupPanel)filterPanel.getPanelByClassName("BandSetupPanel");
|
134 |
|
135 |
//Asignaci?n del alpha actual de la imagen al dialogo
|
136 |
RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)filterPanel.getPanelByClassName("RasterTransparencyPanel");
|
137 |
rasterTrans.setOpacity(alpha); |
138 |
|
139 |
propsDialog.setRasterFilterStackManager(stackManager); |
140 |
|
141 |
ArrayList stackList = stackManager.getStringsFromStack();
|
142 |
String hideBands = null; |
143 |
for(int i=0;i<stackList.size();i++){ |
144 |
if(((String)stackList.get(i)).startsWith("filter.removebands.bands")) |
145 |
hideBands = RasterFilterStackManager.getValue((String)stackList.get(i));
|
146 |
} |
147 |
|
148 |
GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
|
149 |
propsDialog.addFiles(files); |
150 |
for(int i=0; i< files.length;i++) |
151 |
propsDialog.addNumBands(files[i].getBandCount()); |
152 |
|
153 |
RasterAdapter rad = ((FLyrRaster)lyr).getSource(); |
154 |
int posR = 0, posG = 0, posB = 0; |
155 |
|
156 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++) |
157 |
posR += files[i].getBandCount(); |
158 |
posR += rad.getBand(GeoRasterFile.RED_BAND); |
159 |
|
160 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++) |
161 |
posG += files[i].getBandCount(); |
162 |
posG += rad.getBand(GeoRasterFile.GREEN_BAND); |
163 |
|
164 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++) |
165 |
posB += files[i].getBandCount(); |
166 |
posB += rad.getBand(GeoRasterFile.BLUE_BAND); |
167 |
|
168 |
bandSetup.assignBand(posR, GeoRasterFile.RED_BAND); |
169 |
bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND); |
170 |
bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND); |
171 |
|
172 |
InfoPanel pInfo = (InfoPanel)this.propsDialog.getPanelByClassName("InfoPanel"); |
173 |
pInfo.setBands(posR, posG, posB); |
174 |
pInfo.refresh(); |
175 |
|
176 |
//Selecci?n de 1, 2 o 3 bandas para visualizar
|
177 |
if(hideBands != null){ |
178 |
int pos = 2; |
179 |
if(hideBands.length() == 1) |
180 |
pos = 1;
|
181 |
else if(hideBands.length() == 2) |
182 |
pos = 0;
|
183 |
bandSetup.getFileList().getJComboBox().setSelectedIndex(pos); |
184 |
|
185 |
//Reseteamos los controles de la tabla
|
186 |
|
187 |
for(int i=0;i<bandSetup.getRGBTable().getModel().getRowCount();i++) |
188 |
for(int j=0;j<3;j++) |
189 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(false), i, j); |
190 |
|
191 |
if(hideBands.equals("GB") || hideBands.equals("G") || hideBands.equals("B") ) |
192 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posR, 0); |
193 |
|
194 |
if(hideBands.equals("RB") || hideBands.equals("R") || hideBands.equals("B") ) |
195 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posG, 1); |
196 |
|
197 |
if(hideBands.equals("RG") || hideBands.equals("R") || hideBands.equals("G") ) |
198 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posB, 2); |
199 |
} |
200 |
|
201 |
propsDialog.readStat(); |
202 |
|
203 |
//Ejecuta el listener de todos los que se han registrado
|
204 |
for(int i=0;i<listeners.size();i++){ |
205 |
if(listeners.get(i) instanceof IRasterPropertiesRegistrable) |
206 |
((IRasterPropertiesRegistrable)listeners.get(i)).actionPerformed(stackManager, propsDialog, null);
|
207 |
} |
208 |
|
209 |
bcMenuEntry.actionPerformed(stackManager, propsDialog, null);
|
210 |
|
211 |
PluginServices.getMDIManager().addWindow(propsDialog); |
212 |
} |
213 |
} |
214 |
|
215 |
} |