OSDN Git Service

Merge release/v3.121.2
[mikutoga/TogaGem.git] / src / main / java / jp / sfjp / mikutoga / pmd / BoneType.java
1 /*
2  * bone type
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.pmd;
9
10 import java.util.List;
11 import java.util.Locale;
12 import java.util.ResourceBundle;
13
14 /**
15  * ボーン種別。
16  * <ul>
17  * <li>0x00:回転
18  * <li>0x01:回転/移動
19  * <li>0x02:IK
20  * <li>0x03:不明
21  * <li>0x04:IK影響下(回転)
22  * <li>0x05:回転影響下
23  * <li>0x06:IK接続先
24  * <li>0x07:非表示
25  * <li>0x08:捩り
26  * <li>0x09:回転連動
27  * </ul>
28  */
29 public enum BoneType {
30
31     /** 回転。 */
32     ROTATE(0x00),
33     /** 回転/移動。 */
34     ROTMOV(0x01),
35     /** IK。 */
36     IK(0x02),
37     /** 不明。 */
38     UNKNOWN(0x03),
39     /** IK影響下(回転)。 */
40     UNDERIK(0x04),
41     /** 回転影響下。 */
42     UNDERROT(0x05),
43     /** IK接続先。 */
44     IKCONNECTED(0x06),
45     /** 非表示。 */
46     HIDDEN(0x07),
47     /** 捩り。 */
48     TWIST(0x08),
49     /** 回転連動。 */
50     LINKEDROT(0x09),
51     ;
52
53     private static final ResourceBundle.Control NOFALLBACK;
54     private static final String FAMILY_NAME =
55             "jp.sfjp.mikutoga.pmd.resources.BoneTypeName";
56
57     static{
58         List<String> rbforms = ResourceBundle.Control.FORMAT_DEFAULT;
59         NOFALLBACK = ResourceBundle.Control.getNoFallbackControl(rbforms);
60
61         String name = ROTATE.getClass().getPackage().getName();
62         assert FAMILY_NAME.startsWith(name);
63     }
64
65
66     private final byte encoded;
67
68     /**
69      * コンストラクタ。
70      * @param code 符号化int値
71      */
72     private BoneType(int code){
73         this((byte)code);
74         return;
75     }
76
77     /**
78      * コンストラクタ。
79      * @param code 符号化byte値
80      */
81     private BoneType(byte code){
82         this.encoded = code;
83         return;
84     }
85
86     /**
87      * byte値からデコードする。
88      * @param code byte値
89      * @return デコードされた列挙子。該当するものがなければnull
90      */
91     public static BoneType decode(byte code){
92         BoneType result = null;
93
94         for(BoneType type : values()){
95             if(type.encode() == code){
96                 result = type;
97                 break;
98             }
99         }
100
101         return result;
102     }
103
104     /**
105      * byte値にエンコードする。
106      * @return byte値
107      */
108     public byte encode(){
109         return this.encoded;
110     }
111
112     /**
113      * デフォルトロケールでの表示名を返す。
114      * @return 表示名
115      */
116     public String getGuiName(){
117         Locale locale = Locale.getDefault();
118         assert locale != null;
119         return getGuiName(locale);
120     }
121
122     /**
123      * ロケールに準じた表示名を返す。
124      * @param locale ロケール。nullならデフォルトロケールと解釈される。
125      * @return 表示名
126      */
127     public String getGuiName(Locale locale){
128         if(locale == null) return getGuiName();
129         ResourceBundle rb =
130                 ResourceBundle.getBundle(FAMILY_NAME, locale, NOFALLBACK);
131         String key = name();
132         String result = rb.getString(key);
133         return result;
134     }
135
136 }