1 11 package org.eclipse.jdt.internal.ui.text; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.swt.widgets.Shell; 18 19 import org.eclipse.jface.text.BadLocationException; 20 import org.eclipse.jface.text.IDocument; 21 import org.eclipse.jface.text.IInformationControl; 22 import org.eclipse.jface.text.IInformationControlCreator; 23 import org.eclipse.jface.text.ITypedRegion; 24 import org.eclipse.jface.text.TextUtilities; 25 import org.eclipse.jface.text.source.ISourceViewer; 26 import org.eclipse.jface.text.source.LineChangeHover; 27 28 import org.eclipse.ui.editors.text.EditorsUI; 29 30 36 public class JavaChangeHover extends LineChangeHover { 37 38 39 private String fPartition; 40 41 private ChangeHoverInformationControl fInformationControl; 42 43 private String fPartitioning; 44 45 private int fLastScrollIndex= 0; 46 47 52 private int fOrientation; 53 54 60 public JavaChangeHover(String partitioning, int orientation) { 61 Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT); 62 fPartitioning= partitioning; 63 fOrientation= orientation; 64 } 65 66 69 protected String formatSource(String content) { 70 return content; 71 } 72 73 76 public IInformationControlCreator getHoverControlCreator() { 77 return new IInformationControlCreator() { 78 public IInformationControl createInformationControl(Shell parent) { 79 int shellStyle= SWT.TOOL | SWT.NO_TRIM | fOrientation; 80 fInformationControl= new ChangeHoverInformationControl(parent, shellStyle, SWT.NONE, fPartition, EditorsUI.getTooltipAffordanceString()); 81 fInformationControl.setHorizontalScrollPixel(fLastScrollIndex); 82 return fInformationControl; 83 } 84 }; 85 } 86 87 91 public IInformationControlCreator getInformationPresenterControlCreator() { 92 return new IInformationControlCreator() { 93 public IInformationControl createInformationControl(Shell parent) { 94 int shellStyle= SWT.RESIZE | SWT.TOOL | fOrientation; 95 int style= SWT.V_SCROLL | SWT.H_SCROLL; 96 fInformationControl= new ChangeHoverInformationControl(parent, shellStyle, style, fPartition, null); 97 fInformationControl.setHorizontalScrollPixel(fLastScrollIndex); 98 return fInformationControl; 99 } 100 }; 101 } 102 103 106 protected Point computeLineRange(ISourceViewer viewer, int line, int first, int number) { 107 Point lineRange= super.computeLineRange(viewer, line, first, number); 108 if (lineRange != null) { 109 fPartition= getPartition(viewer, lineRange.x); 110 } else { 111 fPartition= IDocument.DEFAULT_CONTENT_TYPE; 112 } 113 fLastScrollIndex= viewer.getTextWidget().getHorizontalPixel(); 114 if (fInformationControl != null) { 115 fInformationControl.setStartingPartitionType(fPartition); 116 fInformationControl.setHorizontalScrollPixel(fLastScrollIndex); 117 } 118 return lineRange; 119 } 120 121 128 private String getPartition(ISourceViewer viewer, int startLine) { 129 if (viewer == null) 130 return null; 131 IDocument doc= viewer.getDocument(); 132 if (doc == null) 133 return null; 134 if (startLine <= 0) 135 return IDocument.DEFAULT_CONTENT_TYPE; 136 try { 137 ITypedRegion region= TextUtilities.getPartition(doc, fPartitioning, doc.getLineOffset(startLine) - 1, true); 138 return region.getType(); 139 } catch (BadLocationException e) { 140 } 141 return IDocument.DEFAULT_CONTENT_TYPE; 142 } 143 144 145 148 protected String getTabReplacement() { 149 return Character.toString('\t'); 150 } 151 } 152 | Popular Tags |