Example usage for org.eclipse.jface.resource ImageDescriptor createImage

List of usage examples for org.eclipse.jface.resource ImageDescriptor createImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createImage.

Prototype

public Image createImage() 

Source Link

Document

Creates and returns a new SWT image for this image descriptor.

Usage

From source file:com.nokia.tools.ui.branding.defaultimpl.BrandingManager.java

License:Open Source License

/**
 * /* www  .j  a v a2  s  .c  o  m*/
 * @see com.nokia.tools.screen.ui.branding.IBrandingManager#getBannerImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)
 */
public ImageDescriptor getBannerImageDescriptor(ImageDescriptor icon) {
    ImageDescriptor desc = Activator.getImageDescriptor("icons/dialog_banner_150x66.bmp");

    if (icon != null) {
        Image bannerImage = null;
        Image iconImage = null;
        GC imageGC = null;

        try {
            bannerImage = desc.createImage();
            iconImage = icon.createImage();
            imageGC = new GC(bannerImage);
            imageGC.drawImage(iconImage,
                    (int) ((bannerImage.getBounds().width - 17) - iconImage.getBounds().width),
                    (int) (33 - (iconImage.getBounds().height / 2)));
            return ImageDescriptor.createFromImageData(bannerImage.getImageData());
        } finally {
            if (imageGC != null) {
                imageGC.dispose();
            }
            if (bannerImage != null) {
                bannerImage.dispose();
            }
            if (iconImage != null) {
                iconImage.dispose();
            }
        }
    }
    return desc;
}

From source file:com.nokia.tools.variant.carbidev.ApplicationWorkbenchWindowAdvisor.java

License:Open Source License

@Override
public void postWindowCreate() {
    super.postWindowCreate();
    ImageDescriptor id = Activator.getImageDescriptor("icons/carbidev_app.ico");
    IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
    configurer.getWindow().getShell().setImage(id.createImage());
}

From source file:com.nokia.tools.variant.editor.dialogs.SaveAsDialog.java

License:Open Source License

/**
 * Configures the shell/*from  www  .j a  v  a  2 s.co  m*/
 * 
 * @param shell
 *            the shell
 */
protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setSize(550, 260);
    shell.setText("Save As");

    ImageDescriptor iconDescriptor = Activator.getImageDescriptor("icons/carbide_v_16x16.png");
    shell.setImage(iconDescriptor.createImage());
}

From source file:com.nokia.tools.variant.editor.dialogs.SaveAsDialog.java

License:Open Source License

/**
 * Creates the dialog's contents/*from  www.  jav  a 2 s . co m*/
 * 
 * @param shell
 *            the dialog window
 */
protected Control createDialogArea(Composite parent) {
    GridLayout childLayout = new GridLayout(1, true);
    childLayout.marginHeight = 0;
    childLayout.marginWidth = 0;
    childLayout.verticalSpacing = 0;

    Composite workArea = new Composite(parent, SWT.NONE | SWT.NO_REDRAW_RESIZE);

    childLayout = new GridLayout(1, true);
    childLayout.marginHeight = 0;
    childLayout.marginWidth = 0;
    childLayout.verticalSpacing = 0;
    workArea.setLayout(childLayout);
    workArea.setLayoutData(new GridData(GridData.FILL_BOTH));

    // ---
    Composite titleComposite = new Composite(workArea, SWT.NO_REDRAW_RESIZE);
    titleComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    childLayout = new GridLayout(3, false);
    childLayout.marginHeight = 0;
    childLayout.marginWidth = 0;
    childLayout.verticalSpacing = 0;
    titleComposite.setLayout(childLayout);

    Label imgLabel = new Label(titleComposite, SWT.NO);
    imgLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    gridData.horizontalIndent = 10;
    imgLabel.setLayoutData(gridData);

    imgLabel.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_INFO));

    Label leftLabel = new Label(titleComposite, SWT.NO);
    leftLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
    gridData.widthHint = 450;
    gridData.heightHint = 55;
    leftLabel.setLayoutData(gridData);

    leftLabel.setText("\n Save your changes as a new CPF.\n" + " You may want to do this for creating "
            + "a new variant or revision of your current CPF.");

    Label rightLabel = new Label(titleComposite, SWT.NO);
    rightLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
    gridData.widthHint = 60;
    gridData.heightHint = 60;
    rightLabel.setLayoutData(gridData);

    ImageDescriptor imageDescriptor = Activator.getImageDescriptor("icons/saveas_wiz.png");
    Image image = imageDescriptor.createImage();

    rightLabel.setImage(image);

    // ---
    createControls(workArea);

    // ---
    Composite btnComposite = new Composite(workArea, SWT.NO_REDRAW_RESIZE);

    childLayout = new GridLayout(2, true);
    childLayout.marginHeight = 0;
    childLayout.marginWidth = 0;
    childLayout.verticalSpacing = 0;
    btnComposite.setLayout(childLayout);

    leftLabel = new Label(btnComposite, SWT.NO);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
    gridData.widthHint = 330;
    gridData.heightHint = 30;
    leftLabel.setLayoutData(gridData);

    Composite btnGroupComposite = new Composite(btnComposite, SWT.NO_REDRAW_RESIZE);

    childLayout = new GridLayout(2, true);
    childLayout.marginHeight = 0;
    childLayout.marginWidth = 0;
    childLayout.verticalSpacing = 0;
    btnGroupComposite.setLayout(childLayout);

    gridData = new GridData();
    gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
    gridData.widthHint = 150;
    gridData.heightHint = 22;
    btnGroupComposite.setLayoutData(gridData);

    // Set the OK button as the default, so
    // user can type input and press Enter
    // to dismiss
    // shell.setDefaultButton(okBtn);
    // shell.layout(true, true);
    return workArea;
}

