Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Furnadjiev2016-10-17 10:18:13 +0000
committerIvan Furnadjiev2016-10-17 10:18:13 +0000
commit4de1647b024adbc2ed96d2916394e443b508aaee (patch)
treebec2a4b8d3de6db5838fdc1e8740fbaecd76aad1 /bundles
parent4df895329d2115095cde4e994f52fd094526b717 (diff)
downloadorg.eclipse.rap-4de1647b024adbc2ed96d2916394e443b508aaee.tar.gz
org.eclipse.rap-4de1647b024adbc2ed96d2916394e443b508aaee.tar.xz
org.eclipse.rap-4de1647b024adbc2ed96d2916394e443b508aaee.zip
Add support for markup in MessageBox message
As Dialog does not extend Widget, setData approach does not work here. Add new public method setMarkupEnabled to MessageBox class to enable markup support on the message Label. Update Controls demo DialogsTab. Re-factor MessageBox_Test class. 430980: MarkUp support for MessageBox text https://bugs.eclipse.org/bugs/show_bug.cgi?id=430980 Change-Id: I112baf8caad8610255b9da9247cf10cc73d95499
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java40
1 files changed, 31 insertions, 9 deletions
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java
index 02a53156ea..37f47fc1ef 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java
@@ -11,9 +11,11 @@
******************************************************************************/
package org.eclipse.swt.widgets;
+import static org.eclipse.rap.rwt.internal.textsize.TextSizeUtil.stringExtent;
+
import java.util.StringTokenizer;
-import org.eclipse.rap.rwt.internal.textsize.TextSizeUtil;
+import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.widgets.DialogCallback;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
@@ -56,6 +58,7 @@ public class MessageBox extends Dialog {
private Image image;
private String message;
+ private boolean markupEnabled;
/**
* Constructs a new instance of this class given only its parent.
@@ -71,7 +74,7 @@ public class MessageBox extends Dialog {
* </ul>
*/
public MessageBox( Shell parent ) {
- this( parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL );
+ this( parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL );
}
/**
@@ -98,9 +101,9 @@ public class MessageBox extends Dialog {
* </ul>
*/
public MessageBox( Shell parent, int style ) {
- super( parent, checkStyle ( style ) );
- checkSubclass();
- message = "";
+ super( parent, checkStyle ( style ) );
+ checkSubclass();
+ message = "";
}
/**
@@ -111,7 +114,7 @@ public class MessageBox extends Dialog {
* @return the message
*/
public String getMessage() {
- return message;
+ return message;
}
/**
@@ -133,6 +136,20 @@ public class MessageBox extends Dialog {
}
/**
+ * Controls whether the use of <em>markup</em> in message is enabled. Once the markup in message
+ * is enabled it's not possible to disable it.
+ *
+ * @param markupEnabled true to enable the markup in message
+ *
+ * @since 3.2
+ */
+ public void setMarkupEnabled( boolean markupEnabled ) {
+ if( !this.markupEnabled ) {
+ this.markupEnabled = markupEnabled;
+ }
+ }
+
+ /**
* Makes the dialog visible and brings it to the front
* of the display.
*
@@ -209,6 +226,9 @@ public class MessageBox extends Dialog {
private void createText() {
Label textLabel = new Label( shell, SWT.WRAP );
+ if( markupEnabled ) {
+ textLabel.setData( RWT.MARKUP_ENABLED, Boolean.TRUE );
+ }
GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
int imageWidth = image == null ? 0 : image.getBounds().width;
int maxTextWidth = MAX_WIDTH - imageWidth - SPACING;
@@ -267,12 +287,13 @@ public class MessageBox extends Dialog {
}
private int getMaxMessageLineWidth() {
- Font font = shell.getFont();
int result = 0;
- StringTokenizer tokenizer = new StringTokenizer( message, "\n" );
+ Font font = shell.getFont();
+ String lineSeparator = markupEnabled ? "<br/>" : "\n";
+ StringTokenizer tokenizer = new StringTokenizer( message, lineSeparator );
while( tokenizer.hasMoreTokens() ) {
String line = tokenizer.nextToken();
- int lineWidth = TextSizeUtil.stringExtent( font, line ).x;
+ int lineWidth = stringExtent( font, line, markupEnabled ).x;
result = Math.max( result, lineWidth );
}
return result;
@@ -299,4 +320,5 @@ public class MessageBox extends Dialog {
}
return chkStyle;
}
+
}

Back to the top