use of org.erlide.ui.prefs.TokenHighlight in project erlide_eclipse by erlang.
the class ErlangSourceViewer method createErlangPreviewer.
public static SourceViewer createErlangPreviewer(final Composite parent, final IColorManager colorManager0, final IPreferenceStore topStore, final Map<TokenHighlight, HighlightStyle> colors0, final String content) {
// TODO we should move this method, to a utility class (or maybe create
// an ErlangPreviewSourceViewer class)
final IColorManager colorManager = colorManager0 != null ? colorManager0 : new ColorManager();
Map<TokenHighlight, HighlightStyle> colors;
if (colors0 == null) {
colors = Maps.newHashMap();
for (final TokenHighlight th : TokenHighlight.values()) {
colors.put(th, null);
}
} else {
colors = colors0;
}
final IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
final IPreferenceStore store = topStore == null ? new ChainedPreferenceStore(new IPreferenceStore[] { generalTextStore }) : new ChainedPreferenceStore(new IPreferenceStore[] { topStore, generalTextStore });
final SourceViewer viewer = new SourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
final IDocument document = new Document(content);
viewer.setDocument(document);
final ErlangDocumentSetupParticipant setupParticipant = new ErlangDocumentSetupParticipant();
setupParticipant.setup(document);
final ErlangSourceViewerConfiguration configuration = new SyntaxColorPreviewEditorConfiguration(store, colorManager);
viewer.configure(configuration);
final Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
viewer.getTextWidget().setFont(font);
new ErlangSourceViewerUpdater(viewer, configuration, store);
viewer.setEditable(false);
final Cursor arrowCursor = viewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
viewer.getTextWidget().setCursor(arrowCursor);
return viewer;
}
use of org.erlide.ui.prefs.TokenHighlight in project erlide_eclipse by erlang.
the class ColoringPreferencePage method getHighlight.
/**
* Returns the current highlighting color list item.
*
* @return the current highlighting color list item
*/
TokenHighlight getHighlight() {
if (fListViewer == null) {
return null;
}
final IStructuredSelection selection = (IStructuredSelection) fListViewer.getSelection();
final Object element = selection.getFirstElement();
if (element == null || element instanceof String) {
return null;
}
return (TokenHighlight) element;
}
use of org.erlide.ui.prefs.TokenHighlight in project erlide_eclipse by erlang.
the class ColoringPreferencePage method createSyntaxPage.
private Control createSyntaxPage(final Composite parent) {
final Composite colorComposite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
colorComposite.setLayout(layout);
final Link link = new Link(colorComposite, SWT.NONE);
link.setText(PreferencesMessages.ErlEditorColoringConfigurationBlock_link);
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
}
});
final GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
gridData.widthHint = 150;
gridData.horizontalSpan = 2;
link.setLayoutData(gridData);
addFiller(colorComposite, 1);
Label label;
label = new Label(colorComposite, SWT.LEFT);
label.setText(PreferencesMessages.ErlEditorPreferencePage_coloring_element);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Composite editorComposite = new Composite(colorComposite, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
editorComposite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
editorComposite.setLayoutData(gd);
fListViewer = new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER);
final Tree tree = fListViewer.getTree();
final GridData gdTree = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
gdTree.widthHint = 100;
tree.setLayoutData(gdTree);
fListViewer.setLabelProvider(new ColorListLabelProvider());
fListViewer.setContentProvider(new ColorListContentProvider());
fListViewer.setInput(fColors);
fListViewer.setSelection(new StructuredSelection(fErlangCategory));
fListViewer.setComparator(new ViewerComparator() {
@Override
public int category(final Object element) {
// don't sort the top level categories
if (fErlangCategory.equals(element)) {
return 0;
}
// return 1;
return 0;
}
});
gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
gd.heightHint = convertHeightInCharsToPixels(9);
int maxWidth = 0;
for (final TokenHighlight item : fColors.keySet()) {
maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getName().length()));
}
final ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar();
if (vBar != null) {
// scrollbars and tree
maxWidth += vBar.getSize().x * 3;
}
// indentation guess
gd.widthHint = maxWidth;
fListViewer.getControl().setLayoutData(gd);
fListViewer.expandAll();
final Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
stylesComposite.setLayout(layout);
stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
fEnableCheckbox = new Button(stylesComposite, SWT.CHECK);
fEnableCheckbox.setText(PreferencesMessages.ErlEditorPreferencePage_enable);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalSpan = 2;
fEnableCheckbox.setLayoutData(gd);
// TODO hide this until reworking the dialog
fEnableCheckbox.setVisible(false);
fColorEditorLabel = new Label(stylesComposite, SWT.LEFT);
fColorEditorLabel.setText(PreferencesMessages.ErlEditorPreferencePage_color);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalIndent = 20;
fColorEditorLabel.setLayoutData(gd);
fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite);
final Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
foregroundColorButton.setLayoutData(gd);
new Label(stylesComposite, SWT.NONE);
fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
fBoldCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_bold);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalIndent = 20;
gd.horizontalSpan = 2;
fBoldCheckBox.setLayoutData(gd);
fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
fItalicCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_italic);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalIndent = 20;
gd.horizontalSpan = 2;
fItalicCheckBox.setLayoutData(gd);
fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK);
fStrikethroughCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_strikeout);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalIndent = 20;
gd.horizontalSpan = 2;
fStrikethroughCheckBox.setLayoutData(gd);
fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK);
fUnderlineCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_underline);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalIndent = 20;
gd.horizontalSpan = 2;
fUnderlineCheckBox.setLayoutData(gd);
final String content = ColoringPreferencePage.loadPreviewContentFromFile(getClass(), // $NON-NLS-1$
"ColorSettingPreviewCode.txt");
fPreviewViewer = ErlangSourceViewer.createErlangPreviewer(colorComposite, fColorManager, fOverlayStore, fColors, content);
final Control previewer = fPreviewViewer.getControl();
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = convertWidthInCharsToPixels(20);
gd.heightHint = convertHeightInCharsToPixels(5);
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
previewer.setLayoutData(gd);
fListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
handleSyntaxColorListSelection();
}
});
foregroundColorButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
final TokenHighlight item = getHighlight();
final HighlightStyle data = item.getStyle(fOverlayStore);
if (data == null) {
return;
}
data.setColor(fSyntaxForegroundColorEditor.getColorValue());
storeHighlight(fOverlayStore, item, data);
fPreviewViewer.invalidateTextPresentation();
}
});
fBoldCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
final TokenHighlight item = getHighlight();
final HighlightStyle data = item.getStyle(fOverlayStore);
if (data == null) {
return;
}
data.setStyle(SWT.BOLD, fBoldCheckBox.getSelection());
storeHighlight(fOverlayStore, item, data);
fPreviewViewer.invalidateTextPresentation();
}
});
fItalicCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
final TokenHighlight item = getHighlight();
final HighlightStyle data = item.getStyle(fOverlayStore);
if (data == null) {
return;
}
data.setStyle(SWT.ITALIC, fItalicCheckBox.getSelection());
storeHighlight(fOverlayStore, item, data);
fPreviewViewer.invalidateTextPresentation();
}
});
fStrikethroughCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
final TokenHighlight item = getHighlight();
final HighlightStyle data = item.getStyle(fOverlayStore);
if (data == null) {
return;
}
data.setStyle(TextAttribute.STRIKETHROUGH, fStrikethroughCheckBox.getSelection());
storeHighlight(fOverlayStore, item, data);
fPreviewViewer.invalidateTextPresentation();
}
});
fUnderlineCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
final TokenHighlight item = getHighlight();
final HighlightStyle data = item.getStyle(fOverlayStore);
if (data == null) {
return;
}
data.setStyle(TextAttribute.UNDERLINE, fUnderlineCheckBox.getSelection());
storeHighlight(fOverlayStore, item, data);
fPreviewViewer.invalidateTextPresentation();
}
});
fEnableCheckbox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
fEnableCheckbox.setSelection(true);
// final TokenHighlight item = getHighlight();
// if (item instanceof SemanticHighlightingColorListItem) {
// final boolean enable = fEnableCheckbox.getSelection();
// getPreferenceStore().setValue(
// ((SemanticHighlightingColorListItem) item)
// .getEnableKey(), enable);
// fEnableCheckbox.setSelection(enable);
// fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
// fColorEditorLabel.setEnabled(enable);
// fBoldCheckBox.setEnabled(enable);
// fItalicCheckBox.setEnabled(enable);
// fStrikethroughCheckBox.setEnabled(enable);
// fUnderlineCheckBox.setEnabled(enable);
// }
}
});
colorComposite.layout(false);
handleSyntaxColorListSelection();
fPreviewViewer.invalidateTextPresentation();
return colorComposite;
}
use of org.erlide.ui.prefs.TokenHighlight in project erlide_eclipse by erlang.
the class ColoringPreferencePage method createOverlayStoreKeys.
private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
final List<OverlayPreferenceStore.OverlayKey> overlayKeys = Lists.newArrayList();
for (final TokenHighlight item : TokenHighlight.values()) {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.TypeDescriptor.STRING, item.getColorKey()));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.TypeDescriptor.INT, item.getStylesKey()));
}
final OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
overlayKeys.toArray(keys);
return keys;
}
use of org.erlide.ui.prefs.TokenHighlight in project erlide_eclipse by erlang.
the class ColoringPreferencePage method init.
/**
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
@Override
public void init(final IWorkbench workbench) {
fColorManager = new ColorManager();
fOverlayStore = new OverlayPreferenceStore(ErlideUIPlugin.getDefault().getPreferenceStore(), new OverlayPreferenceStore.OverlayKey[] {});
fOverlayStore.addKeys(createOverlayStoreKeys());
fOverlayStore.load();
fOverlayStore.start();
for (final TokenHighlight th : TokenHighlight.values()) {
fColors.put(th, null);
}
}
Aggregations