Revision 5497 trunk/extensions/extRasterTools/src/org/gvsig/rasterTools/brightnessContrast/ui/EnhancedBrightnessContrastPanel.java

View differences:

EnhancedBrightnessContrastPanel.java
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

  
1 20
package org.gvsig.rasterTools.brightnessContrast.ui;
2 21

  
3 22
import java.awt.GridBagConstraints;
......
28 47

  
29 48

  
30 49
/**
31
 * 
50
 * Panel para los controles de brillo, contrase y realce.
32 51
 * @author Miguel Angel Querol Carratal? <querol_mig@gva.es>
33 52
 *
34 53
 */
......
55 74
	
56 75
	private BrightnessContrastStackManager bcManager = null;
57 76
	private JCheckBox jCheckBox1 = null;
58
	private JLabel jLabel1 = null;
77
	private JLabel lpreview = null;
59 78
	public FLyrRaster layer = null;
60 79
	public PropertiesRasterDialog propertiesRasterDialog = null;
61 80
	public RasterFilterStackManager rasterStackManager = null;
......
78 97
	 */
79 98
	private void initialize() {
80 99
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
81
		gridBagConstraints3.insets = new java.awt.Insets(8,4,8,8);
100
		gridBagConstraints3.insets = new java.awt.Insets(0,4,0,4);
82 101
		gridBagConstraints3.gridy = 0;
83 102
		gridBagConstraints3.gridx = 1;
84 103
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
85
		gridBagConstraints2.insets = new java.awt.Insets(8,8,8,4);
104
		gridBagConstraints2.insets = new java.awt.Insets(0,4,0,4);
86 105
		gridBagConstraints2.gridy = 0;
87 106
		gridBagConstraints2.gridx = 0;
88 107
		this.setLayout(new GridBagLayout());
......
96 115
		this.getLabelSliderText().getJSlider().addMouseListener(this);
97 116
		this.getLabelSliderText1().getJSlider().addMouseListener(this);
98 117
		this.setTranslation();
118
		this.getLabelSliderText().getJTextField().addActionListener(this);
119
		this.getLabelSliderText1().getJTextField().addActionListener(this);
99 120
	}
100 121

  
101 122
	public void setTranslation(){
102 123
		this.lLineal.setText(PluginServices.getText(this, "lineal_directo"));
103 124
		this.lRemove.setText(PluginServices.getText(this, "eliminar_extremos"));
104 125
		this.cstEnhanced.setName(PluginServices.getText(this, "recorte_colas")+" ( % )");
105
		this.lBrightC.setText(PluginServices.getText(this, "brillo_y_contraste"));
126
		this.lBrightC.setText(PluginServices.getText(this, "activar"));
106 127
		this.lstBrightness.setName(PluginServices.getText(this, "brillo"));
107 128
		this.lstContrast.setName(PluginServices.getText(this, "contraste"));
108
		this.jLabel1.setText(PluginServices.getText(this, "previsualizacion"));
129
		this.lpreview.setText(PluginServices.getText(this, "previsualizacion"));
109 130
	}
110 131
	
111 132
	
......
118 139
		if (pBrightCont == null) {
119 140
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
120 141
			gridBagConstraints4.gridx = 0;
121
			gridBagConstraints4.insets = new java.awt.Insets(8,8,8,8);
142
			gridBagConstraints4.insets = new java.awt.Insets(4,0,8,0);
122 143
			gridBagConstraints4.gridy = 1;
123 144
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
124 145
			gridBagConstraints.gridx = 0;
125
			gridBagConstraints.insets = new java.awt.Insets(8,8,4,8);
146
			gridBagConstraints.insets = new java.awt.Insets(0,8,4,8);
126 147
			gridBagConstraints.gridy = 0;
127 148
			pBrightCont = new JPanel();
128 149
			pBrightCont.setLayout(new GridBagLayout());
129 150
			pBrightCont.setPreferredSize(new java.awt.Dimension(210,223));
130
			pBrightCont.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
151
			pBrightCont.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1), (PluginServices.getText(this, "brillo_y_contraste")), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));
131 152
			pBrightCont.add(getPBCCheck(), gridBagConstraints);
132 153
			pBrightCont.add(getPBCSlider(), gridBagConstraints4);
