Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / profiles / gui / ZProfileOptionsPanel.java @ 20291

History | View | Annotate | Download (9.25 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.Iterator;
53
import java.util.LinkedHashMap;
54

    
55
import javax.swing.ImageIcon;
56
import javax.swing.JPanel;
57
import javax.swing.JToggleButton;
58

    
59
import org.gvsig.fmap.raster.grid.roi.VectorialROI;
60
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
61
import org.gvsig.gui.beans.graphic.GraphicChartPanel;
62
import org.gvsig.gui.beans.table.TableContainer;
63
import org.gvsig.raster.buffer.BufferFactory;
64
import org.gvsig.raster.buffer.RasterBuffer;
65
import org.gvsig.raster.buffer.RasterBufferInvalidException;
66
import org.gvsig.raster.dataset.IRasterDataSource;
67
import org.gvsig.raster.grid.Grid;
68
import org.gvsig.raster.grid.roi.ROI;
69
import org.gvsig.remotesensing.profiles.listener.DrawMouseProfileListener;
70
import org.gvsig.remotesensing.profiles.listener.ZProfileOptionsListener;
71
import org.jfree.chart.axis.NumberAxis;
72
import org.jfree.chart.axis.NumberTickUnit;
73
import org.jfree.chart.plot.XYPlot;
74

    
75
import com.iver.andami.PluginServices;
76
import com.iver.cit.gvsig.fmap.MapControl;
77
import com.iver.cit.gvsig.fmap.layers.FLayer;
78
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
79
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
80
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
81
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
82
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
83

    
84
/**
85
* Panel de opciones para  z-Profiles.
86
*         
87
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)   
88
* @version 11/12/2007
89
*  
90
**/
91

    
92
public class ZProfileOptionsPanel extends JPanel {
93

    
94
        private static final long serialVersionUID = 1L;
95
        private FLayer fLayer = null;
96
        private Grid grid= null;
97
        TableContainer tableContainer = null;
98
        private JToggleButton newButton = null;
99
        private JToggleButton deleteButton = null; 
100
        private JPanel controlPanel = null;
101
        private ZProfileOptionsListener listener= null;
102
        private Cursor cursor = null;
103
        private MapControl mapControl= null;
104
        private LinkedHashMap rois = null;
105
        private HashMap roiGraphics = null;
106
        private GraphicChartPanel                jPanelChart = null;
107
        private ProfilePanel mainPanel= null;
108
        
109
        public  ZProfileOptionsPanel(ProfilePanel mainPanel) {
110
                super();
111
                this.mapControl = mainPanel.getMapControl();
112
                this.mainPanel= mainPanel;
113
                this.fLayer = mapControl.getMapContext().getLayers().getLayer(0);;
114
                BorderLayout bd= new BorderLayout();
115
                listener= new ZProfileOptionsListener(this);
116
                bd.setHgap(1);
117
                setLayout(bd);
118
                add(getTable(), BorderLayout.CENTER);
119
                add(getControlPanel(), BorderLayout.WEST);
120
                initialize();
121
        }
122
        
123
        
124
        private void initialize() {
125
        
126
                getNewButton().addActionListener(listener);
127
                getDeleteButton().addActionListener(listener);
128
                getTable().getTable().getJTable().getSelectionModel()
129
                                .addListSelectionListener(listener);
130
                getTable().getTable().getJTable().getModel().addTableModelListener(
131
                                listener);
132
                
133
                // Grid fuente de datos
134
                FLyrRasterSE rasterLayer = (FLyrRasterSE) fLayer;
135
                IRasterDataSource dsetCopy = null; 
136
                dsetCopy = rasterLayer.getDataSource().newDataset();
137
                BufferFactory bufferFactory = new BufferFactory(dsetCopy);
138
                if (!RasterBuffer.loadInMemory(dsetCopy))
139
                        bufferFactory.setReadOnly(true);
140
                try {
141
                        bufferFactory.setAllDrawableBands();
142
                        grid= new Grid(bufferFactory);
143
                } catch (RasterBufferInvalidException e) {
144
                        e.printStackTrace();
145
                }
146
                StatusBarListener sbl = new StatusBarListener(mapControl);
147
                DrawMouseProfileListener drawMouseViewListener = new DrawMouseProfileListener(
148
                                mainPanel);
149
                mapControl.addMapTool("drawPointROI", new Behavior[] {
150
                                new PointBehavior(drawMouseViewListener),
151
                                new MouseMovementBehavior(sbl) });
152
                
153
        }
154
        
155
        
156
        public TableContainer getTable() {
157
                if (tableContainer == null) {
158
                        String[] columnNames = { PluginServices.getText(this, "punto"),
159
                                        PluginServices.getText(this, "color"),
160
                                        PluginServices.getText(this, "coordx"),
161
                                        PluginServices.getText(this, "coordy"),
162
                        };
163
                        int[] columnWidths = { 20, 25, 25, 25, 0 };
164
                        tableContainer = new TableContainer(columnNames, columnWidths);
165
                        tableContainer.setModel("ProfilesTableModel");
166
                        tableContainer.initialize();
167
                        tableContainer.setControlVisible(false);
168
                }
169
                return tableContainer;
170
        }
171

    
172
        
173
        public JPanel getControlPanel() {
174
                if (controlPanel == null) {
175
                        controlPanel = new JPanel();
176
                        //controlPanel.setPreferredSize(new Dimension(80,20));        
177
                        GridBagLayout gb = new GridBagLayout();
178
                        controlPanel.setLayout(gb);
179
                        GridBagConstraints constrains = new GridBagConstraints();
180
                        constrains.insets = new java.awt.Insets(1,5 , 1, 1);
181
                        constrains.gridx= 0;
182
                        constrains.gridy= 0;
183
                        controlPanel.add(getNewButton(),constrains);
184
                        constrains.insets = new java.awt.Insets(1,5 , 1, 1);
185
                        constrains.gridx= 0;
186
                        constrains.gridy= 1;
187
                        controlPanel.add(getDeleteButton(),constrains);
188

    
189
                }
190
                return controlPanel;
191
        }
192

    
193

    
194
        public JToggleButton getDeleteButton() {
195
                if(deleteButton== null){
196
                        deleteButton = new JToggleButton();
197
                        ImageIcon icono = new ImageIcon(ZProfileOptionsPanel.class.getClassLoader().getResource("images/delete.png"));
198
                        deleteButton.setSize(30,30);
199
                        deleteButton.setIcon(icono);
200
                }
201
                return deleteButton;
202
        }
203

    
204

    
205
        public JToggleButton getNewButton() {
206
                if(newButton== null){
207
                        newButton = new JToggleButton();
208
                        ImageIcon icono = new ImageIcon(ZProfileOptionsPanel.class.getClassLoader().getResource("images/Point.png"));
209
                        newButton.setIcon(icono);
210
                        newButton.setSize(30,30);
211
                }
212
                return newButton;
213
        }
214

    
215
        
216
        
217
        public void selectDrawRoiTool() {
218
                if (mapControl != null){
219
                        if (getNewButton().isSelected()) {
220
                                Image img = new ImageIcon(ZProfileOptionsPanel.class.getClassLoader().getResource(
221
                                                "images/PointCursor.png")).getImage();
222
                                cursor = Toolkit.getDefaultToolkit().createCustomCursor(img,
223
                                                new Point(16, 16), "");
224
                                mapControl.setTool("drawPointROI");
225
                        }
226
                }
227
        }
228

    
229
        public Grid getGrid(){
230
                 return grid;
231
        }
232

    
233

    
234
        public MapControl getMapControl() {
235
                return mapControl;
236
        }
237

    
238
        public Cursor getToolCursor() {
239
                return cursor;
240
        }
241
        
242
        public LinkedHashMap getRois() {
243
                if (rois == null)
244
                        rois = new LinkedHashMap();
245
                return rois;
246
        }
247

    
248
        private HashMap getRoiGraphics() {
249
                if (roiGraphics == null)
250
                        roiGraphics = new HashMap();
251
                return roiGraphics;
252
        }
253

    
254
        public ArrayList getROIs() {
255
                return new ArrayList(getRois().values());
256
        }
257
        
258
        public ArrayList getRoiGraphics(String roiName) {
259
                return (ArrayList) getRoiGraphics().get(roiName);
260
        }
261

    
262
        public void addROI(ROI roi) {
263
                getRois().put(roi.getName(), roi);
264
                getRoiGraphics().put(roi.getName(), new ArrayList());
265
        }
266

    
267

    
268
        public void setJPanelChart(GraphicChartPanel panelChart) {
269
                
270
                
271
                jPanelChart = panelChart;
272
        }
273

    
274

    
275
        public GraphicChartPanel getJPanelChart() {
276
                jPanelChart.cleanChart(); 
277
                XYPlot plot = jPanelChart.getChart().getChart().getXYPlot();
278
                NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"bandas"));
279
                domainAxis.setRange(1,getGrid().getBandCount() );
280
                domainAxis.setTickUnit(new NumberTickUnit(1.0));
281
                plot.setDomainAxis(domainAxis);
282
                return jPanelChart;
283
        }
284

    
285

    
286
        public void removeROI(String roiName) {
287
                boolean repaint = false;
288
                getRois().remove(roiName);
289
                ArrayList roiGraphics = getRoiGraphics(roiName);
290
                if (roiGraphics != null) {
291
                        for (int i = 0; i < roiGraphics.size(); i++){
292
                                getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic) getRoiGraphics(roiName).get(i));
293
                                repaint = true;
294
                        }
295
                        if (repaint)
296
                                getMapControl().rePaintDirtyLayers();
297
                        getRoiGraphics().remove(roiName);
298
                }
299
        }
300
        
301
        
302
        
303
        public void UpdateChart(){
304
                XYPlot plot = jPanelChart.getChart().getChart().getXYPlot();
305
                int index=-1; 
306
                for (Iterator iter = getROIs().iterator(); iter.hasNext();){
307
                        VectorialROI roi = (VectorialROI)iter.next();
308
                        index=index+1;
309
                        plot.getRenderer().setSeriesPaint(index, roi.getColor());
310
                }        
311
        }
312
        
313
        public ROI getROI(String roiName) {
314
                return (ROI) getRois().get(roiName);
315
        }
316

    
317
        public int getNextActive(){
318
                return mainPanel.getActivePanel();
319
        }
320
}