Class UIFactory


  • public class UIFactory
    extends Object
    This class provides constants an methods to create Swing objects and to generate UI elements with a common look and feel.

    When we want to change a color, a background or a font this is the class that should be modified.

    • Field Detail

      • HORIZONTAL_INSET_BETWEEN_BUTTONS

        public static final int HORIZONTAL_INSET_BETWEEN_BUTTONS
        Specifies the horizontal insets between buttons.
        See Also:
        Constant Field Values
      • TOP_INSET_STEP

        public static final int TOP_INSET_STEP
        Specifies the top inset for the steps.
        See Also:
        Constant Field Values
      • LEFT_INSET_STEP

        public static final int LEFT_INSET_STEP
        Specifies the left inset for the steps.
        See Also:
        Constant Field Values
      • LEFT_INSET_SUBSTEP

        public static final int LEFT_INSET_SUBSTEP
        Specifies the extra left inset for the sub-steps.
        See Also:
        Constant Field Values
      • TOP_INSET_INSTRUCTIONS_SUBPANEL

        public static final int TOP_INSET_INSTRUCTIONS_SUBPANEL
        Specifies the top inset for the instructions sub panel.
        See Also:
        Constant Field Values
      • TOP_INSET_INPUT_SUBPANEL

        public static final int TOP_INSET_INPUT_SUBPANEL
        Specifies the top inset for input subpanel.
        See Also:
        Constant Field Values
      • TOP_INSET_PRIMARY_FIELD

        public static final int TOP_INSET_PRIMARY_FIELD
        Specifies the top inset for a primary field.
        See Also:
        Constant Field Values
      • TOP_INSET_SECONDARY_FIELD

        public static final int TOP_INSET_SECONDARY_FIELD
        Specifies the top inset for a secondary field.
        See Also:
        Constant Field Values
      • TOP_INSET_RADIOBUTTON

        public static final int TOP_INSET_RADIOBUTTON
        Specifies the top inset for a radio button.
        See Also:
        Constant Field Values
      • TOP_INSET_RADIO_SUBORDINATE

        public static final int TOP_INSET_RADIO_SUBORDINATE
        Specifies the top inset for a radio button subordinate panel.
        See Also:
        Constant Field Values
      • TOP_INSET_PROGRESS_BAR

        public static final int TOP_INSET_PROGRESS_BAR
        Specifies the top inset for the progress bar.
        See Also:
        Constant Field Values
      • TOP_INSET_PROGRESS_TEXTAREA

        public static final int TOP_INSET_PROGRESS_TEXTAREA
        Specifies the top inset for the progress text area.
        See Also:
        Constant Field Values
      • TOP_INSET_BACKGROUND

        public static final int TOP_INSET_BACKGROUND
        Specifies the top inset for the background image.
        See Also:
        Constant Field Values
      • TOP_INSET_ERROR_MESSAGE

        public static final int TOP_INSET_ERROR_MESSAGE
        Specifies the top inset for the error message.
        See Also:
        Constant Field Values
      • TOP_INSET_BROWSE

        public static final int TOP_INSET_BROWSE
        Specifies the top inset for the browse button.
        See Also:
        Constant Field Values
      • RIGHT_INSET_BACKGROUND

        public static final int RIGHT_INSET_BACKGROUND
        Specifies the right inset for background image.
        See Also:
        Constant Field Values
      • LEFT_INSET_PRIMARY_FIELD

        public static final int LEFT_INSET_PRIMARY_FIELD
        Specifies the left inset for the primary field.
        See Also:
        Constant Field Values
      • LEFT_INSET_BROWSE

        public static final int LEFT_INSET_BROWSE
        Specifies the left inset for the browse button.
        See Also:
        Constant Field Values
      • LEFT_INSET_RADIO_SUBORDINATE

        public static final int LEFT_INSET_RADIO_SUBORDINATE
        Specifies the left inset for radio subordinate panel.
        See Also:
        Constant Field Values
      • LEFT_INSET_SECONDARY_FIELD

        public static final int LEFT_INSET_SECONDARY_FIELD
        Specifies the left inset for the secondary field.
        See Also:
        Constant Field Values
      • LEFT_INSET_BACKGROUND

        public static final int LEFT_INSET_BACKGROUND
        Specifies the left inset for the background image.
        See Also:
        Constant Field Values
      • LEFT_INSET_COPY_BUTTON

        public static final int LEFT_INSET_COPY_BUTTON
        Specifies the left inset for the copy url button.
        See Also:
        Constant Field Values
      • LEFT_INSET_SUBPANEL_SUBORDINATE

        public static final int LEFT_INSET_SUBPANEL_SUBORDINATE
        Specifies the left inset for a subordinate subpanel.
        See Also:
        Constant Field Values
      • BOTTOM_INSET_PROGRESS_BAR

        public static final int BOTTOM_INSET_PROGRESS_BAR
        Specifies the left inset for the progress bar.
        See Also:
        Constant Field Values
      • BOTTOM_INSET_BACKGROUND

        public static final int BOTTOM_INSET_BACKGROUND
        Specifies the bottom inset for the background image.
        See Also:
        Constant Field Values
      • BOTTOM_INSET_SECONDARY_FIELD

        public static final int BOTTOM_INSET_SECONDARY_FIELD
        Specifies the top inset for a secondary field.
        See Also:
        Constant Field Values
      • PATH_FIELD_SIZE

        public static final int PATH_FIELD_SIZE
        Specifies the number of columns of a text field for a path.
        See Also:
        Constant Field Values
      • RELATIVE_PATH_FIELD_SIZE

        public static final int RELATIVE_PATH_FIELD_SIZE
        Specifies the number of columns of a text field for a relative path.
        See Also:
        Constant Field Values
      • HOST_FIELD_SIZE

        public static final int HOST_FIELD_SIZE
        Specifies the number of columns of a text field for a host name.
        See Also:
        Constant Field Values
      • UID_FIELD_SIZE

        public static final int UID_FIELD_SIZE
        Specifies the number of columns of a text field for a UID.
        See Also:
        Constant Field Values
      • PORT_FIELD_SIZE

        public static final int PORT_FIELD_SIZE
        Specifies the number of columns of a text field for a port.
        See Also:
        Constant Field Values
      • DN_FIELD_SIZE

        public static final int DN_FIELD_SIZE
        Specifies the number of columns of a text field for a dn.
        See Also:
        Constant Field Values
      • PASSWORD_FIELD_SIZE

        public static final int PASSWORD_FIELD_SIZE
        Specifies the number of columns of a text field for a password.
        See Also:
        Constant Field Values
      • NUMBER_ENTRIES_FIELD_SIZE

        public static final int NUMBER_ENTRIES_FIELD_SIZE
        Specifies the number of columns of a text field for the number of entries.
        See Also:
        Constant Field Values
      • PROGRESS_BAR_SIZE

        public static final int PROGRESS_BAR_SIZE
        Specifies the number of points for the width of the progress bar.
        See Also:
        Constant Field Values
      • EXTRA_DIALOG_HEIGHT

        public static final int EXTRA_DIALOG_HEIGHT
        Specifies the number of extra points that we add to the minimum size of the dialog.
        See Also:
        Constant Field Values
      • DEFAULT_BACKGROUND

        public static final Color DEFAULT_BACKGROUND
        Specifies the default background color.
      • CURRENT_STEP_PANEL_BACKGROUND

        public static final Color CURRENT_STEP_PANEL_BACKGROUND
        Specifies the current step background color.
      • DEFAULT_LABEL_COLOR

        public static final Color DEFAULT_LABEL_COLOR
        Specifies the default label color.
      • FIELD_VALID_COLOR

        public static final Color FIELD_VALID_COLOR
        Specifies the valid field color.
      • FIELD_INVALID_COLOR

        public static final Color FIELD_INVALID_COLOR
        Specifies the invalid field color.
      • READ_ONLY_COLOR

        public static final Color READ_ONLY_COLOR
        Specifies the read only text color.
      • CHECKBOX_COLOR

        public static final Color CHECKBOX_COLOR
        Specifies the check box text color.
      • PROGRESS_COLOR

        public static final Color PROGRESS_COLOR
        Specifies the progress text color.
      • INSTRUCTIONS_COLOR

        public static final Color INSTRUCTIONS_COLOR
        Specifies the instructions text color.
      • TEXTFIELD_COLOR

        public static final Color TEXTFIELD_COLOR
        Specifies the text field text color.
      • PASSWORDFIELD_COLOR

        public static final Color PASSWORDFIELD_COLOR
        Specifies the password field text color.
      • INLINE_HELP_COLOR

        public static final Color INLINE_HELP_COLOR
        Specifies the in-line help text color.
      • PANEL_BORDER_COLOR

        public static final Color PANEL_BORDER_COLOR
        Specifies the panel border color.
      • CURRENT_STEP_PANEL_BORDER

        public static final Border CURRENT_STEP_PANEL_BORDER
        Specifies the current step panel border.
      • TEXT_AREA_BORDER

        public static final Border TEXT_AREA_BORDER
        Specifies the text area border.
      • DIALOG_PANEL_BORDER

        public static final Border DIALOG_PANEL_BORDER
        Specifies the dialog border.
      • NOT_CURRENT_STEP_FONT

        public static final Font NOT_CURRENT_STEP_FONT
        Specifies the font for the step which is not the current one in the steps panel.
      • CURRENT_STEP_FONT

        public static final Font CURRENT_STEP_FONT
        Specifies the font for the step which is the current one in the steps panel.
      • TITLE_FONT

        public static final Font TITLE_FONT
        Specifies the font for the title of the current panel.
      • INSTRUCTIONS_FONT

        public static final Font INSTRUCTIONS_FONT
        Specifies the font for the instructions of the current panel.
      • INSTRUCTIONS_MONOSPACE_FONT

        public static final Font INSTRUCTIONS_MONOSPACE_FONT
        Specifies the font for the instructions of the current panel.
      • PRIMARY_FIELD_VALID_FONT

        public static final Font PRIMARY_FIELD_VALID_FONT
        Specifies the font for the primary valid field.
      • SECONDARY_FIELD_VALID_FONT

        public static final Font SECONDARY_FIELD_VALID_FONT
        Specifies the font for the secondary valid field.
      • PRIMARY_FIELD_INVALID_FONT

        public static final Font PRIMARY_FIELD_INVALID_FONT
        Specifies the font for the primary invalid field.
      • SECONDARY_FIELD_INVALID_FONT

        public static final Font SECONDARY_FIELD_INVALID_FONT
        Specifies the font for the secondary invalid field.
      • SECONDARY_STATUS_FONT

        public static final Font SECONDARY_STATUS_FONT
        Specifies the font for the secondary status field.
      • READ_ONLY_FONT

        public static final Font READ_ONLY_FONT
        Specifies the font for read only text.
      • CHECKBOX_FONT

        public static final Font CHECKBOX_FONT
        Specifies the font for the check box text.
      • PROGRESS_FONT

        public static final Font PROGRESS_FONT
        Specifies the font for the progress text.
      • TEXTFIELD_FONT

        public static final Font TEXTFIELD_FONT
        Specifies the font for the text field text.
      • PASSWORD_FIELD_FONT

        public static final Font PASSWORD_FIELD_FONT
        Specifies the font for the password field text.
      • PROGRESS_POINTS_FONT

        public static final Font PROGRESS_POINTS_FONT
        Specifies the font for the points '....' in the progress panel.
      • PROGRESS_DONE_FONT

        public static final Font PROGRESS_DONE_FONT
        Specifies the font for the done text 'Done' in the progress panel.
      • PROGRESS_LOG_FONT

        public static final Font PROGRESS_LOG_FONT
        Specifies the font for the log messages in the progress panel.
      • PROGRESS_LOG_ERROR_FONT

        public static final Font PROGRESS_LOG_ERROR_FONT
        Specifies the font for the error log messages in the progress panel.
      • PROGRESS_ERROR_FONT

        public static final Font PROGRESS_ERROR_FONT
        Specifies the font for the error messages in the progress panel.
      • PROGRESS_WARNING_FONT

        public static final Font PROGRESS_WARNING_FONT
        Specifies the font for the warning messages in the progress panel.
      • STACK_FONT

        public static final Font STACK_FONT
        Specifies the font for the stack trace in the progress panel.
      • ERROR_DIALOG_FONT

        public static final Font ERROR_DIALOG_FONT
        Specifies the font for the text in the WebBrowserErrorDialog.
      • INLINE_HELP_FONT

        public static final Font INLINE_HELP_FONT
        Specifies the font for the text in the in-line help.
      • HTML_SEPARATOR

        public static final String HTML_SEPARATOR
        An HTML separator text that can be used in the progress panel.
    • Constructor Detail

      • UIFactory

        public UIFactory()
    • Method Detail

      • initializeLookAndFeel

        public static void initializeLookAndFeel()
                                          throws Throwable
        This method initialize the look and feel.
        Throws:
        Throwable - if there is a problem initializing the look and feel.
      • initialize

        public static void initialize()
                               throws Throwable
        This method initialize the look and feel and UI settings specific to quick setup.
        Throws:
        Throwable - if there is a problem initializing the look and feel.
      • makeJPanel

        public static JPanel makeJPanel()
        Creates a new JPanel.
        Returns:
        JPanel newly created
      • makeJButton

        public static JButton makeJButton​(org.forgerock.i18n.LocalizableMessage label,
                                          org.forgerock.i18n.LocalizableMessage tooltip)
        Creates a JButton with the given label and tooltip.
        Parameters:
        label - the text of the button.
        tooltip - the tooltip of the button.
        Returns:
        a JButton with the given label and tooltip.
      • makeJLabel

        public static JLabel makeJLabel​(LabelFieldDescriptor desc)
        Commodity method that returns a JLabel based on a LabelFieldDescriptor.
        Parameters:
        desc - the LabelFieldDescriptor describing the JLabel.
        Returns:
        a JLabel based on a LabelFieldDescriptor.
      • makeJLabel

        public static JLabel makeJLabel​(UIFactory.IconType iconName,
                                        org.forgerock.i18n.LocalizableMessage text,
                                        UIFactory.TextStyle style)
        Creates a JLabel with the given icon, text and text style.
        Parameters:
        iconName - the icon.
        text - the label text.
        style - the text style.
        Returns:
        a JLabel with the given icon, text and text style.
      • makeJTextComponent

        public static JTextComponent makeJTextComponent​(LabelFieldDescriptor desc,
                                                        String defaultValue)
        Commodity method that returns a JTextComponent based on a LabelFieldDescriptor.
        Parameters:
        desc - the LabelFieldDescriptor describing the JTextField.
        defaultValue - the default value used to initialize the JTextComponent.
        Returns:
        a JTextComponent based on a LabelFieldDescriptor.
      • makeJTextField

        public static JTextField makeJTextField​(org.forgerock.i18n.LocalizableMessage text,
                                                org.forgerock.i18n.LocalizableMessage tooltip,
                                                int size,
                                                UIFactory.TextStyle style)
        Creates a JTextField with the given icon, tooltip text, size and text style.
        Parameters:
        text - the text.
        tooltip - the tooltip text.
        size - the number of columns of the JTextField.
        style - the text style.
        Returns:
        a JTextField with the given icon, tooltip text, size and text style.
      • makeJPasswordField

        public static JPasswordField makeJPasswordField​(org.forgerock.i18n.LocalizableMessage text,
                                                        org.forgerock.i18n.LocalizableMessage tooltip,
                                                        int size,
                                                        UIFactory.TextStyle style)
        Creates a JPasswordField with the given icon, tooltip text, size and text style.
        Parameters:
        text - the text.
        tooltip - the tooltip text.
        size - the number of columns of the JPasswordField.
        style - the text style.
        Returns:
        a JPasswordField with the given icon, tooltip text, size and text style.
      • makeJRadioButton

        public static JRadioButton makeJRadioButton​(org.forgerock.i18n.LocalizableMessage text,
                                                    org.forgerock.i18n.LocalizableMessage tooltip,
                                                    UIFactory.TextStyle style)
        Creates a JRadioButton with the given text, tooltip text and text style.
        Parameters:
        text - the text of the radio button.
        tooltip - the tooltip text.
        style - the text style.
        Returns:
        a JRadioButton with the given text, tooltip text and text style.
      • makeJCheckBox

        public static JCheckBox makeJCheckBox​(org.forgerock.i18n.LocalizableMessage text,
                                              org.forgerock.i18n.LocalizableMessage tooltip,
                                              UIFactory.TextStyle style)
        Creates a JCheckBox with the given text, tooltip text and text style.
        Parameters:
        text - the text of the radio button.
        tooltip - the tooltip text.
        style - the text style.
        Returns:
        a JCheckBox with the given text, tooltip text and text style.
      • makeJList

        public static <T> JList<T> makeJList​(UIFactory.TextStyle textStyle)
        Creates a JList.
        Type Parameters:
        T - The type of the JList elements
        Parameters:
        textStyle - the style to be used for the renderer.
        Returns:
        a JList.
      • setTextStyle

        public static void setTextStyle​(JComponent l,
                                        UIFactory.TextStyle style)
        Sets the specified text style to the component passed as parameter.
        Parameters:
        l - the component to update.
        style - the text style to use.
      • getIconHtml

        public static String getIconHtml​(UIFactory.IconType iconType)
        Returns the HTML string representing the provided IconType.
        Parameters:
        iconType - the IconType for which we want the HTML representation.
        Returns:
        the HTML string representing the provided IconType.
      • getImageIcon

        public static ImageIcon getImageIcon​(UIFactory.IconType iconType)
        Returns an ImageIcon object for the provided IconType.
        Parameters:
        iconType - the IconType for which we want to obtain the ImageIcon.
        Returns:
        the ImageIcon.
      • makeProgressPane

        public static JEditorPane makeProgressPane​(JScrollPane scroll)
        Returns a JEditorPane that works with the provided scroll.
        Parameters:
        scroll - the scroll that will contain the JEditorPane.
        Returns:
        a JEditorPane that works with the provided scroll.
        See Also:
        ProgressJEditorPane
      • makeHtmlPane

        public static JEditorPane makeHtmlPane​(org.forgerock.i18n.LocalizableMessage text,
                                               Font font)
        Returns a read only JEditorPane containing the provided text with the provided font. The JEditorPane will assume that the text is HTML text.
        Parameters:
        text - the text to be used to initialize the JEditorPane contents.
        font - the font to be used.
        Returns:
        a read only JEditorPane containing the provided text with the provided font.
      • makeTextPane

        public static JEditorPane makeTextPane​(org.forgerock.i18n.LocalizableMessage text,
                                               UIFactory.TextStyle style)
        Returns a read only JEditorPane containing the provided text with the provided TextStyle. The JEditorPane will assume that the text is plain text.
        Parameters:
        text - the text to be used to initialize the JEditorPane contents.
        style - the TextStyle to be used.
        Returns:
        a read only JEditorPane containing the provided text with the provided TextStyle.
      • createBorderLessScrollBar

        public static JScrollPane createBorderLessScrollBar​(Component comp)
        Returns a JScrollPane that contains the provided component. The scroll pane will not contain any border.
        Parameters:
        comp - the component contained in the scroll pane.
        Returns:
        a JScrollPane that contains the provided component. The scroll pane will not contain any border.
      • setScrollIncrementUnit

        public static void setScrollIncrementUnit​(JScrollPane scroll)
        Sets the scroll increment unit for the scroll.
        Parameters:
        scroll - the scroll to be updated.
      • getEmptyInsets

        public static Insets getEmptyInsets()
        Return empty insets.
        Returns:
        empty insets.
      • getButtonsPanelInsets

        public static Insets getButtonsPanelInsets()
        Returns the insets to be used for the button panel.
        Returns:
        the insets to be used for the button panel.
      • getStepsPanelInsets

        public static Insets getStepsPanelInsets()
        Returns the insets to be used for the steps panel.
        Returns:
        the insets to be used for the steps panel.
      • getCurrentStepPanelInsets

        public static Insets getCurrentStepPanelInsets()
        Returns the insets to be used for the current step panel.
        Returns:
        the insets to be used for the current step panel.
      • applyFontToHtml

        public static String applyFontToHtml​(String html,
                                             Font font)
        Returns a String that contains the html passed as parameter with a span applied. The span style corresponds to the Font specified as parameter. The goal of this method is to be able to specify a font for an HTML string.
        Parameters:
        html - the original html text.
        font - the font to be used to generate the new HTML.
        Returns:
        a string that represents the original HTML with the font specified as parameter.
      • applyErrorBackgroundToHtml

        public static String applyErrorBackgroundToHtml​(String html)
        Returns the html text passed as parameter with the error background applied to it.
        Parameters:
        html - the original html.
        Returns:
        the html text passed as parameter with the error background applied to it.
      • applyWarningBackgroundToHtml

        public static String applyWarningBackgroundToHtml​(String html)
        Returns the html text passed as parameter with the warning background applied to it.
        Parameters:
        html - the original html.
        Returns:
        the html text passed as parameter with the warning background applied to it.
      • applySuccessfulBackgroundToHtml

        public static String applySuccessfulBackgroundToHtml​(String html)
        Returns the html text passed as parameter with the success background applied to it.
        Parameters:
        html - the original html.
        Returns:
        the html text passed as parameter with the success background applied to it.
      • applyMargin

        public static String applyMargin​(String html,
                                         int top,
                                         int right,
                                         int bottom,
                                         int left)
        Returns the html text passed as parameter with some added margin.
        Parameters:
        html - the original html text.
        top - the top margin.
        right - the right margin.
        bottom - the bottom margin.
        left - the left margin.
        Returns:
        the html text passed as parameter with some added margin.