|
14 | 14 | package org.eclipse.swt.internal;
|
15 | 15 |
|
16 | 16 | import java.util.*;
|
| 17 | +import java.util.concurrent.*; |
17 | 18 |
|
18 | 19 | import org.eclipse.swt.graphics.*;
|
19 | 20 | import org.eclipse.swt.widgets.*;
|
|
26 | 27 | * take the provided values for the zoom into consideration and return scaled variant of a font if necessary.
|
27 | 28 | */
|
28 | 29 | public class SWTFontProvider {
|
29 |
| - private static Map<Device, SWTFontRegistry> fontRegistries = new HashMap<>(); |
| 30 | + private static final Map<Device, SWTFontRegistry> fontRegistries = new ConcurrentHashMap<>(); |
30 | 31 |
|
31 | 32 | private static SWTFontRegistry getFontRegistry(Device device) {
|
32 | 33 | return fontRegistries.computeIfAbsent(device, SWTFontProvider::newFontRegistry);
|
33 | 34 | }
|
34 | 35 |
|
| 36 | + /** |
| 37 | + * Returns the system font for the given device at the specified zoom. |
| 38 | + * |
| 39 | + * <b>Note:</b> This operation is not thread-safe. It must thus always be called |
| 40 | + * from the same thread for the same device, such as the display's UI thread. |
| 41 | + * |
| 42 | + * @param device the device to retrieve the font for, must not be {@code null} |
| 43 | + * @param zoom the zoom for which the font shall be scaled |
| 44 | + */ |
35 | 45 | public static Font getSystemFont(Device device, int zoom) {
|
36 | 46 | return getFontRegistry(device).getSystemFont(zoom);
|
37 | 47 | }
|
38 | 48 |
|
| 49 | + /** |
| 50 | + * Returns the font with the given font data for the given device at the |
| 51 | + * specified zoom. |
| 52 | + * |
| 53 | + * <b>Note:</b> This operation is not thread-safe. It must thus always be called |
| 54 | + * from the same thread for the same device, such as the display's UI thread. |
| 55 | + * |
| 56 | + * @param device the device to retrieve the font for, must not be {@code null} |
| 57 | + * @param fontData the data for the font to retrieve, must not be {@code null} |
| 58 | + * @param zoom the zoom for which the font shall be scaled |
| 59 | + */ |
39 | 60 | public static Font getFont(Device device, FontData fontData, int zoom) {
|
40 | 61 | return getFontRegistry(device).getFont(fontData, zoom);
|
41 | 62 | }
|
42 | 63 |
|
| 64 | + /** |
| 65 | + * Disposes the font registry for the given device, if one exists. |
| 66 | + * |
| 67 | + * @param device the device to dispose the font registry for, must not be |
| 68 | + * {@code null} |
| 69 | + */ |
43 | 70 | public static void disposeFontRegistry(Device device) {
|
44 | 71 | SWTFontRegistry fontRegistry = fontRegistries.remove(device);
|
45 | 72 | if (fontRegistry != null) {
|
|
0 commit comments