* All Rights Reserved.
*/
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.jface.text.source.ISourceViewer;
-
+public class PrintMarginPainter implements IPainter, PaintListener {
+ private StyledText fTextWidget;
-public class PrintMarginPainter implements IPainter, PaintListener {
-
+ private int fMarginWidth = 80;
- private StyledText fTextWidget;
-
- private int fMarginWidth= 80;
private Color fColor;
- private int fLineStyle= SWT.LINE_SOLID;
- private int fLineWidth= 1;
-
- private int fCachedWidgetX= -1;
- private boolean fIsActive= false;
-
+
+ private int fLineStyle = SWT.LINE_SOLID;
+
+ private int fLineWidth = 1;
+
+ private int fCachedWidgetX = -1;
+
+ private boolean fIsActive = false;
+
public PrintMarginPainter(ISourceViewer sourceViewer) {
- fTextWidget= sourceViewer.getTextWidget();
+ fTextWidget = sourceViewer.getTextWidget();
}
-
+
public void setMarginRulerColumn(int width) {
- fMarginWidth= width;
+ fMarginWidth = width;
intialize();
}
-
+
public void setMarginRulerStyle(int lineStyle) {
- fLineStyle= lineStyle;
+ fLineStyle = lineStyle;
}
-
+
public void setMarginRulerWidth(int lineWidth) {
- fLineWidth= lineWidth;
+ fLineWidth = lineWidth;
}
-
+
/**
* Must be called before <code>paint</code> is called the first time.
*/
public void setMarginRulerColor(Color color) {
- fColor= color;
+ fColor = color;
}
-
+
/**
* Must be called explicitly when font of text widget changes.
*/
computeWidgetX();
fTextWidget.redraw();
}
-
+
private void computeWidgetX() {
- GC gc= new GC(fTextWidget);
- int pixels= gc.getFontMetrics().getAverageCharWidth();
+ GC gc = new GC(fTextWidget);
+ int pixels = gc.getFontMetrics().getAverageCharWidth();
gc.dispose();
-
- fCachedWidgetX= pixels * fMarginWidth;
+
+ fCachedWidgetX = pixels * fMarginWidth;
}
-
+
/*
* @see IPainter#deactivate(boolean)
*/
public void deactivate(boolean redraw) {
if (fIsActive) {
- fIsActive= false;
+ fIsActive = false;
fTextWidget.removePaintListener(this);
if (redraw)
fTextWidget.redraw();
- }
+ }
}
/*
* @see IPainter#dispose()
*/
public void dispose() {
- fTextWidget= null;
+ fTextWidget = null;
}
/*
*/
public void paint(int reason) {
if (!fIsActive) {
- fIsActive= true;
+ fIsActive = true;
fTextWidget.addPaintListener(this);
if (fCachedWidgetX == -1)
computeWidgetX();
*/
public void setPositionManager(IPositionManager manager) {
}
-
+
/*
* @see PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent e) {
if (fTextWidget != null) {
- int x= fCachedWidgetX - fTextWidget.getHorizontalPixel();
+ int x = fCachedWidgetX - fTextWidget.getHorizontalPixel();
if (x >= 0) {
- Rectangle area= fTextWidget.getClientArea();
+ Rectangle area = fTextWidget.getClientArea();
e.gc.setForeground(fColor);
e.gc.setLineStyle(fLineStyle);
e.gc.setLineWidth(fLineWidth);