org.eclipse.swt.custom.PaintObjectListener Java Examples

The following examples show how to use org.eclipse.swt.custom.PaintObjectListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HoverInfoWithText.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void deferredCreateContent(Composite parent,
        HoverInformationControl miControl) {
    this.fParent = parent;
    this.fMIControl = miControl;

    fText = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY
            | fMIControl.getAdditionalTextStyles());
    fText.setForeground(parent.getForeground());
    fText.setBackground(parent.getBackground());
    fText.setFont(JFaceResources.getDialogFont());
    fText.addPaintObjectListener(new PaintObjectListener() {
        public void paintObject(PaintObjectEvent event) {
            StyleRange style = event.style;
            Image image = (Image) style.data;
            if (image != null && !image.isDisposed()) {
                int x = event.x + 2;
                int y = event.y + event.ascent / 2 - style.metrics.ascent
                        / 2 + 2;
                event.gc.drawImage(image, x, y);
            }
        }
    });
    FillLayout layout = new FillLayout();
    layout.marginHeight = 2;
    layout.marginWidth = 2;
    parent.setLayout(layout);

    if (monospace) {
        fText.setFont(JFaceResources.getTextFont());
    } else {
        fText.setFont(JFaceResources.getDialogFont());
    }

    fText.setText(xsString.getText());
    fText.setStyleRanges(xsString.getStyleRanges().toArray(new StyleRange[0]));

    parent.layout(true);
}