use of org.eclipse.swt.events.PaintListener in project eclipse.platform.text by eclipse.
the class OverviewRuler method createControl.
@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
fTextViewer = textViewer;
fHitDetectionCursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fHeader = new Canvas(parent, SWT.NONE);
if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
fHeader.addMouseTrackListener(new MouseTrackAdapter() {
/*
* @see org.eclipse.swt.events.MouseTrackAdapter#mouseHover(org.eclipse.swt.events.MouseEvent)
* @since 3.3
*/
@Override
public void mouseEnter(MouseEvent e) {
updateHeaderToolTipText();
}
});
}
fCanvas = new Canvas(parent, SWT.NO_BACKGROUND);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent event) {
handleDispose();
fTextViewer = null;
}
});
fCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
handleMouseDown(event);
}
});
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent event) {
handleMouseMove(event);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fTextViewer != null) {
fTextViewer.addTextListener(fInternalListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fTextViewer.getTextWidget().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fTextViewer == null) {
return;
}
StyledText textWidget = fTextViewer.getTextWidget();
if (textWidget != null && textWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
use of org.eclipse.swt.events.PaintListener 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.PaintListener 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.PaintListener 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.PaintListener 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);
}
});
}
Aggregations