KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > bindings > keys > formatting > KeyFormatterFactory


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  *******************************************************************************/

11
12 package org.eclipse.jface.bindings.keys.formatting;
13
14
15
16 /**
17  * <p>
18  * A cache for formatters. It keeps a few instances of pre-defined instances of
19  * <code>IKeyFormatter</code> available for use. It also allows the default
20  * formatter to be changed.
21  * </p>
22  *
23  * @since 3.1
24  * @see org.eclipse.jface.bindings.keys.formatting.IKeyFormatter
25  */

26 public final class KeyFormatterFactory {
27
28     /**
29      * The formatter that renders key bindings in a platform-dependent manner.
30      */

31     private static final IKeyFormatter FORMAL_KEY_FORMATTER = new FormalKeyFormatter();
32
33     /**
34      * The formatter that renders key bindings in a form similar to XEmacs
35      */

36     private static final IKeyFormatter EMACS_KEY_FORMATTER = new EmacsKeyFormatter();
37
38     /**
39      * The default formatter. This is normally the formal key formatter, but can
40      * be changed by users of this API.
41      */

42     private static IKeyFormatter defaultKeyFormatter = FORMAL_KEY_FORMATTER;
43
44     /**
45      * An accessor for the current default key formatter.
46      *
47      * @return The default formatter; never <code>null</code>.
48      */

49     public static final IKeyFormatter getDefault() {
50         return defaultKeyFormatter;
51     }
52
53     /**
54      * Provides an instance of <code>EmacsKeyFormatter</code>.
55      *
56      * @return The Xemacs formatter; never <code>null</code>.
57      */

58     public static final IKeyFormatter getEmacsKeyFormatter() {
59         return EMACS_KEY_FORMATTER;
60     }
61
62     /**
63      * Provides an instance of <code>FormalKeyFormatter</code>.
64      *
65      * @return The formal formatter; never <code>null</code>.
66      */

67     public static final IKeyFormatter getFormalKeyFormatter() {
68         return FORMAL_KEY_FORMATTER;
69     }
70
71     /**
72      * Sets the default key formatter.
73      *
74      * @param defaultKeyFormatter
75      * the default key formatter. Must not be <code>null</code>.
76      */

77     public static final void setDefault(final IKeyFormatter defaultKeyFormatter) {
78         if (defaultKeyFormatter == null) {
79             throw new NullPointerException JavaDoc();
80         }
81
82         KeyFormatterFactory.defaultKeyFormatter = defaultKeyFormatter;
83     }
84
85     /**
86      * This class should not be instantiated.
87      */

88     private KeyFormatterFactory() {
89         // Not to be constructred.
90
}
91 }
92
Popular Tags