Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / enhanced / ui / SelectorsPanel.java @ 20999

History | View | Annotate | Download (8.32 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.rastertools.enhanced.ui;
20

    
21
import java.awt.GridBagConstraints;
22
import java.awt.GridBagLayout;
23
import java.awt.Insets;
24
import java.awt.event.ActionListener;
25
import java.util.ArrayList;
26

    
27
import javax.swing.BorderFactory;
28
import javax.swing.JLabel;
29
import javax.swing.JPanel;
30
import javax.swing.border.TitledBorder;
31

    
32
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
33
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
34
import org.gvsig.raster.util.RasterToolsUtil;
35
import org.gvsig.rastertools.enhanced.graphics.HistogramGraphicBase;
36

    
37
import com.iver.utiles.swing.JComboBox;
38
/**
39
 * Panel con las selecci?n de opciones.
40
 * 
41
 * 20/02/2008
42
 * @author Nacho Brodin nachobrodin@gmail.com
43
 */
44
public class SelectorsPanel extends JPanel {
45
        private static final long serialVersionUID = 3453973982901626644L;
46
        private JComboBox            enhancedType  = null;
47
        private JComboBox            histogramType = null;
48
        private JComboBox            drawType      = null;
49
        private JComboBox            band          = null;
50
        private HistogramGraphicBase graphicBase   = null;
51
        // private JComboBox sourcesMatchingPanel = null;
52

    
53
        /**
54
         * Crea una instancia del panel GraphicsPanel
55
         * @param lyr
56
         * @param list
57
         * @param graphicBase Grafica donde estan los histogramas, para saber como
58
         *          rellenar el combo de colores
59
         */
60
        public SelectorsPanel(FLyrRasterSE lyr, ArrayList list, HistogramGraphicBase graphicBase) {
61
                this.graphicBase = graphicBase;
62
                init(lyr, list);
63
        }
64
        
65
        /**
66
         * Inicializaci?n de los controles gr?ficos.
67
         */
68
        private void init(FLyrRasterSE lyr, ArrayList list) {
69
                GridBagConstraints gridBagConstraints = null;
70

    
71
                setBorder(BorderFactory.createTitledBorder(null, null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
72

    
73
                setLayout(new GridBagLayout());
74
                
75
                gridBagConstraints = new GridBagConstraints();
76
                gridBagConstraints.gridx = 0;
77
                gridBagConstraints.gridy = 0;
78
                gridBagConstraints.anchor = GridBagConstraints.EAST;
79
                gridBagConstraints.weightx = 1.0;
80
                gridBagConstraints.insets = new Insets(5, 5, 2, 2);
81
                add(new JLabel(RasterToolsUtil.getText(this, "operation")), gridBagConstraints);
82

    
83
                gridBagConstraints = new GridBagConstraints();
84
                gridBagConstraints.gridx = 1;
85
                gridBagConstraints.gridy = 0;
86
                gridBagConstraints.insets = new Insets(5, 2, 2, 2);
87
                gridBagConstraints.anchor = GridBagConstraints.WEST;
88
                add(getEnhancedType(), gridBagConstraints);
89
                
90
                gridBagConstraints = new GridBagConstraints();
91
                gridBagConstraints.gridx = 0;
92
                gridBagConstraints.gridy = 1;
93
                gridBagConstraints.anchor = GridBagConstraints.EAST;
94
                gridBagConstraints.weightx = 1.0;
95
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
96
                add(new JLabel(RasterToolsUtil.getText(this, "band")), gridBagConstraints);
97

    
98
                gridBagConstraints = new GridBagConstraints();
99
                gridBagConstraints.gridx = 1;
100
                gridBagConstraints.gridy = 1;
101
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
102
                gridBagConstraints.anchor = GridBagConstraints.WEST;
103
                add(getBand(lyr), gridBagConstraints);
104
                
105
                gridBagConstraints = new GridBagConstraints();
106
                gridBagConstraints.gridx = 2;
107
                gridBagConstraints.gridy = 0;
108
                gridBagConstraints.anchor = GridBagConstraints.EAST;
109
                gridBagConstraints.weightx = 1.0;
110
                gridBagConstraints.insets = new Insets(5, 2, 2, 2);
111
                add(new JLabel(RasterToolsUtil.getText(this, "drawing_type")), gridBagConstraints);
112

    
113
                gridBagConstraints = new GridBagConstraints();
114
                gridBagConstraints.gridx = 3;
115
                gridBagConstraints.gridy = 0;
116
                gridBagConstraints.insets = new Insets(5, 2, 2, 5);
117
                gridBagConstraints.anchor = GridBagConstraints.WEST;
118
                add(getDrawType(), gridBagConstraints);
119
                
120
                gridBagConstraints = new GridBagConstraints();
121
                gridBagConstraints.gridx = 2;
122
                gridBagConstraints.gridy = 1;
123
                gridBagConstraints.anchor = GridBagConstraints.EAST;
124
                gridBagConstraints.weightx = 1.0;
125
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
126
                add(new JLabel(RasterToolsUtil.getText(this, "histogram_type")), gridBagConstraints);
127

    
128
                gridBagConstraints = new GridBagConstraints();
129
                gridBagConstraints.gridx = 3;
130
                gridBagConstraints.gridy = 1;
131
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
132
                gridBagConstraints.anchor = GridBagConstraints.WEST;
133
                add(getHistogramType(), gridBagConstraints);
134
                
135
//                gridBagConstraints = new GridBagConstraints();
136
//                gridBagConstraints.gridx = 0;
137
//                gridBagConstraints.gridy = 2;
138
//                gridBagConstraints.gridwidth = 4;
139
//                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
140
//                gridBagConstraints.anchor = GridBagConstraints.NORTH;
141
//                gridBagConstraints.weighty = 1.0;
142
//                gridBagConstraints.insets = new Insets(2, 5, 5, 5);
143
//                add(getSourcesMatchingPanel(list), gridBagConstraints);
144
        }
145
        
146
//        /**
147
//         * Obtiene la lista con las capas cargadas en el TOC para la selecci?n de la 
148
//         * que necesitemos en la funcionalidad de histogram matching
149
//         * @return JPanel
150
//         */
151
//        private JComboBox getSourcesMatchingPanel(ArrayList list) {
152
//                if (sourcesMatchingPanel == null) {
153
//                        sourcesMatchingPanel = new JComboBox();
154
//                        for (int i = 0; i < list.size(); i++)
155
//                                sourcesMatchingPanel.addItem(((FLyrRasterSE) list.get(i)).getName());
156
//                }
157
//                return sourcesMatchingPanel;
158
//        }
159
        
160
        /**
161
         * Obtiene el tipo de histograma
162
         * @return JComboBox
163
         */
164
        public JComboBox getHistogramType() {
165
                if (histogramType == null) {
166
                        histogramType = new JComboBox();
167
                        histogramType.addItem("Standard");
168
                        histogramType.addItem("Cumulative");
169
                        histogramType.addItem("Logarithmic");
170
                        histogramType.addItem("Cumulative Logarithmic");
171
                }
172
                return histogramType;
173
        }
174
        
175
        /**
176
         * Obtiene el tipo de dibujado de histograma (lineas, barras, ...)
177
         * @return JComboBox
178
         */
179
        public JComboBox getDrawType() {
180
                if (drawType == null) {
181
                        drawType = new JComboBox();
182
                        drawType.addItem("Line");
183
                        drawType.addItem("Fill");
184
                }
185
                return drawType;
186
        }
187
        
188
        /**
189
         * Obtiene la banda que representa el histograma
190
         * @return JComboBox
191
         */
192
        public JComboBox getBand(FLyrRasterSE lyr) {
193
                if (band == null) {
194
                        band = new JComboBox();
195
                        if (lyr.getBandCount() == 1)
196
                                band.addItem(DatasetColorInterpretation.GRAY_BAND);
197
                        else {
198
                                if (graphicBase.getHistogramStatus(HistogramGraphicBase.RED) != null)
199
                                        band.addItem(DatasetColorInterpretation.RED_BAND);
200
                                if (graphicBase.getHistogramStatus(HistogramGraphicBase.GREEN) != null)
201
                                        band.addItem(DatasetColorInterpretation.GREEN_BAND);
202
                                if (graphicBase.getHistogramStatus(HistogramGraphicBase.BLUE) != null)
203
                                        band.addItem(DatasetColorInterpretation.BLUE_BAND);
204
                        }
205
                }
206
                return band;
207
        }
208

    
209
        /**
210
         * Obtiene el tipo de funci?n a aplicar (ecualizaci?n, realce lineal, ...)
211
         * @return JComboBox
212
         */
213
        public JComboBox getEnhancedType() {
214
                if (enhancedType == null) {
215
                        enhancedType = new JComboBox();
216
                        enhancedType.addItem("Lineal");
217
                        enhancedType.addItem("Square-root");
218
                        enhancedType.addItem("Logaritmic");
219
                        enhancedType.addItem("Exponential");
220
                        enhancedType.addItem("Level-slice");
221
//                        enhancedType.addItem("Gaussian");
222
//                        enhancedType.addItem("Equalization");
223
                }
224
                return enhancedType;
225
        }
226

    
227
        /**
228
         * Selecciona un item del combo EnhancedType sin lanzar un evento
229
         * @param type
230
         */
231
        public void setSelectedEnhancedType(String type) {
232
                if (getEnhancedType().getSelectedItem() != type) {
233
                        ActionListener[] copyActionListeners = getEnhancedType().getActionListeners();
234
                        for (int i = 0; i < copyActionListeners.length; i++)
235
                                getEnhancedType().removeActionListener(copyActionListeners[i]);
236
        
237
                        getEnhancedType().setSelectedItem(type);
238

    
239
                        for (int i = 0; i < copyActionListeners.length; i++)
240
                                getEnhancedType().addActionListener(copyActionListeners[i]);
241
                }
242
        }
243
}