mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

ludovicp
27.03.2010 7164c02689bf2fba4a7b1ec9229d6775d3332adc
opends/src/guitools/org/opends/guitools/controlpanel/ui/components/LabelWithHelpIcon.java
@@ -22,12 +22,13 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.ui.components;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@@ -97,6 +98,18 @@
    add(Box.createHorizontalGlue(), gbc);
    Utilities.addClickTooltipListener(iconLabel);
    updateAccessibleContext();
  }
  /**
   * Set the component this is labeling. Can be {@code null} if this does not
   * label a {@code Component}.
   * @param comp the {@code Component} to be labeled.
   */
  public void setLabelFor(Component comp)
  {
    label.setLabelFor(comp);
  }
  /**
@@ -106,6 +119,7 @@
  public void setText(String text)
  {
    label.setText(text);
    updateAccessibleContext();
  }
  /**
@@ -137,6 +151,7 @@
  public void setHelpTooltip(String tooltip)
  {
    iconLabel.setToolTipText(tooltip);
    updateAccessibleContext();
  }
  /**
@@ -198,4 +213,24 @@
      return null;
    }
  }
  private void updateAccessibleContext()
  {
    StringBuilder sb = new StringBuilder();
    String s = label.getText();
    if (s != null)
    {
      sb.append(s);
    }
    if (iconLabel.getIcon() != null)
    {
      String toolTip = iconLabel.getToolTipText();
      toolTip = Utilities.stripHtmlToSingleLine(toolTip);
      if (toolTip != null)
      {
        sb.append(" - "+toolTip);
      }
    }
    getAccessibleContext().setAccessibleName(sb.toString());
  }
}