Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / FilterRasterDialogPanel.java @ 5354

History | View | Annotate | Download (12.9 KB)

1 2809 nacho
/*
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.raster;
25
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28 5001 nacho
import java.awt.event.ComponentEvent;
29
import java.awt.event.ComponentListener;
30 2809 nacho
import java.awt.event.FocusEvent;
31
import java.awt.event.FocusListener;
32
import java.awt.event.KeyEvent;
33
import java.awt.event.KeyListener;
34
import java.awt.event.MouseEvent;
35
import java.awt.event.MouseListener;
36 4377 nacho
import java.util.ArrayList;
37 3753 nacho
import java.util.TreeMap;
38 2809 nacho
39 3753 nacho
import javax.swing.JPanel;
40 5001 nacho
import javax.swing.JTabbedPane;
41 2809 nacho
import javax.swing.event.ChangeEvent;
42
import javax.swing.event.ChangeListener;
43
44 3578 nacho
import org.cresques.io.GeoRasterFile;
45 4578 nacho
import org.cresques.io.raster.IRasterOperationsRegistrablePanels;
46 4377 nacho
import org.cresques.io.raster.TransparencyRange;
47 3578 nacho
import org.cresques.ui.DefaultTabPanel;
48 2809 nacho
49 3578 nacho
50 2809 nacho
/**
51
 * Panel que contiene todos los paneles de los tabs del cuadro de dialogo
52
 * de bandas y transparencias
53
 *
54
 * @author Nacho Brodin (brodin_ign@gva.es)
55
 */
56
public class FilterRasterDialogPanel extends DefaultTabPanel
57
    implements ActionListener, ChangeListener, MouseListener, FocusListener,
