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

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

Introduction

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

Prototype

public static ImageDescriptor createFromURL(URL url) 

Source Link

Document

Creates and returns a new image descriptor from a URL.

Usage

From source file:com.aptana.interactive_console.InteractiveConsolePlugin.java

License:Open Source License

@Override
protected void initializeImageRegistry(ImageRegistry registry) {
    for (int i = 0; i < IMAGES.length; ++i) {
        URL url = getDefault().getBundle().getEntry(IMAGES[i][0]);
        registry.put(IMAGES[i][1], ImageDescriptor.createFromURL(url));
    }/*from   w w w  .j ava 2  s  .  c o m*/
}

From source file:com.aptana.js.debug.ui.internal.DebugUIImages.java

License:Open Source License

/**
 * Declare an Image in the registry table.
 * /*www .  j  a  v a2s  . co  m*/
 * @param key
 *            The key to use when registering the image
 * @param path
 *            The path where the image can be found. This path is relative to where this plugin class is found (i.e.
 *            typically the packages directory)
 */
private static void declareRegistryImage(String key, String path) {
    ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
    Bundle bundle = Platform.getBundle(JSDebugUIPlugin.PLUGIN_ID);
    URL url = null;
    if (bundle != null) {
        url = FileLocator.find(bundle, new Path(path), null);
        desc = ImageDescriptor.createFromURL(url);
    }
    fgImageRegistry.put(key, desc);
}

From source file:com.aptana.projects.wizards.ProjectTemplateSelectionPage.java

License:Open Source License

private Image getImage(IProjectTemplate template) {
    Image image = templateImages.get(template);
    if (image == null) {
        // Resolve and load the image
        URL iconPath = template.getIconURL();
        if (iconPath != null) {
            ImageDescriptor descriptor = ImageDescriptor.createFromURL(iconPath);
            if (descriptor != null) {
                image = descriptor.createImage(false);
                if (image != null) {
                    // Scale the image to 48x48 in case it's not.
                    ImageData imageData = image.getImageData();
                    if (imageData.x != IMAGE_SIZE || imageData.y != IMAGE_SIZE) {
                        // dispose the previous one
                        image.dispose();
                        // Scale the image data and create a new image
                        imageData = imageData.scaledTo(IMAGE_SIZE, IMAGE_SIZE);
                        image = ImageDescriptor.createFromImageData(imageData).createImage();
                    }/*  w ww  .  ja va 2 s .  c om*/
                }

            }
        }
        if (image == null) {
            image = defaultTemplateImage;
        }
        templateImages.put(template, image);
    }
    return image;
}

From source file:com.aptana.samples.ui.views.SamplesViewLabelProvider.java

License:Open Source License

@Override
public Image getImage(Object element) {
    if (element instanceof SampleCategory) {
        String iconFile = ((SampleCategory) element).getIconFile();
        if (iconFile != null) {
            File file = new File(iconFile);
            if (file.exists()) {
                String iconFilename = file.getAbsolutePath();
                Image image = imageRegistry.get(iconFilename);
                if (image == null) {
                    image = new Image(Display.getDefault(), iconFilename);
                    imageRegistry.put(iconFilename, image);
                }//from   w ww .ja  va2 s.co m
                return image;
            }
        }
        // uses folder as the default image
        return IMAGE_FOLDER;
    }
    if (element instanceof SamplesReference) {
        SamplesReference sample = (SamplesReference) element;
        URL url = sample.getIconUrl(ICON_SIZE);
        if (url == null) {
            // falls back to the default icon
            url = sample.getIconUrl();
        }
        if (url != null) {
            String key = url.toString();
            Image image = imageRegistry.get(key);
            if (image == null) {
                imageRegistry.put(key, ImageDescriptor.createFromURL(url));
                image = imageRegistry.get(key);
            }
            return image;
        }
        return SamplesUIPlugin.getImage(ICON_REMOTE);
    }
    return super.getImage(element);
}

From source file:com.aptana.scripting.model.SnippetCategoryTests.java

License:Open Source License

