KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > workbench > localization > LocaleModel


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.workbench.localization;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Locale JavaDoc;
20
21 import org.apache.tapestry.form.IPropertySelectionModel;
22
23 /**
24  * @author Howard Lewis Ship
25  */

26
27 public class LocaleModel implements IPropertySelectionModel
28 {
29     private Locale JavaDoc locale;
30
31     private List JavaDoc locales = new ArrayList JavaDoc();
32
33     public LocaleModel(Locale JavaDoc locale)
34     {
35         this.locale = locale;
36     }
37
38     public void add(Locale JavaDoc locale)
39     {
40         locales.add(locale);
41     }
42
43     private Locale JavaDoc get(int index)
44     {
45         return (Locale JavaDoc) locales.get(index);
46     }
47
48     public String JavaDoc getLabel(int index)
49     {
50         return get(index).getDisplayName(locale);
51     }
52
53     public int getOptionCount()
54     {
55         return locales.size();
56     }
57
58     public Object JavaDoc getOption(int index)
59     {
60         return locales.get(index);
61     }
62
63     /**
64      * Returns the String version of the integer index.
65      */

66
67     public String JavaDoc getValue(int index)
68     {
69         return Integer.toString(index);
70     }
71
72     public Object JavaDoc translateValue(String JavaDoc value)
73     {
74         int index = Integer.parseInt(value);
75
76         return locales.get(index);
77     }
78 }
Popular Tags