1 19 20 package ca.mcgill.sable.soot.editors; 21 22 import org.eclipse.jface.text.IDocument; 23 import org.eclipse.jface.text.ITextDoubleClickStrategy; 24 import org.eclipse.jface.text.ITextHover; 25 import org.eclipse.jface.text.TextAttribute; 26 27 import org.eclipse.jface.text.contentassist.*; 28 import org.eclipse.jface.text.presentation.IPresentationReconciler; 29 import org.eclipse.jface.text.presentation.PresentationReconciler; 30 import org.eclipse.jface.text.rules.DefaultDamagerRepairer; 31 import org.eclipse.jface.text.rules.Token; 32 import org.eclipse.jface.text.source.ISourceViewer; 33 import org.eclipse.jface.text.source.SourceViewerConfiguration; 34 import ca.mcgill.sable.soot.attributes.SootAttributesJimpleHover; 35 36 37 38 public class JimpleConfiguration extends SourceViewerConfiguration { 39 private JimpleDoubleClickStrategy doubleClickStrategy; 40 private JimpleScanner scanner; 41 private ColorManager colorManager; 42 private JimpleEditor editor; 43 44 public JimpleConfiguration(ColorManager colorManager, JimpleEditor editor) { 45 this.colorManager = colorManager; 46 setEditor(editor); 47 } 48 public String [] getConfiguredContentTypes(ISourceViewer sourceViewer) { 49 return new String [] { 50 IDocument.DEFAULT_CONTENT_TYPE}; 51 } 52 public ITextDoubleClickStrategy getDoubleClickStrategy( 53 ISourceViewer sourceViewer, 54 String contentType) { 55 if (doubleClickStrategy == null) 56 doubleClickStrategy = new JimpleDoubleClickStrategy(); 57 return doubleClickStrategy; 58 } 59 60 protected JimpleScanner getJimpleScanner() { 61 if (scanner == null) { 62 scanner = new JimpleScanner(colorManager); 63 scanner.setDefaultReturnToken( 64 new Token( 65 new TextAttribute(colorManager.getColor(IJimpleColorConstants.JIMPLE_DEFAULT)))); 66 } 67 return scanner; 68 } 69 70 73 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { 74 75 PresentationReconciler reconciler= new PresentationReconciler(); 76 77 DefaultDamagerRepairer dr= new DefaultDamagerRepairer(getJimpleScanner()); 78 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); 79 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); 80 81 dr= new DefaultDamagerRepairer(getJimpleScanner()); 82 reconciler.setDamager(dr, JimplePartitionScanner.JIMPLE_STRING); 83 reconciler.setRepairer(dr, JimplePartitionScanner.JIMPLE_STRING); 84 85 return reconciler; 86 87 } 88 91 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { 92 return new SootAttributesJimpleHover(getEditor()); 93 } 94 95 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer){ 96 IContentAssistant ca = new ContentAssistant(); 97 ca.install(sourceViewer); 98 return ca; 99 } 100 104 public JimpleEditor getEditor() { 105 return editor; 106 } 107 108 112 public void setEditor(JimpleEditor editor) { 113 this.editor = editor; 114 } 115 116 } 117 | Popular Tags |