Revision 166

View differences:

org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/tool/enhanced/EnhancedTocMenuEntry.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.app.extension.tool.enhanced;
23

  
24
import javax.swing.Icon;
25

  
26
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
27
import org.gvsig.app.project.documents.view.toc.ITocItem;
28
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
29
import org.gvsig.fmap.mapcontext.layers.FLayer;
30
import org.gvsig.raster.app.extension.raster.gui.IGenericToolBarMenuItem;
31
import org.gvsig.raster.app.extension.raster.process.HistogramProcess;
32
import org.gvsig.raster.app.extension.raster.process.IProcessActions;
33
import org.gvsig.raster.app.extension.raster.process.StatisticsProcess;
34
import org.gvsig.raster.app.extension.tool.enhanced.ui.EnhancedDialog;
35
import org.gvsig.raster.fmap.layers.FLyrRaster;
36
import org.gvsig.raster.fmap.layers.ILayerState;
37
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
38
import org.gvsig.raster.util.RasterToolsUtil;
39

  
40

  
41
/**
42
 * Punto de entrada para la funcionalidad de realce por expansi?n del contraste
43
 * 19/02/2008
44
 * @author Nacho Brodin nachobrodin@gmail.com
45
 */
46
public class EnhancedTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem, IProcessActions {
47
	static private EnhancedTocMenuEntry   singleton   = null;
48
	private FLyrRaster                  lyr         = null;
49

  
50
	/**
51
	 * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
52
	 * getSingleton()
53
	 */
54
	private EnhancedTocMenuEntry() {}
55

  
56
	/**
57
	 * Devuelve un objeto unico a dicha clase
58
	 * @return
59
	 */
60
	static public EnhancedTocMenuEntry getSingleton() {
61
		if (singleton == null)
62
			singleton = new EnhancedTocMenuEntry();
63
		return singleton;
64
	}
65
	
66
	/*
67
	 * (non-Javadoc)
68
	 * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
69
	 */
70
	public String getGroup() {
71
		return "RasterProcess";
72
	}
73

  
74
	/*
75
	 * (non-Javadoc)
76
	 * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
77
	 */
78
	public int getGroupOrder() {
79
		return 55;
80
	}
81

  
82
	/*
83
	 * (non-Javadoc)
84
	 * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
85
	 */
86
	public int getOrder() {
87
		return 0;
88
	}
89

  
90
	/*
91
	 * (non-Javadoc)
92
	 * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
93
	 */
94
	public String getText() {
95
		return RasterToolsUtil.getText(this, "enhanced_rad");
96
	}
97

  
98
	/*
99
	 * (non-Javadoc)
100
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
101
	 */
102
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
103
		if ((selectedItems == null) || (selectedItems.length != 1))
104
			return false;
105

  
106
		if (!(selectedItems[0] instanceof ILayerState))
107
			return false;
108

  
109
		if (!((ILayerState) selectedItems[0]).isOpen())
110
			return false;
111

  
112
		return true;
113
	}
114

  
115
	/*
116
	 * (non-Javadoc)
117
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
118
	 */
119
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
120
		if ((selectedItems == null) || (selectedItems.length != 1))
121
			return false;
122

  
123
		if (!(selectedItems[0] instanceof IRasterLayerActions))
124
			return false;
125
		
126
		return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.ENHANCED);
127
	}
128

  
129
	/*
130
	 * (non-Javadoc)
131
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
132
	 */
133
	public void execute(ITocItem item, FLayer[] selectedItems) {
134
		if ((selectedItems == null) || (selectedItems.length != 1) || (!(selectedItems[0] instanceof FLyrRaster)))
135
			return;
136
				
137
		this.lyr = (FLyrRaster)selectedItems[0];
138
		if(!lyr.getDataStore().getStatistics().isCalculated()) 
139
			StatisticsProcess.launcher(lyr, this);
140
		else
141
			end(null);
142
	}
143
	
144
	/*
145
	 * (non-Javadoc)
146
	 * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
147
	 */
148
	public Icon getIcon() {
149
		return RasterToolsUtil.getIcon("brush-icon");
150
	}
151

  
152
	/**
153
	 * Lanzamos la ventana al final del proceso de calculo de estad?sticas.
154
	 */
155
	public void end(Object param) {
156
		if(param == null || param instanceof FLyrRaster) {
157
			HistogramProcess histogramProcess = new HistogramProcess();
158
			histogramProcess.setActions(this);
159
			histogramProcess.addParam("histogramable", this.lyr.getDataStore());
160
			histogramProcess.start();
161
		} 
162
		if(param instanceof Histogram) {
163
			EnhancedDialog enhancedDialog = new EnhancedDialog(lyr, 760, 421);
164
			RasterToolsUtil.addWindow(enhancedDialog);
165
		}
166
	}
167

  
168
	public void interrupted() {
169
	}
170
}
0 171

  
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/tool/enhanced/ui/SelectorsPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.app.extension.tool.enhanced.ui;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionListener;
28

  
29
import javax.swing.BorderFactory;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.border.TitledBorder;
33

  
34
import org.gvsig.raster.app.extension.tool.enhanced.graphics.HistogramGraphicBase;
35
import org.gvsig.raster.fmap.layers.FLyrRaster;
36
import org.gvsig.raster.util.RasterToolsUtil;
37
import org.gvsig.utils.swing.JComboBox;
38

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

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

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

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

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

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

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

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

  
211
	/**
212
	 * Obtiene el tipo de funci?n a aplicar (ecualizaci?n, realce lineal, ...)
213
	 * @return JComboBox
214
	 */
215
	public JComboBox getEnhancedType() {
216
		if (enhancedType == null) {
217
			enhancedType = new JComboBox();
218
			enhancedType.addItem(RasterToolsUtil.getText(this, "lineal"));
219
			enhancedType.addItem(RasterToolsUtil.getText(this, "square_root"));
220
			enhancedType.addItem(RasterToolsUtil.getText(this, "logaritmic"));
221
			enhancedType.addItem(RasterToolsUtil.getText(this, "exponential"));
222
			enhancedType.addItem(RasterToolsUtil.getText(this, "level_slice"));
223
//			enhancedType.addItem(RasterToolsUtil.getText(this, "gaussian"));
224
//			enhancedType.addItem(RasterToolsUtil.getText(this, "equalization"));
225
		}
226
		return enhancedType;
227
	}
