Skip to content

Package: RCPImageRegistryService

RCPImageRegistryService

nameinstructionbranchcomplexitylinemethod
RCPImageRegistryService()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getImage(Bundle, String)
M: 0 C: 34
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
getImage(URL)
M: 5 C: 23
82%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 6
86%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.util.swt;
15:
16: import java.net.URL;
17:
18: import org.eclipse.emf.ecp.view.spi.util.swt.ImageRegistryService;
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: /**
25: * An {@link ImageRegistryService} which expects exactly one UI Thread.
26: *
27: * @author Eugen Neufeld
28: *
29: */
30: public class RCPImageRegistryService implements ImageRegistryService {
31:
32:         private ImageRegistry registry;
33:
34:         @Override
35:         public Image getImage(Bundle bundle, String path) {
36:•                if (registry == null) {
37:                         registry = new ImageRegistry();
38:                 }
39:                 Image image = registry.get(path);
40:•                if (image == null) {
41:                         final URL url = bundle.getResource(path);
42:•                        if (url == null) {
43:                                 return null;
44:                         }
45:                         image = ImageDescriptor.createFromURL(url).createImage();
46:                         registry.put(path, image);
47:                 }
48:                 return image;
49:         }
50:
51:         @Override
52:         public Image getImage(URL url) {
53:•                if (registry == null) {
54:                         registry = new ImageRegistry();
55:                 }
56:                 Image image = registry.get(url.toString());
57:•                if (image == null) {
58:                         image = ImageDescriptor.createFromURL(url).createImage();
59:                         registry.put(url.toString(), image);
60:                 }
61:                 return image;
62:         }
63:
64: }