Statistics
| Revision:

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

History | View | Annotate | Download (6.81 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.Color;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.text.NumberFormat;
26

    
27
import javax.swing.JFormattedTextField;
28
import javax.swing.JLabel;
29
import javax.swing.JPanel;
30
import javax.swing.text.DefaultFormatterFactory;
31
import javax.swing.text.NumberFormatter;
32

    
33
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
34
import org.gvsig.raster.beans.previewbase.IUserPanelInterface;
35
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
36
import org.gvsig.raster.datastruct.Histogram;
37
import org.gvsig.raster.datastruct.HistogramException;
38
import org.gvsig.raster.util.RasterToolsUtil;
39
import org.gvsig.rastertools.enhanced.graphics.InputHistogram;
40
import org.gvsig.rastertools.enhanced.graphics.OutputHistogram;
41

    
42
/**
43
 * Panel que contiene las gr?ficas para la modificaci?n del realce.
44
 * 
45
 * 19/02/2008
46
 * @author Nacho Brodin nachobrodin@gmail.com
47
 */
48
public class GraphicsPanel extends JPanel implements IUserPanelInterface {
49
        private static final long            serialVersionUID   = 1L;
50
        private InputHistogram               input              = null;
51
        private OutputHistogram              output             = null;
52
        private JPanel                       controls           = null;
53
        
54
        private JLabel                       lclipPercent       = null;
55
        private JFormattedTextField          tclipPercent       = null;
56
        private JLabel                       llevels            = null;
57
        private JFormattedTextField          tlevels            = null;
58

    
59
        private Histogram                    hist               = null;
60
        private DatasetColorInterpretation   ci                 = null;
61
        
62
        private double[]                     minList            = null;
63
        private double[]                     maxList            = null;
64

    
65
        /**
66
         * Crea una instancia del panel GraphicsPanel
67
         *
68
         */
69
        public GraphicsPanel(FLyrRasterSE lyr) {
70
                try {
71
                        hist = lyr.getDataSource().getHistogram();
72
                        ci = lyr.getDataSource().getColorInterpretation(0);
73
                        minList = lyr.getDataSource().getStatistics().getMin();
74
                        maxList = lyr.getDataSource().getStatistics().getMax();
75
                        if(minList == null)
76
                                minList = new double[]{0};
77
                        if(maxList == null)
78
                                maxList = new double[]{255};
79
                } catch (HistogramException e) {
80
                        hist = null;
81
                } catch (InterruptedException e) {
82
                        hist = null;
83
                }
84
                init();
85
        }
86
        
87
        /**
88
         * Inicializaci?n de los controles gr?ficos.
89
         */
90
        private void init() {
91
                setLayout(new GridBagLayout());
92
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, RasterToolsUtil.getText(this, "histograms"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
93
                GridBagConstraints gbc = new GridBagConstraints();
94
                gbc.insets = new Insets(4, 4, 4, 4);
95
                gbc.weightx = 1;
96
                gbc.weighty = 1;
97
                gbc.fill = GridBagConstraints.BOTH;
98
                add(getInputHistogram(), gbc);
99
                gbc.gridx = 1;
100
                add(getControls(), gbc);                
101
                gbc.gridx = 2;
102
                add(getOutputHistogram(), gbc);
103
                setClipPercentEnabled(true);
104
                setLevelsEnabled(false);
105
        }
106
        
107
        /**
108
         * Obtiene el gr?fico con el histograma de entrada
109
         * @return InputHistogram
110
         */
111
        public InputHistogram getInputHistogram() {
112
                if(input == null) {
113
                        input = new InputHistogram(hist, ci, minList, maxList);
114
                }
115
                return input;
116
        }
117
        
118
        /**
119
         * Obtiene el gr?fico con el histograma de salida
120
         * @return OutputHistogram
121
         */
122
        public OutputHistogram getOutputHistogram() {
123
                if(output == null) {
124
                        output = new OutputHistogram(hist, ci, minList, maxList);
125
                }
126
                return output;
127
        }
128
        
129
        /**
130
         * Obtiene el panel con los controles
131
         * @return JPanel
132
         */
133
        public JPanel getControls() {
134
                if(controls == null) {
135
                        controls = new JPanel();
136
                        controls.setLayout(new GridBagLayout());
137
                        
138
                        lclipPercent = new JLabel(RasterToolsUtil.getText(null, "clip"));
139
                        llevels = new JLabel(RasterToolsUtil.getText(null, "levels"));
140
                        
141
                        NumberFormat doubleDisplayFormat = NumberFormat.getNumberInstance();
142
                        doubleDisplayFormat.setMinimumFractionDigits(0);
143
                        NumberFormat doubleEditFormat = NumberFormat.getNumberInstance();
144
                      
145
                        tclipPercent = new JFormattedTextField(new DefaultFormatterFactory(
146
                                                  new NumberFormatter(doubleDisplayFormat),
147
                                                  new NumberFormatter(doubleDisplayFormat),
148
                                                  new NumberFormatter(doubleEditFormat)));
149
                        
150
                        tlevels = new JFormattedTextField(new DefaultFormatterFactory(
151
                                          new NumberFormatter(doubleDisplayFormat),
152
                                          new NumberFormatter(doubleDisplayFormat),
153
                                          new NumberFormatter(doubleEditFormat)));
154
                        
155
                        GridBagConstraints gbc = new GridBagConstraints();
156
                        gbc.weightx = 1;
157
                        gbc.insets = new Insets(0, 5, 0, 5);
158
                        gbc.fill = GridBagConstraints.BOTH;
159
                        controls.add(lclipPercent, gbc);
160
                        gbc.gridy = 1;
161
                        controls.add(tclipPercent, gbc);                
162
                        gbc.gridy = 2;
163
                        controls.add(llevels, gbc);
164
                        gbc.gridy = 3;
165
                        controls.add(tlevels, gbc);
166
                }
167
                return controls;
168
        }
169
        
170
        /**
171
         * Activa o desactiva el control de porcentaje de recorte.
172
         * @param enabled
173
         */
174
        public void setClipPercentEnabled(boolean enabled) {
175
                tclipPercent.setEnabled(enabled);
176
                if(enabled)
177
                        tclipPercent.setBackground(Color.WHITE);
178
                else
179
                        tclipPercent.setBackground(getControls().getBackground());
180
        }
181
        
182
        /**
183
         * Activa o desactiva el control de niveles de posterizaci?n en level-slice
184
         * de recorte.
185
         * @param enabled
186
         */
187
        public void setLevelsEnabled(boolean enabled) {
188
                tlevels.setEnabled(enabled);
189
                if(enabled)
190
                        tlevels.setBackground(Color.WHITE);
191
                else
192
                        tlevels.setBackground(getControls().getBackground());
193
        }
194
        
195
        /*
196
         * (non-Javadoc)
197
         * @see org.gvsig.raster.beans.previewbase.IUserPanelInterface#getPanel()
198
         */
199
        public JPanel getPanel() {
200
                return this;
201
        }
202

    
203
        /*
204
         * (non-Javadoc)
205
         * @see org.gvsig.raster.beans.previewbase.IUserPanelInterface#getTitle()
206
         */
207
        public String getTitle() {
208
                return "";
209
        }
210

    
211
        /**
212
         * Asigna el listener para gestionar el evento de movimiento de gr?ficos
213
         * @param listener
214
         */
215
        public void setListener(EnhancedListener listener) {
216
                getInputHistogram().setListener(listener);
217
        }
218

    
219
}