svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / profiles / gui / LineProfileOptionsPanel.java @ 20291
History | View | Annotate | Download (10.2 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 Instituto de Desarrollo Regional 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.profiles.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Cursor; |
45 |
import java.awt.GridBagConstraints; |
46 |
import java.awt.GridBagLayout; |
47 |
import java.awt.Image; |
48 |
import java.awt.Point; |
49 |
import java.awt.Toolkit; |
50 |
import java.util.ArrayList; |
51 |
import java.util.HashMap; |
52 |
import java.util.LinkedHashMap; |
53 |
|
54 |
import javax.swing.ComboBoxModel; |
55 |
import javax.swing.DefaultComboBoxModel; |
56 |
import javax.swing.ImageIcon; |
57 |
import javax.swing.JPanel; |
58 |
import javax.swing.JToggleButton; |
59 |
|
60 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
61 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
62 |
import org.gvsig.gui.beans.graphic.GraphicChartPanel; |
63 |
import org.gvsig.gui.beans.table.TableContainer; |
64 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
65 |
import org.gvsig.raster.buffer.BufferFactory; |
66 |
import org.gvsig.raster.buffer.RasterBuffer; |
67 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
68 |
import org.gvsig.raster.dataset.IRasterDataSource; |
69 |
import org.gvsig.raster.grid.Grid; |
70 |
import org.gvsig.raster.grid.roi.ROI; |
71 |
import org.gvsig.remotesensing.profiles.listener.DrawMouseProfileListener; |
72 |
import org.gvsig.remotesensing.profiles.listener.LineProfileOptionsListener; |
73 |
import org.jfree.chart.axis.NumberAxis; |
74 |
import org.jfree.chart.plot.XYPlot; |
75 |
|
76 |
import com.iver.andami.PluginServices; |
77 |
import com.iver.cit.gvsig.fmap.MapControl; |
78 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
79 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
80 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
81 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
82 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
83 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
84 |
import com.iver.utiles.swing.JComboBox; |
85 |
|
86 |
/**
|
87 |
* Panel para los lineProfiles. Contiene la tabla y los controles asociados para a?adir y eliminar
|
88 |
* nuevos profiles.
|
89 |
*
|
90 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
91 |
* @version 11/12/2007
|
92 |
*
|
93 |
**/
|
94 |
public class LineProfileOptionsPanel extends JPanel { |
95 |
|
96 |
private static final long serialVersionUID = 1L; |
97 |
private FLayer fLayer = null; |
98 |
private Grid grid= null; |
99 |
TableContainer tableContainer = null;
|
100 |
private JToggleButton newButton = null; |
101 |
private JToggleButton deleteButton = null; |
102 |
private JPanel controlPanel = null; |
103 |
private LineProfileOptionsListener listener= null; |
104 |
private Cursor cursor = null; |
105 |
private MapControl mapControl= null; |
106 |
private LinkedHashMap rois = null; |
107 |
private HashMap roiGraphics = null; |
108 |
private GraphicChartPanel jPanelChart = null; |
109 |
private ProfilePanel mainPanel= null; |
110 |
private JComboBox comboBands = null; |
111 |
private String previousTool = null; |
112 |
|
113 |
public LineProfileOptionsPanel(ProfilePanel mainPanel) {
|
114 |
super();
|
115 |
this.mapControl = mainPanel.getMapControl();
|
116 |
this.mainPanel = mainPanel;
|
117 |
this.fLayer = mapControl.getMapContext().getLayers().getLayer(0);; |
118 |
BorderLayout bd= new BorderLayout(); |
119 |
listener= new LineProfileOptionsListener(this); |
120 |
bd.setHgap(1);
|
121 |
setLayout(bd); |
122 |
initialize(); |
123 |
add(getTable(), BorderLayout.CENTER);
|
124 |
add(getControlPanel(), BorderLayout.WEST);
|
125 |
previousTool = mapControl.getCurrentTool(); |
126 |
} |
127 |
|
128 |
|
129 |
private void initialize() { |
130 |
|
131 |
getNewButton().addActionListener(listener); |
132 |
getDeleteButton().addActionListener(listener); |
133 |
getTable().getTable().getJTable().getSelectionModel() |
134 |
.addListSelectionListener(listener); |
135 |
getTable().getTable().getJTable().getModel().addTableModelListener( |
136 |
listener); |
137 |
|
138 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) fLayer; |
139 |
IRasterDataSource dsetCopy = null;
|
140 |
dsetCopy = rasterLayer.getDataSource().newDataset(); |
141 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
142 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
143 |
bufferFactory.setReadOnly(true);
|
144 |
try {
|
145 |
bufferFactory.setAllDrawableBands(); |
146 |
grid= new Grid(bufferFactory);
|
147 |
} catch (RasterBufferInvalidException e) {
|
148 |
e.printStackTrace(); |
149 |
} |
150 |
StatusBarListener sbl = new StatusBarListener(mapControl);
|
151 |
DrawMouseProfileListener drawMouseViewListener = new DrawMouseProfileListener(
|
152 |
mainPanel); |
153 |
mapControl.addMapTool("drawLineROI", new Behavior[] { |
154 |
new PolylineBehavior(drawMouseViewListener),
|
155 |
new MouseMovementBehavior(sbl) });
|
156 |
|
157 |
} |
158 |
|
159 |
|
160 |
public TableContainer getTable() {
|
161 |
if (tableContainer == null) { |
162 |
String[] columnNames = { PluginServices.getText(this, "Linea"), |
163 |
PluginServices.getText(this, "color"), |
164 |
PluginServices.getText(this, "valor_max"), |
165 |
PluginServices.getText(this, "valor_min"), |
166 |
PluginServices.getText(this, "valor_medio") |
167 |
}; |
168 |
int[] columnWidths = {30, 30, 25, 25, 25}; |
169 |
tableContainer = new TableContainer(columnNames, columnWidths);
|
170 |
tableContainer.setModel("ProfilesTableModel");
|
171 |
tableContainer.initialize(); |
172 |
tableContainer.setControlVisible(false);
|
173 |
} |
174 |
return tableContainer;
|
175 |
} |
176 |
|
177 |
|
178 |
public JPanel getControlPanel() { |
179 |
if (controlPanel == null) { |
180 |
controlPanel = new JPanel(); |
181 |
GridBagLayout gb = new GridBagLayout(); |
182 |
controlPanel.setLayout(gb); |
183 |
GridBagConstraints constrains = new GridBagConstraints(); |
184 |
constrains.insets = new java.awt.Insets(1,5 , 1, 1); |
185 |
constrains.gridx= 0;
|
186 |
constrains.gridy= 0;
|
187 |
controlPanel.add(getNewButton(),constrains); |
188 |
constrains.insets = new java.awt.Insets(1,5 , 1, 1); |
189 |
constrains.gridx= 0;
|
190 |
constrains.gridy= 1;
|
191 |
controlPanel.add(getDeleteButton(),constrains); |
192 |
constrains.insets = new java.awt.Insets(1,5 , 1, 1); |
193 |
constrains.gridx= 0;
|
194 |
constrains.gridy= 2;
|
195 |
controlPanel.add(getComboBands(),constrains); |
196 |
} |
197 |
return controlPanel;
|
198 |
} |
199 |
|
200 |
|
201 |
public JToggleButton getDeleteButton() { |
202 |
if(deleteButton== null){ |
203 |
deleteButton = new JToggleButton(); |
204 |
ImageIcon icono = new ImageIcon(LineProfileOptionsPanel.class.getClassLoader().getResource("images/delete.png")); |
205 |
deleteButton.setSize(30,30); |
206 |
deleteButton.setIcon(icono); |
207 |
} |
208 |
return deleteButton;
|
209 |
} |
210 |
|
211 |
|
212 |
public JToggleButton getNewButton() { |
213 |
if(newButton== null){ |
214 |
newButton = new JToggleButton(); |
215 |
ImageIcon icono = new ImageIcon(LineProfileOptionsPanel.class.getClassLoader().getResource("images/Line.png")); |
216 |
newButton.setIcon(icono); |
217 |
newButton.setSize(30,30); |
218 |
} |
219 |
return newButton;
|
220 |
} |
221 |
|
222 |
|
223 |
public void selectDrawRoiTool() { |
224 |
if (mapControl != null){ |
225 |
if (getNewButton().isSelected()) {
|
226 |
Image img = new ImageIcon(LineProfileOptionsPanel.class.getClassLoader().getResource( |
227 |
"images/LineCursor.png")).getImage();
|
228 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img,
|
229 |
new Point(16, 16), ""); |
230 |
mapControl.setTool("drawLineROI");
|
231 |
} |
232 |
} |
233 |
} |
234 |
|
235 |
|
236 |
public JComboBox getComboBands() { |
237 |
if (comboBands==null){ |
238 |
comboBands= new JComboBox(); |
239 |
String[] sNames = new String[getGrid().getBandCount()]; |
240 |
for(int i=0; i<getGrid().getBandCount();i++) |
241 |
sNames[i]= PluginServices.getText(this,"banda")+(i+1); |
242 |
ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel(sNames); |
243 |
comboBands.setModel(jComboBoxLayersModel); |
244 |
comboBands.setEnabled(true);
|
245 |
comboBands.addActionListener(listener); |
246 |
} |
247 |
return comboBands;
|
248 |
} |
249 |
|
250 |
public Grid getGrid(){
|
251 |
return grid;
|
252 |
} |
253 |
|
254 |
|
255 |
public MapControl getMapControl() {
|
256 |
return mapControl;
|
257 |
} |
258 |
|
259 |
public Cursor getToolCursor() { |
260 |
return cursor;
|
261 |
} |
262 |
|
263 |
public LinkedHashMap getRois() { |
264 |
if (rois == null) |
265 |
rois = new LinkedHashMap(); |
266 |
return rois;
|
267 |
} |
268 |
|
269 |
private HashMap getRoiGraphics() { |
270 |
if (roiGraphics == null) |
271 |
roiGraphics = new HashMap(); |
272 |
return roiGraphics;
|
273 |
} |
274 |
|
275 |
public ArrayList getROIs() { |
276 |
return new ArrayList(getRois().values()); |
277 |
} |
278 |
|
279 |
public ArrayList getRoiGraphics(String roiName) { |
280 |
return (ArrayList) getRoiGraphics().get(roiName); |
281 |
} |
282 |
|
283 |
public void addROI(ROI roi) { |
284 |
getRois().put(roi.getName(), roi); |
285 |
getRoiGraphics().put(roi.getName(), new ArrayList()); |
286 |
} |
287 |
|
288 |
|
289 |
public void setJPanelChart(GraphicChartPanel panelChart) { |
290 |
jPanelChart = panelChart; |
291 |
} |
292 |
|
293 |
|
294 |
public GraphicChartPanel getJPanelChart() {
|
295 |
jPanelChart.cleanChart(); |
296 |
XYPlot plot = jPanelChart.getChart().getChart().getXYPlot(); |
297 |
NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"pixeles")); |
298 |
plot.setDomainAxis(domainAxis); |
299 |
return jPanelChart;
|
300 |
} |
301 |
|
302 |
|
303 |
public void removeROI(String roiName) { |
304 |
boolean repaint = false; |
305 |
getRois().remove(roiName); |
306 |
ArrayList roiGraphics = getRoiGraphics(roiName);
|
307 |
if (roiGraphics != null) { |
308 |
for (int i = 0; i < roiGraphics.size(); i++){ |
309 |
getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic) getRoiGraphics(roiName).get(i)); |
310 |
repaint = true;
|
311 |
} |
312 |
if (repaint)
|
313 |
getMapControl().rePaintDirtyLayers(); |
314 |
getRoiGraphics().remove(roiName); |
315 |
} |
316 |
} |
317 |
|
318 |
|
319 |
public void UpdateChart(){ |
320 |
XYPlot plot = jPanelChart.getChart().getChart().getXYPlot(); |
321 |
int index=0; |
322 |
try {
|
323 |
index = getTable().getSelectedRow(); |
324 |
VectorialROI roi = (VectorialROI)getROIs().get(index); |
325 |
plot.getRenderer().setSeriesPaint(0, roi.getColor());
|
326 |
} catch (NotInitializeException e) {
|
327 |
e.printStackTrace(); |
328 |
} |
329 |
} |
330 |
|
331 |
public ROI getROI(String roiName) { |
332 |
return (ROI) getRois().get(roiName);
|
333 |
} |
334 |
|
335 |
public int getActive(){ |
336 |
return mainPanel.getActivePanel();
|
337 |
} |
338 |
|
339 |
|
340 |
public String getPreviousTool() { |
341 |
return previousTool;
|
342 |
} |
343 |
} |