1
/*******************************************************************************
2
* Copyright (c) 2006 IBM Corporation.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
10
*******************************************************************************/
12
package org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.c;
14
import org.eclipse.jface.preference.IPreferenceStore;
15
import org.eclipse.jface.preference.PreferenceConverter;
16
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.ITextDoubleClickStrategy;
18
import org.eclipse.jface.text.TextAttribute;
19
import org.eclipse.jface.text.presentation.IPresentationReconciler;
20
import org.eclipse.jface.text.presentation.PresentationReconciler;
21
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
22
import org.eclipse.jface.text.source.ISourceViewer;
23
import org.eclipse.jface.text.source.SourceViewerConfiguration;
24
import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin;
25
import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants;
26
import org.eclipse.linuxtools.systemtap.ui.editor.ColorManager;
27
import org.eclipse.linuxtools.systemtap.ui.editor.DoubleClickStrategy;
28
import org.eclipse.linuxtools.systemtap.ui.editor.NonRuleBasedDamagerRepairer;
29
import org.eclipse.linuxtools.systemtap.ui.logging.LogManager;
30
import org.eclipse.swt.graphics.RGB;
35
* Configures an instance of <code>CEditor</code>. This class is responsible for starting
36
* the Syntax highlighting system.
37
* @author Henry Hughes
40
public class CConfiguration extends SourceViewerConfiguration {
41
private DoubleClickStrategy doubleClickStrategy;
42
private CScanner scanner;
43
private ColorManager colorManager;
46
* The constructor for the <code>CConfiguration</code> class. Takes as its only parameter
47
* the ColorManager to use for syntax highlighting.
48
* @param colorManager the <code>ColorManager</code> to use for text highlighting
50
public CConfiguration(ColorManager colorManager) {
51
LogManager.logDebug("Start/End CConfiguration: colorManager-" + colorManager, this); //$NON-NLS-1$
52
this.colorManager = colorManager;
55
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
56
LogManager.logDebug("Start/End getConfiguredContentTypes: sourceViewer-" + sourceViewer, this); //$NON-NLS-1$
58
IDocument.DEFAULT_CONTENT_TYPE,
59
CPartitionScanner.C_COMMENT};
62
public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
63
LogManager.logDebug("Start getDoubleClickStrategy: sourceViewer-" + sourceViewer + ", contentType-" + contentType, this); //$NON-NLS-1$ //$NON-NLS-2$
64
if (doubleClickStrategy == null)
65
doubleClickStrategy = new DoubleClickStrategy();
66
LogManager.logDebug("End getDoubleClickStrategy: returnVal-" + doubleClickStrategy, this); //$NON-NLS-1$
67
return doubleClickStrategy;
71
* An accessor method for the <code>CScanner</code> associated with this editor. This method is used
72
* in order to dispatch notifications to the <code>CScanner</code> when the color preferences have
73
* been changed. The <code>CEditor</code> class calls this method to get the <code>CScanner</code>
74
* associated with it, and then it reinitializes that <code>CScanner</code> using the
75
* <code>CScanner.initializeScanner</code> method.
76
* @return the instance of the CScanner associated with this instance
78
protected CScanner getCScanner() {
79
LogManager.logDebug("Start getCScanner:", this); //$NON-NLS-1$
80
if (scanner == null) {
81
scanner = new CScanner(colorManager);
83
LogManager.logDebug("End getCScanner: returnVal-" + scanner, this); //$NON-NLS-1$
88
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
89
LogManager.logDebug("Start getPresentationReconciler: sourceViewer-" + sourceViewer, this); //$NON-NLS-1$
90
PresentationReconciler reconciler = new PresentationReconciler();
92
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCScanner());
93
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
94
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
95
IPreferenceStore store = IDEPlugin.getDefault().getPreferenceStore();
96
RGB comment = PreferenceConverter.getColor(store, IDEPreferenceConstants.P_C_COMMENT_COLOR);
97
NonRuleBasedDamagerRepairer ndr =
98
new NonRuleBasedDamagerRepairer(
99
new TextAttribute(colorManager.getColor(comment)));
100
reconciler.setDamager(ndr, CPartitionScanner.C_COMMENT);
101
reconciler.setRepairer(ndr, CPartitionScanner.C_COMMENT);
103
LogManager.logDebug("End getPresentationReconciler: returnVal-" + reconciler, this); //$NON-NLS-1$