Class ViewMenuBuilder


  • public class ViewMenuBuilder
    extends java.lang.Object
    This class provides a number of helper methods for building and manipulating menus.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  ViewMenuBuilder.MenuDragOp
      Class for listening to dragging events within a menu.
      private class  ViewMenuBuilder.MipavMenuItem
      DOCUMENT ME!
      class  ViewMenuBuilder.QuickList
      QuickList class uses Preferences to build a list of the most recently opened images. the frame is passed in for purposes of ActionListener The QuickList is stored as JMenuItems in a Vector that can be retrieved.
    • Constructor Summary

      Constructors 
      Constructor Description
      ViewMenuBuilder​(java.awt.event.ActionListener al)
      Sets frame to add menus to, and initializes menu item vector.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addMenuDragListener​(java.awt.Component comp, javax.swing.event.MenuDragMouseListener op)
      Attaches a MenuDragMouseListener to comp and all of its sub-components (if comp is a JMenu/JMenuItem.
      javax.swing.JCheckBoxMenuItem buildCheckBoxMenuItem​(java.lang.String text, java.lang.String cmd, boolean selected)
      Builds a JCheckBox with the given parameters and adds it to the Vector of menu items.
      static javax.swing.JCheckBoxMenuItem buildCheckBoxMenuItem​(java.lang.String text, java.lang.String cmd, java.awt.event.ActionListener listener, boolean selected)
      Static method for building JCheckBoxes with the given parameters.
      static javax.swing.JMenuItem buildHTMLMenuItem​(java.lang.String text, java.lang.String cmd, int mnemonic, java.awt.event.ActionListener listener, java.lang.String iconName, boolean iconPadding)
      DOCUMENT ME!
      static javax.swing.JMenu buildMenu​(java.lang.String text, int mnemonic, boolean iconPadding)
      Static method for building a JMenu.
      javax.swing.JMenuItem buildMenuItem​(CustomUIBuilder.UIParams params, boolean useIconPadding)
      Build a menu item using a pre-made UIParams
      static javax.swing.JMenuItem buildMenuItem​(CustomUIBuilder.UIParams params, java.awt.event.ActionListener listener, boolean iconPadding)
      Creates a Menu Item using pre-packaged UIParams
      static javax.swing.JMenuItem buildMenuItem​(java.lang.String text, java.lang.String cmd, int mnemonic, java.awt.event.ActionListener listener, java.lang.String iconName, boolean iconPadding)
      DOCUMENT ME!
      javax.swing.JMenuItem buildMenuItem​(java.lang.String text, java.lang.String cmd, int mnemonic, java.lang.String iconName, boolean useIconPadding)
      DOCUMENT ME!
      ViewMenuBuilder.QuickList buildQuickList()
      Builds the quicklist for the first time.
      javax.swing.JRadioButtonMenuItem buildRadioButtonMenuItem​(java.lang.String text, java.lang.String cmd, boolean selected)  
      javax.swing.JRadioButtonMenuItem buildRadioButtonMenuItem​(java.lang.String text, java.lang.String cmd, boolean selected, javax.swing.ButtonGroup group)  
      void finalize()
      Clean up memory used by the menu builder.
      javax.swing.JMenuItem getMenuItem​(java.lang.String menuItemName)
      DOCUMENT ME!
      boolean isMenuItemEnabled​(java.lang.String name)
      Provides a method of checking the state of specified menu.
      boolean isMenuItemSelected​(java.lang.String name)
      Provides a method of checking the state of specified menu.
      javax.swing.JMenu makeMenu​(java.lang.Object parentMenu, boolean iconPadding, javax.swing.JComponent[] menuComponent)
      Makes a menu out of the menu components, using parentMenu as the base for this menu.
      javax.swing.JMenu makeMenu​(java.lang.Object parentMenu, char mnemonic, boolean iconPadding, java.util.Vector<javax.swing.JComponent> menuComponent)  
      javax.swing.JMenu makeMenu​(java.lang.Object parentMenu, char mnemonic, boolean iconPadding, javax.swing.JComponent[] menuComponent)
      Makes a menu out of the menu components, using parentMenu as the base for this menu and adding a mnemonic.
      void setMenuItemEnabled​(java.lang.String name, boolean state)
      Provides a method of setting the state of specified menu.
      void setMenuItemSelected​(java.lang.String name, boolean val)
      Provides a method for changing the status of a checkbox menu item.
      void updateQuickList()
      Updates the most recently opened images list (called when images are opened etc).
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • fileMenu

        private javax.swing.JMenu fileMenu
        Link to the file menu so that quicklist can be rebuilt and added.
      • listener

        private java.awt.event.ActionListener listener
        The class which wants to listen to the menu items generated.
      • quicklistIndex

        private int quicklistIndex
        Index for rebuilding quicklist.
      • buttonGroup

        private javax.swing.ButtonGroup buttonGroup
    • Constructor Detail

      • ViewMenuBuilder

        public ViewMenuBuilder​(java.awt.event.ActionListener al)
        Sets frame to add menus to, and initializes menu item vector.
        Parameters:
        al - class which wants notification of interations with the generated menu items
    • Method Detail

      • buildCheckBoxMenuItem

        public static javax.swing.JCheckBoxMenuItem buildCheckBoxMenuItem​(java.lang.String text,
                                                                          java.lang.String cmd,
                                                                          java.awt.event.ActionListener listener,
                                                                          boolean selected)
        Static method for building JCheckBoxes with the given parameters.
        Parameters:
        text - String text to display on the box
        cmd - String the action command
        listener - ActionListener the action listener for the box
        selected - boolean whether the box should be selected by default
        Returns:
        JCheckBoxMenuItem the jcheckbox that is built
      • buildHTMLMenuItem

        public static javax.swing.JMenuItem buildHTMLMenuItem​(java.lang.String text,
                                                              java.lang.String cmd,
                                                              int mnemonic,
                                                              java.awt.event.ActionListener listener,
                                                              java.lang.String iconName,
                                                              boolean iconPadding)
        DOCUMENT ME!
        Parameters:
        text - DOCUMENT ME!
        cmd - DOCUMENT ME!
        mnemonic - DOCUMENT ME!
        listener - DOCUMENT ME!
        iconName - DOCUMENT ME!
        iconPadding - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • buildMenu

        public static javax.swing.JMenu buildMenu​(java.lang.String text,
                                                  int mnemonic,
                                                  boolean iconPadding)
        Static method for building a JMenu.
        Parameters:
        text - String the name of the menu to be displayed
        mnemonic - int mnemonic for the menu
        iconPadding - boolean an empty icon (transparent) is used to properly pad the text
        Returns:
        JMenu the menu that is built
      • buildMenuItem

        public static javax.swing.JMenuItem buildMenuItem​(CustomUIBuilder.UIParams params,
                                                          java.awt.event.ActionListener listener,
                                                          boolean iconPadding)
        Creates a Menu Item using pre-packaged UIParams
        Parameters:
        params - UI Params
        listener - Action listener
        iconPadding - whether to use icon padding
        Returns:
        the jmenuitem
      • buildMenuItem

        public static javax.swing.JMenuItem buildMenuItem​(java.lang.String text,
                                                          java.lang.String cmd,
                                                          int mnemonic,
                                                          java.awt.event.ActionListener listener,
                                                          java.lang.String iconName,
                                                          boolean iconPadding)
        DOCUMENT ME!
        Parameters:
        text - DOCUMENT ME!
        cmd - DOCUMENT ME!
        mnemonic - DOCUMENT ME!
        listener - DOCUMENT ME!
        iconName - DOCUMENT ME!
        iconPadding - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • buildRadioButtonMenuItem

        public javax.swing.JRadioButtonMenuItem buildRadioButtonMenuItem​(java.lang.String text,
                                                                         java.lang.String cmd,
                                                                         boolean selected)
      • buildRadioButtonMenuItem

        public javax.swing.JRadioButtonMenuItem buildRadioButtonMenuItem​(java.lang.String text,
                                                                         java.lang.String cmd,
                                                                         boolean selected,
                                                                         javax.swing.ButtonGroup group)
      • buildCheckBoxMenuItem

        public javax.swing.JCheckBoxMenuItem buildCheckBoxMenuItem​(java.lang.String text,
                                                                   java.lang.String cmd,
                                                                   boolean selected)
        Builds a JCheckBox with the given parameters and adds it to the Vector of menu items.
        Parameters:
        text - String Checkbox text
        cmd - String actioncommand
        selected - boolean whether the box is selected by default
        Returns:
        JCheckBoxMenuItem
      • buildMenuItem

        public javax.swing.JMenuItem buildMenuItem​(CustomUIBuilder.UIParams params,
                                                   boolean useIconPadding)
        Build a menu item using a pre-made UIParams
        Parameters:
        params - the UIParams (from CustomUIBuilder)
        useIconPadding - use icon padding
        Returns:
      • buildMenuItem

        public javax.swing.JMenuItem buildMenuItem​(java.lang.String text,
                                                   java.lang.String cmd,
                                                   int mnemonic,
                                                   java.lang.String iconName,
                                                   boolean useIconPadding)
        DOCUMENT ME!
        Parameters:
        text - String
        cmd - String
        mnemonic - int
        iconName - String
        useIconPadding - boolean
        Returns:
        JMenuItem
      • buildQuickList

        public ViewMenuBuilder.QuickList buildQuickList()
        Builds the quicklist for the first time.
        Returns:
        QuickList
      • finalize

        public void finalize()
        Clean up memory used by the menu builder.
        Overrides:
        finalize in class java.lang.Object
      • getMenuItem

        public javax.swing.JMenuItem getMenuItem​(java.lang.String menuItemName)
        DOCUMENT ME!
        Parameters:
        menuItemName - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • isMenuItemEnabled

        public boolean isMenuItemEnabled​(java.lang.String name)
        Provides a method of checking the state of specified menu.
        Parameters:
        name - The name of the item whose state needs to be checked.
        Returns:
        Whether or not the item is enabled.
      • isMenuItemSelected

        public boolean isMenuItemSelected​(java.lang.String name)
        Provides a method of checking the state of specified menu.
        Parameters:
        name - The name of the item whose state needs to be checked.
        Returns:
        Whether or not the item is selected.
      • makeMenu

        public javax.swing.JMenu makeMenu​(java.lang.Object parentMenu,
                                          boolean iconPadding,
                                          javax.swing.JComponent[] menuComponent)
        Makes a menu out of the menu components, using parentMenu as the base for this menu.
        Parameters:
        parentMenu - The parent menu, must be of type String or a JMenu, cannot be null.
        iconPadding - Array of menu items, must be of typeJMenu, JMenuItem, JCheckBoxMenuItem, or JSeparator.
        menuComponent - Parent frame, used to add as an item listener to the checkbox menu items.
        Returns:
        The newly created menu.
      • makeMenu

        public javax.swing.JMenu makeMenu​(java.lang.Object parentMenu,
                                          char mnemonic,
                                          boolean iconPadding,
                                          javax.swing.JComponent[] menuComponent)
        Makes a menu out of the menu components, using parentMenu as the base for this menu and adding a mnemonic.
        Parameters:
        parentMenu - The parent menu, must be of type String or a JMenu, cannot be null.
        mnemonic - Mnemonic key for the parent menu name.
        iconPadding - Array of menu items, must be of typeJMenu, JMenuItem, JCheckBoxMenuItem, or JSeparator.
        menuComponent - Parent frame, used to add as an item listener to the checkbox menu items.
        Returns:
        The newly created menu.
      • makeMenu

        public javax.swing.JMenu makeMenu​(java.lang.Object parentMenu,
                                          char mnemonic,
                                          boolean iconPadding,
                                          java.util.Vector<javax.swing.JComponent> menuComponent)
      • setMenuItemEnabled

        public void setMenuItemEnabled​(java.lang.String name,
                                       boolean state)
        Provides a method of setting the state of specified menu.
        Parameters:
        name - The name of the item whose state needs to be set.
        state - true sets the menu item active; false sets the menu item inactive.
      • setMenuItemSelected

        public void setMenuItemSelected​(java.lang.String name,
                                        boolean val)
        Provides a method for changing the status of a checkbox menu item.
        Parameters:
        val - whether the checkbox should be selected.
      • updateQuickList

        public void updateQuickList()
        Updates the most recently opened images list (called when images are opened etc).
      • addMenuDragListener

        private void addMenuDragListener​(java.awt.Component comp,
                                         javax.swing.event.MenuDragMouseListener op)
        Attaches a MenuDragMouseListener to comp and all of its sub-components (if comp is a JMenu/JMenuItem.