Search in sources :

Example 66 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.swt by eclipse.

the class Bug421127_Clipping_is_wrong method showCaseClipping.

private static Composite[] showCaseClipping(Composite main) {
    Composite composite = new Composite(main, SWT.NONE);
    composite.setLayout(new FillLayout());
    Composite left = new Composite(composite, SWT.NONE);
    left.setLayout(new FillLayout(SWT.VERTICAL));
    Composite upperLeft = new Composite(left, SWT.BORDER);
    Composite bottomLeft = new Composite(left, SWT.BORDER);
    Composite right = new Composite(composite, SWT.NONE);
    right.setLayout(new FillLayout(SWT.VERTICAL));
    Composite upperRight = new Composite(right, SWT.BORDER);
    Composite bottomRight = new Composite(right, SWT.BORDER);
    Composite[] squares = { upperLeft, bottomLeft, upperRight, bottomRight };
    for (Composite square : squares) {
        square.setLayout(new FillLayout(SWT.VERTICAL));
        final Canvas canvas = new Canvas(square, SWT.BORDER);
        final Canvas text = new Canvas(square, SWT.BORDER);
        class PaintCanvas implements PaintListener {

            @Override
            public void paintControl(PaintEvent event) {
                paintCanvas(event, canvas);
            }
        }
        class PrintClipping implements PaintListener {

            @Override
            public void paintControl(PaintEvent event) {
                clippingText(event, text);
            }
        }
        canvas.addPaintListener(new PaintCanvas());
        text.addPaintListener(new PrintClipping());
    }
    return squares;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 67 with PaintEvent

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

the class DashboardMainPage method displayUpdate.

private void displayUpdate(final SyndEntry entry, String severity, Composite composite, int pos, Control[] children) {
    ImageHyperlink link;
    FormText text;
    if (pos < children.length / 2) {
        link = (ImageHyperlink) children[pos * 2];
        link.setVisible(true);
        text = (FormText) children[pos * 2 + 1];
        text.setVisible(true);
    } else {
        link = toolkit.createImageHyperlink(composite, SWT.NONE);
        text = new FormText(composite, SWT.WRAP | SWT.MULTI | SWT.NO_BACKGROUND | SWT.NO_FOCUS);
        text.setHyperlinkSettings(toolkit.getHyperlinkGroup());
        final TableWrapData data = new TableWrapData();
        data.indent = UPDATE_INDENTATION;
        data.maxWidth = updateSection.getSize().x - UPDATE_TEXT_WRAP_INDENT;
        text.setLayoutData(data);
        text.addPaintListener(new PaintListener() {

            public void paintControl(PaintEvent e) {
                data.maxWidth = updateSection.getSize().x - UPDATE_TEXT_WRAP_INDENT;
            }
        });
        text.setBackground(toolkit.getColors().getBackground());
        text.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                if (e.data instanceof String) {
                    TasksUiUtil.openUrl((String) e.data);
                }
            }
        });
    }
    link.setText(entry.getTitle());
    TableWrapData linkData = new TableWrapData();
    if ("important".equals(severity)) {
        link.setImage(StsUiImages.getImage(StsUiImages.IMPORTANT));
        linkData.indent = 0;
    } else if ("warning".equals(severity)) {
        link.setImage(StsUiImages.getImage(StsUiImages.WARNING));
        linkData.indent = 0;
    } else {
        // link.setImage(IdeUiPlugin.getImage(ICON_BLOG_BLANK));
        linkData.indent = UPDATE_INDENTATION - 1;
    }
    link.setLayoutData(linkData);
    link.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            String url = entry.getLink();
            if (url == null) {
                return;
            }
            TasksUiUtil.openUrl(url);
        }
    });
    String description = getDescription(entry);
    if (entry.getPublishedDate() != null && description.endsWith("</p></form>")) {
        String dateString = DateFormat.getDateInstance(DateFormat.MEDIUM).format(entry.getPublishedDate());
        description = description.replace("</p></form>", " (" + dateString + ")</p></form>");
    } else if (entry.getPublishedDate() != null) {
        String dateString = DateFormat.getDateInstance(DateFormat.MEDIUM).format(entry.getPublishedDate());
        description = description + " (" + dateString + ")";
    }
    text.setText(description, description.startsWith("<form>"), true);
    text.setForeground(feedColor);
    text.setBackground(toolkit.getColors().getBackground());
    addImages(text, description);
}
Also used : TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) PaintEvent(org.eclipse.swt.events.PaintEvent) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) PaintListener(org.eclipse.swt.events.PaintListener) FormText(org.eclipse.ui.forms.widgets.FormText) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 68 with PaintEvent

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

the class DashboardMainPage method displayFeed.

