⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lyricpanel.java

📁 java+eclipse做的TTPlayer
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.Playerable;import com.hadeslee.yoyoplayer.util.Util;import java.awt.Color;import java.awt.Cursor;import java.awt.Desktop;import java.awt.Font;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Rectangle;import java.awt.RenderingHints;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transferable;import java.awt.dnd.DnDConstants;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetDragEvent;import java.awt.dnd.DropTargetDropEvent;import java.awt.dnd.DropTargetEvent;import java.awt.dnd.DropTargetListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseWheelEvent;import java.awt.event.MouseWheelListener;import java.io.File;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.JDialog;import javax.swing.JPanel;import javax.swing.JPopupMenu;/** * * @author hadeslee */public class LyricPanel extends JPanel implements Runnable, DropTargetListener,        MouseListener, MouseWheelListener, MouseMotionListener {    private static final long serialVersionUID = 20071214L;    private static Logger log = Logger.getLogger(LyricPanel.class.getName());    private DropTarget dt;//一个拖放的目标    private Playerable player;//播放器    private Lyric ly;//表示此歌词面板对应的歌词对象    public static final int V = 0;//表示纵向显示    public static final int H = 1;//表示横向显示    private int state = H;//表示现在是横向还是纵向的    private volatile boolean isPress;//是已经按下,按下就就不滚动歌词了    private volatile boolean isDrag;//是否已经动过了    private int start;//开始的时候座标,在释放的时候,好计算拖了多少    private int end;//现在的座标    private volatile boolean isResized;//是否已经重设大小了    private volatile boolean pause = true;//一个循环的标量    private final Object lock = new Object();    private volatile boolean isOver;//是否手在上面    private Rectangle area = new Rectangle();    private final String logo = Config.getResource("LyricPanel.logo");    private boolean isShowLogo = false;    private Config config;//一个全局配置对象//    private Component parent;//它是被加到谁的身上去了    public LyricPanel(Playerable pl) {        this();        this.player = pl;        this.setDoubleBuffered(true);    }    public LyricPanel() {        config = Config.getConfig();        dt = new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);        state = config.getLpState();        this.addMouseListener(this);        this.addMouseMotionListener(this);        this.addMouseWheelListener(this);        Thread th = new Thread(this);        th.setDaemon(true);        th.start();    }    public void setConfig(Config config) {        this.config = config;    }    public void setShowLogo(boolean b) {        isShowLogo = b;    }    /**     * 设置播放列表     * @param pl 播放列表     */    public void setPlayList(Playerable pl) {        this.player = pl;    }    /**     * 设置一个新的歌词对象,此方法可能会被     * PlayList调用     * @param ly 歌词     */    public void setLyric(Lyric ly) {        this.ly = ly;        isResized = false;    }    public void pause() {        log.log(Level.INFO, "歌词暂停显示了");        pause = true;    }    public void start() {        log.log(Level.INFO, "歌词开始显示了...");        pause = false;        synchronized (lock) {            lock.notifyAll();        }    }    protected void paintComponent(Graphics g) {        Graphics2D gd = (Graphics2D) g;        if (config.isTransparency()) {        } else {            super.paintComponent(g);            gd.setColor(config.getLyricBackground());            gd.fillRect(0, 0, getWidth(), getHeight());        }        if (config.isAntiAliasing()) {            gd.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);//            gd.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);        }        g.setFont(config.getLyricFont());        state = config.getLpState();        if (ly != null) {            //只有要重设大小,并且没有重设大小的时候,才去设,否则就不用理它了            //并且还要不是水平显示,因为水平显示的话,宽度就没有意义了,想多宽就可以多宽            if (config.isAutoResize() && !isResized && ly.isInitDone() && state == V) {                int maxWidth = ly.getMaxWidth(g);                int inset = player.getLyricUI().getInsets().left + player.getLyricUI().getInsets().right;                JDialog win = config.getLrcWindow();                if (win != null) {                    win.setSize(maxWidth + inset, win.getHeight());                    isResized = true;                }            }            if (isPress && isDrag) {                if (state == H) {                    ly.moveH(start - end, g);                } else {                    ly.moveV(start - end, g);                }            }            if (state == H) {                ly.drawH(g);            } else {                ly.drawV(g);            }            if (isPress && isDrag) {                if (state == H) {                    drawTimeH((int) (ly.getTime() / 1000), g);                } else {                    drawTimeV((int) (ly.getTime() / 1000), g);                }            }        } else {            g.setColor(config.getLyricHilight());            int width = Util.getStringWidth(Config.NAME, g);            int height = Util.getStringHeight(Config.NAME, g);            Util.drawString(g, Config.NAME, (getWidth() - width) / 2, (getHeight() - height) / 2);        }        if (isShowLogo) {            drawLogo(g);        }    }    /**     * 画出自己的LOGO     * @param g 画笔     */    private void drawLogo(Graphics g) {        g.setFont(new Font("Dialog", Font.BOLD, 14));        int width = Util.getStringWidth(logo, g);        int height = Util.getStringHeight(logo, g);        area.x = 5;        area.y = 5;        area.width = width;        area.height = height;        if (isOver) {            g.setColor(Color.RED);        } else {            Color bg = config.getLyricBackground();            int rgb = bg.getRGB();            int xor = ~rgb;            rgb = xor & 0x00ffffff;            Color c = new Color(rgb);            g.setColor(c);        }        Util.drawString(g, logo, 5, 5);    }    /**     * 得到播放器对象,此方法一般是给     * 在线搜索歌词框用的     * @return 播放器     */    public Playerable getPlayer() {        return this.player;    }    /**     * 画出正在拖动的时候的时间,以便更好的掌握进度     * 这是画出垂直方向的拖动时间     * @param sec 当前的秒数     * @param g 画笔     */    private void drawTimeV(int sec, Graphics g) {        String s = Util.secondToString(sec);        int width = getWidth();        int height = getHeight();        int centerY = height / 2;        g.drawLine(3, centerY - 5, 3, centerY + 5);        g.drawLine(width - 3, centerY - 5, width - 3, centerY + 5);        g.drawLine(3, centerY, width - 3, centerY);        g.setFont(new Font(Config.getResource("LyricPanel.font"), Font.PLAIN, 14));        g.setColor(Util.getColor(config.getLyricForeground(), config.getLyricHilight()));        Util.drawString(g, s, width - Util.getStringWidth(s, g), (height / 2 - Util.getStringHeight(s, g)));    }    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -