playlistSelectDialog = new JDialog(frame, "Select Playlist", true); playlistSelectList = new JList(availablePlaylists); playlistSelectList. setSelectionMode(ListSelectionModel.SINGLE_SELECTION); PlaylistListSelectionHandler listSelectionHandler = new PlaylistListSelectionHandler(); playlistSelectList. addListSelectionListener(listSelectionHandler); JScrollPane playlistSelectScrollPane = new JScrollPane(playlistSelectList); playlistSelectDialog.getContentPane(). add(playlistSelectScrollPane); playlistSelectDialog.pack(); playlistSelectDialog.show();
showPlaylistSelectDialog();
		public void actionPerformed(ActionEvent e)		{			String actionCommand = e.getActionCommand();			String commandToSend = "";			if (actionCommand.equals("Previous Song"))			{				ioHandler.sendPlay(currentPlaylistIndex - 1);			}			else if (actionCommand.equals("Rewind"))			{				ioHandler.sendSkipBack();			}			else if (actionCommand.equals("Play") ||				actionCommand.equals("Pause") ||				actionCommand.equals("Unpause"))			{				if (playState == PS_STOPPED)				{					ioHandler.sendPlay(currentPlaylistIndex);				}				else if (playState == PS_PLAYING)				{					ioHandler.sendPause();				}				else if (playState == PS_PAUSED)				{					ioHandler.sendPause();				}			}			else if (actionCommand.equals("Stop"))			{				// playState will be changed when we get the acknowledgement				// message back from the server.				ioHandler.sendStop();			}			else if (actionCommand.equals("Fast Forward"))			{				ioHandler.sendSkipForward();			}			else if (actionCommand.equals("Next Song"))			{				ioHandler.sendPlay(currentPlaylistIndex + 1);			}			else if (actionCommand.equals("Remove Song(s)"))			{				Object[] songsToDelete = playlistList.getSelectedValues();				for (int i=0 ; i<songsToDelete.length ; ++i)				{					ioHandler.sendDeleteSongFromPlaylist(						(String) songsToDelete[i]);				}			}			else if (actionCommand.equals("Add Song(s)"))			{				availableSongs.removeAllElements();				ioHandler.sendGetAvailableSongs();				// Wait for up to 45 seconds to get a list of songs back				// from the server				for (int i=0 ; i<45 && availableSongs.size()==0 ; i++)				{					// It would be cool if we popped up some sort of					// progress dialog here					try					{						Thread.sleep(1000);					}					catch (InterruptedException ie)					{					}				}				if (availableSongs.size() == 0)				{					JOptionPane.showMessageDialog(frame,						"No songs received from server",						"Error", JOptionPane.ERROR_MESSAGE);					return;				}				else				{					songSelectDialog = new JDialog(frame, "Select Song(s)",						true);					songSelectList = new JList(availableSongs);					//songSelectList.						//setSelectionMode(ListSelectionModel.SINGLE_SELECTION);					//SongListSelectionHandler listSelectionHandler =						//new SongListSelectionHandler();					//songSelectList.						//addListSelectionListener(listSelectionHandler);					SongDialogActionHandler actionHandler =						new SongDialogActionHandler();					JScrollPane songSelectScrollPane =						new JScrollPane(songSelectList);					JButton okButton = new JButton("OK");					okButton.addActionListener(actionHandler);					JButton cancelButton = new JButton("Cancel");					cancelButton.addActionListener(actionHandler);					JPanel buttonPanel = new JPanel();					buttonPanel.add(okButton);					buttonPanel.add(cancelButton);					songSelectDialog.getContentPane().						add(songSelectScrollPane, BorderLayout.CENTER);					songSelectDialog.getContentPane().						add(buttonPanel, BorderLayout.SOUTH);					songSelectDialog.pack();					songSelectDialog.show();				}			}			else if (actionCommand.equals("Load Playlist"))			{				availablePlaylists.removeAllElements();				ioHandler.sendGetAvailablePlaylists();				// Wait for up to 15 seconds to get a set of playlists back				// from the server				for (int i=0 ; i<15 && availablePlaylists.size()==0 ; i++)				{					try					{						Thread.sleep(1000);					}					catch (InterruptedException ie)					{					}				}				if (availablePlaylists.size() == 0)				{					JOptionPane.showMessageDialog(frame,						"No playlists received from server",						"Error", JOptionPane.ERROR_MESSAGE);					return;				}				else				{					playlistSelectDialog = new JDialog(frame, "Select Playlist",						true);					playlistSelectList = new JList(availablePlaylists);					playlistSelectList.						setSelectionMode(ListSelectionModel.SINGLE_SELECTION);					PlaylistListSelectionHandler listSelectionHandler =						new PlaylistListSelectionHandler();					playlistSelectList.						addListSelectionListener(listSelectionHandler);					JScrollPane playlistSelectScrollPane =						new JScrollPane(playlistSelectList);					playlistSelectDialog.getContentPane().						add(playlistSelectScrollPane);					playlistSelectDialog.pack();					playlistSelectDialog.show();				}			}			else if (actionCommand.equals("Save Playlist"))			{				fileChooser.setCurrentDirectory(new File(songDirectory));				fileChooser.rescanCurrentDirectory();				fileChooser.setFileFilter(playlistFileFilter);				int returnVal = fileChooser.showSaveDialog(frame);				if (returnVal == JFileChooser.APPROVE_OPTION)				{					PrintWriter playlistWriter = null;					try					{						playlistWriter = new PrintWriter(							new FileWriter(fileChooser.								getSelectedFile().getAbsolutePath()));					}					catch (IOException savePlaylistIOException)					{						JOptionPane.showMessageDialog(frame,							"Can't write to playlist file " + 							fileChooser.getSelectedFile().getAbsolutePath(),							"Error", JOptionPane.ERROR_MESSAGE);						return;					}					for (Enumeration savePlaylistEnumeration =						playlist.elements();						savePlaylistEnumeration.hasMoreElements();)					{						playlistWriter.println(							savePlaylistEnumeration.nextElement());					}					playlistWriter.close();				}			}			else if (actionCommand.equals("Clear Playlist"))			{				ioHandler.sendClearPlaylist();			}			//else if (actionCommand.equals("Quit"))			else if (actionCommand.equals("Exit"))			{				System.exit(0);			}		}