Mercurial > projects > dwt2
comparison org.eclipse.jface/src/org/eclipse/jface/bindings/keys/formatting/KeyFormatterFactory.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2004, 2006 IBM Corporation and others. | |
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 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
14 module org.eclipse.jface.bindings.keys.formatting.KeyFormatterFactory; | |
15 | |
16 import org.eclipse.jface.bindings.keys.formatting.FormalKeyFormatter; | |
17 import org.eclipse.jface.bindings.keys.formatting.EmacsKeyFormatter; | |
18 import org.eclipse.jface.bindings.keys.formatting.IKeyFormatter; | |
19 | |
20 import java.lang.all; | |
21 import java.util.Set; | |
22 | |
23 /** | |
24 * <p> | |
25 * A cache for formatters. It keeps a few instances of pre-defined instances of | |
26 * <code>IKeyFormatter</code> available for use. It also allows the default | |
27 * formatter to be changed. | |
28 * </p> | |
29 * | |
30 * @since 3.1 | |
31 * @see org.eclipse.jface.bindings.keys.formatting.IKeyFormatter | |
32 */ | |
33 public final class KeyFormatterFactory { | |
34 | |
35 /** | |
36 * The formatter that renders key bindings in a platform-dependent manner. | |
37 */ | |
38 private static /+const+/ IKeyFormatter FORMAL_KEY_FORMATTER; | |
39 | |
40 /** | |
41 * The formatter that renders key bindings in a form similar to XEmacs | |
42 */ | |
43 private static /+const+/ IKeyFormatter EMACS_KEY_FORMATTER; | |
44 | |
45 /** | |
46 * The default formatter. This is normally the formal key formatter, but can | |
47 * be changed by users of this API. | |
48 */ | |
49 private static IKeyFormatter defaultKeyFormatter; | |
50 | |
51 private static void check_static_init(){ | |
52 if( FORMAL_KEY_FORMATTER is null ){ | |
53 synchronized if( FORMAL_KEY_FORMATTER is null ){ | |
54 FORMAL_KEY_FORMATTER = new FormalKeyFormatter(); | |
55 EMACS_KEY_FORMATTER = new EmacsKeyFormatter(); | |
56 defaultKeyFormatter = FORMAL_KEY_FORMATTER; | |
57 } | |
58 } | |
59 } | |
60 | |
61 /** | |
62 * An accessor for the current default key formatter. | |
63 * | |
64 * @return The default formatter; never <code>null</code>. | |
65 */ | |
66 public static final IKeyFormatter getDefault() { | |
67 check_static_init(); | |
68 return defaultKeyFormatter; | |
69 } | |
70 | |
71 /** | |
72 * Provides an instance of <code>EmacsKeyFormatter</code>. | |
73 * | |
74 * @return The Xemacs formatter; never <code>null</code>. | |
75 */ | |
76 public static final IKeyFormatter getEmacsKeyFormatter() { | |
77 check_static_init(); | |
78 return EMACS_KEY_FORMATTER; | |
79 } | |
80 | |
81 /** | |
82 * Provides an instance of <code>FormalKeyFormatter</code>. | |
83 * | |
84 * @return The formal formatter; never <code>null</code>. | |
85 */ | |
86 public static final IKeyFormatter getFormalKeyFormatter() { | |
87 check_static_init(); | |
88 return FORMAL_KEY_FORMATTER; | |
89 } | |
90 | |
91 /** | |
92 * Sets the default key formatter. | |
93 * | |
94 * @param defaultKeyFormatter | |
95 * the default key formatter. Must not be <code>null</code>. | |
96 */ | |
97 public static final void setDefault(IKeyFormatter defaultKeyFormatter) { | |
98 check_static_init(); | |
99 if (defaultKeyFormatter is null) { | |
100 throw new NullPointerException(); | |
101 } | |
102 | |
103 KeyFormatterFactory.defaultKeyFormatter = defaultKeyFormatter; | |
104 } | |
105 | |
106 /** | |
107 * This class should not be instantiated. | |
108 */ | |
109 private this() { | |
110 // Not to be constructred. | |
111 } | |
112 } |