228

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

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

  
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/tool/enhanced/ui/EnhancedDialog.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.app.extension.tool.enhanced.ui;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.Dimension;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.util.ArrayList;
29

  
30
import javax.swing.JPanel;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.ui.mdiManager.IWindow;
34
import org.gvsig.andami.ui.mdiManager.WindowInfo;
35
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
36
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
37
import org.gvsig.raster.app.extension.raster.bean.createlayer.CreateLayerPanel;
38
import org.gvsig.raster.app.extension.raster.bean.previewbase.PreviewBasePanel;
39
import org.gvsig.raster.fmap.layers.FLyrRaster;
40

  
41
/**
42
 * Dialogo para el realce por expansi?n del contraste
43
 * 
44
 * 19/02/2008
45
 * @author Nacho Brodin nachobrodin@gmail.com
46
 */
47
public class EnhancedDialog extends JPanel implements IWindow {
48
	private static final long serialVersionUID = -5374834293534046986L;
49
	
50
	private PreviewBasePanel    previewBasePanel = null;
51
	private GraphicsPanel       graphicsPanel    = null;
52
	private FLyrRaster        lyr              = null;
53
	private PreviewFiltering    filteredPreview  = null;
54
	private SelectorsPanel      controlsPanel    = null;
55
	private CreateLayerPanel    layerPanel       = null;
56
	private String              viewName         = null;
57
	private EnhancedListener    listener         = null;
58
	
59
	/**
60
	 * Constructor
61
	 * @param lyr Capa raster sobre la que se opera
62
	 * @param lyrs Lista de capas cargadas en el TOC
63
	 * @param width Ancho
64
	 * @param height Alto
65
	 */
66
	public EnhancedDialog(FLyrRaster lyr, int width, int height) {
67
		this.setPreferredSize(new Dimension(width, height));
68
		this.setSize(width, height);
69
		this.setLayout(new BorderLayout(5, 5));
70
		this.lyr = lyr;
71
		
72
		graphicsPanel = new GraphicsPanel(this.lyr);
73
		filteredPreview = new PreviewFiltering();
74
		filteredPreview.setFilterStatus(this.lyr.getRender().getFilterList().getStatusCloned());
75
		controlsPanel = new SelectorsPanel(this.lyr, graphicsPanel.getInputHistogram());
76
				
77
		this.add(getPreviewBasePanel(), BorderLayout.CENTER);
78
		
79
		listener = new EnhancedListener(controlsPanel, graphicsPanel, this, filteredPreview);
80
		
81
		listener.firstLoad();
82
		
83
		graphicsPanel.setListener(listener);
84
		
85
		graphicsPanel.updateHistogram();
86
		listener.updatePreview();
87
		
88
		IWindow window = PluginServices.getMDIManager().getActiveWindow();
89
		if(window instanceof AbstractViewPanel) {
90
			AbstractViewPanel view = (AbstractViewPanel)window;
91
			viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle();
92
		}
93
		
94
		getPreviewBasePanel().getButtonsPanel().addButtonPressedListener(listener);
95
		
96
		previewBasePanel.refreshPreview();
97
	}
98

  
99
	/**
100
	 * Obtiene el panel con el histograma
101
	 * @return HistogramPanel
102
	 */
103
	public PreviewBasePanel getPreviewBasePanel() {
104
		if (previewBasePanel == null) {
105
			ArrayList<GraphicsPanel> list = new ArrayList<GraphicsPanel>();
106
			list.add(graphicsPanel);
107
			
108
			JPanel downPreview = new JPanel();
109
			getNewOrSaveLayerPanel().setLabelFilename("");
110
			downPreview.setLayout(new GridBagLayout());
111
			
112
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
113
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
114
			downPreview.add(getNewOrSaveLayerPanel().getJPanel(), gridBagConstraints);
115
			
116
			gridBagConstraints = new GridBagConstraints();
117
			gridBagConstraints.gridx = 0;
118
			gridBagConstraints.gridy = 1;
119
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
120
			gridBagConstraints.anchor = GridBagConstraints.NORTH;
121
			gridBagConstraints.weightx = 1.0;
122
			gridBagConstraints.weighty = 1.0;
123
			downPreview.add(getNewOrSaveLayerPanel().getFileNamePanel(), gridBagConstraints);
124
			
125
			previewBasePanel = new PreviewBasePanel(ButtonsPanel.BUTTONS_APPLYCLOSE, list, controlsPanel, downPreview, filteredPreview, lyr);
126
			previewBasePanel.getButtonsPanel().addCancel();
127
		}
128
		return previewBasePanel;
129
	}
130
	
131
	/**
132
	 * Devuelve un Panel para el guardado de capas en disco o en memoria.
133
	 */
134
	public CreateLayerPanel getNewOrSaveLayerPanel() {
135
		 if (layerPanel == null) {
136
			 layerPanel = new CreateLayerPanel(lyr);
137
		 }
138
		 return layerPanel;
139
	 }
140
	
141
	/**
142
	 * Acciones a ejecutar cuando se cancela
143
	 */
144
	public void close() {
145
		try {
146
			PluginServices.getMDIManager().closeWindow(this);
147
		} catch (ArrayIndexOutOfBoundsException e) {
148
			//Si la ventana no se puede eliminar no hacemos nada
149
		}
150
	}
151
	
152
	/**
153
	 * Obtiene la capa asociada.
154
	 * @return FLyrRaster
155
	 */
156
	public FLyrRaster getLayer() {
157
		return lyr;
158
	}
159

  
160
	/*
161
	 * (non-Javadoc)
162
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
163
	 */
164
	public WindowInfo getWindowInfo() {
165
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
166
		if(getPreviewBasePanel().getLayer() != null)
167
			m_viewinfo.setAdditionalInfo(getPreviewBasePanel().getLayer().getName());
168
		m_viewinfo.setTitle(PluginServices.getText(this, "enhanced"));
169
		m_viewinfo.setHeight(this.getHeight());
170
		m_viewinfo.setWidth(this.getWidth());
171
		return m_viewinfo;
172
	}
173

  
174
	/**
175
	 * @return the filteredPreview
176
	 */
177
	public PreviewFiltering getFilteredPreview() {
178
		return filteredPreview;
179
	}
180

  
181
	/**
182
	 * @return the viewName
183
	 */
184
	public String getViewName() {
185
		return viewName;
186
	}
187

  
188
	/**
189
	 * @return the graphicsPanel
190
	 */
191
	public GraphicsPanel getGraphicsPanel() {
192
		return graphicsPanel;
193
	}
194

  
195
	public Object getWindowProfile() {
196
		return WindowInfo.PROPERTIES_PROFILE;
197
	}
198
}
0 199

  
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/tool/enhanced/ui/PreviewFiltering.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.app.extension.tool.enhanced.ui;
23

  
24
import java.util.ArrayList;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.fmap.dal.coverage.RasterLocator;
28
import org.gvsig.fmap.dal.coverage.datastruct.Params;
29
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException;
30
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
31
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
33
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager;
34
import org.gvsig.gui.beans.imagenavigator.ImageUnavailableException;
35
import org.gvsig.raster.app.extension.raster.bean.previewbase.IPreviewRenderProcess;
36
import org.gvsig.raster.app.extension.raster.bean.previewbase.ParamStruct;
37
import org.gvsig.raster.fmap.layers.FLyrRaster;
38
import org.gvsig.raster.util.RasterToolsUtil;
39

  
40
/**
41
 * Procesado de la imagen para la previsualizaci?n. Para poder usar esta clase despu?s de instanciarla
42
 * habr? que asignarle un valor a showFiltersSelected aunque por defecto est? a true por lo que se
43
 * visualizaran los cambios sin problemas, asigna una lista de filtros inicial (que ya tenga el raster
44
 * aplicado) con setFilterStatus y asignar los filtros que queramos aplicar con addNewParam (una llamada
45
 * por cada filtro).
46
 * 
47
 * 19/02/2008
48
 * @author Nacho Brodin nachobrodin@gmail.com
49
 */
