View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.util;
16  
17  import java.util.Locale;
18  import javax.swing.*;
19  
20  /**
21   * Object of this class represents locale
22   * with extended functionality/properties.
23   * <p/>
24   * Created date: Jun 2, 2007
25   *
26   * @author Yevgeny Nyden
27   */
28  public class LocaleExt {
29  
30    /** Reference to the locale object. */
31    private Locale locale;
32  
33    /** Language display name. */
34    private String displayLanguage;
35  
36    /** Enabled icon to represent this locale. */
37    private ImageIcon iconEnabled;
38  
39    /** Disabled icon to represent this locale. */
40    private ImageIcon iconDisabled;
41  
42    /**
43     * Constructor.
44     *
45     * @param language        Locale language.
46     * @param country         Locale country.
47     * @param displayLanguage Language display name.
48     */
49    public LocaleExt(String language,
50                     String country,
51                     String displayLanguage) {
52      this.locale = new Locale(language, country);
53      this.displayLanguage = displayLanguage;
54      this.iconEnabled = Utilities.createImage(language);
55      this.iconDisabled = Utilities.createImage(language + "-dis");
56    }
57  
58    /**
59     * Getter for the reference to the locale object.
60     *
61     * @return Reference to the locale object.
62     */
63    public Locale getLocale() {
64      return locale;
65    }
66  
67    /**
68     * Getter for the language display name.
69     *
70     * @return Language display name.
71     */
72    public String getDisplayLanguage() {
73      return displayLanguage;
74    }
75  
76    /**
77     * Gets the enabled icon that represents this locale.
78     *
79     * @return Enabled icon that represents this locale.
80     */
81    public ImageIcon getEnabledIcon() {
82      return iconEnabled;
83    }
84  
85    /**
86     * Gets the disabled icon that represents this locale.
87     *
88     * @return Disabled icon that represents this locale.
89     */
90    public ImageIcon getDisabledIcon() {
91      return iconDisabled;
92    }
93  
94    /** {@inheritDoc} */
95    public boolean equals(Object o) {
96      if (this == o) {
97        return true;
98      }
99      if (o == null || getClass() != o.getClass()) {
100       return false;
101     }
102     final LocaleExt localeExt = (LocaleExt) o;
103     return locale.equals(localeExt.locale);
104   }
105 
106   /** {@inheritDoc} */
107   public int hashCode() {
108     return locale.hashCode();
109   }
110 
111   /** {@inheritDoc} */
112   public String toString() {
113     return displayLanguage;
114   }
115 
116 }