use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.text by eclipse.
the class AnnotationRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
fHitDetectionCursor = parentControl.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fCanvas = createCanvas(parentControl);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseListener = new MouseListener() {
@Override
public void mouseUp(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseClicked(lineNumber);
}
@Override
public void mouseDown(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
AnnotationRulerColumn.this.mouseDown(lineNumber);
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseDoubleClicked(lineNumber);
}
};
fCanvas.addMouseListener(fMouseListener);
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
handleMouseMove(e);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fLineListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the line ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
postRedraw();
}
}
});
// track when StyledText is redrawn to check if some line height changed. In this case, the ruler must be redrawn
// to draw line number with well height.
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCanvas = new Canvas(parentControl, SWT.NO_FOCUS) {
@Override
public void addMouseListener(MouseListener listener) {
// see bug 40889, bug 230073 and AnnotationRulerColumn#isPropagatingMouseListener()
if (listener == fMouseHandler)
super.addMouseListener(listener);
else {
TypedListener typedListener = null;
if (listener != null)
typedListener = new TypedListener(listener);
addListener(SWT.MouseDoubleClick, typedListener);
}
}
};
fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
fCanvas.setForeground(fForeground);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseHandler = new MouseHandler();
fCanvas.addMouseListener(fMouseHandler);
fCanvas.addMouseMoveListener(fMouseHandler);
fCanvas.addMouseWheelListener(fMouseHandler);
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fInternalListener);
if (fFont == null) {
if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
fFont = fCachedTextWidget.getFont();
}
}
if (fFont != null)
fCanvas.setFont(fFont);
updateNumberOfDigits();
computeIndentations();
return fCanvas;
}
use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.text by eclipse.
the class AbstractRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
Assert.isLegal(parentControl != null);
Assert.isLegal(parentRuler != null);
// only call when not yet initialized!
Assert.isLegal(fParentRuler == null);
fParentRuler = parentRuler;
fTextViewer = getParentRuler().getTextViewer();
fTextViewer.addViewportListener(fInternalListener);
fTextViewer.addTextListener(fInternalListener);
fStyledText = fTextViewer.getTextWidget();
fCanvas = new Canvas(parentControl, getCanvasStyle());
fCanvas.setBackground(getDefaultBackground());
fCanvas.setFont(getFont());
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
AbstractRulerColumn.this.paintControl(event);
}
});
fCanvas.addMouseListener(fMouseHandler);
fCanvas.addMouseMoveListener(fMouseHandler);
return fCanvas;
}
use of org.eclipse.swt.events.PaintEvent in project dbeaver by dbeaver.
the class DBeaverSplashHandler method initVisualization.
private void initVisualization() {
String progressRectString = null, messageRectString = null, foregroundColorString = null, versionCoordString = null, versionInfoSizeString = null, versionInfoColorString = null;
final IProduct product = Platform.getProduct();
if (product != null) {
progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
versionCoordString = product.getProperty("versionInfoCoord");
versionInfoSizeString = product.getProperty("versionInfoSize");
versionInfoColorString = product.getProperty("versionInfoColor");
}
setProgressRect(StringConverter.asRectangle(progressRectString, new Rectangle(275, 300, 280, 10)));
setMessageRect(StringConverter.asRectangle(messageRectString, new Rectangle(275, 275, 280, 25)));
final Point versionCoord = StringConverter.asPoint(versionCoordString, new Point(485, 215));
final int versionInfoSize = StringConverter.asInt(versionInfoSizeString, 22);
final RGB versionInfoRGB = StringConverter.asRGB(versionInfoColorString, new RGB(255, 255, 255));
int foregroundColorInteger = 0xD2D7FF;
try {
if (foregroundColorString != null) {
foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
}
} catch (Exception ex) {
// ignore
}
setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
normalFont = getContent().getFont();
// boldFont = UIUtils.makeBoldFont(normalFont);
FontData[] fontData = normalFont.getFontData();
fontData[0].setStyle(fontData[0].getStyle() | SWT.BOLD);
fontData[0].setHeight(versionInfoSize);
boldFont = new Font(normalFont.getDevice(), fontData[0]);
final Color versionColor = new Color(getContent().getDisplay(), versionInfoRGB);
getContent().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
String productVersion = "";
if (product != null) {
productVersion = GeneralUtils.getProductVersion().toString();
}
// String osVersion = Platform.getOS() + " " + Platform.getOSArch();
if (boldFont != null) {
e.gc.setFont(boldFont);
}
e.gc.setForeground(versionColor);
e.gc.drawText(productVersion, versionCoord.x, versionCoord.y, true);
// e.gc.drawText(osVersion, 115, 200, true);
e.gc.setFont(normalFont);
}
});
}
use of org.eclipse.swt.events.PaintEvent in project erlide_eclipse by erlang.
the class SplashHandler method init.
@Override
public void init(final Shell splash) {
super.init(splash);
String progressRectString = null;
String messageRectString = null;
String foregroundColorString = null;
final IProduct product = Platform.getProduct();
if (product != null) {
progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
}
final Rectangle progressRect = StringConverter.asRectangle(progressRectString, new Rectangle(10, 10, 300, 15));
setProgressRect(progressRect);
final Rectangle messageRect = StringConverter.asRectangle(messageRectString, new Rectangle(10, 35, 300, 15));
setMessageRect(messageRect);
int foregroundColorInteger;
try {
foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
} catch (final Exception ex) {
// off white
foregroundColorInteger = 0xD2D7FF;
}
setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
final String buildId = ErlangPlugin.getDefault().getCore().getFeatureVersion();
final Point buildIdPoint;
// hardcoded to be sensible with our current splash Graphic
if (product != null) {
// $NON-NLS-1$
final String buildIdLocString = product.getProperty("buildIdLocation");
buildIdPoint = StringConverter.asPoint(buildIdLocString, new Point(30, splash.getSize().y - 60));
} else {
buildIdPoint = new Point(30, splash.getSize().y - 60);
}
getContent().addPaintListener(new PaintListener() {
@Override
public void paintControl(final PaintEvent e) {
e.gc.setForeground(getForeground());
e.gc.drawText(buildId, buildIdPoint.x, buildIdPoint.y, true);
}
});
}
Aggregations