This repository has been archived on 2025-12-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tdi-studio-se/org.talend.componentdesigner/src/org/talend/componentdesigner/ImageLib.java
mhirt 021fc8d03b Update copyright to 2012
git-svn-id: http://talendforge.org/svn/tos/trunk@77219 f6f1c999-d317-4740-80b0-e6d1abc6f99e
2012-01-24 01:14:15 +00:00

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...
}
}
}