Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / manager / ImageManager.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.serviceprovider.manager;
18
19 import java.net.URL;
20
21 import oic.simulator.serviceprovider.Activator;
22 import oic.simulator.serviceprovider.utils.Constants;
23
24 import org.eclipse.jface.resource.ImageDescriptor;
25 import org.eclipse.jface.resource.ImageRegistry;
26 import org.eclipse.swt.graphics.Image;
27 import org.osgi.framework.Bundle;
28
29 /**
30  * Class which loads the icons/images into the image registry, and has methods
31  * to handle the image related requests from other UI modules.
32  */
33 public class ImageManager {
34
35     private static ImageManager imageManager;
36
37     public static ImageManager getInstance() {
38         if (null == imageManager) {
39             imageManager = new ImageManager();
40         }
41         return imageManager;
42     }
43
44     static {
45         ImageRegistry r = Activator.getDefault().getImageRegistry();
46         Bundle bundle = Activator.getDefault().getBundle();
47
48         r.put(Constants.CHECKED, ImageDescriptor.createFromURL(bundle
49                 .getEntry("icons/checked.gif")));
50         r.put(Constants.UNCHECKED, ImageDescriptor.createFromURL(bundle
51                 .getEntry("icons/unchecked.gif")));
52
53         r.put(Constants.NOTIFY_BUTTON_UNSELECTED, ImageDescriptor
54                 .createFromURL(bundle.getEntry("icons/button_free.PNG")));
55         r.put(Constants.NOTIFY_BUTTON_SELECTED, ImageDescriptor
56                 .createFromURL(bundle.getEntry("icons/button_pressed.PNG")));
57
58         // Resource icons based on the resource type
59         r.put(Constants.SAMPLE_LIGHT, ImageDescriptor.createFromURL(bundle
60                 .getEntry("/icons/light_16x16.png")));
61
62         // Log View related icons
63         r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
64                 .getEntry("/icons/debug_log.gif")));
65         r.put(Constants.INFO_LOG, ImageDescriptor.createFromURL(bundle
66                 .getEntry("/icons/info_log.gif")));
67         r.put(Constants.WARNING_LOG, ImageDescriptor.createFromURL(bundle
68                 .getEntry("/icons/warning_log.gif")));
69         r.put(Constants.ERROR_LOG, ImageDescriptor.createFromURL(bundle
70                 .getEntry("/icons/error_log.gif")));
71         r.put(Constants.UNKNOWN_LOG, ImageDescriptor.createFromURL(bundle
72                 .getEntry("/icons/unknown_log.gif")));
73     }
74
75     public static Image getImage(String imagePath) {
76         if (null == imagePath || imagePath.length() < 1) {
77             return null;
78         }
79         URL imageURL = Activator.getDefault().getBundle().getEntry(imagePath);
80         ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
81         return descriptor.createImage();
82     }
83 }