private SnippetCategoryElement validateCategory(String categoryName, String path, boolean isValidPath) {
    SnippetCategoryElement category = getCategoryByName(categoryName);
    assertNotNull(categoryName + " was not found", category);
    assertEquals(categoryName + " path does not match", path, category.getIconPath());

    if (isValidPath) {
        assertNotNull(category.getIconURL());
        try {// w ww .  j  a va2 s .c  o  m
            ImageDescriptor descriptor = ImageDescriptor.createFromURL(category.getIconURL());
            assertNotNull(descriptor);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    } else {
        URL iconURL = category.getIconURL();

        if (category.getIconPath() == null) {
            assertNull(categoryName + " iconUrl should be null", iconURL);
        }

        if (iconURL != null) {
            try {
                ImageDescriptor descriptor = ImageDescriptor.createFromURL(category.getIconURL());
                Image image = descriptor.createImage(false);
                assertNull(image);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return category;
}

From source file:com.aptana.snippets.ui.views.SnippetsView.java

License:Open Source License

private Image getImage(URL url) {
    String urlString = url.toString();
    Image image = imageRegistry.get(urlString);

    if (image == null) {
        imageRegistry.put(urlString, ImageDescriptor.createFromURL(url));
        image = imageRegistry.get(urlString);
    }/*  w w w .  j  av a 2 s .  c om*/

    return image;
}

From source file:com.aptana.ui.epl.UIEplPlugin.java

License:Open Source License

/**
 * Creates the specified image descriptor and registers it
 *///from  w  w  w  .java 2  s.c  om
private void createImageDescriptor(String id, ImageRegistry reg) {
    URL url = FileLocator.find(getBundle(), new Path(ICON_PATH).append(id), null);
    ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    reg.put(id, desc);
}

From source file:com.aptana.ui.widgets.SelectedTemplateComposite.java

License:Open Source License

protected void createContents() {
    setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    setLayout(GridLayoutFactory.fillDefaults().create());

    group = new Group(this, SWT.NONE);
    group.setText(Messages.SelectedTemplateGroup_Label);
    GridData gd_group = GridDataFactory.fillDefaults().grab(true, false).create();
    group.setLayoutData(gd_group);/*from   w  w  w  . j a va2s.co m*/
    group.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());

    if (projectTemplate.getIconURL() != null) {
        Label templateLabel = new Label(group, SWT.NONE);
        templateIcon = ImageDescriptor.createFromURL(projectTemplate.getIconURL()).createImage();
        templateLabel.setImage(templateIcon);
        templateLabel.setLayoutData(GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.BEGINNING).create());
    }

    final Composite labelComp = new Composite(group, SWT.NONE);
    labelComp.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    labelComp.setLayout(GridLayoutFactory.fillDefaults().create());

    Label templateValue = new Label(labelComp, SWT.WRAP);
    templateValue.setText(projectTemplate.getDisplayName());
    templateValue.setLayoutData(
            GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).create());

    String description = projectTemplate.getDescription();
    final Link descriptionValue = new Link(labelComp, SWT.WRAP);
    if (description.length() > 150) {
        displayingMore = true;
        int cutoffIndex = description.indexOf(".") + 1; //$NON-NLS-1$
        if (cutoffIndex > 150) {
            cutoffIndex = 150;
        }

        final int cutoff = cutoffIndex;
        description = MessageFormat.format(Messages.SelectedTemplateDesc_More_Label,
                projectTemplate.getDescription().substring(0, cutoff));
        descriptionValue.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                Rectangle bounds = descriptionValue.getBounds();
                int width = bounds.width;
                if (!displayingMore) {
                    descriptionValue.setText(MessageFormat.format(Messages.SelectedTemplateDesc_More_Label,
                            projectTemplate.getDescription().substring(0, cutoff)));
                } else {
                    descriptionValue.setText(MessageFormat.format(Messages.SelectedTemplateDesc_Less_Label,
                            projectTemplate.getDescription()));
                }

                displayingMore = !displayingMore;
                Point computeSize = descriptionValue.computeSize(width, SWT.DEFAULT);
                int diff = computeSize.y - bounds.height + 2;
                descriptionValue.setLayoutData(
                        GridDataFactory.fillDefaults().grab(true, true).hint(computeSize).create());
                layout(true, true);
                Point size = getShell().getSize();
                size.y += diff;
                getShell().setSize(size);
            }

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

    GridData layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, true, 1, 1);
    descriptionValue.setText(description);
    //
    // // The description is wrapped, so we have to give hints for the dimensions
    Point computeSize = templateValue.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    layoutData.widthHint = 1;
    layoutData.heightHint = computeSize.y * 2;

    descriptionValue.setLayoutData(layoutData);

}

From source file:com.arc.cdt.debug.seecode.ui.UISeeCodePlugin.java

License:Open Source License

/**
 * Returns the image descriptor with the given relative path.
 *///  w w w  .ja va  2  s. c om
public ImageDescriptor getImageDescriptor(String relativePath) {
    URL url = FileLocator.find(getBundle(), new Path(relativePath), null);
    return url != null ? ImageDescriptor.createFromURL(url) : null;
}

From source file:com.arc.cdt.importer.ImporterPlugin.java

License:Open Source License

/**
 * Returns the image descriptor with the given relative path.
 *//*from  w  w  w .  j  a  v  a 2 s  . co  m*/
public ImageDescriptor getImageDescriptor(String relativePath) {
    URL url = FileLocator.find(getBundle(), new Path(relativePath), null);
    return url != null ? ImageDescriptor.createFromURL(url) : null;

}