/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2013 ForgeRock AS.
*/
/**
* 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.
*
*/
public class UIFactory
{
private static boolean initialized = false;
/**
* Specifies the horizontal insets between buttons.
*/
/**
* Specifies the top inset for the steps.
*/
/**
* Specifies the left inset for the steps.
*/
/**
* Specifies the extra left inset for the sub-steps.
*/
/**
* Specifies the top inset for the instructions sub panel.
*/
/**
* Specifies the top inset for input subpanel.
*/
/**
* Specifies the top inset for a primary field.
*/
/**
* Specifies the top inset for a secondary field.
*/
/**
* Specifies the top inset for a radio button.
*/
/**
* Specifies the top inset for a radio button subordinate panel.
*/
/**
* Specifies the top inset for the progress bar.
*/
/**
* Specifies the top inset for the progress text area.
*/
/**
* Specifies the top inset for the background image.
*/
/**
* Specifies the top inset for the error message.
*/
/**
* Specifies the top inset for the browse button.
*/
/**
* Specifies the right inset for background image.
*/
/**
* Specifies the left inset for the primary field.
*/
/**
* Specifies the left inset for the browse button.
*/
/**
* Specifies the left inset for radio subordinate panel.
*/
/**
* Specifies the left inset for the secondary field.
*/
/**
* Specifies the left inset for the background image.
*/
/**
* Specifies the left inset for the copy url button.
*/
/**
* Specifies the left inset for a subordinate subpanel.
*/
/**
* Specifies the left inset for the progress bar.
*/
/**
* Specifies the bottom inset for the background image.
*/
/**
* Specifies the top inset for a secondary field.
*/
/**
* Specifies the number of columns of a text field for a path.
*/
/**
* Specifies the number of columns of a text field for a relative path.
*/
/**
* Specifies the number of columns of a text field for a host name.
*/
/**
* Specifies the number of columns of a text field for a UID.
*/
/**
* Specifies the number of columns of a text field for a port.
*/
/**
* Specifies the number of columns of a text field for a dn.
*/
/**
* Specifies the number of columns of a text field for a password.
*/
/**
* Specifies the number of columns of a text field for the number of entries.
*/
/**
* Specifies the number of points for the width of the progress bar.
*/
/**
* Specifies the number of extra points that we add to the minimum size of
* the dialog.
*/
/**
* Specifies the default background color.
*/
/**
* Specifies the current step background color.
*/
/**
* Specifies the default label color.
*/
/**
* Specifies the valid field color.
*/
/**
* Specifies the invalid field color.
*/
/**
* Specifies the read only text color.
*/
/**
* Specifies the check box text color.
*/
/**
* Specifies the progress text color.
*/
/**
* Specifies the instructions text color.
*/
/**
* Specifies the text field text color.
*/
/**
* Specifies the password field text color.
*/
/**
* Specifies the in-line help text color.
*/
/**
* Specifies the panel border color.
*/
/**
* Specifies the current step panel border.
*/
/**
* Specifies the text area border.
*/
/**
* Specifies the dialog border.
*/
static
{
try
{
deriveFont(12f);
}
catch (Throwable t)
{
}
}
/**
* Specifies the font for the step which is not the current one in the steps
* panel.
*/
/**
* Specifies the font for the step which is the current one in the steps
* panel.
*/
/**
* Specifies the font for the title of the current panel.
*/
/**
* Specifies the font for the instructions of the current panel.
*/
/**
* Specifies the font for the instructions of the current panel.
*/
/**
* Specifies the font for the primary valid field.
*/
/**
* Specifies the font for the secondary valid field.
*/
/**
* Specifies the font for the primary invalid field.
*/
/**
* Specifies the font for the secondary invalid field.
*/
/**
* Specifies the font for the secondary status field.
*/
/**
* Specifies the font for read only text.
*/
/**
* Specifies the font for the check box text.
*/
/**
* Specifies the font for the progress text.
*/
/**
* Specifies the font for the text field text.
*/
/**
* Specifies the font for the password field text.
*/
/**
* Specifies the font for the points '....' in the progress panel.
*/
/**
* Specifies the font for the done text 'Done' in the progress panel.
*/
/**
* Specifies the font for the log messages in the progress panel.
*/
/**
* Specifies the font for the error log messages in the progress panel.
*/
/**
* Specifies the font for the error messages in the progress panel.
*/
/**
* Specifies the font for the warning messages in the progress panel.
*/
/**
* Specifies the font for the stack trace in the progress panel.
*/
/**
* Specifies the font for the text in the WebBrowserErrorDialog.
*/
/**
* Specifies the font for the text in the in-line help.
*/
"<div style=\"color:#"+
";background-color:#"+
";padding:10px 10px 10px 10px;"+
"border-style:solid;border-width:3px;border-color:#"+
";vertical-align:middle;text-align:left\">";
"<div style=\"color:#"+
";background-color:#"+
";padding:10px 10px 10px 10px;"+
"border-style:solid;border-width:3px;border-color:#"+
";vertical-align:middle;text-align:left\">";
/**
* An HTML separator text that can be used in the progress panel.
*/
"<div style=\"font-size:1px;background-color:#"+
";margin:10px 5px 10px 5px;\"></div>";
/**
* The following enumeration contains the different icons that we can have.
*
*/
public enum IconType
{
/**
* Splash Icon.
*/
/**
* Current Step Icon.
*/
/**
* The icon displayed by the OS when the dialog is minimized.
*/
/**
* The icon displayed by the Mac OS when the dialog is minimized.
*/
/**
* The background icon.
*/
/**
* The warning icon.
*/
/**
* The warning large icon.
*/
/**
* The error icon.
*/
/**
* The error large icon.
*/
/**
* The information icon.
*/
/**
* The information large icon.
*/
/**
* Icon to create subsection title in Status Panel.
*/
/**
* Icon to create subsection title in Status Panel.
*/
/**
* Question icon.
*/
/**
* Hourglass to display when the user must wait.
*/
WAIT,
/**
* 8 x 8 Hourglass to display when the user must wait.
*/
/**
* No icon.
*/
}
/**
* The following enumeration contains the different text styles that we can
* have. A text style basically specifies the font and color to be used to
* render the text.
*
*/
public enum TextStyle
{
/**
* Current Step label style for the steps panel.
*/
/**
* Not current Step label style for the steps panel.
*/
/**
* Title label style for the current step panel.
*/
/**
* Primary field valid label style for the current step panel.
*/
/**
* Primary field invalid text style for the current step panel.
*/
/**
* Secondary field valid text style for the current step panel.
*/
/**
* Secondary field invalid text style for the current step panel.
*/
/**
* Status messages that appear near components.
*/
/**
* Textfield text style for the current step panel.
*/
/**
* Password text style for the current step panel.
*/
/**
* Read only text style for the current step panel.
*/
/**
* Check box text text style for the current step panel.
*/
/**
* Progress messages text style for the current step panel.
*/
/**
* Text style for the instructions.
*/
/**
* In-line help style.
*/
/**
* No text style.
*/
}
/**
* This method initialize the look and feel.
* @throws Throwable if there is a problem initializing the look and feel.
*/
{
{
public void run()
{
try
{
if (lf.equalsIgnoreCase(
"com.sun.java.swing.plaf.motif.MotifLookAndFeel"))
{
}
} catch (Throwable t)
{
ts[0] = t;
}
JFrame.setDefaultLookAndFeelDecorated(false);
}
};
{
r.run();
}
else
{
try
{
}
catch (Throwable t)
{
ts[0] = t;
}
}
{
throw ts[0];
}
}
/**
* 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.
*/
{
if (!initialized)
{
try
{
}
catch (Throwable t)
{
// This might occur when we do not get the display
}
initialized = true;
}
}
/**
* Creates a new JPanel.
* @return JPanel newly created
*/
return pnl;
}
/**
* Creates a JButton with the given label and tooltip.
* @param label the text of the button.
* @param tooltip the tooltip of the button.
* @return a JButton with the given label and tooltip.
*/
{
{
}
{
}
b.setOpaque(false);
return b;
}
/**
* Commodity method that returns a JLabel based on a LabelFieldDescriptor.
* @param desc the LabelFieldDescriptor describing the JLabel.
* @return a JLabel based on a LabelFieldDescriptor.
*/
{
{
} else
{
}
}
/**
* Creates a JLabel with the given icon, text and text style.
* @param iconName the icon.
* @param text the label text.
* @param style the text style.
* @return a JLabel with the given icon, text and text style.
*/
{
{
}
{
}
setTextStyle(l, style);
return l;
}
/**
* Commodity method that returns a JTextComponent based on a
* LabelFieldDescriptor.
* @param desc the LabelFieldDescriptor describing the JTextField.
* @param defaultValue the default value used to initialize the
* JTextComponent.
* @return a JTextComponent based on a
* LabelFieldDescriptor.
*/
{
{
case TEXTFIELD:
field =
break;
case PASSWORD:
field =
break;
case READ_ONLY:
field =
break;
default:
}
return field;
}
/**
* Creates a JTextField with the given icon, tooltip text, size and text
* style.
* @param text the text.
* @param tooltip the tooltip text.
* @param size the number of columns of the JTextField.
* @param style the text style.
* @return a JTextField with the given icon, tooltip text, size and text
* style.
*/
{
JTextField f = new JTextField();
f.addFocusListener(new TextFieldFocusListener(f));
return f;
}
/**
* Creates a JPasswordField with the given icon, tooltip text, size and text
* style.
* @param text the text.
* @param tooltip the tooltip text.
* @param size the number of columns of the JPasswordField.
* @param style the text style.
* @return a JPasswordField with the given icon, tooltip text, size and text
* style.
*/
{
JPasswordField f = new JPasswordField();
f.addFocusListener(new TextFieldFocusListener(f));
return f;
}
/**
* Creates a JRadioButton with the given text, tooltip text and text
* style.
* @param text the text of the radio button.
* @param tooltip the tooltip text.
* @param style the text style.
* @return a JRadioButton with the given text, tooltip text and text
* style.
*/
{
{
}
{
}
return rb;
}
/**
* Creates a JCheckBox with the given text, tooltip text and text
* style.
* @param text the text of the radio button.
* @param tooltip the tooltip text.
* @param style the text style.
* @return a JCheckBox with the given text, tooltip text and text
* style.
*/
{
{
}
{
}
return cb;
}
/**
* Creates a JList.
*
* @param textStyle the style to be used for the renderer.
* @return a JList.
*/
{
return list;
}
/**
* Sets the specified text style to the component passed as parameter.
* @param l the component to update.
* @param style the text style to use.
*/
{
switch (style)
{
case NOT_CURRENT_STEP:
break;
case CURRENT_STEP:
break;
case TITLE:
break;
case PRIMARY_FIELD_VALID:
break;
case PRIMARY_FIELD_INVALID:
break;
case SECONDARY_FIELD_VALID:
break;
case SECONDARY_FIELD_INVALID:
break;
case SECONDARY_STATUS:
break;
case READ_ONLY:
break;
case CHECKBOX:
break;
case PROGRESS:
break;
case INSTRUCTIONS:
break;
case TEXTFIELD:
break;
case PASSWORD_FIELD:
break;
case INLINE_HELP:
break;
case NO_STYLE:
// Do nothing
break;
default:
}
}
/**
* Returns the HTML string representing the provided IconType.
* @param iconType the IconType for which we want the HTML representation.
* @return the HTML string representing the provided IconType.
*/
{
getIconPath(iconType)));
}
/**
* Returns an ImageIcon object for the provided IconType.
* @param iconType the IconType for which we want to obtain the ImageIcon.
* @return the ImageIcon.
*/
{
}
{
try
{
{
ex);
}
}
return icon;
}
/**
* Returns a JEditorPane that works with the provided scroll.
* @see ProgressJEditorPane
* @param scroll the scroll that will contain the JEditorPane.
* @return a JEditorPane that works with the provided scroll.
*/
{
return new ProgressJEditorPane(scroll);
}
/**
* Returns a read only JEditorPane containing the provided text with the
* provided font. The JEditorPane will assume that the text is HTML text.
* @param text the text to be used to initialize the JEditorPane contents.
* @param font the font to be used.
* @return a read only JEditorPane containing the provided text with the
* provided font.
*/
{
}
/**
* Returns a read only JEditorPane containing the provided text with the
* provided font. The JEditorPane will assume that the text is HTML text.
* @param text the text to be used to initialize the JEditorPane contents.
* @param ek HTMLEditor kit used for the new HTML pane
* @param font the font to be used.
* @return a read only JEditorPane containing the provided text with the
* provided font.
*/
{
pane.setEditable(false);
return pane;
}
/**
* Returns a read only JEditorPane containing the provided text with the
* provided TextStyle. The JEditorPane will assume that the text is plain
* text.
* @param text the text to be used to initialize the JEditorPane contents.
* @param style the TextStyle to be used.
* @return a read only JEditorPane containing the provided text with the
* provided TextStyle.
*/
{
pane.setEditable(false);
return pane;
}
/**
* Returns a JScrollPane that contains the provided component. The scroll
* pane will not contain any border.
* @param comp the component contained in the scroll pane.
* @return a JScrollPane that contains the provided component. The scroll
* pane will not contain any border.
*/
{
return scroll;
}
/**
* Sets the scroll increment unit for the scroll.
* @param scroll the scroll to be updated.
*/
{
{
if (increment < 16)
{
}
}
}
/**
* Return empty insets.
* @return empty insets.
*/
{
}
/**
* Returns the insets to be used for the button panel.
* @return the insets to be used for the button panel.
*/
{
}
/**
* Returns the insets to be used for the steps panel.
* @return the insets to be used for the steps panel.
*/
{
}
/**
* Returns the insets to be used for the current step panel.
* @return the insets to be used for the current step panel.
*/
{
}
/**
* 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.
*
* @param html the original html text.
* @param font the font to be used to generate the new HTML.
* @return a string that represents the original HTML with the font specified
* as parameter.
*/
{
}
/**
* Returns a String that contains the html passed as parameter with a div
* applied. The div 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.
*
* @param html the original html text.
* @param font the font to be used to generate the new HTML.
* @return a string that represents the original HTML with the font specified
* as parameter.
*/
{
}
/**
* Returns the HTML style representation for the given font.
* @param font the font for which we want to get an HTML style representation.
* @return the HTML style representation for the given font.
*/
{
.append(";font-size:")
.append("pt");
{
}
{
}
}
/**
* Returns the html text passed as parameter with the error background
* applied to it.
* @param html the original html.
* @return the html text passed as parameter with the error background
* applied to it.
*/
{
}
/**
* Returns the html text passed as parameter with the warning background
* applied to it.
* @param html the original html.
* @return the html text passed as parameter with the warning background
* applied to it.
*/
{
}
/**
* Returns the html text passed as parameter with the success background
* applied to it.
* @param html the original html.
* @return the html text passed as parameter with the success background
* applied to it.
*/
{
}
/**
* Returns the html text passed as parameter with some added margin.
* @param html the original html text.
* @param top the top margin.
* @param right the right margin.
* @param bottom the bottom margin.
* @param left the left margin.
* @return the html text passed as parameter with some added margin.
*/
int left)
{
}
/**
* Updates the provided field with all the other arguments.
* @param field the field to be modified.
* @param text the new text of the field.
* @param tooltip the new tooltip text of the field.
* @param size the new size of the field.
* @param textStyle the new TextStyle of the field.
*/
{
{
}
{
}
{
}
}
{
return new Color(r, g, b);
}
/**
* Returns the parent package path. This is used to retrieve the icon
* qualified names.
* @return the parent package path.
*/
{
if (parentPackagePath == null)
{
}
return parentPackagePath;
}
/**
* Returns the path of the icon for the given IconType.
* @param iconType the IconType for which we want to get the path.
* @return the path of the icon for the given IconType.
*/
{
switch (iconType)
{
case CURRENT_STEP:
break;
case SPLASH:
break;
case BACKGROUND:
break;
case MINIMIZED:
break;
case MINIMIZED_MAC:
break;
case WARNING:
break;
case WARNING_LARGE:
break;
case INFORMATION:
break;
case INFORMATION_LARGE:
break;
case SUBSECTION_LEFT:
break;
case SUBSECTION_RIGHT:
break;
case HELP_SMALL:
break;
case ERROR:
break;
case ERROR_LARGE:
break;
case WAIT_TINY:
break;
case WAIT:
break;
default:
}
}
/**
* Returns the icon description for the given IconType.
* @param iconType the IconType for which we want to get the description.
* @return the icon description for the given IconType.
*/
{
switch (iconType)
{
case CURRENT_STEP:
break;
case SPLASH:
break;
case BACKGROUND:
break;
case MINIMIZED:
break;
case MINIMIZED_MAC:
break;
case WARNING:
break;
case WARNING_LARGE:
break;
case ERROR:
break;
case ERROR_LARGE:
break;
case INFORMATION:
break;
case INFORMATION_LARGE:
break;
case SUBSECTION_LEFT:
break;
case SUBSECTION_RIGHT:
break;
case HELP_SMALL:
break;
case WAIT_TINY:
break;
case WAIT:
break;
case NO_ICON:
description = null;
break;
default:
}
return description;
}
/**
* Returns the icon tooltip text for the given IconType.
* @param iconType the IconType for which we want to get the tooltip text.
* @return the icon tooltip text for the given IconType.
*/
{
}
switch (iconType)
{
case CURRENT_STEP:
break;
case SPLASH:
break;
case BACKGROUND:
break;
case MINIMIZED:
break;
case MINIMIZED_MAC:
break;
case WARNING:
break;
case WARNING_LARGE:
break;
case ERROR:
break;
case ERROR_LARGE:
break;
case INFORMATION:
break;
case INFORMATION_LARGE:
break;
case SUBSECTION_LEFT:
break;
case SUBSECTION_RIGHT:
break;
case HELP_SMALL:
break;
case WAIT_TINY:
break;
case WAIT:
break;
case NO_ICON:
break;
default:
}
return tooltip;
}
{
return new ListCellRenderer()
{
int index,
boolean isSelected,
boolean cellHasFocus)
{
return l;
}
};
}
}
/**
* This class has been written to have a better behaviour with the scroll pane
* than the one we have by default in the case of the progress panel.
*
* With the default scroll pane behaviour when we set a new text in a
* JEditorPane the scroll bar goes systematically up. With this implementation
* the expected behaviour is:
*
* If the scroll bar is at the bottom we will display the latest text contained
* in the pane.
*
* If the scroll bar is not at the bottom we will keep on displaying the same
* thing that the user is viewing.
*
* This behaviour allows the user to check the log content even when the
* installation/uninstallation is still running and sending new log messages.
*
*/
{
private boolean ignoreScrollToVisible;
/**
* Constructor for the ProgressJEditorPane.
* @param scroll the JScrollPane that will contain this editor pane.
*/
{
setEditable(false);
}
/**
* {@inheritDoc}
*/
{
// Scroll can be null in constructor
{
/* We apply the following policy: if the user is displaying the latest
* part of the JTextArea we assume that when we add text (s)he wants
* to see the text that is added, if not we assume that (s)he want to keep
* viewing what is visible and so we ignore the next scrollRectToVisible
* call (that will be done inside JTextArea.setText method).
*/
.getMaximum());
}
}
/**
* {@inheritDoc}
*/
{
if (!ignoreScrollToVisible)
{
super.scrollRectToVisible(rect);
ignoreScrollToVisible = false;
}
}
}
/**
* A class used to be able to select the contents of the text field when
* it gets the focus.
*
*/
{
/**
* The constructor for this listener.
* @param tf the text field associated with this listener.
*/
{
}
/**
* {@inheritDoc}
*/
{
{
}
else
{
}
}
/**
* {@inheritDoc}
*/
{
}
}