connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/mylyn/CompositeElementImageDescriptor.java
changeset 1104 e84724c7f393
equal deleted inserted replaced
1103:a5d7a2345c4a 1104:e84724c7f393
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2004, 2008 Tasktop Technologies and others.
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Tasktop Technologies - initial API and implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 package com.nokia.carbide.remoteconnections.internal.ui.mylyn;
       
    13 
       
    14 import org.eclipse.jface.resource.CompositeImageDescriptor;
       
    15 import org.eclipse.jface.resource.ImageDescriptor;
       
    16 import org.eclipse.swt.graphics.ImageData;
       
    17 import org.eclipse.swt.graphics.Point;
       
    18 
       
    19 /**
       
    20  * @author Mik Kersten
       
    21  */
       
    22 public class CompositeElementImageDescriptor extends CompositeImageDescriptor {
       
    23 
       
    24 	private final ImageData base;
       
    25 
       
    26 	private ImageData kind;
       
    27 
       
    28 	protected Point size;
       
    29 
       
    30 	public static final int OFFSET_DECORATION = 6;
       
    31 
       
    32 	static final int WIDTH_ICON = 16;
       
    33 
       
    34 	private int offset = 0;
       
    35 
       
    36 	public CompositeElementImageDescriptor(ImageDescriptor icon, ImageDescriptor overlayKind, boolean wide) {
       
    37 		this.base = getImageData(icon);
       
    38 		if (overlayKind != null) {
       
    39 			this.kind = getImageData(overlayKind);
       
    40 		}
       
    41 		int width = WIDTH_ICON;
       
    42 		if (wide) {
       
    43 			width += OFFSET_DECORATION;
       
    44 			offset = OFFSET_DECORATION;
       
    45 		}
       
    46 		this.size = new Point(width, base.height);
       
    47 	}
       
    48 
       
    49 	@Override
       
    50 	protected void drawCompositeImage(int width, int height) {
       
    51 		drawImage(base, offset, 1);
       
    52 		if (kind != null) {
       
    53 			drawImage(kind, offset + 5, 6);
       
    54 		}
       
    55 	}
       
    56 
       
    57 	private ImageData getImageData(ImageDescriptor descriptor) {
       
    58 		ImageData data = descriptor.getImageData();
       
    59 		// see bug 51965: getImageData can return null
       
    60 		if (data == null) {
       
    61 			data = DEFAULT_IMAGE_DATA;
       
    62 		}
       
    63 		return data;
       
    64 	}
       
    65 
       
    66 	@Override
       
    67 	protected Point getSize() {
       
    68 		return new Point(size.x, size.y);
       
    69 	}
       
    70 }