Statistics
| Revision:

gvsig-raster / org.gvsig.raster.mosaic / trunk / org.gvsig.raster.mosaic / org.gvsig.raster.mosaic.app / src / main / java / org / gvsig / raster / mosaic / app / gui / MosaicPropertiesPanel.java @ 723

History | View | Annotate | Download (9.68 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.mosaic.app.gui;
23

    
24
import java.awt.Dimension;
25
import java.awt.FlowLayout;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
29
import java.io.File;
30
import java.util.ArrayList;
31

    
32
import javax.swing.BorderFactory;
33
import javax.swing.ButtonGroup;
34
import javax.swing.JButton;
35
import javax.swing.JCheckBox;
36
import javax.swing.JPanel;
37
import javax.swing.JRadioButton;
38
import javax.swing.JScrollPane;
39
import javax.swing.JTable;
40
import javax.swing.table.TableColumnModel;
41

    
42
import org.gvsig.andami.PluginServices;
43
import org.gvsig.fmap.dal.DataStoreParameters;
44
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
45
import org.gvsig.raster.fmap.layers.FLyrRaster;
46
import org.gvsig.raster.impl.provider.RasterProvider;
47
import org.gvsig.raster.mosaic.io.MosaicDataParameters;
48
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
49

    
50
/**
51
 * 
52
 * @author Nacho Brodin (nachobrodin@gmail.com)
53
 */
54
public class MosaicPropertiesPanel extends AbstractPanel {
55
        private static final long            serialVersionUID       = 1L;
56
        private final String[]               columnNames            = { "", "Fichero" };
57
        private FileListTableModel           model                  = null;
58
        private MosaicPropertiesListener     listener               = null;
59

    
60
        private JButton                      addButton              = null;
61
        private JButton                      createButton           = null;
62
        private JButton                      deleteButton           = null;
63
        private JButton                      optionsModifyButton    = null;
64
        
65
        private JCheckBox                    seeListCheck           = null;
66
        
67
        private JRadioButton                 addDirectoryRadio      = null;
68
        private JRadioButton                 addFilesRadio          = null;
69
        private ButtonGroup                  radioGroup             = null;
70
        
71
        private JPanel                       createPanel            = null;
72
        private JPanel                       optionsPanel           = null;
73
        private JPanel                       southPanel             = null;
74
        private JPanel                       buttonsPanel           = null;
75
        private JTable                       table                  = null;
76
        private JScrollPane                  scrollPanel            = null;
77
        
78
        private FLyrRaster                   fLayer                 = null;
79
        
80
        /**
81
         * This method initializes
82
         */
83
        public MosaicPropertiesPanel() {
84
                super();
85
                initialize();
86
                listener = new MosaicPropertiesListener(this);
87
                this.setPreferredSize(new Dimension(100, 80)); 
88
                super.setLabel(PluginServices.getText(this, "mosaic_panel"));
89
        }
90
        
91
        @Override
92
        protected void initialize() {
93
                setLayout(new GridBagLayout());
94
                
95
                GridBagConstraints gbc = new GridBagConstraints();
96
                gbc.insets = new Insets(0, 0, 0, 0);
97
                gbc.fill = GridBagConstraints.BOTH;
98
                gbc.weightx = 1.0;
99
                gbc.weighty = 1.0;
100
                
101
                add(getScrollTable(), gbc);
102
                
103
                gbc.fill = GridBagConstraints.HORIZONTAL;
104
                gbc.weighty = 0.0;
105
                
106
                gbc.gridy = 1;
107
                add(getSouthPanel(), gbc);
108
                
109
                getRadioGroup();
110
                setCreateStatus();
111
        }
112

    
113
        /*
114
         * (non-Javadoc)
115
         * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
116
         */
117
        public void setReference(Object ref) {
118
                super.setReference(ref);
119

    
120
                if (!(ref instanceof FLyrRaster))
121
                        return;
122

    
123
                fLayer = (FLyrRaster) ref;
124
                DataStoreParameters dsp = fLayer.getDataStore().getParameters();
125
                if(dsp instanceof MosaicDataParameters) {
126
                        MosaicDataParameters mosaicParams = (MosaicDataParameters)dsp;
127
                        ArrayList<RasterProvider> provList = mosaicParams.getProviders();
128
                        getModel().clearModel();
129
                        ArrayList<File> fileArray = new ArrayList<File>();
130
                        for (int i = 0; i < provList.size(); i++) {
131
                                fileArray.add(new File(provList.get(i).getURI()));
132
                        }
133
                        listener.addData(fileArray);
134
                }
135
        }
136

    
137
        public JButton getAddButton() {
138
                if(addButton == null) {
139
                        addButton = new JButton(RasterToolsUtil.getText(this, "add"));
140
                        addButton.setPreferredSize(new Dimension(80, 24));
141
                }
142
                return addButton;
143
        }
144

    
145
        public JButton getCreateButton() {
146
                if(createButton == null) {
147
                        createButton = new JButton(RasterToolsUtil.getText(this, "create"));
148
                        createButton.setPreferredSize(new Dimension(80, 24));
149
                }
150
                return createButton;
151
        }
152
        
153
        public JButton getDeleteButton() {
154
                if(deleteButton == null) {
155
                        deleteButton = new JButton(RasterToolsUtil.getText(this, "delete"));
156
                        deleteButton.setPreferredSize(new Dimension(80, 24));
157
                }
158
                return deleteButton;
159
        }
160

    
161
        public JButton getOptionsModifyButton() {
162
                if(optionsModifyButton == null) {
163
                        optionsModifyButton = new JButton(RasterToolsUtil.getText(this, "modify_options"));
164
                }
165
                return optionsModifyButton;
166
        }
167

    
168
        public JCheckBox getSeeListCheck() {
169
                if(seeListCheck == null) {
170
                        seeListCheck = new JCheckBox(RasterToolsUtil.getText(this, "see_path"));
171
                }
172
                return seeListCheck;
173
        }
174
        
175
        public JRadioButton getAddDirectoryRadio() {
176
                if(addDirectoryRadio == null) {
177
                        addDirectoryRadio = new JRadioButton(RasterToolsUtil.getText(this, "add_directory"));
178
                        addDirectoryRadio.setSelected(false);
179
                }
180
                return addDirectoryRadio;
181
        }
182

    
183
        public JRadioButton getAddFilesRadio() {
184
                if(addFilesRadio == null) {
185
                        addFilesRadio = new JRadioButton(RasterToolsUtil.getText(this, "add_files"));
186
                        addFilesRadio.setSelected(true);
187
                }
188
                return addFilesRadio;
189
        }
190

    
191
        public ButtonGroup getRadioGroup() {
192
                if(radioGroup == null) {
193
                        radioGroup = new ButtonGroup();
194
                        radioGroup.add(getAddDirectoryRadio());
195
                        radioGroup.add(getAddFilesRadio());
196
                }
197
                return radioGroup;
198
        }
199

    
200
        public JPanel getCreatePanel() {
201
                if(createPanel == null) {
202
                        createPanel = new JPanel();
203
                        createPanel.setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "create_mosaic")));
204
                        createPanel.setLayout(new GridBagLayout());
205
                        
206
                        GridBagConstraints gbc = new GridBagConstraints();
207
                        gbc.insets = new Insets(0, 0, 0, 0);
208
                        gbc.fill = GridBagConstraints.BOTH;
209
                        gbc.weightx = 1.0;
210
                        gbc.weighty = 1.0;
211
                        
212
                        gbc.gridy = 0;
213
                        createPanel.add(getAddFilesRadio(), gbc);
214
                        gbc.gridy = 1;
215
                        createPanel.add(getAddDirectoryRadio(), gbc);
216
                        
217
                        gbc.fill = GridBagConstraints.HORIZONTAL;
218
                        gbc.weightx = 1.0;
219
                        gbc.weighty = 0.0;
220
                        
221
                        gbc.gridy = 2;
222
                        createPanel.add(getButtonsPanel(), gbc);
223
                        
224
                }
