OSDN Git Service

1.105.3-SNAPSHOT版開発開始
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / RigidBehaviorType.java
1 /*
2  * rigid behavior 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>0x00:ボーン追従
17  * <li>0x01:物理演算
18  * <li>0x02:物理演算+ボーン位置合わせ
19  * </ul>
20  */
21 public enum RigidBehaviorType {
22
23     /** ボーン追従。 */
24     FOLLOWBONE(0x00),
25     /** 物理演算。 */
26     ONLYDYNAMICS(0x01),
27     /** 物理演算+ボーン位置合わせ。 */
28     BONEDDYNAMICS(0x02),
29     ;
30
31     private static final String FAMILY_NAME =
32         "jp.sourceforge.mikutoga.pmd.resources.RigidBehaviorTypeName";
33
34     private final byte encoded;
35
36     /**
37      * コンストラクタ。
38      * @param code 符号化int値
39      */
40     private RigidBehaviorType(int code){
41         this((byte)code);
42         return;
43     }
44
45     /**
46      * コンストラクタ。
47      * @param code 符号化byte値
48      */
49     private RigidBehaviorType(byte code){
50         this.encoded = code;
51         return;
52     }
53
54     /**
55      * byte値からデコードする。
56      * @param code byte値
57      * @return デコードされた列挙子。該当するものがなければnull
58      */
59     public static RigidBehaviorType decode(byte code){
60         RigidBehaviorType result = null;
61
62         for(RigidBehaviorType type : values()){
63             if(type.encode() == code){
64                 result = type;
65                 break;
66             }
67         }
68
69         return result;
70     }
71
72     /**
73      * byte値にエンコードする。
74      * @return byte値
75      */
76     public byte encode(){
77         return this.encoded;
78     }
79
80     /**
81      * デフォルトロケールでの表示名を返す。
82      * @return 表示名
83      */
84     public String getGuiName(){
85         Locale locale = Locale.getDefault();
86         return getGuiName(locale);
87     }
88
89     /**
90      * ロケールに準じた表示名を返す。
91      * @param locale ロケール。nullならデフォルトロケールと解釈される。
92      * @return 表示名
93      */
94     public String getGuiName(Locale locale){
95         if(locale == null) return getGuiName();
96         ResourceBundle rb = ResourceBundle.getBundle(FAMILY_NAME, locale);
97         String key = name();
98         String result = rb.getString(key);
99         return result;
100     }
101
102 }