Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / raw / ui / main / OpenRawFileControlsPanel.java @ 13957

History | View | Annotate | Download (6.17 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.raw.ui.main;
20

    
21
import java.awt.GridBagConstraints;
22
import java.awt.GridBagLayout;
23
import java.io.File;
24

    
25
import javax.swing.JPanel;
26

    
27
import org.gvsig.gui.beans.openfile.OpenFileContainer;
28
import org.gvsig.rastertools.raw.tools.VRTFormatOptions;
29
/**
30
 * This class contains all the components of a open raw file
31
 * panel. It doesn't has the main buttons.
32
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
33
 */
34
public class OpenRawFileControlsPanel extends JPanel {
35
  private static final long serialVersionUID = 6493641545774147712L;
36
        private final int               PANELS_WIDTH            = 510;
37
        private OpenFileContainer       openFilePanel           = null;
38
        private GeometryPropertiesPanel geometryPropertiesPanel = null;
39
        private OutputHeaderFormatPanel outputHeaderFormatPanel = null;
40
        private boolean                 calculateFileSize       = true;
41

    
42
        /**
43
         * Constructor
44
         * @param rawFileName
45
         * Raw file name
46
         */
47
        public OpenRawFileControlsPanel(String rawFileName) {
48
                super();
49
                initialize();
50
                openFilePanel.getTOpen().setText(rawFileName);
51
        }
52

    
53
        /**
54
         * This method initializes this
55
         * 
56
         */
57
        private void initialize() {
58
                GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
59
                gridBagConstraints2.insets = new java.awt.Insets(5, 0, 5, 0);
60
                gridBagConstraints2.gridy = 2;
61
                gridBagConstraints2.gridx = 0;
62
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
63
                gridBagConstraints1.insets = new java.awt.Insets(5, 0, 5, 0);
64
                gridBagConstraints1.gridy = 1;
65
                gridBagConstraints1.gridx = 0;
66
                GridBagConstraints gridBagConstraints = new GridBagConstraints();
67
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
68
                gridBagConstraints.gridy = 0;
69
                gridBagConstraints.gridx = 0;
70
                this.setLayout(new GridBagLayout());
71
                this.add(getOpenFilePanel(), gridBagConstraints);
72
                this.add(getGeometryPropertiesPanel(), gridBagConstraints1);
73
                this.add(getOutputHeaderFormatPanel(), gridBagConstraints2);
74
                new CalculateFileSize();
75
        }
76

    
77
        /**
78
         * This method initializes openFilePanel        
79
         *         
80
         * @return javax.swing.JPanel        
81
         */
82
        private OpenFileContainer getOpenFilePanel() {
83
                if (openFilePanel == null) {
84
                        openFilePanel = new OpenFileContainer(PANELS_WIDTH, 50, false);
85
                        openFilePanel.setPreferredSize(new java.awt.Dimension(PANELS_WIDTH, 50));
86
                }
87
                return openFilePanel;
88
        }
89

    
90
        /**
91
         * This method initializes geometryPropertiesPanel        
92
         *         
93
         * @return javax.swing.JPanel        
94
         */
95
        private GeometryPropertiesPanel getGeometryPropertiesPanel() {
96
                if (geometryPropertiesPanel == null) {
97
                        geometryPropertiesPanel = new GeometryPropertiesPanel();
98
                }
99
                return geometryPropertiesPanel;
100
        }
101

    
102
        /**
103
         * This method initializes outputHeaderFormatPanel        
104
         *         
105
         * @return javax.swing.JPanel        
106
         */
107
        private OutputHeaderFormatPanel getOutputHeaderFormatPanel() {
108
                if (outputHeaderFormatPanel == null) {
109
                        outputHeaderFormatPanel = new OutputHeaderFormatPanel();
110
                }
111
                return outputHeaderFormatPanel;
112
        }
113

    
114
        /**
115
         * Sets the file size into the text field
116
         * @param fileSize
117
         */
118
        public void setFileSize(int fileSize) {
119
                getGeometryPropertiesPanel().setFileSize(fileSize);
120
        }
121

    
122
        /**
123
         * Gets the data type
124
         * @return
125
         */
126
        public VRTFormatOptions.UIOption getDataType() {
127
                return getGeometryPropertiesPanel().getDataType();
128
        }
129

    
130
        /**
131
         * Gets the byte order
132
         * @return
133
         */
134
        public String getByteOrder() {
135
                return getGeometryPropertiesPanel().getByteOrder();
136
        }
137

    
138
        /**
139
         * Gets the type of interleaving
140
         * @return
141
         */
142
        public String getInterleaving() {
143
                return getGeometryPropertiesPanel().getInterleaving();
144
        }
145

    
146
        /**
147
         * gets the image width
148
         * @return
149
         */
150
        public int getImageWidth() {
151
                return getGeometryPropertiesPanel().getImageWidth();
152
        }
153

    
154
        /**
155
         * gets the image height
156
         * @return
157
         */
158
        public int getImageHeight() {
159
                return getGeometryPropertiesPanel().getImageHeight();
160
        }
161

    
162
        /**
163
         * gets the number of bands
164
         * @return
165
         */
166
        public int getNumberOfBands() {
167
                return getGeometryPropertiesPanel().getNumberOfBands();
168
        }
169

    
170
        /**
171
         * gets the header size
172
         * @return
173
         */
174
        public int getHeaderSize() {
175
                return getGeometryPropertiesPanel().getHeaderSize();
176
        }
177

    
178
        /**
179
         * gets the selected outputformat
180
         * @return
181
         */
182
        public String getOutputHeaderFormat() {
183
                return getOutputHeaderFormatPanel().getOutputHeaderFormat();
184
        }
185

    
186
        /**
187
         * Gets the RAW file
188
         * @return
189
         */
190
        public File getFile() {
191
                return getOpenFilePanel().getFile();
192
        }
193

    
194
        /**
195
         * This method is used by the listener to stop the
196
         * thread that calculates the file size
197
         *
198
         */
199
        public void stopThread() {
200
                calculateFileSize = false;
201
        }
202

    
203
        /**
204
         * This class is a thread that try if the textbox (where
205
         * the file to open is written) contains a valid file and
206
         * calculate its size.
207
         * @author Jorge Piera Llodr? (piera_jor@gva.es)
208
         */
209
        public class CalculateFileSize implements Runnable {
210
                volatile Thread myThread = null;
211

    
212
                public CalculateFileSize() {
213
                        if (myThread == null) {
214
                                myThread = new Thread(this);
215
                                myThread.start();
216
                        }
217
                }
218

    
219
                /*
220
                 *  (non-Javadoc)
221
                 * @see java.lang.Runnable#run()
222
                 */
223
                public void run() {
224
                        while (calculateFileSize) {
225
                                File file = getFile();
226
                                if ((file.exists() && (file.isFile()))) {
227
                                        getGeometryPropertiesPanel().setFileSize(file.length());
228
                                } else {
229
                                        getGeometryPropertiesPanel().setFileSize(0);
230
                                }
231
                                try {
232
                                        Thread.sleep(1000);
233
                                } catch (InterruptedException e) {
234
                                        // TODO Auto-generated catch block
235
                                        e.printStackTrace();
236
                                }
237
                        }
238
                }
239
        }
240
}