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

The following examples show how to use org.eclipse.jface.resource.ImageDescriptor#createImage() . 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 File: WebBrowserEditor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@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 File: TestEditor.java    From ermaster-b with 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 3
Source File: XpectLabelProvider.java    From n4js with 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 4
Source File: BosArchiveImporterPlugin.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: ImageDescriptorRegistry.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
Source File: WorkingSetMenuContributionItem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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 7
Source File: HtmlBrowserEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@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 8
Source File: Activator.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
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 9
Source File: AboutDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: ImageDescriptorRegistry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 11
Source File: HsImageLabel.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public HsImageLabel(String description, ImageDescriptor imageDescription) {
	this.description = description;
	this.imageDescription = imageDescription;
	if (imageDescription != null) {
		image = imageDescription.createImage();
	}
}
 
Example 12
Source File: ResourceManager.java    From scava with 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 13
Source File: WSO2PluginSampleExt.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
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 14
Source File: XliffEditorGUIHelper.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 根据给定的图片文件名(不带后缀)创建图片对象
 * @param ImageName
 *            图片名
 * @return 图片;
 */
private static Image createImage(ImageName imageName) {
	ImageDescriptor imageDescriptor = getImageDescriptor(imageName.value);
	if (imageDescriptor != null) {
		return imageDescriptor.createImage();
	}
	return null;
}
 
Example 15
Source File: ImagesPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
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 16
Source File: RenameTypeWizardSimilarElementsPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Image manageImageDescriptor(ImageDescriptor descriptor) {
	Image image= fDescriptorImageMap.get(descriptor);
	if (image == null) {
		image= descriptor.createImage();
		fDescriptorImageMap.put(descriptor, image);
	}
	return image;
}
 
Example 17
Source File: CommonVoiceXMLBrowserTab.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 18
Source File: XtextPluginImages.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static Image manage(String key, ImageDescriptor desc) {
	Image image = desc.createImage();
	PLUGIN_REGISTRY.put(key, image);
	return image;
}
 
Example 19
Source File: JimpleOutlineLabelProvider.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @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 File: UiDesk.java    From elexis-3-core with 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;
}