Search in sources :

Example 71 with PaintListener

use of org.eclipse.swt.events.PaintListener in project webtools.sourceediting by eclipse.

the class CommonMultiPageEditor method createViewModeToolbar.

protected void createViewModeToolbar(Composite parent) {
    EditorModeManager manager = (EditorModeManager) getAdapter(EditorModeManager.class);
    final ProductCustomizationProvider productCustomizationProvider = (ProductCustomizationProvider) getAdapter(ProductCustomizationProvider.class);
    EditorMode[] modeList = manager.getModes();
    int modeListLength = modeList.length;
    boolean showToolBar = modeListLength > 1;
    if (showToolBar) {
        toolbar = new Composite(parent, SWT.FLAT | SWT.DRAW_TRANSPARENT);
        toolbar.setBackground(ColorConstants.listBackground);
        toolbar.addPaintListener(new PaintListener() {

            public void paintControl(PaintEvent e) {
                Rectangle clientArea = toolbar.getClientArea();
                e.gc.setForeground(ColorConstants.lightGray);
                e.gc.drawRectangle(clientArea.x, clientArea.y, clientArea.width - 1, clientArea.height - 1);
            }
        });
        GridLayout gridLayout = new GridLayout(3, false);
        toolbar.setLayout(gridLayout);
        Label label = new Label(toolbar, SWT.FLAT | SWT.HORIZONTAL);
        label.setBackground(ColorConstants.listBackground);
        label.setText(Messages._UI_LABEL_VIEW);
        label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
        modeCombo = new FlatCCombo(toolbar, SWT.FLAT);
        modeCombo.setEditable(false);
        modeCombo.setText(getEditModeName(manager.getCurrentMode(), productCustomizationProvider));
        GC gc = new GC(modeCombo);
        int textWidth = 0;
        maxLength = 0;
        // populate combo with modes
        editorModeAndCustomizedNames = new EditorModeAndCustomizedName[modeListLength];
        for (int i = 0; i < modeListLength; i++) {
            EditorModeAndCustomizedName entry = new EditorModeAndCustomizedName();
            editorModeAndCustomizedNames[i] = entry;
            entry.name = getEditModeName(modeList[i], productCustomizationProvider);
            entry.mode = modeList[i];
        }
        Arrays.sort(editorModeAndCustomizedNames, new Comparator() {

            public int compare(Object arg0, Object arg1) {
                EditorModeAndCustomizedName a = (EditorModeAndCustomizedName) arg0;
                EditorModeAndCustomizedName b = (EditorModeAndCustomizedName) arg1;
                return Collator.getInstance().compare(a.name, b.name);
            }
        });
        for (int i = 0; i < editorModeAndCustomizedNames.length; i++) {
            EditorModeAndCustomizedName entry = editorModeAndCustomizedNames[i];
            modeCombo.add(entry.name);
            maxLength = Math.max(gc.stringExtent(entry.name).x, maxLength);
            int approxWidthOfStrings = Math.max(gc.stringExtent(entry.name).x, textWidth);
            if (approxWidthOfStrings > maxLength)
                maxLength = approxWidthOfStrings;
        }
        maxLength += gc.stringExtent(Messages._UI_LABEL_VIEW).x;
        gc.dispose();
        modeComboListener = new ModeComboListener();
        modeCombo.addSelectionListener(modeComboListener);
        modeCombo.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
        modeCombo.setBackground(toolbar.getBackground());
        ImageHyperlink hyperlink = new ImageHyperlink(toolbar, SWT.FLAT);
        hyperlink.setBackground(ColorConstants.white);
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=154457
        Image image = XSDEditorPlugin.getDefault().getIconImage("etool16/help_contents");
        hyperlink.setImage(image);
        hyperlink.setToolTipText(Messages._UI_HOVER_VIEW_MODE_DESCRIPTION);
        hyperlink.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
        hyperlink.addMouseListener(new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
                if (productCustomizationProvider != null) {
                    productCustomizationProvider.handleAction("showEditorModeHelp");
                }
            }
        });
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.draw2d.geometry.Point) Comparator(java.util.Comparator) GridLayout(org.eclipse.swt.layout.GridLayout) FlatCCombo(org.eclipse.wst.xsd.ui.internal.adt.design.FlatCCombo) GridData(org.eclipse.swt.layout.GridData) EventObject(java.util.EventObject) GC(org.eclipse.swt.graphics.GC)

Example 72 with PaintListener

use of org.eclipse.swt.events.PaintListener in project eclipse-integration-commons by spring-projects.

the class WizardPageWithSections method createControl.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
public void createControl(Composite parent) {
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
    scroller = new SharedScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL) {
    };
    // scroller.setWidthHint(500); // Avoid excessively wide dialogs
    // Display display = Display.getCurrent();
    // Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    // scroller.setBackground(blue);
    scroller.setExpandHorizontal(true);
    scroller.setExpandVertical(true);
    page = new Composite(scroller, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 12;
    layout.marginWidth = 12;
    page.setLayout(layout);
    validator = new CompositeValidator();
    for (PageSection section : getSections()) {
        section.createContents(page);
        validator.addChild(section.getValidator());
    }
    validator.addListener(this);
    Dialog.applyDialogFont(page);
    page.pack(true);
    // scroller.setMinSize(page.getSize());
    // scroller.setSize(page.getSize());
    scroller.setContent(page);
    setControl(scroller);
    page.addPaintListener(new PaintListener() {

        // This is a bit yuck. But don't know a better way to 'reflow' the page the first time
        // it gets shown. And if we don't do that, then there are often layout issues.
        // See for example: https://www.pivotaltracker.com/story/show/130209913
        @Override
        public void paintControl(PaintEvent e) {
            page.removePaintListener(this);
            reflow();
        }
    });
    if (getContainer().getCurrentPage() != null) {
        // Otherwise an NPE will ensue when updating buttons. Buttons depend on current page so that is logical.
        getContainer().updateButtons();
        getContainer().updateMessage();
    }
}
Also used : SharedScrolledComposite(org.eclipse.ui.forms.widgets.SharedScrolledComposite) GridLayout(org.eclipse.swt.layout.GridLayout) CompositeValidator(org.springsource.ide.eclipse.commons.livexp.core.CompositeValidator) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) SharedScrolledComposite(org.eclipse.ui.forms.widgets.SharedScrolledComposite) PaintListener(org.eclipse.swt.events.PaintListener)