225
                return createPanel;
226
        }
227
        
228
        public JPanel getButtonsPanel() {
229
                if(buttonsPanel == null) {
230
                        buttonsPanel = new JPanel();
231
                        buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
232
                        buttonsPanel.add(getAddButton());
233
                        buttonsPanel.add(getCreateButton());
234
                        buttonsPanel.add(getDeleteButton());
235
                }
236
                return buttonsPanel;
237
        }
238

    
239

    
240
        public JPanel getOptionsPanel() {
241
                if(optionsPanel == null) {
242
                        optionsPanel = new JPanel();
243
                        optionsPanel.setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "options")));
244
                        optionsPanel.setLayout(new GridBagLayout());
245
                        
246
                        GridBagConstraints gbc = new GridBagConstraints();
247
                        gbc.insets = new Insets(0, 0, 0, 0);
248
                        gbc.fill = GridBagConstraints.HORIZONTAL;
249
                        gbc.weightx = 1.0;
250
                        
251
                        gbc.gridy = 0;
252
                        optionsPanel.add(getSeeListCheck(), gbc);
253
                        
254
                        gbc.gridy = 1;
255
                        optionsPanel.add(getOptionsModifyButton(), gbc);
256
                        
257
                        gbc.fill = GridBagConstraints.BOTH;