50
public class PreviewFiltering implements IPreviewRenderProcess {
51

  
52
	private boolean                  showFiltersSelected     = true;
53
	private ArrayList<ParamStruct>   paramsList              = new ArrayList<ParamStruct>();
54
	private ArrayList<RasterFilter>  filtersInit             = new ArrayList<RasterFilter>();
55
	private boolean                  showPreview             = true;	
56
	
57
	/**
58
	 * Flag de selecci?n de activaci?n y desactivaci?n
59
	 * @param show
60
	 */
61
	public void showFiltersSelected(boolean show) {
62
		this.showFiltersSelected = show;
63
	}
64
	
65
	/**
66
	 * Obtiene la lista de par?metros
67
	 * @return the paramsList
68
	 */
69
	public ArrayList<ParamStruct> getParamsList() {
70
		return paramsList;
71
	}
72
	
73
	/**
74
	 * Asigna la lista de par?metros
75
	 * @param params
76
	 */
77
	public void setParamsList(ArrayList<ParamStruct> params) {
78
		this.paramsList = params;
79
	}
80
	
81
	/**
82
	 * Asigna el arrayList de filtros inicial. Esto hace que aplique los filtros que ya
83
	 * existen en el raster. Estos pueden ser obtenidos del render de la capa de la forma
84
	 * lyr.getRender().getFilterList().getStatusCloned().  
85
	 * @param params Lista de filtros aplicados.
86
	 */
87
	public void setFilterStatus(ArrayList<RasterFilter> filtersInit) {
88
		this.filtersInit = filtersInit;
89
	}
90
	
91
	/**
92
	 * Devuelve el arrayList de filtros inicial
93
	 * @return
94
	 */
95
	public ArrayList<RasterFilter> getFilterStatus() {
96
		return filtersInit;
97
	}
98
	
99
	/**
100
	 * A?adir un nuevo Params a la lista de Params que podemos manejar. Un Params
101
	 * equivale a un filtro cargado. El hecho de trabajar con Params y no con
102
	 * filtros, simplifica totalmente el panel. Sin tener que depender de los
103
	 * filtros nada m?s que para el momento de dibujado o guardado.
104
	 * @param name
105
	 * @param params
106
	 * @param classFilter
107
	 */
108
	@SuppressWarnings("unchecked")
109
	public void addNewParam(String name, Params params, Class classFilter) {
110
		ParamStruct param = new ParamStruct();
111
		param.setFilterName(name);
112
		param.setFilterParam(params);
113
		param.setFilterClass(classFilter);
114
		paramsList.add(param);
115
	}
116

  
117
	/**
118
	 * Procesa la imagen con la lista de filtros si el flag showFilterSelected est? a true.
119
	 * Esta funci?n llama a addFilter por cada filtro a?adido pero es applyFilters la encargada
120
	 * de construir la lista. 
121
	 */
122
	public void process(FLyrRaster rendering) throws ImageUnavailableException {
123
		if(!showPreview)
124
			throw new ImageUnavailableException(RasterToolsUtil.getText(this, "panel_preview_not_available"));
125
		
126
		rendering.getRender().getFilterList().clear();
127

  
128
		if (showFiltersSelected) {
129
			RasterFilterList filterList = rendering.getRender().getFilterList();
130

  
131
			ArrayList<ParamStruct> listFilterUsed = applyFilters(rendering);
132
			ArrayList<Exception> exc = new ArrayList<Exception>();
133
			for (int i = 0; i < listFilterUsed.size(); i++) {
134
				try {
135
					RasterFilterListManager filterManager = filterList.getManagerByFilterClass(((ParamStruct) listFilterUsed.get(i)).getFilterClass());
136
					filterManager.addFilter(((ParamStruct) listFilterUsed.get(i)).getFilterClass(), ((ParamStruct) listFilterUsed.get(i)).getFilterParam());
137
				} catch (FilterTypeException e) {
138
					exc.add(e);
139
				} catch (FilterManagerException e) {
140
					exc.add(e);
141
				}
142
			}
143
			if(exc.size() != 0) {
144
				RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_adding_filters"), this, exc);
145
				exc.clear();
146
			}
147
		}
148
	}
149
	
150
	/**
151
	 * Aqui se seleccionan que filtros se van a aplicar y se devuelven en forma
152
	 * de ArrayList tanto para el dibujado como cuando aceptan o aplican el panel.
153
	 * @param layerRaster
154
	 * @return
155
	 */
156
	@SuppressWarnings("unchecked")
157
	public ArrayList<ParamStruct> applyFilters(FLyrRaster layerRaster) {
158
		ArrayList<ParamStruct> listFilterUsed = new ArrayList<ParamStruct>();
159

  
160
		RasterFilterList filterList = RasterLocator.getManager().createEmptyFilterList();
161
		filterList.setEnv(layerRaster.getRender().getFilterList().getEnv());
162
		ArrayList<Class> registeredFilters = filterList.getRegisteredFilterList();
163

  
164
		if(filtersInit == null)
165
			return listFilterUsed;
166
		
167
		// Conservamos filtros ya existentes
168
		for (int i = 0; i < filtersInit.size(); i++) {
169
			
170
			RasterFilter obj = null;
171
			for (int j = 0; j < registeredFilters.size(); j++) {
172
				Class classFilter = (Class) registeredFilters.get(j);
173
				try {
174
					obj = (RasterFilter) classFilter.newInstance();
175
					if (obj.getName().equals(((RasterFilter) filtersInit.get(i)).getName()))
176
						break;
177
				} catch (InstantiationException e) {
178
					RasterToolsUtil.messageBoxError("error_creando_filtro", this, e);
179
				} catch (IllegalAccessException e) {
180
					RasterToolsUtil.messageBoxError("error_creando_filtro", this, e);
181
				}
182
			}
183

  
184
			// Si no encontramos el filtro apropiado, nos olvidamos de el
185
			if (obj == null)
186
				continue;
187

  
188
			// Si no es visible tenemos que conservar el filtro
189
			try {
190
				Params params = (Params) ((RasterFilter) filtersInit.get(i)).getUIParams(((RasterFilter) filtersInit.get(i)).getName()).clone();
191
				// A?ado el parametro RenderBands a los parametros del filtro
192
				String rgb = layerRaster.getRender().getRenderBands()[0] + " " + layerRaster.getRender().getRenderBands()[1] + " " + layerRaster.getRender().getRenderBands()[2];
193
				params.setParam("RenderBands", rgb, 0, null);
194
			
195
				ParamStruct newParam = new ParamStruct();
196
				newParam.setFilterClass(obj.getClass());
197
				newParam.setFilterName(((RasterFilter) filtersInit.get(i)).getName());
198
				newParam.setFilterParam(params);
199
				listFilterUsed.add(newParam);
200
			} catch (CloneNotSupportedException e) {
201
			}
202
		}
203
		
204
		// Metemos los filtros seleccionados en listFilterUsed
205
		for (int i = 0; i < paramsList.size(); i++) {
206
			// En caso de existir el filtro, lo reemplazamos
207
			boolean finded = false;
208
			for (int j = 0; j < listFilterUsed.size(); j++) {
209
				if (((ParamStruct) listFilterUsed.get(j)).getFilterName().equals(((ParamStruct) paramsList.get(i)).getFilterName())) {
210
					listFilterUsed.set(j, paramsList.get(i));
211
					finded = true;
212
					break;
213
				}
214
			}
215
			if (!finded)
216
				listFilterUsed.add(paramsList.get(i));
217
		}
218
		
219
		return listFilterUsed;
220
	}
221
	
222
	/**
223
	 * Obtiene el flag que informa de si se est? mostrando la previsualizaci?n o no.
224
	 * En caso de no mostrarse se lanza una excepci?n ImageUnavailableExcepcion con el 
225
	 * mensaje "La previsualizaci?n no est? disponible para este panel"
226
	 * @return
227
	 */
228
	public boolean isShowPreview() {
229
		return showPreview;
230
	}
231
	
232
	/**
233
	 * Asigna el flag para mostrar u ocultar la preview. En caso de no mostrarse se lanza una 
234
	 * excepci?n ImageUnavailableExcepcion con el mensaje "La previsualizaci?n no est? disponible para
235
	 * este panel"
236
	 * @param showPreview
237
	 */
238
	public void setShowPreview(boolean showPreview) {
239
		this.showPreview = showPreview;
240
	}
241
}
0 242

  
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/tool/enhanced/ui/EnhancedHistogramController.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.app.extension.tool.enhanced.ui;
23

  
24
import org.gvsig.fmap.dal.coverage.RasterLocator;
25
import org.gvsig.fmap.dal.coverage.datastruct.Params;
26
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.function.StraightLine;
27
import org.gvsig.raster.app.extension.tool.enhanced.graphics.HistogramGraphicBase;
28
import org.gvsig.raster.app.extension.tool.enhanced.graphics.InputHistogram;
29
import org.gvsig.raster.app.extension.tool.enhanced.graphics.OutputHistogram;
30
import org.gvsig.raster.app.extension.tool.enhanced.graphics.HistogramGraphicBase.HistogramStatus;
31
/**
32
 * Manager para actualizar la vista previa y el histograma de salida del cuadro
33
 * de realce
34
 * 
35
 * @version 04/03/2008
36
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
37
 */
