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

The following examples show how to use org.eclipse.jface.resource.ImageDescriptor#createImage() . 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
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	if (input instanceof WebBrowserEditorInput) {
		WebBrowserEditorInput wbei = (WebBrowserEditorInput) input;
		initialURL = null;
		if (wbei.getURL() != null)
			initialURL = wbei.getURL().toExternalForm();
		if (webBrowser != null) {
			webBrowser.setURL(initialURL);
			site.getWorkbenchWindow().getActivePage().activate(this);
		}

		setPartName(wbei.getName());
		setTitleToolTip(wbei.getToolTipText());
		Image oldImage = image;
		ImageDescriptor id = wbei.getImageDescriptor();
		image = id.createImage();

		setTitleImage(image);
		if (oldImage != null && !oldImage.isDisposed())
			oldImage.dispose();
	}
}
 
Example 2
Source Project: n4js   File: XpectLabelProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Image getImage(Object element) {
	ImageDescriptor descriptor = getImageDescriptor(element);

	if (descriptor == null) {
		return null;
	}

	// obtain the cached image corresponding to the descriptor
	Image image = imageCache.get(descriptor);
	if (image == null) {
		image = descriptor.createImage();
		imageCache.put(descriptor, image);
	}
	return image;

}
 
Example 3
@Override
public void fill(Menu menu, int index) {
	MenuItem mi= new MenuItem(menu, SWT.RADIO, index);

	String name= fWorkingSet.getLabel();

	mi.setText("&" + fId + " " + name);  //$NON-NLS-1$  //$NON-NLS-2$
	if (fImage == null) {
		ImageDescriptor imageDescriptor= fWorkingSet.getImageDescriptor();
		if (imageDescriptor != null)
			fImage= imageDescriptor.createImage();
	}
	mi.setImage(fImage);
	mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet()));
	mi.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
			fActionGroup.setWorkingSet(fWorkingSet, true);
			manager.addRecentWorkingSet(fWorkingSet);
		}
	});
}
 
Example 4
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	setPartName(input.getName());
	
	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	FileEditorInput fileInput = (FileEditorInput) input;
	htmlUrl = fileInput.getFile().getLocation().toOSString();
}
 
Example 5
/**
 * Returns the image associated with the given image descriptor.
 * 
 * @param descriptor the image descriptor for which the registry manages an image
 * @return the image associated with the image descriptor or <code>null</code>
 *  if the image descriptor can't create the requested image.
 */
public Image get(ImageDescriptor descriptor) {
	if (descriptor == null) {
		descriptor= ImageDescriptor.getMissingImageDescriptor();
	}
		
	Image result= fRegistry.get(descriptor);
	if (result != null) {
		return result;
	}

	Assert.isTrue(fDisplay == LangUIPlugin.getStandardDisplay(), "Allocating image for wrong display"); 
	result= descriptor.createImage();
	if (result != null) {
		fRegistry.put(descriptor, result);
	}
	return result;
}
 
Example 6
public static Image getImage(final String imageName) {
    final ImageRegistry reg = getDefault().getImageRegistry();

    Image result = reg.get(imageName);

    if (result != null && !result.isDisposed()) {//prevent from bad dispose
        return result;
    }

    final ImageDescriptor descriptor = ImageDescriptor.createFromURL(getDefault().getBundle().getResource(imageName));
    if (descriptor != null) {
        result = descriptor.createImage();
    }

    reg.remove(imageName);
    if (result != null) {
        reg.put(imageName, result);
    }

    return result;
}
 
Example 7
Source Project: ermaster-b   File: TestEditor.java    License: Apache License 2.0 6 votes vote down vote up
private void initializeTitle(IEditorInput input) {

		Image oldImage = fTitleImage;
		fTitleImage = null;
		String title = ""; //$NON-NLS-1$

		if (input != null) {
			IEditorRegistry editorRegistry = PlatformUI.getWorkbench()
					.getEditorRegistry();
			IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite()
					.getId());
			ImageDescriptor imageDesc = editorDesc != null ? editorDesc
					.getImageDescriptor() : null;

			fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
			title = input.getName();
		}

		setTitleImage(fTitleImage);
		setPartName(title);

		firePropertyChange(PROP_DIRTY);

		if (oldImage != null && !oldImage.isDisposed())
			oldImage.dispose();
	}
 
