1 11 package org.eclipse.jdt.internal.ui.compare; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.Font; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Control; 17 18 import org.eclipse.core.runtime.CoreException; 19 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.jface.resource.JFaceResources; 22 23 import org.eclipse.jface.text.Document; 24 import org.eclipse.jface.text.source.SourceViewer; 25 import org.eclipse.jface.viewers.ISelection; 26 import org.eclipse.jface.viewers.Viewer; 27 28 import org.eclipse.jdt.ui.text.IJavaPartitions; 29 import org.eclipse.jdt.ui.text.JavaTextTools; 30 import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; 31 import org.eclipse.jdt.internal.ui.JavaPlugin; 32 33 import org.eclipse.compare.IStreamContentAccessor; 34 35 36 public class JavaTextViewer extends Viewer { 37 38 private SourceViewer fSourceViewer; 39 private Object fInput; 40 41 42 JavaTextViewer(Composite parent) { 43 fSourceViewer= new SourceViewer(parent, null, SWT.LEFT_TO_RIGHT | SWT.H_SCROLL | SWT.V_SCROLL); 44 JavaTextTools tools= JavaCompareUtilities.getJavaTextTools(); 45 if (tools != null) { 46 IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); 47 fSourceViewer.configure(new JavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING)); 48 } 49 50 fSourceViewer.setEditable(false); 51 52 String symbolicFontName= JavaMergeViewer.class.getName(); 53 Font font= JFaceResources.getFont(symbolicFontName); 54 if (font != null) 55 fSourceViewer.getTextWidget().setFont(font); 56 57 } 58 59 public Control getControl() { 60 return fSourceViewer.getControl(); 61 } 62 63 public void setInput(Object input) { 64 if (input instanceof IStreamContentAccessor) { 65 Document document= new Document(getString(input)); 66 JavaCompareUtilities.setupDocument(document); 67 fSourceViewer.setDocument(document); 68 } 69 fInput= input; 70 } 71 72 public Object getInput() { 73 return fInput; 74 } 75 76 public ISelection getSelection() { 77 return null; 78 } 79 80 public void setSelection(ISelection s, boolean reveal) { 81 } 82 83 public void refresh() { 84 } 85 86 90 private static String getString(Object input) { 91 92 if (input instanceof IStreamContentAccessor) { 93 IStreamContentAccessor sca= (IStreamContentAccessor) input; 94 try { 95 return JavaCompareUtilities.readString(sca); 96 } catch (CoreException ex) { 97 JavaPlugin.log(ex); 98 } 99 } 100 return ""; } 102 } 103 | Popular Tags |