38
public class EnhancedHistogramController {
39
	private InputHistogram  inputHistogram  = null;
40
	private OutputHistogram outputHistogram = null;
41
	private EnhancedDialog  enhancedDialog  = null;
42

  
43
	public EnhancedHistogramController(InputHistogram inputHistogram, OutputHistogram outputHistogram, EnhancedDialog enhancedDialog) {
44
		this.inputHistogram = inputHistogram;
45
		this.outputHistogram = outputHistogram;
46
		this.enhancedDialog = enhancedDialog;
47
	}
48
	
49
	@SuppressWarnings("unchecked")
50
	public void updatePreview() {
51
		Params params = RasterLocator.getManager().createParams("", 0, 0, null);
52

  
53
//		Double min = Double.valueOf(0.0D);
54
		boolean rgb = enhancedDialog.getGraphicsPanel().getRGB().isSelected();
55
		HistogramStatus histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.GRAY);
56
		if (enhancedDialog.getLayer().getRender().isRenderingAsGray()) {
57
			if (histogram.getBaseFunction() instanceof StraightLine) {
58
				StraightLine line = (StraightLine) histogram.getBaseFunction();
59
				double[] valuesIn;
60
				if (rgb)
61
					valuesIn = line.getInValues(0, 255);
62
				else
63
					valuesIn = line.getInValues(histogram.getMin(), histogram.getMax());
64
				int[] valuesOut = line.getOutValues();
65
				params.setParam("StretchInRed", valuesIn, -1, null);
66
				params.setParam("StretchOutRed", valuesOut, -1, null);
67
				params.setParam("StretchRedFunctionType", Integer.valueOf(line.getFunctionType()), -1, null);
68
				params.setParam("StretchRedValueFunction", Double.valueOf(line.getValueFunction()), -1, null);
69
				params.setParam("StretchInGreen", valuesIn, -1, null);
70
				params.setParam("StretchOutGreen", valuesOut, -1, null);
71
				params.setParam("StretchGreenFunctionType", Integer.valueOf(line.getFunctionType()), -1, null);
72
				params.setParam("StretchGreenValueFunction", Double.valueOf(line.getValueFunction()), -1, null);
73
				params.setParam("StretchInBlue", valuesIn, -1, null);
74
				params.setParam("StretchOutBlue", valuesOut, -1, null);
75
				params.setParam("StretchBlueFunctionType", Integer.valueOf(line.getFunctionType()), -1, null);
76
				params.setParam("StretchBlueValueFunction", Double.valueOf(line.getValueFunction()), -1, null);
77
			}
78
		} else {
79
			histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.RED);
80
			if (histogram != null) {
81
				if (histogram.getBaseFunction() instanceof StraightLine) {
82
					StraightLine line = (StraightLine) histogram.getBaseFunction();
83
					double[] valuesIn;
84
					if (rgb)
85
						valuesIn = line.getInValues(0, 255);
86
					else
87
						valuesIn = line.getInValues(histogram.getMin(), histogram.getMax());
88
					int[] valuesOut = line.getOutValues();
89

  
90
					params.setParam("StretchInRed", valuesIn, -1, null);
91
					params.setParam("StretchOutRed", valuesOut, -1, null);
92
					params.setParam("StretchRedFunctionType", Integer.valueOf(line.getFunctionType()), -1, null);
93
					params.setParam("StretchRedValueFunction", Double.valueOf(line.getValueFunction()), -1, null);
94
				}
95
			}
96
			histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.GREEN);
97
			if (histogram != null) {
98
				if (histogram.getBaseFunction() instanceof StraightLine) {
99
					StraightLine line = (StraightLine) histogram.getBaseFunction();
100
					double[] valuesIn;
101
					if (rgb)
102
						valuesIn = line.getInValues(0, 255);
103
					else
104
						valuesIn = line.getInValues(histogram.getMin(), histogram.getMax());
105
					int[] valuesOut = line.getOutValues();
106

  
107
					params.setParam("StretchInGreen", valuesIn, -1, null);
108
					params.setParam("StretchOutGreen", valuesOut, -1, null);
109
					params.setParam("StretchGreenFunctionType", Integer.valueOf(line.getFunctionType()), -1, null);
110
					params.setParam("StretchGreenValueFunction", Double.valueOf(line.getValueFunction()), -1, null);
111
				}
112
			}
113
			histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.BLUE);
114
			if (histogram != null) {
115
				if (histogram.getBaseFunction() instanceof StraightLine) {
116
					StraightLine line = (StraightLine) histogram.getBaseFunction();
117
					double[] valuesIn;
118
					if (rgb)
119
						valuesIn = line.getInValues(0, 255);
120
					else
121
						valuesIn = line.getInValues(histogram.getMin(), histogram.getMax());
122
					int[] valuesOut = line.getOutValues();
123

  
124
					params.setParam("StretchInBlue", valuesIn, -1, null);
125
					params.setParam("StretchOutBlue", valuesOut, -1, null);
126
					params.setParam("StretchBlueFunctionType", Integer.valueOf(line.getFunctionType()), -1, null);
127
					params.setParam("StretchBlueValueFunction", Double.valueOf(line.getValueFunction()), -1, null);
128
				}
129
			}
130
		}
131
		
132
		params.setParam("TailTrimRedMin",   Double.valueOf(0.0D), -1, null);
133
		params.setParam("TailTrimRedMax",   Double.valueOf(0.0D), -1, null);
134
		params.setParam("TailTrimGreenMin", Double.valueOf(0.0D), -1, null);
135
		params.setParam("TailTrimGreenMax", Double.valueOf(0.0D), -1, null);
136
		params.setParam("TailTrimBlueMin",  Double.valueOf(0.0D), -1, null);
137
		params.setParam("TailTrimBlueMax",  Double.valueOf(0.0D), -1, null);
138

  
139
		params.setParam("RGB", new Boolean(rgb), -1, null);
140
		String render = "";
141
		for (int i = 0; i < enhancedDialog.getLayer().getRender().getRenderBands().length; i++) {
142
			if (render != "")
143
				render += " ";
144
			render = render + "" + enhancedDialog.getLayer().getRender().getRenderBands()[i];
145
		}
146
		params.setParam("RenderBands", render, -1, null);
147

  
148
		enhancedDialog.getFilteredPreview().getParamsList().clear();
149
		Class filterClass = enhancedDialog.getLayer().getRender().getFilterList().getFilterClassByID("enhanced_stretch");
150
		enhancedDialog.getFilteredPreview().addNewParam("enhanced_stretch", params, filterClass);
151
		
152
		enhancedDialog.getPreviewBasePanel().refreshPreview();
153
	}
154

  
155
	/**
156
	 * Actualiza el histograma de salida del cuadro de realce
157
	 */
158
	public void updateHistogramOut() {
159
		HistogramStatus histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.DRAWED);
160
		if (histogram != null) {
161
			if (histogram.getBaseFunction() instanceof StraightLine) {
162
				StraightLine line = (StraightLine) histogram.getBaseFunction();
163
				double[] valuesIn = line.getPercentInValues();
164
				double[] valuesOut = line.getPercentOutValues();
165

  
166
				double origenHistogram[] = inputHistogram.getHistogramStatus(HistogramGraphicBase.DRAWED).getHistogram();
167
				double newHistogram[] = new double[origenHistogram.length];
168

  
169
				for (int i = 0; i < newHistogram.length; i++)
170
					newHistogram[i] = 0.0D;
171

  
172
				int pos;
173
				double p;
174
				for (int i = 0; i < origenHistogram.length; i++) {
175
					p = (((double) i) / (origenHistogram.length - 1.0D));
176
					
177
					for (int j = 0; j < (valuesIn.length - 1); j++) {
178
						if (valuesIn[j] == valuesIn[j + 1]) continue;
179
						if (p >= valuesIn[j] && p <= valuesIn[j + 1]) {
180
							p = valuesOut[j] + ((valuesOut[j + 1] - valuesOut[j]) * ((p - valuesIn[j]) / (valuesIn[j + 1] - valuesIn[j])));
181
							break;
182
						}
183
					}
184

  
185
					pos = (int) Math.round(p * (origenHistogram.length - 1.0D));
186
					if (pos < 0)
187
						pos = 0;
188
					if (pos > (origenHistogram.length - 1))
189
						pos = (origenHistogram.length - 1);
190

  
191
					newHistogram[pos] += origenHistogram[i];
192
				}
193

  
194
				HistogramStatus histogramOut = outputHistogram.getHistogramStatus(HistogramGraphicBase.DRAWED);
195
				histogramOut.setHistogram(newHistogram);
196
				histogramOut.setLimits(0.0D, 255.0D);
197
				outputHistogram.repaint();
198
			}
199
		}
