00001 package i2bpro.layer.Dialogs;
00002
00003 import i2bpro.Exceptions.ErrorMsg;
00004 import i2bpro.Exceptions.PlayListException;
00005 import i2bpro.layer.Layer;
00006 import i2bpro.playlist.PlayList;
00007 import java.awt.Dimension;
00008 import java.awt.Toolkit;
00009 import java.awt.event.ActionEvent;
00010 import java.awt.event.ActionListener;
00011 import java.io.File;
00012 import java.io.FileNotFoundException;
00013 import java.io.IOException;
00014 import javax.swing.*;
00015 import javax.swing.filechooser.FileFilter;
00016 import org.jaudiotagger.audio.exceptions.CannotReadException;
00017 import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
00018 import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
00019 import org.jaudiotagger.tag.TagException;
00020
00021
00022
00041 public final class PlayListOpenDlg extends JDialog implements ActionListener
00042 {
00043
00044
00045 private static PlayListOpenDlg instance = new PlayListOpenDlg();
00046
00047
00048
00049 private JFileChooser fc = new JFileChooser();
00050
00051
00052
00067 private PlayListOpenDlg()
00068 {
00069 setTitle("Wiedergabeliste öffnen");
00070 setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
00071 fc.setDialogType(JFileChooser.OPEN_DIALOG);
00072 fc.setAcceptAllFileFilterUsed(false);
00073 fc.setFileFilter(createFilter());
00074 fc.addActionListener(this);
00075 add(fc);
00076 }
00077
00078
00079
00087 public static PlayListOpenDlg getInstance() { return instance; }
00088
00089
00090
00100 public void run()
00101 {
00102 pack();
00103 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
00104 int y = (int)((dim.getHeight()/2)-(getHeight()/2));
00105 int x = (int)((dim.getWidth()/2)-(getWidth()/2));
00106 setLocation(x, y);
00107 setVisible(true);
00108 }
00109
00110
00111
00120 private FileFilter createFilter()
00121 {
00122 FileFilter filefilter = new FileFilter()
00123 {
00131 @Override
00132 public boolean accept(File file)
00133 {
00134
00135
00136
00137 if (file.isDirectory())
00138 {
00139 return true;
00140 }
00141
00142 String extension = Utils.getExtension(file);
00143 if (extension != null)
00144 {
00145
00146
00147
00148
00149
00150 return (extension.equals(Utils.m3u)
00151 || extension.equals(Utils.cue)) ? true : false;
00152 }
00153
00154
00155 return false;
00156 }
00157
00158
00159
00171 public String getDescription(File file)
00172 {
00173 String ext = Utils.getExtension(file);
00174 if (ext.equals(Utils.mp3)) return "Wiedergabeliste m3u";
00175 if (ext.equals(Utils.wav)) return "Wiedergabeliste cue";
00176 return null;
00177 }
00178
00179
00186 public String getDescription()
00187 {
00188 return "Wiedergabelisten (m3u, cue)";
00189 }
00190 };
00191 return filefilter;
00192 }
00193
00194
00195
00206 public void actionPerformed(ActionEvent e)
00207 {
00208 setVisible(false);
00209 if (e.getActionCommand().equals("ApproveSelection"))
00210 {
00211 try
00212 {
00213 PlayList.getInstance().setPlayList(
00214 fc.getSelectedFile().getAbsolutePath());
00215 Layer.getInstance().PlayListChange();
00216 }
00217 catch (PlayListException ex) {ErrorMsg.show(ex.getMessage());}
00218 catch (FileNotFoundException ex) {ErrorMsg.show(ex.getMessage());}
00219 catch (IOException ex) {ErrorMsg.show(ex.getMessage());}
00220 catch (CannotReadException ex) {ErrorMsg.show(ex.getMessage());}
00221 catch (TagException ex) {ErrorMsg.show(ex.getMessage());}
00222 catch (ReadOnlyFileException ex) {ErrorMsg.show(ex.getMessage());}
00223 catch (InvalidAudioFrameException ex) {ErrorMsg.show(ex.getMessage());}
00224 }
00225 }
00226 }