1 package net.sourceforge.phpeclipse.phpeditor;
4 * (c) Copyright IBM Corp. 2000, 2001.
8 import org.eclipse.jface.text.source.ISourceViewer;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.custom.StyledText;
11 import org.eclipse.swt.events.PaintEvent;
12 import org.eclipse.swt.events.PaintListener;
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.graphics.GC;
15 import org.eclipse.swt.graphics.Rectangle;
19 public class PrintMarginPainter implements IPainter, PaintListener {
22 private StyledText fTextWidget;
24 private int fMarginWidth= 80;
26 private int fLineStyle= SWT.LINE_SOLID;
27 private int fLineWidth= 1;
29 private int fCachedWidgetX= -1;
30 private boolean fIsActive= false;
32 public PrintMarginPainter(ISourceViewer sourceViewer) {
33 fTextWidget= sourceViewer.getTextWidget();
36 public void setMarginRulerColumn(int width) {
41 public void setMarginRulerStyle(int lineStyle) {
42 fLineStyle= lineStyle;
45 public void setMarginRulerWidth(int lineWidth) {
46 fLineWidth= lineWidth;
50 * Must be called before <code>paint</code> is called the first time.
52 public void setMarginRulerColor(Color color) {
57 * Must be called explicitly when font of text widget changes.
59 public void intialize() {
64 private void computeWidgetX() {
65 GC gc= new GC(fTextWidget);
66 int pixels= gc.getFontMetrics().getAverageCharWidth();
69 fCachedWidgetX= pixels * fMarginWidth;
73 * @see IPainter#deactivate(boolean)
75 public void deactivate(boolean redraw) {
78 fTextWidget.removePaintListener(this);
85 * @see IPainter#dispose()
87 public void dispose() {
92 * @see IPainter#paint(int)
94 public void paint(int reason) {
97 fTextWidget.addPaintListener(this);
98 if (fCachedWidgetX == -1)
100 fTextWidget.redraw();
105 * @see IPainter#setPositionManager(IPositionManager)
107 public void setPositionManager(IPositionManager manager) {
111 * @see PaintListener#paintControl(PaintEvent)
113 public void paintControl(PaintEvent e) {
114 if (fTextWidget != null) {
115 int x= fCachedWidgetX - fTextWidget.getHorizontalPixel();
117 Rectangle area= fTextWidget.getClientArea();
118 e.gc.setForeground(fColor);
119 e.gc.setLineStyle(fLineStyle);
120 e.gc.setLineWidth(fLineWidth);
121 e.gc.drawLine(x, 0, x, area.height);