root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / modeler / parameters / FilepathPanel.java @ 83
History | View | Annotate | Download (5.37 KB)
1 |
package es.unex.sextante.gui.modeler.parameters; |
---|---|
2 |
|
3 |
import info.clearthought.layout.TableLayout; |
4 |
import info.clearthought.layout.TableLayoutConstants; |
5 |
|
6 |
import javax.swing.ComboBoxModel; |
7 |
import javax.swing.DefaultComboBoxModel; |
8 |
import javax.swing.JCheckBox; |
9 |
import javax.swing.JComboBox; |
10 |
import javax.swing.JDialog; |
11 |
import javax.swing.JLabel; |
12 |
import javax.swing.JOptionPane; |
13 |
import javax.swing.JTextField; |
14 |
|
15 |
import es.unex.sextante.additionalInfo.AdditionalInfoFilepath; |
16 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
17 |
import es.unex.sextante.core.Sextante; |
18 |
import es.unex.sextante.exceptions.NullParameterAdditionalInfoException; |
19 |
import es.unex.sextante.gui.modeler.ModelerPanel; |
20 |
import es.unex.sextante.parameters.Parameter; |
21 |
import es.unex.sextante.parameters.ParameterFilepath; |
22 |
|
23 |
public class FilepathPanel |
24 |
extends
|
25 |
ParameterPanel { |
26 |
|
27 |
private JTextField jTextFieldExtension; |
28 |
private JLabel jLabelExtension; |
29 |
private JComboBox jComboBoxType; |
30 |
private JLabel jLabelType; |
31 |
private JCheckBox jCheckBoxVoxel; |
32 |
|
33 |
|
34 |
public FilepathPanel(final JDialog parent, |
35 |
final ModelerPanel panel) {
|
36 |
|
37 |
super(parent, panel);
|
38 |
|
39 |
} |
40 |
|
41 |
|
42 |
public FilepathPanel(final ModelerPanel panel) { |
43 |
|
44 |
super(panel);
|
45 |
|
46 |
} |
47 |
|
48 |
|
49 |
@Override
|
50 |
protected void initGUI() { |
51 |
|
52 |
super.initGUI();
|
53 |
|
54 |
super.setTitle(Sextante.getText("modeler_add_par_filepath")); |
55 |
|
56 |
super.setPreferredSize(new java.awt.Dimension(400, 250)); |
57 |
|
58 |
try {
|
59 |
{ |
60 |
final TableLayout thisLayout = new TableLayout |
61 |
(new double[][] { { TableLayoutConstants.MINIMUM, 5.0, TableLayoutConstants.FILL }, |
62 |
{ TableLayoutConstants.MINIMUM, |
63 |
1.0,
|
64 |
TableLayoutConstants.MINIMUM, |
65 |
1.0,
|
66 |
TableLayoutConstants.MINIMUM } }); |
67 |
thisLayout.setHGap(5);
|
68 |
thisLayout.setVGap(5);
|
69 |
|
70 |
jPanelMiddle.setLayout(thisLayout); |
71 |
|
72 |
jLabelType = new JLabel(); |
73 |
jLabelType.setText(Sextante.getText("filepath_type"));
|
74 |
jPanelMiddle.add(jLabelType, "0, 0");
|
75 |
final ComboBoxModel jComboBoxTypeModel = new DefaultComboBoxModel(new String[] { |
76 |
Sextante.getText("filepath_file_open"),
|
77 |
Sextante.getText("filepath_file_save"),
|
78 |
Sextante.getText("filepath_folder") });
|
79 |
jComboBoxType = new JComboBox(); |
80 |
jComboBoxType.setModel(jComboBoxTypeModel); |
81 |
jPanelMiddle.add(jComboBoxType, "2, 0");
|
82 |
|
83 |
jLabelExtension = new JLabel(); |
84 |
jPanelMiddle.add(jLabelExtension, "0, 2");
|
85 |
jLabelExtension.setText(Sextante.getText("file_extension"));
|
86 |
jTextFieldExtension = new JTextField(); |
87 |
jPanelMiddle.add(jTextFieldExtension, "2, 2");
|
88 |
|
89 |
jCheckBoxVoxel = new JCheckBox(); |
90 |
jCheckBoxVoxel.setSelected(false);
|
91 |
jCheckBoxVoxel.setText(Sextante.getText("filepath_is_voxel_data"));
|
92 |
jPanelMiddle.add(jCheckBoxVoxel, "0, 4");
|
93 |
} |
94 |
} |
95 |
catch (final Exception e) { |
96 |
Sextante.addErrorToLog(e); |
97 |
} |
98 |
|
99 |
} |
100 |
|
101 |
|
102 |
@Override
|
103 |
public String getParameterDescription() { |
104 |
|
105 |
return Sextante.getText("Filepath"); |
106 |
|
107 |
} |
108 |
|
109 |
|
110 |
@Override
|
111 |
protected boolean prepareParameter() { |
112 |
|
113 |
|
114 |
final String sDescription = jTextFieldDescription.getText(); |
115 |
String[] sDefault; |
116 |
|
117 |
if (sDescription.length() != 0) { |
118 |
final AdditionalInfoFilepath ai = new AdditionalInfoFilepath(); |
119 |
sDefault = new String[1]; |
120 |
sDefault[0]=jTextFieldExtension.getText();
|
121 |
if ( sDefault[0] != null && sDefault[0].length() > 0 ) { |
122 |
ai.setExtensions(sDefault); |
123 |
} |
124 |
ai.setIsFolder(false);
|
125 |
ai.setIsOpenDialog(false);
|
126 |
switch (jComboBoxType.getSelectedIndex()) {
|
127 |
case 0: |
128 |
ai.setIsOpenDialog(true);
|
129 |
break;
|
130 |
case 2: |
131 |
ai.setIsFolder(true);
|
132 |
break;
|
133 |
} |
134 |
ai.setIsVoxelData(jCheckBoxVoxel.isSelected()); |
135 |
m_Parameter = new ParameterFilepath();
|
136 |
m_Parameter.setParameterDescription(sDescription); |
137 |
m_Parameter.setParameterAdditionalInfo(ai); |
138 |
|
139 |
m_Parameter.setColorR(m_Color.getRed()); |
140 |
m_Parameter.setColorG(m_Color.getGreen()); |
141 |
m_Parameter.setColorB(m_Color.getBlue()); |
142 |
m_Parameter.setColorAlpha(m_Color.getAlpha()); |
143 |
|
144 |
return true; |
145 |
} |
146 |
else {
|
147 |
JOptionPane.showMessageDialog(null, Sextante.getText("Invalid_description"), Sextante.getText("Warning"), |
148 |
JOptionPane.WARNING_MESSAGE);
|
149 |
return false; |
150 |
} |
151 |
|
152 |
|
153 |
} |
154 |
|
155 |
|
156 |
@Override
|
157 |
public void setParameter(final Parameter param) { |
158 |
|
159 |
super.setParameter(param);
|
160 |
|
161 |
try {
|
162 |
final AdditionalInfoFilepath ai = (AdditionalInfoFilepath) param.getParameterAdditionalInfo();
|
163 |
if ( ai.getExtensions() != null ) |
164 |
jTextFieldExtension.setText(ai.getExtensions()[0]);
|
165 |
jComboBoxType.setSelectedIndex(1);
|
166 |
if ( ai.isOpenDialog() == true ) |
167 |
jComboBoxType.setSelectedIndex(0);
|
168 |
if ( ai.isFolder() == true ) |
169 |
jComboBoxType.setSelectedIndex(2);
|
170 |
if ( ai.getIsVoxelData() == true ) |
171 |
jCheckBoxVoxel.setSelected(true);
|
172 |
} |
173 |
catch (final NullParameterAdditionalInfoException e) { |
174 |
e.printStackTrace(); |
175 |
} |
176 |
|
177 |
} |
178 |
|
179 |
|
180 |
@Override
|
181 |
public boolean parameterCanBeAdded() { |
182 |
|
183 |
return true; |
184 |
|
185 |
} |
186 |
|
187 |
} |