Java Code Examples for org.eclipse.swt.custom.StyledText#setText()
The following examples show how to use
org.eclipse.swt.custom.StyledText#setText() .
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: RenameRefactoringPopup.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
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 2
Source File: HoverInfoWithSpellingAnnotation.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); text.setText(annotation.getText()); }
Example 3
Source File: TMinGenericEditorTest.java From tm4e with Eclipse Public License 1.0 | 6 votes |
@Test public void testTMHighlightInGenericEditorEdit() throws IOException, PartInitException { f = File.createTempFile("test" + System.currentTimeMillis(), ".ts"); FileOutputStream fileOutputStream = new FileOutputStream(f); fileOutputStream.write("let a = '';".getBytes()); fileOutputStream.close(); f.deleteOnExit(); editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(), editorDescriptor.getId(), true); StyledText text = (StyledText)editor.getAdapter(Control.class); Assert.assertTrue(new DisplayHelper() { @Override protected boolean condition() { return text.getStyleRanges().length > 1; } }.waitForCondition(text.getDisplay(), 3000)); int initialNumberOfRanges = text.getStyleRanges().length; text.setText("let a = '';\nlet b = 10;\nlet c = true;"); Assert.assertTrue("More styles should have been added", new DisplayHelper() { @Override protected boolean condition() { return text.getStyleRanges().length > initialNumberOfRanges + 3; } }.waitForCondition(text.getDisplay(), 300000)); }
Example 4
Source File: Comment.java From Rel with Apache License 2.0 | 6 votes |
@Override protected void buildControlPanel(Composite container) { container.setLayout(new GridLayout(1, false)); Label label = new Label(container, SWT.None); label.setText("Comment:"); StyledText expression = new StyledText(container, SWT.MULTI); expression.setText(operatorLabel.getText()); expression.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); expression.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { operatorLabel.setText(expression.getText()); Comment.this.pack(); container.getShell().pack(); } }); }
Example 5
Source File: RenameInformationPopup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 6
Source File: Log.java From AndroidRobot with Apache License 2.0 | 5 votes |
public static void loadLogs(StyledText styledTextLog, Display display, String file, String taskName, String loop, String logName, int index) { try{ FileInputStream instream = new FileInputStream(file); ObjectInputStream in = new ObjectInputStream(instream); int count = 0; while(true){ try{ LogInfo logInfo = (LogInfo)in.readObject(); if(logInfo.task.equals(taskName) && logInfo.loop == Integer.parseInt(loop)){ if(logInfo.name.trim().equals(logName)){ count++; if(count == index){ styledTextLog.setText(logInfo.getRunLog().toString()); break; } } } }catch(Exception eof){ break; } } in.close(); }catch(Exception ex){ ex.printStackTrace(); } }
Example 7
Source File: AnnotationWithQuickFixesHover.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); String annotationText= annotation.getText(); if (annotationText != null) text.setText(annotationText); }
Example 8
Source File: HoverInfoWithText.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@Override public void deferredCreateContent(Composite parent, HoverInformationControl miControl) { this.fParent = parent; this.fMIControl = miControl; fText = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | fMIControl.getAdditionalTextStyles()); fText.setForeground(parent.getForeground()); fText.setBackground(parent.getBackground()); fText.setFont(JFaceResources.getDialogFont()); fText.addPaintObjectListener(new PaintObjectListener() { public void paintObject(PaintObjectEvent event) { StyleRange style = event.style; Image image = (Image) style.data; if (image != null && !image.isDisposed()) { int x = event.x + 2; int y = event.y + event.ascent / 2 - style.metrics.ascent / 2 + 2; event.gc.drawImage(image, x, y); } } }); FillLayout layout = new FillLayout(); layout.marginHeight = 2; layout.marginWidth = 2; parent.setLayout(layout); if (monospace) { fText.setFont(JFaceResources.getTextFont()); } else { fText.setFont(JFaceResources.getDialogFont()); } fText.setText(xsString.getText()); fText.setStyleRanges(xsString.getStyleRanges().toArray(new StyleRange[0])); parent.layout(true); }
Example 9
Source File: ParamView.java From http4e with Apache License 2.0 | 5 votes |
void setFocus( boolean focusGained){ StyledText st = (StyledText) textView.getControl(); if (focusGained) { if (CoreConstants.EMPTY_TEXT.equals(getParamText())) { st.setText(CoreConstants.EMPTY_TEXT); } st.setForeground(ResourceUtils.getColor(Styles.DARK_RGB_TEXT)); } }
Example 10
Source File: AbstractAnnotationHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); String annotationText= annotation.getText(); if (annotationText != null) text.setText(annotationText); }
Example 11
Source File: RunClientDialog.java From tesb-studio-se with Apache License 2.0 | 5 votes |
/** * Create contents of the dialog. * * @param parent */ @Override protected Control createDialogArea(Composite parent) { setMessage("Runtime client running information"); setTitle("Initalize Runtime Server"); Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); logStyledText = new StyledText(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY); logStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); logStyledText.setText("Checking for all bundles start..."); return area; }
Example 12
Source File: CDSSGroup.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override protected Control createContents(Composite parent){ Composite ret = new Composite(parent, SWT.NONE); ret.setLayout(new FillLayout()); StyledText text = new StyledText(ret, SWT.READ_ONLY); text.setWordWrap(true); text.setText(Messages.CDSSGroup_ExplanationCDSSLine1 + Messages.CDSSGroup_ExplanationCDSSLine2 + Messages.CDSSGroup_ExplanationCDSSLine3); return ret; }
Example 13
Source File: SuffixText.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * 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 14
Source File: DiffAttributeEditor.java From git-appraise-eclipse with Eclipse Public License 1.0 | 5 votes |
@Override public void createControl(final Composite parent, FormToolkit toolkit) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); composite.setLayout(layout); final String filePath = getTaskAttribute().getAttribute(AppraiseReviewTaskSchema.DIFF_NEWPATH).getValue(); Link fileLink = new Link(composite, SWT.BORDER); fileLink.setText("<a>View in Workspace</a>"); fileLink.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { AppraiseUiPlugin.openFileInEditor(filePath, getModel().getTaskRepository()); } }); final String diffText = getTaskAttribute().getAttribute(AppraiseReviewTaskSchema.DIFF_TEXT).getValue(); final StyledText text = new StyledText(composite, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.READ_ONLY); text.setText(diffText); text.setStyleRanges(getStyleRangesForDiffText(diffText)); GridData diffTextGridData = new GridData(); diffTextGridData.grabExcessHorizontalSpace = true; diffTextGridData.horizontalAlignment = SWT.FILL; text.setLayoutData(diffTextGridData); composite.pack(); setControl(composite); }
Example 15
Source File: CustomTxtParserInputWizardPage.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
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 16
Source File: SeparatorPanel.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void initComponents(String label) { GridLayout gridLayout = new GridLayout(2, false); setLayout(gridLayout); GridData layoutData = new GridData(); layoutData.grabExcessHorizontalSpace = true; layoutData.horizontalAlignment = GridData.FILL; setLayoutData(layoutData); // Text label StyledText gridLinesLabel = new StyledText(this, SWT.NONE); gridLinesLabel.setEditable(false); Display display = Display.getDefault(); FontData data = display .getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), data.getHeight(), SWT.BOLD); gridLinesLabel.setFont(font); gridLinesLabel.setBackground(Display.getCurrent().getSystemColor (SWT.COLOR_WIDGET_BACKGROUND)); gridLinesLabel.setText(label); // Separator line Label separator = new Label (this, SWT.SEPARATOR | SWT.HORIZONTAL); GridData separatorData = new GridData(); separatorData.grabExcessHorizontalSpace = true; separatorData.horizontalAlignment = GridData.FILL; separatorData.horizontalIndent = 5; separator.setLayoutData(separatorData); }
Example 17
Source File: StatisticsView.java From CogniCrypt with Eclipse Public License 2.0 | 4 votes |
@Override public void createPartControl(Composite parent) { GridLayout layout = new GridLayout(3, false); parent.setLayout(layout); resultsEnabled = true; // Project Name Label projectnameLabel = new Label(parent, SWT.NONE); projectnameLabel.setText("Project Name: "); projectname = new StyledText(parent, SWT.NONE); projectname.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); projectname.setText("Nothing for now"); projectname.setEditable(false); // Refresh Button reRunButton = new Button(parent, SWT.PUSH); reRunButton.setText("Rerun the Analysis on this Project"); reRunButton.setEnabled(false); reRunButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); // register listener for the selection event reRunButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { final AnalysisKickOff runningAnalysis = new AnalysisKickOff(); runningAnalysis.setUp(JavaCore.create(lastProject)); runningAnalysis.run(); resultsEnabled = true; } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); // Time of Analysis Label timeofanalysisLabel = new Label(parent, SWT.NONE); timeofanalysisLabel.setText("Time of Analysis: "); timeofanalysis = new StyledText(parent, SWT.NONE); timeofanalysis.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); timeofanalysis.setWordWrap(true); timeofanalysis.setEditable(false); // Results Table createViewer(parent); }
Example 18
Source File: TestAutoClosing.java From tm4e with Eclipse Public License 1.0 | 4 votes |
@Test public void testAutoClose() throws Exception { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis()); p.create(null); p.open(null); IFile file = p.getFile("test.lc-test"); file.create(new ByteArrayInputStream(new byte[0]), true, null); ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); StyledText text = (StyledText)editor.getAdapter(Control.class); // insert closing text.setText(""); text.replaceTextRange(0, 0, "("); Assert.assertEquals("()", text.getText()); Assert.assertEquals(1, text.getCaretOffset()); // nested insert closing text.setText("foo(String::from)"); text.replaceTextRange(16, 0, "("); Assert.assertEquals("foo(String::from())", text.getText()); Assert.assertEquals(17, text.getCaretOffset()); // ignore already opened text.setText("()"); text.replaceTextRange(0, 0, "("); Assert.assertEquals("()", text.getText()); Assert.assertEquals(1, text.getCaretOffset()); // ignore already closed text.setText("()"); text.replaceTextRange(1, 0, ")"); Assert.assertEquals("()", text.getText()); Assert.assertEquals(2, text.getCaretOffset()); // text.setText("()"); text.replaceTextRange(2, 0, ")"); Assert.assertEquals("())", text.getText()); // text.setText(""); text.replaceTextRange(0, 0, "\""); Assert.assertEquals("\"\"", text.getText()); Assert.assertEquals(1, text.getCaretOffset()); // continued text.replaceTextRange(1, 0, "\""); Assert.assertEquals("\"\"", text.getText()); Assert.assertEquals(2, text.getCaretOffset()); // continued text.replaceTextRange(2, 0, "\""); Assert.assertEquals("\"\"\"\"", text.getText()); Assert.assertEquals(3, text.getCaretOffset()); }
Example 19
Source File: UndoRedo.java From Rel with Apache License 2.0 | 4 votes |
public void restore(StyledText text) { text.setText(content); text.setCaretOffset(caretOffset); text.setTopIndex(topIndex); }
Example 20
Source File: UpdaterDialog.java From developer-studio with Apache License 2.0 | 4 votes |
private void createFeatureNewVersionText(EnhancedFeature feature, final Group featureInfoGroup) { StyledText featureNewVersion = new StyledText(featureInfoGroup, SWT.WRAP); String featureVersionString = VERSION_LABEL + feature.getVersion(); featureNewVersion.setText(featureVersionString); }