OSDN Git Service

b9e6358dfcd689601923a9904ea6535c546a27b6
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / MorphType.java
1 /*
2  * morph type
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.pmd;
9
10 import java.util.Locale;
11 import java.util.ResourceBundle;
12
13 /**
14  * モーフ種別。
15  * <ul>
16  * <li>0:base
17  * <li>1:まゆ
18  * <li>2:目
19  * <li>3:リップ
20  * <li>4:その他
21  * </ul>
22  */
23 public enum MorphType {
24
25     /** base。 */
26     BASE(0x00),
27     /** まゆ。 */
28     EYEBROW(0x01),
29     /** 目。 */
30     EYE(0x02),
31     /** リップ。 */
32     LIP(0x03),
33     /** その他。 */
34     EXTRA(0x04),
35     ;
36
37     private static final String FAMILY_NAME =
38             "jp.sourceforge.mikutoga.pmd.resources.MorphTypeName";
39
40     private final byte encoded;
41
42     /**
43      * コンストラクタ。
44      * @param code 符号化int値
45      */
46     private MorphType(int code){
47         this((byte)code);
48         return;
49     }
50
51     /**
52      * コンストラクタ。
53      * @param code 符号化byte値
54      */
55     private MorphType(byte code){
56         this.encoded = code;
57         return;
58     }
59
60     /**
61      * byte値からデコードする。
62      * @param code byte値
63      * @return デコードされた列挙子。該当するものがなければnull
64      */
65     public static MorphType decode(byte code){
66         MorphType result = null;
67
68         for(MorphType type : values()){
69             if(type.encode() == code){
70                 result = type;
71                 break;
72             }
73         }
74
75         return result;
76     }
77
78     /**
79      * byte値にエンコードする。
80      * @return byte値
81      */
82     public byte encode(){
83         return this.encoded;
84     }
85
86     /**
87      * デフォルトロケールでの表示名を返す。
88      * @return 表示名
89      */
90     public String getGuiName(){
91         Locale locale = Locale.getDefault();
92         return getGuiName(locale);
93     }
94
95     /**
96      * ロケールに準じた表示名を返す。
97      * @param locale ロケール。nullならデフォルトロケールと解釈される。
98      * @return 表示名
99      */
100     public String getGuiName(Locale locale){
101         if(locale == null) return getGuiName();
102         ResourceBundle rb = ResourceBundle.getBundle(FAMILY_NAME, locale);
103         String key = name();
104         String result = rb.getString(key);
105         return result;
106     }
107
108     /**
109      * モーフ種別がbaseか否か判定する。
110      * @return baseならtrue
111      */
112     public boolean isBase(){
113         if(this == BASE) return true;
114         return false;
115     }
116
117 }