|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.s60tools.ui; |
|
18 |
|
19 import org.eclipse.jface.resource.ImageDescriptor; |
|
20 import org.eclipse.swt.graphics.GC; |
|
21 import org.eclipse.swt.graphics.Image; |
|
22 |
|
23 import com.nokia.s60tools.ui.internal.S60ToolsUiPlugin; |
|
24 |
|
25 /** |
|
26 * Miscellaneous utility methods related to UI. |
|
27 */ |
|
28 public class UiUtils { |
|
29 |
|
30 /** |
|
31 * Empty banner image name. |
|
32 */ |
|
33 public static String NOKIA_TOOLS_BANNER = "empty_banner.png"; //$NON-NLS-1$ |
|
34 |
|
35 /** |
|
36 * Method for retrieving wizard banner background for the given icon. |
|
37 * @param toolWizardIcon Tool's wizard icon to be added on top of background banner. |
|
38 * @return given icon with the wizard banner background |
|
39 */ |
|
40 public static ImageDescriptor getBannerImageDescriptor(ImageDescriptor toolWizardIcon) { |
|
41 |
|
42 // Getting background image. |
|
43 ImageDescriptor bannerDesc = S60ToolsUiPlugin.getImageDescriptorForKey(NOKIA_TOOLS_BANNER); |
|
44 |
|
45 // If icon is null, return only the banner |
|
46 if(toolWizardIcon == null) |
|
47 return bannerDesc; |
|
48 |
|
49 Image bannerImage = bannerDesc.createImage(); |
|
50 Image iconImage = toolWizardIcon.createImage(); |
|
51 |
|
52 GC imageGC = new GC(bannerImage); |
|
53 |
|
54 // Draw icon over the banner, in the middle |
|
55 imageGC.drawImage(iconImage, |
|
56 bannerImage.getBounds().width / 2 - iconImage.getBounds().width / 2, |
|
57 bannerImage.getBounds().height / 2 - iconImage.getBounds().height / 2); |
|
58 |
|
59 ImageDescriptor finalDesc = ImageDescriptor.createFromImageData(bannerImage.getImageData()); |
|
60 |
|
61 // Dispose graphics |
|
62 imageGC.dispose(); |
|
63 bannerImage.dispose(); |
|
64 iconImage.dispose(); |
|
65 |
|
66 return finalDesc; |
|
67 } |
|
68 } |