?? sentence.java
字號:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.hadeslee.yoyoplayer.lyric;import com.hadeslee.yoyoplayer.util.Config;import com.hadeslee.yoyoplayer.util.Util;import java.awt.Color;import java.awt.Graphics;import java.io.Serializable;/** * 一個用來表示每一句歌詞的類 * 它封裝了歌詞的內容以及這句歌詞的起始時間 * 和結束時間,還有一些實用的方法 * @author hadeslee */public class Sentence implements Serializable { private static final long serialVersionUID = 20071125L; private long fromTime;//這句的起始時間,時間是以毫秒為單位 private long toTime;//這一句的結束時間 private String content;//這一句的內容 private final static long DISAPPEAR_TIME = 1000L;//歌詞從顯示完到消失的時間 public Sentence(String content, long fromTime, long toTime) { this.content = content; this.fromTime = fromTime; this.toTime = toTime; } public Sentence(String content, long fromTime) { this(content, fromTime, 0); } public Sentence(String content) { this(content, 0, 0); } public long getFromTime() { return fromTime; } public void setFromTime(long fromTime) { this.fromTime = fromTime; } public long getToTime() { return toTime; } public void setToTime(long toTime) { this.toTime = toTime; } /** * 檢查某個時間是否包含在某句中間 * @param time 時間 * @return 是否包含了 */ public boolean isInTime(long time) { return time >= fromTime && time <= toTime; } /** * 得到這一句的內容 * @return 內容 */ public String getContent() { return content; } /** * 得到V方向的增量 * @param time 時間 * @return 增量 */ public int getVIncrease(Graphics g, long time) { int height = getContentHeight(g); return (int) ((height + Config.getConfig().getV_SPACE()) * ((time - fromTime) * 1.0 / (toTime - fromTime))); } /** * 得到H向方的增量 * @param time 時間 * @return 增時 */ public int getHIncrease(Graphics g, long time) { int width = getContentWidth(g); return (int) ((width + Config.getConfig().getH_SPACE()) * ((time - fromTime) * 1.0 / (toTime - fromTime))); } /** * 得到內容的寬度 * @param g 畫筆 * @return 寬度 */ public int getContentWidth(Graphics g) { return (int) g.getFontMetrics().getStringBounds(content, g).getWidth(); } /** * 得到這個句子的時間長度,毫秒為單位 * @return 長度 */ public long getDuring() { return toTime - fromTime; } /** * 移動這些距離來說,對于這個句子 * 花了多少的時間 * @param length 要移動的距離 * @param g 畫筆 * @return 時間長度 */ public long getTimeH(int length, Graphics g) { return getDuring() * length / getContentWidth(g); } /** * 對于豎直方向的移動這些象素所代表的時間 * @param length 距離的長度 * @param g 畫筆 * @return 時間長度 */ public long getTimeV(int length, Graphics g) { return getDuring() * length / getContentHeight(g); } /** * 得到內容的高度 * @param g 畫筆 * @return 高度 */ public int getContentHeight(Graphics g) { return (int) g.getFontMetrics().getStringBounds(content, g).getHeight() + Config.getConfig().getV_SPACE(); } /** * 根據當前指定的時候,得到這個時候應該 * 取漸變色的哪個階段了,目前的算法是從 * 快到結束的五分之一處開始漸變,這樣平緩一些 * @param c1 高亮色 * @param c2 普通色 * @param time 時間 * @return 新的顏色 */ public Color getBestInColor(Color c1, Color c2, long time) { float f = (time - fromTime) * 1.0f / getDuring(); if (f > 0.1f) {//如果已經過了十分之一的地方,就直接返高亮色 return c1; } else { long dur = getDuring(); f = (time - fromTime) * 1.0f / (dur * 0.1f); if (f > 1 || f < 0) { return c1; } return Util.getGradientColor(c2, c1, f); } } /** * 得到最佳的漸出顏色 * @param c1 * @param c2 * @param time * @return */ public Color getBestOutColor(Color c1, Color c2, long time) { if (isInTime(time)) { return c1; } float f = (time - toTime) * 1.0f / DISAPPEAR_TIME; if (f > 1f || f <= 0) {//如果時間已經超過了最大的時間了,則直接返回原來的顏色 return c2; } else { return Util.getGradientColor(c1, c2, f); } } public String toString() { return "{" + fromTime + "(" + content + ")" + toTime + "}"; } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -