From 7164c02689bf2fba4a7b1ec9229d6775d3332adc Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 09:03:15 +0000
Subject: [PATCH] GUI L&F enhancements, including accessibility and 508 compliances.

---
 opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java b/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
index 5273bf6..7654c1c 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -101,6 +101,10 @@
 import org.opends.guitools.controlpanel.event.TextComponentFocusListener;
 import org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
 import org.opends.guitools.controlpanel.ui.components.LabelWithHelpIcon;
+import org.opends.guitools.controlpanel.ui.components.
+ SelectableLabelWithHelpIcon;
+import org.opends.guitools.controlpanel.ui.renderer.
+ AccessibleTableHeaderRenderer;
 import org.opends.messages.Message;
 import org.opends.quicksetup.ui.UIFactory;
 import org.opends.quicksetup.util.Utils;
@@ -338,6 +342,7 @@
   {
     JEditorPane pane = new JEditorPane();
     pane.setContentType("text/html");
+    pane.setFont(font);
     if (text != null)
     {
       pane.setText(applyFont(text, font));
@@ -350,6 +355,28 @@
   }
 
   /**
+   * Creates a JEditorPane that displays a message.
+   * @param text the message of the editor pane in plain text format.
+   * @param font the font to be used in the message.
+   * @return a JEditorPane that displays a message.
+   */
+  public static JEditorPane makePlainTextPane(String text, Font font)
+  {
+    JEditorPane pane = new JEditorPane();
+    pane.setContentType("text/plain");
+    if (text != null)
+    {
+      pane.setText(text);
+    }
+    pane.setFont(font);
+    pane.setEditable(false);
+    pane.setBorder(new EmptyBorder(0, 0, 0, 0));
+    pane.setOpaque(false);
+    pane.setFocusCycleRoot(false);
+    return pane;
+  }
+
+  /**
    * 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.
@@ -434,6 +461,7 @@
     JButton button = new JButton(text.toString());
     button.setOpaque(false);
     button.setForeground(ColorAndFontConstants.buttonForeground);
+    button.getAccessibleContext().setAccessibleName(text.toString());
     return button;
   }
 
@@ -447,6 +475,7 @@
     JRadioButton button = new JRadioButton(text.toString());
     button.setOpaque(false);
     button.setForeground(ColorAndFontConstants.buttonForeground);
+    button.getAccessibleContext().setAccessibleName(text.toString());
     return button;
   }
 
@@ -460,6 +489,7 @@
     JCheckBox cb = new JCheckBox(text.toString());
     cb.setOpaque(false);
     cb.setForeground(ColorAndFontConstants.buttonForeground);
+    cb.getAccessibleContext().setAccessibleName(text.toString());
     return cb;
   }
 
@@ -585,6 +615,9 @@
           BorderFactory.createMatteBorder(1, 1, 0, 1,
               ColorAndFontConstants.gridColor));
     }
+    table.getTableHeader().setDefaultRenderer(
+        new AccessibleTableHeaderRenderer(
+            table.getTableHeader().getDefaultRenderer()));
 
     for (int i=0; i<tableModel.getColumnCount(); i++)
     {
@@ -1018,6 +1051,28 @@
     }
   }
 
+  /**
+   * Strips any potential HTML markup from a given string.
+   * @param s string to strip
+   * @return resulting string
+   */
+  static public String stripHtmlToSingleLine(String s) {
+    String o = null;
+    if (s != null) {
+      s = s.replaceAll("<br>", " ");
+      // This is not a comprehensive solution but addresses
+      // the few tags that we have in Resources.properties
+      // at the moment.  Note that the following might strip
+      // out more than is intended for non-tags like
+      // '<your name here>' or for funky tags like
+      // '<tag attr="1 > 0">'. See test class for cases that
+      // might cause problems.
+      o = s.replaceAll("\\<.*?\\>","");
+
+    }
+    return o;
+  }
+
   private final static String HTML_SPACE = "&nbsp;";
   /**
    * Wraps the contents of the provided message using the specified number of
@@ -1715,6 +1770,36 @@
   }
 
   /**
+   * Sets the not available text to a label and associates a help icon and
+   * a tooltip explaining that the data is not available because the server is
+   * down.
+   * @param l the label.
+   */
+  public static void setNotAvailableBecauseServerIsDown(
+      SelectableLabelWithHelpIcon l)
+  {
+    l.setText(INFO_CTRL_PANEL_NOT_AVAILABLE_LONG_LABEL.get().toString());
+    l.setHelpIconVisible(true);
+    l.setHelpTooltip(INFO_NOT_AVAILABLE_SERVER_DOWN_TOOLTIP.get().toString());
+  }
+
+  /**
+   * Sets the not available text to a label and associates a help icon and
+   * a tooltip explaining that the data is not available because authentication
+   * is required.
+   * @param l the label.
+   */
+  public static void setNotAvailableBecauseAuthenticationIsRequired(
+      SelectableLabelWithHelpIcon l)
+  {
+    l.setText(INFO_CTRL_PANEL_NOT_AVAILABLE_LONG_LABEL.get().toString());
+    l.setHelpIconVisible(true);
+    l.setHelpTooltip(
+            INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_TOOLTIP.get()
+                    .toString());
+  }
+
+  /**
    * Updates a label by setting a warning icon and a text.
    * @param l the label to be updated.
    * @param text the text to be set on the label.
@@ -1726,6 +1811,10 @@
     {
       warningIcon =
         createImageIcon("org/opends/quicksetup/images/warning_medium.gif");
+      warningIcon.setDescription(
+          INFO_WARNING_ICON_ACCESSIBLE_DESCRIPTION.get().toString());
+      warningIcon.getAccessibleContext().setAccessibleName(
+          INFO_WARNING_ICON_ACCESSIBLE_DESCRIPTION.get().toString());
     }
     l.setIcon(warningIcon);
     l.setToolTipText(text.toString());
@@ -1756,6 +1845,29 @@
   }
 
   /**
+   * Sets the not available text to a label with no icon nor tooltip.
+   * @param l the label.
+   */
+  public static void setNotAvailable(SelectableLabelWithHelpIcon l)
+  {
+    l.setText(INFO_CTRL_PANEL_NOT_AVAILABLE_LONG_LABEL.get().toString());
+    l.setHelpIconVisible(false);
+    l.setHelpTooltip(null);
+  }
+
+  /**
+   * Sets the a text to a label with no icon nor tooltip.
+   * @param l the label.
+   * @param text the text.
+   */
+  public static void setTextValue(SelectableLabelWithHelpIcon l, String text)
+  {
+    l.setText(text);
+    l.setHelpIconVisible(false);
+    l.setHelpTooltip(null);
+  }
+
+  /**
    * Returns the server root directory (the path where the server is installed).
    * @return the server root directory (the path where the server is installed).
    */
@@ -2396,6 +2508,10 @@
     {
       requiredIcon =
         createImageIcon(IconPool.IMAGE_PATH+"/required.gif");
+      requiredIcon.setDescription(
+          INFO_REQUIRED_ICON_ACCESSIBLE_DESCRIPTION.get().toString());
+      requiredIcon.getAccessibleContext().setAccessibleName(
+          INFO_REQUIRED_ICON_ACCESSIBLE_DESCRIPTION.get().toString());
     }
     label.setIcon(requiredIcon);
     label.setHorizontalTextPosition(SwingConstants.LEADING);

--
Gitblit v1.10.0