Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / profiles / gui / ZProfileOptionsPanel.java @ 26348

History | View | Annotate | Download (9.43 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
        private String previousTool = null;
109
        
110
        public  ZProfileOptionsPanel(ProfilePanel mainPanel) {
111
                super();
112
                this.mapControl = mainPanel.getMapControl();
113
                this.mainPanel= mainPanel;
114
                this.fLayer = mainPanel.getFlayer();
115
                BorderLayout bd= new BorderLayout();
116
                listener= new ZProfileOptionsListener(this);
117
                bd.setHgap(1);
118
                setLayout(bd);
119
                add(getTable(), BorderLayout.CENTER);
120
                add(getControlPanel(), BorderLayout.WEST);
121
                previousTool = mapControl.getCurrentTool();
122
                initialize();
123
        }
124
        
125
        
126
        private void initialize() {
127
        
128
                getNewButton().addActionListener(listener);
129
                getDeleteButton().addActionListener(listener);
130
                getTable().getTable().getJTable().getSelectionModel()
131
                                .addListSelectionListener(listener);
132
                getTable().getTable().getJTable().getModel().addTableModelListener(
133
                                listener);
134
                
135
                // Grid fuente de datos
136
                FLyrRasterSE rasterLayer = (FLyrRasterSE) fLayer;
137
                IRasterDataSource dsetCopy = null; 
138
                dsetCopy = rasterLayer.getDataSource().newDataset();
139
                BufferFactory bufferFactory = new BufferFactory(dsetCopy);
140
                if (!RasterBuffer.loadInMemory(dsetCopy))
141
                        bufferFactory.setReadOnly(true);
142
                try {
143
                        bufferFactory.setAllDrawableBands();
144
                        grid= new Grid(bufferFactory);
145
                } catch (RasterBufferInvalidException e) {
146
                        e.printStackTrace();
147
                }
148
                StatusBarListener sbl = new StatusBarListener(mapControl);
149
                DrawMouseProfileListener drawMouseViewListener = new DrawMouseProfileListener(
150
                                mainPanel);
151
                mapControl.addMapTool("drawPointROI", new Behavior[] {
152
                                new PointBehavior(drawMouseViewListener),
153
                                new MouseMovementBehavior(sbl) });
154
                
155
        }
156
        
157
        
158
        public TableContainer getTable() {
159
                if (tableContainer == null) {
160
                        String[] columnNames = { PluginServices.getText(this, "punto"),
161
                                        PluginServices.getText(this, "color"),
162
                                        PluginServices.getText(this, "coordx"),
163
                                        PluginServices.getText(this, "coordy"),
164
                        };
165
                        int[] columnWidths = { 20, 25, 25, 25, 0 };
166
                        tableContainer = new TableContainer(columnNames, columnWidths);
167
                        tableContainer.setModel("ProfilesTableModel");
168
                        tableContainer.initialize();
169
                        tableContainer.setControlVisible(false);
170
                }
171
                return tableContainer;
172
        }
173

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

    
191
                }
192
                return controlPanel;
193
        }
194

    
195

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

    
206

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

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

    
231
        public Grid getGrid(){
232
                 return grid;
233
        }
234

    
235

    
236
        public MapControl getMapControl() {
237
                return mapControl;
238
        }
239

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

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

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

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

    
269

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

    
276

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

    
287

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

    
319
        public int getNextActive(){
320
                return mainPanel.getActivePanel();
321
        }
322

    
323

    
324
        public String getPreviousTool() {
325
                return previousTool;
326
        }
327

    
328

    
329
        public ZProfileOptionsListener getListener() {
330
                return listener;
331
        }
332
}