01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.texteditor;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.widgets.Shell;
14:
15: import org.eclipse.jface.resource.JFaceResources;
16:
17: import org.eclipse.jface.text.IInformationControl;
18: import org.eclipse.jface.text.IInformationControlCreator;
19: import org.eclipse.jface.text.source.ILineRange;
20: import org.eclipse.jface.text.source.ISourceViewer;
21: import org.eclipse.jface.text.source.LineChangeHover;
22:
23: import org.eclipse.ui.editors.text.EditorsUI;
24:
25: /**
26: * Change hover for text editors. Respects tab settings and text editor font.
27: *
28: * @since 3.0
29: */
30: public class TextChangeHover extends LineChangeHover {
31:
32: /** The last created information control. */
33: private int fLastScrollIndex = 0;
34:
35: /*
36: * @see org.eclipse.jface.text.source.LineChangeHover#getTabReplacement()
37: */
38: protected String getTabReplacement() {
39: return Character.toString('\t');
40: }
41:
42: /*
43: * @see org.eclipse.jface.text.source.LineChangeHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, org.eclipse.jface.text.source.ILineRange, int)
44: */
45: public Object getHoverInfo(ISourceViewer sourceViewer,
46: ILineRange lineRange, int visibleLines) {
47: fLastScrollIndex = sourceViewer.getTextWidget()
48: .getHorizontalPixel();
49: return super
50: .getHoverInfo(sourceViewer, lineRange, visibleLines);
51: }
52:
53: /*
54: * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverControlCreator()
55: */
56: public IInformationControlCreator getHoverControlCreator() {
57: return new IInformationControlCreator() {
58: public IInformationControl createInformationControl(
59: Shell parent) {
60: SourceViewerInformationControl control = new SourceViewerInformationControl(
61: parent, SWT.NO_TRIM | SWT.TOOL, SWT.NONE,
62: JFaceResources.TEXT_FONT, EditorsUI
63: .getTooltipAffordanceString());
64: control.setHorizontalScrollPixel(fLastScrollIndex);
65: return control;
66: }
67: };
68: }
69:
70: /*
71: * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
72: * @since 3.3
73: */
74: public IInformationControlCreator getInformationPresenterControlCreator() {
75: return new IInformationControlCreator() {
76: public IInformationControl createInformationControl(
77: Shell parent) {
78: int shellStyle = SWT.RESIZE | SWT.TOOL;
79: int style = SWT.V_SCROLL | SWT.H_SCROLL;
80: return new SourceViewerInformationControl(parent,
81: shellStyle, style, JFaceResources.TEXT_FONT,
82: null);
83: }
84: };
85: }
86:
87: }
|