PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/YOYOPlayer/src/com/hadeslee/audiotag/tag/datatype/Lyrics3Line.java

http://yoyoplayer.googlecode.com/
Java | 257 lines | 147 code | 22 blank | 88 comment | 16 complexity | 353c4288b158becdba4144654063deb0 MD5 | raw file
  1. /**
  2. * @author : Paul Taylor
  3. * @author : Eric Farng
  4. *
  5. * Version @version:$Id: Lyrics3Line.java,v 1.7 2007/11/29 12:05:26 paultaylor Exp $
  6. *
  7. * MusicTag Copyright (C)2003,2004
  8. *
  9. * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
  10. * General Public License as published by the Free Software Foundation; either version 2.1 of the License,
  11. * or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  14. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this library; if not,
  18. * you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * Description:
  22. *
  23. */
  24. package com.hadeslee.audiotag.tag.datatype;
  25. import com.hadeslee.audiotag.tag.id3.AbstractTagFrameBody;
  26. import com.hadeslee.audiotag.tag.InvalidDataTypeException;
  27. import com.hadeslee.audiotag.audio.generic.Utils;
  28. import java.util.Iterator;
  29. import java.util.LinkedList;
  30. public class Lyrics3Line
  31. extends AbstractDataType
  32. {
  33. /**
  34. *
  35. */
  36. private LinkedList timeStamp = new LinkedList();
  37. /**
  38. *
  39. */
  40. private String lyric = "";
  41. /**
  42. * Creates a new ObjectLyrics3Line datatype.
  43. *
  44. * @param identifier
  45. */
  46. public Lyrics3Line(String identifier, AbstractTagFrameBody frameBody)
  47. {
  48. super(identifier, frameBody);
  49. }
  50. public Lyrics3Line(Lyrics3Line copy)
  51. {
  52. super(copy);
  53. this.lyric = new String(copy.lyric);
  54. Lyrics3TimeStamp newTimeStamp;
  55. for (int i = 0; i < copy.timeStamp.size(); i++)
  56. {
  57. newTimeStamp = new Lyrics3TimeStamp((Lyrics3TimeStamp) copy.timeStamp.get(i));
  58. this.timeStamp.add(newTimeStamp);
  59. }
  60. }
  61. public void setLyric(String lyric)
  62. {
  63. this.lyric = lyric;
  64. }
  65. public void setLyric(ID3v2LyricLine line)
  66. {
  67. this.lyric = line.getText();
  68. }
  69. /**
  70. *
  71. *
  72. * @return
  73. */
  74. public String getLyric()
  75. {
  76. return lyric;
  77. }
  78. /**
  79. *
  80. *
  81. * @return
  82. */
  83. public int getSize()
  84. {
  85. int size = 0;
  86. for (Object aTimeStamp : timeStamp)
  87. {
  88. size += ((Lyrics3TimeStamp) aTimeStamp).getSize();
  89. }
  90. return size + lyric.length();
  91. }
  92. /**
  93. *
  94. *
  95. * @param time
  96. */
  97. public void setTimeStamp(Lyrics3TimeStamp time)
  98. {
  99. timeStamp.clear();
  100. timeStamp.add(time);
  101. }
  102. /**
  103. *
  104. *
  105. * @return
  106. */
  107. public Iterator getTimeStamp()
  108. {
  109. return timeStamp.iterator();
  110. }
  111. public void addLyric(String newLyric)
  112. {
  113. this.lyric += newLyric;
  114. }
  115. public void addLyric(ID3v2LyricLine line)
  116. {
  117. this.lyric += line.getText();
  118. }
  119. /**
  120. *
  121. *
  122. * @param time
  123. */
  124. public void addTimeStamp(Lyrics3TimeStamp time)
  125. {
  126. timeStamp.add(time);
  127. }
  128. /**
  129. *
  130. *
  131. * @param obj
  132. * @return
  133. */
  134. public boolean equals(Object obj)
  135. {
  136. if ((obj instanceof Lyrics3Line) == false)
  137. {
  138. return false;
  139. }
  140. Lyrics3Line object = (Lyrics3Line) obj;
  141. if (this.lyric.equals(object.lyric) == false)
  142. {
  143. return false;
  144. }
  145. if (this.timeStamp.equals(object.timeStamp) == false)
  146. {
  147. return false;
  148. }
  149. return super.equals(obj);
  150. }
  151. /**
  152. *
  153. *
  154. * @return
  155. */
  156. public boolean hasTimeStamp()
  157. {
  158. if (timeStamp.isEmpty())
  159. {
  160. return false;
  161. }
  162. return true;
  163. }
  164. /**
  165. *
  166. *
  167. * @param lineString
  168. * @param offset
  169. * @throws NullPointerException
  170. * @throws IndexOutOfBoundsException
  171. */
  172. public void readString(String lineString, int offset)
  173. {
  174. if (lineString == null)
  175. {
  176. throw new NullPointerException("Image is null");
  177. }
  178. if ((offset < 0) || (offset >= lineString.length()))
  179. {
  180. throw new IndexOutOfBoundsException("Offset to line is out of bounds: offset = " + offset +
  181. ", line.length()" + lineString.length());
  182. }
  183. int delim = 0;
  184. Lyrics3TimeStamp time;
  185. timeStamp = new LinkedList();
  186. delim = lineString.indexOf("[", offset);
  187. while (delim >= 0)
  188. {
  189. offset = lineString.indexOf("]", delim) + 1;
  190. time = new Lyrics3TimeStamp("Time Stamp");
  191. time.readString(lineString.substring(delim, offset));
  192. timeStamp.add(time);
  193. delim = lineString.indexOf("[", offset);
  194. }
  195. lyric = lineString.substring(offset);
  196. }
  197. /**
  198. *
  199. *
  200. * @return
  201. */
  202. public String toString()
  203. {
  204. String str = "";
  205. for (Object aTimeStamp : timeStamp)
  206. {
  207. str += aTimeStamp.toString();
  208. }
  209. return "timeStamp = " + str + ", lyric = " + lyric + "\n";
  210. }
  211. /**
  212. *
  213. *
  214. * @return
  215. */
  216. public String writeString()
  217. {
  218. String str = "";
  219. Lyrics3TimeStamp time;
  220. for (Object aTimeStamp : timeStamp)
  221. {
  222. time = (Lyrics3TimeStamp) aTimeStamp;
  223. str += time.writeString();
  224. }
  225. return str + lyric;
  226. }
  227. public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
  228. {
  229. readString(arr.toString(), offset);
  230. }
  231. public byte[] writeByteArray()
  232. {
  233. return Utils.getDefaultBytes(writeString(),"ISO8859-1");
  234. }
  235. }