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