root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / settings / SextanteScriptsSettingsPanel.java @ 119
History | View | Annotate | Download (5.41 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.util.HashMap; |
11 |
|
12 |
import javax.swing.JButton; |
13 |
import javax.swing.JCheckBox; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JOptionPane; |
16 |
import javax.swing.JSeparator; |
17 |
import javax.swing.SwingConstants; |
18 |
|
19 |
import es.unex.sextante.core.Sextante; |
20 |
import es.unex.sextante.gui.algorithm.FileSelectionPanel; |
21 |
import es.unex.sextante.gui.cmd.ScriptAlgorithmProvider; |
22 |
import es.unex.sextante.gui.core.SextanteGUI; |
23 |
|
24 |
public class SextanteScriptsSettingsPanel |
25 |
extends
|
26 |
SettingPanel { |
27 |
|
28 |
// private JCheckBox jPortableCheckBox;
|
29 |
private JLabel jLabelScripts; |
30 |
private FileSelectionPanel jScriptsFolder;
|
31 |
private JLabel jLabelUpdate; |
32 |
private JButton jButtonUpdate; |
33 |
|
34 |
|
35 |
@Override
|
36 |
protected void initGUI() { |
37 |
final TableLayout thisLayout = new TableLayout(new double[][] { |
38 |
{ SextanteConfigurationDialog.SPACER_SMALL, |
39 |
TableLayoutConstants.FILL, |
40 |
TableLayoutConstants.FILL, |
41 |
SextanteConfigurationDialog.SPACER_SMALL }, |
42 |
{ SextanteConfigurationDialog.SPACER_SMALL, |
43 |
TableLayoutConstants.MINIMUM, //row 1
|
44 |
TableLayoutConstants.MINIMUM, //row 2
|
45 |
TableLayoutConstants.MINIMUM, //row 3
|
46 |
TableLayoutConstants.MINIMUM, //row 4
|
47 |
TableLayoutConstants.FILL } }); |
48 |
thisLayout.setHGap(5);
|
49 |
thisLayout.setVGap(5);
|
50 |
this.setLayout(thisLayout);
|
51 |
|
52 |
// jPortableCheckBox = new JCheckBox(Sextante.getText("Portable"));
|
53 |
// final String sActivatePortable = SextanteGUI.getSettingParameterValue(SextanteScriptsSettings.SCRIPTS_PORTABLE);
|
54 |
final boolean bActivatePortable = true; |
55 |
// jPortableCheckBox.setSelected(bActivatePortable);
|
56 |
// this.add(jPortableCheckBox, "1, 1");
|
57 |
|
58 |
jLabelScripts = new JLabel(); |
59 |
jLabelScripts.setEnabled(true);
|
60 |
if (bActivatePortable == true) { |
61 |
jLabelScripts.setEnabled(false);
|
62 |
} |
63 |
jLabelScripts.setText(Sextante.getText("Scripts_folder"));
|
64 |
this.add(jLabelScripts, "1, 2"); |
65 |
jScriptsFolder = new FileSelectionPanel(true, true, (String[]) null, Sextante.getText("selector_choose_folder")); |
66 |
jScriptsFolder.getTextField().setEnabled(true);
|
67 |
jScriptsFolder.getButton().setEnabled(true);
|
68 |
if (bActivatePortable == true) { |
69 |
jScriptsFolder.getTextField().setEnabled(false);
|
70 |
jScriptsFolder.getButton().setEnabled(false);
|
71 |
} |
72 |
final String sFolder = SextanteGUI.getSettingParameterValue(SextanteScriptsSettings.SCRIPTS_FOLDER); |
73 |
jScriptsFolder.setFilepath(sFolder); |
74 |
this.add(jScriptsFolder, "2, 2"); |
75 |
|
76 |
this.add(new JSeparator(SwingConstants.HORIZONTAL), "1, 3, 2, 3"); |
77 |
/* ----------------------------------------------------------- */
|
78 |
|
79 |
jLabelUpdate = new JLabel(); |
80 |
jLabelUpdate.setText( Sextante.getText("update_library") );
|
81 |
jLabelUpdate.setEnabled(true);
|
82 |
this.add(jLabelUpdate, "1, 4"); |
83 |
jButtonUpdate = new JButton(Sextante.getText("load_scripts")); |
84 |
this.add(jButtonUpdate, "2, 4"); |
85 |
|
86 |
/**********************************/
|
87 |
/** Action listeners for widgets **/
|
88 |
/**********************************/
|
89 |
|
90 |
// jPortableCheckBox.addActionListener(new ActionListener() {
|
91 |
// public void actionPerformed(final ActionEvent arg0) {
|
92 |
// setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
93 |
// SextanteGUI.setSettingParameterValue(SextanteScriptsSettings.SCRIPTS_PORTABLE,
|
94 |
// new Boolean(jPortableCheckBox.isSelected()).toString());
|
95 |
// //Set portable user scripts folder
|
96 |
// SextanteGUI.checkDir ( Sextante.PORTABLE_SCRIPTS_FOLDER, true, "Toolbox user scripts" );
|
97 |
// String sPath = new String (SextanteGUI.getSextanteHomePath() + File.separator +
|
98 |
// Sextante.PORTABLE_SCRIPTS_FOLDER);
|
99 |
// SextanteGUI.setSettingParameterValue(SextanteScriptsSettings.SCRIPTS_FOLDER, sPath);
|
100 |
// jScriptsFolder.setFilepath(sPath);
|
101 |
// //Activate/deactivate the remaining widgets on this page
|
102 |
// final boolean active = jPortableCheckBox.isSelected();
|
103 |
// if ( active == true ) {
|
104 |
// jLabelScripts.setEnabled(false);
|
105 |
// jScriptsFolder.getTextField().setEnabled(false);
|
106 |
// jScriptsFolder.getButton().setEnabled(false);
|
107 |
//
|
108 |
// } else {
|
109 |
// jLabelScripts.setEnabled(true);
|
110 |
// jScriptsFolder.getTextField().setEnabled(true);
|
111 |
// jScriptsFolder.getButton().setEnabled(true);
|
112 |
//
|
113 |
// }
|
114 |
// setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
115 |
// }
|
116 |
// });
|
117 |
|
118 |
jButtonUpdate.addActionListener(new ActionListener() { |
119 |
public void actionPerformed(final ActionEvent arg0) { |
120 |
SextanteGUI.setSettingParameterValue(SextanteScriptsSettings.SCRIPTS_FOLDER, jScriptsFolder.getFilepath()); |
121 |
SextanteGUI.updateAlgorithmProvider(ScriptAlgorithmProvider.class); |
122 |
final int iNumAlgs = Sextante.getAlgorithms().get(new ScriptAlgorithmProvider().getName()).size(); |
123 |
JOptionPane.showMessageDialog(null, Sextante.getText("ScriptsLoaded") + " " + iNumAlgs + ". ", |
124 |
Sextante.getText("Scripts"), JOptionPane.INFORMATION_MESSAGE); |
125 |
} |
126 |
}); |
127 |
} |
128 |
|
129 |
|
130 |
@Override
|
131 |
public HashMap<String, String> getValues() { |
132 |
|
133 |
final HashMap<String, String> map = new HashMap<String, String>(); |
134 |
map.put(SextanteScriptsSettings.SCRIPTS_PORTABLE, Boolean.TRUE.toString());
|
135 |
final String path = jScriptsFolder.getFilepath(); |
136 |
if (path != null) { |
137 |
map.put(SextanteScriptsSettings.SCRIPTS_FOLDER, path); |
138 |
} |
139 |
return map;
|
140 |
|
141 |
} |
142 |
|
143 |
} |