| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package org.opends.guitools.controlpanel.util; |
| | | |
| | |
| | | SelectableLabelWithHelpIcon; |
| | | import org.opends.guitools.controlpanel.ui.renderer. |
| | | AccessibleTableHeaderRenderer; |
| | | import org.opends.messages.Message; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.quicksetup.Installation; |
| | | import org.opends.quicksetup.ui.UIFactory; |
| | | import org.opends.quicksetup.util.Utils; |
| | |
| | | private static ImageIcon requiredIcon; |
| | | |
| | | |
| | | private static Message NO_VALUE_SET = |
| | | private static LocalizableMessage NO_VALUE_SET = |
| | | INFO_CTRL_PANEL_NO_MONITORING_VALUE.get(); |
| | | private static Message NOT_IMPLEMENTED = |
| | | private static LocalizableMessage NOT_IMPLEMENTED = |
| | | INFO_CTRL_PANEL_NOT_IMPLEMENTED.get(); |
| | | |
| | | /** |
| | |
| | | * @param errors the set of error messages that the dialog must display. |
| | | */ |
| | | public static void displayErrorDialog(Component parentComponent, |
| | | Collection<Message> errors) |
| | | Collection<LocalizableMessage> errors) |
| | | { |
| | | /* |
| | | ErrorPanel panel = new ErrorPanel("Error", errors); |
| | |
| | | dlg.setVisible(true); |
| | | */ |
| | | ArrayList<String> stringErrors = new ArrayList<String>(); |
| | | for (Message err : errors) |
| | | for (LocalizableMessage err : errors) |
| | | { |
| | | stringErrors.add(err.toString()); |
| | | } |
| | |
| | | * |
| | | */ |
| | | public static boolean displayConfirmationDialog(Component parentComponent, |
| | | Message title, Message msg) |
| | | LocalizableMessage title, LocalizableMessage msg) |
| | | { |
| | | String plainText = msg.toString().replaceAll("<br>", ServerConstants.EOL); |
| | | String wrappedText = StaticUtils.wrapText(plainText, 70); |
| | |
| | | * @param msg the message to be displayed. |
| | | */ |
| | | public static void displayWarningDialog(Component parentComponent, |
| | | Message title, Message msg) |
| | | LocalizableMessage title, LocalizableMessage msg) |
| | | { |
| | | String plainText = msg.toString().replaceAll("<br>", ServerConstants.EOL); |
| | | String wrappedText = StaticUtils.wrapText(plainText, 70); |
| | |
| | | * @param msg the message to be displayed in the titled border. |
| | | * @return the created titled border. |
| | | */ |
| | | public static Border makeTitledBorder(Message msg) |
| | | public static Border makeTitledBorder(LocalizableMessage msg) |
| | | { |
| | | TitledBorder border = new TitledBorder(new EtchedBorder(), |
| | | " "+msg+" "); |
| | |
| | | * @param text the message to be displayed by the button. |
| | | * @return the created button. |
| | | */ |
| | | public static JButton createButton(Message text) |
| | | public static JButton createButton(LocalizableMessage text) |
| | | { |
| | | JButton button = new JButton(text.toString()); |
| | | button.setOpaque(false); |
| | |
| | | * @param text the message to be displayed by the radio button. |
| | | * @return the created radio button. |
| | | */ |
| | | public static JRadioButton createRadioButton(Message text) |
| | | public static JRadioButton createRadioButton(LocalizableMessage text) |
| | | { |
| | | JRadioButton button = new JRadioButton(text.toString()); |
| | | button.setOpaque(false); |
| | |
| | | * @param text the message to be displayed by the check box. |
| | | * @return the created check box. |
| | | */ |
| | | public static JCheckBox createCheckBox(Message text) |
| | | public static JCheckBox createCheckBox(LocalizableMessage text) |
| | | { |
| | | JCheckBox cb = new JCheckBox(text.toString()); |
| | | cb.setOpaque(false); |
| | |
| | | * @param msg the text. |
| | | * @return a menu item with the provided text. |
| | | */ |
| | | public static JMenuItem createMenuItem(Message msg) |
| | | public static JMenuItem createMenuItem(LocalizableMessage msg) |
| | | { |
| | | return new JMenuItem(msg.toString()); |
| | | } |
| | |
| | | * @param description the accessible description. |
| | | * @return a menu with the provided text. |
| | | */ |
| | | public static JMenu createMenu(Message msg, Message description) |
| | | public static JMenu createMenu(LocalizableMessage msg, LocalizableMessage description) |
| | | { |
| | | JMenu menu = new JMenu(msg.toString()); |
| | | menu.getAccessibleContext().setAccessibleDescription( |
| | |
| | | */ |
| | | public static JLabel createPrimaryLabel() |
| | | { |
| | | return createPrimaryLabel(Message.EMPTY); |
| | | return createPrimaryLabel(LocalizableMessage.EMPTY); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param text the message to be displayed by the label. |
| | | * @return the label of type 'primary' (with bigger font than usual). |
| | | */ |
| | | public static JLabel createPrimaryLabel(Message text) |
| | | public static JLabel createPrimaryLabel(LocalizableMessage text) |
| | | { |
| | | JLabel label = new JLabel(text.toString()); |
| | | label.setFont(ColorAndFontConstants.primaryFont); |
| | |
| | | * @param text the message to be displayed by the label. |
| | | * @return the label of type 'inline help' (with smaller font). |
| | | */ |
| | | public static JLabel createInlineHelpLabel(Message text) |
| | | public static JLabel createInlineHelpLabel(LocalizableMessage text) |
| | | { |
| | | JLabel label = new JLabel(text.toString()); |
| | | label.setFont(ColorAndFontConstants.inlineHelpFont); |
| | |
| | | * @param text the message to be displayed by the label. |
| | | * @return the label of type 'title' (with bigger font). |
| | | */ |
| | | public static JLabel createTitleLabel(Message text) |
| | | public static JLabel createTitleLabel(LocalizableMessage text) |
| | | { |
| | | JLabel label = new JLabel(text.toString()); |
| | | label.setFont(ColorAndFontConstants.titleFont); |
| | |
| | | */ |
| | | public static JLabel createDefaultLabel() |
| | | { |
| | | return createDefaultLabel(Message.EMPTY); |
| | | return createDefaultLabel(LocalizableMessage.EMPTY); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param text the message to be displayed by the label. |
| | | * @return the label (with default font). |
| | | */ |
| | | public static JLabel createDefaultLabel(Message text) |
| | | public static JLabel createDefaultLabel(LocalizableMessage text) |
| | | { |
| | | JLabel label = new JLabel(text.toString()); |
| | | label.setFont(ColorAndFontConstants.defaultFont); |
| | |
| | | * @param cols the columns of the text area. |
| | | * @return a text area with borders similar to the ones of a text field. |
| | | */ |
| | | public static JTextArea createTextAreaWithBorder(Message text, int rows, |
| | | public static JTextArea createTextAreaWithBorder(LocalizableMessage text, int rows, |
| | | int cols) |
| | | { |
| | | JTextArea ta = createTextArea(text, rows, cols); |
| | |
| | | * @param cols the columns of the text area. |
| | | * @return a non-editable text area. |
| | | */ |
| | | public static JTextArea createNonEditableTextArea(Message text, int rows, |
| | | public static JTextArea createNonEditableTextArea(LocalizableMessage text, int rows, |
| | | int cols) |
| | | { |
| | | JTextArea ta = createTextArea(text, rows, cols); |
| | |
| | | * @param cols the columns of the text area. |
| | | * @return a text area. |
| | | */ |
| | | public static JTextArea createTextArea(Message text, int rows, |
| | | public static JTextArea createTextArea(LocalizableMessage text, int rows, |
| | | int cols) |
| | | { |
| | | JTextArea ta = new JTextArea(text.toString(), rows, cols); |
| | |
| | | * specifying the maximum height of the image. |
| | | */ |
| | | public static ImageIcon createImageIcon(byte[] bytes, int maxHeight, |
| | | Message description, boolean useFast) |
| | | LocalizableMessage description, boolean useFast) |
| | | { |
| | | ImageIcon icon = new ImageIcon(bytes, description.toString()); |
| | | if ((maxHeight > icon.getIconHeight()) || (icon.getIconHeight() <= 0)) |
| | |
| | | * @param nCols the number of columns. |
| | | * @return the wrapped message. |
| | | */ |
| | | public static Message wrapHTML(Message msg, int nCols) |
| | | public static LocalizableMessage wrapHTML(LocalizableMessage msg, int nCols) |
| | | { |
| | | String s = msg.toString(); |
| | | StringBuilder sb = new StringBuilder(); |
| | |
| | | { |
| | | sb.append(lastLine); |
| | | } |
| | | return Message.raw(sb.toString()); |
| | | return LocalizableMessage.raw(sb.toString()); |
| | | } |
| | | |
| | | private static boolean isLineBreakTag(String tag) |
| | |
| | | * @return the HTML representation of a message to which some points have |
| | | * been appended. |
| | | */ |
| | | public static String getProgressWithPoints(Message plainText, |
| | | public static String getProgressWithPoints(LocalizableMessage plainText, |
| | | Font progressFont) |
| | | { |
| | | return applyFont(plainText.toString(), progressFont)+ |
| | |
| | | * @param detailsFont the font to be used for the details. |
| | | * @return the HTML representation of an error for the given text. |
| | | */ |
| | | public static String getFormattedError(Message title, Font titleFont, |
| | | Message details, Font detailsFont) |
| | | public static String getFormattedError(LocalizableMessage title, Font titleFont, |
| | | LocalizableMessage details, Font detailsFont) |
| | | { |
| | | StringBuilder buf = new StringBuilder(); |
| | | buf.append(UIFactory.getIconHtml(UIFactory.IconType.ERROR_LARGE)) |
| | |
| | | * @param detailsFont the font to be used for the details. |
| | | * @return the HTML representation of a success for the given text. |
| | | */ |
| | | public static String getFormattedSuccess(Message title, Font titleFont, |
| | | Message details, Font detailsFont) |
| | | public static String getFormattedSuccess(LocalizableMessage title, Font titleFont, |
| | | LocalizableMessage details, Font detailsFont) |
| | | { |
| | | StringBuilder buf = new StringBuilder(); |
| | | buf.append(UIFactory.getIconHtml(UIFactory.IconType.INFORMATION_LARGE)) |
| | |
| | | * @param detailsFont the font to be used for the details. |
| | | * @return the HTML representation of a confirmation for the given text. |
| | | */ |
| | | public static String getFormattedConfirmation(Message title, Font titleFont, |
| | | Message details, Font detailsFont) |
| | | public static String getFormattedConfirmation(LocalizableMessage title, Font titleFont, |
| | | LocalizableMessage details, Font detailsFont) |
| | | { |
| | | StringBuilder buf = new StringBuilder(); |
| | | buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE)) |
| | |
| | | * @param detailsFont the font to be used for the details. |
| | | * @return the HTML representation of a success for the given text. |
| | | */ |
| | | public static String getFormattedWarning(Message title, Font titleFont, |
| | | Message details, Font detailsFont) |
| | | public static String getFormattedWarning(LocalizableMessage title, Font titleFont, |
| | | LocalizableMessage details, Font detailsFont) |
| | | { |
| | | StringBuilder buf = new StringBuilder(); |
| | | buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE)) |
| | |
| | | * @param l the label to be updated. |
| | | * @param text the text to be set on the label. |
| | | */ |
| | | public static void setWarningLabel(JLabel l, Message text) |
| | | public static void setWarningLabel(JLabel l, LocalizableMessage text) |
| | | { |
| | | l.setText(text.toString()); |
| | | if (warningIcon == null) |