📄 playerui.java
字号:
} public void mouseExited(MouseEvent me) { about.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); this.add(about); this.add(infoPanel); this.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent me) { if (me.getButton() == MouseEvent.BUTTON3) { showOptionDialog(me); } } }); } public Loader getLoader() { return loader; } /** * 用于显示关于的一系列菜单的方法 * 供自己还有Main调用,因为Main里面 * 注册了系统栏图标 */ public void showOptionDialog(MouseEvent me) { JPopupMenu pop = new JPopupMenu("Set"); pop.add(new AbstractAction(Config.getResource("PlayerUI.option")) { public void actionPerformed(ActionEvent e) { JDialog jd = config.getOptionDialog(); jd.setVisible(true); } }); pop.addSeparator(); pop.add(createPlayMenu()); pop.add(createVolumeMenu()); pop.add(createPlayModeMenu()); pop.add(createPlayWhichMenu()); pop.addSeparator(); pop.add(createAudioChartMenu()); pop.add(createLyricMenu()); pop.add(createEqMenu()); pop.addSeparator(); pop.add(createViewMenu()); pop.add(new AbstractAction(Config.getResource("PlayerUI.minimize")) { public void actionPerformed(ActionEvent e) { loader.minimize(); } }); pop.add(new AbstractAction(Config.getResource("PlayerUI.exit")) { public void actionPerformed(ActionEvent e) { closePlayer(); } }); pop.show(me.getComponent(), me.getX(), me.getY()); } private JMenu createPlayMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.playControl")); menu.add(new AbstractAction(playerState == PLAY ? Config.getResource("PlayerUI.pause") : Config.getResource("PlayerUI.play")) { public void actionPerformed(ActionEvent e) { if (playerState == PLAY) { processPause(0); } else { processPlay(0); } } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.stop")) { public void actionPerformed(ActionEvent e) { processStop(0); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.ff5")) { public void actionPerformed(ActionEvent e) { if (currentItem == null) { return; } int sec = timePanel.getSeconds(); if (sec >= 5) { setTime((sec - 5) * 1000); } else { setTime(0); } } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.ss5")) { public void actionPerformed(ActionEvent e) { if (currentItem == null) { return; } int sec = timePanel.getSeconds(); if (sec + 5 < currentItem.getLength()) { setTime((sec + 5) * 1000); } } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.pre")) { public void actionPerformed(ActionEvent e) { previousSong(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.next")) { public void actionPerformed(ActionEvent e) { nextSong(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.playFile")) { public void actionPerformed(ActionEvent e) { JFileChooser jf = Util.getFileChooser(new FileNameFilter(Config.EXTS, Config.getResource("playlist.filechooser.name"), true), JFileChooser.FILES_ONLY); int i = jf.showOpenDialog(config.getPlWindow()); if (i == JFileChooser.APPROVE_OPTION) { File f = jf.getSelectedFile(); PlayListItem item = new PlayListItem(Util.getSongName(f), f.getPath(), -1, true); playlist.removeAllItems(); playlist.appendItem(item); playlistUI.repaint(); playerState = PLAY; setCurrentSong(item); } } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.playURL")) { public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(config.getTopParent(), Config.getResource("playlist.add.inputurl")); if (s != null) { if (Config.startWithProtocol(s)) { PlayListItem item = new PlayListItem(s, s, -1, false); playlist.removeAllItems(); playlist.appendItem(item); playlistUI.repaint(); playerState = PLAY; setCurrentSong(item); } else { JOptionPane.showMessageDialog(config.getPlWindow(), Config.getResource("playlist.add.invalidUrl")); } } } }); return menu; } private JMenu createVolumeMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.volumeControl")); menu.add(new AbstractAction(Config.getResource("PlayerUI.increase")) { public void actionPerformed(ActionEvent e) { int value = volume.getValue(); volume.setValue(value + 10); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.decrease")) { public void actionPerformed(ActionEvent e) { int value = volume.getValue(); volume.setValue(value - 10); } }); menu.addSeparator(); JCheckBoxMenuItem mute = new JCheckBoxMenuItem(Config.getResource("PlayerUI.mute"), config.isMute()); mute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JCheckBoxMenuItem check = (JCheckBoxMenuItem) ae.getSource(); config.setMute(check.isSelected()); changeSpeakerState(); } }); menu.add(mute); return menu; } private void changeSpeakerState() { if (config.isMute()) { speaker.setActionCommand(Config.VOL_ON); speaker.setSelected(true); try { player.setGain(0); } catch (BasicPlayerException ex) { Logger.getLogger(PlayerUI.class.getName()).log(Level.SEVERE, null, ex); } } else { speaker.setActionCommand(Config.VOL_OFF); speaker.setSelected(false); int gainValue = volume.getValue(); int maxGain = volume.getMaximum(); if (gainValue == 0) { try { player.setGain(0); } catch (BasicPlayerException ex) { } } else { try { player.setGain((double) gainValue / (double) maxGain); } catch (BasicPlayerException ex) { } } } } private JMenu createPlayModeMenu() { JMenu menu = new JMenu(Config.getResource("playlist.mode")); ButtonGroup bg1 = new ButtonGroup(); ButtonGroup bg2 = new ButtonGroup(); //不循环 JRadioButtonMenuItem noCircle = new JRadioButtonMenuItem(Config.getResource("playlist.mode.noCircle")); noCircle.setSelected(!config.isRepeatEnabled()); menu.add(noCircle).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { config.setRepeatEnabled(false); } }); //单曲循环 JRadioButtonMenuItem singleCircle = new JRadioButtonMenuItem(Config.getResource("playlist.mode.singleCircle")); singleCircle.setSelected(config.isRepeatEnabled() && config.getRepeatStrategy() == Config.REPEAT_ONE); menu.add(singleCircle).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { config.setRepeatEnabled(true); config.setRepeatStrategy(Config.REPEAT_ONE); } }); //整体循环 JRadioButtonMenuItem allCircle = new JRadioButtonMenuItem(Config.getResource("playlist.mode.allCircle")); allCircle.setSelected(config.isRepeatEnabled() && config.getRepeatStrategy() == Config.REPEAT_ALL); menu.add(allCircle).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { config.setRepeatEnabled(true); config.setRepeatStrategy(Config.REPEAT_ALL); } }); menu.addSeparator(); //顺序播放 JRadioButtonMenuItem orderPlay = new JRadioButtonMenuItem(Config.getResource("playlist.mode.orderPlay")); orderPlay.setSelected(config.getPlayStrategy() == Config.ORDER_PLAY); menu.add(orderPlay).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { config.setPlayStrategy(Config.ORDER_PLAY); } }); //随机播放 JRadioButtonMenuItem randomPlay = new JRadioButtonMenuItem(Config.getResource("playlist.mode.randomPlay")); randomPlay.setSelected(config.getPlayStrategy() == Config.RANDOM_PLAY); menu.add(randomPlay).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { config.setPlayStrategy(Config.RANDOM_PLAY); } }); bg1.add(noCircle); bg1.add(singleCircle); bg1.add(allCircle); bg2.add(orderPlay); bg2.add(randomPlay); return menu; } private JMenu createPlayWhichMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.playSong")); for (final PlayListItem item : playlist.getAllItems()) { menu.add(new AbstractAction(item.getFormattedName()) { public void actionPerformed(ActionEvent e) { playerState = PLAY; setCurrentSong(item); } }); } return menu; } private JMenu createAudioChartMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.audioChart")); menu.add(new AbstractAction(Config.getResource("PlayerUI.analyzing")) { public void actionPerformed(ActionEvent e) { audioChart.setDisplayMode(AudioChart.DISPLAY_MODE_SPECTRUM_ANALYSER); config.setAudioChartDisplayMode(AudioChart.DISPLAY_MODE_SPECTRUM_ANALYSER); audioChart.repaint(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.line")) { public void actionPerformed(ActionEvent e) { audioChart.setDisplayMode(AudioChart.DISPLAY_MODE_SCOPE); config.setAudioChartDisplayMode(AudioChart.DISPLAY_MODE_SCOPE); audioChart.repaint(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.noshow")) { public void actionPerformed(ActionEvent e) { audioChart.setDisplayMode(AudioChart.DISPLAY_MODE_OFF); config.setAudioChartDisplayMode(AudioChart.DISPLAY_MODE_OFF); audioChart.repaint(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.optional")) { public void actionPerformed(ActionEvent e) { OptionDialog jd = config.getOptionDialog(); jd.setSelected(Config.getResource("PlayerUI.view")); jd.setVisible(true); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -