Example usage for javax.swing JProgressBar revalidate

List of usage examples for javax.swing JProgressBar revalidate

Introduction

In this page you can find the example usage for javax.swing JProgressBar revalidate.

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:projectresurrection.Music.java

public void addSongs(String dir) {
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            File directory = new File(dir);
            JProgressBar progress = (JProgressBar) pnlAdd.getComponent(3);
            progress.setValue(0);//from   w w w  .j ava  2  s . c o m
            files = new ArrayList();
            List tempSongs = new ArrayList();
            Map<String, Map> artists = fileData.get("artists");
            getFiles(directory);
            List<File> mp3s = new ArrayList();
            for (int i = 0; i < files.size(); i++) {
                if (FilenameUtils.getExtension(files.get(i).getAbsolutePath()).equals("mp3")) {
                    mp3s.add(files.get(i));
                }
            }
            for (int i = 0; i < mp3s.size(); i++) {
                try {
                    File file = mp3s.get(i);
                    File tempFile = new File(FOLDER.getAbsolutePath() + "\\" + file.getName());
                    String name;
                    if (tempFile.exists()) {
                        String prevName = file.getName();
                        name = ("(1)" + file.getName());
                        int j = 2;
                        while (new File(FOLDER.getAbsoluteFile() + "\\" + name).exists()) {
                            name = "(" + j + ")" + file.getName();
                            j++;
                        }
                        file.renameTo(new File(file.getParent() + "\\" + name));
                        file = new File(file.getParent() + "\\" + name);
                        FileUtils.copyFileToDirectory(new File(file.getAbsolutePath()), FOLDER);
                        file.renameTo(new File(file.getParent() + "\\" + prevName));
                        file = new File(FOLDER.getAbsolutePath() + "\\" + name);
                    } else {
                        FileUtils.copyFileToDirectory(file.getAbsoluteFile(), FOLDER);
                        file = new File(FOLDER.getAbsolutePath() + "\\" + file.getName());
                    }
                    Mp3File song = new Mp3File(file.getAbsolutePath());
                    ID3v2 tag = song.getId3v2Tag();
                    if (tag.getArtist() == null || tag.getArtist().equals("")) {
                        tag.setArtist("Unknown");
                    }
                    if (tag.getAlbum() == null || tag.getAlbum().equals("")) {
                        tag.setAlbum("Unknown");
                    }
                    if (tag.getTitle() == null || tag.getTitle().equals("")) {
                        tag.setTitle("Unknown");
                    }
                    if (songs.containsKey(tag.getTitle())) {
                        String title = tag.getTitle() + "(1)";
                        int j = 2;
                        while (tempSongs.contains(title)) {
                            title = tag.getTitle() + "(" + j + ")";
                            j++;
                        }
                        tag.setTitle(title);
                    }
                    if (tag.getTrack() == null || tag.getTrack().equals("")) {
                        tag.setTrack("-1");
                    }
                    if (!artists.containsKey(tag.getArtist())) {
                        artists.put(tag.getArtist(), new HashMap<String, Map>());
                    }
                    if (!artists.get(tag.getArtist()).containsKey(tag.getAlbum())) {
                        artists.get(tag.getArtist()).put(tag.getAlbum(), new HashMap<String, List>());
                    }
                    ((Map) artists.get(tag.getArtist()).get(tag.getAlbum())).put(tag.getTitle(),
                            Arrays.asList(file.getName(), tag.getTrack(), false));
                    songs.put(tag.getTitle(), Arrays.asList(file.getName(), tag.getTrack()));
                    progress.setValue(((i + 1) * 100) / mp3s.size());
                    progress.revalidate();
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                }
            }
            fileData = new HashMap();
            fileData.put("artists", artists);
            xmlWrite(MUSIC_FILE, fileData);
            update();
        }
    });
    t1.start();
}