133 154
		}
......
143 164
		if (pEnhanced == null) {
144 165
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
145 166
			gridBagConstraints12.gridx = 0;
146
			gridBagConstraints12.insets = new java.awt.Insets(8,8,76,8);
167
			gridBagConstraints12.insets = new java.awt.Insets(4,4,59,4);
147 168
			gridBagConstraints12.gridy = 1;
148 169
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
149 170
			gridBagConstraints11.gridx = 0;
150
			gridBagConstraints11.insets = new java.awt.Insets(8,8,4,8);
171
			gridBagConstraints11.insets = new java.awt.Insets(0,8,4,8);
151 172
			gridBagConstraints11.gridy = 0;
152 173
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
153 174
			gridBagConstraints1.gridx = 0;
......
155 176
			pEnhanced = new JPanel();
156 177
			pEnhanced.setLayout(new GridBagLayout());
157 178
			pEnhanced.setPreferredSize(new java.awt.Dimension(210,223));
158
			pEnhanced.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
179
			pEnhanced.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1), (PluginServices.getText(this, "realce")), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));
159 180
			pEnhanced.add(getPEnCheck(), gridBagConstraints11);
160 181
			pEnhanced.add(getPEnSlider(), gridBagConstraints12);
161 182
		}
162 183
		return pEnhanced;
163 184
	}
164 185

  
186
	/**
187
	 * inicializa el conponente LabelSliderText
188
	 */
165 189
	public LabelSliderText getLabelSliderText(){
166 190
		if(lstBrightness == null){
167 191
			lstBrightness = new LabelSliderText();
......
172 196
		return lstBrightness;
173 197
	}
174 198

  
199
	/**
200
	 * inicializa el conponente LabelSliderText
201
	 */
175 202
	public LabelSliderText getLabelSliderText1(){
176 203
		if (lstContrast == null){
177 204
			lstContrast = new LabelSliderText();
178 205
			lstContrast.setName("Contraste");
206
			lstContrast.setPreferredSize(new java.awt.Dimension(180,45));
179 207
			lstContrast.setSliderRange(-255,255);
180 208
			lstContrast.setSliderValue(0);
181 209
		}
......
193 221
			gridBagConstraints9.gridx = 1;
194 222
			gridBagConstraints9.gridy = 0;
195 223
			lBrightC = new JLabel();
196
			lBrightC.setText("Brillo y Contraste");
224
			lBrightC.setText("Activar");
197 225
			lBrightC.setPreferredSize(new java.awt.Dimension(160,15));
198 226
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
199 227
			gridBagConstraints8.gridx = 0;
200 228
			gridBagConstraints8.gridy = 0;
201 229
			pBCCheck = new JPanel();
202 230
			pBCCheck.setLayout(new GridBagLayout());
203
			pBCCheck.setPreferredSize(new java.awt.Dimension(192,25));
231
			pBCCheck.setPreferredSize(new java.awt.Dimension(182,25));
204 232
			pBCCheck.add(getCBrightC(), gridBagConstraints8);
205 233
			pBCCheck.add(lBrightC, gridBagConstraints9);
206 234
		}
......
224 252
			gridBagConstraints6.gridy = 2;
225 253
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
226 254
			gridBagConstraints5.gridx = 0;
227
			gridBagConstraints5.insets = new java.awt.Insets(2,0,2,0);
255
			gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0);
228 256
			gridBagConstraints5.gridy = 1;
229 257
			pBCSlider = new JPanel();
230 258
			pBCSlider.setLayout(new GridBagLayout());
231
			pBCSlider.setPreferredSize(new java.awt.Dimension(192,168));
259
			pBCSlider.setPreferredSize(new java.awt.Dimension(188,150));
232 260
			pBCSlider.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
233 261
			pBCSlider.add(getLabelSliderText(), gridBagConstraints7);
234 262
			pBCSlider.add(getLabelSliderText1(), gridBagConstraints5);
......
248 276
			GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
249 277
			gridBagConstraints19.gridx = 1;
250 278
			gridBagConstraints19.gridy = 0;
251
			jLabel1 = new JLabel();
252
			jLabel1.setText("Previsualizacion");
253
			jLabel1.setPreferredSize(new java.awt.Dimension(150,15));
