1 11 package org.eclipse.jface.text.source; 12 13 14 import java.util.Arrays ; 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.RGB; 18 import org.eclipse.swt.widgets.Shell; 19 20 import org.eclipse.jface.text.DefaultAutoIndentStrategy; 21 import org.eclipse.jface.text.DefaultInformationControl; 22 import org.eclipse.jface.text.DefaultTextDoubleClickStrategy; 23 import org.eclipse.jface.text.IAutoEditStrategy; 24 import org.eclipse.jface.text.IAutoIndentStrategy; 25 import org.eclipse.jface.text.IDocument; 26 import org.eclipse.jface.text.IDocumentExtension3; 27 import org.eclipse.jface.text.IInformationControl; 28 import org.eclipse.jface.text.IInformationControlCreator; 29 import org.eclipse.jface.text.ITextDoubleClickStrategy; 30 import org.eclipse.jface.text.ITextHover; 31 import org.eclipse.jface.text.ITextViewerExtension2; 32 import org.eclipse.jface.text.IUndoManager; 33 import org.eclipse.jface.text.TextViewerUndoManager; 34 import org.eclipse.jface.text.contentassist.IContentAssistant; 35 import org.eclipse.jface.text.formatter.IContentFormatter; 36 import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter; 37 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; 38 import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter; 39 import org.eclipse.jface.text.hyperlink.URLHyperlinkDetector; 40 import org.eclipse.jface.text.information.IInformationPresenter; 41 import org.eclipse.jface.text.presentation.IPresentationReconciler; 42 import org.eclipse.jface.text.presentation.PresentationReconciler; 43 import org.eclipse.jface.text.quickassist.IQuickAssistAssistant; 44 import org.eclipse.jface.text.reconciler.IReconciler; 45 46 47 63 public class SourceViewerConfiguration { 64 65 66 70 public SourceViewerConfiguration() { 71 super(); 72 } 73 74 81 public int getTabWidth(ISourceViewer sourceViewer) { 82 return 4; 83 } 84 85 93 public IUndoManager getUndoManager(ISourceViewer sourceViewer) { 94 return new TextViewerUndoManager(25); 95 } 96 97 104 public IReconciler getReconciler(ISourceViewer sourceViewer) { 105 return null; 106 } 107 108 114 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { 115 PresentationReconciler reconciler= new PresentationReconciler(); 116 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); 117 return reconciler; 118 } 119 120 127 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { 128 return null; 129 } 130 131 138 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { 139 return null; 140 } 141 142 151 public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) { 152 return null; 153 } 154 155 165 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) { 166 return new DefaultAutoIndentStrategy(); 167 } 168 169 179 public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { 180 return new IAutoEditStrategy[] { getAutoIndentStrategy(sourceViewer, contentType) }; 181 } 182 183 193 public String [] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) { 194 return null; 195 } 196 197 206 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { 207 return new DefaultTextDoubleClickStrategy(); 208 } 209 210 222 public String [] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { 223 return new String [] { "\t", " ", "" }; } 225 226 235 protected String [] getIndentPrefixesForTab(int tabWidth) { 236 String [] indentPrefixes= new String [tabWidth + 2]; 237 for (int i= 0; i <= tabWidth; i++) { 238 char[] spaceChars= new char[i]; 239 Arrays.fill(spaceChars, ' '); 240 String spaces= new String (spaceChars); 241 if (i < tabWidth) 242 indentPrefixes[i]= spaces + '\t'; 243 else 244 indentPrefixes[i]= new String (spaces); 245 } 246 indentPrefixes[tabWidth + 1]= ""; return indentPrefixes; 248 } 249 250 258 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { 259 return null; 260 } 261 262 272 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) { 273 return getAnnotationHover(sourceViewer); 274 } 275 276 286 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) { 287 return null; 288 } 289 290 302 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { 303 if (stateMask == ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK) 304 return getTextHover(sourceViewer, contentType); 305 return null; 306 } 307 308 318 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { 319 return null; 320 } 321 322 331 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { 332 return new IInformationControlCreator() { 333 public IInformationControl createInformationControl(Shell parent) { 334 return new DefaultInformationControl(parent); 335 } 336 }; 337 } 338 339 348 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { 349 return null; 350 } 351 352 362 public String [] getConfiguredContentTypes(ISourceViewer sourceViewer) { 363 return new String [] { IDocument.DEFAULT_CONTENT_TYPE }; 364 } 365 366 376 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) { 377 return IDocumentExtension3.DEFAULT_PARTITIONING; 378 } 379 380 389 public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { 390 if (sourceViewer == null) 391 return null; 392 393 return new IHyperlinkDetector[] { new URLHyperlinkDetector() }; 394 } 395 396 404 public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer) { 405 return new DefaultHyperlinkPresenter(new RGB(0, 0, 255)); 406 } 407 408 417 public int getHyperlinkStateMask(ISourceViewer sourceViewer) { 418 return SWT.MOD1; 419 } 420 } 421 | Popular Tags |