Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extWCS / src / com / iver / cit / gvsig / gui / toc / WCSPropsRasterTocMenuEntry.java @ 9058

History | View | Annotate | Download (7.39 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.toc;
42

    
43
import java.awt.event.ActionEvent;
44

    
45
import javax.swing.JMenuItem;
46

    
47
import org.cresques.filter.RasterFilter;
48
import org.cresques.filter.RasterFilterStackManager;
49
import org.cresques.io.GeoRasterFile;
50
import org.cresques.px.PxRaster;
51
import org.cresques.ui.BrightnessContrast.EnhancedBrightnessContrastPanel;
52
import org.cresques.ui.filter.FilterRasterDialogPanel;
53
import org.cresques.ui.filter.RasterTransparencyPanel;
54
import org.cresques.ui.raster.BandSetupPanel;
55
import org.cresques.ui.raster.InfoPanel;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.layers.FLayer;
59
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
60
import com.iver.cit.gvsig.fmap.layers.FLyrWCS;
61
import com.iver.cit.gvsig.gui.dialog.WCSRasterPropsDialog;
62
import com.iver.cit.gvsig.project.documents.view.toc.TocMenuEntry;
63
import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu;
64

    
65
/**
66
 * 
67
 * @author Nacho Brodin (brodin_ign@gva.es)
68
 */
69
public class WCSPropsRasterTocMenuEntry  extends TocMenuEntry {
70
        private JMenuItem propsMenuItem;
71
        FLayer lyr = null;
72
        private WCSRasterPropsDialog        propsDialog = null;
73
        private BandSetupPanel                         bandSetup = null;
74
        
75
        public void initialize(FPopupMenu m) {
76
                super.initialize(m);
77
                
78
                if (isTocItemBranch()) {
79
                        lyr = getNodeLayer();
80
                    // Opcciones para capas WCS
81
                    if ((lyr instanceof FLyrWCS)) {
82
                            propsMenuItem = new JMenuItem(PluginServices.getText(this, "propiedades_raster"));
83
                            getMenu().add( propsMenuItem );
84
                            propsMenuItem.setFont(FPopupMenu.theFont);
85
                            getMenu().setEnabled(true);
86
                            //getMenu().addSeparator();
87
                    //Cambio color
88
                            propsMenuItem.addActionListener(this);                           
89
                     }
90
                }
91
        }
92
        /* (non-Javadoc)
93
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
94
         */
95
        public void actionPerformed(ActionEvent e) {
96
               lyr = getNodeLayer();
97
        
98
                if(lyr instanceof FLyrWCS && ((FLyrWCS) lyr).getPxRaster()!=null){
99
                        RasterFilterStackManager         stackManager = null;
100
                        
101
                        FLyrWCS layer = (FLyrWCS) lyr;
102

    
103
                        stackManager = new RasterFilterStackManager(layer.getFilterStack());
104
                        propsDialog = new WCSRasterPropsDialog(layer, stackManager.getTransparencyRGB());
105
                        
106
                        int alpha = layer.getPxRaster().getAlpha();
107
                        
108
                        FilterRasterDialogPanel filterPanel = ((FilterRasterDialogPanel)propsDialog.getContentPane());
109
                        
110
                        bandSetup = (BandSetupPanel)filterPanel.getPanelByClassName("BandSetupPanel");
111
                        GeoRasterFile[] files = layer.getPxRaster().getFiles();
112
                        bandSetup.addFiles(files);
113
                        for(int i=0; i< files.length;i++)
114
                                propsDialog.addNumBands(files[i].getBandCount());
115
                                
116
                        PxRaster px = layer.getPxRaster();
117
                        int posR = 0, posG = 0, posB = 0;
118
                        
119
                        for(int i=0;i<px.getPosFile(GeoRasterFile.RED_BAND);i++)
120
                                posR += files[i].getBandCount();
121
                        posR += px.getBand(GeoRasterFile.RED_BAND);
122
                        
123
                        for(int i=0;i<px.getPosFile(GeoRasterFile.GREEN_BAND);i++)
124
                                posG += files[i].getBandCount();
125
                        posG += px.getBand(GeoRasterFile.GREEN_BAND);
126
                        
127
                        for(int i=0;i<px.getPosFile(GeoRasterFile.BLUE_BAND);i++)
128
                                posB += files[i].getBandCount();
129
                        posB += px.getBand(GeoRasterFile.BLUE_BAND);
130
                        
131
                                        
132
                        bandSetup.assignBand(posR, GeoRasterFile.RED_BAND);
133
                        bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND);
134
                        bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND);        
135

    
136
                        InfoPanel pInfo = (InfoPanel)this.propsDialog.getPanelByClassName("InfoPanel");
137
                        pInfo.setBands(posR, posG, posB);
138
                        pInfo.addFiles(files);        
139
                        
140
                        //Asignaci?n del alpha actual de la imagen al dialogo
141
                        RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)filterPanel.getPanelByClassName("RasterTransparencyPanel");
142
                        rasterTrans.setOpacity(alpha);
143
                                                        
144
                        propsDialog.setRasterFilterStackManager(stackManager);                                                        
145
                        propsDialog.readStat();
146
                        
147
                        actionPerformed(stackManager, propsDialog, null);
148
                        
149
                        PluginServices.getMDIManager().addWindow(propsDialog);               
150
                }
