org.eclipse.swt.custom.StyledText Java Examples

The following examples show how to use org.eclipse.swt.custom.StyledText. 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: PythonSourceViewer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the font for the given viewer sustaining selection and scroll position.
 *
 * @param font the font
 */
private void applyFont(Font font) {
    IDocument doc = getDocument();
    if (doc != null && doc.getLength() > 0) {
        Point selection = getSelectedRange();
        int topIndex = getTopIndex();

        StyledText styledText = getTextWidget();
        styledText.setRedraw(false);

        styledText.setFont(font);
        setSelectedRange(selection.x, selection.y);
        setTopIndex(topIndex);

        styledText.setRedraw(true);
    } else {
        getTextWidget().setFont(font);
    }
}
 
Example #2
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void setupReadOnlyMode() {
	checkWidget();

	StyledText text = viewer.getTextWidget();
	if (!close) {
		if (!editable) {
			return;
		}
		text.removeVerifyKeyListener(edit_VerifyKey);
		text.removeTraverseListener(edit_Traverse);
	}
	editable = false;
	text.setEditable(false);
	text.addVerifyKeyListener(readOnly_VerifyKey);
}
 
Example #3
Source File: AbstractThemeableEditor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public int getCaretOffset()
{
	ISourceViewer sourceViewer = getSourceViewer();
	if (sourceViewer == null)
	{
		return -1;
	}
	StyledText styledText = sourceViewer.getTextWidget();
	if (styledText == null)
	{
		return -1;
	}

	if (sourceViewer instanceof ITextViewerExtension5)
	{
		ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
		return extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
	}
	int offset = sourceViewer.getVisibleRegion().getOffset();
	return offset + styledText.getCaretOffset();
}
 
Example #4
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void mouseUp(MouseEvent e) {
    Widget w = e.widget;
    if (w instanceof StyledText) {
        StyledText styledText = (StyledText) w;
        int offset = styledText.getCaretOffset();
        if (offset >= 0 && offset < styledText.getCharCount()) {
            StyleRange styleRangeAtOffset = styledText.getStyleRangeAtOffset(offset);
            if (styleRangeAtOffset instanceof StyleRangeWithCustomData) {
                StyleRangeWithCustomData styleRangeWithCustomData = (StyleRangeWithCustomData) styleRangeAtOffset;
                Object l = styleRangeWithCustomData.customData;
                if (l instanceof IHyperlink) {
                    ((IHyperlink) l).linkActivated();
                }
            }
        }
    }
}
 
Example #5
Source File: ContentAssistSubjectControlAdapter.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see org.eclipse.jface.contentassist.IContentAssistSubjectControl#removeVerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener)
 */
public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener)
{
	if (fContentAssistSubjectControl != null)
	{
		fContentAssistSubjectControl.removeVerifyKeyListener(verifyKeyListener);
	}
	else if (fViewer instanceof ITextViewerExtension)
	{
		ITextViewerExtension extension = (ITextViewerExtension) fViewer;
		extension.removeVerifyKeyListener(verifyKeyListener);
	}
	else
	{
		StyledText textWidget = fViewer.getTextWidget();
		if (Helper.okToUse(textWidget))
		{
			textWidget.removeVerifyKeyListener(verifyKeyListener);
		}
	}
}
 
Example #6
Source File: GamlEditorDragAndDropHandler.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
protected void uninstall() {
	if (getViewer() == null || !fIsTextDragAndDropInstalled) { return; }

	final IDragAndDropService dndService = editor.getSite().getService(IDragAndDropService.class);
	if (dndService == null) { return; }

	final StyledText st = getStyledText();
	dndService.removeMergedDropTarget(st);

	final DragSource dragSource = (DragSource) st.getData(DND.DRAG_SOURCE_KEY);
	if (dragSource != null) {
		dragSource.dispose();
		st.setData(DND.DRAG_SOURCE_KEY, null);
	}

	fIsTextDragAndDropInstalled = false;
}
 
Example #7
Source File: FocusControlListenerFactory.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param control control on which the listener will be added
 * @return a BaseControlFocus Listener that can be attached to the events
 *         focusLost, focusGained and controlResized
 */
static BaseFocusControlListener getFocusControlListenerFor(final Control control) {
	if (control instanceof Combo) {
		return new ComboFocusControlListener((Combo) control);
	}
	if (control instanceof CCombo) {
		return new CComboFocusControlListener((CCombo) control);
	}

	if (control instanceof Text) {
		return new TextFocusControlListener((Text) control);
	}

	if (control instanceof StyledText) {
		return new StyledTextFocusControlListener((StyledText) control);
	}
	throw new IllegalArgumentException("Control should be a Text, a Combo, a CCombo or a StyledText widget");
}
 
Example #8
Source File: XtextDirectEditManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void initCellEditor() {
	committed = false;

	// Get the Text Compartments Edit Part

	setEditText(getEditPart().getEditText());

	IFigure label = getEditPart().getFigure();
	Assert.isNotNull(label);
	StyledText text = (StyledText) getCellEditor().getControl();
	// scale the font accordingly to the zoom level
	text.setFont(getScaledFont(label));

	// Hook the cell editor's copy/paste actions to the actionBars so that
	// they can
	// be invoked via keyboard shortcuts.
	actionBars = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
			.getEditorSite().getActionBars();
	saveCurrentActions(actionBars);
	actionHandler = new CellEditorActionHandler(actionBars);
	actionHandler.addCellEditor(getCellEditor());
	actionBars.updateActionBars();
}
 
Example #9
Source File: XLIFFEditorImplWithNatTable.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.ts.ui.editors.IXliffEditor#getSelectPureText()
 */
public String getSelectPureText() {
	StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
	String selectionText = null;
	if (cellEditor != null && !cellEditor.isClosed()) {
		StyledText styledText = cellEditor.getSegmentViewer().getTextWidget();
		Point p = styledText.getSelection();
		if (p != null) {
			if (p.x != p.y) {
				selectionText = cellEditor.getSelectedPureText();
			} else {
				selectionText = "";
			}
		}
	}

	if (selectionText != null) {
		// 将换行符替换为空
		selectionText = selectionText.replaceAll("\n", "");
	}
	return selectionText;
}
 
Example #10
Source File: AbstractDebugVariableCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Draw square of the given rgb.
 *
 * @param rgb        the rgb color
 * @param gc         the graphic context
 * @param textWidget the text widget
 * @param x          the location y
 * @param y          the location y
 * @return the square width.
 */
private int drawSquare(RGB rgb, GC gc, StyledText textWidget, int x, int y) {
	FontMetrics fontMetrics = gc.getFontMetrics();
	int size = getSquareSize(fontMetrics);
	x += fontMetrics.getLeading();
	y += fontMetrics.getDescent();

	Rectangle rect = new Rectangle(x, y, size, size);

	// Fill square
	gc.setBackground(getColor(rgb, textWidget.getDisplay()));
	gc.fillRectangle(rect);

	// Draw square box
	gc.setForeground(textWidget.getForeground());
	gc.drawRectangle(rect);
	return getSquareWidth(gc.getFontMetrics());
}
 
Example #11
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 初始化默认颜色、字体等
 * @param textControl
 *            ;
 */
private void initStyle(final StyledText textControl, IStyle cellStyle) {
	// textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
	textControl.setBackground(GUIHelper.getColor(210, 210, 240));
	textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));

	textControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
	textControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
	textControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
	textControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
	textControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);

	// textControl.setLeftMargin(0);
	// textControl.setRightMargin(0);
	// textControl.setTopMargin(0);
	// textControl.setBottomMargin(0);

	textControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.XLIFF_EDITOR_TEXT_FONT));
	textControl.setIME(new IME(textControl, SWT.NONE));

}
 
Example #12
Source File: StyledTextCellEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void setupEditMode() {
	checkWidget();

	StyledText text = viewer.getTextWidget();
	if (!close) {
		if (editable) {
			return;
		}
		text.removeVerifyKeyListener(readOnly_VerifyKey);
	}
	editable = true;
	text.setEditable(true);
	text.addVerifyKeyListener(edit_VerifyKey);
	text.addTraverseListener(edit_Traverse);
}
 
Example #13
Source File: ChatLine.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private void addHyperLinkListener(final StyledText text) {
  text.addListener(
      SWT.MouseDown,
      new Listener() {
        @Override
        public void handleEvent(Event event) {
          try {

            int offset = text.getOffsetAtLocation(new Point(event.x, event.y));

            StyleRange style = text.getStyleRangeAtOffset(offset);
            if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
              String url = (String) style.data;
              SWTUtils.openInternalBrowser(url, url);
            }
          } catch (IllegalArgumentException e) {
            // no character under event.x, event.y
          }
        }
      });
}
 
