|
RichTextEditor Example Code
|
|
|
|
final String menuHeaderName = "Edit";
final boolean preventTypingOfHTMLTags = true;
final int compositeStyle = SWT.BORDER;
final int toolBarStyle = SWT.NULL;
final int styledTextStyle = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP;
RichTextEditorWidgetFeatureSet featureSet = RichTextEditorWidgetFeatureSet.ALL_FEATURES;
IStyledTextWidgetImageCreator imageCreator = new RichTextEditorWidgetBasicImageCreator(
iconsDirPath, false);
Composite parent = shell;
htmlTextEditorWidget = new HTMLTextEditorWidget(
featureSet,
imageCreator,
parent,
menuHeaderName,
preventTypingOfHTMLTags,
compositeStyle,
toolBarStyle,
styledTextStyle);
// The SWT RichTextEditor relies on GridData for its layout information...
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = SWT.BEGINNING;
gridData.verticalAlignment = SWT.BEGINNING;
gridData.minimumWidth = 200;
gridData.minimumHeight = 50;
htmlTextEditorWidget.setLayoutData(gridData);
// Now set the content in your format (HTML in this case, but you could write
// other converters for other content types)...
HTMLTextModel htmlTextModel = new HTMLTextModel(htmlContent);
htmlTextEditorWidget.setFormattedText(htmlTextModel);
|