From source file:com.nokia.tools.variant.editor.dialogs.SelectConfigurationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    GridLayout layout3 = (GridLayout) parent.getLayout();
    layout3.marginLeft = 0;//  www .jav  a  2s .c o  m
    layout3.marginRight = 0;
    layout3.marginTop = 0;
    layout3.marginBottom = 0;
    layout3.horizontalSpacing = 0;
    layout3.verticalSpacing = 0;
    parent.setLayout(layout3);

    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(1, false);
    dialogArea.setLayout(layout);

    Composite c = new Composite(dialogArea, SWT.NONE);
    c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout2 = new GridLayout(2, false);
    c.setLayout(layout2);
    c.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    Label l = new Label(c, SWT.NONE);
    l.setText("The file contains multiple configurations. Select configuration and then press OK.");
    l.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.heightHint = 60;
    layoutData.grabExcessHorizontalSpace = true;
    l.setLayoutData(layoutData);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
    gridData.heightHint = 60;
    Label rightLabel = new Label(c, SWT.NO);
    rightLabel.setLayoutData(gridData);

    ImageDescriptor imageDescriptor = Activator.getImageDescriptor("icons/saveas_wiz.png");
    Image image = imageDescriptor.createImage();

    rightLabel.setImage(image);
    rightLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    Rectangle bounds = dialogArea.getShell().getBounds();
    getShell().setBounds(bounds);

    dialogArea.setLayout(new GridLayout());
    configTable = new Table(dialogArea, SWT.FULL_SELECTION);
    final TableViewer viewer = new TableViewer(configTable);

    final Listener labelDisposeListener = new Listener() {
        public void handleEvent(Event event) {
            StyledText styledText = (StyledText) event.widget;
            Shell shell = styledText.getShell();
            switch (event.type) {
            case SWT.MouseDown:
                Event e = new Event();
                e.item = (TableItem) styledText.getData(KEY_TOOLTIPTEXT);
                configTable.setSelection(new TableItem[] { (TableItem) e.item });
                configTable.notifyListeners(SWT.Selection, e);
                // dispose shell on mouse down
            case SWT.MouseExit:
                shell.dispose();
                break;
            }
        }
    };

    Listener toolTipDisplayListener = new Listener() {
        Shell tooltipShell = null;
        StyledText styledText = null;

        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
            case SWT.KeyDown:
            case SWT.MouseMove:
                if (tooltipShell == null || tooltipShell.isDisposed()) {
                    break;
                }
                tooltipShell.dispose();
                tooltipShell = null;
                styledText = null;
                break;
            case SWT.MouseHover:
                TableItem item = configTable.getItem(new Point(event.x, event.y));
                if (item != null) {
                    if (tooltipShell != null && !tooltipShell.isDisposed()) {
                        tooltipShell.dispose();
                    }
                    tooltipShell = new Shell(configTable.getShell(), SWT.ON_TOP | SWT.TOOL);
                    tooltipShell.setLayout(new FillLayout());
                    styledText = new StyledText(tooltipShell, SWT.NONE);
                    styledText.setEditable(false);
                    styledText.getCaret().setVisible(false);
                    styledText
                            .setBackground(configTable.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                    styledText
                            .setForeground(configTable.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                    styledText.setData(KEY_TOOLTIPTEXT, item);
                    Object data = item.getData();
                    CPFInformation cpfInformation = (CPFInformation) data;
                    styledText.setText(cpfInformation.getLayerPopupInfoText());
                    styledText.addListener(SWT.MouseExit, labelDisposeListener);
                    styledText.addListener(SWT.MouseDown, labelDisposeListener);
                    Point size = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    Rectangle rect = item.getBounds(0);
                    Point pt = configTable.toDisplay(rect.x, rect.y);
                    tooltipShell.setBounds(pt.x, pt.y, size.x, size.y);
                    tooltipShell.setVisible(true);
                }
                break;
            }
        }
    };

    configTable.addListener(SWT.Dispose, toolTipDisplayListener);
    configTable.addListener(SWT.KeyDown, toolTipDisplayListener);
    configTable.addListener(SWT.MouseMove, toolTipDisplayListener);
    configTable.addListener(SWT.MouseHover, toolTipDisplayListener);

    configTable.setHeaderVisible(true);
    configTable.setLayoutData(new GridData(GridData.FILL_BOTH));

    configTable.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            selectedConfigurationIndex = configTable.getSelectionIndex();
            viewer.setSelection(new StructuredSelection(viewer.getElementAt(selectedConfigurationIndex)), true);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    final String[] columnNames = new String[] { "Name", "Version", "Platform", "Release", "Product", "Date" };
    final int[] columnWidths = new int[] { 170, 50, 100, 60, 100, 100 };

    viewer.setColumnProperties(columnNames);

    TableColumn nameColumn = new TableColumn(configTable, SWT.LEFT);
    nameColumn.setText(columnNames[0]);
    nameColumn.setWidth(columnWidths[0]);

    TableColumn versionColumn = new TableColumn(configTable, SWT.LEFT);
    versionColumn.setText(columnNames[1]);
    versionColumn.setWidth(columnWidths[1]);

    TableColumn platformColumn = new TableColumn(configTable, SWT.LEFT);
    platformColumn.setText(columnNames[2]);
    platformColumn.setWidth(columnWidths[2]);

    TableColumn releaseColumn = new TableColumn(configTable, SWT.LEFT);
    releaseColumn.setText(columnNames[3]);
    releaseColumn.setWidth(columnWidths[3]);

    TableColumn productColumn = new TableColumn(configTable, SWT.LEFT);
    productColumn.setText(columnNames[4]);
    productColumn.setWidth(columnWidths[4]);

    TableColumn dateColumn = new TableColumn(configTable, SWT.LEFT);
    dateColumn.setText(columnNames[5]);
    dateColumn.setWidth(columnWidths[5]);

    viewer.setLabelProvider(new ITableLabelProvider() {

        public void removeListener(ILabelProviderListener listener) {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public String getColumnText(Object element, int columnIndex) {
            if (!(element instanceof CPFInformation)) {
                return null;
            }
            CPFInformation ci = (CPFInformation) element;
            switch (columnIndex) {
            case 0:
                return ci.getName();
            case 1:
                return ci.getVersion();
            case 2:
                return ci.getPlatform();
            case 3:
                return ci.getRelease();
            case 4:
                return ci.getProduct();
            case 5:
                return ci.getDate();
            }
            return null;
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    ArrayContentProvider provider = new ArrayContentProvider();
    viewer.setContentProvider(provider);

    viewer.setInput(configurations);

    int itemCount = configTable.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        TableItem item = configTable.getItem(i);
        // ToolTip.createToolTip(item, "");
    }
    viewer.setSelection(new StructuredSelection(viewer.getElementAt(0)), true);
    dialogArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    return dialogArea;
}

From source file:com.predic8.plugin.membrane.views.RequestView.java

License:Apache License

@Override
public void createPartControl(final Composite parent) {
    super.createPartControl(parent);

    itemResendRequest = new ToolItem(toolBar, SWT.PUSH);
    itemResendRequest.setText("Resend");
    ImageDescriptor descriptorResend = MembraneUIPlugin.getDefault().getImageRegistry()
            .getDescriptor(ImageKeys.IMAGE_ARROW_REDO);

    Image iconResend = descriptorResend.createImage();
    itemResendRequest.setImage(iconResend);
    itemResendRequest.addSelectionListener(new SelectionAdapter() {
        @Override// w  w  w  . j av  a 2s . c  o  m
        public void widgetSelected(SelectionEvent e) {
            ((RequestComp) baseComp).resendRequest();
        }
    });
    itemResendRequest.setEnabled(false);

    baseComp = new RequestComp(partComposite, SWT.NONE, this);
    baseComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    contentProvider = new RequestViewContentProvider(this);
}

From source file:com.puppetlabs.geppetto.pp.dsl.ui.internal.PPPluginImages.java

License:Open Source License

public static Image manage(String key, ImageDescriptor desc) {
    Image image = desc.createImage();
    PLUGIN_REGISTRY.put(key, image);/*from w ww  .j  a  v a2  s .  com*/
    return image;
}

From source file:com.python.pydev.ui.hierarchy.HierarchyViewer.java

License:Open Source License

public void setHierarchy(HierarchyNodeModel model) {
    if (classImage == null) {
        classImage = PydevPlugin.getImageCache().get(UIConstants.CLASS_ICON);
    }//from  w  w  w  . j  a  va  2 s. c  om

    DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
    DataAndImageTreeNode item = new DataAndImageTreeNode(root, model, classImage);

    DataAndImageTreeNode base = item;
    recursivelyAdd(model, base, true, new HashSet<HierarchyNodeModel>());

    if (parentsImage == null) {
        ImageDescriptor imageDescriptor = com.python.pydev.PydevPlugin.getImageDescriptor("icons/class_hi.gif");
        if (imageDescriptor != null) {
            parentsImage = imageDescriptor.createImage();
        }
    }

    DataAndImageTreeNode parents = new DataAndImageTreeNode(root, "Parents", parentsImage);
    recursivelyAdd(model, parents, false, new HashSet<HierarchyNodeModel>());

    treeClassesViewer.setInput(root);

    onClick(model, 1);
}

From source file:com.rcpcompany.uibindings.uiAttributes.UIAttributePainter.java

License:Open Source License

/**
 * Makes an image of a Check button in selected or un-selected mode.
 * /*  w ww .j ava  2s  .  c om*/
 * @param control the parent control
 * @param type selected or not
 * @return the image
 */
private Image makeShot(Control control, boolean type) {
    /*
     * First try to load the image directly from the plugin...
     */
    final String osname = System.getProperty("os.name"); //$NON-NLS-1$
    final String osversion = System.getProperty("os.version"); //$NON-NLS-1$

    String imageName = "images/checkbox/" + osname + "-" + osversion;

    /*
     * Check for classic theme
     */
    final RGB widgetBackgroundColor = control.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB();
    if (widgetBackgroundColor.red == 212 && widgetBackgroundColor.green == 208
            && widgetBackgroundColor.blue == 200) {
        imageName += "-classic";
    }

    imageName += "-" + type + ".png";
    final ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.ID, imageName);
    if (id != null) {
        final Image i = id.createImage();
        final Rectangle bounds = i.getBounds();
        if (bounds.height + EXTRA_CELL_HEIGHT > myMinHeight) {
            myMinHeight = bounds.height + EXTRA_CELL_HEIGHT;
        }
        return i;
    }

    /*
     * Hopefully no platform uses exactly this color because we'll make it transparent in the
     * image.
     */
    final Color greenScreen = new Color(control.getDisplay(), 222, 223, 224);

    final Shell shell = new Shell(control.getShell(), SWT.NO_TRIM);

    // otherwise we have a default gray color
    shell.setBackground(greenScreen);

    if (Util.isMac()) {
        final Button button2 = new Button(shell, SWT.CHECK);
        final Point bsize = button2.computeSize(SWT.DEFAULT, SWT.DEFAULT);

        // otherwise an image is stretched by width
        bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
        bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
        button2.setSize(bsize);
        button2.setLocation(100, 100);
    }

    final Button button = new Button(shell, SWT.CHECK);
    button.setBackground(greenScreen);
    button.setSelection(type);

    // otherwise an image is located in a corner
    button.setLocation(1, 1);
    final Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    // otherwise an image is stretched by width
    bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
    bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
    button.setSize(bsize);

    shell.setSize(bsize);

    final Image image;
    GC gc = null;
    try {
        shell.open();
        gc = new GC(shell);

        image = new Image(control.getDisplay(), bsize.x, bsize.y);
        gc.copyArea(image, 0, 0);
    } finally {
        if (gc != null) {
            gc.dispose();
        }
        shell.close();
    }

    final ImageData imageData = image.getImageData();
    imageData.transparentPixel = imageData.palette.getPixel(greenScreen.getRGB());

    final Image img = new Image(control.getDisplay(), imageData);
    image.dispose();

    if (bsize.y + EXTRA_CELL_HEIGHT > myMinHeight) {
        myMinHeight = bsize.y + EXTRA_CELL_HEIGHT;
    }

    // final ImageLoader imageLoader = new ImageLoader();
    // imageLoader.data = new ImageData[] { imageData };
    //
    // imageLoader.save("/tmp/" + imageName, SWT.IMAGE_PNG);

    return img;
}

From source file:com.rcpcompany.utils.extensionpoints.CEResourceHolder.java

License:Open Source License

/**
 * Returns the image for the holder object.
 * /*from   w w w . ja v  a  2 s. c  o  m*/
 * @return the image or <code>null</code>
 */
public Image getImage() {
    if (myImage == null) {
        final ImageDescriptor descriptor = getImageDescriptor();
        if (descriptor != null) {
            myImage = descriptor.createImage();
        }
    }
    return myImage;
}