Example #14
Source File: ParameterizeTextView.java    From http4e with Apache License 2.0 6 votes vote down vote up
private StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
   final HConfiguration sourceConf = new HConfiguration(HContentAssistProcessor.PARAM_PROCESSOR);
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument1());

   sourceViewer.getControl().addKeyListener(new KeyAdapter() {

      public void keyPressed( KeyEvent e){
         // if ((e.character == ' ') && ((e.stateMask & SWT.CTRL) != 0)) {
         if (Utils.isAutoAssistInvoked(e)) {
            IContentAssistant ca = sourceConf.getContentAssistant(sourceViewer);
            ca.showPossibleCompletions();
         }
      }
   });

   return sourceViewer.getTextWidget();
}
 
Example #15
Source File: TMinGenericEditorTest.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
@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 #16
Source File: StyledTextForShowingCodeFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return a styled text that can be used to show code with the colors based on the color cache received.
 */
public StyledText createStyledTextForCodePresentation(Composite parent) {
    styledText = new StyledText(parent, SWT.BORDER | SWT.READ_ONLY);
    this.backgroundColorCache = new ColorAndStyleCache(new PreferenceStore());
    this.colorCache = new ColorAndStyleCache(null);

    try {
        styledText.setFont(new Font(parent.getDisplay(), FontUtils.getFontData(IFontUsage.STYLED, true)));
    } catch (Throwable e) {
        //ignore
    }
    updateBackgroundColor();

    PyDevUiPrefs.getChainedPrefStore().addPropertyChangeListener(this);

    return styledText;
}
 
Example #17
Source File: MarkExchangeHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Support exchange for simple mark on TextConsole
 * 
 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, org.eclipse.ui.console.IConsoleView, org.eclipse.core.commands.ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	int mark = viewer.getMark();
	StyledText st = viewer.getTextWidget(); 
	if (mark != -1) {
		try {
			st.setRedraw(false);
			int offset = st.getCaretOffset();
			viewer.setMark(offset);
			st.setCaretOffset(mark);
			int len = offset - mark;
			viewer.setSelectedRange(offset, -len);
		} finally {
			st.setRedraw(true);
		}
	}
	return null;
}
 
Example #18
Source File: LogAnalysis.java    From AndroidRobot with Apache License 2.0 6 votes vote down vote up
public void createLogDetail() {
    tabFolderLogDetail = new CTabFolder(sashFormLog, SWT.CLOSE | SWT.BORDER);
    tabFolderLogDetail.setTabHeight(0);
    tabFolderLogDetail.marginHeight = 0;
    tabFolderLogDetail.marginWidth = 0;
    tabFolderLogDetail.setMaximizeVisible(false);
    tabFolderLogDetail.setMinimizeVisible(false);
    //tabFolderLogDetail.setSelectionBackground(new Color(display, new RGB(153, 186, 243)));
    tabFolderLogDetail.setSimple(false);
    tabFolderLogDetail.setUnselectedCloseVisible(true);

    CTabItem tabItemLogList = new CTabItem(tabFolderLogDetail, SWT.NONE | SWT.MULTI
                                                               | SWT.V_SCROLL);
    tabFolderLogDetail.setSelection(tabItemLogList);

    //styledTextLog = new List(tabFolderLogDetail, SWT.BORDER);
    styledTextLog = new StyledText(tabFolderLogDetail, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL
                                                       | SWT.V_SCROLL | SWT.READ_ONLY);
    styledTextLog.addLineStyleListener(new LogLineStyleListener(shell));
    tabItemLogList.setControl(styledTextLog);
    //sTextLog.setFont(new Font(display,"Courier New",10,SWT.NONE));

}
 
Example #19
Source File: BaseYankHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * In the console context, use paste as
 * in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText
 * will not simulate keyboard input
 *  
 * @param event the ExecutionEvent
 * @param widget The consoles StyledText widget
 */
protected void paste(ExecutionEvent event, StyledText widget) {
		IWorkbenchPart apart = HandlerUtil.getActivePart(event);
		if (apart != null) {
			try {
				IWorkbenchPartSite site = apart.getSite();
				if (site != null) {
					IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
					if (service != null) {
						service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null);
						KillRing.getInstance().setYanked(true);
					}
				}
			} catch (CommandException e) {
			}
		}
}
 
Example #20
Source File: ScreenFlasher.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private void runFlasher(final int count, final StyledText item) {
	if (count > 0) {
		Display.getDefault().asyncExec(() -> {
			item.setBackground(flash);					
			item.setVisible(true);
			item.redraw();
			item.update();
			Display.getDefault().asyncExec(() -> {
				try {
					Thread.sleep(waitTime);
				} catch (InterruptedException e) {}
				item.setBackground(background);					
				item.redraw();
				item.update();
				runFlasher(count -1, item);
			});
		});
	} 
}
 
Example #21
Source File: SearchWholeWordAction.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void selectionChanged(IAction action, ISelection selection) {
	IWorkbenchPart activePart = WorkbenchUtils.getActivePart();
	if (activePart instanceof ITextEditor) {
		ITextEditor textEditor = (ITextEditor) activePart;
		textWidget = JavaUtils.as(StyledText.class, textEditor.getAdapter(Control.class));
		action.setEnabled(true);
	}
	else {
		action.setEnabled(false);
	}
}
 
Example #22
Source File: BracketDrawingStrategy.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Draws an opening bracket to the begin and a closing bracket to the end of the given annotation.
 *
 * @param annotation the annotation
 * @param gc the gc
 * @param textWidget the text widget
 * @param offset the offset
 * @param length the length
 * @param color the color
 */
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length,
        Color color) {
  if (length > 0) {
    if (annotation instanceof EclipseAnnotationPeer) {
      AnnotationFS annotationFS = ((EclipseAnnotationPeer) annotation).getAnnotationFS();

      if (gc != null) {
        Rectangle bounds = textWidget.getTextBounds(offset, offset + length - 1);

        gc.setForeground(color);

        boolean isDrawOpenBracket = annotationFS.getBegin() == offset;
        if (isDrawOpenBracket) {
          gc.drawLine(bounds.x, bounds.y + bounds.height - 1, bounds.x + BRACKET_WIDTH, bounds.y
                  + bounds.height - 1);

          gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x, bounds.y, bounds.x + BRACKET_WIDTH, bounds.y);
        }

        boolean isDrawCloseBracket = annotationFS.getEnd() == offset + length;
        if (isDrawCloseBracket) {
          gc.drawLine(bounds.x + bounds.width, bounds.y + bounds.height - 1, bounds.x
                  + bounds.width - BRACKET_WIDTH, bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x + bounds.width - 1, bounds.y, bounds.x + bounds.width - 1, bounds.y
                  + bounds.height - 1);

          gc.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width - BRACKET_WIDTH,
                  bounds.y);
        }
      } else {
        textWidget.redrawRange(offset, length, true);
      }
    }
  }
}
 
Example #23
Source File: ControlSpaceKeyAdapter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static final void applyChanges( Shell shell, List list, Control control, int position,
  InsertTextInterface insertTextInterface ) {
  String selection =
      list.getSelection()[0].contains( Const.getDeprecatedPrefix() )
      ? list.getSelection()[0].replace( Const.getDeprecatedPrefix(), "" )
      : list.getSelection()[0];
  String extra = "${" + selection + "}";
  if ( insertTextInterface != null ) {
    insertTextInterface.insertText( extra, position );
  } else {
    if ( control.isDisposed() ) {
      return;
    }

    if ( list.getSelectionCount() <= 0 ) {
      return;
    }
    if ( control instanceof Text ) {
      ( (Text) control ).insert( extra );
    } else if ( control instanceof CCombo ) {
      CCombo combo = (CCombo) control;
      combo.setText( extra ); // We can't know the location of the cursor yet. All we can do is overwrite.
    } else if ( control instanceof StyledTextComp ) {
      ( (StyledTextComp) control ).insert( extra );
    } else if ( control instanceof StyledText ) {
      ( (StyledText) control ).insert( extra );
    }
  }
  if ( !shell.isDisposed() ) {
    shell.dispose();
  }
  if ( !control.isDisposed() ) {
    control.setData( Boolean.FALSE );
  }
}
 
Example #24
Source File: XdsConsoleViewer.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * makes the associated text widget uneditable.
 */
public void setReadOnly() {
    ConsolePlugin.getStandardDisplay().asyncExec(new Runnable() {
        public void run() {
            StyledText text = getTextWidget();
            if (text != null && !text.isDisposed()) {
                text.setEditable(false);
            }
        }
    });
}
 
Example #25
Source File: GamlEditorDragAndDropHandler.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param sb
 * @param file
 * @return
 */
private int addDropImport(final StringBuilder sb, final IFile file) {
	final String name = obtainRelativePath(file);
	sb.append(Strings.LN).append("import ").append('"').append(name).append('"').append(Strings.LN);
	final StyledText st = getStyledText();
	final String text = st.getText();
	final int startOfGlobal = text.indexOf("global");
	final int startOfModel = text.indexOf("\nmodel");
	if (startOfGlobal == -1 && startOfModel == -1) { return -1; }
	final int endOfModel = text.indexOf("\n", startOfModel + 1);
	return endOfModel + 1;
}
 
Example #26
Source File: FormHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Creates the source viewer
 * @param parent
 * @param flags
 * @return
 */
public static SourceViewer createOutputViewer(Composite parent, int flags)
{
    SourceViewer sourceViewer = new SourceViewer(parent, null, null, false, flags);
    SourceViewerConfiguration configuration = new SourceViewerConfiguration();
    sourceViewer.configure(configuration);
    sourceViewer.setTabsToSpacesConverter(getTabToSpacesConverter());

    StyledText control = sourceViewer.getTextWidget();
    control.setFont(TLCUIActivator.getDefault().getOutputFont());
    control.setEditable(false);
    return sourceViewer;
}
 
Example #27
Source File: ModulaEditor.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleXdsPreferenceStoreChanged(IPreferenceStore store, PropertyChangeEvent event) {
    String property= event.getProperty();
    if (FormatterProfile.TAB_SIZE_PROPERTY_NAME.equals(property)) {
        int tabSize = store.getInt(FormatterProfile.TAB_SIZE_PROPERTY_NAME);
        StyledText stext = getSourceViewer().getTextWidget();
        if (tabSize != stext.getTabs()) {
            stext.setTabs(tabSize);
            if (isTabsToSpacesConversionEnabled()) {
                uninstallTabsToSpacesConverter();
                installTabsToSpacesConverter();
            }
        }
    }
}
 
Example #28
Source File: SqlEditor.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void createStatementSection(Composite body, FormToolkit toolkit) {
	Section section = UI.section(body, toolkit, "SQL Statement");
	Composite composite = UI.sectionClient(section, toolkit, 1);
	queryText = new StyledText(composite, SWT.BORDER);
	toolkit.adapt(queryText);
	UI.gridData(queryText, true, false).heightHint = 150;
	queryText.addModifyListener(new SyntaxStyler(queryText));
	Actions.bind(section, runAction = new RunAction());
}
 
Example #29
Source File: TMEditorColorTest.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void userDefinedEditorColorTest() throws Exception {
	String testColorVal = "255,128,0";
	Color testColor = new Color(Display.getCurrent(), 255, 128, 0);
	IPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.editors");
	prefs.setValue(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, testColorVal);
	prefs.setValue(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, false);

	prefs.setValue(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, testColorVal);
	prefs.setValue(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT, false);

	f = File.createTempFile("test" + System.currentTimeMillis(), ".ts");

	editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), f.toURI(),
			editorDescriptor.getId(), true);

	StyledText styledText = (StyledText) editor.getAdapter(Control.class);

	String themeId = manager.getDefaultTheme().getId();
	ITheme theme = manager.getThemeById(themeId);
	assertEquals("Default light theme isn't set", themeId, SolarizedLight);

	assertEquals("Background color should be user defined", styledText.getBackground(), testColor);
	assertEquals("Foreground colors should be ", theme.getEditorForeground(), styledText.getForeground());
	assertEquals("Selection background color should be user defined", theme.getEditorSelectionBackground(),
			testColor);
	assertNull("Selection foreground should be System default (null)", theme.getEditorSelectionForeground());

	Color lineHighlight = ColorManager.getInstance()
			.getPreferenceEditorColor(EDITOR_CURRENTLINE_HIGHLIGHT);
	assertNotNull("Highlight shouldn't be a null", lineHighlight);
	assertEquals("Line highlight should be from preferences (because of user defined background)", lineHighlight,
			theme.getEditorCurrentLineHighlight());
}
 
Example #30
Source File: JavadocView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ISelection getSelection() {
	if (fControl instanceof StyledText) {
		IDocument document= new Document(((StyledText)fControl).getSelectionText());
		return new TextSelection(document, 0, document.getLength());
	} else {
		// FIXME: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63022
		return StructuredSelection.EMPTY;
	}
}