00001 package i2bpro.layer.Dialogs;
00002
00003 import i2bpro.Exceptions.ErrorMsg;
00004 import i2bpro.playlist.PlayList;
00005 import java.awt.Dimension;
00006 import java.awt.Toolkit;
00007 import java.awt.event.ActionEvent;
00008 import java.awt.event.ActionListener;
00009 import java.io.File;
00010 import java.io.IOException;
00011 import javax.swing.JDialog;
00012 import javax.swing.JFileChooser;
00013 import javax.swing.filechooser.FileFilter;
00014 import org.jaudiotagger.audio.exceptions.CannotReadException;
00015 import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
00016 import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
00017 import org.jaudiotagger.tag.TagException;
00018
00019
00020
00039 public final class InsertMediaDlg extends JDialog implements ActionListener
00040 {
00041
00042
00043 private static InsertMediaDlg instance = new InsertMediaDlg();
00044
00045
00046
00047 private JFileChooser fc = new JFileChooser();
00048
00049
00050
00065 private InsertMediaDlg()
00066 {
00067 setTitle("Audiodateien hinzufügen");
00068 setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
00069 fc.setDialogType(JFileChooser.OPEN_DIALOG);
00070 fc.setFileFilter(createFilter());
00071 fc.setAcceptAllFileFilterUsed(false);
00072 fc.setApproveButtonText("Hinzufügen");
00073 fc.setApproveButtonToolTipText("Audiodateien der Wiedergabeliste hinzufügen");
00074 fc.setMultiSelectionEnabled(true);
00075 fc.addActionListener(this);
00076 add(fc);
00077 }
00078
00079
00080
00089 public static InsertMediaDlg getInstance() { return instance; }
00090
00091
00092
00102 public void run()
00103 {
00104 pack();
00105 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
00106 int y = (int)((dim.getHeight()/2)-(getHeight()/2));
00107 int x = (int)((dim.getWidth()/2)-(getWidth()/2));
00108 setLocation(x, y);
00109 setVisible(true);
00110 }
00111
00112
00113
00122 private FileFilter createFilter()
00123 {
00124 FileFilter filefilter = new FileFilter()
00125 {
00133 @Override
00134 public boolean accept(File f)
00135 {
00136
00137
00138
00139 if (f.isDirectory())
00140 {
00141 return true;
00142 }
00143
00144 String extension = Utils.getExtension(f);
00145 if (extension != null)
00146 {
00147
00148
00149
00150
00151
00152 return (extension.equals(Utils.wav)
00153 || extension.equals(Utils.mp3)) ? true : false;
00154 }
00155
00156
00157 return false;
00158 }
00159
00160
00161
00173 public String getDescription(File f)
00174 {
00175 String ext = Utils.getExtension(f);
00176 if (ext.equals(Utils.mp3)) return "*.mp3";
00177 if (ext.equals(Utils.wav)) return "*.wav";
00178 return "*.*";
00179 }
00180
00187 public String getDescription()
00188 {
00189 return "Audiodateien (mp3, wav)";
00190 }
00191
00192 };
00193 return filefilter;
00194 }
00195
00196
00197
00208 public void actionPerformed(ActionEvent e)
00209 {
00210 setVisible(false);
00211 if (e.getActionCommand().equals("ApproveSelection"))
00212 {
00213 try
00214 {
00215 PlayList.getInstance().InsertMedia(fc.getSelectedFiles());
00216 }
00217 catch (CannotReadException ex) { ErrorMsg.show(ex.getMessage()); }
00218 catch (IOException ex) { ErrorMsg.show(ex.getMessage()); }
00219 catch (TagException ex) { ErrorMsg.show(ex.getMessage()); }
00220 catch (ReadOnlyFileException ex) { ErrorMsg.show(ex.getMessage()); }
00221 catch (InvalidAudioFrameException ex) { ErrorMsg.show(ex.getMessage()); }
00222 }
00223 }
00224 }