📄 playlistui.java
字号:
Collections.shuffle(currentPlayList.getAllItems()); rightList.setListData(currentPlayList.getAllItems()); } }); return menu; } private JMenu createEditMenu() { JMenu menu = new JMenu(Config.getResource("playlist.edit")); //剪切 if (rightIndex != -1) { menu.add(Config.getResource("playlist.edit.cut")).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { clip.clear(); Object[] objs = rightList.getSelectedValues(); for (Object obj : objs) { PlayListItem item = (PlayListItem) obj; currentPlayList.removeItem(item); clip.add(item); } rightList.setListData(currentPlayList.getAllItems()); rightList.setSelectedIndex(rightIndex); } }); } //复制 if (rightIndex != -1) { menu.add(Config.getResource("playlist.edit.copy")).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { clip.clear(); Object[] objs = rightList.getSelectedValues(); for (Object obj : objs) { PlayListItem item = (PlayListItem) obj; clip.add(item); } rightList.setSelectedIndex(rightIndex); } }); } //粘帖 menu.add(Config.getResource("playlist.edit.paste")).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (clip.size() > 0) { PlayListItem last = null; for (PlayListItem item : clip) { PlayListItem it = new PlayListItem(item.getName(), item.getLocation(), item.getLength(), item.isFile()); int index = rightIndex; if (index == -1) { currentPlayList.appendItem(it); } else { currentPlayList.addItemAt(it, index); } last = it; } rightList.setListData(currentPlayList.getAllItems()); rightList.setSelectedValue(last, true); rightList.requestFocus(); rightHasFocus = true; } } }); menu.addSeparator(); //全选 menu.add(Config.getResource("playlist.edit.selectAll")).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { rightList.setSelectionInterval(0, currentPlayList.getPlaylistSize() - 1); } }); //全不选 menu.add(Config.getResource("playlist.edit.selectNone")).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { rightList.clearSelection(); rightIndex = -1; } }); //反选 menu.add(Config.getResource("playlist.edit.selectReverse")).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int[] indexes = rightList.getSelectedIndices(); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < currentPlayList.getPlaylistSize(); i++) { boolean has = false; for (int index : indexes) { if (i == index) { has = true; } } if (has == false) { list.add(i); } } int[] selects = new int[list.size()]; for (int i = 0; i < list.size(); i++) { selects[i] = list.get(i); } rightList.setSelectedIndices(selects); } }); return menu; } private JMenu createModeMenu() { 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; } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } /** * 用于应用程序之间传递数据时用到的对象 * @param T */ private class MyData<T> { private int oldIndex; private T t; public MyData(int oldIndex, T t) { this.oldIndex = oldIndex; this.t = t; } public int getOldIndex() { return oldIndex; } public T getData() { return t; } } /** * 左边列表的渲染器 */ private class LeftListCellRenderer extends JLabel implements ListCellRenderer { private static final long serialVersionUID = 20071214L; private volatile boolean hasFocus; public LeftListCellRenderer() { this.setOpaque(true); this.setHorizontalAlignment(JLabel.CENTER); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { this.setText(value.toString()); hasFocus = cellHasFocus; if (value.equals(currentPlayList)) { isSelected = true; } else { isSelected = false; } if (isSelected) { setBackground(BG); setForeground(HILIGHT); } else { setBackground(BG); setForeground(FORE); } if (cellHasFocus) { setForeground(BG); setBackground(FORE); } return this; } public void paint(Graphics g) { super.paint(g); if (hasFocus) { g.setColor(HILIGHT); g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); } } public void repaint() { } public void repaint(Rectangle rec) { } public void repaint(long l, int x, int y, int width, int height) { } public void validate() { } public void invalidate() { } public void revalidate() { } public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { } } /** * 右边的列表的渲染器 */ private class RightListCellRenderer extends YOYOLabel implements ListCellRenderer { private static final long serialVersionUID = 20071214L; public RightListCellRenderer() { this.setOpaque(true); this.setBorder(new EmptyBorder(0, 0, 0, 0)); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { this.setText("hadeslee"); PlayListItem item = (PlayListItem) value; if (item == player.getCurrentItem()) { item.setSelected(true); } else { item.setSelected(false); } this.setFont(config.getPlaylistFont()); list.setFont(config.getPlaylistFont()); this.setPlayListItem(item); this.setIsSelected(isSelected && rightHasFocus); this.setIndex(index); this.setItemCount(currentPlayList.getPlaylistSize());// this.setHasFocus(rightHasFocus && (cellHasFocus || (rightIndex == index))); this.setHasFocus(rightHasFocus && (cellHasFocus));// if (cellHasFocus || isSelected) {//// setBackground(Color.WHITE);//// setForeground(Color.BLACK);// } else {// setForeground(FORE);// setBackground(BG);// } if (index % 2 == 0) { setBackground(config.getPlaylistBackground1()); } else { setBackground(config.getPlaylistBackground2()); } return this; } public void repaint() { } public void repaint(Rectangle rec) { } public void repaint(long l, int x, int y, int width, int height) { } public void validate() { } public void invalidate() { } public void revalidate() { } public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { } } public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) { int index = rightList.locationToIndex(e.getPoint()); if (index != onIndex) { onIndex = index; showInfo(); } } /** * 显示ToolTip的提示 */ private void showInfo() { if (onIndex == -1 || !config.isShowTooltipOnPlayList()) { rightList.setToolTipText(null); return; } PlayListItem item = currentPlayList.getItemAt(onIndex); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(Config.getResource("songinfo.title")).append(" ").append(item.getTitle()).append("<br>"); sb.append(Config.getResource("songinfo.artist")).append(" ").append(item.getArtist()).append("<br>"); sb.append(Config.getResource("songinfo.album")).append(" ").append(item.getAlbum()).append("<br>"); sb.append(Config.getResource("songinfo.format")).append(" ").append(item.getFormat()).append("<br>"); sb.append(Config.getResource("songinfo.length")).append(" ").append(item.getFormattedLength()).append("<br>"); sb.append(Config.getResource("songinfo.location")).append(" ").append(item.getLocation()).append("<br> <p>"); sb.append("</html>"); rightList.setToolTipText(sb.toString()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -