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.FileWriter;
00013 import java.io.IOException;
00014 import javax.swing.JDialog;
00015 import javax.swing.JFileChooser;
00016 import javax.swing.filechooser.FileFilter;
00017 import org.jaudiotagger.audio.exceptions.CannotReadException;
00018 import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
00019 import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
00020 import org.jaudiotagger.tag.TagException;
00021
00022
00023
00041 public final class PlayListNewDlg extends JDialog implements ActionListener
00042 {
00043
00044
00045 private static PlayListNewDlg instance = new PlayListNewDlg();
00046
00047
00048
00049
00050 private JFileChooser fc = new JFileChooser();
00051
00052
00053
00068 private PlayListNewDlg()
00069 {
00070 setTitle("Wiedergabeliste anlegen");
00071 setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
00072 fc.setDialogType(JFileChooser.SAVE_DIALOG);
00073 fc.setAcceptAllFileFilterUsed(false);
00074 fc.setFileFilter(createFilter());
00075 fc.addActionListener(this);
00076 add(fc);
00077 }
00078
00079
00080
00088 public static PlayListNewDlg getInstance() { return instance; }
00089
00090
00091
00101 public void run()
00102 {
00103 pack();
00104 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
00105 int y = (int)((dim.getHeight()/2)-(getHeight()/2));
00106 int x = (int)((dim.getWidth()/2)-(getWidth()/2));
00107 setLocation(x, y);
00108 setVisible(true);
00109 }
00110
00111
00112
00121 private FileFilter createFilter()
00122 {
00123 FileFilter filefilter = new FileFilter()
00124 {
00132 @Override
00133 public boolean accept(File f)
00134 {
00135
00136
00137
00138 if (f.isDirectory())
00139 {
00140 return true;
00141 }
00142
00143 String extension = Utils.getExtension(f);
00144 if (extension != null)
00145 {
00146
00147
00148
00149
00150
00151 return (extension.equals(Utils.m3u)
00152 || extension.equals(Utils.cue)) ? true : false;
00153 }
00154
00155
00156 return false;
00157 }
00158
00159
00160
00172 public String getDescription(File f)
00173 {
00174 String ext = Utils.getExtension(f);
00175 if (ext.equals(Utils.m3u)) return "*.m3u";
00176 if (ext.equals(Utils.cue)) return "*.cue";
00177 return "*.*";
00178 }
00179
00180
00181
00188 public String getDescription()
00189 {
00190 return "Wiedergabelisten (m3u, cue)";
00191 }
00192 };
00193 return filefilter;
00194 }
00195
00196
00197
00209 public void actionPerformed(ActionEvent e)
00210 {
00211 try
00212 {
00213 setVisible(false);
00214 if (e.getActionCommand().equals("ApproveSelection"))
00215 {
00216 String filename = fc.getSelectedFile().getAbsolutePath();
00217 String extension = Utils.getExtension(new File(filename));
00218 if (extension != null) {
00219 if ((extension.equals(Utils.cue))
00220 || (extension.equals(Utils.m3u)))
00221 {
00222 FileWriter f = new FileWriter(filename);
00223 f.close();
00224 PlayList.getInstance().setPlayList(filename);
00225 Layer.getInstance().PlayListChange();
00226 } else {
00227 throw new PlayListException(200);
00228 }
00229 } else {
00230 PlayListAuswahlDlg.getInstance().run(filename);
00231 }
00232 }
00233 }
00234 catch (IOException ex){ ErrorMsg.show(ex.getMessage()); }
00235 catch (PlayListException ex) { ErrorMsg.show(ex.getMessage()); }
00236 catch (CannotReadException ex) { ErrorMsg.show(ex.getMessage()); }
00237 catch (TagException ex) { ErrorMsg.show(ex.getMessage()); }
00238 catch (ReadOnlyFileException ex) { ErrorMsg.show(ex.getMessage()); }
00239 catch (InvalidAudioFrameException ex) {ErrorMsg.show(ex.getMessage());}
00240 }
00241 }