Package com.tulskiy.musique.playlist

Examples of com.tulskiy.musique.playlist.Playlist


        add(tabs, BorderLayout.CENTER);

        List<String> bounds = PlaylistConfiguration.getTabBounds();

        for (int i = 0; i < playlists.size(); i++) {
            Playlist pl = playlists.get(i);
            PlaylistTable newTable = new PlaylistTable(pl, pl.getColumns());
            newTable.setUpDndCCP();
            columnModels.add(newTable.getColumnModel());

            //try to set last position
            try {
                String s = bounds.get(i);
                Integer y = Integer.valueOf(s);
                newTable.scrollRectToVisible(new Rectangle(0, y, 0, 0));
            } catch (Exception ignored) {
            }

            tabs.addTab(pl.getName(), newTable.getScrollPane());
        }

        final Playlist playlist = playlistManager.getActivePlaylist();

        tabs.setSelectedIndex(-1);
        tabs.setSelectedIndex(playlists.indexOf(playlist));

        PlaybackOrder order = app.getPlayer().getPlaybackOrder();
View Full Code Here


            public void actionPerformed(ActionEvent e) {
                PlaylistTable table = tabs.getSelectedTable();
                if (table == null)
                    return;

                Playlist playlist = table.getPlaylist();
                int row = table.rowAtPoint(table.getVisibleRect().getLocation());
                Track firstVisibleTrack;
                do {
                    firstVisibleTrack = playlist.get(row++);
                } while (firstVisibleTrack.getTrackData().getLocation() == null);

                JMenuItem src = (JMenuItem) e.getSource();
                Integer index = (Integer) src.getClientProperty("index");
                if (index < groupItems.length - 1) {
                    playlist.setGroupBy(groupValues[index]);
                } else {
                    Object ret = JOptionPane.showInputDialog(comp,
                            "Select formatting",
                            config.getString("playlists.groupBy", playlist.getGroupBy()));
                    if (ret != null) {
                        playlist.setGroupBy(ret.toString());
                        config.setString("playlists.groupBy", ret.toString());
                    }
                }

                int firstVisibleIndex = playlist.indexOf(firstVisibleTrack);
                if (firstVisibleIndex != -1) {
                    Rectangle cellRect = table.getCellRect(firstVisibleIndex, 0, true);
                    Rectangle visibleRect = table.getVisibleRect();
                    cellRect.setSize(visibleRect.width, visibleRect.height);
                    table.scrollRectToVisible(cellRect);
                }

                table.update();
            }
        };

        for (int i = 0; i < groupItems.length; i++) {
            String groupValue = groupItems[i];
            if (groupValue == null) {
                groups.addSeparator();
                continue;
            }

            AbstractButton item = groups.add(groupValue);
            item.setIcon(emptyIcon);
            item.addActionListener(groupListener);
            item.putClientProperty("index", i);
        }

        editMenu.add(groups);

        JMenu sort = new JMenu("Sort");
        String[] sortItems = {
                "Sort by...", "Randomize", "Reverse",
                "Sort by Artist", "Sort by Album",
                "Sort by File Path", "Sort by Title",
                "Sort by Track Number", "Sort by Album Artist/Year/Album/Disc/Track/File Name"
        };

        final String[] sortValues = {
                null, null, null, "%artist%", "%album%",
                "%file%", "%title%", "%trackNumber%",
                "%albumArtist% - %year% - %album% - %discNumber% - %trackNumber% - %fileName%"
        };

        ActionListener sortListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JMenuItem src = (JMenuItem) e.getSource();
                Integer index = (Integer) src.getClientProperty("index");
                PlaylistTable table = tabs.getSelectedTable();
                if (table == null)
                    return;

                Playlist playlist = table.getPlaylist();
                switch (index) {
                    case 0:
                        Object ret = JOptionPane.showInputDialog(comp,
                                "Sort By...",
                                config.getString("playlist.sortString", ""));
                        if (ret != null) {
                            playlist.sort(ret.toString(), false);
                            config.setString("playlist.sortString", ret.toString());
                        }

                        break;
                    case 1:
                        Collections.shuffle(playlist);
                        playlist.firePlaylistChanged();
                        break;
                    case 2:
                        Collections.reverse(playlist);
                        playlist.firePlaylistChanged();
                        break;
                    default:
                        playlist.sort(sortValues[index], false);
                }
            }
        };

        for (int i = 0; i < sortItems.length; i++) {
View Full Code Here

        try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        Playlist pl = new Playlist();
        JLabel label = new JLabel();
        pl.insertItem("/windows/Users/tulskiy/Music/Avril Lavigne", 0, true, null);
        FileOperations dialog = new FileOperations(label, Operation.Rename, pl);
        dialog.setVisible(true);
    }
