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

The following examples show how to use org.eclipse.swt.custom.StyledText#setStyleRange() . 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: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void updateStyle(ITextViewer viewer) {
	StyledText text= viewer.getTextWidget();
	int widgetOffset= getWidgetOffset(viewer, fRememberedStyleRange.start);
	StyleRange range= new StyleRange(fRememberedStyleRange);
	range.start= widgetOffset;
	range.length= fRememberedStyleRange.length;
	StyleRange currentRange= text.getStyleRangeAtOffset(widgetOffset);
	if (currentRange != null) {
		range.strikeout= currentRange.strikeout;
		range.underline= currentRange.underline;
		range.fontStyle= currentRange.fontStyle;
	}

	// http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
	try {
		text.setStyleRange(range);
	} catch (IllegalArgumentException x) {
		// catching exception as offset + length might be outside of the text widget
		fRememberedStyleRange= null;
	}
}
 
Example 2
Source File: BufferDialog.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private Control createBufferTip(Composite parent, IEditorReference ref) {

		Composite result = new Composite(parent, SWT.NO_FOCUS);
		Color bg = parent.getBackground();
		result.setBackground(bg);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 1;
		result.setLayout(gridLayout);

		StyledText name = new StyledText(result, SWT.READ_ONLY | SWT.HIDE_SELECTION);
		// italics results in slightly clipped text unless extended
		String text = ref.getTitleToolTip() + ' ';
		name.setText(text);
		name.setBackground(bg);
		name.setCaret(null);
		StyleRange styleIt = new StyleRange(0, text.length(), null, bg);
		styleIt.fontStyle = SWT.ITALIC;
		name.setStyleRange(styleIt);
		
		return result;
	}
 
Example 3
Source File: HsMultiCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 刷新拼写检查中错误单词的样式
 * @param ranges
 */
public void refreshErrorWordsStyle(List<StyleRange> ranges){
	StyledText styledText = cellEditor.viewer.getTextWidget();
	List<StyleRange> oldRangeList = new ArrayList<StyleRange>();
	for(StyleRange oldRange : styledText.getStyleRanges()){
		if (oldRange.underlineStyle != SWT.UNDERLINE_ERROR) {
			oldRangeList.add(oldRange);
		}
	}
	styledText.setStyleRange(null);

	styledText.setStyleRanges(oldRangeList.toArray(new StyleRange[oldRangeList.size()]));
	if (ranges != null) {
		for (StyleRange range : ranges) {
			styledText.setStyleRange(range);
		}
	}
}
 
Example 4
Source File: HsMultiCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void highlightedTerms(List<String> terms) {
	if (!isValid()) {
		return;
	}
	StyledText styledText = cellEditor.viewer.getTextWidget();
	String text = styledText.getText();
	char[] source = text.toCharArray();
	List<StyleRange> ranges = new ArrayList<StyleRange>();
	TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null,
			ColorConfigBean.getInstance().getHighlightedTermColor());
	for (String term : terms) {
		ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
	}
	for (StyleRange range : ranges) {
		styledText.setStyleRange(range);
	}
}
 
Example 5
Source File: HsMultiCellEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 刷新拼写检查中错误单词的样式
 * @param ranges
 */
public void refreshErrorWordsStyle(List<StyleRange> ranges){
	StyledText styledText = cellEditor.viewer.getTextWidget();
	List<StyleRange> oldRangeList = new ArrayList<StyleRange>();
	for(StyleRange oldRange : styledText.getStyleRanges()){
		if (oldRange.underlineStyle != SWT.UNDERLINE_ERROR) {
			oldRangeList.add(oldRange);
		}
	}
	styledText.setStyleRange(null);

	styledText.setStyleRanges(oldRangeList.toArray(new StyleRange[oldRangeList.size()]));
	if (ranges != null) {
		for (StyleRange range : ranges) {
			styledText.setStyleRange(range);
		}
	}
}
 
Example 6
Source File: HsMultiCellEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void highlightedTerms(List<String> terms) {
	if (!isValid()) {
		return;
	}
	StyledText styledText = cellEditor.viewer.getTextWidget();
	String text = styledText.getText();
	char[] source = text.toCharArray();
	List<StyleRange> ranges = new ArrayList<StyleRange>();
	TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null,
			ColorConfigBean.getInstance().getHighlightedTermColor());
	for (String term : terms) {
		if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
			term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
			term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B");
			term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B");
		}
		ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
	}
	for (StyleRange range : ranges) {
		styledText.setStyleRange(range);
	}
}
 
Example 7
Source File: AnnotationExpansionControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void resetViewerBackground(StyleRange[] oldRanges) {

		if (oldRanges == null)
			return;

		if (fInput == null)
			return;

		StyledText text= fInput.fViewer.getTextWidget();
		if (text == null || text.isDisposed())
			return;

		// set the ranges one by one
		for (int i= 0; i < oldRanges.length; i++) {
			text.setStyleRange(oldRanges[i]);
		}
	}
 
Example 8
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 9
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 10
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 11
Source File: IDEUtil.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void setBold(StyledText text) {
	StyleRange range = new StyleRange();
	range.start = 0;
	range.length = text.getText().length();
	range.fontStyle = SWT.BOLD;
	text.setStyleRange(range);
}
 
Example 12
Source File: CustomTxtParserInputWizardPage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void openLegend() {
    final String cg = Messages.CustomTxtParserInputWizardPage_capturedGroup;
    final String ucg = Messages.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;
    final String ut = Messages.CustomTxtParserInputWizardPage_uncapturedText;
    int line1start = 0;
    String line1 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;
    int line2start = line1start + line1.length();
    String line2 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + ' ' + cg + ' ' + ucg + ' ' + ut + " \n"; //$NON-NLS-1$
    int line3start = line2start + line2.length();
    String line3 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + ' '  + cg + ' ' + ucg + ' ' + ut + " \n"; //$NON-NLS-1$
    int line4start = line3start + line3.length();
    String line4 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + ' ' + cg + ' ' + ucg + ' ' + ut + " \n"; //$NON-NLS-1$
    int line5start = line4start + line4.length();
    String line5 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;
    int line6start = line5start + line5.length();
    String line6 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + cg + ' ' + ucg + ' ' + ut + " \n"; //$NON-NLS-1$

    final Shell legendShell = new Shell(getShell(), SWT.DIALOG_TRIM);
    legendShell.setLayout(new FillLayout());
    StyledText legendText = new StyledText(legendShell, SWT.MULTI);
    legendText.setFont(fixedFont);
    legendText.setText(line1 + line2 + line3 + line4 + line5 + line6);
    legendText.setStyleRange(new StyleRange(line2start, line2.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));
    legendText.setStyleRange(new StyleRange(line3start, line3.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
    legendText.setStyleRange(new StyleRange(line4start, line4.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
    legendText.setStyleRange(new StyleRange(line6start, line6.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));
    legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(cg), cg.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));
    legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(ucg), ucg.length(), COLOR_BLACK, COLOR_MAGENTA));
    legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(cg), cg.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));
    legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(ucg), ucg.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));
    legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(cg), cg.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));
    legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(ucg), ucg.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));
    legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(cg), cg.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));
    legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(ucg), ucg.length(), COLOR_BLACK, COLOR_MAGENTA));
    legendShell.setText(Messages.CustomTxtParserInputWizardPage_previewLegend);
    legendShell.pack();
    legendShell.open();
}
 
Example 13
Source File: SourceMapView.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static void doStyleText(StyledText text, Color colorBackground, int start, int end) {
	final int max = text.getCharCount();
	if (end >= max) {
		end = max - 1;
	}
	if (start < 0 || end < 0 || start > end || end - start == 0) {
		return;
	}
	StyleRange styleRange = new StyleRange();
	styleRange.start = start;
	styleRange.length = end - start;
	styleRange.background = colorBackground;
	text.setStyleRange(styleRange);
}
 
Example 14
Source File: SVNHistoryPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
void updatePanels(ISelection selection) {
  if(selection == null || !(selection instanceof IStructuredSelection)) {
    textViewer.setDocument(new Document("")); //$NON-NLS-1$
    changePathsViewer.setInput(null);
    return;
  }
  IStructuredSelection ss = (IStructuredSelection) selection;
  if(ss.size() != 1) {
    textViewer.setDocument(new Document("")); //$NON-NLS-1$
    changePathsViewer.setInput(null);
    return;
  }
  LogEntry entry = (LogEntry) ss.getFirstElement();
  textViewer.setDocument(new Document(entry.getComment()));
  StyledText text = textViewer.getTextWidget();
  
  // TODO move this logic into the hyperlink detector created in createText()
  if(projectProperties == null) {
    linkList = ProjectProperties.getUrls(entry.getComment());
  } else {
    linkList = projectProperties.getLinkList(entry.getComment());
  }
  if(linkList != null) {
    int[][] linkRanges = linkList.getLinkRanges();
    // String[] urls = linkList.getUrls();
    for(int i = 0; i < linkRanges.length; i++) {
      text.setStyleRange(new StyleRange(linkRanges[ i][ 0], linkRanges[ i][ 1], 
          JFaceColors.getHyperlinkText(Display.getCurrent()), null));
    }
  }
  if (changePathsViewer instanceof ChangePathsTreeViewer) {
  	((ChangePathsTreeViewer)changePathsViewer).setCurrentLogEntry(entry);
  }
  if (changePathsViewer instanceof ChangePathsFlatViewer) {
  	((ChangePathsFlatViewer)changePathsViewer).setCurrentLogEntry(entry);
  }
  if (changePathsViewer instanceof ChangePathsTableProvider) {
  	((ChangePathsTableProvider)changePathsViewer).setCurrentLogEntry(entry);
  }      
  changePathsViewer.setInput(entry);
}
 
Example 15
Source File: GetActiveKeyDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite tparent = (Composite) super.createDialogArea(parent);

	GridLayout layout = new GridLayout();
	layout.marginWidth = 10;
	layout.marginTop = 10;
	tparent.setLayout(layout);

	GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);

	Composite compNav = new Composite(tparent, SWT.NONE);
	GridLayout navLayout = new GridLayout();
	compNav.setLayout(navLayout);

	createNavigation(compNav);

	Group groupActivekey = new Group(tparent, SWT.NONE);
	groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
	GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
	GridLayout layoutGroup = new GridLayout(2, false);
	layoutGroup.marginWidth = 5;
	layoutGroup.marginHeight = 20;
	groupActivekey.setLayout(layoutGroup);

	StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
	text.setBackground(text.getParent().getBackground());
	text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
	GridData dataText = new GridData();
	dataText.horizontalSpan = 2;
	dataText.widthHint = 470;
	text.setLayoutData(dataText);
	int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(
			Messages.getString("license.GetActiveKeyDialog.ts"));
	int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
	StyleRange styleRange = new StyleRange();
	styleRange.start = start;
	styleRange.length = length;
	styleRange.fontStyle = SWT.BOLD;
	styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
	text.setStyleRange(styleRange);

	Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
	label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
	GridDataFactory.fillDefaults().span(2, 1).applyTo(label);

	textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
	textActivekey.setEditable(false);
	textActivekey.setText(activekey);
	textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
	GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);

	Button btnCopy = new Button(groupActivekey, SWT.NONE);
	GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
	btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
	btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
	btnCopy.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent event) {
			Clipboard cb = new Clipboard(Display.getCurrent());
			String textData = textActivekey.getText();
			TextTransfer textTransfer = TextTransfer.getInstance();
			cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
		}
	});

	return tparent;
}
 
Example 16
Source File: ProblemView.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Fill data
 * @param specLoaded
 */
