Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 19602 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/text/source/SourceViewer.java (+9 lines)
Lines 13-18 Link Here
13
import java.util.Stack;
13
import java.util.Stack;
14
14
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.custom.StyledTextPrintMarginDecorator;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.widgets.Canvas;
19
import org.eclipse.swt.widgets.Canvas;
Lines 1011-1014 Link Here
1011
			}
1012
			}
1012
		}
1013
		}
1013
	}
1014
	}
1015
1016
	/* (non-Javadoc)
1017
	 * @see org.eclipse.jface.text.TextViewer#getPreferredLineNumberDecorator(int)
1018
	 */
1019
	public StyledTextPrintMarginDecorator getPreferredLineNumberDecorator() {
1020
		return new SourceLineNumberMarginDecorator(this);
1021
	}
1022
1014
}
1023
}
(-)src/org/eclipse/jface/text/TextViewer.java (-2 / +30 lines)
Lines 28-33 Link Here
28
import org.eclipse.swt.custom.ST;
28
import org.eclipse.swt.custom.ST;
29
import org.eclipse.swt.custom.StyleRange;
29
import org.eclipse.swt.custom.StyleRange;
30
import org.eclipse.swt.custom.StyledText;
30
import org.eclipse.swt.custom.StyledText;
31
import org.eclipse.swt.custom.StyledTextPrintMarginDecorator;
32
import org.eclipse.swt.custom.StyledTextPrintOptions;
31
import org.eclipse.swt.custom.VerifyKeyListener;
33
import org.eclipse.swt.custom.VerifyKeyListener;
32
import org.eclipse.swt.dnd.DND;
34
import org.eclipse.swt.dnd.DND;
33
import org.eclipse.swt.events.ControlEvent;
35
import org.eclipse.swt.events.ControlEvent;
Lines 95-101 Link Here
95
public class TextViewer extends Viewer implements
97
public class TextViewer extends Viewer implements
96
					ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4, ITextViewerExtension6, IEditingSupportRegistry,
98
					ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4, ITextViewerExtension6, IEditingSupportRegistry,
97
					ITextOperationTarget, ITextOperationTargetExtension,
99
					ITextOperationTarget, ITextOperationTargetExtension,
98
					IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider {
100
					IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider, IPrintOptionsConsumer {
99
101
100
	/** Internal flag to indicate the debug state. */
102
	/** Internal flag to indicate the debug state. */
101
	public static final boolean TRACE_ERRORS= false;
103
	public static final boolean TRACE_ERRORS= false;
Lines 1394-1399 Link Here
1394
	 * @since 3.1
1396
	 * @since 3.1
1395
	 */
1397
	 */
1396
	private IPositionUpdater fSelectionUpdater;
1398
	private IPositionUpdater fSelectionUpdater;
1399
	/**
1400
	 * Options provider for the <code>print()</code> method
1401
	 * @since 3.2
1402
	 */
1403
	private IPrintOptionsProvider fPrintOptionsProvider;
1397
1404
1398
1405
1399
	//---- Construction and disposal ------------------
1406
	//---- Construction and disposal ------------------
Lines 3908-3913 Link Here
3908
		PrinterData[] printerList= Printer.getPrinterList();
3915
		PrinterData[] printerList= Printer.getPrinterList();
3909
		return (printerList != null && printerList.length > 0);
3916
		return (printerList != null && printerList.length > 0);
3910
	}
3917
	}
3918
	
3919
	/* (non-Javadoc)
3920
	 * @see org.eclipse.jface.text.IPrintOptionsConsumer#setPrintOptionProvider(org.eclipse.jface.text.IPrintOptionsProvider)
3921
	 */
3922
	public void setPrintOptionProvider(IPrintOptionsProvider provider) {
3923
		fPrintOptionsProvider = provider;
3924
	}
3925
3926
	/* (non-Javadoc)
3927
	 * @see org.eclipse.jface.text.IPrintOptionsConsumer#getPreferredLineNumberDecorator(int)
3928
	 */
3929
	public StyledTextPrintMarginDecorator getPreferredLineNumberDecorator() {
3930
		return null;
3931
	}