Example 8
public Image getImage() {
    try {
        if (icon != null) {
            return icon;
        }
        URL imageURL = new URL(
                "platform:/plugin/org.jvoicexml.eclipse.debug.ui/icons/cview16/VoiceXMLFile.gif"); //$NON-NLS-1$
        ImageDescriptor id = ImageDescriptor.createFromURL(imageURL);
        icon = id.createImage();
        return icon;
    } catch (Exception e) {
        return super.getImage();
    }
}
 
Example 9
private Image manageImageDescriptor(ImageDescriptor descriptor) {
	Image image= fDescriptorImageMap.get(descriptor);
	if (image == null) {
		image= descriptor.createImage();
		fDescriptorImageMap.put(descriptor, image);
	}
	return image;
}
 
Example 10
private static void checkImageDescriptor( String constantValue ) {
  ImageDescriptor descriptor = Images.getImageDescriptor( constantValue );
  assertNotNull( "No image descriptor registered for: " + constantValue, descriptor );
  Image image = descriptor.createImage( false );
  assertNotNull( "Image descriptor does not return image: " + constantValue, image );
  image.dispose();
}
 
Example 11
/**
 * 根据给定的图片文件名(不带后缀)创建图片对象
 * @param ImageName
 *            图片名
 * @return 图片;
 */
private static Image createImage(ImageName imageName) {
	ImageDescriptor imageDescriptor = getImageDescriptor(imageName.value);
	if (imageDescriptor != null) {
		return imageDescriptor.createImage();
	}
	return null;
}
 
Example 12
public Image getImage(String iconLocation, String id, String isFromGit) {
	ImageDescriptor imageDescriptor = null;
	if (!Boolean.parseBoolean(isFromGit)) {
		if (iconLocation != null && !iconLocation.isEmpty()) {
			imageDescriptor =
			                  ImageDescriptor.createFromURL(FileLocator.find(Platform.getBundle(bundleID),
			                                                                 new Path(iconLocation), null));
		} else {
			imageDescriptor =
			                  ImageDescriptor.createFromURL(FileLocator.find(Platform.getBundle(Activator.PLUGIN_ID),
			                                                                 new Path("icons/plugin-icon.png"),
			                                                                 null));
		}
		return imageDescriptor.createImage();
	} else {
		try {
			String gitIconLoc =
			                    WSO2PluginListSelectionPage.tempCloneDir + File.separator + id + File.separator +
			                            "icons" + File.separator + iconLocation;
			imageDescriptor =
			                  ImageDescriptor.createFromURL(new URL(WSO2PluginConstants.FILE_PROTOCOL + gitIconLoc));
			return imageDescriptor.createImage();
		} catch (MalformedURLException e) {
			// log image cannot be found at location
			return null;
		}
	}
}
 
Example 13
Source Project: scava   File: ResourceManager.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns an {@link Image} based on the specified {@link ImageDescriptor}.
 * 
 * @param descriptor
 *            the {@link ImageDescriptor} for the {@link Image}.
 * @return the {@link Image} based on the specified {@link ImageDescriptor}.
 */
public static Image getImage(ImageDescriptor descriptor) {
	if (descriptor == null) {
		return null;
	}
	Image image = m_descriptorImageMap.get(descriptor);
	if (image == null) {
		image = descriptor.createImage();
		m_descriptorImageMap.put(descriptor, image);
	}
	return image;
}
 
Example 14
public HsImageLabel(String description, ImageDescriptor imageDescription) {
	this.description = description;
	this.imageDescription = imageDescription;
	if (imageDescription != null) {
		image = imageDescription.createImage();
	}
}
 
Example 15
/**
 * Returns the image associated with the given image descriptor.
 *
 * @param descriptor the image descriptor for which the registry manages an image,
 *  or <code>null</code> for a missing image descriptor
 * @return the image associated with the image descriptor or <code>null</code>
 *  if the image descriptor can't create the requested image.
 */
public Image get(ImageDescriptor descriptor) {
	if (descriptor == null)
		descriptor= ImageDescriptor.getMissingImageDescriptor();

	Image result= fRegistry.get(descriptor);
	if (result != null)
		return result;

	result= descriptor.createImage();
	if (result != null)
		fRegistry.put(descriptor, result);
	return result;
}
 
Example 16
private Button createFeatureButton(Composite parent,
          final AboutBundleGroupData info) {
      if (!buttonManager.add(info)) {
	return null;
}

      ImageDescriptor desc = info.getFeatureImage();
      Image featureImage = null;

      Button button = new Button(parent, SWT.FLAT | SWT.PUSH);
      button.setData(info);
      featureImage = desc.createImage();
      images.add(featureImage);
      button.setImage(featureImage);
      button.setToolTipText(info.getProviderName());
      
      button.getAccessible().addAccessibleListener(new AccessibleAdapter(){
      	/* (non-Javadoc)
	 * @see org.eclipse.swt.accessibility.AccessibleAdapter#getName(org.eclipse.swt.accessibility.AccessibleEvent)
	 */
	public void getName(AccessibleEvent e) {
		e.result = info.getProviderName();
	}
      });
      button.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
              AboutBundleGroupData[] groupInfos = buttonManager
                      .getRelatedInfos(info);
              AboutBundleGroupData selection = (AboutBundleGroupData) event.widget
                      .getData();

              AboutFeaturesDialog d = new AboutFeaturesDialog(getShell(),
                      productName, groupInfos, selection);
              d.open();
          }
      });

      return button;
  }
 
Example 17
public static Image getImage(String location) {
    Image ret = getDefault().getImageRegistry().get( location );
    if (ret == null){
        ImageDescriptor imgDesc = getImageDescriptor( location );
        if (imgDesc != null) {
            ret = imgDesc.createImage();
            getDefault().getImageRegistry().put( location, ret );
        }
    }
    return ret;
}
 
Example 18
public static Image manage(String key, ImageDescriptor desc) {
	Image image = desc.createImage();
	PLUGIN_REGISTRY.put(key, image);
	return image;
}
 
Example 19
/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
 */
public Image getImage(Object element) {
	
	ImageDescriptor descriptor = null;
	if (element instanceof JimpleOutlineObject){
		
		switch (((JimpleOutlineObject)element).getType()){
			case JimpleOutlineObject.CLASS: {
				descriptor = SootPlugin.getImageDescriptor("class_obj.gif");
				break;
			}
			case JimpleOutlineObject.INTERFACE: {
				descriptor = SootPlugin.getImageDescriptor("int_obj.gif");
				break;
			}
			case JimpleOutlineObject.PUBLIC_METHOD:{
				descriptor = SootPlugin.getImageDescriptor("public_co.gif");
				break;
			}
			case JimpleOutlineObject.PROTECTED_METHOD:{
				descriptor = SootPlugin.getImageDescriptor("protected_co.gif");
				break;
			}
			case JimpleOutlineObject.PRIVATE_METHOD:{
				descriptor = SootPlugin.getImageDescriptor("private_co.gif");
				break;
			}
			case JimpleOutlineObject.NONE_METHOD: {
				descriptor = SootPlugin.getImageDescriptor("default_co.gif");
				break;
			}
			case JimpleOutlineObject.PUBLIC_FIELD: {
				descriptor = SootPlugin.getImageDescriptor("field_public_obj.gif");
				break;
			}
			case JimpleOutlineObject.PROTECTED_FIELD: {
				descriptor = SootPlugin.getImageDescriptor("field_protected_obj.gif");
				break;
			}
			case JimpleOutlineObject.PRIVATE_FIELD: {
				descriptor = SootPlugin.getImageDescriptor("field_private_obj.gif");
				break;
			}	
			case JimpleOutlineObject.NONE_FIELD: {
				descriptor = SootPlugin.getImageDescriptor("field_default_obj.gif");
				break;
			}				
			default:{
				return null;
				
			}
		}
	}
	if (getImageCache() == null){
		setImageCache(new HashMap());
		
	}
	Image image = (Image)getImageCache().get(descriptor);
	if (image == null) {
	  	image = descriptor.createImage();
	   	getImageCache().put(descriptor, image);
           
	}
	

	return image;
	
	
	
}
 
Example 20
Source Project: elexis-3-core   File: UiDesk.java    License: Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Return an image with a specified name. This method is applicable for images only, that has
 * been registered beforehand. The default images resp. icons are delivered by a separate plugin
 * (in the core this is ch.elexis.core.ui.icons)
 * 
 * @param name
 *            the name of the image to retrieve
 * @return the Image or null if no such image was found
 * 
 * @since 3.0.0 will only serve pre-registered icons, <b>default icons have been outsourced</b>
 */
public static Image getImage(String name){
	Image ret = getImageRegistry().get(name);
	if (ret == null) {
		ImageDescriptor id = getImageRegistry().getDescriptor(name);
		if (id != null) {
			ret = id.createImage();
		}
	}
	return ret;
}