root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / settings / SextanteSagaSettingsPanel.java @ 119
History | View | Annotate | Download (8.43 KB)
1 |
package es.unex.sextante.gui.settings; |
---|---|
2 |
|
3 |
import info.clearthought.layout.TableLayout; |
4 |
import info.clearthought.layout.TableLayoutConstants; |
5 |
|
6 |
import java.awt.Cursor; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.io.File; |
10 |
import java.net.URL; |
11 |
import java.util.HashMap; |
12 |
|
13 |
import javax.swing.ImageIcon; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JCheckBox; |
16 |
import javax.swing.JLabel; |
17 |
import javax.swing.JOptionPane; |
18 |
import javax.swing.JSeparator; |
19 |
import javax.swing.SwingConstants; |
20 |
|
21 |
import es.unex.sextante.core.GeoAlgorithm; |
22 |
import es.unex.sextante.core.Sextante; |
23 |
import es.unex.sextante.gui.algorithm.FileSelectionPanel; |
24 |
import es.unex.sextante.gui.core.SextanteGUI; |
25 |
import es.unex.sextante.gui.saga.SagaAlgorithmProvider; |
26 |
import es.unex.sextante.gui.saga.SagaExecutionException; |
27 |
import es.unex.sextante.gui.saga.SagaUtils; |
28 |
|
29 |
|
30 |
public class SextanteSagaSettingsPanel |
31 |
extends
|
32 |
SettingPanel { |
33 |
|
34 |
private JCheckBox jActivateCheckBox; |
35 |
private JCheckBox jPortableCheckBox; |
36 |
private JLabel jLabelSagaFolder; |
37 |
private FileSelectionPanel jSagaFolder;
|
38 |
private JLabel jLabelUpdate; |
39 |
private JButton jButtonUpdate; |
40 |
|
41 |
|
42 |
|
43 |
@Override
|
44 |
protected void initGUI() { |
45 |
|
46 |
final TableLayout thisLayout = new TableLayout(new double[][] { |
47 |
{ SextanteConfigurationDialog.SPACER_SMALL, |
48 |
TableLayoutConstants.FILL, |
49 |
TableLayoutConstants.FILL, |
50 |
SextanteConfigurationDialog.SPACER_SMALL}, |
51 |
{ SextanteConfigurationDialog.SPACER_SMALL, |
52 |
TableLayoutConstants.MINIMUM, // row 1
|
53 |
TableLayoutConstants.MINIMUM, // row 2
|
54 |
TableLayoutConstants.MINIMUM, // row 3
|
55 |
TableLayoutConstants.MINIMUM, // row 4
|
56 |
TableLayoutConstants.MINIMUM, // row 5
|
57 |
TableLayoutConstants.MINIMUM, // row 6
|
58 |
TableLayoutConstants.FILL, |
59 |
TableLayoutConstants.MINIMUM, // row 8
|
60 |
SextanteConfigurationDialog.SPACER_SMALL } }); |
61 |
thisLayout.setHGap(5);
|
62 |
thisLayout.setVGap(5);
|
63 |
this.setLayout(thisLayout);
|
64 |
|
65 |
jActivateCheckBox = new JCheckBox(Sextante.getText("ActivateProvider") + " SAGA GIS"); |
66 |
final String sActivate = SextanteGUI.getSettingParameterValue(SextanteSagaSettings.SAGA_ACTIVATE); |
67 |
final boolean bActivate = Boolean.parseBoolean(sActivate); |
68 |
jActivateCheckBox.setSelected(bActivate); |
69 |
this.add(jActivateCheckBox, "1, 1"); |
70 |
|
71 |
this.add(new JSeparator(SwingConstants.HORIZONTAL), "1, 2, 2, 2"); |
72 |
/* ----------------------------------------------------------- */
|
73 |
|
74 |
jPortableCheckBox = new JCheckBox(Sextante.getText("Portable")); |
75 |
final String sActivatePortable = SextanteGUI.getSettingParameterValue(SextanteSagaSettings.SAGA_PORTABLE); |
76 |
final boolean bActivatePortable = Boolean.parseBoolean(sActivatePortable); |
77 |
jPortableCheckBox.setEnabled(bActivate); |
78 |
jPortableCheckBox.setSelected(bActivatePortable); |
79 |
this.add(jPortableCheckBox, "1, 3"); |
80 |
|
81 |
jLabelSagaFolder = new JLabel(); |
82 |
jLabelSagaFolder.setEnabled(bActivate); |
83 |
if (bActivatePortable == true) { |
84 |
jLabelSagaFolder.setEnabled(false);
|
85 |
} |
86 |
this.add(jLabelSagaFolder, "1, 4"); |
87 |
jLabelSagaFolder.setText(Sextante.getText("Saga_folder"));
|
88 |
jSagaFolder = new FileSelectionPanel(true, true, (String[]) null, Sextante.getText("selector_choose_folder")); |
89 |
jSagaFolder.getTextField().setEnabled(bActivate); |
90 |
jSagaFolder.getButton().setEnabled(bActivate); |
91 |
if (bActivatePortable == true) { |
92 |
jSagaFolder.getTextField().setEnabled(false);
|
93 |
jSagaFolder.getButton().setEnabled(false);
|
94 |
} |
95 |
final String sFolder = SextanteGUI.getSettingParameterValue(SextanteSagaSettings.SAGA_FOLDER); |
96 |
jSagaFolder.setFilepath(sFolder); |
97 |
this.add(jSagaFolder, "2, 4"); |
98 |
|
99 |
this.add(new JSeparator(SwingConstants.HORIZONTAL), "1, 5, 2, 5"); |
100 |
/* ----------------------------------------------------------- */
|
101 |
|
102 |
jLabelUpdate = new JLabel(); |
103 |
jLabelUpdate.setText( Sextante.getText("update_library") );
|
104 |
jLabelUpdate.setEnabled(bActivate); |
105 |
this.add(jLabelUpdate, "1, 6"); |
106 |
jButtonUpdate = new JButton(Sextante.getText("load_SAGA_modules")); |
107 |
jButtonUpdate.setEnabled(bActivate); |
108 |
this.add(jButtonUpdate, "2, 6"); |
109 |
|
110 |
/* add provider logo and URL */
|
111 |
final URL res = getClass().getClassLoader().getResource("images/logo_saga.png"); |
112 |
if (res != null) { |
113 |
final ImageIcon logo = new ImageIcon(res); |
114 |
JLabel logoLabel = new JLabel(logo); |
115 |
logoLabel.setIconTextGap(4);
|
116 |
logoLabel.setVerticalTextPosition(SwingConstants.BOTTOM);
|
117 |
logoLabel.setText("<html><i><a href=http://www.saga-gis.org/>http://www.saga-gis.org/</a></i></html>");
|
118 |
this.add(logoLabel,"1, 8, 2, 8"); |
119 |
} |
120 |
|
121 |
/**********************************/
|
122 |
/** Action listeners for widgets **/
|
123 |
/**********************************/
|
124 |
|
125 |
jActivateCheckBox.addActionListener(new ActionListener() { |
126 |
public void actionPerformed(final ActionEvent arg0) { |
127 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
128 |
SextanteGUI.setSettingParameterValue(SextanteSagaSettings.SAGA_ACTIVATE, |
129 |
new Boolean(jActivateCheckBox.isSelected()).toString()); |
130 |
SextanteGUI.updateAlgorithmProvider(SagaAlgorithmProvider.class); |
131 |
/* toggle remaining widgets on or off */
|
132 |
boolean active = jActivateCheckBox.isSelected();
|
133 |
jPortableCheckBox.setEnabled(active); |
134 |
jLabelSagaFolder.setEnabled(active); |
135 |
jSagaFolder.getTextField().setEnabled(active); |
136 |
jSagaFolder.getButton().setEnabled(active); |
137 |
jLabelUpdate.setEnabled(active); |
138 |
jButtonUpdate.setEnabled(active); |
139 |
jActivateCheckBox.getParent().repaint(); |
140 |
active = jPortableCheckBox.isSelected(); |
141 |
if ( active == true ) { |
142 |
jLabelSagaFolder.setEnabled(false);
|
143 |
jSagaFolder.getTextField().setEnabled(false);
|
144 |
jSagaFolder.getButton().setEnabled(false);
|
145 |
} |
146 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
147 |
} |
148 |
}); |
149 |
|
150 |
jPortableCheckBox.addActionListener(new ActionListener() { |
151 |
public void actionPerformed(final ActionEvent arg0) { |
152 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
153 |
SextanteGUI.setSettingParameterValue(SextanteSagaSettings.SAGA_PORTABLE, |
154 |
new Boolean(jPortableCheckBox.isSelected()).toString()); |
155 |
//Set portable SAGA bin dir
|
156 |
SextanteGUI.checkDir ( Sextante.PORTABLE_SAGA_FOLDER, true, "SAGA GIS" ); |
157 |
String sPath = new String (SextanteGUI.getSextanteInstallPath() + File.separator + |
158 |
Sextante.PORTABLE_SAGA_FOLDER); |
159 |
SextanteGUI.setSettingParameterValue(SextanteSagaSettings.SAGA_FOLDER, sPath); |
160 |
jSagaFolder.setFilepath(sPath); |
161 |
//Activate/deactivate the remaining widgets on this page
|
162 |
final boolean active = jPortableCheckBox.isSelected(); |
163 |
if ( active == true ) { |
164 |
jLabelSagaFolder.setEnabled(false);
|
165 |
jSagaFolder.getTextField().setEnabled(false);
|
166 |
jSagaFolder.getButton().setEnabled(false);
|
167 |
|
168 |
} else {
|
169 |
jLabelSagaFolder.setEnabled(true);
|
170 |
jSagaFolder.getTextField().setEnabled(true);
|
171 |
jSagaFolder.getButton().setEnabled(true);
|
172 |
|
173 |
} |
174 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
175 |
} |
176 |
}); |
177 |
|
178 |
jButtonUpdate.addActionListener(new ActionListener() { |
179 |
public void actionPerformed(final ActionEvent arg0) { |
180 |
SextanteGUI.setSettingParameterValue(SextanteSagaSettings.SAGA_FOLDER, jSagaFolder.getFilepath()); |
181 |
setupSaga(); |
182 |
} |
183 |
}); |
184 |
|
185 |
} |
186 |
|
187 |
|
188 |
protected void setupSaga() { |
189 |
|
190 |
try {
|
191 |
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
192 |
SagaUtils.installSaga(); |
193 |
SextanteGUI.updateAlgorithmProvider(SagaAlgorithmProvider.class); |
194 |
final HashMap<String, GeoAlgorithm> algs = Sextante.getAlgorithms().get("SAGA"); |
195 |
int iNumAlgs = 0; |
196 |
if (algs != null) { |
197 |
iNumAlgs = algs.size(); |
198 |
} |
199 |
this.setCursor(Cursor.getDefaultCursor()); |
200 |
JOptionPane.showMessageDialog(null, Sextante.getText("SagaAlgorithmsLoaded") + " " + iNumAlgs + ".", |
201 |
Sextante.getText("SAGA"), JOptionPane.INFORMATION_MESSAGE); |
202 |
} |
203 |
catch (final SagaExecutionException e) { |
204 |
e.printStackTrace(); |
205 |
JOptionPane.showMessageDialog(null, Sextante.getText("ErrorInstallingSaga"), Sextante.getText("SAGA"), |
206 |
JOptionPane.ERROR_MESSAGE);
|
207 |
} |
208 |
|
209 |
} |
210 |
|
211 |
|
212 |
@Override
|
213 |
public HashMap<String, String> getValues() { |
214 |
|
215 |
final HashMap<String, String> map = new HashMap<String, String>(); |
216 |
map.put(SextanteSagaSettings.SAGA_ACTIVATE, new Boolean(jActivateCheckBox.isSelected()).toString()); |
217 |
map.put(SextanteSagaSettings.SAGA_PORTABLE, new Boolean(jPortableCheckBox.isSelected()).toString()); |
218 |
final String path = jSagaFolder.getFilepath(); |
219 |
if (path != null) { |
220 |
map.put(SextanteSagaSettings.SAGA_FOLDER, path); |
221 |
} |
222 |
return map;
|
223 |
|
224 |
} |
225 |
|
226 |
} |