258
                        gbc.weighty = 1.0;
259
                        
260
                        gbc.gridy = 2;
261
                        optionsPanel.add(new JPanel(), gbc);
262
                }
263
                return optionsPanel;
264
        }
265
        
266
        public JPanel getSouthPanel() {
267
                if(southPanel == null) {
268
                        southPanel = new JPanel();
269
                        southPanel.setLayout(new GridBagLayout());
270
                        
271
                        GridBagConstraints gbc = new GridBagConstraints();
272
                        gbc.insets = new Insets(0, 0, 0, 0);
273
                        gbc.fill = GridBagConstraints.BOTH;
274
                        gbc.weightx = 1.0;
275
                        gbc.weighty = 1.0;
276
                        
277
                        gbc.gridx = 0;
278
                        southPanel.add(getCreatePanel(), gbc);
279
                        
280
                        gbc.gridx = 1;
281
                        southPanel.add(getOptionsPanel(), gbc);
282
                }
283
                return southPanel;
284
        }
285

    
286
        public JScrollPane getScrollTable() {
287
                if(scrollPanel == null) {
288
                        scrollPanel = new JScrollPane();
289
                        scrollPanel.setViewportView(getFileList());
290
                }
291
                return scrollPanel;
292
        }
293
        
294
        public FileListTableModel getModel() {
295
                if(model == null)
296
                        model = new FileListTableModel(columnNames, null);
297
                return model;
298
        }
299
        
300
        public JTable getFileList() {
301
                if(table == null) {
302
                        table = new JTable(getModel());
303
                        TableColumnModel columnModel = table.getColumnModel();
304
                        columnModel.getColumn(0).setMaxWidth(26);
305
                }
306
                return table;
307
        }
308

    
309
        public FLyrRaster getfLayer() {
310
                return fLayer;
311
        }
312
        
313

    
314
        /**
315
         * Enables o disables buttons
316
         */
317
        public void setCreateStatus() {
318
                if(getFileList().getModel().getRowCount() == 0) {
319
                        getAddButton().setEnabled(false);
320
                        getCreateButton().setEnabled(true);
321
                        getDeleteButton().setEnabled(false);
322
                        getOptionsModifyButton().setEnabled(false);
323
                } else {
324
                        getAddButton().setEnabled(true);
325
                        getCreateButton().setEnabled(false);
326
                        getDeleteButton().setEnabled(true);
327
                        getOptionsModifyButton().setEnabled(true);
328
                }
329
        }
330

    
331
        public void accept() {
332
                listener.accept();
333
        }
334

    
335
        public void apply() {
336
                listener.apply();
337
        }
338

    
339
        public void cancel() {
340
                listener.cancel();
341
        }
342

    
343
        public void selected() {
344
                listener.selected();
345
        }
346
        
347
        
348
}