Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / roi / ui / ROIManagerDialog.java @ 21739

History | View | Annotate | Download (5.67 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.rastertools.roi.ui;
42

    
43
import java.awt.BorderLayout;
44
import java.util.ArrayList;
45

    
46
import javax.swing.JPanel;
47

    
48
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
49
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
50
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
51
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
52
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
53
import org.gvsig.raster.grid.GridException;
54

    
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.ui.mdiManager.IWindow;
57
import com.iver.andami.ui.mdiManager.IWindowListener;
58
import com.iver.andami.ui.mdiManager.WindowInfo;
59
import com.iver.cit.gvsig.fmap.MapControl;
60
import com.iver.cit.gvsig.fmap.layers.FLayer;
61
import com.iver.cit.gvsig.project.documents.view.gui.View;
62

    
63
/**
64
 * Di?logo para el gestor de ROIs.
65
 * 
66
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
67
 *
68
 */
69
public class ROIManagerDialog extends JPanel implements IWindow, IWindowListener, ButtonsPanelListener {
70
        private static final long serialVersionUID = 2847035927527203595L;
71
        
72
        
73
        private ROIsManagerPanel roiManagerPanel = null;
74
        
75
        private MapControl mapControl = null;
76
        
77
        private String previousTool = null;
78
        
79
        /**
80
         * Constructor
81
         * @param width Ancho del panel
82
         * @param height Alto del panel
83
         */
84
        public ROIManagerDialog(int width, int height) {
85
                this.setSize(width, height);
86
                this.setLayout(new BorderLayout());
87
                this.add(getROIsManagerPanel(), BorderLayout.CENTER);
88
                IWindow[] list = PluginServices.getMDIManager().getAllWindows();
89
                View view = null;
90
                for (int i = 0; i < list.length; i++) {
91
                        if(list[i] instanceof View)
92
                                view = (View)list[i];
93
                }
94
                if (view == null)
95
                        return;
96
                mapControl = view.getMapControl();
97
                previousTool = mapControl.getCurrentTool();
98
                
99
        }
100

    
101
        public ROIsManagerPanel getROIsManagerPanel() {
102
                if (roiManagerPanel == null){
103
                        roiManagerPanel = new ROIsManagerPanel(this);
104
                        roiManagerPanel.addButtonPressedListener(this);
105
                }
106
                return roiManagerPanel;
107
        }
108

    
109
        public WindowInfo getWindowInfo() {
110
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
111
                if(roiManagerPanel.getTablePanel().getFLayer() != null)
112
                        m_viewinfo.setAdditionalInfo(roiManagerPanel.getTablePanel().getFLayer().getName());
113
                m_viewinfo.setTitle(PluginServices.getText(this, "regiones_interes")+" - "+m_viewinfo.getAdditionalInfo());
114
                m_viewinfo.setHeight(this.getHeight());
115
                m_viewinfo.setWidth(this.getWidth());
116
                return m_viewinfo;
117
        }
118

    
119
        public void actionButtonPressed(ButtonsPanelEvent e) {
120
//                 Al pulsar Aceptar o Aplicar se ejecuta el aceptar del panel
121
                if (e.getButton() == ButtonsPanel.BUTTON_APPLY || e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
122
                        ArrayList rois = roiManagerPanel.getTablePanel().getROIs();
123
                        if (rois.size() >0){
124
                                ((FLyrRasterSE)roiManagerPanel.getTablePanel().getFLayer()).setRois(rois);
125
                        }else
126
                                ((FLyrRasterSE)roiManagerPanel.getTablePanel().getFLayer()).setRois(null);
127
                }
128

    
129
                // Al pulsar Cancelar la ventana se cierra y se refresca la vista
130
                if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
131
                        close();
132
                }
133

    
134
                // Al pulsar Aceptar simplemente la ventana se cierra
135
                if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
136
                        close();
137
                }
138
        }
139
        
140
        /**
141
         * Acciones a ejecutar cuando se cancela
142
         */
143
        public void close() {
144
                try {
145
                        PluginServices.getMDIManager().closeWindow(this);
146
                } catch (ArrayIndexOutOfBoundsException e) {
147
                        //Si la ventana no se puede eliminar no hacemos nada
148
                }
149
        }
150
        
151
        /**
152
         * Se asigna el layer sobre el que trabaja el gestor de ROIs
153
         * @param layer
154
         * @throws GridException 
155
         */
156
        public void setLayer(FLayer layer) throws GridException {
157
                getROIsManagerPanel().getTablePanel().setFLayer(layer);
158
        }
159
        
160
        public void setPreviousTool(){
161
                if (previousTool!=null)
162
                        roiManagerPanel.getTablePanel().getMapControl().setTool(previousTool);
163
        }
164

    
165
        public void windowActivated() {
166
                try {
167
                        if (getROIsManagerPanel().getTablePanel().getTable().getSelectedRows().length==1){
168
                                getROIsManagerPanel().getTablePanel().setToolsEnabled(true);
169
                                getROIsManagerPanel().getTablePanel().selectDrawRoiTool();
170
                        }
171
                } catch (NotInitializeException e) {
172
                        // TODO Auto-generated catch block
173
                        e.printStackTrace();
174
                }
175
        }
176

    
177
        public void windowClosed() {
178
                /*
179
                 * Limpiar los gr?ficos de la vista:
180
                 */
181
                getROIsManagerPanel().getTablePanel().clearRoiGraphics();
182
                getROIsManagerPanel().getTablePanel().getMapControl().rePaintDirtyLayers();
183
                setPreviousTool();
184
        }
185
}