58
               KeyListener {
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 5001 nacho
    protected int sizePanelX = 460;
65 2809 nacho
66
    /**
67
     * Tama?o en Y del panel interior. El tab de dentro es proporcional
68
     */
69 5001 nacho
    protected int sizePanelY = 275;
70 2809 nacho
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 4578 nacho
81 2809 nacho
    /**
82 3578 nacho
     * Lista de georrasterfiles correspondiente a los ficheros de bandas
83
     */
84
    protected GeoRasterFile[] grf = null;
85 3753 nacho
    private TreeMap shadePanel = new TreeMap();
86 4578 nacho
87
    //Paneles que se registran dentro de esta misma clase
88
    private RasterTransparencyPanel pTrans = null;
89
    private BandSetupPanel pSetup = null;
90
    private EnhancedPanel pEnhan = null;
91
    private InfoPanel pInfo = null;
92
93
94 3578 nacho
    /**
95 2809 nacho
     * 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 5001 nacho
        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 2809 nacho
        this.props = props;
120
        initPanels();
121 5001 nacho
122 2809 nacho
    }
123
124
    /**
125
     * This method initializes this
126
     *
127
     * @return void
128
     */
129
    protected void initPanels() {
130
        this.setBounds(0, 0, 355, 230);
131
        pTrans = new RasterTransparencyPanel(this);
132
        pSetup = new BandSetupPanel();
133
        pEnhan = new EnhancedPanel(this);
134
        pInfo = new InfoPanel(this);
135 4578 nacho
136 3753 nacho
        this.addTab(pInfo.getName(), pInfo);
137
        this.addTab(pSetup.getName(), pSetup);
138
        this.addTab(pTrans.getName(), pTrans);
139 5354 maquerol
        //this.addTab(pEnhan.getName(), pEnhan);
140 4578 nacho
141 2809 nacho
        pTrans.getOpacityCheck().addActionListener(this);
142
        pTrans.getTransparencyCheck().addActionListener(this);
143
        pTrans.getOpacitySlider().addChangeListener(this);
144
        pTrans.getOpacityText().addActionListener(this);
145
        pTrans.getOpacityText().addFocusListener(this);
146
        pTrans.addFocusListener(this);
147
        this.getTab().addFocusListener(this);
148
149
        pEnhan.getTailCheck().addActionListener(this);
150
        pEnhan.getTailSlider().addChangeListener(this);
151
        pEnhan.getSinRealceRadioButton().addMouseListener(this);
152
        pEnhan.getLinealDirectoRadioButton().addMouseListener(this);
153
        pEnhan.getTailText().addActionListener(this);
154
        pEnhan.getTailText().addFocusListener(this);
155
156
        //Ocultamos el bot?n de aplicar
157
        //this.getApplyButton().setVisible(false);
158
    }
159
160
    /**
161 3753 nacho
     * Asigna la visibilidad de un tab a verdadero o falso. La
162
     * selecci?n del tab se hace por el identificador.
163
     * @param tab        Identificador del tab. Variable nom del mismo
164
     * @param active        True o false para visible o invisible.
165
     */
166
    public void setTabVisible(String tab, boolean active){
167
            if(active == false){
168
                    for(int i=0; i<this.getTab().getTabCount(); i++){
169
                            if(tab.equals( ((JPanel)this.getTab().getComponentAt(i)).getName() )){
170
                                    shadePanel.put(tab, this.getTab().getComponentAt(i));
171
                                    this.getTab().removeTabAt(i);
172
                            }
173
                    }
174 4231 nacho
            }else
175
                    this.addTab(tab, ((JPanel)shadePanel.get(tab)) );
176 3753 nacho
    }
177
178
    /**
179 2809 nacho
     * Selecciona el panel indicado por index
180
     * @param index        panel seleccionado
181
     */
182
    public void setSelectedIndex(int index) {
183
        tabbedPane.setSelectedIndex(index);
184
    }
185
186
    /**
187 4578 nacho
     * Obtiene un panel a trav?s del nombre de su clase
188
     * @param name Nombre de la clase del panel
189 2809 nacho
     */
190 4578 nacho
    public JPanel getPanelByClassName(String name){
191
            for(int i=0;i<super.getTab().getTabCount() ;i++){
192
                    JPanel p = (JPanel)super.getTab().getComponentAt(i);
193
                    if(p.getClass().getName().endsWith(name))
194
                            return p;
195
            }
196
            return null;
197 2809 nacho
    }
198 3578 nacho
199
    /**
200 2809 nacho
     * Eventos sobre TextField y CheckBox. Controla eventos de checkbox de opacidad, transparencia,
201
     * recorte de colas y los textfield de opacidad, valores de transparencia por banda y
202
     * porcentaje de recorte.
203
     */
204
    public void actionPerformed(ActionEvent e) {
205
        //Evento sobre el checkbox de opacidad
206
        if (e.getSource().equals(pTrans.getOpacityCheck())) {
207
            //Check de opacidad activado -> Activar controles de opacidad
208
            if (pTrans.getOpacityCheck().isSelected()) {
209
                pTrans.getOpacitySlider().setEnabled(true);
210
                pTrans.getOpacityText().setEnabled(true);
211
            } else {
212
                pTrans.getOpacitySlider().setEnabled(false);
213
                pTrans.getOpacityText().setEnabled(false);
214
            }
215
        }
216
217
        //Evento sobre el checkbox de transparencia
218
        if (e.getSource().equals(pTrans.getTransparencyCheck())) {
219
            //Check de opacidad activado -> Activar controles de opacidad
220
            if (pTrans.getTransparencyCheck().isSelected()) {
221 4377 nacho
                    pTrans.getPTranspByPixel().setControlEnabled(true);
222
                    pTrans.getPTranspByPixel().getPRGBInput().setActiveBands(nbands);
223
            }else
224
                    pTrans.getPTranspByPixel().setControlEnabled(false);
225 2809 nacho
        }
226
227
        //Evento sobre el textfield de opacidad
228
        if (e.getSource().equals(pTrans.getOpacityText())) {
229
            checkOpacityText();
230
        }
231
232
        //Evento sobre el checkbox de Recorte de colas
233
        if (e.getSource().equals(pEnhan.getTailCheck())) {
234
            if (pEnhan.getTailCheck().isSelected()) {
235
                pEnhan.setActiveTailControl(true);
236
            } else {
237
                pEnhan.setActiveTailControl(false);
238
            }
239
        }
240
241
        //Evento sobre el textfield de porcentaje de recorte
242
        if (e.getSource().equals(pEnhan.getTailText())) {
243
            checkTailText();
244
        }
245 4377 nacho
    }
246 2809 nacho
247
    /**
248 4377 nacho
     * Asigna valores para los rangos.
249
     * @param ranges
250 2809 nacho
     */
251 4377 nacho
    public void setRanges(ArrayList ranges) {
252
      if(ranges != null){
253
              TransparencyByPixelPanel panel = (TransparencyByPixelPanel)pTrans.getPTranspByPixel();
254
              pTrans.getTransparencyCheck().setSelected(true);
255
              panel.setControlEnabled(true);
256
              panel.setEntries(ranges);
257
              for(int i=0;i<ranges.size();i++)
258
                      panel.getListModel().addElement( ((TransparencyRange)ranges.get(i)).getStrEntry() );
259
      }
260 2809 nacho
    }
261
262
    /**
263 3578 nacho
     * A?ade las bandas de los georrasterfile a los paneles
264
     * que lo necesitan
265
     * @param files
266
     */
267
    public void addFiles(GeoRasterFile[] files){
268 4578 nacho
            for(int i=0;i<this.getTab().getTabCount();i++){
269
                    if(this.getTab().getComponentAt(i) instanceof IRasterOperationsRegistrablePanels)
270
                             ((IRasterOperationsRegistrablePanels)getTab().getComponentAt(i)).addFiles(files);
271
            }
272
273 3578 nacho
        if(pSetup != null)
274
                pSetup.addFiles(files);
275
    }
276
277
    /**
278
     * Elimina las bandas de los georrasterfile a los paneles
279
     * @param file Banda a eliminar
280
     */
281
    public void removeFile(String file) {
282 4578 nacho
            for(int i=0;i<this.getTab().getTabCount();i++){
283
                    if(this.getTab().getComponentAt(i) instanceof IRasterOperationsRegistrablePanels);
284
                             ((IRasterOperationsRegistrablePanels)getTab().getComponentAt(i)).removeFile(file);
285
            }
286 3578 nacho
        if(pSetup != null)
287
                pSetup.removeFile(file);
288
    }
289
290
    /**
291 2809 nacho
     * Controla que si el formato introducido en el textfield
292
     * de opacidad es numerico se actualiza la posici?n del
293
     * slider.
294
     */
295
    private void checkOpacityText() {
296
        String op = pTrans.getOpacityText().getText();
297
        int value = 0;
298
299
        try {
300
            if (!op.equals("")) {
301
                value = Integer.parseInt(op);
302
            }
303
304
            pTrans.getOpacitySlider().setValue(value);
305
        } catch (NumberFormatException exc) {
306
            System.err.println("Formato no numerico");
307
            pTrans.getOpacityText().setText("100");
308
            pTrans.getOpacitySlider().setValue(100);
309
        }
310
    }
311
312
    /**
313
     * Controla que si el formato introducido en el textfield
314
     * de Recorte de colas es numerico se actualiza la posici?n del
315
     * slider
316
     */
317
    private void checkTailText() {
318
        String op = pEnhan.getTailText().getText();
319
        double value = 0;
320
321
        try {
322
            if (!op.equals("")) {
323
                value = (Double.parseDouble(op) * 100) / 50;
324
            }
325
326
            pEnhan.getTailSlider().setValue((int) Math.round(value));
327
            pEnhan.getTailText().setText(op);
328
        } catch (NumberFormatException exc) {
329
            System.err.println("Formato no numerico");
330
            pEnhan.getTailText().setText("0.0");
331
            pEnhan.getTailSlider().setValue(0);
332
        }
333
    }
334
335
    /*
336
     *
337
     */
338
    public void stateChanged(ChangeEvent e) {
339 5001 nacho
            super.stateChanged(e);
340 2809 nacho
        //Ponemos el valor del texto de la opacidad de pendiendo de la posici?n del Slider
341
        if (e.getSource().equals(pTrans.getOpacitySlider())) {
342 4578 nacho
            pTrans.getOpacityText().setText(
343
                            String.valueOf(pTrans.getOpacitySlider().getValue()));
344 2809 nacho
        }
345
346
        if (e.getSource().equals(pEnhan.getTailSlider())) {
347 4578 nacho
            pEnhan.getTailText().setText(
348
                            String.valueOf((pEnhan.getTailSlider().getValue() >> 1)) + ".0");
349 2809 nacho
        }
350 5001 nacho
351 2809 nacho
    }
352
353
    public void focusGained(FocusEvent e) {
354
        //pTrans.updateTextBox();
355
    }
356
357
    public void focusLost(FocusEvent e) {
358
        checkOpacityText();
359
        checkTailText();
360
    }
361
362
    public void mouseExited(MouseEvent e) {
363
    }
364
365
    public void mouseReleased(MouseEvent e) {
366
    }
367
368
    public void mouseEntered(MouseEvent e) {
369
    }
370
371
    public void mouseClicked(MouseEvent e) {
372
    }
373
374
    public void mousePressed(MouseEvent e) {
375
        //Evento sobre los radio button de Realce
376
        if (e.getSource().equals(pEnhan.getSinRealceRadioButton())) {
377
            if (pEnhan.getSinRealceRadioButton().isEnabled()) {
378
                pEnhan.getTailCheck().setEnabled(false);
379
                pEnhan.setActiveTailControl(false);
380
                pEnhan.getSinRealceRadioButton().setSelected(true);
381
                pEnhan.setActiveRemoveCheck(false);
382
            }
383
        }
384
385
        if (e.getSource().equals(pEnhan.getLinealDirectoRadioButton())) {
386
            pEnhan.getTailCheck().setEnabled(true);
387
            pEnhan.setActiveRemoveCheck(true);
388
389
            if (pEnhan.getTailCheck().isSelected()) {
390
                pEnhan.setActiveTailControl(true);
391
            }
392
        }
393
    }
394
395
    public void keyTyped(KeyEvent e) {
396
    }
397
398
    public void keyPressed(KeyEvent e) {
399
    }
400
401
    public void keyReleased(KeyEvent e) {
402
    }
403 5001 nacho
404 2809 nacho
}