Logo Search packages:      
Sourcecode: jlgui version File versions  Download package

void javazoom::jlgui::player::amp::tag::ui::TagSearch::searchList ( String  searchString  )  [inline, private]

Searches the playlist for a song containing the words in the given search string. It searches on the title, artist, album and filename of each song in the playlist.

Parameters:
searchString The string to search for in all songs in the playlist

Definition at line 201 of file TagSearch.java.

References javazoom::jlgui::player::amp::tag::TagInfo::getAlbum(), javazoom::jlgui::player::amp::tag::TagInfo::getArtist(), javazoom::jlgui::player::amp::tag::TagInfo::getTitle(), and search().

    {
        String[] s = searchString.split(" ");
        String lastS = "";
        if (s.length > 0) lastS = s[s.length - 1];
        if (lastS.equals(""))
        {
            list.setModel(m);
            restrictedPlaylist = _playlist;
        }
        else
        {
            DefaultListModel newModel = new DefaultListModel();
            if (lastSearch != null)
            {
                if (searchString.length() <= 1 || !searchString.substring(searchString.length() - 2).equals(lastSearch))
                {
                    list.setModel(m);
                    restrictedPlaylist = _playlist;
                }
            }
            Vector pI = restrictedPlaylist;
            restrictedPlaylist = new Vector();
            for (int a = 0; a < s.length; a++)
            {
                String currentS = s[a];
                int size = list.getModel().getSize();
                boolean[] remove = new boolean[size];
                for (int i = 0; i < size; i++)
                {
                    final int TITLE_SEARCH = 0;
                    final int ARTIST_SEARCH = 1;
                    final int ALBUM_SEARCH = 2;
                    final int FILENAME_SEARCH = 3;
                    TagInfo pli = ((PlaylistItem) pI.get(i)).getTagInfo();
                    remove[i] = false;
                    boolean found = false;
                    int searchType;
                    if (artist.isSelected())
                    {
                        searchType = ARTIST_SEARCH;
                    }
                    else if (album.isSelected())
                    {
                        searchType = ALBUM_SEARCH;
                    }
                    else if (title.isSelected())
                    {
                        searchType = TITLE_SEARCH;
                    }
                    else
                    {
                        searchType = -1;
                    }
                    for (int j = 0; j <= FILENAME_SEARCH; j++)
                    {
                        String listString = "";
                        if (pli == null)
                        {
                            if (searchType != -1)
                            {
                                break;
                            }
                            j = FILENAME_SEARCH;
                        }
                        else if (searchType != -1)
                        {
                            j = searchType;
                        }
                        switch (j)
                        {
                            case (TITLE_SEARCH):
                                if (pli.getTitle() != null) listString = pli.getTitle().toLowerCase();
                                break;
                            case (ARTIST_SEARCH):
                                if (pli.getArtist() != null) listString = pli.getArtist().toLowerCase();
                                break;
                            case (ALBUM_SEARCH):
                                if (pli.getAlbum() != null) listString = pli.getAlbum().toLowerCase();
                                break;
                            case (FILENAME_SEARCH):
                                String location = ((PlaylistItem) pI.get(i)).getLocation().toLowerCase();
                                listString = location.substring(location.lastIndexOf(sep) + 1, location.lastIndexOf("."));
                                break;
                        }
                        currentS = currentS.toLowerCase();
                        if (found = search(currentS, listString))
                        {
                            break;
                        }
                        if (searchType != -1)
                        {
                            break;
                        }
                    }
                    //if(found)foundAt[a] = i;
                    if (found && a == 0)
                    {
                        //todo new
                        newModel.addElement(getDisplayString((PlaylistItem) pI.get(i)));
                        restrictedPlaylist.add(pI.get(i));
                    }
                    if (!found && a != 0)
                    {
                        remove[i] = true;
                    }
                }
                //remove all unmatching items
                for (int x = size - 1; x >= 0; x--)
                {
                    if (remove[x])
                    {
                        newModel.remove(x);
                        restrictedPlaylist.remove(x);
                    }
                }
                pI = restrictedPlaylist;
                list.setModel(newModel);
            }
            list.setModel(newModel);
            lastSearch = searchField.getText();
        }
        if (list.getModel().getSize() > 0) list.setSelectedIndex(0);
    }


Generated by  Doxygen 1.6.0   Back to index