1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.app;
17
18 import net.sf.jguiraffe.resources.Message;
19
20 /**
21 * <p>
22 * A class defining constants for default resources provided by the application
23 * framework.
24 * </p>
25 * <p>
26 * Some components of the <em>JGUIraffe</em> library can produce messages
27 * visible to the end user. The messages are defined as resource IDs, so they
28 * can be translated into different languages. This class defines constants for
29 * these messages. They correspond to resource keys used by the default
30 * application resource bundle shipped with the library.
31 * </p>
32 * <p>
33 * Typically a concrete application can use this default messages. It is also
34 * possible to override them with custom resource IDs. The message producing
35 * components typically allow specifying custom resource IDs.
36 * </p>
37 *
38 * @author Oliver Heger
39 * @version $Id: ApplicationResources.java 205 2012-01-29 18:29:57Z oheger $
40 */
41 public final class ApplicationResources
42 {
43 /**
44 * Constant for the name of the resource group used for the
45 * application-related resources.
46 */
47 public static final String APPLICATION_RESOURCE_GROUP = "application";
48
49 /**
50 * Private constructor so that no instances can be created.
51 */
52 private ApplicationResources()
53 {
54 }
55
56 /**
57 * <p>
58 * An enumeration class defining the keys of all resources contained within
59 * the <em>application</em> default resource bundle.
60 * </p>
61 *
62 * @author Oliver Heger
63 * @version $Id: ApplicationResources.java 205 2012-01-29 18:29:57Z oheger $
64 */
65 public static enum Keys
66 {
67 /** The message of the application exit prompt dialog. */
68 EXIT_PROMPT_MSG,
69
70 /** The title of the application exit prompt dialog. */
71 EXIT_PROMPT_TIT,
72
73 /** The standard text for the exit action. */
74 EXIT_ACTION_TEXT,
75
76 /** The standard tool tip for the exit action. */
77 EXIT_ACTION_TOOLTIP,
78
79 /** The standard mnemonic for the exit action. */
80 EXIT_ACTION_MNEMO
81 }
82
83 /**
84 * A convenience method for generating the resource ID for the specified
85 * enumeration literal. The literals cannot be passed directly to a resource
86 * manager. Rather, their name has to be extracted. This is done by this
87 * method.
88 *
89 * @param key the key (must not be <b>null</b>)
90 * @return the corresponding resource ID
91 * @throws IllegalArgumentException if the key is <b>null</b>
92 */
93 public static Object resourceID(Keys key)
94 {
95 if (key == null)
96 {
97 throw new IllegalArgumentException("Resource key must not be null!");
98 }
99 return key.name();
100 }
101
102 /**
103 * Returns a {@code Message} object for the specified enumeration literal.
104 * This object is initialized with the default application resource group
105 * and the resource ID extracted from the literal.
106 *
107 * @param key the key (must not be <b>null</b>)
108 * @return a {@code Message} object for this key
109 * @throws IllegalArgumentException if the key is <b>null</b>
110 */
111 public static Message message(Keys key)
112 {
113 return new Message(APPLICATION_RESOURCE_GROUP, resourceID(key));
114 }
115 }