200
	}
201
}
0 202

  
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/tool/enhanced/ui/EnhancedListener.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.app.extension.tool.enhanced.ui;
23

  
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26
import java.io.File;
27
import java.util.ArrayList;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.fmap.dal.coverage.RasterLocator;
31
import org.gvsig.fmap.dal.coverage.datastruct.Params;
32
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException;
33
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
34
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
35
import org.gvsig.fmap.dal.coverage.grid.filter.LinearStretchParams;
36
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
37
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
38
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
39
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
40
import org.gvsig.raster.app.extension.raster.bean.canvas.GCanvasEvent;
41
import org.gvsig.raster.app.extension.raster.bean.canvas.IGCanvasListener;
42
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.GraphicHistogram;
43
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.function.BaseFunction;
44
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.function.DensitySlicingLine;
45
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.function.LogaritmicExponentialLine;
46
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.function.SquareRootPowLine;
47
import org.gvsig.raster.app.extension.raster.bean.canvas.layer.function.StraightLine;
48
import org.gvsig.raster.app.extension.raster.bean.previewbase.ParamStruct;
49
import org.gvsig.raster.app.extension.raster.process.FilterProcess;
50
import org.gvsig.raster.app.extension.raster.process.IProcessActions;
51
import org.gvsig.raster.app.extension.tool.enhanced.graphics.HistogramGraphicBase;
52
import org.gvsig.raster.app.extension.tool.enhanced.graphics.HistogramGraphicBase.HistogramStatus;
53
import org.gvsig.raster.fmap.layers.FLyrRaster;
54
import org.gvsig.raster.util.LayerVisualStatusList;
55
import org.gvsig.raster.util.RasterNotLoadException;
56
import org.gvsig.raster.util.RasterToolsUtil;
57

  
58
/**
59
 * Gestor de eventos de los paneles de gr?ficas y controles.
60
 * 
61
 * 21/02/2008
62
 * @author Nacho Brodin nachobrodin@gmail.com
63
 */
64
public class EnhancedListener implements ActionListener, IGCanvasListener, ButtonsPanelListener, IProcessActions {
65
	private SelectorsPanel               selectorsPanel  = null;
66
	private GraphicsPanel                graphicsPanel   = null;
67
	private EnhancedDialog               enhancedDialog  = null;
68
	private PreviewFiltering             filteredPreview = null;
69
	private EnhancedHistogramController  enhancedManager = null;
70
	private LayerVisualStatusList        status          = new LayerVisualStatusList();
71
	
72
	/**
73
	 * Constructor
74
	 * @param selectorsPanel Panel con los selectores de opciones
75
	 * @param graphicsPanel Panel con los gr?ficos
76
	 * @param enhancedPanel Panel base con la previsualizaci?n
77
	 * @param enhancedDialog Dialogo general
78
	 * @param filteredPreview Preprocesado para la preview
79
	 */
80
	public EnhancedListener(SelectorsPanel selectorsPanel, 
81
							GraphicsPanel graphicsPanel, 
82
							EnhancedDialog enhancedDialog, 
83
							PreviewFiltering filteredPreview) {
84
		this.selectorsPanel = selectorsPanel;
85
		this.graphicsPanel = graphicsPanel;
86
		this.enhancedDialog = enhancedDialog;
87
		this.filteredPreview = filteredPreview;
88
		status.getVisualStatus(((FLyrRaster) enhancedDialog.getLayer()));
89
		
90
		
91
		enhancedManager = new EnhancedHistogramController(graphicsPanel.getInputHistogram(), graphicsPanel.getOutputHistogram(), enhancedDialog);
92
		
93
		selectorsPanel.getHistogramType().addActionListener(this);
94
		selectorsPanel.getDrawType().addActionListener(this);
95
		selectorsPanel.getBand(null).addActionListener(this);
96
		selectorsPanel.getEnhancedType().addActionListener(this);
97
		graphicsPanel.getLevels().addActionListener(this);
98
		graphicsPanel.getRGB().addActionListener(this);
99
	}
100
	
101
	/*
102
	 * (non-Javadoc)
103
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
104
	 */
105
	@SuppressWarnings("unchecked")
106
	public void actionPerformed(ActionEvent e) {
107
		//Cambio del tipo de de dibujado del histograma
108
		if(e.getSource() == selectorsPanel.getDrawType()) {
109
			if(((String)selectorsPanel.getDrawType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "fill"))) {
110
				graphicsPanel.getInputHistogram().setType(GraphicHistogram.TYPE_FILL);
111
				graphicsPanel.getOutputHistogram().setType(GraphicHistogram.TYPE_FILL);
112
			}
113
			
114
			if(((String)selectorsPanel.getDrawType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "line"))) {
115
				graphicsPanel.getInputHistogram().setType(GraphicHistogram.TYPE_LINE);
116
				graphicsPanel.getOutputHistogram().setType(GraphicHistogram.TYPE_LINE);
117
			}
118
			graphicsPanel.getInputHistogram().getCanvas().repaint();
119
			graphicsPanel.getOutputHistogram().getCanvas().repaint();
120
		}
121

  
122
		// Cambio el tipo de visualizacion del histograma
123
		if (e.getSource() == selectorsPanel.getHistogramType()) {
124
			if (((String) selectorsPanel.getHistogramType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "standard"))) {
125
				graphicsPanel.getOutputHistogram().setHistogramType(GraphicHistogram.VIEW_LINEAL);
126
			}
127
			
128
			if (((String) selectorsPanel.getHistogramType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "cumulative"))) {
129
				graphicsPanel.getOutputHistogram().setHistogramType(GraphicHistogram.VIEW_ACUMMULATED);
130
			}
131
			