Example 73 with PaintListener

use of org.eclipse.swt.events.PaintListener in project netxms by netxms.

the class SplashHandler method init.

/* (non-Javadoc)
	 * @see org.eclipse.ui.splash.AbstractSplashHandler#init(org.eclipse.swt.widgets.Shell)
	 */
public void init(Shell splash) {
    super.init(splash);
    instance = this;
    String progressRectString = null;
    String messageRectString = null;
    String foregroundColorString = null;
    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);
    }
    if (progressRectString != null) {
        Rectangle progressRect = StringConverter.asRectangle(progressRectString, new Rectangle(10, 10, 300, 15));
        setProgressRect(progressRect);
    }
    if (messageRectString != null) {
        Rectangle messageRect = StringConverter.asRectangle(messageRectString, new Rectangle(10, 35, 300, 15));
        setMessageRect(messageRect);
    }
    int foregroundColorInteger;
    try {
        foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
    } catch (Exception ex) {
        // off white
        foregroundColorInteger = 0xD2D7FF;
    }
    setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
    final Color versionColor = new Color(Display.getCurrent(), 224, 224, 224);
    // $NON-NLS-1$
    final Font versionFont = new Font(Display.getCurrent(), "Verdana", 9, SWT.NONE);
    // $NON-NLS-1$ //$NON-NLS-2$
    final String versionText = Messages.get().SplashHandler_Version + NXCommon.VERSION + " (" + BuildNumber.TEXT + ")";
    // $NON-NLS-1$
    final String copyrightText = "\u00A9 2003-2018 Raden Solutions";
    final Composite content = getContent();
    content.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(versionColor);
            e.gc.setFont(versionFont);
            int y = 240;
            Point size = e.gc.textExtent(copyrightText);
            e.gc.drawText(copyrightText, 485 - size.x, y, true);
            y += size.y + 2;
            size = e.gc.textExtent(versionText);
            e.gc.drawText(versionText, 485 - size.x, y, true);
        }
    });
    content.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            versionColor.dispose();
            versionFont.dispose();
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) IProduct(org.eclipse.core.runtime.IProduct)

Example 74 with PaintListener

use of org.eclipse.swt.events.PaintListener in project netxms by netxms.

the class ScreenshotView method createPartControl.

/*
    * (non-Javadoc)
    * 
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new FillLayout());
    scroller = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    canvas = new Canvas(scroller, SWT.NONE);
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            GC gc = e.gc;
            if (image != null) {
                gc.drawImage(image, 0, 0);
                gc.drawText(imageInfo, 10, image.getImageData().height + 10);
            } else if (errorMessage != null) {
                gc.setForeground(canvas.getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
                gc.setFont(JFaceResources.getBannerFont());
                gc.drawText(errorMessage, 10, 10, true);
            }
        }
    });
    scroller.setContent(canvas);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);
    scroller.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            updateScrollerSize();
        }
    });
    activateContext();
    createActions();
    contributeToActionBars();
    refresh();
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FillLayout(org.eclipse.swt.layout.FillLayout) GC(org.eclipse.swt.graphics.GC) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 75 with PaintListener

use of org.eclipse.swt.events.PaintListener in project netxms by netxms.

the class AvailabilityChart method createClientArea.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.widgets.DashboardElement#createClientArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createClientArea(Composite parent) {
    Composite clientArea = new Composite(parent, SWT.NONE);
    colors = new ColorCache(clientArea);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    clientArea.setLayout(layout);
    dayChart = createChart(clientArea, Messages.get().AvailabilityChart_Today);
    weekChart = createChart(clientArea, Messages.get().AvailabilityChart_ThisWeek);
    monthChart = createChart(clientArea, Messages.get().AvailabilityChart_ThisMonth);
    Canvas legend = new Canvas(clientArea, SWT.NONE);
    legend.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            paintLegend(e.gc);
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    legend.setLayoutData(gd);
    return clientArea;
}
Also used : ColorCache(org.netxms.ui.eclipse.tools.ColorCache) GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData)

Aggregations

PaintListener (org.eclipse.swt.events.PaintListener)89 PaintEvent (org.eclipse.swt.events.PaintEvent)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)29 MouseEvent (org.eclipse.swt.events.MouseEvent)26 GridData (org.eclipse.swt.layout.GridData)26 Rectangle (org.eclipse.swt.graphics.Rectangle)25 Point (org.eclipse.swt.graphics.Point)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 DisposeEvent (org.eclipse.swt.events.DisposeEvent)14 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 Control (org.eclipse.swt.widgets.Control)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Event (org.eclipse.swt.widgets.Event)11 GC (org.eclipse.swt.graphics.GC)10 Button (org.eclipse.swt.widgets.Button)10