Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / SavePropsSetupPanel.java @ 2312

History | View | Annotate | Download (6.44 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.raster;
25

    
26

    
27
import java.awt.Dimension;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.event.FocusEvent;
31
import java.awt.event.FocusListener;
32
import java.awt.event.KeyEvent;
33
import java.awt.event.KeyListener;
34
import java.awt.event.MouseEvent;
35
import java.awt.event.MouseListener;
36

    
37
import javax.swing.JPanel;
38
import javax.swing.event.ChangeEvent;
39
import javax.swing.event.ChangeListener;
40

    
41
import org.cresques.io.CXMLParser;
42
import org.cresques.io.GeoRasterWriter;
43

    
44
 
45
/**
46
 * Panel que maneja los eventos de las propiedades de escritura del panel de un 
47
 * tipo de raster concreto. Estan propiedades son obtenidas desde un texto en XML 
48
 * que es generado por el driver. Este XML se pasa desde aqu? al panel que 
49
 * contendr? los elementos para su generaci?n din?mica. Dependiendo del tipo de 
50
 * driver el panel generado (DataInputProps) ser? diferente.
51
 * @author Nacho Brodin <brodin_ign@gva.es>
52
 */
53
public class SavePropsSetupPanel extends JPanel implements ActionListener, ChangeListener, MouseListener, FocusListener, KeyListener{
54
        
55
        private DataInputProps                                                         saveRaster = null;
56
        private SaveRasterPropsDialogPanel                                 dialogPanel = null;
57
        private String                                                                         fName = null;
58
        private GeoRasterWriter                                                 writer = null;
59
        private String                                                                         formato = null;
60
        private String[]                                                                properties = null;
61

    
62
        /**
63
         * Constructor 
64
         * 
65
         */
66
        public SavePropsSetupPanel() {
67
                super();
68
        }
69
        
70
        /**
71
         * Asigna el formato del fichero del que se quieren ver las propiedades
72
         * @param formato
73
         */
74
        public void setFormat(String formato){
75
                this.formato = formato;
76
                initialize();
77
        }
78
        
79
        /**
80
         * Asigna el GeoRasterFile que corresonde al driver
81
         * @param writer
82
         */
83
        public void setWriter(GeoRasterWriter writer){
84
                this.writer = writer;
85
                initialize();
86
        }
87
        
88
        /**
89
         * Inicializaci?n de la ventana
90
         * 
91
         * @return void
92
         */
93
        void initialize() {
94
                int widthPanel=350;
95
                int heightPanel=210;
96
                
97
                //Obtenemos el ancho y alto del panel interior del XML
98
                String xml = writer.getXMLPropertiesDialog();
99
                if(xml!=null){
100
                        CXMLParser parser = new CXMLParser(xml);
101
                        parser.getValue("window", true);
102
                        String w = parser.getAttr("panel","sizex");
103
                        String h = parser.getAttr("panel","sizey");
104
                        if(w!=null && !w.equals(""))
105
                                widthPanel = Integer.parseInt(w);
106
                        if(h!=null && !h.equals(""))
107
                                heightPanel = Integer.parseInt(h);
108
                }
109
        this.setPreferredSize(new Dimension(widthPanel, heightPanel)); //AnchoxAlto  panel interior
110
        this.setBounds(0, 0, 300, 250);
111
        this.setLayout(null);
112
        this.add(getSaveParameters(), null);
113
               
114
        //A?adimos gesti?n de eventos        
115
        
116
        if(saveRaster.getCombos() != null){
117
                for(int i=0;i<saveRaster.getCombos().length;i++)
118
                        saveRaster.getCombos()[i].addActionListener(this);
119
        }
120
        
121
        if(saveRaster.getSliders() != null){
122
                for(int i=0;i<saveRaster.getSliders().length;i++)
123
                        saveRaster.getSliders()[i].getSlider().addChangeListener(this);
124
        }
125
        
126
        if(saveRaster.getChecks() != null){
127
                for(int i=0;i<saveRaster.getChecks().length;i++)
128
                        saveRaster.getChecks()[i].addActionListener(this);
129
        }
130
     
131
        }
132

    
133
        /**
134
         * Asigna un valor al panel padre
135
         * @param dialogPanel
136
         */
137
        
138
        public void setDialogPanel(SaveRasterPropsDialogPanel dialogPanel){
139
                this.dialogPanel = dialogPanel; 
140
        } 
141
        
142
        /**
143
         * Obtiene el Panel de Controles interior
144
         * @return
145
         */
146
        
147
        public DataInputProps getSaveParameters() {
148
                if (saveRaster == null) {
149
                                saveRaster = new DataInputProps(writer);
150
                }
151
                return saveRaster;
152
        }
153
        
154
        
155
        
156
        /**
157
         * Controla cuando se cumplen todos los requisitos en el formulario para 
158
         * poder activar el bot?n de aceptar.
159
         *
160
         */
161
        private void enableButtons(){
162
                        
163
                if(dialogPanel!=null){
164
                        dialogPanel.getAcceptButton().setEnabled(true);
165
                }
166
                        
167
        }
168
        
169
        /**
170
         * Devuelve un vector de Strings en el que cada elemento es un par propiedad=valor
171
         * con las propiedades del driver seleccionado
172
         * @return Vector de propiedades
173
         */
174
        public String[] getProperties(){
175
                return properties;
176
        }
177
        
178
        /**
179
         * Obtiene el nuevo vector de propiedades 
180
         */
181
        public void stateChanged(ChangeEvent e){
182
                properties = saveRaster.getElements();
183
        }
184
        
185
        /**
186
         * Obtiene el nuevo vector de propiedades 
187
         */
188
        public void actionPerformed(ActionEvent e){
189
                properties = saveRaster.getElements();
190
        }
191
        
192
        /**
193
         * Devuelve el nombre del fichero seleccionado
194
         * @return Nombre del fichero seleccionado
195
         */
196
        public String getFileName(){
197
                return fName;
198
        }
199
        
200
        /**
201
         * Controla la activaci?n y desactivaci?n de los botones
202
         */
203
        public void mouseClicked(MouseEvent e){        
204
                enableButtons();
205
        }
206
        
207
        /**
208
         * Controla la activaci?n y desactivaci?n de los botones
209
         */
210
        public void focusLost(FocusEvent e){
211
                enableButtons();
212
        }
213
        
214
        /**
215
         * Controla la activaci?n y desactivaci?n de los botones
216
         */
217
        public void keyTyped(KeyEvent e){
218
                enableButtons();
219
        }
220
        
221
        /**
222
         * Controla la activaci?n y desactivaci?n de los botones
223
         */
224
        public void keyPressed(KeyEvent e){
225
                enableButtons();
226
        }
227
        
228
        /**
229
         * Controla la activaci?n y desactivaci?n de los botones
230
         */
231
        public void keyReleased(KeyEvent e){
232
                enableButtons();
233
        }
234
        
235
        /**
236
         * Unused. Only for compilant purposes
237
         */
238
        public void mouseExited(MouseEvent e){}
239
        
240
        /**
241
         * Unused. Only for compilant purposes
242
         */
243
        public void mouseReleased(MouseEvent e){}
244
        
245
        /**
246
         * Unused. Only for compilant purposes
247
         */
248
        public void mouseEntered(MouseEvent e){}
249
        
250
        /**
251
         * Unused. Only for compilant purposes
252
         */
253
        public void mousePressed(MouseEvent e){}
254
        
255
        /**
256
         * Unused. Only for compilant purposes
257
         */
258
        public void focusGained(FocusEvent e){}
259
 }  
260

    
261