[18688] | 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);
|
---|
[18886] | 97 | if (level.equals("document") || level.equals("section")) {
|
---|
| 98 | meta.setValue("_text" + level + "_");
|
---|
| 99 | } else {
|
---|
| 100 | meta.setValue(level);
|
---|
| 101 | }
|
---|
[18688] | 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)) {
|
---|
[36140] | 146 | add(stem_control, BorderLayout.EAST);
|
---|
[18688] | 147 | //}
|
---|
| 148 | if (!build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
[36140] | 149 | add(level_control, BorderLayout.WEST);
|
---|
[18688] | 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
|
---|
[36140] | 178 | add(level_control, BorderLayout.WEST);
|
---|
[18688] | 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();
|
---|
[36140] | 227 | checkbox_panel.setLayout(new GridLayout(1, 1));
|
---|
[18688] | 228 | checkbox_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
[36140] | 229 | // todo, remove one of these panels
|
---|
[18688] | 230 | JPanel stem_panel = new JPanel();
|
---|
[36140] | 231 | stem_panel.setLayout(new GridLayout(4,1));
|
---|
[18688] | 232 | stem_panel.add(stem_checkbox);
|
---|
| 233 | stem_panel.add(casefold_checkbox);
|
---|
| 234 | stem_panel.add(accentfold_checkbox);
|
---|
[36140] | 235 | stem_panel.add(separate_cjk_checkbox);
|
---|
[18688] | 236 | stem_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 237 |
|
---|
[36140] | 238 | // JPanel other_panel = new JPanel();
|
---|
| 239 | // other_panel.setLayout(new GridLayout(1,1));
|
---|
| 240 | // other_panel.add(separate_cjk_checkbox);
|
---|
| 241 | // other_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 242 |
|
---|
[18688] | 243 |
|
---|
| 244 | checkbox_panel.add(stem_panel);
|
---|
[36140] | 245 | //checkbox_panel.add(other_panel);
|
---|
[18688] | 246 |
|
---|
| 247 | JLabel tmp = new JLabel(Dictionary.get("CDM.IndexingManager.Options"));
|
---|
| 248 | tmp.setComponentOrientation(Dictionary.getOrientation());
|
---|
[36140] | 249 | add(tmp, BorderLayout.NORTH);
|
---|
[18688] | 250 | add(checkbox_panel, BorderLayout.CENTER);
|
---|
| 251 |
|
---|
| 252 | // set the defaults
|
---|
[36140] | 253 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)|| build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR)) {
|
---|
[18688] | 254 | stem_checkbox.setSelected(false);
|
---|
| 255 | stem_checkbox.setEnabled(false);
|
---|
| 256 | casefold_checkbox.setSelected(true);
|
---|
| 257 | casefold_checkbox.setEnabled(false);
|
---|
| 258 | accentfold_checkbox.setSelected(true);
|
---|
| 259 | accentfold_checkbox.setEnabled(false);
|
---|
| 260 | if (options_model.getOption(StaticStrings.SEPARATE_CJK_OPTION_STR) != null) {
|
---|
| 261 | separate_cjk_checkbox.setSelected(true);
|
---|
| 262 | }
|
---|
| 263 | } else {
|
---|
| 264 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
| 265 | accentfold_checkbox.setEnabled(false);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | // set up the checked/unchecked boxes
|
---|
| 269 | // we'll assume that the config file has got it correct
|
---|
[28216] | 270 | // no more setting all to on if nothing in config file
|
---|
| 271 | if (options_model.getSize()!=0) {
|
---|
[18688] | 272 | if (options_model.getOption(StaticStrings.STEM_OPTION_STR)!=null) {
|
---|
| 273 | stem_checkbox.setSelected(true);
|
---|
| 274 | }
|
---|
| 275 | if (options_model.getOption(StaticStrings.CASEFOLD_OPTION_STR)!=null) {
|
---|
| 276 | casefold_checkbox.setSelected(true);
|
---|
| 277 | }
|
---|
| 278 | if (options_model.getOption(StaticStrings.ACCENTFOLD_OPTION_STR)!=null) {
|
---|
| 279 | accentfold_checkbox.setSelected(true);
|
---|
| 280 | }
|
---|
| 281 | if (options_model.getOption(StaticStrings.SEPARATE_CJK_OPTION_STR) != null) {
|
---|
| 282 | separate_cjk_checkbox.setSelected(true);
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | CheckBoxListener cbl = new CheckBoxListener();
|
---|
| 289 | stem_checkbox.addActionListener(cbl);
|
---|
| 290 | casefold_checkbox.addActionListener(cbl);
|
---|
| 291 | accentfold_checkbox.addActionListener(cbl);
|
---|
| 292 | separate_cjk_checkbox.addActionListener(cbl);
|
---|
| 293 |
|
---|
| 294 | // changing stem indexes changes build settings
|
---|
| 295 | stem_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
| 296 | casefold_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
| 297 | accentfold_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
| 298 | separate_cjk_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
| 299 |
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | public void buildTypeChanged(String new_build_type) {
|
---|
| 303 | // accentfold only enabled for mgpp
|
---|
| 304 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_MGPP)) {
|
---|
| 305 | accentfold_checkbox.setEnabled(true);
|
---|
| 306 | accentfold_checkbox.setSelected(true);
|
---|
| 307 | options_model.addOption(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
[36140] | 308 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE) || build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR)) {
|
---|
| 309 | // was lucene/solr
|
---|
[18688] | 310 | stem_checkbox.setEnabled(true);
|
---|
| 311 | stem_checkbox.setSelected(true);
|
---|
| 312 | options_model.addOption(StaticStrings.STEM_OPTION_STR);
|
---|
| 313 | casefold_checkbox.setEnabled(true);
|
---|
| 314 | casefold_checkbox.setSelected(true);
|
---|
| 315 | options_model.addOption(StaticStrings.CASEFOLD_OPTION_STR);
|
---|
| 316 | } // else, was mg, stem and case remain the same
|
---|
| 317 |
|
---|
| 318 | }
|
---|
| 319 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
| 320 | accentfold_checkbox.setSelected(false);
|
---|
| 321 | accentfold_checkbox.setEnabled(false);
|
---|
| 322 | options_model.removeOption(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
| 323 |
|
---|
[36140] | 324 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE) || build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR)) {
|
---|
[18688] | 325 | // was lucene
|
---|
| 326 | stem_checkbox.setEnabled(true);
|
---|
| 327 | stem_checkbox.setSelected(true);
|
---|
| 328 | options_model.addOption(StaticStrings.STEM_OPTION_STR);
|
---|
| 329 | casefold_checkbox.setEnabled(true);
|
---|
| 330 | casefold_checkbox.setSelected(true);
|
---|
| 331 | options_model.addOption(StaticStrings.CASEFOLD_OPTION_STR);
|
---|
| 332 | } // else, was mgpp, stem and case remain the same
|
---|
| 333 |
|
---|
| 334 | }
|
---|
[36140] | 335 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE) || new_build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR)) {
|
---|
[18688] | 336 | accentfold_checkbox.setSelected(true);
|
---|
| 337 | accentfold_checkbox.setEnabled(false);
|
---|
| 338 | options_model.removeOption(StaticStrings.ACCENTFOLD_OPTION_STR);
|
---|
| 339 | stem_checkbox.setSelected(false);
|
---|
| 340 | stem_checkbox.setEnabled(false);
|
---|
| 341 | options_model.removeOption(StaticStrings.STEM_OPTION_STR);
|
---|
| 342 | casefold_checkbox.setSelected(true);
|
---|
| 343 | casefold_checkbox.setEnabled(false);
|
---|
| 344 | options_model.removeOption(StaticStrings.CASEFOLD_OPTION_STR);
|
---|
| 345 |
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | private class CheckBoxListener
|
---|
| 350 | implements ActionListener {
|
---|
| 351 | public void actionPerformed(ActionEvent event) {
|
---|
| 352 | if (!((JCheckBox)event.getSource()).isSelected()) {
|
---|
| 353 | // deselecting
|
---|
| 354 | options_model.removeOption(event.getActionCommand());
|
---|
| 355 | }
|
---|
| 356 | else {
|
---|
| 357 | // selecting a new one
|
---|
| 358 | options_model.addOption(event.getActionCommand());
|
---|
| 359 | }
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 |
|
---|
| 365 |
|
---|
| 366 | /** This class creates a set of controls for editing the levels. */
|
---|
| 367 | private class LevelControl
|
---|
| 368 | extends JPanel
|
---|
| 369 | implements BuildTypeManager.BuildTypeListener
|
---|
| 370 | {
|
---|
| 371 |
|
---|
| 372 | JCheckBox document_checkbox = null;
|
---|
| 373 | JCheckBox section_checkbox = null;
|
---|
| 374 | JRadioButton document_default_radio = null;
|
---|
| 375 | JRadioButton section_default_radio = null;
|
---|
| 376 |
|
---|
| 377 | public LevelControl() {
|
---|
| 378 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 379 | JPanel checkbox_panel = new JPanel();
|
---|
| 380 | checkbox_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 381 | JPanel default_panel = new JPanel();
|
---|
| 382 | default_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 383 | document_checkbox = new JCheckBox();
|
---|
| 384 | document_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 385 | document_checkbox.setText(Dictionary.get("CDM.LevelManager.Document"));
|
---|
| 386 | document_checkbox.setActionCommand(StaticStrings.DOCUMENT_STR);
|
---|
| 387 | document_default_radio = new JRadioButton();
|
---|
| 388 | document_default_radio.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
| 389 | document_default_radio.setOpaque(false);
|
---|
| 390 | document_default_radio.setActionCommand(StaticStrings.DOCUMENT_STR);
|
---|
| 391 | document_default_radio.setIcon(JarTools.getImage("radio_unselected.gif"));
|
---|
| 392 | document_default_radio.setSelectedIcon(JarTools.getImage("radio_selected.gif"));
|
---|
| 393 | document_default_radio.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 394 |
|
---|
| 395 | section_checkbox = new JCheckBox();
|
---|
| 396 | section_checkbox.setText(Dictionary.get("CDM.LevelManager.Section"));
|
---|
| 397 | section_checkbox.setActionCommand(StaticStrings.SECTION_STR);
|
---|
| 398 | section_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 399 |
|
---|
| 400 | section_default_radio = new JRadioButton();
|
---|
| 401 | section_default_radio.setOpaque(true);
|
---|
| 402 | section_default_radio.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
| 403 | section_default_radio.setOpaque(false);
|
---|
| 404 | section_default_radio.setIcon(JarTools.getImage("radio_unselected.gif"));
|
---|
| 405 | section_default_radio.setSelectedIcon(JarTools.getImage("radio_selected.gif"));
|
---|
| 406 | section_default_radio.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 407 |
|
---|
| 408 | section_default_radio.setActionCommand(StaticStrings.SECTION_STR);
|
---|
| 409 | ButtonGroup default_group = new ButtonGroup();
|
---|
| 410 | default_group.add(document_default_radio);
|
---|
| 411 | default_group.add(section_default_radio);
|
---|
| 412 |
|
---|
| 413 |
|
---|
| 414 |
|
---|
| 415 | if (level_model.getSize()==0) {
|
---|
| 416 | // no levels yet, set document
|
---|
| 417 | document_checkbox.setSelected(true);
|
---|
| 418 | addLevel(StaticStrings.DOCUMENT_STR);
|
---|
| 419 | } else {
|
---|
| 420 | if (getLevel(StaticStrings.DOCUMENT_STR)!= null) {
|
---|
| 421 | document_checkbox.setSelected(true);
|
---|
| 422 | }
|
---|
| 423 | if (getLevel(StaticStrings.SECTION_STR) != null) {
|
---|
| 424 | section_checkbox.setSelected(true);
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | if (default_level.isAssigned()) {
|
---|
| 429 | // set the default based on specified default
|
---|
| 430 | if (default_level.getValue().equals(StaticStrings.DOCUMENT_STR) && document_checkbox.isSelected()) {
|
---|
| 431 | document_default_radio.setSelected(true);
|
---|
| 432 | }
|
---|
| 433 | else if (default_level.getValue().equals(StaticStrings.SECTION_STR) && section_checkbox.isSelected()) {
|
---|
| 434 | section_default_radio.setSelected(true);
|
---|
| 435 | } else {
|
---|
| 436 | default_level.setAssigned(false);
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 | // if have no valid specified default
|
---|
| 440 | if (!default_level.isAssigned()) {
|
---|
| 441 | String default_l = StaticStrings.DOCUMENT_STR;
|
---|
| 442 | if (document_checkbox.isSelected()) {
|
---|
| 443 | document_default_radio.setSelected(true);
|
---|
| 444 | default_l = StaticStrings.DOCUMENT_STR;
|
---|
| 445 | } else if (section_checkbox.isSelected()) {
|
---|
| 446 | section_default_radio.setSelected(true);
|
---|
| 447 | default_l = StaticStrings.SECTION_STR;
|
---|
| 448 | }
|
---|
| 449 | setDefaultLevel(default_l);
|
---|
| 450 | }
|
---|
| 451 |
|
---|
| 452 | validateControls();
|
---|
| 453 | JLabel checkbox_label = new JLabel(Dictionary.get("CDM.LevelManager.Level_Title"));
|
---|
| 454 | checkbox_panel.setLayout(new GridLayout(3,1));
|
---|
| 455 | checkbox_panel.setToolTipText(Dictionary.get("CDM.IndexManager.Level_Tooltip"));
|
---|
| 456 | checkbox_panel.add(checkbox_label);
|
---|
| 457 | checkbox_panel.add(document_checkbox);
|
---|
| 458 | checkbox_panel.add(section_checkbox);
|
---|
| 459 | checkbox_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 460 |
|
---|
| 461 | JLabel default_label = new JLabel(Dictionary.get("CDM.LevelManager.Default"));
|
---|
| 462 | default_panel.setLayout(new GridLayout(3,1));
|
---|
| 463 | default_panel.setToolTipText(Dictionary.get("CDM.LevelManager.Default_Tooltip"));
|
---|
| 464 | default_panel.add(default_label);
|
---|
| 465 | default_panel.add(document_default_radio);
|
---|
| 466 | default_panel.add(section_default_radio);
|
---|
| 467 | default_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 468 |
|
---|
| 469 | CheckBoxListener cbl = new CheckBoxListener();
|
---|
| 470 | document_checkbox.addActionListener(cbl);
|
---|
| 471 | section_checkbox.addActionListener(cbl);
|
---|
| 472 |
|
---|
| 473 | // changing selected levels changes build settings
|
---|
| 474 | document_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
| 475 | section_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
| 476 |
|
---|
| 477 | RadioListener rl = new RadioListener();
|
---|
| 478 | document_default_radio.addActionListener(rl);
|
---|
| 479 | section_default_radio.addActionListener(rl);
|
---|
| 480 | // changing the default doesn't need a rebuild
|
---|
| 481 |
|
---|
| 482 | setLayout(new BorderLayout(10,10));
|
---|
| 483 | setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 484 | add(checkbox_panel, BorderLayout.LINE_START);
|
---|
| 485 | add(default_panel, BorderLayout.CENTER);
|
---|
| 486 | } // LevelControl
|
---|
| 487 |
|
---|
| 488 | public void buildTypeChanged(String new_build_type) {};
|
---|
| 489 | public void gainFocus() {
|
---|
| 490 |
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | public void loseFocus() {
|
---|
| 494 |
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | public void destroy() {
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | private class RadioListener
|
---|
| 501 | implements ActionListener {
|
---|
| 502 | public void actionPerformed(ActionEvent event) {
|
---|
| 503 | String new_level = event.getActionCommand();
|
---|
| 504 | setDefaultLevel(new_level);
|
---|
| 505 | }
|
---|
| 506 | }
|
---|
| 507 | private class CheckBoxListener
|
---|
| 508 | implements ActionListener {
|
---|
| 509 |
|
---|
| 510 | public void actionPerformed(ActionEvent event) {
|
---|
| 511 | if (!((JCheckBox)event.getSource()).isSelected()) {
|
---|
| 512 | // deselecting
|
---|
| 513 | if (noLevelsSelected()) {
|
---|
| 514 | // can't do this
|
---|
| 515 | ((JCheckBox)event.getSource()).setSelected(true);
|
---|
| 516 | } else {
|
---|
| 517 | // remove the level
|
---|
| 518 | removeLevel(event.getActionCommand());
|
---|
| 519 | }
|
---|
| 520 | } else {
|
---|
| 521 | // selecting a new one
|
---|
| 522 | addLevel(event.getActionCommand());
|
---|
| 523 | }
|
---|
| 524 | validateControls();
|
---|
| 525 | }
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | private boolean noLevelsSelected() {
|
---|
| 529 | if (!document_checkbox.isSelected() && !section_checkbox.isSelected()) {
|
---|
| 530 | return true;
|
---|
| 531 |
|
---|
| 532 | }
|
---|
| 533 | return false;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | private void validateControls() {
|
---|
| 537 |
|
---|
| 538 | boolean document_enabled = document_checkbox.isSelected();
|
---|
| 539 | document_default_radio.setEnabled(document_enabled);
|
---|
| 540 |
|
---|
| 541 | boolean section_enabled = section_checkbox.isSelected();
|
---|
| 542 | section_default_radio.setEnabled(section_enabled);
|
---|
| 543 |
|
---|
| 544 | // have we disabled our default??
|
---|
| 545 | if (!document_enabled && document_default_radio.isSelected()) {
|
---|
| 546 | section_default_radio.setSelected(true);
|
---|
| 547 | setDefaultLevel(StaticStrings.SECTION_STR);
|
---|
| 548 |
|
---|
| 549 | } else if (!section_enabled && section_default_radio.isSelected()) {
|
---|
| 550 | document_default_radio.setSelected(true);
|
---|
| 551 | setDefaultLevel(StaticStrings.DOCUMENT_STR);
|
---|
| 552 | }
|
---|
| 553 |
|
---|
| 554 |
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | }
|
---|