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 jp.sfjp.mikutoga.xml.SaxAttr;
14 import org.xml.sax.Attributes;
19 class SaxVmdListener {
21 private VmdMotion vmdMotion;
23 private PosCurve currentPosCurve;
26 private BezierParam currentBezParam;
32 protected SaxVmdListener(){
35 this.vmdMotion = null;
37 this.currentPosCurve = null;
40 this.currentBezParam = null;
51 void openTag(VmdTag tag, Attributes attr){
73 void closeTag(VmdTag tag){
79 * @param motion ビルド対象オブジェクト
80 * @throws NullPointerException 引数がnull
82 void setVmdMotion(VmdMotion motion) throws NullPointerException{
83 if(motion == null) throw new NullPointerException();
84 this.vmdMotion = motion;
90 * @return ビルド対象オブジェクト。未登録の場合はnull。
92 protected VmdMotion getVmdMotion(){
93 return this.vmdMotion;
97 * ビルド対象の位置補間曲線情報を受け取る。
98 * @param curve 位置補間曲線情報
100 protected void setCurrentPosCurve(PosCurve curve){
101 this.currentPosCurve = curve;
104 this.currentBezParam = null;
110 * ビルド対象の単一補間曲線情報を受け取る。
113 protected void setCurrentBezierParam(BezierParam bez){
114 this.currentBezParam = bez;
116 this.currentPosCurve = null;
126 private BezierParam getTargetBezierParam(){
127 if(this.currentBezParam != null){
128 return this.currentBezParam;
131 if(this.currentPosCurve == null){
133 throw new AssertionError();
138 switch(this.axisIdx){
140 result = this.currentPosCurve.getIntpltXpos();
143 result = this.currentPosCurve.getIntpltYpos();
146 result = this.currentPosCurve.getIntpltZpos();
150 throw new AssertionError();
165 protected void putBezier(byte p1x, byte p1y, byte p2x, byte p2y){
166 BezierParam bez = getTargetBezierParam();
178 protected void openBezier(Attributes attr){
179 byte p1x = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P1X);
180 byte p1y = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P1Y);
181 byte p2x = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P2X);
182 byte p2y = SaxAttr.getByteAttr(attr, XmlAttr.ATTR_P2Y);
184 putBezier(p1x, p1y, p2x, p2y);
192 protected void openDefLinear(){
193 byte p1x = BezierParam.DEF_P1X;
194 byte p1y = BezierParam.DEF_P1Y;
195 byte p2x = BezierParam.DEF_P2X;
196 byte p2y = BezierParam.DEF_P2Y;
198 putBezier(p1x, p1y, p2x, p2y);
204 * defEaseInOut要素開始の通知。
206 protected void openDefEaseInOut(){
207 byte p1x = BezierParam.EIO_P1X;
208 byte p1y = BezierParam.EIO_P1Y;
209 byte p2x = BezierParam.EIO_P2X;
210 byte p2y = BezierParam.EIO_P2Y;
212 putBezier(p1x, p1y, p2x, p2y);