Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / saveraster / ui / info / EndInfoPanel.java @ 21684

History | View | Annotate | Download (10 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2007 IVER T.I. 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
package org.gvsig.rastertools.saveraster.ui.info;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.CardLayout;
23
import java.awt.Color;
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.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.io.File;
32

    
33
import javax.swing.BorderFactory;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JTextField;
37
import javax.swing.border.TitledBorder;
38

    
39
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
40
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
41
import org.gvsig.raster.util.RasterUtilities;
42

    
43
import com.iver.andami.PluginServices;
44
import com.iver.utiles.swing.JComboBox;
45
/**
46
 * Panel principal del dialogo de finalizaci?n del salvado a raster. En el se
47
 * muestra la informaci?n de nombre de fichero, tama?o de este, tiempo de la
48
 * operaci?n, etc...
49
 *
50
 * @version 18/04/2007
51
 * @author Nacho Brodin (nachobrodin@gmail.com)
52
 */
53
public class EndInfoPanel extends DefaultButtonsPanel implements ActionListener {
54
        private static final long        serialVersionUID        = -2280318605043767336L;
55
        private JPanel contentPane = null;
56
        private JComboBox comboBox = null;
57

    
58
        private String labelFilename = "File:";
59
        private String labelPath = "Path:";
60
        private String labelTime = "Time:";
61
        private String labelSize = "Size:";
62
        private String labelCompression = "Compression:";
63

    
64
        /**
65
         * This is the default constructor
66
         */
67
        protected EndInfoPanel() {
68
                super(ButtonsPanel.BUTTONS_ACCEPT);
69
                setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
70
                initialize();
71
                setTranslation();
72
        }
73

    
74
        /**
75
         * Asigna los textos a los paneles en el idioma seleccionado
76
         */
77
        private void setTranslation() {
78
                setLabelFilename(PluginServices.getText(this, "file") + ":");
79
                setLabelPath(PluginServices.getText(this, "path") + ":");
80
                setLabelSize(PluginServices.getText(this, "size") + ":");
81
                setLabelTime(PluginServices.getText(this, "time") + ":");
82
                setLabelCompression(PluginServices.getText(this, "compress") + ":");
83
        }
84

    
85
        protected void addFile(String fileName, long time) {
86
                File f = new File(fileName);
87
                String size = RasterUtilities.formatFileSize(f.length());
88

    
89
                String compression;
90
                if (fileName.endsWith("ecw") || fileName.endsWith("jp2") ||
91
                                fileName.endsWith("jpg") || fileName.endsWith("jpeg")) {
92
                        compression = "Yes";
93
                } else {
94
                        compression = "No";
95
                }
96
                
97
                JPanel pContent = new JPanel();
98
                pContent.setLayout(new GridBagLayout());
99

    
100
                GridBagConstraints gridBagConstraints;
101
                gridBagConstraints = new GridBagConstraints();
102
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
103
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
104
                pContent.add(newPanelFile(fileName), gridBagConstraints);
105

    
106
                gridBagConstraints = new GridBagConstraints();
107
                gridBagConstraints.gridx = 0;
108
                gridBagConstraints.gridy = 1;
109
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
110
                gridBagConstraints.insets = new Insets(2, 5, 2, 5);
111
                pContent.add(newPanelTimeSize(RasterUtilities.formatTime(time), size), gridBagConstraints);
112

    
113
                gridBagConstraints = new GridBagConstraints();
114
                gridBagConstraints.gridx = 0;
115
                gridBagConstraints.gridy = 2;
116
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
117
                gridBagConstraints.insets = new Insets(2, 5, 5, 5);
118
                pContent.add(newPanelCompression(compression), gridBagConstraints);
119

    
120
                gridBagConstraints = new GridBagConstraints();
121
                gridBagConstraints.gridx = 0;
122
                gridBagConstraints.gridy = 4;
123
                gridBagConstraints.weightx = 1.0;
124
                gridBagConstraints.weighty = 1.0;
125
                JPanel emptyPanel = new JPanel();
126
                emptyPanel.setPreferredSize(new Dimension(0, 0));
127
                pContent.add(emptyPanel, gridBagConstraints);
128

    
129
                pContent.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray, 1), "Estadisticas",
130
                                TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
131

    
132
                File file = new File(fileName);
133
                
134
                contentPane.add(pContent, file.getName());
135
                if (comboBox.getItemCount() == 0)
136
                        comboBox.setVisible(false);
137
                else
138
                        comboBox.setVisible(true);
139
                comboBox.addItem(file.getName());
140
        }
141

    
142
        /**
143
         * This method initializes this
144
         * @return void
145
         */
146
        private void initialize() {
147
                setLayout(new BorderLayout(5, 5));
148

    
149
                contentPane = new JPanel();
150
                contentPane.setLayout(new CardLayout());
151
                
152
                comboBox = new JComboBox();
153
                comboBox.setVisible(false);
154
                comboBox.addActionListener(this);
155
                
156
                this.add(contentPane, BorderLayout.CENTER);
157
                this.add(comboBox, BorderLayout.SOUTH);
158
        }
159

    
160
        /**
161
         * This method initializes jPanel
162
         *
163
         * @return javax.swing.JPanel
164
         */
165
        private JPanel newPanelFile(String file) {
166
                JLabel lFileNameTag = new JLabel(labelFilename);
167
                JLabel lPathTag = new JLabel(labelPath);
168

    
169
                File fileorig = new File(file);
170

    
171
                JTextField tFile = new JTextField(fileorig.getName());
172
                tFile.setBackground(new Color(236, 233, 216));
173
                tFile.setEditable(false);
174
                tFile.setHorizontalAlignment(JTextField.LEFT);
175
                tFile.setBorder(null);
176
                
177
                JTextField pathFile = new JTextField(fileorig.getParent() + File.separator);
178
                pathFile.setBackground(new Color(236, 233, 216));
179
                pathFile.setEditable(false);
180
                pathFile.setHorizontalAlignment(JTextField.LEFT);
181
                pathFile.setBorder(null);
182
                
183
                JPanel pFile = new JPanel();
184
                pFile.setLayout(new GridBagLayout());
185
                
186
                GridBagConstraints gridBagConstraints;
187
                gridBagConstraints = new GridBagConstraints();
188
                gridBagConstraints.gridx = 0;
189
                gridBagConstraints.gridy = 0;
190
                gridBagConstraints.anchor = GridBagConstraints.WEST;
191
                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
192
                pFile.add(lFileNameTag, gridBagConstraints);
193

    
194
                gridBagConstraints = new GridBagConstraints();
195
                gridBagConstraints.gridx = 1;
196
                gridBagConstraints.gridy = 0;
197
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
198
                gridBagConstraints.anchor = GridBagConstraints.WEST;
199
                gridBagConstraints.weightx = 1.0;
200
                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
201
                pFile.add(tFile, gridBagConstraints);
202
                
203
                gridBagConstraints = new GridBagConstraints();
204
                gridBagConstraints.gridx = 0;
205
                gridBagConstraints.gridy = 1;
206
                gridBagConstraints.anchor = GridBagConstraints.WEST;
207
                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
208
                pFile.add(lPathTag, gridBagConstraints);
209

    
210
                gridBagConstraints = new GridBagConstraints();
211
                gridBagConstraints.gridx = 1;
212
                gridBagConstraints.gridy = 1;
213
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
214
                gridBagConstraints.anchor = GridBagConstraints.WEST;
215
                gridBagConstraints.weightx = 1.0;
216
                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
217
                pFile.add(pathFile, gridBagConstraints);
218

    
219
                
220
                return pFile;
221
        }
222

    
223
        /**
224
         * This method initializes jPanel1
225
         *
226
         * @return javax.swing.JPanel
227
         */
228
        private JPanel newPanelTimeSize(String time, String size) {
229
                JPanel pTime = new JPanel();
230
                pTime.setLayout(new GridBagLayout());
231

    
232
                JLabel lTimeTag = new JLabel(labelTime);
233
                GridBagConstraints gridBagConstraints;
234
                gridBagConstraints = new java.awt.GridBagConstraints();
235
                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
236
                gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 2);
237
                pTime.add(lTimeTag, gridBagConstraints);
238

    
239
                JLabel lTime = new JLabel(time);
240
                gridBagConstraints = new java.awt.GridBagConstraints();
241
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
242
                gridBagConstraints.weightx = 1.0;
243
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 11);
244
                pTime.add(lTime, gridBagConstraints);
