Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1002 / libraries / libCq_CMS_praster / src / org / cresques / ui / filter / FilterRasterDialogPanel.java @ 12070

History | View | Annotate | Download (9.66 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.filter;
25

    
26
import java.awt.event.ComponentEvent;
27
import java.awt.event.ComponentListener;
28
import java.awt.event.FocusEvent;
29
import java.awt.event.FocusListener;
30
import java.awt.event.KeyEvent;
31
import java.awt.event.KeyListener;
32
import java.awt.event.MouseEvent;
33
import java.awt.event.MouseListener;
34
import java.util.ArrayList;
35
import java.util.TreeMap;
36

    
37
import javax.swing.JPanel;
38
import javax.swing.event.ChangeEvent;
39
import javax.swing.event.ChangeListener;
40

    
41
import org.cresques.filter.IRasterOperationsRegistrablePanels;
42
import org.cresques.filter.enhancement.TransparencyRange;
43
import org.cresques.io.GeoRasterFile;
44
import org.cresques.ui.DefaultTabPanel;
45
import org.cresques.ui.BrightnessContrast.EnhancedBrightnessContrastPanel;
46
import org.cresques.ui.raster.BandSetupPanel;
47
import org.cresques.ui.raster.IResize;
48
import org.cresques.ui.raster.InfoPanel;
49

    
50

    
51
/**
52
 * Panel que contiene todos los paneles de los tabs del cuadro de dialogo
53
 * de bandas y transparencias
54
 *
55
 * @author Nacho Brodin (brodin_ign@gva.es)
56
 */
57
public class FilterRasterDialogPanel extends DefaultTabPanel
58
    implements MouseListener, FocusListener, KeyListener, ChangeListener, ComponentListener {
59
    final private static long serialVersionUID = -3370601314380922368L;
60

    
61
    /**
62
     * Tama?o en X del panel interior.El tab de dentro es proporcional
63
     */
64
    protected int sizePanelX = 460;
65
    
66
    /**
67
     * Tama?o en Y del panel interior. El tab de dentro es proporcional
68
     */
69
    protected int sizePanelY = 285;
70
    
71
    /**
72
     * Propiedades guardadas en una matriz Nx2 con la forma propiedad/valor.
73
     */
74
    public Object[][] props = null;
75
    
76
    /**
77
     * N?mero de bandas.
78
     */
79
    protected int nbands = 0;
80
    
81
    /**
82
     * Lista de georrasterfiles correspondiente a los ficheros de bandas
83
     */
84
    protected GeoRasterFile[] grf = null;
85
    private TreeMap shadePanel = new TreeMap();
86
    
87
    //Paneles que se registran dentro de esta misma clase
88
    private RasterTransparencyPanel                         pTrans = null;
89
    private BandSetupPanel                                                pSetup = null;
90
    private InfoPanel                                                         pInfo = null;
91
    private EnhancedBrightnessContrastPanel         pEnhancedBrightnessContrast = null;
92
    
93
            
94
    /**
95
     * Constructor. Inicializa los paneles y propiedades
96
     * @param props        Propiedades
97
     */
98
    public FilterRasterDialogPanel(Object[][] props) {
99
        super();
100
        init(props);
101
    }
102

    
103
    /**
104
     * Constructor
105
     */
106
    public FilterRasterDialogPanel() {
107
        super();
108
    }
109

    
110
    /**
111
     * Inicializa las propiedades
112
     * @param props        Propiedades. Guardadas en una matriz Nx2 con la forma proiedad/valor
113
     */
114
    public void init(Object[][] props) {
115
        contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX + this.difWidth,
116
                                                            sizePanelY + this.difHeight));
117
        this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX + this.difWidth,
118
                                                                sizePanelY + difHeight - 5));
119
        this.pButton.setPreferredSize(new java.awt.Dimension(sizePanelX + this.difWidth, 25));
120
        //this.buttonPane.setPreferredSize(new java.awt.Dimension(200,25));
121
        
122
        this.props = props;
123
        initPanels();
124
        
125
    }
126

    
127
    /**
128
     * This method initializes this
129
     *
130
     * @return void
131
     */
132
    protected void initPanels() {
133
        this.setBounds(0, 0, 355, 230);
134
        pTrans = new RasterTransparencyPanel(this);
135
        pSetup = new BandSetupPanel();
136
        pInfo = new InfoPanel(this);
137
        pEnhancedBrightnessContrast = new EnhancedBrightnessContrastPanel(this);
138
        
139
        this.addTab(pInfo.getName(), pInfo);
140
        this.addTab(pSetup.getName(), pSetup);
141
        this.addTab(pTrans.getName(), pTrans);
142
        this.addTab(pEnhancedBrightnessContrast.getName(), pEnhancedBrightnessContrast);
143
   
144
        //pTrans.getOpacitySlider().addChangeListener(this);
145
        //pTrans.addFocusListener(this);
146
        this.getTab().addFocusListener(this);
147
    }
148

    
149
    /**
150
     * Asigna la visibilidad de un tab a verdadero o falso. La
151
     * selecci?n del tab se hace por el identificador.
152
     * @param tab        Identificador del tab. Variable nom del mismo
153
     * @param active        True o false para visible o invisible.
154
     */
155
    public void setTabVisible(String tab, boolean active){
156
            if(active == false){
157
                    for(int i=0; i<this.getTab().getTabCount(); i++){
158
                            if(tab.equals( ((JPanel)this.getTab().getComponentAt(i)).getName() )){
159
                                    shadePanel.put(tab, this.getTab().getComponentAt(i));
160
                                    this.getTab().removeTabAt(i);
161
                            }
162
                    }
163
            }else
164
                    this.addTab(tab, ((JPanel)shadePanel.get(tab)) );
165
    }
