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:es.cv.gvcase.trmanager.ui.views.TransformationsView.java

License:Open Source License

public static ImageDescriptor getImageDescriptor(String name) {
    String iconPath = "icons/";
    URL url = Platform.getBundle("es.cv.gvcase.trmanager.ui").getResource(iconPath + name);
    return ImageDescriptor.createFromURL(url);
}

From source file:es.org.chemi.games.snake.ui.MainView.java

License:Open Source License

private void createView(Composite parent) {
    // Create the counter.
    SnakePlugin.trace(this.getClass().getName(), "Adding the counter."); //$NON-NLS-1$

    // Create the main button.
    SnakePlugin.trace(this.getClass().getName(), "Adding the main button."); //$NON-NLS-1$
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.BEGINNING;
    gridData.verticalAlignment = GridData.CENTER;
    gridData.widthHint = 48;/*from   w  w w.  ja v a 2s . c o  m*/
    gridData.heightHint = 48;
    mainButton = new Label(parent, SWT.NONE);
    mainButton.setLayoutData(gridData);
    Bundle bundle = Platform.getBundle("com.genuitec.piplug.app.snake");
    URL url = bundle.getEntry("icons/icon-restart48.png");
    mainButton.setImage(ImageDescriptor.createFromURL(url).createImage());
    mainButton.addMouseListener(new ResetGameListener());
    mainButton.setBackground(parent.getBackground());

    gridData = new GridData();
    gridData.horizontalAlignment = GridData.CENTER;
    gridData.verticalAlignment = GridData.CENTER;
    this.counter = new Counter(parent, SWT.BORDER, 4, 0, Constants.PLUGIN_ID);
    this.counter.setLayoutData(gridData);

    Label button = new Label(parent, SWT.NONE);
    gridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    gridData.widthHint = 48;
    gridData.heightHint = 48;
    button.setLayoutData(gridData);
    url = bundle.getEntry("icons/icon-close48.png");
    button.setImage(ImageDescriptor.createFromURL(url).createImage());
    button.addMouseListener(new GoHomeListener());
    button.setBackground(parent.getBackground());

    // Create the game field.
    SnakePlugin.trace(this.getClass().getName(), "Adding the game field."); //$NON-NLS-1$
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;

    // SWT.NO_BACKGROUND is used for Double Buffering.
    gameField = new GameField(parent, SWT.BORDER | SWT.NO_BACKGROUND, this);
    gameField.setLayoutData(gridData);
}

From source file:es.uah.aut.srg.micobs.pdl.ui.wizards.NewArchitectureFileWizard.java

License:Open Source License

@Override
protected void initializeDefaultPageImageDescriptor() {

    URI iconURI = URI.createPlatformPluginURI("/es.uah.aut.srg.micobs.pdl/icons/full/wizban/PDLNewWizard.gif",
            true);/*from  w  w w.  j  a  v  a 2s .  c o m*/
    try {
        ImageDescriptor desc = ImageDescriptor.createFromURL(FileConverter.platformPluginURItoURL(iconURI));
        setDefaultPageImageDescriptor(desc);
    } catch (IOException e) {
        MICOBSPlugin.INSTANCE.log(e);
    }
}

From source file:es.uah.aut.srg.micobs.ui.wizards.EmptyMICOBSProjectWizard.java

License:Open Source License

/**
 * Initializes the default image descriptor of the wizard.
 *///from  ww w .j av a2  s .  com
protected void initializeDefaultPageImageDescriptor() {

    URI iconURI = URI.createPlatformPluginURI("/es.uah.aut.srg.micobs/icons/full/wizban/MICOBSNewWizard.gif",
            true);
    try {
        ImageDescriptor desc = ImageDescriptor.createFromURL(FileConverter.platformPluginURItoURL(iconURI));
        setDefaultPageImageDescriptor(desc);
    } catch (IOException e) {
        MICOBSPlugin.INSTANCE.log(e);
    }
}

From source file:eu.abc4trust.ri.ui.user.utils.ResourceRegistryStore.java

License:Open Source License

private static Image getThumbnail(URL image, int maxSideLength, boolean gray) {
    String id = "thumbmail::" + maxSideLength + "::" + image + "::" + gray; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    // check whether there is already a thumbnail for this image URL in the registry
    Image cachedThumbnail = ResourceRegistryStore.getImage(id);
    if (cachedThumbnail != null) {
        return cachedThumbnail;
    }/*from  ww  w .j  ava 2s. c  om*/

    ImageDescriptor imgDesc = ImageDescriptor.createFromURL(image);
    if (imgDesc == null)
        return getImage(IMG_MISSING);
    ImageData imgData = imgDesc.getImageData();
    if (imgData == null)
        return getImage(IMG_MISSING);

    int oWidth = imgData.width;
    int oHeight = imgData.height;

    double ratio;
    if (oWidth >= oHeight) {
        ratio = (double) maxSideLength / oWidth;
    } else {
        ratio = (double) maxSideLength / oHeight;
    }

    Image thumbnail = new Image(Display.getDefault(),
            imgData.scaledTo((int) (oWidth * ratio), (int) (oHeight * ratio)));
    //      if (gray) { // TODO add support for gray image or remove gray parameter
    //         Image grayed = new Image(Display.getDefault(), thumbnail, SWT.image);
    //         thumbnail.dispose();
    //         // put into registry
    //      }
    ResourceRegistryStore.getImageRegistry().put(id, thumbnail);
    return thumbnail;
}

From source file:eu.abc4trust.ri.ui.user.view.CredentialAttributesView.java

License:Open Source License

