Skip to content

Package: SWTImageHelper

SWTImageHelper

nameinstructionbranchcomplexitylinemethod
getImage(Object)
M: 3 C: 32
91%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 1 C: 8
89%
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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.edit.internal.swt;
15:
16: import java.net.MalformedURLException;
17: import java.net.URL;
18:
19: import org.eclipse.emf.common.util.URI;
20: import org.eclipse.emf.edit.provider.ComposedImage;
21: import org.eclipse.swt.graphics.Image;
22:
23: /**
24: * Helper methods for handling of SWT images.
25: */
26: public final class SWTImageHelper {
27:
28:         private SWTImageHelper() {
29:         }
30:
31:         /**
32:          * @param image an {@link URI}. {@link URL} or {@link ComposedImage} describing the {@link Image} to be retrieved
33:          *
34:          * @return the {@link Image}
35:          */
36:         public static Image getImage(Object image) {
37:•                if (ComposedImage.class.isInstance(image)) {
38:                         image = ((ComposedImage) image).getImages().get(0);
39:                 }
40:•                if (URI.class.isInstance(image)) {
41:                         try {
42:                                 image = new URL(((URI) image).toString());
43:                         } catch (final MalformedURLException ex) {
44:                                 Activator.logException(ex);
45:                         }
46:                 }
47:•                if (URL.class.isInstance(image)) {
48:                         return Activator.getImage((URL) image);
49:                 }
50:                 return null;
51:         }
52:
53: }