Java Code Examples for org.eclipse.jface.resource.ImageDescriptor#createFromImage()

The following examples show how to use org.eclipse.jface.resource.ImageDescriptor#createFromImage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gama   File: GamaIcon.java    License: GNU General Public License v3.0 6 votes vote down vote up
public ImageDescriptor descriptor() {
	if (descriptor == null) {
		final Image image = GamaIcons.getInstance().getImageInCache(code);
		if (image != null) {
			descriptor = ImageDescriptor.createFromImage(image);
		} else {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(plugin, GamaIcons.DEFAULT_PATH + path + ".png");
		}

		if (descriptor == null) {
			DEBUG.ERR("ERROR: Cannot find icon " + GamaIcons.DEFAULT_PATH + path + ".png in plugin: " + plugin);
			descriptor = ImageDescriptor.getMissingImageDescriptor();
		}
	}
	return descriptor;
}
 
Example 2
private void setColorToImage() {
    // #for_now jflute cannot test so suppress warning only (2020/05/16)
    @SuppressWarnings("deprecation")
    final ImageData imageData = Activator.getImageDescriptor(ImageKey.CHANGE_BACKGROUND_COLOR).getImageData();
    final int blackPixel = imageData.palette.getPixel(new RGB(0, 0, 0));
    imageData.transparentPixel = imageData.palette.getPixel(new RGB(255, 255, 255));
    imageData.palette.colors[blackPixel] = rgb;

    image = new Image(Display.getCurrent(), imageData);

    final ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
    setImageDescriptor(descriptor);
    if (getSelection() instanceof StructuredSelection) {
        for (final Object element : ((StructuredSelection) getSelection()).toList()) {
            if (element instanceof TableViewEditPart) {
                ((TableViewEditPart) element).refresh();
                ((TableViewEditPart) element).refreshVisuals();
            }
        }
    }
}
 
Example 3
@Override
public void decorate(Object element, IDecoration decoration){
	IContact contact = (IContact) element;
	if (contact.isDeleted()) {
		ImageDescriptor deleted = Images.IMG_DELETE.getImageDescriptor();
		decoration.addOverlay(deleted, IDecoration.TOP_LEFT);
	}
	
	if (contact.isMandator()) {
		ImageDescriptor vip = Images.IMG_VIP_OVERLAY.getImageDescriptor();
		decoration.addOverlay(vip, IDecoration.BOTTOM_RIGHT);
	}
	if (contact.isUser()) {
		FieldDecoration info =
			FieldDecorationRegistry.getDefault().getFieldDecoration(
				FieldDecorationRegistry.DEC_INFORMATION);
		ImageDescriptor infoD = ImageDescriptor.createFromImage(info.getImage());
		decoration.addOverlay(infoD, IDecoration.BOTTOM_LEFT);
	}
}
 
Example 4
private void setColorToImage() {
	ImageData imageData = Activator.getImageDescriptor(
			ImageKey.CHANGE_BACKGROUND_COLOR).getImageData();
	int blackPixel = imageData.palette.getPixel(new RGB(0, 0, 0));
	imageData.transparentPixel = imageData.palette.getPixel(new RGB(255,
			255, 255));
	imageData.palette.colors[blackPixel] = this.rgb;

	if (this.image != null) {
		// this.image.dispose();
	}
	this.image = new Image(Display.getCurrent(), imageData);

	ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
	this.setImageDescriptor(descriptor);
	if (this.getSelection() instanceof StructuredSelection) {
		for (Object element : ((StructuredSelection) this.getSelection()).toList()) {
			if (element instanceof TableViewEditPart) {
				((TableViewEditPart)element).refresh();
				((TableViewEditPart)element).refreshVisuals();
			}
		}
	}
}
 
Example 5
/**
 * Checks the indirect {@link ImageDescriptor image descriptor} caching.
 */
@Test
public void testIndirectImageDescriptorCaching() {
	final Image img1 = ImageRef.LIB_PATH.asImage().orNull();
	final Image img2 = ImageRef.LIB_PATH.asImage().orNull();
	final ImageDescriptor desc1 = ImageDescriptor.createFromImage(img1);
	final ImageDescriptor desc2 = ImageDescriptor.createFromImage(img2);
	assertTrue("Expected different reference of image descriptors.", desc1 != desc2);
}
 
