1 | package org.greenstone.gatherer.cdm;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 | import java.util.*;
|
---|
6 | import javax.swing.*;
|
---|
7 | import javax.swing.event.*;
|
---|
8 | import org.greenstone.gatherer.Configuration;
|
---|
9 | import org.greenstone.gatherer.DebugStream;
|
---|
10 | import org.greenstone.gatherer.Dictionary;
|
---|
11 | import org.greenstone.gatherer.Gatherer;
|
---|
12 | import org.greenstone.gatherer.util.JarTools;
|
---|
13 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
14 | import org.w3c.dom.*;
|
---|
15 |
|
---|
16 |
|
---|
17 | public class IndexOptionManager
|
---|
18 | implements BuildTypeManager.BuildTypeListener {
|
---|
19 |
|
---|
20 | // we have an IndexOptionList (DOMProxyListModel) for each option type
|
---|
21 | private IndexOptionList level_model = null;
|
---|
22 | private IndexOptionList stem_model = null;
|
---|
23 |
|
---|
24 | /** the default level option - for mgpp and lucene */
|
---|
25 | private IndexOption default_level = null;
|
---|
26 |
|
---|
27 | private String build_type = null;
|
---|
28 | private Control controls = null;
|
---|
29 |
|
---|
30 | public IndexOptionManager(String current_build_type) {
|
---|
31 | level_model = new IndexOptionList(CollectionDesignManager.collect_config.getLevels());
|
---|
32 | stem_model = new IndexOptionList(CollectionDesignManager.collect_config.getStemOptions());
|
---|
33 |
|
---|
34 | DebugStream.println("IndexOptionManager: " + level_model.getSize() + " levels parsed.");
|
---|
35 | DebugStream.println("IndexOptionManager: " + stem_model.getSize() + " stem options parsed.");
|
---|
36 |
|
---|
37 | build_type = current_build_type;
|
---|
38 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
39 | level_model.setAssigned(false);
|
---|
40 | }
|
---|
41 | else if (build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
42 | stem_model.setAssigned(false);
|
---|
43 | }
|
---|
44 | // Parse and retrieve the default level
|
---|
45 | Element default_level_element = CollectionDesignManager.collect_config.getLevelDefault();
|
---|
46 | default_level = new IndexOption(default_level_element);
|
---|
47 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
48 | default_level.setAssigned(false);
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | public void buildTypeChanged(String new_build_type) {
|
---|
55 | boolean levels_enabled = true;
|
---|
56 | boolean stem_enabled = true;
|
---|
57 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
58 | levels_enabled = false;
|
---|
59 | } else if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
60 | stem_enabled = false;
|
---|
61 | }
|
---|
62 | level_model.setAssigned(levels_enabled);
|
---|
63 | default_level.setAssigned(levels_enabled);
|
---|
64 | stem_model.setAssigned(stem_enabled);
|
---|
65 | ((IndexOptionControl)controls).buildTypeChanged(new_build_type);
|
---|
66 | build_type = new_build_type;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /** Method to acquire the controls for editing the indexes.
|
---|
70 | * @return the Control
|
---|
71 | */
|
---|
72 | public Control getControls() {
|
---|
73 | if(controls == null) {
|
---|
74 | // Build controls
|
---|
75 | controls = new IndexOptionControl();
|
---|
76 | }
|
---|
77 | return controls;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public int getNumLevels() {
|
---|
81 | return level_model.getSize();
|
---|
82 | }
|
---|
83 | public ArrayList getLevels() {
|
---|
84 | return level_model.children();
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void addLevel(String level) {
|
---|
88 | if (level_model.getOption(level) == null) {
|
---|
89 | int position = 0;
|
---|
90 |
|
---|
91 | if (level.equals(StaticStrings.SECTION_STR) && level_model.getSize()==1) {
|
---|
92 | position = 1;
|
---|
93 | }
|
---|
94 | level_model.add(position, new IndexOption(level));
|
---|
95 | // add in a default collection meta
|
---|
96 | CollectionMeta meta = new CollectionMeta(StaticStrings.STOP_CHARACTER + level);
|
---|
97 | meta.setAssigned(true);
|
---|
98 | meta.setValue(level);
|
---|
99 | CollectionDesignManager.collectionmeta_manager.addMetadatum(meta);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | private IndexOption getLevel(String level) {
|
---|
104 | return level_model.getOption(level);
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void removeLevel(String level_name) {
|
---|
108 | // Remove any current metadata from this level
|
---|
109 | CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + level_name);
|
---|
110 | // Remove the level
|
---|
111 | level_model.removeOption(level_name);
|
---|
112 | }
|
---|
113 |
|
---|
114 | /** Method to set the default level
|
---|
115 | * @param level the new default level
|
---|
116 | */
|
---|
117 | private void setDefaultLevel(String level) {
|
---|
118 | if(level != null) {
|
---|
119 | default_level.setValue(level);
|
---|
120 | if (!build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
121 | default_level.setAssigned(true);
|
---|
122 | }
|
---|
123 | } else {
|
---|
124 | default_level.setAssigned(false);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | private class IndexOptionControl
|
---|
129 | extends JPanel
|
---|
130 | implements Control {
|
---|
131 |
|
---|
132 | public StemmingControl stem_control = null;
|
---|
133 | public LevelControl level_control = null;
|
---|
134 |
|
---|
135 | public IndexOptionControl() {
|
---|
136 |
|
---|
137 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
138 | stem_control = new StemmingControl();
|
---|
139 | level_control = new LevelControl();
|
---|
140 |
|
---|
141 | setLayout(new BorderLayout());
|
---|
142 | if (!build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
143 | add(stem_control, BorderLayout.NORTH);
|
---|
144 | }
|
---|
145 | if (!build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
146 | add(level_control, BorderLayout.CENTER);
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | public void destroy() {}
|
---|
151 | public void gainFocus() {}
|
---|
152 | public void loseFocus() {}
|
---|
153 |
|
---|
154 | public void buildTypeChanged(String new_build_type)
|
---|
155 | {
|
---|
156 | if (build_type.equals(new_build_type)) {
|
---|
157 | // shouldn't happen
|
---|
158 | return;
|
---|
159 | }
|
---|
160 | // tell our sub parts about the change in build type
|
---|
161 | stem_control.buildTypeChanged(new_build_type);
|
---|
162 | level_control.buildTypeChanged(new_build_type);
|
---|
163 |
|
---|
164 | // then display/hide as appropriate
|
---|
165 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
166 | // Changing to MG/MGPP
|
---|
167 | add(stem_control, BorderLayout.NORTH);
|
---|
168 | }
|
---|
169 | else if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
170 | // Changing to Lucene
|
---|
171 | remove(stem_control);
|
---|
172 | }
|
---|
173 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
174 | // changing from MG
|
---|
175 | add(level_control, BorderLayout.CENTER);
|
---|
176 | }
|
---|
177 | else if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
178 | // changing to MG
|
---|
179 | remove(level_control);
|
---|
180 | }
|
---|
181 |
|
---|
182 | }
|
---|
183 |
|
---|
184 | }
|
---|
185 |
|
---|
186 | private class StemmingControl
|
---|
187 | extends JPanel
|
---|
188 | implements BuildTypeManager.BuildTypeListener
|
---|
189 | {
|
---|
190 | private JCheckBox stem_checkbox = new JCheckBox();
|
---|
191 | private JCheckBox casefold_checkbox = new JCheckBox();
|
---|
192 | private JCheckBox accentfold_checkbox = new JCheckBox();
|
---|
193 | private JCheckBox separate_cjk_checkbox =new JCheckBox();
|
---|
194 |
|
---|
195 | public StemmingControl()
|
---|
196 | {
|
---|
197 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
198 | setLayout(new BorderLayout(10,10));
|
---|
199 | setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
200 |
|
---|
201 | stem_checkbox.setText(Dictionary.get("CDM.IndexingManager.Stem"));
|
---|
202 | stem_checkbox.setToolTipText(Dictionary.get("CDM.IndexingManager.Stem_Tooltip"));
|
---|
203 | stem_checkbox.setActionCommand(StaticStrings.STEM_OPTION_STR);
|
---|
204 | stem_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
205 |
|
---|
206 | casefold_checkbox.setText(Dictionary.get("CDM.IndexingManager.Casefold"));
|
---|
207 | casefold_checkbox.setToolTipText(Dictionary.get("CDM.IndexingManager.Casefold_Tooltip"));
|
---|
208 | casefold_checkbox.setActionCommand(StaticStrings.CASEFOLD_OPTION_STR);
|
---|
209 | casefold_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
210 |
|
---|
211 | accentfold_checkbox.setText(Dictionary.get("CDM.IndexingManager.Accent_fold"));
|
---|
212 | accentfold_checkbox.setToolTipText(Dictionary.get("CDM.IndexingManager.Accent_fold_Tooltip"));
|
---|
213 | accentfold_checkbox.setActionCommand(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
214 | // Accent-folding is currently not available for MG
|
---|
215 | accentfold_checkbox.setEnabled(!build_type.equals(BuildTypeManager.BUILD_TYPE_MG));
|
---|
216 | accentfold_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
217 |
|
---|
218 | separate_cjk_checkbox.setText(Dictionary.get("CDM.IndexingManager.Separate_cjk"));
|
---|
219 | separate_cjk_checkbox.setToolTipText(Dictionary.get("CDM.IndexingManager.Separate_cjk_Tooltip"));
|
---|
220 | separate_cjk_checkbox.setActionCommand(StaticStrings.SEPARATE_CJK_OPTION_STR);
|
---|
221 | separate_cjk_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
222 |
|
---|
223 | JPanel checkbox_panel = new JPanel();
|
---|
224 | checkbox_panel.setLayout(new GridLayout(2, 1));
|
---|
225 | checkbox_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
226 |
|
---|
227 | JPanel stem_panel = new JPanel();
|
---|
228 | stem_panel.setLayout(new GridLayout(1,3));
|
---|
229 | stem_panel.add(stem_checkbox);
|
---|
230 | stem_panel.add(casefold_checkbox);
|
---|
231 | stem_panel.add(accentfold_checkbox);
|
---|
232 | stem_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
233 |
|
---|
234 | JPanel other_panel = new JPanel();
|
---|
235 | other_panel.setLayout(new GridLayout(1,1));
|
---|
236 | other_panel.add(separate_cjk_checkbox);
|
---|
237 | other_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
238 |
|
---|
239 | checkbox_panel.add(stem_panel);
|
---|
240 | checkbox_panel.add(other_panel);
|
---|
241 |
|
---|
242 | JLabel tmp = new JLabel(Dictionary.get("CDM.IndexingManager.Options"));
|
---|
243 | tmp.setComponentOrientation(Dictionary.getOrientation());
|
---|
244 | add(tmp, BorderLayout.LINE_START);
|
---|
245 | add(checkbox_panel, BorderLayout.CENTER);
|
---|
246 |
|
---|
247 | // set up the checked/unchecked boxes
|
---|
248 | if (stem_model.getSize()==0) {
|
---|
249 | // select all
|
---|
250 | stem_checkbox.setSelected(true);
|
---|
251 | stem_model.addOption(StaticStrings.STEM_OPTION_STR);
|
---|
252 | casefold_checkbox.setSelected(true);
|
---|
253 | stem_model.addOption(StaticStrings.CASEFOLD_OPTION_STR);
|
---|
254 | if (accentfold_checkbox.isEnabled()) {
|
---|
255 | accentfold_checkbox.setSelected(true);
|
---|
256 | stem_model.addOption(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
257 | }
|
---|
258 | separate_cjk_checkbox.setSelected(false);
|
---|
259 | }
|
---|
260 | else {
|
---|
261 | if (stem_model.getOption(StaticStrings.STEM_OPTION_STR)!=null) {
|
---|
262 | stem_checkbox.setSelected(true);
|
---|
263 | }
|
---|
264 | if (stem_model.getOption(StaticStrings.CASEFOLD_OPTION_STR)!=null) {
|
---|
265 | casefold_checkbox.setSelected(true);
|
---|
266 | }
|
---|
267 | if (stem_model.getOption(StaticStrings.ACCENTFOLD_OPTION_STR)!=null) {
|
---|
268 | accentfold_checkbox.setSelected(true);
|
---|
269 | }
|
---|
270 | if (stem_model.getOption(StaticStrings.SEPARATE_CJK_OPTION_STR) != null) {
|
---|
271 | separate_cjk_checkbox.setSelected(true);
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | }
|
---|
276 |
|
---|
277 | CheckBoxListener cbl = new CheckBoxListener();
|
---|
278 | stem_checkbox.addActionListener(cbl);
|
---|
279 | casefold_checkbox.addActionListener(cbl);
|
---|
280 | accentfold_checkbox.addActionListener(cbl);
|
---|
281 | separate_cjk_checkbox.addActionListener(cbl);
|
---|
282 |
|
---|
283 | // changing stem indexes changes build settings
|
---|
284 | stem_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
285 | casefold_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
286 | accentfold_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
287 | separate_cjk_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
288 |
|
---|
289 | }
|
---|
290 |
|
---|
291 | public void buildTypeChanged(String new_build_type) {
|
---|
292 | // Accent-folding is currently not available for MG
|
---|
293 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
294 | //changing to MG
|
---|
295 | accentfold_checkbox.setSelected(false);
|
---|
296 | accentfold_checkbox.setEnabled(false);
|
---|
297 | if (accentfold_checkbox.isSelected()) {
|
---|
298 | stem_model.removeOption(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
299 | }
|
---|
300 | }
|
---|
301 | else if (build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
302 | //Changing from MG
|
---|
303 | accentfold_checkbox.setEnabled(true);
|
---|
304 | if (accentfold_checkbox.isSelected()) {
|
---|
305 | stem_model.addOption(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | }
|
---|
310 |
|
---|
311 | private class CheckBoxListener
|
---|
312 | implements ActionListener {
|
---|
313 | public void actionPerformed(ActionEvent event) {
|
---|
314 | if (!((JCheckBox)event.getSource()).isSelected()) {
|
---|
315 | // deselecting
|
---|
316 | stem_model.removeOption(event.getActionCommand());
|
---|
317 | }
|
---|
318 | else {
|
---|
319 | // selecting a new one
|
---|
320 | stem_model.addOption(event.getActionCommand());
|
---|
321 | }
|
---|
322 | }
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 |
|
---|
327 |
|
---|
328 | /** This class creates a set of controls for editing the levels. */
|
---|
329 | private class LevelControl
|
---|
330 | extends JPanel
|
---|
331 | implements BuildTypeManager.BuildTypeListener
|
---|
332 | {
|
---|
333 |
|
---|
334 | JCheckBox document_checkbox = null;
|
---|
335 | JCheckBox section_checkbox = null;
|
---|
336 | JRadioButton document_default_radio = null;
|
---|
337 | JRadioButton section_default_radio = null;
|
---|
338 |
|
---|
339 | public LevelControl() {
|
---|
340 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
341 | JPanel checkbox_panel = new JPanel();
|
---|
342 | checkbox_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
343 | JPanel default_panel = new JPanel();
|
---|
344 | default_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
345 | document_checkbox = new JCheckBox();
|
---|
346 | document_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
347 | document_checkbox.setText(Dictionary.get("CDM.LevelManager.Document"));
|
---|
348 | document_checkbox.setActionCommand(StaticStrings.DOCUMENT_STR);
|
---|
349 | document_default_radio = new JRadioButton();
|
---|
350 | document_default_radio.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
351 | document_default_radio.setOpaque(false);
|
---|
352 | document_default_radio.setActionCommand(StaticStrings.DOCUMENT_STR);
|
---|
353 | document_default_radio.setIcon(JarTools.getImage("radio_unselected.gif"));
|
---|
354 | document_default_radio.setSelectedIcon(JarTools.getImage("radio_selected.gif"));
|
---|
355 | document_default_radio.setComponentOrientation(Dictionary.getOrientation());
|
---|
356 |
|
---|
357 | section_checkbox = new JCheckBox();
|
---|
358 | section_checkbox.setText(Dictionary.get("CDM.LevelManager.Section"));
|
---|
359 | section_checkbox.setActionCommand(StaticStrings.SECTION_STR);
|
---|
360 | section_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
361 |
|
---|
362 | section_default_radio = new JRadioButton();
|
---|
363 | section_default_radio.setOpaque(true);
|
---|
364 | section_default_radio.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
365 | section_default_radio.setOpaque(false);
|
---|
366 | section_default_radio.setIcon(JarTools.getImage("radio_unselected.gif"));
|
---|
367 | section_default_radio.setSelectedIcon(JarTools.getImage("radio_selected.gif"));
|
---|
368 | section_default_radio.setComponentOrientation(Dictionary.getOrientation());
|
---|
369 |
|
---|
370 | section_default_radio.setActionCommand(StaticStrings.SECTION_STR);
|
---|
371 | ButtonGroup default_group = new ButtonGroup();
|
---|
372 | default_group.add(document_default_radio);
|
---|
373 | default_group.add(section_default_radio);
|
---|
374 |
|
---|
375 |
|
---|
376 |
|
---|
377 | if (level_model.getSize()==0) {
|
---|
378 | // no levels yet, set document
|
---|
379 | document_checkbox.setSelected(true);
|
---|
380 | addLevel(StaticStrings.DOCUMENT_STR);
|
---|
381 | } else {
|
---|
382 | if (getLevel(StaticStrings.DOCUMENT_STR)!= null) {
|
---|
383 | document_checkbox.setSelected(true);
|
---|
384 | }
|
---|
385 | if (getLevel(StaticStrings.SECTION_STR) != null) {
|
---|
386 | section_checkbox.setSelected(true);
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | if (default_level.isAssigned()) {
|
---|
391 | // set the default based on specified default
|
---|
392 | if (default_level.getValue().equals(StaticStrings.DOCUMENT_STR) && document_checkbox.isSelected()) {
|
---|
393 | document_default_radio.setSelected(true);
|
---|
394 | }
|
---|
395 | else if (default_level.getValue().equals(StaticStrings.SECTION_STR) && section_checkbox.isSelected()) {
|
---|
396 | section_default_radio.setSelected(true);
|
---|
397 | } else {
|
---|
398 | default_level.setAssigned(false);
|
---|
399 | }
|
---|
400 | }
|
---|
401 | // if have no valid specified default
|
---|
402 | if (!default_level.isAssigned()) {
|
---|
403 | String default_l = StaticStrings.DOCUMENT_STR;
|
---|
404 | if (document_checkbox.isSelected()) {
|
---|
405 | document_default_radio.setSelected(true);
|
---|
406 | default_l = StaticStrings.DOCUMENT_STR;
|
---|
407 | } else if (section_checkbox.isSelected()) {
|
---|
408 | section_default_radio.setSelected(true);
|
---|
409 | default_l = StaticStrings.SECTION_STR;
|
---|
410 | }
|
---|
411 | setDefaultLevel(default_l);
|
---|
412 | }
|
---|
413 |
|
---|
414 | validateControls();
|
---|
415 | JLabel checkbox_label = new JLabel(Dictionary.get("CDM.LevelManager.Level_Title"));
|
---|
416 | checkbox_panel.setLayout(new GridLayout(3,1));
|
---|
417 | checkbox_panel.setToolTipText(Dictionary.get("CDM.IndexManager.Level_Tooltip"));
|
---|
418 | checkbox_panel.add(checkbox_label);
|
---|
419 | checkbox_panel.add(document_checkbox);
|
---|
420 | checkbox_panel.add(section_checkbox);
|
---|
421 | checkbox_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
422 |
|
---|
423 | JLabel default_label = new JLabel(Dictionary.get("CDM.LevelManager.Default"));
|
---|
424 | default_panel.setLayout(new GridLayout(3,1));
|
---|
425 | default_panel.setToolTipText(Dictionary.get("CDM.LevelManager.Default_Tooltip"));
|
---|
426 | default_panel.add(default_label);
|
---|
427 | default_panel.add(document_default_radio);
|
---|
428 | default_panel.add(section_default_radio);
|
---|
429 | default_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
430 |
|
---|
431 | CheckBoxListener cbl = new CheckBoxListener();
|
---|
432 | document_checkbox.addActionListener(cbl);
|
---|
433 | section_checkbox.addActionListener(cbl);
|
---|
434 |
|
---|
435 | // changing selected levels changes build settings
|
---|
436 | document_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
437 | section_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
438 |
|
---|
439 | RadioListener rl = new RadioListener();
|
---|
440 | document_default_radio.addActionListener(rl);
|
---|
441 | section_default_radio.addActionListener(rl);
|
---|
442 | // changing the default doesn't need a rebuild
|
---|
443 |
|
---|
444 | setLayout(new BorderLayout(10,10));
|
---|
445 | setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
446 | add(checkbox_panel, BorderLayout.LINE_START);
|
---|
447 | add(default_panel, BorderLayout.CENTER);
|
---|
448 | } // LevelControl
|
---|
449 |
|
---|
450 | public void buildTypeChanged(String new_build_type) {};
|
---|
451 | public void gainFocus() {
|
---|
452 |
|
---|
453 | }
|
---|
454 |
|
---|
455 | public void loseFocus() {
|
---|
456 |
|
---|
457 | }
|
---|
458 |
|
---|
459 | public void destroy() {
|
---|
460 | }
|
---|
461 |
|
---|
462 | private class RadioListener
|
---|
463 | implements ActionListener {
|
---|
464 | public void actionPerformed(ActionEvent event) {
|
---|
465 | String new_level = event.getActionCommand();
|
---|
466 | setDefaultLevel(new_level);
|
---|
467 | }
|
---|
468 | }
|
---|
469 | private class CheckBoxListener
|
---|
470 | implements ActionListener {
|
---|
471 |
|
---|
472 | public void actionPerformed(ActionEvent event) {
|
---|
473 | if (!((JCheckBox)event.getSource()).isSelected()) {
|
---|
474 | // deselecting
|
---|
475 | if (noLevelsSelected()) {
|
---|
476 | // can't do this
|
---|
477 | ((JCheckBox)event.getSource()).setSelected(true);
|
---|
478 | } else {
|
---|
479 | // remove the level
|
---|
480 | removeLevel(event.getActionCommand());
|
---|
481 | }
|
---|
482 | } else {
|
---|
483 | // selecting a new one
|
---|
484 | addLevel(event.getActionCommand());
|
---|
485 | }
|
---|
486 | validateControls();
|
---|
487 | }
|
---|
488 | }
|
---|
489 |
|
---|
490 | private boolean noLevelsSelected() {
|
---|
491 | if (!document_checkbox.isSelected() && !section_checkbox.isSelected()) {
|
---|
492 | return true;
|
---|
493 |
|
---|
494 | }
|
---|
495 | return false;
|
---|
496 | }
|
---|
497 |
|
---|
498 | private void validateControls() {
|
---|
499 |
|
---|
500 | boolean document_enabled = document_checkbox.isSelected();
|
---|
501 | document_default_radio.setEnabled(document_enabled);
|
---|
502 |
|
---|
503 | boolean section_enabled = section_checkbox.isSelected();
|
---|
504 | section_default_radio.setEnabled(section_enabled);
|
---|
505 |
|
---|
506 | // have we disabled our default??
|
---|
507 | if (!document_enabled && document_default_radio.isSelected()) {
|
---|
508 | section_default_radio.setSelected(true);
|
---|
509 | setDefaultLevel(StaticStrings.SECTION_STR);
|
---|
510 |
|
---|
511 | } else if (!section_enabled && section_default_radio.isSelected()) {
|
---|
512 | document_default_radio.setSelected(true);
|
---|
513 | setDefaultLevel(StaticStrings.DOCUMENT_STR);
|
---|
514 | }
|
---|
515 |
|
---|
516 |
|
---|
517 | }
|
---|
518 |
|
---|
519 | }
|
---|
520 |
|
---|
521 | }
|
---|