Search in sources :

Example 81 with PaintListener

use of org.eclipse.swt.events.PaintListener in project hale by halestudio.

the class HaleSplash method init.

@Override
public void init(Shell splash) {
    IProduct product = Platform.getProduct();
    if (product != null) {
        /*
			 * Using a custom property for the foreground color, because when
			 * using the one defined in IProductConstants, it is overriden when
			 * recreating a run configuration from the product.
			 */
        String foregroundColorString = product.getProperty(PRODUCT_PROP_SPLASH_FONT_COLOR);
        int foregroundColorInteger;
        try {
            foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
        } catch (Exception ex) {
            // off white
            foregroundColorInteger = 0xD2D7FF;
        }
        /*
			 * Foreground color will be overriden in super.init(...), that's why
			 * we have to set it in getContent() - store it here for later
			 * access.
			 */
        customFontColor = new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF);
    }
    super.init(splash);
    if (product != null) {
        // get application version
        Version haleVersion = Version.parseVersion(Display.getAppVersion());
        // classified as development version if a qualifier other than
        // RELEASE is given
        boolean developmentVersion = haleVersion.getQualifier() != null && !haleVersion.getQualifier().isEmpty() && !haleVersion.getQualifier().equalsIgnoreCase("RELEASE");
        if (!developmentVersion) {
            // strip qualifier for RELEASE
            haleVersion = new Version(haleVersion.getMajor(), haleVersion.getMinor(), haleVersion.getMicro());
        }
        StringBuilder versionStringBuilder = new StringBuilder();
        versionStringBuilder.append(haleVersion.toString());
        if (developmentVersion) {
            // add revision information
            String revisionString = product.getProperty(PRODUCT_PROP_REVISION);
            if (revisionString != null && !revisionString.isEmpty()) {
                versionStringBuilder.insert(0, '\n');
                versionStringBuilder.insert(0, revisionString);
                versionStringBuilder.insert(0, "Revision ");
            }
        }
        // add version tag
        String versionTagString = product.getProperty(PRODUCT_PROP_VERSION_TAG);
        if (versionTagString != null && !versionTagString.isEmpty()) {
            versionStringBuilder.append('-');
            versionStringBuilder.append(versionTagString);
        }
        // add copyright notice
        String copyrightString = product.getProperty(PRODUCT_PROP_COPYRIGHT);
        if (copyrightString != null && !copyrightString.isEmpty()) {
            versionStringBuilder.append(' ');
            versionStringBuilder.append(copyrightString);
        }
        final String versionString = versionStringBuilder.toString();
        getContent().addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                // computed version string location
                Point extent = e.gc.textExtent(versionString);
                if (versionStringFont == null) {
                    // find fitting font
                    Font customFont = null;
                    while (extent.x >= e.width || extent.y > MAX_HEIGHT) {
                        FontData[] orgFont = e.gc.getFont().getFontData();
                        // minimum font size
                        if (orgFont[0].getHeight() <= MIN_SIZE) {
                            break;
                        }
                        FontData fd = new FontData(orgFont[0].toString());
                        fd.setHeight(orgFont[0].getHeight() - 1);
                        if (customFont != null) {
                            // dispose previous custom font
                            customFont.dispose();
                        }
                        customFont = new Font(e.display, fd);
                        e.gc.setFont(customFont);
                        extent = e.gc.textExtent(versionString);
                    }
                    if (customFont != null) {
                        versionStringFont = customFont;
                    }
                }
                e.gc.setForeground(getForeground());
                e.gc.drawText(versionString, (e.width - extent.x) / 2, e.height - extent.y - BOTTOM_MARGIN, true);
            }
        });
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) FontData(org.eclipse.swt.graphics.FontData) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Version(org.osgi.framework.Version) IProduct(org.eclipse.core.runtime.IProduct)

Example 82 with PaintListener

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

the class ScribbleView method createPartControl.