254
			jLabel1.setSize(new java.awt.Dimension(160,15));
279
			lpreview = new JLabel();
280
			lpreview.setText("Previsualizacion");
281
			lpreview.setPreferredSize(new java.awt.Dimension(150,15));
282
			lpreview.setSize(new java.awt.Dimension(160,15));
255 283
			GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
256 284
			gridBagConstraints10.gridx = 0;
257 285
			gridBagConstraints10.insets = new java.awt.Insets(0,0,0,0);
......
260 288
			jPanel1.setLayout(new GridBagLayout());
261 289
			jPanel1.setPreferredSize(new java.awt.Dimension(180,25));
262 290
			jPanel1.add(getJCheckBox1(), gridBagConstraints10);
263
			jPanel1.add(jLabel1, gridBagConstraints19);
291
			jPanel1.add(lpreview, gridBagConstraints19);
264 292
		}
265 293
		return jPanel1;
266 294
	}
......
297 325
			lLineal.setPreferredSize(new java.awt.Dimension(160,15));
298 326
			pEnCheck = new JPanel();
299 327
			pEnCheck.setLayout(new GridBagLayout());
300
			pEnCheck.setPreferredSize(new java.awt.Dimension(190,25));
328
			pEnCheck.setPreferredSize(new java.awt.Dimension(182,25));
301 329
			pEnCheck.add(getCEnhanced(), gridBagConstraints13);
302 330
			pEnCheck.add(lLineal, gridBagConstraints14);
303 331
		}
......
321 349
			gridBagConstraints15.gridx = 0;
322 350
			pEnSlider = new JPanel();
323 351
			pEnSlider.setLayout(new GridBagLayout());
324
			pEnSlider.setPreferredSize(new java.awt.Dimension(190,100));
352
			pEnSlider.setPreferredSize(new java.awt.Dimension(188,100));
325 353
			pEnSlider.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
326 354
			pEnSlider.add(getPDelInt(), gridBagConstraints15);
327 355
			pEnSlider.add(getCheckSliderText(), gridBagConstraints18);
......
380 408
		return jCheckBox;
381 409
	}
382 410
	
411
	/**
412
	 * inicializa el conponente CheckSliderText
413
	 */
383 414
	public CheckSliderText getCheckSliderText(){
384 415
		String rcName = "Recorte de colas"; 
385 416
		if (cstEnhanced == null){
......
387 418
			cstEnhanced.setName(rcName);
388 419
			cstEnhanced.setSliderValue(0);
389 420
			cstEnhanced.setSliderRange(0,50);
421
			cstEnhanced.setDecimal(true);
390 422
			cstEnhanced.setTextValue("0.0");
391 423
			
392 424
		}
393 425
		return cstEnhanced;
394 426
	}
395 427

  
428
	/**
429
	 * Habilita o dehabilita el panel de brillo y contraste
430
	 * @param active
431
	 */
396 432
	public void setBCControlEnabled(boolean active){
397 433
		this.lstBrightness.setControlEnabled(active);
398 434
		this.lstContrast.setControlEnabled(active);
399 435
		this.getJCheckBox1().setEnabled(active);
400
		this.jLabel1.setEnabled(active);
401
		this.lBrightC.setEnabled(active);
436
		this.lpreview.setEnabled(active);
402 437
	}
403 438
	
439
	/**
440
	 * Habilita o dehabilita el panel de realce
441
	 * @param active
442
	 */
404 443
	public void setEControlEnabled(boolean active){
405 444
		this.jCheckBox.setEnabled(active);
406 445
		this.lRemove.setEnabled(active);
407
		this.cstEnhanced.setControlEnabled(active);
408
		this.lLineal.setEnabled(active);		
446
		this.cstEnhanced.setControlEnabled(active);		
409 447
	}
410 448
	
411 449
	
......
416 454
		if(e.getSource() == cEnhanced){
417 455
			this.setEControlEnabled(this.getCEnhanced().isSelected());
418 456
		}
457
		if((e.getSource() == this.getLabelSliderText().getJTextField()) ||
458
			(e.getSource() == this.getLabelSliderText1().getJTextField())){
459
			
460
			if(this.getJCheckBox1().isSelected()){		
461
				this.layer = propertiesRasterDialog.getFLyrRaster();
462
				this.rasterStackManager = propertiesRasterDialog.getStackManager();
463
				processBrightnessContrastPanel(this.rasterStackManager, this.propertiesRasterDialog, this.layer);
464
			}
465
	
466
		}
419 467
	} 
420 468
	
469
	/**
470
	 * Asigna a este panel un stack manager
471
	 * @param p
472
	 */
421 473
	public void setBrightnessContrastStackManager (BrightnessContrastStackManager p){
422 474
		this.bcManager = p;
423 475
	}
424 476
	
477
	/**
478
	 * A?ade los filtros de frillo y contraste a la pila de filtros con los valores
479
	 * introducidos en el panel. 
480
	 * @param stackManager
481
	 * @param propsDialog
482
	 * @param layer
483
	 */
425 484
	private void processBrightnessContrastPanel(RasterFilterStackManager stackManager, PropertiesRasterDialog propsDialog, FLyrRaster layer){
426 485
		EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("EnhancedBrightnessContrastPanel");
427 486
		// Si est? activo el panel de brillo y contraste tomamos los valores y cargamos un filtro de 
......
430 489
		if(ebcPanel.getCBrightC().isSelected()){
431 490
			int incrBrillo = (int)Math.round(Double.valueOf(ebcPanel.lstBrightness.getTextValue()).doubleValue());
432 491
			int incrContraste = (int)Math.round(Double.valueOf(ebcPanel.lstContrast.getTextValue()).doubleValue());
433
			bcManager.addHistogramFilter();
434 492
			bcManager.addBrightnessFilter(incrBrillo);
435 493
			bcManager.addContrastFilter(incrContraste);
436 494
		}else{
437
			stackManager.removeFilter(bcManager.histogram);
438 495
			stackManager.removeFilter(bcManager.brightness);
439 496
			stackManager.removeFilter(bcManager.contrast);
440 497
		}	
......
456 513
		
457 514
		//Filtro de realce lineal seleccionado
458 515
		if(ebcPanel.getCEnhanced().isSelected()){
459
			if((ebcPanel.getJCheckBox().isSelected()) && (!ebcPanel.getCheckSliderText().isSelected()))
516
			if((ebcPanel.getJCheckBox().isSelected()) && (!ebcPanel.getCheckSliderText().getJCheckBox().isSelected()))
460 517
				stackManager.addEnhancedFilter(true, fLayer.getSource().getFiles()[0].getName());
461 518
			else
462 519
				stackManager.addEnhancedFilter(false, fLayer.getSource().getFiles()[0].getName());
463 520
				
464 521
			//Recorte de colas seleccionado
465
			if(ebcPanel.getCheckSliderText().isSelected()){
522
			if(ebcPanel.getCheckSliderText().getJCheckBox().isSelected()){
466 523
				stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
467 524
				double recorte = Double.parseDouble(ebcPanel.getCheckSliderText().getTextValue())/100;
468 525
				if(ebcPanel.getJCheckBox().isSelected())
......
554 611
		
555 612
	}
556 613

  
614
	/**
615
	 * Listener que actua cuando el check "previsualizar" est? activado
616
	 * y aplica los filtros con los valores seleccionados cuando soltamos
617
	 * el bot?n del rat?n al seleccionar valor en el slider.
618
	 */
557 619
	public void mouseReleased(MouseEvent e) {
558 620
		if (((e.getSource() == this.lstBrightness.getJSlider()) || 
559 621
				(e.getSource() == this.lstContrast.getJSlider())) &&
......
569 631
		if(e.getSource() == this.getCheckSliderText().getJTextField()){
570 632
			this.getCheckSliderText().getJSlider().setValue((int) Math.round(Double.valueOf(this.getCheckSliderText().getTextValue()).doubleValue()));
571 633
		}
572
		
573 634
	}
574

  
635
	
575 636
	public void keyReleased(KeyEvent e) {
576 637
		// TODO Auto-generated method stub
577 638
		
578 639
	}
579 640

  
580 641
	public void keyTyped(KeyEvent e) {
581
		// TODO Auto-generated method stub
582 642
		
583 643
	}
644
}
584 645

  
585
}

Also available in: Unified diff