132
			if (((String) selectorsPanel.getHistogramType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "logaritmic"))) {
133
				graphicsPanel.getOutputHistogram().setHistogramType(GraphicHistogram.VIEW_LOGARITHMIC);
134
			}
135
			
136
			if (((String) selectorsPanel.getHistogramType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "cumulative_logarithmic"))) {
137
				graphicsPanel.getOutputHistogram().setHistogramType(GraphicHistogram.VIEW_ACUMMULATEDLOG);
138
			}
139
			graphicsPanel.getOutputHistogram().getCanvas().repaint();
140
		}
141

  
142
		// Seleccion de modo RGB o normal
143
		if (e.getSource() == graphicsPanel.getRGB()) {
144
			graphicsPanel.updateHistogram();
145
			updatePreview();
146
		}
147
		
148
		//Cambio de banda
149
		if(e.getSource() == selectorsPanel.getBand(null)) {
150
			if(((String)selectorsPanel.getBand(null).getSelectedItem()).equals(RasterToolsUtil.getText(this, "red"))) {
151
				graphicsPanel.getInputHistogram().setHistogramDrawed(HistogramGraphicBase.RED);
152
				graphicsPanel.getOutputHistogram().setHistogramDrawed(HistogramGraphicBase.RED);
153
			}
154
			
155
			if(((String)selectorsPanel.getBand(null).getSelectedItem()).equals(RasterToolsUtil.getText(this, "green"))) {
156
				graphicsPanel.getInputHistogram().setHistogramDrawed(HistogramGraphicBase.GREEN);
157
				graphicsPanel.getOutputHistogram().setHistogramDrawed(HistogramGraphicBase.GREEN);
158
			}
159
			
160
			if(((String)selectorsPanel.getBand(null).getSelectedItem()).equals(RasterToolsUtil.getText(this, "blue"))) {
161
				graphicsPanel.getInputHistogram().setHistogramDrawed(HistogramGraphicBase.BLUE);
162
				graphicsPanel.getOutputHistogram().setHistogramDrawed(HistogramGraphicBase.BLUE);
163
			}
164

  
165
			updateTypeSelected();
166
			
167
			HistogramStatus status = graphicsPanel.getOutputHistogram().getHistogramStatus(HistogramGraphicBase.DRAWED);
168

  
169
			switch (status.getGraphicHistogram().getType()) {
170
				case GraphicHistogram.TYPE_FILL:
171
					selectorsPanel.getDrawType().setSelectedItem(RasterToolsUtil.getText(this, "fill"));
172
					break;
173
				default:
174
					selectorsPanel.getDrawType().setSelectedItem(RasterToolsUtil.getText(this, "line"));
175
					break;
176
			}
177

  
178
			switch (status.getGraphicHistogram().getTypeViewed()) {
179
				case GraphicHistogram.VIEW_ACUMMULATED:
180
					selectorsPanel.getHistogramType().setSelectedItem(RasterToolsUtil.getText(this, "cumulative"));
181
					break;
182
				case GraphicHistogram.VIEW_LOGARITHMIC:
183
					selectorsPanel.getHistogramType().setSelectedItem(RasterToolsUtil.getText(this, "logaritmic"));
184
					break;
185
				case GraphicHistogram.VIEW_ACUMMULATEDLOG:
186
					selectorsPanel.getHistogramType().setSelectedItem(RasterToolsUtil.getText(this, "cumulative_logarithmic"));
187
					break;
188
				default:
189
					selectorsPanel.getHistogramType().setSelectedItem(RasterToolsUtil.getText(this, "standard"));
190
					break;
191
			}
192
		}
193
		
194
		//Cambio de operaci?n
195
		if(e.getSource() == selectorsPanel.getEnhancedType()) {
196
			graphicsPanel.setLevelsEnabled(false);
197
			
198
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "lineal"))) {
199
				graphicsPanel.getInputHistogram().setFunction(GraphicHistogram.FUNCTION_LINEAL);
200
				updatePreview();
201
			}
202
			
203
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "gaussian"))) {
204

  
205
			}
206
			
207
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "logaritmic"))) {
208
				graphicsPanel.getInputHistogram().setFunction(GraphicHistogram.FUNCTION_LOGARIT);
209
				updatePreview();
210
			}
211
			
212
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "exponential"))) {
213
				graphicsPanel.getInputHistogram().setFunction(GraphicHistogram.FUNCTION_EXPONENT);
214
				updatePreview();
215
			}
216
			
217
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "equalization"))) {
218
				graphicsPanel.getInputHistogram().setFunction(GraphicHistogram.FUNCTION_NONE);
219
				int[] renderBands = enhancedDialog.getLayer().getRender().getRenderBands();
220
				String values = "";
221
				for (int i = 0; i < renderBands.length; i++) 
222
					values += renderBands[i] + " ";
223
				values = values.trim();
224
				Params params = RasterLocator.getManager().createParams("", 0, 0, null);
225
				params.setParam("Histogram", graphicsPanel.getHistogram(), -1, null);
226
				params.setParam("RenderBands", values, -1, null);
227
				params.setParam("EcualizedBands", new int[]{0, 1, 2}, -1, null);
228
						
229
				Class filterClass = enhancedDialog.getLayer().getRender().getFilterList().getFilterClassByID("equalization");
230
				filteredPreview.addNewParam("equalization", params, filterClass);				
231
				updatePreview();
232
			}
233
			
234
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "square_root"))) {
235
				graphicsPanel.getInputHistogram().setFunction(GraphicHistogram.FUNCTION_SQUARE_ROOT);
236
				updatePreview();
237
			}
238
			
239
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "level_slice"))) {
240
				graphicsPanel.setLevelsEnabled(true);
241
				graphicsPanel.getInputHistogram().setFunction(GraphicHistogram.FUNCTION_DENSITY);
242

  
243
				// Establece el numero de niveles en el cuadro de texto
244
				HistogramStatus status = graphicsPanel.getInputHistogram().getHistogramStatus(HistogramGraphicBase.DRAWED);
245
				graphicsPanel.getLevels().setValue(new Long(((DensitySlicingLine) status.getBaseFunction()).getLevels()));
246
				updatePreview();
247
			}
248
		}
249
		
250
		//Cambio de tipo (estandar/acumulado)
251
		if(e.getSource() == selectorsPanel.getHistogramType()) {
252
			if(((String)selectorsPanel.getHistogramType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "standard"))) {
253
				
254
			}
