Class WidgetFactory


  • public class WidgetFactory
    extends java.lang.Object
    This class is a collection of GUI widget generation methods. Widgets are created in a MIPAV-consistent manner and style.
    Author:
    mccreedy
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  WidgetFactory.ScrollTextArea
      ScrollPane with an accessible JTextArea
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.awt.Font courier10
      A 10 point, plain, courier font.
      static java.awt.Font courier12
      A 12 point, plain, courier font.
      static java.awt.Font courier12B
      A 12 point, bold, courier font.
      static java.awt.Font font10
      A 10 point, plain, serif font.
      static java.awt.Font font12
      A 12 point, plain, serif font.
      static java.awt.Font font12B
      A 12 point, bold, serif font.
      static java.awt.Font font12I
      A 12 point, italic, serif font.
      static java.awt.Font font13B
      A 13 point, bold, serif font.
      static java.awt.Font font14
      A 14 point, plain, serif font.
      static java.awt.Font font14B
      A 14 point, bold, serif font.
      static java.awt.Font font16B
      A 16 point, bold, serif font.
      static java.awt.Font font18B
      A 18 point, bold, serif font.
    • Constructor Summary

      Constructors 
      Constructor Description
      WidgetFactory()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.JCheckBox buildCheckBox​(java.lang.String label, boolean isSelected)
      Builds a new check box component.
      static javax.swing.JCheckBox buildCheckBox​(java.lang.String label, boolean isSelected, java.awt.event.ItemListener listener)
      Builds a new check box component.
      static javax.swing.JButton buildIconButton​(javax.swing.Icon icon, java.lang.String toolTip, java.lang.String action, java.awt.event.ActionListener listener)
      Helper method to build a icon button.
      static javax.swing.JLabel buildLabel​(java.lang.String text)
      Builds a label with the proper font and font color.
      static javax.swing.JPasswordField buildPasswordField()
      Helper method to create a password field with the proper font and font color.
      static javax.swing.border.Border buildPressedButtonBorder()
      Builds a new border of the type used when a toggle button is depressed.
      static javax.swing.JRadioButton buildRadioButton​(java.lang.String label, boolean isSelected, javax.swing.ButtonGroup group)
      Builds a new radio button component.
      static javax.swing.JScrollPane buildScrollPane​(javax.swing.JComponent component)
      Create a new scroll pane, containing a component.
      static javax.swing.JScrollPane buildScrollPane​(javax.swing.JComponent component, int preferredWidth, int preferredHeight)
      Create a new scroll pane, containing a component.
      static WidgetFactory.ScrollTextArea buildScrollTextArea​(java.awt.Color bg)  
      static javax.swing.JTextArea buildTextArea​(java.lang.String text, boolean isEditable)
      Builds a new text area.
      static javax.swing.JButton buildTextButton​(java.lang.String text, java.lang.String toolTip, java.lang.String action, java.awt.event.ActionListener listener)
      Helper method to build a text button.
      static javax.swing.JTextField buildTextField​(java.lang.String text)
      Helper method to create a text field with the proper font and font color.
      static javax.swing.border.Border buildTitledBorder​(java.lang.String title)
      Builds a titled border with the given title, an etched border, and the proper font and color.
      static javax.swing.border.Border buildToolbarBorder()
      Builds a new border of the type used by toolbars.
      static java.awt.Dimension getDefaultButtonSize()
      Returns the default size used for most text buttons.
      static javax.swing.ImageIcon getIcon​(java.lang.String name)
      Finds the icon of the specified name.
      static java.awt.Image getIconImage​(java.lang.String name)
      Finds the image of the specified name.
      static javax.swing.JToolBar initToolbar()
      Create a blank toolbar and set it up.
      static javax.swing.JButton makeToolbarSeparator()
      Makes a separator for the use in the toolbars - a button with the proper icon.
      • Methods inherited from class java.lang.Object

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

      • font10

        public static final java.awt.Font font10
        A 10 point, plain, serif font.
      • font12

        public static final java.awt.Font font12
        A 12 point, plain, serif font.
      • font12B

        public static final java.awt.Font font12B
        A 12 point, bold, serif font.
      • font12I

        public static final java.awt.Font font12I
        A 12 point, italic, serif font.
      • font13B

        public static final java.awt.Font font13B
        A 13 point, bold, serif font.
      • font14

        public static final java.awt.Font font14
        A 14 point, plain, serif font.
      • font14B

        public static final java.awt.Font font14B
        A 14 point, bold, serif font.
      • font16B

        public static final java.awt.Font font16B
        A 16 point, bold, serif font.
      • font18B

        public static final java.awt.Font font18B
        A 18 point, bold, serif font.
      • courier10

        public static final java.awt.Font courier10
        A 10 point, plain, courier font.
      • courier12

        public static final java.awt.Font courier12
        A 12 point, plain, courier font.
      • courier12B

        public static final java.awt.Font courier12B
        A 12 point, bold, courier font.
    • Constructor Detail

      • WidgetFactory

        public WidgetFactory()
    • Method Detail

      • buildCheckBox

        public static final javax.swing.JCheckBox buildCheckBox​(java.lang.String label,
                                                                boolean isSelected)
        Builds a new check box component.
        Parameters:
        label - the label to place in front of the check box
        isSelected - whether the check box should initially be selected
        Returns:
        the new check box
      • buildCheckBox

        public static final javax.swing.JCheckBox buildCheckBox​(java.lang.String label,
                                                                boolean isSelected,
                                                                java.awt.event.ItemListener listener)
        Builds a new check box component.
        Parameters:
        label - the label to place in front of the check box
        isSelected - whether the check box should initially be selected
        listener - the object to notify of ItemEvents generated by this check box (on selection/deselction)
        Returns:
        the new check box
      • buildLabel

        public static final javax.swing.JLabel buildLabel​(java.lang.String text)
        Builds a label with the proper font and font color.
        Parameters:
        text - text of the label
        Returns:
        the new label
      • buildPasswordField

        public static final javax.swing.JPasswordField buildPasswordField()
        Helper method to create a password field with the proper font and font color.
        Returns:
        New password field.
      • buildPressedButtonBorder

        public static final javax.swing.border.Border buildPressedButtonBorder()
        Builds a new border of the type used when a toggle button is depressed.
        Returns:
        a new border
      • buildRadioButton

        public static final javax.swing.JRadioButton buildRadioButton​(java.lang.String label,
                                                                      boolean isSelected,
                                                                      javax.swing.ButtonGroup group)
        Builds a new radio button component.
        Parameters:
        label - the label to place in front of the radio button
        isSelected - whether the check box should initially be selected
        group - the button group to add the new radio button to
        Returns:
        the new radio button
      • buildScrollPane

        public static final javax.swing.JScrollPane buildScrollPane​(javax.swing.JComponent component)
        Create a new scroll pane, containing a component.
        Parameters:
        component - the component to put inside the scroll pane
        Returns:
        the new scroll pane
      • buildScrollPane

        public static final javax.swing.JScrollPane buildScrollPane​(javax.swing.JComponent component,
                                                                    int preferredWidth,
                                                                    int preferredHeight)
        Create a new scroll pane, containing a component.
        Parameters:
        component - the component to put inside the scroll pane
        preferredWidth - the width of the scroll pane
        preferredHeight - the height of the scroll pane
        Returns:
        the new scroll pane
      • buildTextArea

        public static final javax.swing.JTextArea buildTextArea​(java.lang.String text,
                                                                boolean isEditable)
        Builds a new text area.
        Parameters:
        text - the text to put inside the text area
        isEditable - whether the text area should be editable by the user
        Returns:
        the new text area
      • buildTextButton

        public static final javax.swing.JButton buildTextButton​(java.lang.String text,
                                                                java.lang.String toolTip,
                                                                java.lang.String action,
                                                                java.awt.event.ActionListener listener)
        Helper method to build a text button.
        Parameters:
        text - Text for button.
        toolTip - Tool tip to be associated with button.
        action - Action command for button.
        listener - the listener for this button's actions
        Returns:
        a new text button
      • buildIconButton

        public static final javax.swing.JButton buildIconButton​(javax.swing.Icon icon,
                                                                java.lang.String toolTip,
                                                                java.lang.String action,
                                                                java.awt.event.ActionListener listener)
        Helper method to build a icon button.
        Parameters:
        icon - icon for button.
        toolTip - Tool tip to be associated with button.
        action - Action command for button.
        listener - the listener for this button's actions
        Returns:
        a new text button
      • buildTextField

        public static final javax.swing.JTextField buildTextField​(java.lang.String text)
        Helper method to create a text field with the proper font and font color.
        Parameters:
        text - Text int the field.
        Returns:
        New text field.
      • buildTitledBorder

        public static final javax.swing.border.Border buildTitledBorder​(java.lang.String title)
        Builds a titled border with the given title, an etched border, and the proper font and color.
        Parameters:
        title - the title of the border
        Returns:
        the titled border.
      • buildToolbarBorder

        public static final javax.swing.border.Border buildToolbarBorder()
        Builds a new border of the type used by toolbars.
        Returns:
        a new border
      • getDefaultButtonSize

        public static final java.awt.Dimension getDefaultButtonSize()
        Returns the default size used for most text buttons.
        Returns:
        the default text button size
      • getIcon

        public static final javax.swing.ImageIcon getIcon​(java.lang.String name)
        Finds the icon of the specified name. Uses the PlaceHolder class, which is in the same directory as the icons, to locate the icons.
        Parameters:
        name - name of the icon
        Returns:
        the icon
      • getIconImage

        public static final java.awt.Image getIconImage​(java.lang.String name)
                                                 throws java.io.FileNotFoundException
        Finds the image of the specified name. Uses the PlaceHolder class, which is in the same directory as the icons images, to locate the images.
        Parameters:
        name - name of the image
        Returns:
        the image
        Throws:
        java.io.FileNotFoundException - if we can't find the icon file
      • initToolbar

        public static final javax.swing.JToolBar initToolbar()
        Create a blank toolbar and set it up.
        Returns:
        a new toolbar
      • makeToolbarSeparator

        public static final javax.swing.JButton makeToolbarSeparator()
        Makes a separator for the use in the toolbars - a button with the proper icon.
        Returns:
        The new separator.