|
1 /******************************************************************************* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 * Nokia Corporation - initial implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 package org.eclipse.swt.internal.extension; |
|
13 |
|
14 import org.eclipse.swt.widgets.Display; |
|
15 import org.eclipse.swt.widgets.Internal_PackageSupport; |
|
16 |
|
17 public final class DisplayExtension extends Display { |
|
18 |
|
19 /* Image types, same values as MIDP */ |
|
20 public static final int LIST_ELEMENT = 1; |
|
21 public static final int CHOICE_GROUP_ELEMENT = 2; |
|
22 public static final int ALERT = 3; |
|
23 |
|
24 public DisplayExtension() { |
|
25 super(); |
|
26 } |
|
27 |
|
28 /** |
|
29 * Determine the best width for the given image type. |
|
30 * @param imageType |
|
31 * @return Best height or -1 if invalid image type given. |
|
32 */ |
|
33 public static int getBestImageWidth(int imageType) { |
|
34 return getBestImageSize(imageType); |
|
35 } |
|
36 |
|
37 /** |
|
38 * Determine the best height for the given image type. |
|
39 * @param imageType |
|
40 * @return Best height or -1 if invalid image type given. |
|
41 */ |
|
42 public static int getBestImageHeight(int imageType) { |
|
43 return getBestImageSize(imageType); |
|
44 } |
|
45 |
|
46 /** |
|
47 * Gets the default display instance, but does not create one if it doesn't exist. |
|
48 * @return Default display if one has been initialized otherwise null |
|
49 */ |
|
50 public static Display getDisplayInstance() { |
|
51 return Internal_PackageSupport.getDisplayInstance(); |
|
52 } |
|
53 |
|
54 private static int getBestImageSize(int imageType) { |
|
55 switch (imageType) { |
|
56 case LIST_ELEMENT: |
|
57 case CHOICE_GROUP_ELEMENT: |
|
58 return Style.pixelMetric(Style.QSTYLE_PM_SMALLICONSIZE); |
|
59 case ALERT: |
|
60 return Style.pixelMetric(Style.QSTYLE_PM_MESSAGEBOXICONSIZE); |
|
61 default: |
|
62 return -1; |
|
63 } |
|
64 } |
|
65 } |