3911
3932
3912
	/**
3933
	/**
3913
	 * Brings up a print dialog and calls <code>printContents(Printer)</code> which
3934
	 * Brings up a print dialog and calls <code>printContents(Printer)</code> which
Lines 3921-3927 Link Here
3921
		if (data != null) {
3942
		if (data != null) {
3922
3943
3923
			final Printer printer= new Printer(data);
3944
			final Printer printer= new Printer(data);
3924
			final Runnable styledTextPrinter= fTextWidget.print(printer);
3945
			StyledTextPrintOptions options = null;
3946
			if (fPrintOptionsProvider != null)
3947
				options = fPrintOptionsProvider.getPrintOptions();
3948
			final Runnable styledTextPrinter =
3949
				options == null
3950
					? fTextWidget.print(printer)
3951
					: fTextWidget.print(printer, options);
3952
3925
3953
3926
			Thread printingThread= new Thread("Printing") { //$NON-NLS-1$
3954
			Thread printingThread= new Thread("Printing") { //$NON-NLS-1$
3927
				public void run() {
3955
				public void run() {
(-)projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java (+9 lines)
Lines 18-23 Link Here
18
import org.eclipse.swt.SWTError;
18
import org.eclipse.swt.SWTError;
19
import org.eclipse.swt.custom.ST;
19
import org.eclipse.swt.custom.ST;
20
import org.eclipse.swt.custom.StyledText;
20
import org.eclipse.swt.custom.StyledText;
21
import org.eclipse.swt.custom.StyledTextPrintMarginDecorator;
21
import org.eclipse.swt.dnd.Clipboard;
22
import org.eclipse.swt.dnd.Clipboard;
22
import org.eclipse.swt.dnd.DND;
23
import org.eclipse.swt.dnd.DND;
23
import org.eclipse.swt.dnd.TextTransfer;
24
import org.eclipse.swt.dnd.TextTransfer;
Lines 1772-1775 Link Here
1772
1773
1773
		return -1;
1774
		return -1;
1774
	}
1775
	}
1776
1777
	/* (non-Javadoc)
1778
	 * @see org.eclipse.jface.text.source.SourceViewer#getPreferredLineNumberDecorator(int)
1779
	 */
1780
	public StyledTextPrintMarginDecorator getPreferredLineNumberDecorator() {
1781
		return new ProjectionLineNumberMarginDecorator(this);
1782
	}
1783
1775
}
1784
}
(-)src/org/eclipse/jface/text/IPrintOptionsConsumer.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jface.text;
12
13
import org.eclipse.swt.custom.StyledTextPrintMarginDecorator;
14
15
/**
16
 * A print options consumer uses an {@link IPrintOptionsProvider} to acquire
17
 * print options. The class {@link TextViewer} implements this interface to
18
 * enable editors to set options providers.
19
 * 
20
 * @since 3.2
21
 */