public void createPartControl(Composite parent) {
    Composite backgroundComposite = new Composite(parent, SWT.NONE);
    GridLayout backgroundGridLayout = new GridLayout(3, false);
    backgroundGridLayout.marginHeight = 0;
    backgroundGridLayout.marginBottom = 0;
    backgroundGridLayout.marginLeft = 0;
    backgroundGridLayout.marginRight = 0;
    backgroundGridLayout.marginWidth = 0;
    backgroundGridLayout.horizontalSpacing = 0;
    backgroundComposite.setLayout(backgroundGridLayout);
    backgroundComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite paletteComposite = new Composite(backgroundComposite, SWT.NONE);
    backgroundGridLayout = new GridLayout();
    backgroundGridLayout.marginHeight = 0;
    backgroundGridLayout.marginBottom = 0;
    backgroundGridLayout.marginLeft = 0;
    backgroundGridLayout.marginRight = 0;
    backgroundGridLayout.marginWidth = 0;
    backgroundGridLayout.horizontalSpacing = 0;
    paletteComposite.setLayout(backgroundGridLayout);
    GridData toolboxGridData = new GridData(GridData.FILL_VERTICAL);
    toolboxGridData.widthHint = 60;
    paletteComposite.setLayoutData(toolboxGridData);
    final TableViewer toolbox = new TableViewer(paletteComposite, SWT.FLAT | SWT.FULL_SELECTION);
    toolboxGridData = new GridData(GridData.FILL_BOTH);
    toolbox.getTable().setLayoutData(toolboxGridData);
    toolbox.setLabelProvider(new ToolboxLabelProvider());
    toolbox.setContentProvider(new ListContentProvider());
    toolbox.setInput(createTools());
    toolbox.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            currentTool = (AbstractTool) ((StructuredSelection) toolbox.getSelection()).getFirstElement();
            // Apply the drawSettings to the currently selected tool.
            currentTool.setDrawSettings(drawSettings);
        }
    });
    // Create the UI widgets to modify the DrawSettings instance.
    createSettings(paletteComposite);
    Label separator = new Label(backgroundComposite, SWT.SEPARATOR | SWT.VERTICAL);
    separator.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    canvas = new Canvas(backgroundComposite, SWT.NONE);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    display = parent.getDisplay();
    canvas.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            for (Iterator i = tools.iterator(); i.hasNext(); ) {
                AbstractTool at = (AbstractTool) i.next();
                at.draw(canvas);
            }
        }
    });
    Listener listener = new Listener() {

        public void handleEvent(Event event) {
            if (currentTool != null) {
                // Have the tool interpret the mouse events.
                currentTool.handleUIEvent(event, canvas);
                // other clients for rendering.
                if (currentTool.isComplete()) {
                    tools.add(currentTool);
                    sendTool(currentTool);
                    // Only do this once per Tool.
                    currentTool.setComplete(false);
                }
            /*else {
						if (currentTool instanceof Pencil) {
							tools.add(currentTool);
						}
					}*/
            }
        }
    };
    canvas.addListener(SWT.MouseDown, listener);
    canvas.addListener(SWT.MouseMove, listener);
    canvas.addListener(SWT.MouseUp, listener);
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PaintListener(org.eclipse.swt.events.PaintListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.eclipse.ecf.tutorial.scribbleshare.toolbox.ListContentProvider) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolboxLabelProvider(org.eclipse.ecf.tutorial.scribbleshare.toolbox.ToolboxLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractTool(org.eclipse.ecf.tutorial.scribbleshare.toolbox.AbstractTool)

Example 83 with PaintListener

use of org.eclipse.swt.events.PaintListener in project statecharts by Yakindu.

the class DiagramPartitioningBreadcrumbViewer method createDropDownTreeViewer.

protected TreeViewer createDropDownTreeViewer(final Composite composite, TreePath paramPath, final IBreadcrumbDropDownSite site) {
    Diagram diagram = (Diagram) paramPath.getParentPath().getLastSegment();
    TreeViewer viewer = null;
    if (diagram != null)
        viewer = createDiagramViewer(composite, diagram);
    else
        viewer = createProjectStatechartViewer(composite, (Diagram) paramPath.getLastSegment());
    viewer.getControl().addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            getDropDownShell().pack(true);
        }
    });
    return viewer;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 84 with PaintListener

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

the class ScreenCaptureConfirmationDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(width, height));
    composite.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            e.gc.drawImage(image, 0, 0);
        }
    });
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) GridData(org.eclipse.swt.layout.GridData)

Example 85 with PaintListener

use of org.eclipse.swt.events.PaintListener in project pentaho-kettle by pentaho.

the class StarModelDialog method addModelTab.

private void addModelTab() {
    wModelTab = new CTabItem(wTabFolder, SWT.NONE);
    wModelTab.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelTab.Label"));
    Composite wModelComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wModelComp);
    FormLayout transLayout = new FormLayout();
    transLayout.marginWidth = Const.MARGIN;
    transLayout.marginHeight = Const.MARGIN;
    wModelComp.setLayout(transLayout);
    // Model name:
    // 
    Label wlModelName = new Label(wModelComp, SWT.RIGHT);
    wlModelName.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelName.Label"));
    props.setLook(wlModelName);
    FormData fdlJobname = new FormData();
    fdlJobname.left = new FormAttachment(0, 0);
    fdlJobname.right = new FormAttachment(middle, -margin);
    fdlJobname.top = new FormAttachment(0, margin);
    wlModelName.setLayoutData(fdlJobname);
    wModelName = new Text(wModelComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wModelName);
    FormData fdJobname = new FormData();
    fdJobname.left = new FormAttachment(middle, 0);
    fdJobname.top = new FormAttachment(0, margin);
    fdJobname.right = new FormAttachment(100, 0);
    wModelName.setLayoutData(fdJobname);
    Control lastControl = wModelName;
    // Model description
    // 
    Label wlModelDescription = new Label(wModelComp, SWT.RIGHT);
    wlModelDescription.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelDescription.Label"));
    props.setLook(wlModelDescription);
    FormData fdlJobFilename = new FormData();
    fdlJobFilename.left = new FormAttachment(0, 0);
    fdlJobFilename.right = new FormAttachment(middle, -margin);
    fdlJobFilename.top = new FormAttachment(lastControl, margin);
    wlModelDescription.setLayoutData(fdlJobFilename);
    wModelDescription = new Text(wModelComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wModelDescription);
    FormData fdJobFilename = new FormData();
    fdJobFilename.left = new FormAttachment(middle, 0);
    fdJobFilename.top = new FormAttachment(lastControl, margin);
    fdJobFilename.right = new FormAttachment(100, 0);
    wModelDescription.setLayoutData(fdJobFilename);
    lastControl = wModelDescription;
    canvas = new Canvas(wModelComp, SWT.BORDER);
    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(0, 0);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.top = new FormAttachment(lastControl, 3 * margin);
    fdCanvas.bottom = new FormAttachment(100, -margin);
    canvas.setLayoutData(fdCanvas);
    canvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent paintEvent) {
            drawLogicalModel(logicalModel, canvas, paintEvent);
        }
    });
    FormData fdModelComp = new FormData();
    fdModelComp.left = new FormAttachment(0, 0);
    fdModelComp.top = new FormAttachment(0, 0);
    fdModelComp.right = new FormAttachment(100, 0);
    fdModelComp.bottom = new FormAttachment(100, 0);
    wModelComp.setLayoutData(fdModelComp);
    wModelTab.setControl(wModelComp);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Control(org.eclipse.swt.widgets.Control) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) CTabItem(org.eclipse.swt.custom.CTabItem) FormAttachment(org.eclipse.swt.layout.FormAttachment)

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