private Composite createContent(Composite parent) {
    int firstColumWidth = 300; // TODO calculate dynamically by the widest column

    ScrolledComposite scrolledContent = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);

    Composite content = new Composite(scrolledContent, SWT.NONE);
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = 5;/*  www  . jav a  2 s .  com*/
    formLayout.marginWidth = 5;
    formLayout.spacing = 5;
    content.setLayout(formLayout);

    scrolledContent.setContent(content);
    scrolledContent.setExpandVertical(false);
    scrolledContent.setExpandHorizontal(false);

    Label imageLabel = new Label(content, SWT.NONE);
    Image image = null;
    try {
        // image = ResourceRegistryStore.getThumbnail(currentCredential.desc.getImageReference().toURL(), 200);
        image = ImageDescriptor.createFromURL(currentCredential.desc.getImageReference().toURL()).createImage();
        if (image != null && image.getBounds().width > 150) {
            ImageData scaledImage = image.internalImage.getImageData().scaledTo(150, 150);
            Device device = parent.getDisplay();
            image = new Image(device, scaledImage);
        }
        imagesToDispose.add(image);
        imageLabel.setImage(image);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    FormData formData = new FormData(SWT.DEFAULT, SWT.DEFAULT);
    formData.left = new FormAttachment(0);
    formData.top = new FormAttachment(0);
    imageLabel.setLayoutData(formData);
    Text typeLabel = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
    typeLabel.setText(Messages.get().CredentialAttributesView_credentialType + ":"); //$NON-NLS-1$
    Text typeText = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
    String credSpecUID = currentCredential.desc.getCredentialSpecificationUID().toString();
    String humanReadableCredSpecName = UIUtil
            .getHumanReadable(currentCredential.spec.spec.getFriendlyCredentialName());
    typeText.setText(humanReadableCredSpecName + " (" + credSpecUID + ")");

    formData = new FormData(firstColumWidth, SWT.DEFAULT); // width: 180
    formData.left = new FormAttachment(0);
    formData.top = new FormAttachment(typeText, 0, SWT.CENTER);
    typeLabel.setLayoutData(formData);
    formData = new FormData(SWT.DEFAULT, SWT.DEFAULT);
    formData.left = new FormAttachment(typeLabel);
    formData.top = new FormAttachment(imageLabel);
    typeText.setLayoutData(formData);
    typeText.setBackground(typeLabel.getBackground());

    Text issuerLabel = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
    issuerLabel.setText(Messages.get().CredentialAttributesView_issuer + ":"); //$NON-NLS-1$
    Text issuerText = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
    String issuerUID = currentCredential.desc.getIssuerParametersUID().toString();
    String humanReadableIssuerName = UIUtil.getHumanReadable(currentCredential.issuer.description);
    issuerText.setText(humanReadableIssuerName + " (" + issuerUID + ")");
    issuerText.setBackground(issuerLabel.getBackground());

    formData = new FormData(firstColumWidth, SWT.DEFAULT); // width: 180
    formData.left = new FormAttachment(0);
    formData.top = new FormAttachment(issuerText, 0, SWT.CENTER);
    issuerLabel.setLayoutData(formData);
    formData = new FormData(SWT.DEFAULT, SWT.DEFAULT);
    formData.left = new FormAttachment(issuerLabel);
    formData.top = new FormAttachment(typeText);
    issuerText.setLayoutData(formData);

    Text revocationLabel = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
    revocationLabel.setText(Messages.get().CredentialAttributesView_revokedByIssuer + ":"); //$NON-NLS-1$
    Label revocationCheckboxOrText = new Label(content, SWT.NONE);
    if (currentCredential.spec.spec.isRevocable()) {
        // Show checkbox if the credential is revocable
        final boolean state = currentCredential.desc.isRevokedByIssuer();
        revocationCheckboxOrText
                .setImage(ResourceRegistryStore.getImage(state ? ResourceRegistryStore.IMG_CHECKBOX_SELECTED
                        : ResourceRegistryStore.IMG_CHECKBOX_UNSELECTED)); // This is a workaround as disabled checkboxes are very light grey and almost invisible.
    } else {
        // Inform the user that the credential is not revocable
        revocationCheckboxOrText.setText(Messages.get().CredentialAttributesView_msg_notRevocable);
    }
    formData = new FormData(firstColumWidth, SWT.DEFAULT); // width: 180
    formData.left = new FormAttachment(0);
    formData.top = new FormAttachment(revocationCheckboxOrText, 0, SWT.CENTER);
    revocationLabel.setLayoutData(formData);
    formData = new FormData(SWT.DEFAULT, SWT.DEFAULT);
    formData.left = new FormAttachment(revocationLabel, 9);
    formData.top = new FormAttachment(issuerText);
    revocationCheckboxOrText.setLayoutData(formData);

    // Create a label and appropriate further controls (text field, date element,
    // checkbox, etc.) for every attribute of the current credential
    List<Control> valueControls = new ArrayList<Control>();
    for (Attribute attribute : currentCredential.desc.getAttribute()) {
        Control valueControl = null; // Create the control already now for layouting the label correctly

        //////////////////////////////////////////////
        // Label showing the attribute name
        String attributeType = attribute.getAttributeDescription().getType().toString();
        String fallback;
        if (attributeType.equals("http://abc4trust.eu/wp2/abcschemav1.0/revocationhandle")) { //$NON-NLS-1$
            fallback = Messages.get().CredentialAttributesView_revocationHandle;
        } else {
            fallback = attributeType;
        }
        Text label = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
        label.setText(UIUtil.getHumanReadable(attribute.getAttributeDescription().getFriendlyAttributeName(),
                fallback) + ":"); //$NON-NLS-1$

        //////////////////////////////////////////////
        // Control (text field, date element, checkbox, etc.) showing the attribute value
        // TODO: properly support data types with different control types         
        //         URI dataType = attribute.getAttributeDescription().getDataType();
        //         if (dataType.equals(Date.class)) {
        //            // Attribute is a date
        //            Date d = (Date) currentCredential.getAttributeValue(attributeName);
        //            Calendar c = new GregorianCalendar();
        //            try {
        //               Date origin = Translator.DATE_FORMAT.parse(Constants.DATE_ORIGIN);
        //               c.setTime(origin);
        //               c.add(Calendar.YEAR, 1);
        //            } catch (ParseException e) {
        //               e.printStackTrace();
        //            }
        //            
        //            valueControl = new Text(content, SWT.SINGLE | SWT.READ_ONLY);
        //            if(c.getTime().after(d)) {
        //               ((Text)valueControl).setText("None");
        //            } else {
        //               SimpleDateFormat df = new SimpleDateFormat("EEEE, d MMMM yyyy 'at' HH:mm z");
        //               ((Text)valueControl).setText(df.format(d));
        //            }
        //            
        //            valueControl.setBackground(label.getBackground());
        //            
        //         } else if (dataType.equals(Boolean.class)) {
        //            // Attribute is a boolean value
        //            final boolean state = ((Boolean)currentCredential.getAttributeValue(attributeName)).booleanValue();
        //            valueControl = new Button(content, SWT.CHECK);
        //            valueControl.setBackground(label.getBackground());
        //            ((Button)valueControl).setSelection(state);
        //            ((Button)valueControl).addSelectionListener(new SelectionAdapter() {
        //               @Override
        //               // This is a workaround as "valueControl.setEnabled(false)" results
        //               // in a very light grey checkbox that is almost invisible.
        //               public void widgetSelected(SelectionEvent e) {
        //                  // e.doit = false; // does not work...
        //                  Button checkBox = ((Button) e.widget);
        //                  checkBox.setSelection(state);
        //               }
        //            });
        //            
        //         } else {
        // Attribute value is represented as text.
        valueControl = new Text(content, SWT.SINGLE | SWT.READ_ONLY);

        String textValue;
        String attributeDataType = attribute.getAttributeDescription().getDataType().toString().substring(3);
        if (attributeDataType.equals(DatatypeConstants.DATE.getLocalPart())) {
            Calendar c = DatatypeConverter.parseDate(attribute.getAttributeValue().toString());
            textValue = new SimpleDateFormat(DATE_FORMAT).format(c.getTime());
        } else {
            textValue = attribute.getAttributeValue().toString();
        }

        ((Text) valueControl).setText(textValue);
        valueControl.setBackground(label.getBackground());
        //         }

        //////////////////////////////////////////////
        // Lay out the controls
        formData = new FormData(firstColumWidth, SWT.DEFAULT); // width: 180
        formData.left = new FormAttachment(0);
        formData.top = new FormAttachment(valueControl, 0, SWT.CENTER);
        label.setLayoutData(formData);

        formData = new FormData();
        formData.left = new FormAttachment(label);
        if (valueControls.isEmpty()) {
            formData.top = new FormAttachment(revocationLabel);
        } else {
            // Attach the top of the valueControl to the bottom of the one above
            formData.top = new FormAttachment(valueControls.get(valueControls.size() - 1));
        }
        valueControl.setLayoutData(formData);

        // Remember the control to lay out subsequent ones right below it
        valueControls.add(valueControl);
    }

    ///////////////////////////////////////////////////////////////////////
    // Make the scrollbars work
    Point size = scrolledContent.getContent().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    scrolledContent.getContent().setSize(size);
    scrolledContent.setMinSize(size);
    //scrolledContent.layout(true, true);

    focusElement = typeText;
    return scrolledContent;
}

