OSDN Git Service

d809a585e5df49e8c920edb9418e8ad0fbe2e612
[mikutoga/Pmd2XML.git] / src / main / java / jp / sfjp / mikutoga / pmd / model / ToonMap.java
1 /*
2  * toon file mapping
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.pmd.model;
9
10 import java.util.Collections;
11 import java.util.Map;
12 import java.util.TreeMap;
13
14 /**
15  * インデックス化されたトゥーンファイル構成。
16  * 既存のトゥーンファイル構成と異なるトゥーンファイル名を用いることが可能。
17  * <h1>デフォルトのトゥーンファイル構成。</h1>
18  * <ul>
19  * <li>0x00:toon01.bmp
20  * <li>0x01:toon02.bmp
21  * <li>.....
22  * <li>0x09:toon10.bmp
23  * <li>0xff:toon0.bmp
24  * </ul>
25  */
26 public class ToonMap {
27
28     private static final Map<Integer, String> DEF_TOONMAP;
29
30     static{
31         Map<Integer, String> map = new TreeMap<Integer, String>();
32
33         map.put(0x00, "toon01.bmp");
34         map.put(0x01, "toon02.bmp");
35         map.put(0x02, "toon03.bmp");
36         map.put(0x03, "toon04.bmp");
37         map.put(0x04, "toon05.bmp");
38         map.put(0x05, "toon06.bmp");
39         map.put(0x06, "toon07.bmp");
40         map.put(0x07, "toon08.bmp");
41         map.put(0x08, "toon09.bmp");
42         map.put(0x09, "toon10.bmp");
43         map.put(0xff, "toon0.bmp");
44
45         DEF_TOONMAP = Collections.unmodifiableMap(map);
46     }
47
48     private final Map<Integer, String> toonMap =
49             new TreeMap<Integer, String>(DEF_TOONMAP);
50
51     /**
52      * コンストラクタ。
53      */
54     public ToonMap(){
55         super();
56         return;
57     }
58
59     /**
60      * 指定したインデックス値に対応したトゥーンファイル名を返す。
61      * @param idx インデックス値
62      * @return トゥーンファイル名。該当するものがなければnull
63      */
64     public String getIndexedToon(int idx){
65         String result = this.toonMap.get(idx);
66         return result;
67     }
68
69     /**
70      * 指定したインデックス値にトゥーンファイル名を設定する。
71      * @param idx インデックス値
72      * @param toonFileName トゥーンフィル名
73      * @throws NullPointerException トゥーンファイル名がnull
74      */
75     public void setIndexedToon(int idx, String toonFileName)
76             throws NullPointerException{
77         if(toonFileName == null) throw new NullPointerException();
78         this.toonMap.put(idx, toonFileName);
79         return;
80     }
81
82     /**
83      * このトゥーンファイル構成が
84      * デフォルトのトゥーンファイル構成と等しいか判定する。
85      * @return 等しければtrue
86      */
87     public boolean isDefaultMap(){
88         if(this.toonMap.equals(DEF_TOONMAP)) return true;
89         return false;
90     }
91
92     /**
93      * 指定インデックスのトゥーンファイル名がデフォルトと等しいか判定する。
94      * @param idx インデックス
95      * @return デフォルトと等しければtrue。
96      */
97     public boolean isDefaultToon(int idx){
98         String thisToon = this.toonMap.get(idx);
99         if(thisToon == null) return false;
100
101         String defToon = DEF_TOONMAP.get(idx);
102         if(thisToon.equals(defToon)) return true;
103
104         return false;
105     }
106
107     /**
108      * このトゥーンファイル構成をデフォルト構成内容でリセットする。
109      */
110     public void resetDefaultMap(){
111         this.toonMap.clear();
112         this.toonMap.putAll(DEF_TOONMAP);
113         return;
114     }
115
116     /**
117      * 指定インデックスのトゥーンファイル名を
118      * デフォルトのトゥーンファイル名にリセットする。
119      * @param idx インデックス値
120      */
121     public void resetIndexedToon(int idx){
122         String toonFile = DEF_TOONMAP.get(idx);
123         this.toonMap.put(idx, toonFile);
124         return;
125     }
126
127     /**
128      * {@inheritDoc}
129      * @return {@inheritDoc}
130      */
131     @Override
132     public String toString(){
133         StringBuilder result = new StringBuilder();
134
135         boolean dumped = false;
136         for(Map.Entry<Integer, String> entry : this.toonMap.entrySet()){
137             Integer idx = entry.getKey();
138             String toonFile = entry.getValue();
139
140             if(dumped) result.append(", ");
141             result.append('(').append(idx).append(')');
142             result.append(toonFile);
143             dumped = true;
144         }
145
146         return result.toString();
147     }
148
149 }