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

jvergara
04.46.2010 125dcdb0cc0a10cf735f04493fef194a72f49dcb
Complete fix for issue 4412 (creating bogus entry from ldif in control panel, the error warning winodw shows hidden behind)
Rewrite the code used to calculate the preferred size of the error pane.
3 files modified
225 ■■■■■ changed files
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/ProgressDialog.java 22 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java 31 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java 172 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/ProgressDialog.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.ui;
@@ -289,6 +289,26 @@
    public void setSummary(Message msg)
    {
      errorPane.setText(msg.toString());
      if (!details.isSelected() && isVisible())
      {
        Message wrappedText = Utilities.wrapHTML(msg, 70);
        JEditorPane pane = new JEditorPane();
        pane.setContentType("text/html");
        pane.setText(wrappedText.toString());
        ProgressDialog dlg = (ProgressDialog)Utilities.getParentDialog(this);
        int width = Math.max(pane.getPreferredSize().width + 40,
        dlg.getWidth());
        int height = Math.max(pane.getPreferredSize().height + 40 +
            extraStrut.getHeight() + details.getPreferredSize().height,
        dlg.getHeight());
        // We might want to resize things.
        if (width > dlg.getWidth() || height > dlg.getHeight())
        {
          Dimension newDim = new Dimension(width, height);
          dlg.setSize(newDim);
        }
      }
    }
    /**
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.ui;
@@ -1280,30 +1280,27 @@
    }
    if (!text.equals(lastDisplayedError))
    {
      JEditorPane pane1 = Utilities.makeHtmlPane(null, pane.getFont());
      String text1;
      Message wrappedTitle = Utilities.wrapHTML(title, 80);
      Message wrappedDetails = Utilities.wrapHTML(details, 90);
      JEditorPane wrappedPane = Utilities.makeHtmlPane(null, pane.getFont());
      String wrappedText;
      switch (type)
      {
      case ERROR:
        text1 = Utilities.getFormattedError(title, titleFont,
            null, detailsFont);
        wrappedText = Utilities.getFormattedError(wrappedTitle, titleFont,
            wrappedDetails, detailsFont);
        break;
      default:
        text1 = Utilities.getFormattedSuccess(title, titleFont,
            null, detailsFont);
        wrappedText = Utilities.getFormattedSuccess(wrappedTitle, titleFont,
            wrappedDetails, detailsFont);
        break;
      }
      pane1.setText(text1);
      Dimension d1 = pane1.getPreferredSize();
      JEditorPane pane2 = Utilities.makeHtmlPane(null, pane.getFont());
      pane2.setText(details.toString());
      String plainText = details.toString().replaceAll("<br>",
          ServerConstants.EOL);
      Utilities.updatePreferredSize(pane2, 100, plainText, detailsFont, true);
      Dimension d2 = pane2.getPreferredSize();
      wrappedPane.setText(wrappedText);
      Dimension d = wrappedPane.getPreferredSize();
      pane.setText(text);
      pane.setPreferredSize(new Dimension(Math.max(d1.width, d2.width),
          d1.height + d2.height));
      pane.setPreferredSize(d);
      lastDisplayedError = text;
    }
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.util;
@@ -1016,6 +1016,176 @@
    }
  }
  private final static String HTML_SPACE = "&nbsp;";
  /**
   * Wraps the contents of the provided message using the specified number of
   * columns.
   * @param msg the message to be wrapped.
   * @param nCols the number of columns.
   * @return the wrapped message.
   */
  public static Message wrapHTML(Message msg, int nCols)
  {
    String s = msg.toString();
    StringBuilder sb = new StringBuilder();
    StringBuilder lastLine = new StringBuilder();
    int lastOpenTag = -1;
    boolean inTag = false;
    int lastSpace = -1;
    int lastLineLengthInLastSpace = 0;
    int lastLineLength = 0;
    for (int i=0; i<s.length() ; i++)
    {
      boolean isNormalChar = false;
      char c = s.charAt(i);
      if (c == '<')
      {
        inTag = true;
        lastOpenTag = i;
        lastLine.append(c);
      }
      else if (c == '>')
      {
        if (lastOpenTag != -1)
        {
          inTag = false;
          String tag = s.substring(lastOpenTag, i+1);
          lastOpenTag = -1;
          if (isLineBreakTag(tag))
          {
            lastLine.append(c);
            sb.append(lastLine);
            lastLine.delete(0, lastLine.length());
            lastLineLength = 0;
            lastSpace = -1;
            lastLineLengthInLastSpace = 0;
          }
          else
          {
            lastLine.append(c);
          }
        }
        else
        {
          isNormalChar = true;
        }
      }
      else if (inTag)
      {
        lastLine.append(c);
      }
      else if (c == HTML_SPACE.charAt(0))
      {
        if (s.length() >= i + HTML_SPACE.length())
        {
          if (s.substring(i, i + HTML_SPACE.length()).equalsIgnoreCase(
              HTML_SPACE))
          {
            if (lastLineLength < nCols)
            {
              // Only count as 1 space
              lastLine.append(HTML_SPACE);
              lastSpace = lastLine.length() - HTML_SPACE.length();
              lastLineLength ++;
              lastLineLengthInLastSpace = lastLineLength;
              i += HTML_SPACE.length() - 1;
            }
            else
            {
              // Insert a line break
              sb.append(lastLine);
              sb.append("<br>");
              lastLine.delete(0, lastLine.length());
              lastLineLength = 0;
              lastSpace = -1;
              lastLineLengthInLastSpace = 0;
              i += HTML_SPACE.length() - 1;
            }
          }
          else
          {
            isNormalChar = true;
          }
        }
        else
        {
          isNormalChar = true;
        }
      }
      else if (c == ' ')
      {
        if (lastLineLength < nCols)
        {
          // Only count as 1 space
          lastLine.append(c);
          lastSpace = lastLine.length() - 1;
          lastLineLength ++;
          lastLineLengthInLastSpace = lastLineLength;
        }
        else
        {
          // Insert a line break
          sb.append(lastLine);
          sb.append("<br>");
          lastLine.delete(0, lastLine.length());
          lastLineLength = 0;
          lastSpace = -1;
          lastLineLengthInLastSpace = 0;
        }
      }
      else
      {
        isNormalChar = true;
      }
      if (isNormalChar)
      {
        if (lastLineLength < nCols)
        {
          lastLine.append(c);
          lastLineLength ++;
        }
        else
        {
          // Check where to insert a line break
          if (lastSpace != -1)
          {
            sb.append(lastLine.subSequence(0, lastSpace));
            sb.append("<br>");
            lastLine.delete(0, lastSpace + 1);
            lastLine.append(c);
            lastLineLength = lastLineLength - lastLineLengthInLastSpace + 1;
            lastLineLengthInLastSpace = 0;
            lastSpace = -1;
          }
          else
          {
            // Force the line break.
            sb.append(lastLine);
            sb.append("<br>");
            lastLine.delete(0, lastLine.length());
            lastLine.append(c);
            lastLineLength = 1;
          }
        }
      }
    }
    if (lastLine.length() > 0)
    {
      sb.append(lastLine);
    }
    return Message.raw(sb.toString());
  }
  private static boolean isLineBreakTag(String tag)
  {
    return tag.equalsIgnoreCase("<br>") ||
    tag.equalsIgnoreCase("</br>") ||
    tag.equalsIgnoreCase("</div>") ||
    tag.equalsIgnoreCase("<p>") ||
    tag.equalsIgnoreCase("</p>");
  }
  /**
   * Center the component location based on its preferred size. The code
   * considers the particular case of 2 screens and puts the component on the