151
        }
152
        
153
        /**
154
         * Modificaci?n del estado de los controles del panel de brillo y contraste
155
         */
156
        public void actionPerformed(RasterFilterStackManager stackManager, WCSRasterPropsDialog propsDialog, FLyrRaster fLayer) {
157
                EnhancedBrightnessContrastPanel bcPanel = (EnhancedBrightnessContrastPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("EnhancedBrightnessContrastPanel"); 
158
                //bcPanel.setPropertiesDialog(propsDialog);
159
                
160
                if(stackManager.isActive(stackManager.getTypeFilter("brightness"))){
161
                        bcPanel.getCBrightC().setSelected(true);
162
                        bcPanel.setBCControlEnabled(true);
163
                        
164
                        RasterFilter bright = stackManager.getFilter("brightness");
165
                        
166
                        if(bright.getParam("incrBrillo") != null){
167
                                int incr = ((Integer)bright.getParam("incrBrillo")).intValue();
168
                                bcPanel.getLabelSliderText().setSliderValue(incr);
169
                                bcPanel.getLabelSliderText().setTextValue(String.valueOf(incr));
170
                        }
171
                }
172
                
173
                if(stackManager.isActive(stackManager.getTypeFilter("contrast"))){
174
                        bcPanel.getCBrightC().setSelected(true);
175
                        bcPanel.setBCControlEnabled(true);
176
                        
177
                        RasterFilter cont = stackManager.getFilter("contrast");
178
                        
179
                        if(cont.getParam("incrContraste") != null){
180
                                int incr = ((Integer)cont.getParam("incrContraste")).intValue();
181
                                bcPanel.getLabelSliderText1().setSliderValue(incr);
182
                                bcPanel.getLabelSliderText1().setTextValue(String.valueOf(incr));
183
                        }
184
                }
185
                
186
                if(stackManager.isActive(stackManager.getTypeFilter("enhanced"))){
187
                        bcPanel.getCEnhanced().setSelected(true);
188
                        bcPanel.setEControlEnabled(true);
189
                        
190
                        RasterFilter enhan = stackManager.getFilter("enhanced");
191
                        RasterFilter tail = stackManager.getFilter("tail");
192
                        
193
                        
194
                                boolean rem = ((Boolean)enhan.getParam("remove")).booleanValue();
195
                                bcPanel.getJCheckBox().setSelected(rem);
196
                        
197
                        if(stackManager.isActive(stackManager.getTypeFilter("tail"))){
198
                                double percent = (stackManager.getStackStats().tailPercent)*100;
199
                                bcPanel.getCheckSliderText().setTextValue(String.valueOf(percent));
200
                                bcPanel.getCheckSliderText().setSliderValue((int)percent);
201
                                bcPanel.getCheckSliderText().setSelected(true);
202
                                bcPanel.getCheckSliderText().setControlEnabled(true);
203
                                boolean remove = ((Boolean)tail.getParam("remove")).booleanValue();
204
                                if((remove == true) || (rem == true))
205
                                        bcPanel.getJCheckBox().setSelected(true);
206
                                else 
207
                                        bcPanel.getJCheckBox().setSelected(false);
208
                                
209
                        }
210
                }
211
        }
212
}