1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.eclipse.common.util; |
17 | |
|
18 | |
import org.eclipse.jface.resource.FontRegistry; |
19 | |
import org.eclipse.swt.graphics.Font; |
20 | |
import org.eclipse.swt.graphics.FontData; |
21 | |
import org.eclipse.swt.widgets.Display; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class FontManager { |
28 | 4 | protected static final FontRegistry registry = new FontRegistry(Display |
29 | |
.getCurrent(), true); |
30 | |
|
31 | |
public static Font get(final String name, final int height, final int style) { |
32 | 524 | String descriptor = getDescriptor(name, height, style); |
33 | |
Font font; |
34 | 524 | if (registry.hasValueFor(descriptor)) { |
35 | 500 | font = registry.get(descriptor); |
36 | |
} else { |
37 | 24 | FontData fontData = new FontData(name, height, style); |
38 | 24 | font = new Font(Display.getCurrent(), fontData); |
39 | 24 | registry.put(descriptor, new FontData[] { fontData }); |
40 | |
} |
41 | 524 | return font; |
42 | |
} |
43 | |
|
44 | |
protected static String getDescriptor(final String name, final int height, |
45 | |
final int style) { |
46 | 524 | return name + "_" + height + "_" + style; |
47 | |
} |
48 | |
} |