Search in sources :

Example 91 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method setFont.

/**
 * Sets the font for the given viewer sustaining selection and scroll position.
 *
 * @param sourceViewer the source viewer
 * @param font the font
 * @since 2.0
 */
private void setFont(ISourceViewer sourceViewer, Font font) {
    if (sourceViewer.getDocument() != null) {
        ISelectionProvider provider = sourceViewer.getSelectionProvider();
        ISelection selection = provider.getSelection();
        int topIndex = sourceViewer.getTopIndex();
        StyledText styledText = sourceViewer.getTextWidget();
        Control parent = styledText;
        if (sourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) sourceViewer;
            parent = extension.getControl();
        }
        parent.setRedraw(false);
        styledText.setFont(font);
        if (fVerticalRuler instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
            e.setFont(font);
        }
        provider.setSelection(selection);
        sourceViewer.setTopIndex(topIndex);
        if (parent instanceof Composite) {
            Composite composite = (Composite) parent;
            composite.layout(true);
        }
        parent.setRedraw(true);
    } else {
        StyledText styledText = sourceViewer.getTextWidget();
        styledText.setFont(font);
        if (fVerticalRuler instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
            e.setFont(font);
        }
    }
}
Also used : IVerticalRulerExtension(org.eclipse.jface.text.source.IVerticalRulerExtension) Control(org.eclipse.swt.widgets.Control) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Composite(org.eclipse.swt.widgets.Composite) ISelection(org.eclipse.jface.viewers.ISelection) Point(org.eclipse.swt.graphics.Point)

Example 92 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method setBlockSelectionMode.

/**
 * @see org.eclipse.ui.texteditor.ITextEditorExtension5#setBlockSelectionMode(boolean)
 * @since 3.5
 */
@Override
public void setBlockSelectionMode(boolean enable) {
    if (!isBlockSelectionModeSupported())
        return;
    ISourceViewer viewer = getSourceViewer();
    if (viewer != null) {
        StyledText styledText = viewer.getTextWidget();
        if (styledText != null) {
            /*
				 * Font switching. block selection mode needs a monospace font.
				 *  - set the font _before enabling_ block selection mode in order to maintain the
				 * selection
				 * - revert the font _after disabling_ block selection mode in order to maintain the
				 * selection
				 */
            if (enable) {
                Font blockFont = JFaceResources.getFont(BLOCK_SELECTION_MODE_FONT);
                Font normalFont = styledText.getFont();
                if (!blockFont.equals(normalFont) && !normalFont.getFontData()[0].equals(blockFont.getFontData()[0])) {
                    setFont(viewer, blockFont);
                    disposeFont();
                    updateCaret();
                }
                // we must unset word wrap before we can set block selection
                if (isWordWrapEnabled()) {
                    setWordWrap(false);
                }
            }
            styledText.setBlockSelection(enable);
            if (!enable) {
                initializeViewerFont(viewer);
                updateCaret();
            }
        }
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Font(org.eclipse.swt.graphics.Font)

Example 93 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method initializeViewerColors.

/**
 * Initializes the fore- and background colors of the given viewer for both
 * normal and selected text.
 *
 * @param viewer the viewer to be initialized
 * @since 2.0
 */
protected void initializeViewerColors(ISourceViewer viewer) {
    IPreferenceStore store = getPreferenceStore();
    if (store != null) {
        StyledText styledText = viewer.getTextWidget();
        // ----------- foreground color --------------------
        Color color = store.getBoolean(PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
        styledText.setForeground(color);
        if (fForegroundColor != null)
            fForegroundColor.dispose();
        fForegroundColor = color;
        // ---------- background color ----------------------
        color = store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
        styledText.setBackground(color);
        if (fBackgroundColor != null)
            fBackgroundColor.dispose();
        fBackgroundColor = color;
        // ----------- selection foreground color --------------------
        color = store.getBoolean(PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, PREFERENCE_COLOR_SELECTION_FOREGROUND, styledText.getDisplay());
        styledText.setSelectionForeground(color);
        if (fSelectionForegroundColor != null)
            fSelectionForegroundColor.dispose();
        fSelectionForegroundColor = color;
        // ---------- selection background color ----------------------
        color = store.getBoolean(PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, PREFERENCE_COLOR_SELECTION_BACKGROUND, styledText.getDisplay());
        styledText.setSelectionBackground(color);
        if (fSelectionBackgroundColor != null)
            fSelectionBackgroundColor.dispose();
        fSelectionBackgroundColor = color;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Color(org.eclipse.swt.graphics.Color) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 94 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method getCursorPosition.

/**
 * Returns a description of the cursor position.
 *
 * @return a description of the cursor position
 * @since 2.0
 */
protected String getCursorPosition() {
    if (fSourceViewer == null)
        return fErrorLabel;
    StyledText styledText = fSourceViewer.getTextWidget();
    int caret = widgetOffset2ModelOffset(fSourceViewer, styledText.getCaretOffset());
    IDocument document = fSourceViewer.getDocument();
    if (document == null)
        return fErrorLabel;
    try {
        int line = document.getLineOfOffset(caret);
        int lineOffset = document.getLineOffset(line);
        int tabWidth = styledText.getTabs();
        int column = 0;
        for (int i = lineOffset; i < caret; i++) if ('\t' == document.getChar(i))
            column += tabWidth - (tabWidth == 0 ? 0 : column % tabWidth);
        else
            column++;
        fLineLabel.fValue = line + 1;
        fColumnLabel.fValue = column + 1;
        return NLSUtility.format(fPositionLabelPattern, fPositionLabelPatternArguments);
    } catch (BadLocationException x) {
        return fErrorLabel;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 95 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method doRestoreState.

/**
 * Restores this editor's state using the given memento.
 * <p>
 * Subclasses may extend or override this method.</p>
 *
 * @param memento the saved state of this editor
 * @since 3.3
 */
protected void doRestoreState(IMemento memento) {
    Integer offset = memento.getInteger(TAG_SELECTION_OFFSET);
    if (offset == null)
        return;
    Integer length = memento.getInteger(TAG_SELECTION_LENGTH);
    if (length == null)
        return;
    doSetSelection(new TextSelection(offset.intValue(), length.intValue()));
    final StyledText textWidget = fSourceViewer.getTextWidget();
    Integer topPixel = memento.getInteger(TAG_SELECTION_TOP_PIXEL);
    if (topPixel != null)
        textWidget.setTopPixel(topPixel.intValue());
    Integer horizontalPixel = memento.getInteger(TAG_SELECTION_HORIZONTAL_PIXEL);
    if (horizontalPixel != null)
        textWidget.setHorizontalPixel(horizontalPixel.intValue());
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)329 Point (org.eclipse.swt.graphics.Point)102 GridData (org.eclipse.swt.layout.GridData)68 Composite (org.eclipse.swt.widgets.Composite)63 GridLayout (org.eclipse.swt.layout.GridLayout)62 Control (org.eclipse.swt.widgets.Control)46 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Label (org.eclipse.swt.widgets.Label)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Display (org.eclipse.swt.widgets.Display)30 Shell (org.eclipse.swt.widgets.Shell)30 Rectangle (org.eclipse.swt.graphics.Rectangle)27 Color (org.eclipse.swt.graphics.Color)25 FillLayout (org.eclipse.swt.layout.FillLayout)25 Button (org.eclipse.swt.widgets.Button)23 Text (org.eclipse.swt.widgets.Text)21 StyleRange (org.eclipse.swt.custom.StyleRange)20 Font (org.eclipse.swt.graphics.Font)20 Event (org.eclipse.swt.widgets.Event)20 Test (org.junit.Test)20