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);
}
}
}
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();
}
}
}
}
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;
}
}
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;
}
}
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());
}
Aggregations