Changeset 5234


Ignore:
Timestamp:
2003-08-21T11:09:06+12:00 (21 years ago)
Author:
jmt12
Message:

Move buttons now actually do something ;)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/SearchTypeManager.java

    r5223 r5234  
    8888    }
    8989
     90    public void moveSearchType(SearchType search_type, boolean direction) {
     91    // Try to move the classifier one step in the desired direction.
     92    int index = indexOf(search_type);
     93    if(direction) {
     94        index--;
     95    }
     96    else {
     97        index++;
     98    }
     99    // Check we aren't at an edge
     100    if((direction && index < 0) || (!direction && index >= getSize())) {
     101        String args[] = new String[2];
     102        args[0] = Gatherer.dictionary.get("CDM.SearchTypeManager.SearchType");
     103        args[1] = search_type.toString();
     104        String message = null;
     105        if(direction) {
     106        message = Gatherer.dictionary.get("CDM.Move.At_Top", args);
     107        }
     108        else {
     109        message = Gatherer.dictionary.get("CDM.Move.At_Bottom", args);
     110        }
     111        JOptionPane.showMessageDialog(Gatherer.g_man, message, Gatherer.dictionary.get("CDM.Move.Title"), JOptionPane.ERROR_MESSAGE);
     112        return;
     113    }
     114    remove(search_type);
     115    add(index, search_type);
     116    Gatherer.c_man.configurationChanged();
     117    }
     118
    90119    public void removeSearchType(SearchType searchtype) {
    91120    if(contains(searchtype)) {
     
    121150        title_label = new JLabel("CDM.SearchTypeManager.Title");
    122151        title_label.setHorizontalAlignment(JLabel.CENTER);
    123         instructions_textarea = new JTextArea("CDM.SearchTypeManager.Instructions");
     152        instructions_textarea = new JTextArea(Gatherer.dictionary.get("CDM.SearchTypeManager.Instructions"));
     153        instructions_textarea.setCaretPosition(0);
    124154        instructions_textarea.setEditable(false);
    125155        instructions_textarea.setLineWrap(true);
     
    153183
    154184        JPanel search_type_panel = new JPanel();
    155         search_type_label = new JLabel("CDM.SearchTypeManager.SearchType");
     185        search_type_label = new JLabel("CDM.SearchTypeManager.SearchType_Selection");
    156186        search_type_combobox = new GComboBox(SEARCH_TYPES);
    157187        search_type_combobox.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.editable_background", false));
     
    175205        current_search_types_list.addListSelectionListener(new CurrentSearchTypesListSelectionListener());
    176206        enable_advanced_searches_checkbox.addActionListener(new EnableAdvancedSearchesActionListener());
     207        move_up_button.addActionListener(new MoveListener(true));
     208        move_down_button.addActionListener(new MoveListener(false));
    177209        Gatherer.dictionary.register(add_button, null, false);
    178210        Gatherer.dictionary.register(current_search_types_label, null, false);
    179211        Gatherer.dictionary.register(enable_advanced_searches_checkbox, null, false);
    180         Gatherer.dictionary.register(instructions_textarea, null, false);
     212        //Gatherer.dictionary.register(instructions_textarea, null, false);
    181213        Gatherer.dictionary.register(move_up_button, null, false);
    182214        Gatherer.dictionary.register(move_down_button, null, false);
     
    234266        Gatherer.dictionary.deregister(current_search_types_label);
    235267        Gatherer.dictionary.deregister(enable_advanced_searches_checkbox);
    236         Gatherer.dictionary.deregister(instructions_textarea);
     268        //Gatherer.dictionary.deregister(instructions_textarea);
    237269        Gatherer.dictionary.deregister(move_up_button);
    238270        Gatherer.dictionary.deregister(move_down_button);
     
    291323        public void valueChanged(ListSelectionEvent event) {
    292324        if(!event.getValueIsAdjusting()) {
    293             if (current_search_types_list.isSelectionEmpty()) {
     325            SearchType search_type = null;
     326            if ((search_type = (SearchType) current_search_types_list.getSelectedValue()) != null) {
     327            int index = model.indexOf(search_type);
     328            // Move up is only enabled if the current selection isn't at index 0
     329            move_up_button.setEnabled(index != 0);
     330            // Move down is only enabled if the current selection isn't at index getSize() - 1
     331            move_down_button.setEnabled(index != model.getSize() - 1);
     332            // Remove is only enabled if this isn't the last search type
     333            remove_button.setEnabled(current_search_types_list.getModel().getSize() > 1);
     334            }
     335            else {
    294336            move_up_button.setEnabled(false);
    295337            move_down_button.setEnabled(false);
    296             }
    297             else {
    298             move_up_button.setEnabled(true);
    299             move_down_button.setEnabled(true);
    300             remove_button.setEnabled(current_search_types_list.getModel().getSize() > 1);
     338            remove_button.setEnabled(false);
    301339            }
    302340        }
     
    344382    }
    345383
     384    private class MoveListener
     385        implements ActionListener {
     386        private boolean move_up;
     387        public MoveListener(boolean move_up) {
     388        this.move_up = move_up;
     389        }
     390        public void actionPerformed(ActionEvent event) {
     391        // Retrieve the first selected search type (if any)
     392        SearchType search_type = null;
     393        if((search_type = (SearchType) current_search_types_list.getSelectedValue()) != null) {
     394            // Move search type
     395            moveSearchType(search_type, move_up);
     396            // Reselect the moved search type
     397            current_search_types_list.setSelectedValue(search_type, true);
     398        }
     399        // No selection - no movement
     400        else {
     401            move_up_button.setEnabled(false);
     402            move_down_button.setEnabled(false);
     403        }
     404        }
     405    }
     406
    346407    /** Listens for changes in the search types combobox, and enabled add button appropriately. */
    347408    private class SearchTypesActionDocumentListener
Note: See TracChangeset for help on using the changeset viewer.