1 package net.sourceforge.phpeclipse.phpeditor;
4 * (c) Copyright IBM Corp. 2000, 2001.
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.custom.StyledText;
10 import org.eclipse.swt.events.PaintEvent;
11 import org.eclipse.swt.events.PaintListener;
12 import org.eclipse.swt.graphics.Color;
13 import org.eclipse.swt.graphics.GC;
14 import org.eclipse.swt.graphics.Rectangle;
16 import org.eclipse.jface.text.source.ISourceViewer;
20 public class PrintMarginPainter implements IPainter, PaintListener {
23 private StyledText fTextWidget;
25 private int fMarginWidth= 80;
27 private int fLineStyle= SWT.LINE_SOLID;
28 private int fLineWidth= 1;
30 private int fCachedWidgetX= -1;
31 private boolean fIsActive= false;
33 public PrintMarginPainter(ISourceViewer sourceViewer) {
34 fTextWidget= sourceViewer.getTextWidget();
37 public void setMarginRulerColumn(int width) {
42 public void setMarginRulerStyle(int lineStyle) {
43 fLineStyle= lineStyle;
46 public void setMarginRulerWidth(int lineWidth) {
47 fLineWidth= lineWidth;
51 * Must be called before <code>paint</code> is called the first time.
53 public void setMarginRulerColor(Color color) {
58 * Must be called explicitly when font of text widget changes.
60 public void intialize() {
65 private void computeWidgetX() {
66 GC gc= new GC(fTextWidget);
67 int pixels= gc.getFontMetrics().getAverageCharWidth();
70 fCachedWidgetX= pixels * fMarginWidth;
74 * @see IPainter#deactivate(boolean)
76 public void deactivate(boolean redraw) {
79 fTextWidget.removePaintListener(this);
86 * @see IPainter#dispose()
88 public void dispose() {
93 * @see IPainter#paint(int)
95 public void paint(int reason) {
98 fTextWidget.addPaintListener(this);
99 if (fCachedWidgetX == -1)
101 fTextWidget.redraw();
106 * @see IPainter#setPositionManager(IPositionManager)
108 public void setPositionManager(IPositionManager manager) {
112 * @see PaintListener#paintControl(PaintEvent)
114 public void paintControl(PaintEvent e) {
115 if (fTextWidget != null) {
116 int x= fCachedWidgetX - fTextWidget.getHorizontalPixel();
118 Rectangle area= fTextWidget.getClientArea();
119 e.gc.setForeground(fColor);
120 e.gc.setLineStyle(fLineStyle);
121 e.gc.setLineWidth(fLineWidth);
122 e.gc.drawLine(x, 0, x, area.height);