Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / 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.clientcontroller.manager;
18
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
22 import org.osgi.framework.Bundle;
23
24 import java.net.URL;
25
26 import oic.simulator.clientcontroller.Activator;
27 import oic.simulator.clientcontroller.utils.Constants;
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         // Log View related icons
54         r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
55                 .getEntry("/icons/debug_log.gif")));
56         r.put(Constants.INFO_LOG, ImageDescriptor.createFromURL(bundle
57                 .getEntry("/icons/info_log.gif")));
58         r.put(Constants.WARNING_LOG, ImageDescriptor.createFromURL(bundle
59                 .getEntry("/icons/warning_log.gif")));
60         r.put(Constants.ERROR_LOG, ImageDescriptor.createFromURL(bundle
61                 .getEntry("/icons/error_log.gif")));
62         r.put(Constants.UNKNOWN_LOG, ImageDescriptor.createFromURL(bundle
63                 .getEntry("/icons/unknown_log.gif")));
64     }
65
66     public static Image getImage(String imagePath) {
67         if (null == imagePath || imagePath.length() < 1) {
68             return null;
69         }
70         URL imageURL = Activator.getDefault().getBundle().getEntry(imagePath);
71         ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
72         return descriptor.createImage();
73     }
74 }