166
    
167
    /**
168
     * Selecciona el panel indicado por index
169
     * @param index        panel seleccionado
170
     */
171
    public void setSelectedIndex(int index) {
172
        tabbedPane.setSelectedIndex(index);
173
    }
174

    
175
    /**
176
     * Obtiene un panel a trav?s del nombre de su clase
177
     * @param name Nombre de la clase del panel
178
     */
179
    public JPanel getPanelByClassName(String name){
180
            for(int i=0;i<super.getTab().getTabCount() ;i++){
181
                    JPanel p = (JPanel)super.getTab().getComponentAt(i);
182
                    if(p.getClass().getName().endsWith(name))
183
                            return p;
184
            }
185
            return null;
186
    }
187

    
188
    /**
189
     * Asigna valores para los rangos.
190
     * @param ranges
191
     */
192
    public void setRanges(ArrayList ranges) {      
193
      if(ranges != null){              
194
              TransparencyByPixelPanel panel = (TransparencyByPixelPanel)pTrans.getPTranspByPixel();
195
              pTrans.getTransparencyCheck().setSelected(true);
196
              panel.setControlEnabled(true);
197
              panel.setEntries(ranges);
198
              for(int i=0;i<ranges.size();i++)
199
                      panel.getListModel().addElement( ((TransparencyRange)ranges.get(i)).getStrEntry() );
200
      }
201
    }
202

    
203
    /**
204
     * A?ade las bandas de los georrasterfile a los paneles 
205
     * que lo necesitan
206
     * @param files
207
     */
208
    public void addFiles(GeoRasterFile[] files){
209
            for(int i=0;i<this.getTab().getTabCount();i++){
210
                    if(this.getTab().getComponentAt(i) instanceof IRasterOperationsRegistrablePanels)
211
                             ((IRasterOperationsRegistrablePanels)getTab().getComponentAt(i)).addFiles(files);
212
            }
213
                    
214
        if(pSetup != null)
215
                pSetup.addFiles(files);
216
        if(pInfo != null)
217
            pInfo.addFiles(files);
218
        
219
                
220
 
221
    }
222
    
223
    public void addInfoFiles(GeoRasterFile[] files){
224
            if(pInfo != null){
225
                    pInfo.setBands(pSetup.getAssignedBand(GeoRasterFile.RED_BAND), pSetup.getAssignedBand(GeoRasterFile.GREEN_BAND), pSetup.getAssignedBand(GeoRasterFile.BLUE_BAND));
226
                    pInfo.addFiles(files);
227
            }
228
                    
229
             
230
    }
231
    
232
    /**
233
     * Elimina las bandas de los georrasterfile a los paneles
234
     * @param file Banda a eliminar
235
     */
236
    public void removeFile(String file) {
237
            for(int i=0;i<this.getTab().getTabCount();i++){
238
                    if(this.getTab().getComponentAt(i) instanceof IRasterOperationsRegistrablePanels)
239
                             ((IRasterOperationsRegistrablePanels)(getTab().getComponentAt(i))).removeFile(file);
240
            }
241
        if(pSetup != null)
242
                pSetup.removeFile(file);
243
    }
244
    
245
    public void focusGained(FocusEvent e) {
246
        //pTrans.updateTextBox();
247
    }
248

    
249
    public void focusLost(FocusEvent e) {
250
        //checkOpacityText();
251
    }
252

    
253
    public void mouseExited(MouseEvent e) {
254
    }
255

    
256
    public void mouseReleased(MouseEvent e) {
257
    }
258

    
259
    public void mouseEntered(MouseEvent e) {
260
    }
261

    
262
    public void mouseClicked(MouseEvent e) {
263
    }
264

    
265
    public void mousePressed(MouseEvent e) {
266
    }
267

    
268
    public void keyTyped(KeyEvent e) {
269
    }
270

    
271
    public void keyPressed(KeyEvent e) {
272
    }
273

    
274
    public void keyReleased(KeyEvent e) {
275
    }
276

    
277
    public void stateChanged(ChangeEvent e) {
278
             contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX + this.difWidth,
279
                 sizePanelY + this.difHeight));
280
             this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX + this.difWidth,
281
                 sizePanelY + difHeight - 5));
282
             this.pButton.setPreferredSize(new java.awt.Dimension(sizePanelX + this.difWidth, 25));
283

    
284
    }
285
    
286
    public void componentResized(ComponentEvent e){
287
            super.componentResized(e);
288
            contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX,
289
                sizePanelY));
290
                    this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX,
291
                sizePanelY));
292
                    this.pButton.setPreferredSize(new java.awt.Dimension(sizePanelX , 25));
293
     
294
            for(int i=0;i<super.getTab().getTabCount() ;i++){
295
                        JPanel p = (JPanel)super.getTab().getComponentAt(i);
296
                        
297
                        if(p instanceof IResize){
298
                                ((IResize)p).setComponentSize(this.getWidth() - 20, this.getHeight() - 108);        
299
                        }        
300
            }
301
    }
302

    
303
    /**
304
     * Obtiene la lista de GeoRasterFile asociada al dialogo
305
     * @return Array de GeoRasterFile
306
     */
307
        public GeoRasterFile[] getGrf() {
308
                return grf;
309
        }
310
}