| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.ui; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | import javax.swing.*; |
| | | import javax.swing.border.Border; |
| | |
| | | * @param tooltip the tooltip of the button. |
| | | * @return a JButton with the given label and tooltip. |
| | | */ |
| | | public static JButton makeJButton(Message label, Message tooltip) |
| | | public static JButton makeJButton(LocalizableMessage label, LocalizableMessage tooltip) |
| | | { |
| | | JButton b = new JButton(); |
| | | |
| | |
| | | * @param style the text style. |
| | | * @return a JLabel with the given icon, text and text style. |
| | | */ |
| | | public static JLabel makeJLabel(IconType iconName, Message text, |
| | | public static JLabel makeJLabel(IconType iconName, LocalizableMessage text, |
| | | TextStyle style) |
| | | { |
| | | JLabel l = new JLabel(); |
| | |
| | | |
| | | ImageIcon icon = getImageIcon(iconName); |
| | | l.setIcon(icon); |
| | | Message tooltip = getIconTooltip(iconName); |
| | | LocalizableMessage tooltip = getIconTooltip(iconName); |
| | | |
| | | if (tooltip != null) |
| | | { |
| | |
| | | case TEXTFIELD: |
| | | |
| | | field = |
| | | makeJTextField(Message.raw(defaultValue), desc.getTooltip(), desc |
| | | makeJTextField(LocalizableMessage.raw(defaultValue), desc.getTooltip(), desc |
| | | .getSize(), TextStyle.TEXTFIELD); |
| | | break; |
| | | |
| | | case PASSWORD: |
| | | |
| | | field = |
| | | makeJPasswordField(Message.raw(defaultValue), desc.getTooltip(), desc |
| | | makeJPasswordField(LocalizableMessage.raw(defaultValue), desc.getTooltip(), desc |
| | | .getSize(), TextStyle.PASSWORD_FIELD); |
| | | break; |
| | | |
| | | case READ_ONLY: |
| | | |
| | | field = |
| | | makeTextPane(Message.raw(defaultValue), TextStyle.READ_ONLY); |
| | | makeTextPane(LocalizableMessage.raw(defaultValue), TextStyle.READ_ONLY); |
| | | break; |
| | | |
| | | default: |
| | |
| | | * @return a JTextField with the given icon, tooltip text, size and text |
| | | * style. |
| | | */ |
| | | public static JTextField makeJTextField(Message text, Message tooltip, |
| | | public static JTextField makeJTextField(LocalizableMessage text, LocalizableMessage tooltip, |
| | | int size, TextStyle style) |
| | | { |
| | | JTextField f = new JTextField(); |
| | |
| | | * @return a JPasswordField with the given icon, tooltip text, size and text |
| | | * style. |
| | | */ |
| | | public static JPasswordField makeJPasswordField(Message text, Message tooltip, |
| | | public static JPasswordField makeJPasswordField(LocalizableMessage text, LocalizableMessage tooltip, |
| | | int size, TextStyle style) |
| | | { |
| | | JPasswordField f = new JPasswordField(); |
| | |
| | | * @return a JRadioButton with the given text, tooltip text and text |
| | | * style. |
| | | */ |
| | | public static JRadioButton makeJRadioButton(Message text, Message tooltip, |
| | | public static JRadioButton makeJRadioButton(LocalizableMessage text, LocalizableMessage tooltip, |
| | | TextStyle style) |
| | | { |
| | | JRadioButton rb = new JRadioButton(); |
| | |
| | | * @return a JCheckBox with the given text, tooltip text and text |
| | | * style. |
| | | */ |
| | | public static JCheckBox makeJCheckBox(Message text, Message tooltip, |
| | | public static JCheckBox makeJCheckBox(LocalizableMessage text, LocalizableMessage tooltip, |
| | | TextStyle style) |
| | | { |
| | | JCheckBox cb = new JCheckBox(); |
| | |
| | | String url = |
| | | String.valueOf(UIFactory.class.getClassLoader().getResource( |
| | | getIconPath(iconType))); |
| | | Message description = getIconDescription(iconType); |
| | | Message title = getIconTooltip(iconType); |
| | | LocalizableMessage description = getIconDescription(iconType); |
| | | LocalizableMessage title = getIconTooltip(iconType); |
| | | return "<img src=\"" + url + "\" alt=\"" + description + |
| | | "\" align=\"middle\" title=\"" + title + "\" >"; |
| | | } |
| | |
| | | if ((icon == null) && (iconType != IconType.NO_ICON)) |
| | | { |
| | | String path = getIconPath(iconType); |
| | | Message description = getIconDescription(iconType); |
| | | LocalizableMessage description = getIconDescription(iconType); |
| | | try |
| | | { |
| | | Image im = |
| | |
| | | * @return a read only JEditorPane containing the provided text with the |
| | | * provided font. |
| | | */ |
| | | public static JEditorPane makeHtmlPane(Message text, Font font) |
| | | public static JEditorPane makeHtmlPane(LocalizableMessage text, Font font) |
| | | { |
| | | return makeHtmlPane(text, null, font); |
| | | } |
| | |
| | | * @return a read only JEditorPane containing the provided text with the |
| | | * provided font. |
| | | */ |
| | | public static JEditorPane makeHtmlPane(Message text, HTMLEditorKit ek, |
| | | public static JEditorPane makeHtmlPane(LocalizableMessage text, HTMLEditorKit ek, |
| | | Font font) |
| | | { |
| | | JEditorPane pane = new JEditorPane(); |
| | |
| | | * @return a read only JEditorPane containing the provided text with the |
| | | * provided TextStyle. |
| | | */ |
| | | public static JEditorPane makeTextPane(Message text, TextStyle style) |
| | | public static JEditorPane makeTextPane(LocalizableMessage text, TextStyle style) |
| | | { |
| | | String s = text != null ? String.valueOf(text) : null; |
| | | JEditorPane pane = new JEditorPane("text/plain", s); |
| | |
| | | * @param size the new size of the field. |
| | | * @param textStyle the new TextStyle of the field. |
| | | */ |
| | | private static void updateTextFieldComponent(JTextField field, Message text, |
| | | Message tooltip, int size, TextStyle textStyle) |
| | | private static void updateTextFieldComponent(JTextField field, LocalizableMessage text, |
| | | LocalizableMessage tooltip, int size, TextStyle textStyle) |
| | | { |
| | | field.setColumns(size); |
| | | if (text != null) |
| | |
| | | } |
| | | } |
| | | |
| | | private static Color getColor(Message l) |
| | | private static Color getColor(LocalizableMessage l) |
| | | { |
| | | String s = String.valueOf(l); |
| | | String[] colors = s.split(","); |
| | |
| | | */ |
| | | private static String getIconPath(IconType iconType) |
| | | { |
| | | Message key; |
| | | LocalizableMessage key; |
| | | switch (iconType) |
| | | { |
| | | case CURRENT_STEP: |
| | |
| | | * @param iconType the IconType for which we want to get the description. |
| | | * @return the icon description for the given IconType. |
| | | */ |
| | | private static Message getIconDescription(IconType iconType) |
| | | private static LocalizableMessage getIconDescription(IconType iconType) |
| | | { |
| | | Message description; |
| | | LocalizableMessage description; |
| | | switch (iconType) |
| | | { |
| | | case CURRENT_STEP: |
| | |
| | | * @param iconType the IconType for which we want to get the tooltip text. |
| | | * @return the icon tooltip text for the given IconType. |
| | | */ |
| | | private static Message getIconTooltip(IconType iconType) |
| | | private static LocalizableMessage getIconTooltip(IconType iconType) |
| | | { |
| | | if (iconType == null) { |
| | | iconType = IconType.NO_ICON; |
| | | } |
| | | Message tooltip; |
| | | LocalizableMessage tooltip; |
| | | switch (iconType) |
| | | { |
| | | case CURRENT_STEP: |
| | |
| | | boolean isSelected, |
| | | boolean cellHasFocus) |
| | | { |
| | | JLabel l = makeJLabel(IconType.NO_ICON, Message.fromObject(value), |
| | | textStyle); |
| | | JLabel l = |
| | | makeJLabel(IconType.NO_ICON, LocalizableMessage.raw(value |
| | | .toString()), textStyle); |
| | | l.setBorder(new EmptyBorder(TOP_INSET_SECONDARY_FIELD, 0, 0, 0)); |
| | | return l; |
| | | } |