root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / gui / FLyrRasterAdjustPropertiesTocMenuEntry.java @ 9727
History | View | Annotate | Download (8.04 KB)
1 | 7304 | caballero | /*
|
---|---|---|---|
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.project.documents.view.toc.gui; |
||
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 | 9727 | nacho | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
41 | 7304 | caballero | import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
42 | 9727 | nacho | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
43 | 7304 | caballero | import com.iver.cit.gvsig.gui.panels.IRasterPropertiesRegistrable; |
44 | import com.iver.cit.gvsig.gui.panels.PropertiesRasterDialog; |
||
45 | 9727 | nacho | import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
46 | import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
||
47 | 7304 | caballero | |
48 | |||
49 | /**
|
||
50 | * Entrada en del men? contextual del TOC correspondiente al cuadro de
|
||
51 | * propiedades del raster
|
||
52 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
53 | *
|
||
54 | */
|
||
55 | 9727 | nacho | public class FLyrRasterAdjustPropertiesTocMenuEntry extends AbstractTocContextMenuAction { |
56 | 7304 | caballero | private JMenuItem properties; |
57 | private FLayer lyr = null; |
||
58 | private PropertiesRasterDialog propsDialog = null; |
||
59 | private BandSetupPanel bandSetup = null; |
||
60 | private ArrayList listeners = new ArrayList(); |
||
61 | private RasterFilterStackManager stackManager = null; |
||
62 | private BrightnessContrastTocMenuEntry bcMenuEntry = null; |
||
63 | |||
64 | 9727 | nacho | public String getGroup() { |
65 | return "raster"; |
||
66 | 7304 | caballero | } |
67 | 9727 | nacho | |
68 | public int getGroupOrder() { |
||
69 | return 60; |
||
70 | } |
||
71 | |||
72 | public int getOrder() { |
||
73 | return 0; |
||
74 | } |
||
75 | |||
76 | public String getText() { |
||
77 | return PluginServices.getText(this, "propiedades_raster"); |
||
78 | } |
||
79 | 7304 | caballero | |
80 | /**
|
||
81 | * Obtiene la instancia del cuadro de propiedades
|
||
82 | * @return PropertiesRasterDialog
|
||
83 | */
|
||
84 | public PropertiesRasterDialog getPropertiesDialog(){
|
||
85 | return propsDialog;
|
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * Los objetos que quieren que se ejecute su listerner deben ser
|
||
90 | * registrados a traves de este m?todo. Cuando se ejecute el actionPerformed
|
||
91 | * se buscar? todos los objetos registrados y ejecutar? el actionPerformed de
|
||
92 | * cada uno,
|
||
93 | * @param obj Objeto a registrar
|
||
94 | */
|
||
95 | public void register(Object obj){ |
||
96 | if(obj instanceof IRasterPropertiesRegistrable) |
||
97 | listeners.add(obj); |
||
98 | } |
||
99 | |||
100 | /**
|
||
101 | * Obtiene el gestor de la pila de filtros
|
||
102 | * @return RasterFilterStackManager
|
||
103 | */
|
||
104 | public RasterFilterStackManager getStackManager() {
|
||
105 | return stackManager;
|
||
106 | } |
||
107 | |||
108 | 9727 | nacho | public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
109 | return selectedItems.length == 1; |
||
110 | } |
||
111 | |||
112 | public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
||
113 | if (isTocItemBranch(item))
|
||
114 | return (getNodeLayer(item) instanceof FLyrRaster); |
||
115 | return false; |
||
116 | |||
117 | } |
||
118 | |||
119 | 7304 | caballero | /**
|
120 | * Gestiona la apertura del dialogo de propiedades de raster cuando se pulsa
|
||
121 | * la opci?n asignando a este las propiedades iniciales.
|
||
122 | */
|
||
123 | 9727 | nacho | public void execute(ITocItem item, FLayer[] selectedItems) { |
124 | if (selectedItems.length==1) |
||
125 | lyr = selectedItems[0];
|
||
126 | else
|
||
127 | return;
|
||
128 | |||
129 | stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
|
||
130 | if(bcMenuEntry == null) |
||
131 | bcMenuEntry = new BrightnessContrastTocMenuEntry();
|
||
132 | |||
133 | 7304 | caballero | if(lyr instanceof FLyrRaster){ |
134 | stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
|
||
135 | propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), stackManager.getTransparencyRGB());
|
||
136 | |||
137 | //A?adimos los paneles de las ventanas registradas
|
||
138 | for(int i=0;i<listeners.size();i++){ |
||
139 | if(listeners.get(i) instanceof IRasterPropertiesRegistrable){ |
||
140 | ((IRasterPropertiesRegistrable)listeners.get(i)).setStackManager(stackManager); |
||
141 | ((IRasterPropertiesRegistrable)listeners.get(i)).addTabPanel(this);
|
||
142 | } |
||
143 | } |
||
144 | |||
145 | FilterRasterDialogPanel filterPanel = ((FilterRasterDialogPanel)propsDialog.getContentPane()); |
||
146 | |||
147 | int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency(); |
||
148 | |||
149 | bandSetup = (BandSetupPanel)filterPanel.getPanelByClassName("BandSetupPanel");
|
||
150 | |||
151 | //Asignaci?n del alpha actual de la imagen al dialogo
|
||
152 | RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)filterPanel.getPanelByClassName("RasterTransparencyPanel");
|
||
153 | rasterTrans.setOpacity(alpha); |
||
154 | |||
155 | propsDialog.setRasterFilterStackManager(stackManager); |
||
156 | |||
157 | ArrayList stackList = stackManager.getStringsFromStack();
|
||
158 | String hideBands = null; |
||
159 | for(int i=0;i<stackList.size();i++){ |
||
160 | if(((String)stackList.get(i)).startsWith("filter.removebands.bands")) |
||
161 | hideBands = RasterFilterStackManager.getValue((String)stackList.get(i));
|
||
162 | } |
||
163 | |||
164 | GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
|
||
165 | propsDialog.addFiles(files); |
||
166 | for(int i=0; i< files.length;i++) |
||
167 | propsDialog.addNumBands(files[i].getBandCount()); |
||
168 | |||
169 | RasterAdapter rad = ((FLyrRaster)lyr).getSource(); |
||
170 | int posR = 0, posG = 0, posB = 0; |
||
171 | |||
172 | for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++) |
||
173 | posR += files[i].getBandCount(); |
||
174 | posR += rad.getBand(GeoRasterFile.RED_BAND); |
||
175 | |||
176 | for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++) |
||
177 | posG += files[i].getBandCount(); |
||
178 | posG += rad.getBand(GeoRasterFile.GREEN_BAND); |
||
179 | |||
180 | for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++) |
||
181 | posB += files[i].getBandCount(); |
||
182 | posB += rad.getBand(GeoRasterFile.BLUE_BAND); |
||
183 | |||
184 | bandSetup.assignBand(posR, GeoRasterFile.RED_BAND); |
||
185 | bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND); |
||
186 | bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND); |
||
187 | |||
188 | InfoPanel pInfo = (InfoPanel)this.propsDialog.getPanelByClassName("InfoPanel"); |
||
189 | pInfo.setBands(posR, posG, posB); |
||
190 | pInfo.refresh(); |
||
191 | |||
192 | //Selecci?n de 1, 2 o 3 bandas para visualizar
|
||
193 | if(hideBands != null){ |
||
194 | int pos = 2; |
||
195 | if(hideBands.length() == 1) |
||
196 | pos = 1;
|
||
197 | else if(hideBands.length() == 2) |
||
198 | pos = 0;
|
||
199 | bandSetup.getFileList().getJComboBox().setSelectedIndex(pos); |
||
200 | |||
201 | //Reseteamos los controles de la tabla
|
||
202 | |||
203 | for(int i=0;i<bandSetup.getRGBTable().getModel().getRowCount();i++) |
||
204 | for(int j=0;j<3;j++) |
||
205 | bandSetup.getRGBTable().getModel().setValueAt(new Boolean(false), i, j); |
||
206 | |||
207 | if(hideBands.equals("GB") || hideBands.equals("G") || hideBands.equals("B") ) |
||
208 | bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posR, 0); |
||
209 | |||
210 | if(hideBands.equals("RB") || hideBands.equals("R") || hideBands.equals("B") ) |
||
211 | bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posG, 1); |
||
212 | |||
213 | if(hideBands.equals("RG") || hideBands.equals("R") || hideBands.equals("G") ) |
||
214 | bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posB, 2); |
||
215 | } |
||
216 | |||
217 | propsDialog.readStat(); |
||
218 | |||
219 | //Ejecuta el listener de todos los que se han registrado
|
||
220 | for(int i=0;i<listeners.size();i++){ |
||
221 | if(listeners.get(i) instanceof IRasterPropertiesRegistrable) |
||
222 | ((IRasterPropertiesRegistrable)listeners.get(i)).actionPerformed(stackManager, propsDialog, null);
|
||
223 | } |
||
224 | |||
225 | bcMenuEntry.actionPerformed(stackManager, propsDialog, null);
|
||
226 | |||
227 | PluginServices.getMDIManager().addWindow(propsDialog); |
||
228 | } |
||
229 | } |
||
230 | |||
231 | } |