gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.algorithm / org.gvsig.raster.tools.algorithm.swing / org.gvsig.raster.tools.algorithm.swing.impl / src / main / java / org / gvsig / raster / tools / algorithm / swing / impl / layerdatatype / LayerDatatypePanelImpl.java @ 2101
History | View | Annotate | Download (7.71 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.algorithm.swing.impl.layerdatatype; |
23 |
|
24 |
import java.awt.GridBagConstraints; |
25 |
import java.awt.GridBagLayout; |
26 |
import java.io.File; |
27 |
import java.util.EventListener; |
28 |
|
29 |
import javax.swing.BorderFactory; |
30 |
import javax.swing.JComboBox; |
31 |
import javax.swing.JComponent; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
|
35 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
36 |
import org.gvsig.i18n.Messages; |
37 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
38 |
import org.gvsig.raster.algorithm.process.ProcessException; |
39 |
import org.gvsig.raster.algorithm.process.DataProcess; |
40 |
import org.gvsig.raster.swing.RasterSwingLocator; |
41 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
42 |
import org.gvsig.raster.tools.algorithm.layerdatatype.LayerDatatypeProcess; |
43 |
|
44 |
/**
|
45 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
46 |
*/
|
47 |
public class LayerDatatypePanelImpl extends JPanel implements BasicAPISwingPanel { |
48 |
private static final long serialVersionUID = 1L; |
49 |
private JComboBox comboOutput = null; |
50 |
private JComboBox comboDec2Int = null; |
51 |
private JComboBox comboBig2Small = null; |
52 |
private String inputDatatype = null; |
53 |
private String layerName = null; |
54 |
private CreateNewLayerPanel newLayerPanel = null; |
55 |
private Object inputStore = null; |
56 |
|
57 |
public LayerDatatypePanelImpl(Object inputStore, String inputDatatype, String layerName) { |
58 |
this.inputStore = inputStore;
|
59 |
this.layerName = layerName;
|
60 |
this.inputDatatype = inputDatatype;
|
61 |
init(); |
62 |
} |
63 |
|
64 |
private void init() { |
65 |
setLayout(new GridBagLayout()); |
66 |
|
67 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
68 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
69 |
gridBagConstraints1.weightx = 1;
|
70 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0); |
71 |
gridBagConstraints1.gridx = 0;
|
72 |
gridBagConstraints1.gridy = 0;
|
73 |
add(getLayerPanel(), gridBagConstraints1); |
74 |
|
75 |
gridBagConstraints1.gridy = 1;
|
76 |
add(getInputsPanel(), gridBagConstraints1); |
77 |
|
78 |
gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 2); |
79 |
gridBagConstraints1.gridy = 2;
|
80 |
add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1);
|
81 |
|
82 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
83 |
gridBagConstraints1.weighty = 1;
|
84 |
gridBagConstraints1.gridy = 3;
|
85 |
add(new JPanel(), gridBagConstraints1); |
86 |
} |
87 |
|
88 |
private JPanel getLayerPanel() { |
89 |
JPanel p = new JPanel(); |
90 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("layer"))); |
91 |
p.setLayout(new GridBagLayout()); |
92 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
93 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
94 |
gridBagConstraints1.weightx = 1;
|
95 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0); |
96 |
|
97 |
gridBagConstraints1.gridx = 0;
|
98 |
gridBagConstraints1.gridy = 0;
|
99 |
p.add(new JLabel(layerName), gridBagConstraints1); |
100 |
|
101 |
return p;
|
102 |
} |
103 |
|
104 |
private JPanel getInputsPanel() { |
105 |
JPanel p = new JPanel(); |
106 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("datatype"))); |
107 |
p.setLayout(new GridBagLayout()); |
108 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
109 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
110 |
gridBagConstraints1.weightx = 1;
|
111 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0); |
112 |
|
113 |
gridBagConstraints1.gridx = 0;
|
114 |
gridBagConstraints1.gridy = 0;
|
115 |
p.add(new JLabel(Messages.getText("entrada")), gridBagConstraints1); |
116 |
|
117 |
gridBagConstraints1.gridx = 1;
|
118 |
gridBagConstraints1.gridy = 0;
|
119 |
p.add(new JLabel(inputDatatype), gridBagConstraints1); |
120 |
|
121 |
gridBagConstraints1.gridx = 0;
|
122 |
gridBagConstraints1.gridy = 1;
|
123 |
p.add(new JLabel(Messages.getText("salida")), gridBagConstraints1); |
124 |
|
125 |
gridBagConstraints1.gridx = 1;
|
126 |
gridBagConstraints1.gridy = 1;
|
127 |
p.add(getComboOutput(), gridBagConstraints1); |
128 |
|
129 |
gridBagConstraints1.gridx = 0;
|
130 |
gridBagConstraints1.gridy = 2;
|
131 |
p.add(new JLabel(Messages.getText("adjust_dec2int")), gridBagConstraints1); |
132 |
|
133 |
gridBagConstraints1.gridx = 1;
|
134 |
gridBagConstraints1.gridy = 2;
|
135 |
p.add(getComboDec2Int(), gridBagConstraints1); |
136 |
|
137 |
gridBagConstraints1.gridx = 0;
|
138 |
gridBagConstraints1.gridy = 3;
|
139 |
p.add(new JLabel(Messages.getText("adjust_big2small")), gridBagConstraints1); |
140 |
|
141 |
gridBagConstraints1.gridx = 1;
|
142 |
gridBagConstraints1.gridy = 3;
|
143 |
p.add(getComboBig2Small(), gridBagConstraints1); |
144 |
|
145 |
return p;
|
146 |
} |
147 |
|
148 |
public JComponent getComponent() { |
149 |
return this; |
150 |
} |
151 |
|
152 |
public DataProcess getResult() throws ProcessException { |
153 |
DataProcess task = new LayerDatatypeProcess();
|
154 |
task.addParam(LayerDatatypeProcess.RASTER_STORE1, inputStore); |
155 |
String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected(); |
156 |
if(!filename.endsWith(".tif")) |
157 |
filename += ".tif";
|
158 |
task.addParam(LayerDatatypeProcess.PATH, filename); |
159 |
task.addParam(LayerDatatypeProcess.DATATYPE, getDatatypeFromCombo()); |
160 |
task.addParam(LayerDatatypeProcess.ADJUST_DEC2INT, getComboDec2Int().getSelectedIndex()); |
161 |
task.addParam(LayerDatatypeProcess.ADJUST_BIG2SMALL, getComboBig2Small().getSelectedIndex()); |
162 |
return task;
|
163 |
} |
164 |
|
165 |
public JComboBox getComboOutput() { |
166 |
if(comboOutput == null) { |
167 |
comboOutput = new JComboBox(); |
168 |
comboOutput.addItem("BYTE");
|
169 |
comboOutput.addItem("SHORT");
|
170 |
comboOutput.addItem("INT");
|
171 |
comboOutput.addItem("FLOAT");
|
172 |
comboOutput.addItem("DOUBLE");
|
173 |
} |
174 |
return comboOutput;
|
175 |
} |
176 |
|
177 |
private int getDatatypeFromCombo() { |
178 |
String item = (String)getComboOutput().getSelectedItem(); |
179 |
if(item.equals("BYTE")) |
180 |
return Buffer.TYPE_BYTE; |
181 |
if(item.equals("SHORT")) |
182 |
return Buffer.TYPE_SHORT; |
183 |
if(item.equals("INT")) |
184 |
return Buffer.TYPE_INT; |
185 |
if(item.equals("FLOAT")) |
186 |
return Buffer.TYPE_FLOAT; |
187 |
if(item.equals("DOUBLE")) |
188 |
return Buffer.TYPE_DOUBLE; |
189 |
return -1; |
190 |
} |
191 |
|
192 |
public JComboBox getComboDec2Int() { |
193 |
if(comboDec2Int == null) { |
194 |
comboDec2Int = new JComboBox(); |
195 |
for (int i = 0; i < LayerDatatypeProcess.DEC2INT_OPTIONS.length; i++) { |
196 |
comboDec2Int.addItem(LayerDatatypeProcess.DEC2INT_OPTIONS[i]); |
197 |
} |
198 |
} |
199 |
return comboDec2Int;
|
200 |
} |
201 |
|
202 |
public JComboBox getComboBig2Small() { |
203 |
if(comboBig2Small == null) { |
204 |
comboBig2Small = new JComboBox(); |
205 |
for (int i = 0; i < LayerDatatypeProcess.BIG2SMALL_OPTIONS.length; i++) { |
206 |
comboBig2Small.addItem(LayerDatatypeProcess.BIG2SMALL_OPTIONS[i]); |
207 |
} |
208 |
} |
209 |
return comboBig2Small;
|
210 |
} |
211 |
|
212 |
public CreateNewLayerPanel getCreateNewLayerPanel() {
|
213 |
if(newLayerPanel == null) { |
214 |
newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel(); |
215 |
//newLayerPanel = new CreateNewLayerPanelImpl(new FileNameManagementImpl());
|
216 |
} |
217 |
return newLayerPanel;
|
218 |
} |
219 |
|
220 |
public void initialize() { |
221 |
|
222 |
} |
223 |
|
224 |
public int getComponentIDByObject(Object obj) { |
225 |
return -1; |
226 |
} |
227 |
|
228 |
public void addListener(EventListener listener) { |
229 |
} |
230 |
} |