git-svn-id: http://talendforge.org/svn/tos/trunk@77219 f6f1c999-d317-4740-80b0-e6d1abc6f99e
140 lines
4.2 KiB
Java
140 lines
4.2 KiB
Java
// ============================================================================
|
|
//
|
|
// Copyright (C) 2006-2012 Talend Inc. - www.talend.com
|
|
//
|
|
// This source code is available under agreement available at
|
|
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
|
//
|
|
// You should have received a copy of the agreement
|
|
// along with this program; if not, write to Talend SA
|
|
// 9 rue Pages 92150 Suresnes, France
|
|
//
|
|
// ============================================================================
|
|
package org.talend.componentdesigner;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
|
|
import org.eclipse.jface.resource.ImageDescriptor;
|
|
import org.eclipse.jface.resource.ImageRegistry;
|
|
import org.eclipse.swt.graphics.Image;
|
|
|
|
/**
|
|
* Store and lazy load Imaged. <br/>
|
|
*
|
|
* $Id: ImageLib.java,v 1.5 2007/04/05 05:33:07 pub Exp $
|
|
*
|
|
*/
|
|
public class ImageLib {
|
|
|
|
private static ImageRegistry imageRegistry;
|
|
|
|
private static URL iconURL;
|
|
|
|
public static final String COMPONENT_DEFAULT = "defaultcomponent_icon32.png"; //$NON-NLS-1$
|
|
|
|
public static final String COPYCOMPONENT_ACTION = "copycomponent_action.gif"; //$NON-NLS-1$
|
|
|
|
public static final String EDITCOMPONENT_ACTION = "editcomponent_action.gif"; //$NON-NLS-1$
|
|
|
|
public static final String NEWCOMPONENT_WIZARD = "newcomponent_wiz.png"; //$NON-NLS-1$
|
|
|
|
public static final String JAR_OBJ = "jar_obj.gif"; //$NON-NLS-1$
|
|
|
|
public static final String PM_OBJ = "pm_obj.gif"; //$NON-NLS-1$
|
|
|
|
/**
|
|
* get <code>ImageDescriptor</code> with special imageName.
|
|
*
|
|
* @param imageName
|
|
* @return
|
|
*/
|
|
public static ImageDescriptor getImageDescriptor(String imageName) {
|
|
if (imageRegistry == null) {
|
|
initialize();
|
|
}
|
|
ImageDescriptor imageDesc = imageRegistry.getDescriptor(imageName);
|
|
if (imageDesc == null) {
|
|
addImage(imageName);
|
|
return imageRegistry.getDescriptor(imageName);
|
|
}
|
|
return imageDesc;
|
|
}
|
|
|
|
/**
|
|
* get <code>Image</code> with special imageName.
|
|
*
|
|
* @param imageName
|
|
* @return
|
|
*/
|
|
public static Image getImage(String imageName) {
|
|
if (imageRegistry == null) {
|
|
initialize();
|
|
}
|
|
if (imageRegistry == null) {
|
|
return null;
|
|
}
|
|
Image image = imageRegistry.get(imageName);
|
|
if (image == null) {
|
|
addImage(imageName);
|
|
return imageRegistry.get(imageName);
|
|
}
|
|
return image;
|
|
}
|
|
|
|
/**
|
|
* initialize the fieds.
|
|
*/
|
|
static void initialize() {
|
|
ComponentDesigenerPlugin amcPlugin = ComponentDesigenerPlugin.getDefault();
|
|
if (amcPlugin != null) {
|
|
imageRegistry = amcPlugin.getImageRegistry();
|
|
iconURL = getIconLocation();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get current icons URL.
|
|
*
|
|
* @return
|
|
*/
|
|
private static URL getIconLocation() {
|
|
URL installURL = ComponentDesigenerPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$
|
|
try {
|
|
return new URL(installURL, "icons/"); //$NON-NLS-1$
|
|
} catch (MalformedURLException e) {
|
|
// e.printStackTrace();
|
|
org.talend.componentdesigner.exception.ExceptionHandler.process(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static InputStream getImageInputStream(String imageName) {
|
|
InputStream inputStream = null;
|
|
try {
|
|
inputStream = ComponentDesigenerPlugin.getDefault().getBundle().getEntry("/icons/" + imageName).openStream(); //$NON-NLS-1$
|
|
} catch (IOException e) {
|
|
// e.printStackTrace();
|
|
org.talend.componentdesigner.exception.ExceptionHandler.process(e);
|
|
}
|
|
return inputStream;
|
|
}
|
|
|
|
/**
|
|
* store the image with special name(the name with suffix,such as "sample.gif").
|
|
*
|
|
* @param iconName
|
|
*/
|
|
public static void addImage(String iconName) {
|
|
try {
|
|
ImageDescriptor descriptor = ImageDescriptor.createFromURL(new URL(iconURL, iconName));
|
|
imageRegistry.put(iconName, descriptor);
|
|
} catch (MalformedURLException e) {
|
|
// skip, but try to go on to the next one...
|
|
}
|
|
}
|
|
|
|
}
|