private void fillData(Spec specLoaded)
{
    if (specLoaded == null)
    {
        hide();
        return;
    } else
    {

        // retrieve the markers associated with the loaded spec
        IMarker[] markers = TLAMarkerHelper.getProblemMarkers(specLoaded.getProject(), null);

        if (markers == null || markers.length == 0)
        {
            hide();
        }

        // sort the markers
        List<IMarker> markersList = new ArrayList<IMarker>(Arrays.asList(markers));
        Collections.sort(markersList, new MarkerComparator());

        // Bug fix: 2 June 2010.  It takes forever if
        // there are a large number of markers, which
        // can easily happen if you remove a definition
        // that's used hundreds of times.
        int iterations = Math.min(markers.length, 20);
        for (int j = 0; j < iterations; j++)
        {
            final IMarker problem = markersList.get(j);

            // listener
            Listener listener = new Listener() {
                // goto marker on click
                public void handleEvent(Event event)
                {
                    TLAMarkerHelper.gotoMarker(problem, ((event.stateMask & SWT.MOD1) != 0));
                }
            };

            // contents of the item
            Composite problemItem = new Composite(bar, SWT.LINE_SOLID);
            problemItem.setLayout(new RowLayout(SWT.VERTICAL));
            problemItem.addListener(SWT.MouseDown, listener);

            String[] lines = problem.getAttribute(IMarker.MESSAGE, "").split("\n");
            for (int i = 0; i < lines.length; i++)
            {
                StyledText styledText = new StyledText(problemItem, SWT.INHERIT_DEFAULT);
                styledText.setEditable(false);
                styledText.setCursor(styledText.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                styledText.setText(lines[i]);
                styledText.addListener(SWT.MouseDown, listener);

                if (isErrorLine(lines[i], problem))
                {
                    StyleRange range = new StyleRange();
                    range.underline = true;
                    range.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_RED);
                    range.start = 0;
                    range.length = lines[i].length();
                    styledText.setStyleRange(range);
                }
            }

            ExpandItem item = new ExpandItem(bar, SWT.NONE, 0);
            item.setExpanded(true);
            
            String markerType = TLAMarkerHelper.getType(problem);
            item.setText(AdapterFactory.getMarkerTypeAsText(markerType) + " " + AdapterFactory.getSeverityAsText(problem.getAttribute(IMarker.SEVERITY,
                    IMarker.SEVERITY_ERROR)));
            item.setHeight(problemItem.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            item.setControl(problemItem);
            item.addListener(SWT.MouseDown, listener);
        }
    }
    return ;
}
 
Example 17
Source File: GetActiveKeyDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite tparent = (Composite) super.createDialogArea(parent);

	GridLayout layout = new GridLayout();
	layout.marginWidth = 10;
	layout.marginTop = 10;
	tparent.setLayout(layout);

	GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);

	Composite compNav = new Composite(tparent, SWT.NONE);
	GridLayout navLayout = new GridLayout();
	compNav.setLayout(navLayout);

	createNavigation(compNav);

	Group groupActivekey = new Group(tparent, SWT.NONE);
	groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
	GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
	GridLayout layoutGroup = new GridLayout(2, false);
	layoutGroup.marginWidth = 5;
	layoutGroup.marginHeight = 20;
	groupActivekey.setLayout(layoutGroup);

	StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
	text.setBackground(text.getParent().getBackground());
	text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
	GridData dataText = new GridData();
	dataText.horizontalSpan = 2;
	dataText.widthHint = 470;
	text.setLayoutData(dataText);
	int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(
			Messages.getString("license.GetActiveKeyDialog.ts"));
	int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
	StyleRange styleRange = new StyleRange();
	styleRange.start = start;
	styleRange.length = length;
	styleRange.fontStyle = SWT.BOLD;
	styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
	text.setStyleRange(styleRange);

	Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
	label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
	GridDataFactory.fillDefaults().span(2, 1).applyTo(label);

	textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
	textActivekey.setEditable(false);
	textActivekey.setText(activekey);
	textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
	GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);

	Button btnCopy = new Button(groupActivekey, SWT.NONE);
	GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
	btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
	btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
	btnCopy.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent event) {
			Clipboard cb = new Clipboard(Display.getCurrent());
			String textData = textActivekey.getText();
			TextTransfer textTransfer = TextTransfer.getInstance();
			cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
		}
	});

	return tparent;
}
 
Example 18
Source File: TLCUIHelper.java    From tlaplus with MIT License 3 votes vote down vote up
/**
   * Installs hyperlinks for locations reported by TLC on the {@link StyledText}.
   * This handles both creating the appearance of the hyperlink and storing
   * the module location that should be shown when the link is opened.
   * 
   * When this method is used to create the links, {@link TLCUIHelper#openTLCLocationHyperlink(StyledText, Event, ILaunchConfiguration)}
   * should be used to open the link.
   * 
   * @param styledText
   */
  public static void setTLCLocationHyperlinks(final StyledText styledText)
  {
      final String text = styledText.getText();
      final List<StyleRange> list = setTLCLocationHyperlinks(text);
      for (StyleRange styleRange : list) {
	styledText.setStyleRange(styleRange);
}
  }