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 java.util.Locale;
19
20 import net.sf.jguiraffe.di.BeanContext;
21 import net.sf.jguiraffe.di.ClassLoaderProvider;
22 import net.sf.jguiraffe.gui.builder.Builder;
23 import net.sf.jguiraffe.gui.builder.action.ActionStore;
24 import net.sf.jguiraffe.gui.builder.utils.GUISynchronizer;
25 import net.sf.jguiraffe.gui.builder.utils.MessageOutput;
26 import net.sf.jguiraffe.gui.builder.window.Window;
27 import net.sf.jguiraffe.resources.Message;
28 import net.sf.jguiraffe.resources.ResourceManager;
29 import net.sf.jguiraffe.transform.TransformerContext;
30
31 import org.apache.commons.configuration.Configuration;
32
33 /**
34 * <p>
35 * Definition of an interface for accessing application global information.
36 * </p>
37 * <p>
38 * This interface defines a context of the actual running application. This
39 * context stores some important information and helper objects that are usually
40 * needed by many components in the application. The main application class of
41 * this framework will provide access to the global context object so the
42 * information stored here can be obtained from everywhere.
43 * </p>
44 *
45 * @author Oliver Heger
46 * @version $Id: ApplicationContext.java 205 2012-01-29 18:29:57Z oheger $
47 */
48 public interface ApplicationContext extends TransformerContext
49 {
50 /**
51 * Allows to set the current locale. This locale can be used for
52 * internationalization purposes, e.g. for resolving resources.
53 *
54 * @param locale the locale of the actual user
55 */
56 void setLocale(Locale locale);
57
58 /**
59 * Sets the resource manager. All accesses to system resources are performed
60 * using this object.
61 *
62 * @param rm the resource manager to use
63 */
64 void setResourceManager(ResourceManager rm);
65
66 /**
67 * Returns a reference to the configuration data of the running application.
68 * All configuration information can be obtained using this object.
69 *
70 * @return the global configuration object
71 */
72 Configuration getConfiguration();
73
74 /**
75 * Sets the global configuration object of this application.
76 *
77 * @param configuration the configuration object
78 */
79 void setConfiguration(Configuration configuration);
80
81 /**
82 * Returns the application global <code>BeanContext</code>. This is the
83 * main entry point into the <em>dependency injection</em> framework. From
84 * this object the globally defined beans can be obtained.
85 *
86 * @return the global bean context
87 */
88 BeanContext getBeanContext();
89
90 /**
91 * Returns the <code>ClassLoaderProvider</code> to be used.
92 *
93 * @return the <code>ClassLoaderProvider</code>
94 */
95 ClassLoaderProvider getClassLoaderProvider();
96
97 /**
98 * Sets the <code>ClassLoaderProvider</code> to be used. This object is
99 * consulted when a class is to be resolved by name.
100 *
101 * @param provider the class loader provider to be used
102 */
103 void setClassLoaderProvider(ClassLoaderProvider provider);
104
105 /**
106 * Returns a reference to the object for displaying messages. This object
107 * can be used to create message boxes.
108 *
109 * @return the object for displaying messages
110 */
111 MessageOutput getMessageOutput();
112
113 /**
114 * Sets the message output object to be used by this application.
115 *
116 * @param msg the new <code>MessageOutput</code> object
117 */
118 void setMessageOutput(MessageOutput msg);
119
120 /**
121 * A convenience method for displaying a message box. This method invokes
122 * the application's associated <code>MessageOutput</code> object. Before
123 * that the passed in resource IDs (which can be either resource IDs or
124 * instances of the {@link net.sf.jguiraffe.resources.Message Message}
125 * class) will be resolved.
126 *
127 * @param resMsg the resource defining the message to be displayed
128 * @param resTitle the resource defining the message box's title (can be
129 * <b>null</b>)
130 * @param msgType the message type (one of the <code>MESSAGE_XXX</code>
131 * constants of <code>MessageOutput</code>)
132 * @param btnType the button type (one of the <code>BTN_XXX</code> constants
133 * of <code>MessageOutput</code>)
134 * @return the message box's return value (one of the <code>RET_XXX</code>
135 * constants of <code>MessageOutput</code>)
136 * @see net.sf.jguiraffe.gui.builder.utils.MessageOutput
137 */
138 int messageBox(Object resMsg, Object resTitle, int msgType, int btnType);
139
140 /**
141 * Returns the GUI synchronizer. This object is needed for updating the GUI
142 * in a different thread than the main event dispatch thread.
143 *
144 * @return the <code>GUISynchronizer</code> object
145 */
146 GUISynchronizer getGUISynchronizer();
147
148 /**
149 * Returns the application's main window.
150 *
151 * @return the main window of this application
152 */
153 Window getMainWindow();
154
155 /**
156 * Allows to set the application's main window.
157 *
158 * @param mainWindow the new main window
159 */
160 void setMainWindow(Window mainWindow);
161
162 /**
163 * Returns a new <code>{@link Builder}</code> instance. This instance can
164 * be used for processing a builder definition file. Note that the returned
165 * <code>Builder</code> object should only be used by a single thread.
166 *
167 * @return the new <code>Builder</code> instance
168 */
169 Builder newBuilder();
170
171 /**
172 * Returns an initialized <code>ApplicationBuilderData</code> object that
173 * can be used for calling the GUI builder. Most of the properties of the
174 * returned object are already set to default values, so only specific
175 * settings must be performed.
176 *
177 * @return an initialized GUI builder parameter object
178 */
179 ApplicationBuilderData initBuilderData();
180
181 /**
182 * Convenience method for looking up a resource specified as group and
183 * resource ID.
184 *
185 * @param groupID the resource group ID
186 * @param resID the resource ID
187 * @return the found resource
188 * @throws java.util.MissingResourceException if the resource cannot be found
189 */
190 Object getResource(Object groupID, Object resID);
191
192 /**
193 * Convenience method for looking up a resource that is specified as a
194 * <code>Message</code> object.
195 *
196 * @param msg the resource definition (must not be <b>null</b>)
197 * @return the found resource
198 * @throws java.util.MissingResourceException if the resource cannot be found
199 * @throws IllegalArgumentException if then message is undefined
200 */
201 Object getResource(Message msg);
202
203 /**
204 * Convenience method for looking up a resource. The passed in object is
205 * checked to be an instance of
206 * {@link net.sf.jguiraffe.resources.Message Message}. If
207 * this is the case, the resource group and the resource ID are extracted
208 * from this object. Otherwise the passed in object is interpreted as
209 * resource ID and the default resource group will be used.
210 *
211 * @param resID the resource ID
212 * @return the found resource
213 * @throws java.util.MissingResourceException if the resource cannot be found
214 */
215 Object getResource(Object resID);
216
217 /**
218 * Convenience method for looking up the text of a resource specified as
219 * group and resource ID.
220 *
221 * @param groupID the resource group ID
222 * @param resID the resource ID
223 * @return the found resource text
224 * @throws java.util.MissingResourceException if the resource cannot be found
225 */
226 String getResourceText(Object groupID, Object resID);
227
228 /**
229 * Convenience method for looking up the text of a resource specified as a
230 * <code>Message</code> object.
231 *
232 * @param msg defines the resource (must not be <b>null</b>)
233 * @return the found resource
234 * @throws java.util.MissingResourceException if the resource cannot be found
235 * @throws IllegalArgumentException if the message is undefined
236 */
237 String getResourceText(Message msg);
238
239 /**
240 * Convenience method for looking up the text of a specified resource. This
241 * method works analogous to <code>getResourceText(Object)</code>,
242 * especially the passed in object can be an instance of
243 * <code>{@link net.sf.jguiraffe.resources.Message Message}</code>.
244 *
245 * @param resID defines the requested resource
246 * @return the found resource
247 * @throws java.util.MissingResourceException if the resource cannot be found
248 */
249 String getResourceText(Object resID);
250
251 /**
252 * Returns the application's <code>ActionStore</code>.
253 *
254 * @return the application's action store
255 */
256 ActionStore getActionStore();
257
258 /**
259 * Sets the application's <code>ActionStore</code>. This object contains
260 * the definitions for all top level actions known to the application.
261 *
262 * @param actionStore the new action store
263 */
264 void setActionStore(ActionStore actionStore);
265
266 /**
267 * Sets the value of a typed property. With this method properties can be
268 * set that can later be queried using the {@link #getTypedProperty(Class)}
269 * method. This provides type-safe access to arbitrary properties. A use
270 * case for this method is the storage of application-global data in the
271 * {@code ApplicationContext}. All components that have access to an {@code
272 * ApplicationContext} can also obtain or manipulate the data stored in
273 * these properties. Because the {@code ApplicationContext} can be accessed
274 * from multiple threads (e.g. the event dispatch thread and the worker
275 * thread used by the application to execute background tasks) an
276 * implementation should ensure a proper synchronization. A typed property
277 * can be cleared by passing the value <b>null</b>. The property class must
278 * not be <b>null</b>, otherwise an exception is thrown.
279 *
280 * @param <T> the type of the property
281 * @param propCls the property class
282 * @param value the new value for this property
283 * @throws IllegalArgumentException if the property class is <b>null</b>
284 */
285 <T> void setTypedProperty(Class<T> propCls, T value);
286 }