upload tizen1.0 source
[sdk/ide/common-eplugin.git] / org.tizen.common / src / org / tizen / common / util / ImageUtils.java
1 /*
2 *  Common
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: 
7 * Kangho Kim <kh5325.kim@samsung.com>
8
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 * Contributors:
22 * - S-Core Co., Ltd
23 *
24 */
25 package org.tizen.common.util;
26
27 import java.net.URL;
28
29 import org.eclipse.core.runtime.Platform;
30 import org.eclipse.core.runtime.Plugin;
31 import org.eclipse.jface.resource.ImageDescriptor;
32 import org.eclipse.swt.graphics.Image;
33 import org.eclipse.swt.graphics.ImageData;
34
35
36 public class ImageUtils {
37         // get ImageDescriptor from Plugin ID (ID -> ImageDescriptor)
38         public static ImageDescriptor getImageDescriptor(String pluginID, String filePath) {
39                 URL url = Platform.getBundle(pluginID).getEntry(filePath);
40                 return ImageDescriptor.createFromURL(url);
41         }
42
43         // get ImageDescriptor from Activator Plugin (Activator -> ImageDescriptor)
44         public static ImageDescriptor getImageDescriptor(Plugin plugin, String filePath) {
45                 URL url = plugin.getBundle().getEntry(filePath); // $NON-NLS-1$
46                 return ImageDescriptor.createFromURL(url);
47         }
48
49         // get Image from ImageDescriptor (ImageDescriptor -> Image)
50         public static Image getImage(ImageDescriptor descriptor) {
51                 return (descriptor != null) ? descriptor.createImage() : null;
52         }
53
54         // get ImageData from ImageDescriptor (ImageDescriptor -> ImageData)
55         public static ImageData getImageData(ImageDescriptor descriptor) {
56                 return (descriptor != null) ? descriptor.getImageData() : null;
57         }
58
59         // get Image from Activator Plugin (Activator -> ImageDescriptor -> Image)
60         public static Image getImage(Plugin plugin, String filePath) {
61                 ImageDescriptor descriptor = getImageDescriptor(plugin, filePath);
62                 return getImage(descriptor);
63         }
64
65         // get ImageData from Activator Plugin (Activator -> ImageDescriptor -> ImageData)
66         public static ImageData getImageData(Plugin plugin, String filePath) {
67                 ImageDescriptor descriptor = getImageDescriptor(plugin, filePath);
68                 return getImageData(descriptor);
69         }
70
71         // get Image from Plugin ID (ID -> ImageDescriptor -> Image)
72         public static Image getImage(String pluginID, String filePath) {
73                 ImageDescriptor descriptor = getImageDescriptor(pluginID, filePath);
74                 return getImage(descriptor);
75         }
76
77         // get Image from Plugin ID (ID -> ImageDescriptor -> ImageData)
78         public static ImageData getImageData(String pluginID, String filePath) {
79                 ImageDescriptor descriptor = getImageDescriptor(pluginID, filePath);
80                 return getImageData(descriptor);
81         }
82 }