root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / settings / AlgorithmGroupsConfigurationDialog.java @ 119
History | View | Annotate | Download (4.82 KB)
1 |
package es.unex.sextante.gui.settings; |
---|---|
2 |
|
3 |
import info.clearthought.layout.TableLayout; |
4 |
|
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.util.HashMap; |
8 |
|
9 |
import javax.swing.JButton; |
10 |
import javax.swing.JDialog; |
11 |
import javax.swing.JScrollPane; |
12 |
import javax.swing.JTable; |
13 |
import javax.swing.table.TableModel; |
14 |
import javax.swing.table.TableColumn; |
15 |
|
16 |
import es.unex.sextante.core.Sextante; |
17 |
import es.unex.sextante.gui.core.SextanteGUI; |
18 |
import es.unex.sextante.gui.toolbox.AlgorithmGroupConfiguration; |
19 |
import es.unex.sextante.gui.toolbox.AlgorithmGroupsOrganizer; |
20 |
|
21 |
public class AlgorithmGroupsConfigurationDialog |
22 |
extends
|
23 |
JDialog {
|
24 |
|
25 |
|
26 |
private HashMap<String, AlgorithmGroupConfiguration> m_Map; |
27 |
private JButton jButtonCancel; |
28 |
private JButton jButtonRestore; |
29 |
private JTable jTable; |
30 |
private JScrollPane jScrollPane; |
31 |
private JButton jButtonOK; |
32 |
private boolean m_bIsDefaultSettings; |
33 |
|
34 |
|
35 |
public AlgorithmGroupsConfigurationDialog() {
|
36 |
|
37 |
super(SextanteGUI.getMainFrame(), true); |
38 |
initGUI(); |
39 |
|
40 |
} |
41 |
|
42 |
|
43 |
private void initGUI() { |
44 |
|
45 |
m_Map = AlgorithmGroupsOrganizer.getGrouppingMap(); |
46 |
|
47 |
final TableLayout thisLayout = new TableLayout(new double[][] { |
48 |
{ 3.0,
|
49 |
TableLayout.MINIMUM, // 1: Restore Default
|
50 |
TableLayout.FILL, // 2: Filler
|
51 |
90.0, // 3: Cancel |
52 |
6.0, // 4: Spacer |
53 |
90.0, // 5: Ok |
54 |
3.0 },
|
55 |
{ 3.0, TableLayout.FILL, 3.0, 30.0, 3.0 } }); |
56 |
thisLayout.setHGap(5);
|
57 |
thisLayout.setVGap(5);
|
58 |
getContentPane().setLayout(thisLayout); |
59 |
|
60 |
{ |
61 |
jButtonRestore = new JButton(); |
62 |
getContentPane().add(jButtonRestore, "1, 3");
|
63 |
jButtonRestore.setText(Sextante.getText("RestoreDefault"));
|
64 |
jButtonRestore.addActionListener(new ActionListener() { |
65 |
public void actionPerformed(final ActionEvent evt) { |
66 |
jButtonRestoreActionPerformed(evt); |
67 |
} |
68 |
}); |
69 |
} |
70 |
{ |
71 |
jButtonCancel = new JButton(); |
72 |
getContentPane().add(jButtonCancel, "3, 3");
|
73 |
jButtonCancel.setText(Sextante.getText("Cancel"));
|
74 |
jButtonCancel.addActionListener(new ActionListener() { |
75 |
public void actionPerformed(final ActionEvent evt) { |
76 |
jButtonCancelActionPerformed(evt); |
77 |
} |
78 |
}); |
79 |
} |
80 |
{ |
81 |
jButtonOK = new JButton(); |
82 |
getContentPane().add(jButtonOK, "5, 3");
|
83 |
jButtonOK.setText(Sextante.getText("OK"));
|
84 |
jButtonOK.addActionListener(new ActionListener() { |
85 |
public void actionPerformed(final ActionEvent evt) { |
86 |
jButtonOKActionPerformed(evt); |
87 |
} |
88 |
}); |
89 |
} |
90 |
{ |
91 |
jScrollPane = new JScrollPane(); |
92 |
getContentPane().add(jScrollPane, "1, 1, 5, 1");
|
93 |
TableModel jTableModel;
|
94 |
if (m_Map.size() == 0) { |
95 |
jTableModel = new AlgorithmGroupsConfigurationTableModel(this); |
96 |
m_bIsDefaultSettings = true;
|
97 |
} |
98 |
else {
|
99 |
jTableModel = new AlgorithmGroupsConfigurationTableModel(m_Map, this); |
100 |
} |
101 |
jTable = new JTable(); |
102 |
jTable.getTableHeader().setReorderingAllowed(false);
|
103 |
jScrollPane.setViewportView(jTable); |
104 |
jTable.setModel(jTableModel); |
105 |
TableColumn column = null; |
106 |
/* Set column widths. */
|
107 |
for (int i = 0; i < 5; i++) { |
108 |
column = jTable.getColumnModel().getColumn(i); |
109 |
column.setPreferredWidth(100);
|
110 |
if ( i == 2 || i == 4 ) { |
111 |
column.setPreferredWidth(50);
|
112 |
} |
113 |
if ( i == 1 ) { |
114 |
column.setPreferredWidth(150);
|
115 |
} |
116 |
} |
117 |
|
118 |
} |
119 |
{ |
120 |
this.setTitle(Sextante.getText("Toolbox")+ " - " + Sextante.getText("ConfigureAlgGroups")); |
121 |
this.setSize(800, 500); |
122 |
//this.pack();
|
123 |
this.setLocationRelativeTo(null); |
124 |
} |
125 |
|
126 |
|
127 |
} |
128 |
|
129 |
|
130 |
public HashMap<String, AlgorithmGroupConfiguration> getGrouppingsMap() { |
131 |
|
132 |
return m_Map;
|
133 |
|
134 |
} |
135 |
|
136 |
|
137 |
private void jButtonOKActionPerformed(final ActionEvent evt) { |
138 |
|
139 |
m_Map.clear(); |
140 |
if (!m_bIsDefaultSettings) {
|
141 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
142 |
final AlgorithmGroupConfiguration conf = new AlgorithmGroupConfiguration(); |
143 |
conf.setGroup(jTable.getValueAt(i, 2).toString());
|
144 |
conf.setSubgroup(jTable.getValueAt(i, 3).toString());
|
145 |
conf.setShow(((Boolean) jTable.getValueAt(i, 4)).booleanValue()); |
146 |
m_Map.put(jTable.getValueAt(i, 0).toString(), conf);
|
147 |
} |
148 |
} |
149 |
this.dispose();
|
150 |
this.setVisible(false); |
151 |
|
152 |
} |
153 |
|
154 |
|
155 |
private void jButtonCancelActionPerformed(final ActionEvent evt) { |
156 |
|
157 |
m_Map = null;
|
158 |
this.dispose();
|
159 |
this.setVisible(false); |
160 |
|
161 |
|
162 |
} |
163 |
|
164 |
|
165 |
private void jButtonRestoreActionPerformed(final ActionEvent evt) { |
166 |
|
167 |
m_Map.clear(); |
168 |
final TableModel jTableModel = new AlgorithmGroupsConfigurationTableModel(this); |
169 |
jTable.setModel(jTableModel); |
170 |
m_bIsDefaultSettings = true;
|
171 |
|
172 |
} |
173 |
|
174 |
|
175 |
public void hasBeenModified() { |
176 |
|
177 |
m_bIsDefaultSettings = false;
|
178 |
|
179 |
} |
180 |
|
181 |
|
182 |
} |