private void displayFeed(SyndEntry entry, Composite composite, final Section section, final int pos, Control[] children) {
    ImageHyperlink link;
    FormText text;
    if (pos < children.length / 2) {
        link = (ImageHyperlink) children[pos * 2];
        link.setVisible(true);
        text = (FormText) children[pos * 2 + 1];
        text.setVisible(true);
    } else {
        final ImageHyperlink newLink = toolkit.createImageHyperlink(composite, SWT.NONE);
        feedControls.add(newLink);
        link = newLink;
        link.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                Object source = e.getSource();
                if (source instanceof ImageHyperlink && ((ImageHyperlink) source).getData() != null) {
                    SyndEntry entry = (SyndEntry) ((ImageHyperlink) source).getData();
                    String url = entry.getLink();
                    if (url == null) {
                        return;
                    }
                    int urlPos = url.indexOf("?");
                    String newUrl = url;
                    if (urlPos > 0) {
                        newUrl = url.substring(0, urlPos + 1) + url.substring(urlPos + 1).replaceAll("\\?", "&");
                    }
                    TasksUiUtil.openUrl(url);
                    prefStore.setValue(IIdeUiConstants.PREF_FEED_ENTRY_READ_STATE + ":" + newUrl, true);
                    IdeUiPlugin.getDefault().savePluginPreferences();
                    newLink.setImage(IdeUiPlugin.getImage(ICON_BLOG_BLANK));
                }
            }
        });
        // text = new Text(composite, SWT.WRAP | SWT.MULTI |
        // SWT.NO_BACKGROUND);
        text = new FormText(composite, SWT.WRAP | SWT.MULTI | SWT.NO_BACKGROUND | SWT.NO_FOCUS);
        text.setHyperlinkSettings(toolkit.getHyperlinkGroup());
        feedControls.add(text);
        final TableWrapData data = new TableWrapData();
        data.indent = UPDATE_INDENTATION;
        data.maxWidth = section.getSize().x - FEEDS_TEXT_WRAP_INDENT;
        data.grabVertical = true;
        text.setLayoutData(data);
        text.addPaintListener(new PaintListener() {

            public void paintControl(PaintEvent e) {
                data.maxWidth = section.getSize().x - FEEDS_TEXT_WRAP_INDENT;
            }
        });
        text.setForeground(feedColor);
        text.setBackground(toolkit.getColors().getBackground());
    }
    String title = entry.getTitle();
    Date entryDate = new Date(0);
    if (entry.getUpdatedDate() != null) {
        entryDate = entry.getUpdatedDate();
    } else {
        entryDate = entry.getPublishedDate();
    }
    String dateString = "";
    if (entryDate != null) {
        dateString = DateFormat.getDateInstance(DateFormat.MEDIUM).format(entryDate);
    }
    String entryAuthor = "";
    if (entry.getAuthor() != null && entry.getAuthor().trim() != "") {
        entryAuthor = " by " + entry.getAuthor();
    }
    if (dateString.length() > 0 && entryAuthor.length() > 0) {
        link.setText(removeHtmlEntities(title));
    }
    TableWrapData linkData = new TableWrapData();
    if (!prefStore.getBoolean(IIdeUiConstants.PREF_FEED_ENTRY_READ_STATE + ":" + entry.getLink())) {
        link.setImage(IdeUiPlugin.getImage(ICON_BLOG_INCOMING));
        linkData.indent = 0;
    } else {
        // link.setImage(IdeUiPlugin.getImage(ICON_BLOG_BLANK));
        linkData.indent = UPDATE_INDENTATION - 1;
    }
    link.setLayoutData(linkData);
    link.setData(entry);
    String description = trimText(getDescription(entry));
    text.setText(description + " (" + dateString + entryAuthor + ")", false, false);
}
Also used : TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) PaintListener(org.eclipse.swt.events.PaintListener) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) FormText(org.eclipse.ui.forms.widgets.FormText) Date(java.util.Date) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 69 with PaintEvent

use of org.eclipse.swt.events.PaintEvent 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 70 with PaintEvent

use of org.eclipse.swt.events.PaintEvent 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)

Aggregations

PaintEvent (org.eclipse.swt.events.PaintEvent)96 PaintListener (org.eclipse.swt.events.PaintListener)92 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 MouseEvent (org.eclipse.swt.events.MouseEvent)27 GridData (org.eclipse.swt.layout.GridData)26 Point (org.eclipse.swt.graphics.Point)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 DisposeEvent (org.eclipse.swt.events.DisposeEvent)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DisposeListener (org.eclipse.swt.events.DisposeListener)15 FillLayout (org.eclipse.swt.layout.FillLayout)15 Event (org.eclipse.swt.widgets.Event)15 MouseAdapter (org.eclipse.swt.events.MouseAdapter)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 ControlEvent (org.eclipse.swt.events.ControlEvent)12 Control (org.eclipse.swt.widgets.Control)12 GC (org.eclipse.swt.graphics.GC)11 Listener (org.eclipse.swt.widgets.Listener)11