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