View Full Code Here

        });

        aMap.put(SEND_TO_NEW, new AbstractAction(SEND_TO_NEW.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                Playlist playlist = playlistManager.addPlaylist(getSelectionPath().getLastPathComponent().toString());
                sendToPlaylist(playlist);
            }
        });
        aMap.put(ADD_TO_CURRENT, new AbstractAction(ADD_TO_CURRENT.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                Playlist playlist = playlistManager.getVisiblePlaylist();
                playlist.addAll(getSelectedTracks(true));
                playlist.firePlaylistChanged();
            }
        });

        aMap.put(EXPAND_COLLAPSE, new AbstractAction() {
            @Override
View Full Code Here

                    tabbedPane.getActionMap().get("newPlaylist").actionPerformed(
                            new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
                } else if (e.getButton() == MouseEvent.BUTTON2) {
                    int index = tabbedPane.indexAtLocation(e.getX(), e.getY());
                    if (index != -1) {
                        Playlist playlist = getTableAt(index).getPlaylist();
                        playlistManager.removePlaylist(playlist);
                    }
                }
            }
        });
View Full Code Here

        });
        aMap.put("renamePlaylist", new AbstractAction("Rename") {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedTable != null) {
                    Playlist playlist = selectedTable.getPlaylist();
                    String name = JOptionPane.showInputDialog("Rename", playlist.getName());
                    if (!Util.isEmpty(name)) {
                        playlist.setName(name);
                        tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), center(name));
                    }
                }
            }
        });
        aMap.put("removePlaylist", new AbstractAction("Remove Playlist") {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedTable != null) {
                    playlistManager.removePlaylist(selectedTable.getPlaylist());
                    checkTabCount();
                }
            }
        });
        aMap.put("savePlaylist", new AbstractAction("Save Playlist") {
            @Override
            public void actionPerformed(ActionEvent e) {
                JFileChooser fc = new JFileChooser();
                String path = config.getString("playlists.lastDir", "");
                if (!path.isEmpty()) fc.setCurrentDirectory(new File(path));
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                fc.setAcceptAllFileFilterUsed(false);
                FileNameExtensionFilter musFiler = new FileNameExtensionFilter("Musique Playlist", "mus");
                FileNameExtensionFilter m3uFilter = new FileNameExtensionFilter("M3U Playlist", "m3u", "m3u8");
                FileNameExtensionFilter plsFiler = new FileNameExtensionFilter("PLS Playlist", "pls");
                fc.addChoosableFileFilter(musFiler);
                fc.addChoosableFileFilter(m3uFilter);
                fc.addChoosableFileFilter(plsFiler);
                Playlist playlist = selectedTable.getPlaylist();
                String fileName = playlist.getName().toLowerCase().replaceAll("\\s+", "_");
                fc.setSelectedFile(new File(fileName));

                int ret = fc.showSaveDialog(getRootPane());
                if (ret == JFileChooser.APPROVE_OPTION) {
                    FileNameExtensionFilter filter = (FileNameExtensionFilter) fc.getFileFilter();
                    File file = fc.getSelectedFile();
                    String suffix = filter.getExtensions()[0];
                    if (!file.getName().endsWith(suffix)) {
                        file = new File(file.getParent(),
                                Util.removeExt(file.getName()) + "." + suffix);
                    }
                    if (filter == musFiler) {
                        playlist.save(file);
                    } else if (filter == m3uFilter) {
                        playlist.saveM3U(file);
                    } else if (filter == plsFiler) {
                        playlist.savePLS(file);
                    }
                    config.setString("playlists.lastDir", fc.getCurrentDirectory().getAbsolutePath());
                }
            }
        });
        aMap.put("loadPlaylist", new AbstractAction("Load Playlist") {
            @Override
            public void actionPerformed(ActionEvent e) {
                JFileChooser fc = new JFileChooser();
                String path = config.getString("playlists.lastDir", "");
                if (!path.isEmpty()) fc.setCurrentDirectory(new File(path));
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                fc.setMultiSelectionEnabled(false);
                fc.setAcceptAllFileFilterUsed(false);
                fc.addChoosableFileFilter(new FileNameExtensionFilter("All supported formats", "mus", "m3u", "m3u8", "pls"));
                fc.addChoosableFileFilter(new FileNameExtensionFilter("Musique Playlist", "mus"));
                fc.addChoosableFileFilter(new FileNameExtensionFilter("M3U Playlist", "m3u", "m3u8"));
                fc.addChoosableFileFilter(new FileNameExtensionFilter("PLS Playlist", "pls"));

                int ret = fc.showOpenDialog(getRootPane());
                if (ret == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    Playlist playlist = addPlaylist(Util.capitalize(Util.removeExt(file.getName()), " "));
                    ProgressDialog dialog = new ProgressDialog(tabbedPane, "Adding Files");
                    dialog.show(new Task.FileAddingTask(playlist, new File[]{fc.getSelectedFile()}, -1));
                    config.setString("playlists.lastDir", fc.getCurrentDirectory().getAbsolutePath());
                }
            }
View Full Code Here

                searchWorker = new SearchWorker(library.getData(), searchField.getText(), true) {
                    @Override
                    protected void done() {
                        try {
                            Playlist result = get();
                            if (result != null) {
                                libraryView = new Library(result);
                                tree.setRootNode(libraryView.getRootNode());
                            } else {
                                libraryView = null;
View Full Code Here

                }
            } else if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
            }

            Playlist playlist = table.getPlaylist();
            int insertRow = 0;
            if (support.isDrop()) {
                JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();
                int index = dl.getRow();
                if (index == playlist.size()) {
                    //corner case
                    insertRow = index;
                } else {
                    insertRow = table.convertRowIndexToModel(index);
                }
            }

            if (files != null) {
                if (insertRow == -1)
                    insertRow = playlist.size();
                addFiles(table, files, insertRow);
                return true;
            }

            if (tracks != null && !tracks.isEmpty()) {
                if (support.isDrop()) {
                    if (insertRow != -1) {
                        int toSubstract = 0;
                        for (Track track : tracks) {
                            int i = playlist.indexOf(track);
                            if (i > -1 && i < insertRow)
                                toSubstract++;
                        }

                        insertRow -= toSubstract;
                    }

                    playlist.removeAll(tracks);
                } else {
                    int selectedRow = table.getSelectedRow();
                    if (selectedRow != -1)
                        insertRow = selectedRow + 1;
                    else
                        insertRow = -1;
                }

                if (insertRow == -1)
                    insertRow = playlist.size();

                playlist.addAll(insertRow, tracks);
                playlist.firePlaylistChanged();
                table.setRowSelectionInterval(insertRow, insertRow + tracks.size() - 1);
                tracks.clear();
                return true;
            }
View Full Code Here

    @Override
    protected void exportDone(JComponent source, Transferable data, int action) {
        try {
            if (data.isDataFlavorSupported(SongsSelection.getFlavor())) {
                List<Track> tracks = (List<Track>) data.getTransferData(SongsSelection.getFlavor());
                Playlist playlist = table.getPlaylist();

                if (action == MOVE) {
                    playlist.removeAll(tracks);
                    table.update();
                } else if (action == COPY) {
                    ArrayList<Track> temp = new ArrayList<Track>();
                    for (Track track : tracks) {
                        temp.add(new Track(track));
View Full Code Here

                }
                searchWorker = new SearchWorker(playlist, searchField.getText(), false) {
                    @Override
                    protected void done() {
                        try {
                            Playlist result = get();
                            if (result != null) {
                                viewToModel.clear();
                                viewToModel.addAll(viewToModelList);
                                view.clear();
                                view.addAll(result);
                                table.update();
                                if (result.size() > 0) {
                                    table.clearSelection();
                                    table.getSelectionModel().setSelectionInterval(0, 0);
                                }
                                result.clear();
                                result.trimToSize();
                                viewToModelList.clear();
                                viewToModelList.trimToSize();
                            }
                        } catch (Exception ignored) {
                        }
View Full Code Here

TOP

Related Classes of com.tulskiy.musique.playlist.Playlist

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.