Example 6
/**
 * @since 2.4
 */
@Override
public ImageDescriptor getImageDescriptor(Image image) {
	for(Map.Entry<ImageDescriptor, Image> entry : registry.entrySet()) {
		if(entry.getValue().equals(image))
			return entry.getKey();
	}
	ImageDescriptor newDescriptor = ImageDescriptor.createFromImage(image);
	registry.put(newDescriptor, image);
	return newDescriptor;
}
 
Example 7
@Override
public ImageDescriptor getImageDescriptor(Object o) {
    IXdsElement xe = getXdsElement(o);
    if (xe instanceof IXdsCompilationUnit ) {
        return ImageDescriptor.createFromImage(ImageUtils.getImage(ImageUtils.IMPLEMENTATION_MODULE_IMAGE_NAME));
    }
    else if (xe instanceof IXdsContainer) {
        return ImageDescriptor.createFromImage(ImageUtils.getImage(ImageUtils.PACKAGE_FRAGMENT_IMAGE_NAME));
    }
    return null;
}
 
Example 8
private void setColorToImage() {
    final ImageData imageData = ERDiagramActivator.getImageDescriptor(ImageKey.CHANGE_BACKGROUND_COLOR).getImageData();
    final int blackPixel = imageData.palette.getPixel(new RGB(0, 0, 0));
    imageData.transparentPixel = imageData.palette.getPixel(new RGB(255, 255, 255));
    imageData.palette.colors[blackPixel] = rgb;

    // if (this.image != null) {
    // this.image.dispose();
    // }
    image = new Image(Display.getCurrent(), imageData);

    final ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
    setImageDescriptor(descriptor);
}
 
Example 9
/**
 * @see org.eclipse.xtext.ui.IImageHelper.IImageDescriptorHelper#getImageDescriptor(org.eclipse.swt.graphics.Image)
 */
@Override
public ImageDescriptor getImageDescriptor(final Image image) {
	for (final Map.Entry<ImageDescriptor, Image> entry : registry.entrySet()) {
		if (entry.getValue().equals(image)) { return entry.getKey(); }
	}
	final ImageDescriptor newDescriptor = ImageDescriptor.createFromImage(image);
	registry.put(newDescriptor, image);
	return newDescriptor;

}
 
Example 10
Source Project: sarl   File: SARLLabelProvider.java    License: Apache License 2.0 5 votes vote down vote up
/** Invoked when an image descriptor cannot be found.
 *
 * @param params the parameters given to the method polymorphic dispatcher.
 * @param exception the cause of the error.
 * @return the image descriptor for the error.
 */
protected ImageDescriptor handleImageDescriptorError(Object[] params, Throwable exception) {
	if (exception instanceof NullPointerException) {
		final Object defaultImage = getDefaultImage();
		if (defaultImage instanceof ImageDescriptor) {
			return (ImageDescriptor) defaultImage;
		}
		if (defaultImage instanceof Image) {
			return ImageDescriptor.createFromImage((Image) defaultImage);
		}
		return super.imageDescriptor(params[0]);
	}
	return Exceptions.throwUncheckedException(exception);
}
 
Example 11
public FlashTask(final IDialogPage page, final int delay, final Image... images) {
  this.page = page;
  this.delay = delay;

  control = page.getControl();
  display = page.getControl().getDisplay();
  states = new ImageDescriptor[images.length];

  for (int i = 0; i < states.length; i++)
    states[i] = ImageDescriptor.createFromImage(images[i]);
}
 
Example 12
Source Project: n4js   File: Node.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Override
default ImageDescriptor getImageDescriptor(final Object object) {
	final Image image = getImage();
	return null == image ? null : ImageDescriptor.createFromImage(image);
}
 
Example 13
private void initializeOverlayImageDescriptor() {
	if (overlayImageDesc == null) {
		Image image = ImageUtils.getImage(ImageUtils.IN_COMP_SET_OVERLAY_IMAGE_NAME);
		overlayImageDesc = ImageDescriptor.createFromImage(image);
	}
}
 
Example 14
Source Project: saros   File: ImageManager.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an image descriptor for the given image.
 *
 * @param image image to obtain the image descriptor for, not <code>null</code>
 * @return the image descriptor
 */
public static ImageDescriptor getImageDescriptor(final Image image) {
  return ImageDescriptor.createFromImage(image);
}