From source file:eu.abc4trust.ri.ui.user.wizard.IssueWizardPageTwo.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);// w w  w  .ja  v  a2s .  co  m

    layout.numColumns = 2;

    Bundle bundle = FrameworkUtil.getBundle(this.getClass());
    URL url = FileLocator.find(bundle, new Path("icons/load.gif"), null);
    Image image = ImageDescriptor.createFromURL(url).createImage();

    label1 = new Label(container, SWT.NONE);
    label1.setImage(image);

    label2 = new Label(container, SWT.NONE);
    label2.setText("Getting crendential, please wait...");

    setControl(container);
    setPageComplete(false);
}

From source file:eu.aniketos.ncvm.userinterface.Activator.java

License:Open Source License

protected void initializeImageRegistry(ImageRegistry registry) {
    IPath path;/*from  w  w w  .  ja v a 2  s  .c  o  m*/
    URL url;
    ImageDescriptor desc;

    Bundle bundle = Platform.getBundle(PLUGIN_ID);
    path = new Path("icons/configure.gif");
    url = FileLocator.find(bundle, path, null);
    desc = ImageDescriptor.createFromURL(url);
    registry.put(IMG_NCVM_CONFIGURE, desc);

    path = new Path("icons/aniketos-small.png");
    url = FileLocator.find(bundle, path, null);
    desc = ImageDescriptor.createFromURL(url);
    registry.put(IMG_NCVM_ANIKETOS_SMALL, desc);
}

From source file:eu.artist.postmigration.nfrvt.lang.common.ui.labeling.ARTISTCommonLabelProvider.java

License:Open Source License

/**
 * Retrieves the image specified by the imageName from the given plugin.
 * If no such image can be found, null is returned.
 * @param plugin plugin to be searched//from ww w  .  j a  va  2s  .c  o  m
 * @param imageName name of the image
 * @return image if found or null
 */
private Image getImageByName(AbstractUIPlugin plugin, String imageName) {
    if (plugin == null || imageName == null || imageName.isEmpty())
        return null;

    URL imgUrl = plugin.getBundle().getEntry(IMAGE_DIRECTORY + imageName);
    if (imgUrl != null) {
        ImageDescriptor id = null;
        Image result = plugin.getImageRegistry().get(imgUrl.toExternalForm());
        if (result == null) {
            id = ImageDescriptor.createFromURL(imgUrl);
            if (id != null) {
                result = id.createImage();
                plugin.getImageRegistry().put(imgUrl.toExternalForm(), result);
            }
        }
        return result;
    }
    return null;
}

From source file:eu.artist.postmigration.nfrvt.lang.util.run.ui.ModelSelectionTab.java

License:Open Source License

@Override
public Image getImage() {
    ImageDescriptor id = ImageDescriptor.createFromURL(getIcon());
    if (id != null)
        return id.createImage();
    return null;//w w w .  j  a  va2s. co  m
}