2 * VMD-SAX element listsner
4 * License : The MIT License
5 * Copyright(c) 2013 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.model.xml;
10 import jp.sfjp.mikutoga.vmd.model.BezierParam;
11 import jp.sfjp.mikutoga.vmd.model.PosCurve;
12 import jp.sfjp.mikutoga.vmd.model.VmdMotion;
13 import org.xml.sax.Attributes;
18 class SaxVmdListener {
20 private VmdMotion vmdMotion;
22 private PosCurve currentPosCurve;
25 private BezierParam currentBezParam;
31 protected SaxVmdListener(){
34 this.vmdMotion = null;
36 this.currentPosCurve = null;
39 this.currentBezParam = null;
50 void openTag(VmdTag tag, Attributes attr){
72 void closeTag(VmdTag tag){
78 * @param motion ビルド対象オブジェクト
79 * @throws NullPointerException 引数がnull
81 void setVmdMotion(VmdMotion motion) throws NullPointerException{
82 if(motion == null) throw new NullPointerException();
83 this.vmdMotion = motion;
89 * @return ビルド対象オブジェクト。未登録の場合はnull。
91 protected VmdMotion getVmdMotion(){
92 return this.vmdMotion;
96 * ビルド対象の位置補間曲線情報を受け取る。
97 * @param curve 位置補間曲線情報
99 protected void setCurrentPosCurve(PosCurve curve){
100 this.currentPosCurve = curve;
103 this.currentBezParam = null;
109 * ビルド対象の単一補間曲線情報を受け取る。
112 protected void setCurrentBezierParam(BezierParam bez){
113 this.currentBezParam = bez;
115 this.currentPosCurve = null;
125 private BezierParam getTargetBezierParam(){
126 if(this.currentBezParam != null){
127 return this.currentBezParam;
130 if(this.currentPosCurve == null){
132 throw new AssertionError();
137 switch(this.axisIdx){
139 result = this.currentPosCurve.getIntpltXpos();
142 result = this.currentPosCurve.getIntpltYpos();
145 result = this.currentPosCurve.getIntpltZpos();
149 throw new AssertionError();
164 protected void putBezier(byte p1x, byte p1y, byte p2x, byte p2y){
165 BezierParam bez = getTargetBezierParam();
177 protected void openBezier(Attributes attr){
178 byte p1x = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P1X);
179 byte p1y = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P1Y);
180 byte p2x = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P2X);
181 byte p2y = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P2Y);
183 putBezier(p1x, p1y, p2x, p2y);
191 protected void openDefLinear(){
192 byte p1x = BezierParam.DEF_P1X;
193 byte p1y = BezierParam.DEF_P1Y;
194 byte p2x = BezierParam.DEF_P2X;
195 byte p2y = BezierParam.DEF_P2Y;
197 putBezier(p1x, p1y, p2x, p2y);
203 * defEaseInOut要素開始の通知。
205 protected void openDefEaseInOut(){
206 byte p1x = BezierParam.EIO_P1X;
207 byte p1y = BezierParam.EIO_P1Y;
208 byte p2x = BezierParam.EIO_P2X;
209 byte p2y = BezierParam.EIO_P2Y;
211 putBezier(p1x, p1y, p2x, p2y);