245

    
246
                JLabel lSizeTag = new JLabel(labelSize);
247
                gridBagConstraints = new java.awt.GridBagConstraints();
248
                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
249
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 11);
250
                pTime.add(lSizeTag, gridBagConstraints);
251

    
252
                JLabel lSize = new JLabel(size);
253
                gridBagConstraints = new java.awt.GridBagConstraints();
254
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
255
                gridBagConstraints.weightx = 1.0;
256
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 5);
257
                pTime.add(lSize, gridBagConstraints);
258

    
259
                return pTime;
260
        }
261

    
262
        /**
263
         * This method initializes jPanel
264
         *
265
         * @return javax.swing.JPanel
266
         */
267
        private JPanel newPanelCompression(String compression) {
268
                JPanel pCompression = new JPanel();
269

    
270
                JLabel lCompressTag = new JLabel(labelCompression);
271
                JLabel lCompress = new JLabel(compression);
272

    
273
                pCompression.setLayout(new FlowLayout(FlowLayout.LEFT));
274
                pCompression.add(lCompressTag);
275
                pCompression.add(lCompress);
276

    
277
                return pCompression;
278
        }
279

    
280
        /**
281
         * @param labelFilename the labelFilename to set
282
         */
283
        private void setLabelFilename(String labelFilename) {
284
                this.labelFilename = labelFilename;
285
        }
286

    
287
        /**
288
         * @param labelFilename the labelFilename to set
289
         */
290
        private void setLabelPath(String labelPath) {
291
                this.labelPath = labelPath;
292
        }
293

    
294
        /**
295
         * @param labelTime the labelTime to set
296
         */
297
        private void setLabelTime(String labelTime) {
298
                this.labelTime = labelTime;
299
        }
300

    
301
        /**
302
         * @param labelSize the labelSize to set
303
         */
304
        private void setLabelSize(String labelSize) {
305
                this.labelSize = labelSize;
306
        }
307

    
308
        /**
309
         * @param labelCompression the labelCompression to set
310
         */
311
        private void setLabelCompression(String labelCompression) {
312
                this.labelCompression = labelCompression;
313
        }
314

    
315
        public void actionPerformed(ActionEvent e) {
316
                if (e.getSource() == comboBox)
317
                        ((CardLayout) contentPane.getLayout()).show(contentPane, (String) comboBox.getSelectedItem());
318
        }
319
}