22
public interface IPrintOptionsConsumer {
23
24
	/**
25
	 * Implementors must return an instance of
26
	 * <code>StyledTextPrintOptions</code> suitable for printing the current
27
	 * contents of this viewer's <code>StyledText</code> control.
28
	 * 
29
	 * @param provider the options provider
30
	 */
31
	public void setPrintOptionProvider(IPrintOptionsProvider provider);
32
33
	/**
34
	 * A consumer will have the opportunity to return an instance of their
35
	 * preferred <code>StyledTextPrintMarginDecorator</code> implementation.
36
	 * It is permissible to return <code>null</code>.
37
	 * 
38
	 * @return the preferred line number print margin decorator
39
	 */
40
	public StyledTextPrintMarginDecorator getPreferredLineNumberDecorator();
41
}
(-)src/org/eclipse/jface/text/source/SourceLineNumberMarginDecorator.java (+103 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jface.text.source;
12
13
import org.eclipse.jface.internal.text.JFaceTextUtil;
14
import org.eclipse.jface.text.ITextViewer;
15
import org.eclipse.swt.custom.StyledTextPrintMarginDecorator;
16
import org.eclipse.swt.graphics.GC;
17
import org.eclipse.swt.graphics.TextStyle;
18
19
/**
20
 * A simple implementation of StyledTextPrintMarginDecorator that prints right
21
 * aligned line numbers. The line numbers are mapped to the document line
22
 * numbers.
23
 */
24
public class SourceLineNumberMarginDecorator implements
25
		StyledTextPrintMarginDecorator {
26
27
	private ITextViewer fTextViewer = null;
28
29
	private int fGutter = 0;
30
31
	/**
32
	 * Constructs a decorator with a gutter as specified.
33
	 * 
34
	 * @param viewer the viewer for line number conversion. If <code>null</code>
35
	 *            is passed, null is returned from {@link #getMarginText(int)}
36
	 */
37
	public SourceLineNumberMarginDecorator(ITextViewer viewer) {
38
		super();
39
		fTextViewer = viewer;
40
41
		GC gc = new GC(fTextViewer.getTextWidget());
42
		fGutter = gc.getAdvanceWidth(' ');
43
		gc.dispose();
44
	}
45
46
	/*
47
	 * (non-Javadoc)
48
	 */
49
	protected SourceLineNumberMarginDecorator(ITextViewer viewer, int gutter) {
50
		super();
51
		fTextViewer = viewer;
52
		fGutter = gutter;
53
	}
54
55
	/*
56
	 * (non-Javadoc)
57
	 * 
58
	 * @see org.eclipse.swt.custom.StyledTextPrintMarginDecorator#getAlignment()
59
	 */
60
	public int getAlignment() {
61
		return FORCE_RIGHT;
62
	}
63
64
	/*
65
	 * (non-Javadoc)
66
	 * 
67
	 * @see org.eclipse.swt.custom.StyledTextPrintMarginDecorator#getGutter()
68
	 */
69
	public int getGutter() {
70
		return fGutter;
71
	}
72
73
	/*
74
	 * (non-Javadoc)
75
	 * 
76
	 * @see org.eclipse.swt.custom.StyledTextPrintMarginDecorator#getMarginText(int)
77
	 */
78
	public String getMarginText(int line) {
79
		String text = null;
80
		// This should not happen but degrade non-essential function gracefully.
81
		if (fTextViewer != null)
82
			text = Integer.toString(getModelLineNumber(line) + 1);
83
		return text;
84
	}
85
86
	/**
87
	 * @param line the widget line number
88
	 * @return the model line number
89
	 */
90
	protected int getModelLineNumber(int line) {
91
		return JFaceTextUtil.widgetLine2ModelLine(fTextViewer, line);
92
	}
93
94
	/*
95
	 * (non-Javadoc)
96
	 * 
97
	 * @see org.eclipse.swt.custom.StyledTextPrintMarginDecorator#getMarginTextStyle()
98
	 */
99
	public TextStyle getMarginTextStyle() {
100
		return null;
101
	}
102
103
}
(-)src/org/eclipse/jface/text/IPrintOptionsProvider.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jface.text;
12
13
import org.eclipse.swt.custom.StyledTextPrintOptions;
14
15
/**
16
 * A print options provider is used by <code>TextViewer.print()</code> to
17
 * retrieve the appropriate <code>StyledTextPrintOptions</code>demaps an
18
 * element of the viewer's model to for the active print job.
19
 * 
20
 * @since 3.2
21
 */
22
public interface IPrintOptionsProvider {
23
	/**
24
	 * Implementors must return an instance of
25
	 * <code>StyledTextPrintOptions</code> suitable for printing the current
26
	 * contents of this viewer's <code>StyledText</code> control.
27
	 * 
28
	 * @return the options
29
	 */
30
	public StyledTextPrintOptions getPrintOptions();
31
}
(-)projection/org/eclipse/jface/text/source/projection/ProjectionLineNumberMarginDecorator.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jface.text.source.projection;
12
13
import org.eclipse.jface.text.ITextViewer;
14
import org.eclipse.jface.text.source.SourceLineNumberMarginDecorator;
15
16
/**
17
 * An implementation of StyledTextPrintMarginDecorator that prints right aligned
18
 * line numbers. The line numbers are mapped to the document line numbers. If a
19
 * projection is collapsed a '+' annotation is printed.
20
 */
21
public class ProjectionLineNumberMarginDecorator extends
22
		SourceLineNumberMarginDecorator {
23
24
	/**
25
	 * Constructs a decorator with a gutter as specified.
26
	 * 
27
	 * @param viewer the viewer for line number conversion. If <code>null</code>
28
	 *            is passed, null is returned from {@link #getMarginText(int)}
29
	 */
30
	public ProjectionLineNumberMarginDecorator(ITextViewer viewer) {
31
		super(viewer, 0);
32
	}
33
34
	/*
35
	 * (non-Javadoc)
36
	 * 
37
	 * @see org.eclipse.swt.custom.StyledTextPrintMarginDecorator#getMarginText(int)
38
	 */
39
	public String getMarginText(int line) {
40
		String text = super.getMarginText(line);
41
		if (text != null) {
42
			int nextModelLine = getModelLineNumber(line + 1);
43
			if (((getModelLineNumber(line) + 1) == nextModelLine)
44
					|| (nextModelLine == -1))
45
				text = text + ' ';
46
			else
47
				text = text + '+';
48
		}
49
		return text;
50
	}
51
52
}

Return to bug 19602