gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / raw / ui / listener / OpenRawFileDefaultViewListener.java @ 2340
History | View | Annotate | Download (3.63 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.tools.app.basic.tool.raw.ui.listener; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.io.IOException; |
28 |
|
29 |
import javax.swing.JOptionPane; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
33 |
import org.gvsig.raster.tools.app.basic.tool.raw.tool.VRTFileCreator; |
34 |
import org.gvsig.raster.tools.app.basic.tool.raw.ui.main.OpenRawFileControlsPanel; |
35 |
import org.gvsig.raster.tools.app.basic.tool.raw.ui.main.OpenRawFileDefaultView; |
36 |
|
37 |
/**
|
38 |
* Listener for the open raw file window. It implements actions for the "open
|
39 |
* file" and for the "close window" buttons.
|
40 |
*
|
41 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
42 |
*/
|
43 |
public class OpenRawFileDefaultViewListener implements ActionListener { |
44 |
private OpenRawFileDefaultView openRawView = null; |
45 |
|
46 |
/**
|
47 |
* Contructor
|
48 |
* @param view Open raw file view
|
49 |
*/
|
50 |
public OpenRawFileDefaultViewListener(OpenRawFileDefaultView view) {
|
51 |
super();
|
52 |
this.openRawView = view;
|
53 |
} |
54 |
|
55 |
/*
|
56 |
* (non-Javadoc)
|
57 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
58 |
*/
|
59 |
public void actionPerformed(ActionEvent event) { |
60 |
if (event.getActionCommand() == "close") { |
61 |
closeButtonActionPerformed(); |
62 |
} else
|
63 |
if (event.getActionCommand() == "open") { |
64 |
openButtonActionPerformed(); |
65 |
} |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Open raw file button action
|
70 |
*/
|
71 |
private void openButtonActionPerformed() { |
72 |
OpenRawFileControlsPanel controls = openRawView.getControlsPanel(); |
73 |
if (!(controls.getFile().exists())) {
|
74 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "file_doesn_exists")); |
75 |
return;
|
76 |
} |
77 |
if (controls.getOutputHeaderFormat().equals("VRT")) { |
78 |
String vrtFileName = controls.getFile().getAbsolutePath().replaceAll("\\.raw", ".vrt"); |
79 |
VRTFileCreator vrt = new VRTFileCreator(vrtFileName);
|
80 |
vrt.setImageWidth(controls.getImageWidth()); |
81 |
vrt.setImageHeight(controls.getImageHeight()); |
82 |
vrt.setBands(controls.getNumberOfBands()); |
83 |
vrt.setHeaderSize(controls.getHeaderSize()); |
84 |
vrt.setDataType(controls.getDataType().getVrtOptionName()); |
85 |
vrt.setDataSize(controls.getDataType().getDataSize()); |
86 |
vrt.setByteOrder(controls.getByteOrder()); |
87 |
vrt.setInterleaving(controls.getInterleaving()); |
88 |
vrt.setRawFile(controls.getFile().getName()); |
89 |
try {
|
90 |
vrt.writeFile(); |
91 |
openRawView.setImageFile(vrt.getM_File()); |
92 |
} catch (IOException e) { |
93 |
RasterSwingLibrary.messageBoxError("cant_create_vrt_file", this, e); |
94 |
} |
95 |
} |
96 |
closeButtonActionPerformed(); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* Close window
|
101 |
*/
|
102 |
private void closeButtonActionPerformed() { |
103 |
OpenRawFileControlsPanel controls = openRawView.getControlsPanel(); |
104 |
controls.stopThread(); |
105 |
PluginServices.getMDIManager().closeWindow(openRawView); |
106 |
} |
107 |
} |