Changeset 6254


Ignore:
Timestamp:
2003-12-12T17:55:02+13:00 (20 years ago)
Author:
jmt12
Message:

Provided a custom basic JSeparator for plugin list

File:
1 edited

Legend:

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

    r6087 r6254  
    3333import javax.swing.*;
    3434import javax.swing.event.*;
     35import javax.swing.plaf.*;
    3536import javax.swing.plaf.basic.*;
    3637import org.apache.xerces.parsers.*;
     
    870871            }
    871872            else {
    872                configure.setEnabled(true);
    873                // Some buttons are only available for plugins other than ArcPlug and RecPlug
    874                PlugIn selected_plugin = (PlugIn) plugin_list.getSelectedValue();
    875                String plugin_name = selected_plugin.getName();
    876                if(plugin_name.equals(StaticStrings.ARCPLUG_STR) || plugin_name.equals(StaticStrings.RECPLUG_STR)) {
    877                move_top_button.setEnabled(false);
    878                move_up_button.setEnabled(false);
    879                move_down_button.setEnabled(false);
    880                move_bottom_button.setEnabled(false);
    881                remove.setEnabled(false);
    882                }
    883                else {
    884               // Move ups are only enabled if the selected plugin isn't already at the top
    885               PlugIn first_plugin = (PlugIn) getElementAt(0);
    886               if(!first_plugin.equals(selected_plugin)) {
    887                  move_top_button.setEnabled(true);
    888                  move_up_button.setEnabled(true);
    889               }
    890               else {
    891                  move_top_button.setEnabled(false);
    892                  move_up_button.setEnabled(false);
    893               }
    894               // And move downs are only allowed when the selected plugin isn't at an index one less than the separator line.
    895               int separator_index = findSeparatorIndex();
    896               int selected_index = plugin_list.getSelectedIndex();
    897               if(selected_index != separator_index - 1) {
    898                  move_down_button.setEnabled(true);
    899                  move_bottom_button.setEnabled(true);
    900               }
    901               else {
    902                  move_down_button.setEnabled(false);
    903                  move_bottom_button.setEnabled(false);
    904               }
    905               remove.setEnabled(true);
    906                }
    907                selected_plugin = null;
    908                plugin_name = null;
     873            PlugIn selected_plugin = (PlugIn) plugin_list.getSelectedValue();
     874            if(selected_plugin.isSeparator()) {
     875                move_top_button.setEnabled(false);
     876                move_up_button.setEnabled(false);
     877                move_down_button.setEnabled(false);
     878                move_bottom_button.setEnabled(false);
     879                configure.setEnabled(false);
     880                remove.setEnabled(false);
     881            }
     882            else {
     883                configure.setEnabled(true);
     884                String plugin_name = selected_plugin.getName();
     885                // Some buttons are only available for plugins other than ArcPlug and RecPlug
     886                if(plugin_name.equals(StaticStrings.ARCPLUG_STR) || plugin_name.equals(StaticStrings.RECPLUG_STR)) {
     887                move_top_button.setEnabled(false);
     888                move_up_button.setEnabled(false);
     889                move_down_button.setEnabled(false);
     890                move_bottom_button.setEnabled(false);
     891                remove.setEnabled(false);
     892                }
     893                else {
     894                // Move ups are only enabled if the selected plugin isn't already at the top
     895                PlugIn first_plugin = (PlugIn) getElementAt(0);
     896                if(!first_plugin.equals(selected_plugin)) {
     897                    move_top_button.setEnabled(true);
     898                    move_up_button.setEnabled(true);
     899                }
     900                else {
     901                    move_top_button.setEnabled(false);
     902                    move_up_button.setEnabled(false);
     903                }
     904                // And move downs are only allowed when the selected plugin isn't at an index one less than the separator line.
     905                int separator_index = findSeparatorIndex();
     906                int selected_index = plugin_list.getSelectedIndex();
     907                if(selected_index != separator_index - 1) {
     908                    move_down_button.setEnabled(true);
     909                    move_bottom_button.setEnabled(true);
     910                }
     911                else {
     912                    move_down_button.setEnabled(false);
     913                    move_bottom_button.setEnabled(false);
     914                }
     915                remove.setEnabled(true);
     916                }
     917                selected_plugin = null;
     918                plugin_name = null;
     919            }
    909920            }
    910921        }
     
    968979    }
    969980
    970     /** This listener reacts to changes in the current selection of the plugin combobox. */
    971     private class PlugInComboboxListener
     981    /** This listener reacts to changes in the current selection of the plugin combobox. */
     982    private class PlugInComboboxListener
    972983        implements ItemListener {
    973984        /** When a user selects a certain plugin, update the tooltip to show the plugin description. */
     
    9891000        }
    9901001    }
    991 
     1002   
    9921003    /** This class listens for actions upon the remove button in the controls, and if detected calls the <i>removePlugIn()</i> method.
    9931004     */
    9941005    private class RemoveListener
    995         implements ActionListener {
    996         /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
     1006        implements ActionListener {
     1007        /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
    9971008         * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
    9981009         */
     
    10251036                remove.setEnabled(false);
    10261037            }
    1027             /*
    1028             if(!plugin_list.isSelectionEmpty()) {
    1029                 Object [] objects = plugin_list.getSelectedValues();
    1030                 for(int i = 0; i < objects.length; i++) {
    1031                     if(objects[i] instanceof PlugIn) {
    1032                         removePlugIn((PlugIn)objects[i]);
    1033                     }
    1034                 }
    1035                 // Refresh the available plugins
    1036                 plugin.setModel(new DefaultComboBoxModel(getAvailable()));
    1037             }
    1038             */
    10391038        }
    10401039    }
    10411040    }
    10421041    /** Creates a list separator.
    1043      * Code courtesy of Farwell, Paul. Contact <a href="mailto:[email protected]">[email protected]</a>
    1044      */
    1045     static private JPanel getSeparator() {
     1042     * Found on Google Groups. Code courtesy of Paul Farwell.
     1043     */
     1044    private JPanel getSeparator() {
    10461045    // We put the separator inside a panel to control its appearance
    10471046    JPanel _sepPanel = new JPanel();
     
    10501049    _sepPanel.setLayout(new BoxLayout(_sepPanel, BoxLayout.Y_AXIS));
    10511050    _sepPanel.add(Box.createRigidArea(new Dimension(0, 4)));
    1052     _sepPanel.add(new JPopupMenu.Separator());
     1051    // We have to be a little careful here, as the default UI for separators under MacOS is a blank box. Instead we force a BasicUI look
     1052    _sepPanel.add(new BasicSeparator());
    10531053    _sepPanel.add(Box.createRigidArea(new Dimension(0, 4)));
    10541054    return _sepPanel;
    10551055    }
     1056
     1057    /** This class behaves just like a normal JSeparator except that, no matter what the current settings in the UIManager are, it always paints itself with BasicSeparatorUI. */
     1058    private class BasicSeparator
     1059    extends JSeparator {
     1060
     1061    private ComponentUI basic_ui;
     1062
     1063    public BasicSeparator() {
     1064        super();
     1065        basic_ui = new BasicSeparatorUI();
     1066    }
     1067
     1068    public void paintComponent(Graphics g) {
     1069        if (basic_ui != null) {
     1070        basic_ui.update(g, this);
     1071        }   
     1072    }
     1073    }
    10561074}
     1075
Note: See TracChangeset for help on using the changeset viewer.