From 38a8fdce94e08220c2a1d409858566b33a2907fe Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 04 Jan 2010 06:46:50 +0000
Subject: [PATCH] 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.
---
opends/src/guitools/org/opends/guitools/controlpanel/ui/ProgressDialog.java | 22 +++++
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java | 174 +++++++++++++++++++++++++++++++++++++++++++
opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java | 31 +++----
3 files changed, 207 insertions(+), 20 deletions(-)
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ProgressDialog.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/ProgressDialog.java
index fe9f3c6..7eba75e 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ProgressDialog.java
+++ b/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);
+ }
+ }
}
/**
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
index c64bd4d..8242c43 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
+++ b/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;
}
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 ef3ebd7..e8840e5 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/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;
@@ -988,7 +988,7 @@
}
/**
- * Updates the preferredsize of an editor pane.
+ * Updates the preferred size of an editor pane.
* @param pane the panel to be updated.
* @param nCols the number of columns that the panel must have.
* @param plainText the text to be displayed (plain text).
@@ -1016,6 +1016,176 @@
}
}
+ private final static String HTML_SPACE = " ";
+ /**
+ * 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
--
Gitblit v1.10.0