255
			
256
			if(((String)selectorsPanel.getHistogramType().getSelectedItem()).equals(RasterToolsUtil.getText(this, "cumulative"))) {
257
				
258
			}
259
		}
260
		
261
		//Cambio en el n?mero de niveles
262
		if(e.getSource() == graphicsPanel.getLevels()) {
263
			Long lValue = (Long)graphicsPanel.getLevels().getValue();
264
			int value = lValue.intValue();
265
			if(value > 30 || value < 2) {
266
				RasterToolsUtil.messageBoxInfo(RasterToolsUtil.getText(this, "range_wrong") + " [2-30]", null);
267
				if(value > 30)
268
					value = 30;
269
				if(value < 2)
270
					value = 2;
271
			}
272
			graphicsPanel.getLevels().setValue(new Long(value));
273
			try {
274
				graphicsPanel.getInputHistogram().setLevel(value);
275
				updatePreview();
276
			} catch (NumberFormatException exc) {
277
				//No asignamos el nivel
278
			}
279
		}
280
	}
281
	
282
	/**
283
	 * Actualiza el combo de EnhancedType para que este seleccionado siempre el
284
	 * item que corresponde con la grafica mostrada en ese momento
285
	 */
286
	private void updateTypeSelected() {
287
		HistogramStatus status = graphicsPanel.getInputHistogram().getHistogramStatus(HistogramGraphicBase.DRAWED);
288

  
289
		if (status.getBaseFunction().getClass().equals(DensitySlicingLine.class))
290
			selectorsPanel.setSelectedEnhancedType(RasterToolsUtil.getText(this, "level_slice"));
291

  
292
		if (status.getBaseFunction().getClass().equals(StraightLine.class))
293
			selectorsPanel.setSelectedEnhancedType(RasterToolsUtil.getText(this, "lineal"));
294

  
295
		Class filterClass = enhancedDialog.getLayer().getRender().getFilterList().getFilterClassByID("equalization");
296
		if (status.getBaseFunction().getClass().equals(filterClass))
297
			selectorsPanel.setSelectedEnhancedType(RasterToolsUtil.getText(this, "equalization"));
298

  
299
		if (status.getBaseFunction().getClass().equals(SquareRootPowLine.class))
300
			selectorsPanel.setSelectedEnhancedType(RasterToolsUtil.getText(this, "square_root"));
301

  
302
		if (status.getBaseFunction().getClass().equals(LogaritmicExponentialLine.class)) {
303
			if (((StraightLine) status.getBaseFunction()).getValueFunction() >= 0)
304
				selectorsPanel.setSelectedEnhancedType(RasterToolsUtil.getText(this, "logaritmic"));
305
			else
306
				selectorsPanel.setSelectedEnhancedType(RasterToolsUtil.getText(this, "exponential"));
307
		}
308
	}
309
	
310
	/**
311
	 * En la primera carga se define cada banda en los histogramas, para dejarlo en
312
	 * su estado logico.
313
	 * @param stretch
314
	 * @param band
315
	 */
316
	private void firstLoadBand(Stretch stretch, int band) {
317
		boolean firstBand = ((band == HistogramGraphicBase.GRAY) || (band == HistogramGraphicBase.RED));
318

  
319
		graphicsPanel.getInputHistogram().setHistogramDrawed(band);
320
		
321
		BaseFunction baseFunction = null;
322
		HistogramStatus status;
323
		status = graphicsPanel.getInputHistogram().getHistogramStatus(band);
324
		if (status == null)
325
			return;
326
		
327
		switch (stretch.functionType) {
328
			case 0:
329
				if (firstBand) {
330
					selectorsPanel.getEnhancedType().setSelectedItem(RasterToolsUtil.getText(this, "lineal"));
331
					graphicsPanel.setLevelsEnabled(false);
332
				}
333
				baseFunction = new StraightLine(status.getBaseFunction().getColor());
334
				((StraightLine) baseFunction).clearSquares();
335
				for (int i = 0; i < stretch.stretchIn.length; i++) {
336
					((StraightLine) baseFunction).addSquare(
337
						(stretch.stretchIn[i] - stretch.minValue) / (stretch.maxValue - stretch.minValue),
338
						stretch.stretchOut[i] / 255.0D);
339
				}
340
				break;
341
			case 1:
342
				if (firstBand) {
343
					if (stretch.valueFunction >= 0)
344
						selectorsPanel.getEnhancedType().setSelectedItem(RasterToolsUtil.getText(this, "logaritmic"));
345
					else
346
						selectorsPanel.getEnhancedType().setSelectedItem(RasterToolsUtil.getText(this, "exponential"));
347
					graphicsPanel.setLevelsEnabled(false);
348
				}
349
				baseFunction = new LogaritmicExponentialLine(status.getBaseFunction().getColor(), stretch.valueFunction);
350
				break;
351
			case 2:
352
				if (firstBand) {
353
					selectorsPanel.getEnhancedType().setSelectedItem(RasterToolsUtil.getText(this, "square_root"));
354
					graphicsPanel.setLevelsEnabled(false);
355
				}
356
				baseFunction = new SquareRootPowLine(status.getBaseFunction().getColor(), stretch.valueFunction);
357
				break;
358
			case 3:
359
				if (firstBand) {
360
					selectorsPanel.getEnhancedType().setSelectedItem(RasterToolsUtil.getText(this, "level_slice"));
361
					graphicsPanel.setLevelsEnabled(true);
362
				}
363
				baseFunction = new DensitySlicingLine(status.getBaseFunction().getColor(), (int) stretch.valueFunction);
364
				break;
365
		}
366
		if (baseFunction != null) {
367
			status.setBaseFunction(baseFunction);
368
			graphicsPanel.getInputHistogram().setHistogramDrawed(band);
369
		}
370
	}
371
	
372
	/**
373
	 * En la primera carga se han de establecer todos los histogramas de entrada
374
	 * a sus valores correspondientes segun el filtro.
375
	 */
376
	public void firstLoad() {
377
		RasterFilterList rasterFilterList = ((FLyrRaster) enhancedDialog.getLayer()).getRenderFilterList();
378

  
379
		LinearStretchEnhancementFilter filter = (LinearStretchEnhancementFilter) rasterFilterList.getByName(LinearStretchEnhancementFilter.names[0]);
380
		if (filter != null) {
381
			LinearStretchParams stretch = filter.getStretchs();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff