Java Code Examples for org.eclipse.swt.custom.StyledText#setEnabled()

The following examples show how to use org.eclipse.swt.custom.StyledText#setEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Notifier.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates the text part of the window
 *
 * @param shell the window
 * @param text the text
 * @param colors the color set
 */
private static void createText(final Shell shell, final String text, final NotifierColors colors) {
	final StyledText textLabel = new StyledText(shell, SWT.WRAP | SWT.READ_ONLY);
	final GridData gdText = new GridData(GridData.FILL, GridData.FILL, true, true);
	gdText.horizontalIndent = 15;
	textLabel.setLayoutData(gdText);
	textLabel.setEnabled(false);
	final Font textFont = SWTGraphicUtil.buildFontFrom(textLabel, SWT.NONE, 10);
	textLabel.setFont(textFont);

	final Color textColor = colors.textColor;
	textLabel.setForeground(textColor);
	final Color fillColor = colors.rightColor;
	textLabel.setBackground(fillColor);

	textLabel.setText(text);
	SWTGraphicUtil.applyHTMLFormating(textLabel);

	SWTGraphicUtil.addDisposer(shell, textFont);
}
 
Example 2
Source File: RenameRefactoringPopup.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createContent(Composite parent) {
	Display display = parent.getDisplay();
	ColorRegistry registry = JFaceResources.getColorRegistry();
	Color foreground= registry.get("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
	if (foreground == null) {
		foreground = display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
	}
	Color background= registry.get("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
	if (background == null) {
		background = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
	}
	StyledText hint = new StyledText(popup, SWT.READ_ONLY | SWT.SINGLE);
	String enterKeyName = getEnterBinding();
	String hintTemplate = "Enter new name, press {0} to refactor";
	hint.setText(Messages.format(hintTemplate, enterKeyName));
	hint.setForeground(foreground);
	hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$
	hint.setEnabled(false); // text must not be selectable
	addViewMenu(parent);
	recursiveSetBackgroundColor(parent, background);
}
 
Example 3
Source File: RenameInformationPopup.java    From typescript.java with MIT License 6 votes vote down vote up
private void createContent(Composite parent) {
	Display display= parent.getDisplay();
	Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
	Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
	addMoveSupport(fPopup, parent);

	StyledText hint= new StyledText(fPopup, SWT.READ_ONLY | SWT.SINGLE);
	hint.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
	String enterKeyName= getEnterBinding();
	String hintTemplate= RefactoringMessages.RenameInformationPopup_EnterNewName;
	hint.setText(NLS.bind(hintTemplate, enterKeyName));
	hint.setForeground(foreground);
	hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$
	hint.setEnabled(false); // text must not be selectable
	addMoveSupport(fPopup, hint);

	addLink(parent);
	addViewMenu(parent);

	recursiveSetBackgroundColor(parent, background);

}
 
Example 4
Source File: RenameInformationPopup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createContent(Composite parent) {
	Display display= parent.getDisplay();
	Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
	Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
	addMoveSupport(fPopup, parent);

	StyledText hint= new StyledText(fPopup, SWT.READ_ONLY | SWT.SINGLE);
	String enterKeyName= getEnterBinding();
	String hintTemplate= ReorgMessages.RenameInformationPopup_EnterNewName;
	hint.setText(Messages.format(hintTemplate, enterKeyName));
	hint.setForeground(foreground);
	hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$
	hint.setEnabled(false); // text must not be selectable
	addMoveSupport(fPopup, hint);

	addViewMenu(parent);

	recursiveSetBackgroundColor(parent, background);

}
 
Example 5
Source File: PWLabel.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
 */
@Override
public Control build(final Composite parent) {
	if (getLabel() == null) {
		throw new UnsupportedOperationException("You need to set a description for a PWLabel object");
	}
	labelWidget = new StyledText(parent, SWT.WRAP | SWT.READ_ONLY);
	labelWidget.setEnabled(false);
	labelWidget.setBackground(parent.getBackground());
	labelWidget.setText(getLabel());
	SWTGraphicUtil.applyHTMLFormating(labelWidget);
	return labelWidget;
}
 
Example 6
Source File: Header.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create the description
 */
private void createDescription() {
	final StyledText labelDescription = new StyledText(this, SWT.WRAP | SWT.READ_ONLY);
	labelDescription.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
	labelDescription.setEnabled(false);
	labelDescription.setFont(getFont());
	labelDescription.setForeground(getForeground());
	labelDescription.setText(description);
	SWTGraphicUtil.applyHTMLFormating(labelDescription);
}
 
Example 7
Source File: SuffixText.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates, configures and returns the suffix text control.
 */
private StyledText createSuffixText() {
	StyledText styledText = new StyledText(this, SWT.TRANSPARENT);
	styledText.setText("");
	styledText.setForeground(INACTIVE_COLOR);
	styledText.setBackground(getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT));
	styledText.setEditable(false);
	styledText.setEnabled(false);
	styledText.setLeftMargin(0);

	return styledText;
}
 
Example 8
Source File: AssignmentWizardPage.java    From tlaplus with MIT License 5 votes vote down vote up
private void configureTextWidget(final boolean forModelValue) {
  	final StyledText textWidget = source.getTextWidget();
  	
if (forModelValue) {
	textWidget.setBackground(textWidget.getParent().getBackground());
} else {
	textWidget.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE));
}		
textWidget.setEnabled(!forModelValue);
  }
 
Example 9
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected EmbeddedEditor createSpecificationEditor() {
	ContextScopeHandler.defineContext(EMBEDDED_TEXT_EDITOR_SCOPE, TEXT_EDITOR_SCOPE);
	EmbeddedEditor embeddedEditor = createEmbeddedEditor();
	embeddedEditor.createPartialEditor();
	GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(embeddedEditor.getViewer().getControl());
	StyledText text = embeddedEditor.getViewer().getTextWidget();
	text.setAlwaysShowScrollBars(false);
	text.setSelection(0);
	text.setKeyBinding(SWT.MOD1 | SWT.KEY_MASK & 'a', ST.SELECT_ALL);
	initXtextSelectionProvider(text);
	initContextMenu(text);
	text.addModifyListener((event) -> editorPart.firePropertyChange(IEditorPart.PROP_DIRTY));
	text.setEnabled(editorPart.isEditable());
	return embeddedEditor;
}
 
Example 10
Source File: StyledTextDescriptor.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates and returns with a new {@link StyledText styled text} instance hooked up to the given parent composite.
 *
 * @param parent
 *            the parent of the styled text control.
 * @param style
 *            style bits for the new text control.
 * @return a new styled text control initialized from the descriptor.
 */
default StyledText toStyledText(final Composite parent, final int style) {

	final StyledText text = new StyledText(parent, READ_ONLY | style);
	text.setText(getText());
	text.setStyleRanges(getRanges());
	text.setFont(getFont());
	text.setEditable(false);
	text.setEnabled(false);

	final AtomicReference<Color> colorRef = new AtomicReference<>();
	final IPreferenceStore prefStore = EditorsUI.getPreferenceStore();
	if (null == prefStore
			|| prefStore.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {

		colorRef.set(getDefault().getSystemColor(COLOR_LIST_BACKGROUND));

	} else {

		RGB rgb = null;
		if (prefStore.contains(PREFERENCE_COLOR_BACKGROUND)) {
			if (prefStore.isDefault(PREFERENCE_COLOR_BACKGROUND)) {
				rgb = getDefaultColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
			} else {
				rgb = getColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
			}
			if (rgb != null) {
				colorRef.set(new Color(text.getDisplay(), rgb));
			}
		}

	}

	if (null != colorRef.get()) {
		text.setBackground(colorRef.get());
		text.addDisposeListener(e -> {
			if (!colorRef.get().isDisposed()) {
				colorRef.get().dispose();
			}
		});
	}

	text.pack();
	return text;
}
 
Example 11
Source File: ExecutionStatisticsDialog.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
  protected Control createCustomArea(Composite parent) {
final Composite c = new Composite(parent, SWT.BORDER);
c.setLayout(new GridLayout());
c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

//NOTE: Take care of ExecutionStatisticsCollector.md when updating!!!
final String txt = String.format("%s"
		+ "* Total number of cores and cores assigned to TLC\n"
		+ "* Heap and off-heap memory allocated to TLC\n"
		+ "* TLC's version (git commit SHA)\n"
		+ "* If breadth-first search, depth-first search or simulation mode is active\n"
		+ "* TLC's implementation for the sets of seen and unseen states\n"
		+ "* If TLC has been launched from the TLA Toolbox\n"
		+ "* Name, version, and architecture of your operating system\n"
		+ "* Vendor, version, and architecture of your Java virtual machine\n"
		+ "* The current date and time\n"
		+ "* An installation identifier which allows us to group execution statistics\n\n"
		+ "The execution statistics do not contain personal information. If you wish to revoke\n"
		+ "your consent to share execution statistics at a later point, please chose \n"
		+ "\"Never Share Execution Statistics\" below by re-opening this dialog via\n"
		+ "Help > Opt In/Out Execution Statistics accessible from the Toolbox's main menu.", prettyPrintSelection2(esc));

final StyledText st = new StyledText(c, SWT.SHADOW_NONE | SWT.WRAP);
st.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

st.setEnabled(true);
st.setEditable(false);
st.setText(txt);

final StyleRange[] ranges = new StyleRange[3];
ranges[0] = new StyleRange(txt.indexOf("(TLC) execution statistics"), "(TLC) execution statistics".length(), null, null);
ranges[0].underline = true;
ranges[0].underlineStyle = SWT.UNDERLINE_LINK;
ranges[0].data = "https://exec-stats.tlapl.us";

ranges[1] = new StyleRange(txt.indexOf("publicly available"), "publicly available".length(), null, null);
ranges[1].underline = true;
ranges[1].underlineStyle = SWT.UNDERLINE_LINK;
ranges[1].data = "https://exec-stats.tlapl.us/tlaplus.csv";
		
ranges[2] = new StyleRange(txt.indexOf("git commit SHA"), "git commit SHA".length(), null, null);
ranges[2].underline = true;
ranges[2].underlineStyle = SWT.UNDERLINE_LINK;
ranges[2].data = "https://git-scm.com/book/en/v2/Git-Internals-Git-Objects";

st.setStyleRanges(ranges);
st.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseUp(final MouseEvent event) {
              final int offset = st.getOffsetAtPoint(new Point(event.x, event.y));
              if (offset < 0 || offset >= st.getCharCount()) {
              	return;
              }
		final StyleRange style = st.getStyleRangeAtOffset(offset);
              if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK && style.data instanceof String) {
                  try {
				PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL((String) style.data));
			} catch (PartInitException | MalformedURLException notExpectedToHappen) {
				notExpectedToHappen.printStackTrace();
			}
              }
	}
});
	
      return c;
  }
 
Example 12
Source File: BibtexMergeDialog.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
private void buildPreview(Composite container) {
	GridData gridData = new GridData();
	gridData.horizontalAlignment = SWT.RIGHT;
	gridData.verticalAlignment = SWT.TOP;
	gridData.grabExcessVerticalSpace = true;
	gridData.horizontalSpan = 1;
	gridData.verticalSpan = 5;

	Composite composite = new Composite(container, SWT.NONE);
	composite.setLayout(new GridLayout(1, false));
	composite.setLayoutData(gridData);

	// create overview
	Table table = new Table(composite, SWT.BORDER);
	table.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1));

	TableColumn intersection = new TableColumn(table, SWT.CENTER);
	TableColumn mergeConflicts = new TableColumn(table, SWT.CENTER);
	TableColumn unionWithoutConflicts = new TableColumn(table, SWT.CENTER);
	intersection.setText("Intersection");
	mergeConflicts.setText("Merge conflicts");
	unionWithoutConflicts.setText("Union without conflicts");
	intersection.setWidth(80);
	mergeConflicts.setWidth(100);
	unionWithoutConflicts.setWidth(140);
	table.setHeaderVisible(true);

	previewStats = new TableItem(table, SWT.NONE);

	Label label = new Label(composite, SWT.NONE);
	label.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1));
	label.setText("Preview: ");

	preview = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
	preview.setLayoutData(new GridData(GridData.FILL_BOTH));
	preview.setEditable(false);
	preview.setEnabled(false);
	preview.setBlockSelection(true);

	// highlight current conflict
	initializeConflictIterator();
	preview.addLineStyleListener(new LineStyleListener() {
		public void lineGetStyle(LineStyleEvent event) {
			if (currentConflictedField == null
					|| currentConflictedResource.getConflictForField(currentConflictedField) == null)
				return;

			String currentConflict = currentConflictedResource.getConflictForField(currentConflictedField);
			StyleRange styleRange = new StyleRange();
			styleRange.start = preview.getText().indexOf(currentConflict);
			styleRange.length = currentConflict.length();
			styleRange.background = getParentShell().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
			event.styles = new StyleRange[] { styleRange };
		}
	});

	GridData textGrid = new GridData(500, 500);
	textGrid.horizontalSpan = 2;
	preview.setLayoutData(textGrid);

	updatePreview();
}