Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5a287ed2c6af84c23c6e990881ec2c996630e3b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
 * Copyright (c) 2004, 2013 Tasktop Technologies and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *     David Green - fix for bug 247182
 *     Frank Becker - fixes for bug 259877
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.util;

import org.eclipse.core.runtime.Platform;
import org.eclipse.mylyn.commons.ui.PlatformUiUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;

/**
 * @author Steffen Pingel
 * @deprecated use {@link PlatformUiUtil} instead.
 */
@Deprecated
public class PlatformUtil {

	private static class Eclipse36Checker {
		public static final boolean result;
		static {
			boolean methodAvailable = false;
			try {
				StyledText.class.getMethod("setTabStops", int[].class); //$NON-NLS-1$
				methodAvailable = true;
			} catch (NoSuchMethodException e) {
			}
			result = methodAvailable;
		}
	}

	/**
	 * bug 247182: file import dialog doesn't work on Mac OS X if the file extension has more than one dot.
	 */
	public static String[] getFilterExtensions(String... extensions) {
		for (int i = 0; i < extensions.length; i++) {
			String extension = extensions[i];
			if (Platform.OS_MACOSX.equals(Platform.getOS())) {
				int j = extension.lastIndexOf('.');
				if (j != -1) {
					extension = extension.substring(j);
				}
			}
			extensions[i] = "*" + extension; //$NON-NLS-1$
		}
		return extensions;
	}

	public static int getToolTipXShift() {
		if ("gtk".equals(SWT.getPlatform()) || "carbon".equals(SWT.getPlatform()) || "cocoa".equals(SWT.getPlatform())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			return -26;
		} else {
			return -23;
		}
	}

	public static int getTreeImageOffset() {
		if ("carbon".equals(SWT.getPlatform())) { //$NON-NLS-1$
			return 16;
		} else if ("cocoa".equals(SWT.getPlatform())) { //$NON-NLS-1$
			return 13;
		} else {
			return 20;
		}
	}

	public static int getIncomingImageOffset() {
		if ("carbon".equals(SWT.getPlatform())) { //$NON-NLS-1$
			return 5;
		} else if ("cocoa".equals(SWT.getPlatform())) { //$NON-NLS-1$
			return 2;
		} else {
			return 6;
		}
	}

	public static int getTreeItemSquish() {
		if ("gtk".equals(SWT.getPlatform())) { //$NON-NLS-1$
			return 8;
		} else if (isMac()) {
			return 3;
		} else {
			return 0;
		}
	}

	private static boolean isMac() {
		return "carbon".equals(SWT.getPlatform()) || "cocoa".equals(SWT.getPlatform()); //$NON-NLS-1$ //$NON-NLS-2$
	}

	public static boolean isPaintItemClippingRequired() {
		return "gtk".equals(SWT.getPlatform()); //$NON-NLS-1$
	}

	public static boolean spinnerHasNativeBorder() {
		return isMac() && !isEclipse36orLater();
	}

	private static boolean isEclipse36orLater() {
		return Eclipse36Checker.result;
	}

	public static boolean hasNarrowToolBar() {
		return Platform.WS_WIN32.equals(SWT.getPlatform());
	}

	/**
	 * Returns the width of the view menu drop-down button.
	 */
	public static int getViewMenuWidth() {
		return 32;
	}

}

Back to the top