private void btnAddSongsActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed if (musicLibraryAgent != null) { int selectedViewRow = tblCollectionLists.getSelectedRow(); if (selectedViewRow != -1 && musicLibraryAgent != null && musicLibraryAgent.getMusicLibrary() != null) { int selectedModelRow = tblCollectionLists.convertRowIndexToModel(selectedViewRow); SongCollection selectedCollection = musicLibraryAgent.getMusicLibrary().get(selectedModelRow); if (selectedCollection != null && selectedCollection.getSongsList() != null) { // **** int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); List<File> fileList = new ArrayList<File>(); List<CollectionSong> songList = new ArrayList<CollectionSong>(); for (File file : files) { // This is where a real application would open the file. System.out.println( "Addint: " + file.getName() + " : " + file.getAbsolutePath() + "\n"); CollectionSong song = (CollectionSong) CollectionSong.getInstance(file.getAbsolutePath(), file.getName(), null); // song.setPath( file.getAbsolutePath() ); // song.setName( file.getLibraryName() ); songList.add(song); // TODO: send to feature extraction // String[] row = {file.getLibraryName(), file.getAbsolutePath()}; // ( (DefaultTableModel) tblCollectionLists.getModel() ).addRow( row ); // ( (DefaultTableModel) jTableListners.getModel() ).addRow( row ); // ( (DefaultTableModel) tblSongClasses.getModel() ).addRow( row ); } if (!songList.isEmpty()) { selectedCollection.getSongsList().addAll(songList); musicLibraryAgent.setLibraryUpdatesToBeSentToDj(true); } ((AbstractTableModel) tblCollectionSongs.getModel()).fireTableDataChanged(); } else { System.out.println("Open command cancelled by user."); } } } else { JOptionPane.showMessageDialog(this, "Please select collection to add songs"); } } else { System.out.println("Music library is not available for the GUI"); } } // GEN-LAST:event_jButton1ActionPerformed
private void btnAddCollectionActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed String res = JOptionPane.showInputDialog("Enter Collection Name:"); if (res == null || res.isEmpty()) { res = "New Collection"; } SongCollection collection = new SongCollection(); collection.setName(res); collection.setEnabled(true); collection.setSequenced(false); if (!musicLibraryAgent.getMusicLibrary().contains(collection)) { musicLibraryAgent.getMusicLibrary().add(collection); } else { String originalName = collection.getName(); for (int suffix = 0; suffix < 100; suffix++) { collection.setName(originalName + suffix); if (!musicLibraryAgent.getMusicLibrary().contains(collection)) { musicLibraryAgent.getMusicLibrary().add(collection); break; } } } musicLibraryAgent.setLibraryUpdatesToBeSentToDj(true); ((AbstractTableModel) tblCollectionLists.getModel()).fireTableDataChanged(); }