Revision 12154 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/properties/panels/EnhancedControl.java

View differences:

EnhancedControl.java
18 18
 */
19 19
package org.gvsig.rastertools.properties.panels;
20 20

  
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
21 23
import java.awt.event.KeyEvent;
22 24
import java.awt.event.KeyListener;
25
import java.util.ArrayList;
23 26

  
27
import javax.swing.JCheckBox;
24 28
import javax.swing.event.ChangeEvent;
25 29
import javax.swing.event.ChangeListener;
26 30

  
......
35 39
import org.gvsig.raster.grid.filter.statistics.TailTrimFilter;
36 40
import org.gvsig.raster.shared.IRasterDataset;
37 41
import org.gvsig.raster.shared.IRasterRendering;
42
import org.gvsig.rastertools.properties.dialog.RegistrableTabPanel;
38 43

  
39 44
import com.iver.cit.gvsig.fmap.layers.FLayer;
40 45
/**
......
55 60
	 * Manejador de eventos de los slider de brillo y contraste.
56 61
	 * @author Nacho Brodin (nachobrodin@gmail.com)
57 62
	 */
58
	class BrightnessContrastListener implements KeyListener, ChangeListener {
59

  
63
	class BrightnessContrastListener implements KeyListener, ChangeListener, ActionListener {
64
		JCheckBox active = null;
60 65
		/**
61 66
		 * Constructor. Registra los listener
62 67
		 * @param panel
......
66 71
			panel.addContrastChangeListener(this);
67 72
			panel.addBrightnessKeyListener(this);
68 73
			panel.addContrastKeyListener(this);
74
			active = panel.getActive();
75
			active.addActionListener(this);
69 76
		}
70 77

  
71 78
		public void keyPressed(KeyEvent e) {
......
73 80

  
74 81
		public void keyReleased(KeyEvent e) {
75 82
			if (e.getKeyCode() == 10)
76
				apply();
83
				onlyApply();
77 84
		}
78 85

  
79 86
		public void keyTyped(KeyEvent e) {
80 87
		}
81 88

  
82 89
		public void stateChanged(ChangeEvent e) {
83
			if (bcPanel.getPreview().isSelected())
84
				apply();
90
			onlyApply();
85 91
		}
92

  
93
		public void actionPerformed(ActionEvent e) {
94
			if (e.getSource() == active)
95
				onlyApply();
96
		}
86 97
	}
87 98

  
88 99
	/**
100
	 * Manejador de eventos del panel EnhancedWithTrim.
101
	 *
102
	 * @version 14/06/2007
103
	 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
104
	 */
105
	class EnhancedWithTrimListener implements ActionListener {
106
		JCheckBox active = null;
107
		/**
108
		 * Constructor. Registra los listener
109
		 * @param panel
110
		 */
111
		public EnhancedWithTrimListener(EnhancedWithTrimPanel panel) {
112
			active = panel.getActive();
113
			active.addActionListener(this);
114
		}
115

  
116
		public void actionPerformed(ActionEvent e) {
117
			if (e.getSource() == active)
118
				onlyApply();
119
		}
120
	}
121

  
122
	/**
89 123
	 * Constructor
90 124
	 * @param tp
91 125
	 */
92 126
	public EnhancedControl(EnhancedPanel tp, IRasterDataset dataset, FLayer lyr, RasterFilterList rfl) {
93 127
		this.tPanel = tp;
94 128
		this.dataset = dataset;
95
		filterList = rfl;
129
		this.filterList = rfl;
96 130
		this.lyr = lyr;
97
		bcPanel = tPanel.getBrightnessContrastPanel();
98
		ePanel = tPanel.getEnhancedWithTrimPanel();
131
		this.bcPanel = tPanel.getBrightnessContrastPanel();
132
		this.ePanel = tPanel.getEnhancedWithTrimPanel();
99 133
		new BrightnessContrastListener(bcPanel);
134
		new EnhancedWithTrimListener(ePanel);
135

  
136
		saveStatus();
137

  
100 138
		setValuesFromFilterToPanel();
101 139
	}
102 140

  
......
173 211

  
174 212
		// BRILLO Y CONTRASTE
175 213
		BrightnessContrastListManager bcManager = (BrightnessContrastListManager) manager.getManagerByClass(BrightnessContrastListManager.class);
176
		if (bcPanel.getActive().isSelected()) {
177
			if ((int) bcPanel.getBrightnessValue() != 0)
178
				bcManager.addBrightnessFilter((int) bcPanel.getBrightnessValue(), insertionModeBrightness);
179
			else
180
				filterList.remove(BrightnessFilter.class);
181 214

  
182
			if ((int) bcPanel.getContrastValue() != 0)
183
				bcManager.addContrastFilter((int) bcPanel.getContrastValue(), insertionModeContrast);
184
			else
185
				filterList.remove(ContrastFilter.class);
186
		}
215
		if (bcPanel.getActive().isSelected() && ((int) bcPanel.getBrightnessValue() != 0))
216
			bcManager.addBrightnessFilter((int) bcPanel.getBrightnessValue(), insertionModeBrightness);
217
		else
218
			filterList.remove(BrightnessFilter.class);
187 219

  
220
		if (bcPanel.getActive().isSelected() && ((int) bcPanel.getContrastValue() != 0))
221
			bcManager.addContrastFilter((int) bcPanel.getContrastValue(), insertionModeContrast);
222
		else
223
			filterList.remove(ContrastFilter.class);
224

  
188 225
		// Redibujamos
189
		lyr.getMapContext().invalidate();
226
		if (lyr != null)
227
			lyr.getMapContext().invalidate();
190 228
	}
191 229

  
192 230
	/**
......
200 238
	 * Acciones a ejecutar cuando se aplica
201 239
	 */
202 240
	public void apply() {
241
		onlyApply();
242
		saveStatus();
243
	}
244

  
245
	/**
246
	 * Acciones a ejecutar cuando se aplica
247
	 */
248
	public void onlyApply() {
203 249
		setValuesFromPanelToFilter();
204 250
	}
205 251

  
......
207 253
	 * Acciones a ejecutar cuando se cancela
208 254
	 */
209 255
	public void cancel() {
256
		restoreStatus();
210 257
	}
258

  
259
	public void saveStatus() {
260
		RegistrableTabPanel.initialProperties.put("filterStatus", filterList.getStatusCloned());
261
	}
262

  
263
	public void restoreStatus() {
264
		filterList.setStatus((ArrayList) RegistrableTabPanel.initialProperties.get("filterStatus"));
265

  
266
		if (lyr != null)
267
			lyr.getMapContext().invalidate();
268
	}
211 269
}

Also available in: Unified diff