KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > examples > misc > OptionsForm


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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 org.apache.myfaces.examples.misc;
17
18 import javax.faces.context.FacesContext;
19 import javax.faces.model.SelectItem;
20 import java.util.AbstractList JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Locale JavaDoc;
24
25 /**
26  * DOCUMENT ME!
27  * @author Manfred Geiler (latest modification by $Author: matzew $)
28  * @version $Revision: 1.1 $ $Date: 2005/03/24 16:47:10 $
29  */

30 public class OptionsForm
31 {
32     private static final Locale JavaDoc SPANISH = new Locale JavaDoc("es", "","");
33     private static final Locale JavaDoc CATALAN = new Locale JavaDoc("ca", "","");
34
35     private static final List JavaDoc AVAILABLE_LOCALES
36         = Arrays.asList(new Locale JavaDoc[] {Locale.ENGLISH,
37                                       Locale.CHINESE,
38                                       Locale.GERMAN,
39                                       Locale.JAPANESE,
40                                       Locale.FRENCH,
41                                       SPANISH,
42                                       CATALAN});
43
44     private Locale JavaDoc _locale = null;
45
46     public String JavaDoc getLanguage()
47     {
48         return _locale != null
49                 ? _locale.getLanguage()
50                 : FacesContext.getCurrentInstance().getViewRoot().getLocale().getLanguage();
51     }
52
53     public void setLanguage(String JavaDoc language)
54     {
55         _locale = new Locale JavaDoc(language);
56     }
57
58     public Locale JavaDoc getLocale()
59     {
60         return _locale;
61     }
62
63     public List JavaDoc getAvailableLanguages()
64     {
65         return new AbstractList JavaDoc()
66         {
67             public Object JavaDoc get(int index)
68             {
69                 Locale JavaDoc locale = (Locale JavaDoc)AVAILABLE_LOCALES.get(index);
70                 String JavaDoc language = locale.getDisplayLanguage(locale);
71                 return new SelectItem(locale.getLanguage(), language, language);
72             }
73
74             public int size()
75             {
76                 return AVAILABLE_LOCALES.size();
77             }
78         };
79     }
80
81
82 }
83
Popular Tags