Package displayables

Source Code of displayables.DirectoryEditor

package displayables;

import jMp3Tag.Tag;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

public class DirectoryEditor extends Form {

  Vector files;
    int controls_init = 0;
  public DirectoryEditor(String title) {
    super(title);
    files = new Vector();
    this.append("Los siguientes archivos seran modificados.\n\n");
    this.getFileList(title);
    this.append("Los campos vacios ser�n ignorados");
    if (files.isEmpty()) {
      this.deleteAll();
      this.append("No se encontraron archivos MP3");
      return;
    }
    controls_init = this.size();
    this.append(new TextField("Album", "", 30, TextField.ANY));
    this.append(new TextField("Compositor", "", 30, TextField.ANY));
    this.append(new TextField("Artista", "", 30, TextField.ANY));
    this.append(new TextField("A�o", "", 4, TextField.ANY));
  }

  protected void getFileList(String path) {
    try {
      // Opens a file connection in READ mode
      FileConnection fc = (FileConnection) Connector.open(path,
          Connector.READ);
      Enumeration filelist = fc.list("*", true); // also hidden files are
      String filename;
      while (filelist.hasMoreElements()) {
        filename = (String) filelist.nextElement();
        fc = (FileConnection) Connector.open(path + filename,
            Connector.READ);
        if (fc.isDirectory()) { // checks if fc is a directory
          this.getFileList(path + filename);
        } else {
          if (filename.endsWith(".mp3")) {
            this.append(filename + "\n");
            files.addElement(path + filename);
          }
        }
      }
      fc.close();
    } catch (IOException ioe) {
      System.out.println("IOException: " + ioe.getMessage());
    } catch (SecurityException se) {
      System.out.println("SecurityException: " + se.getMessage());
    }
  }

  public void saveTag() {
    for (int i = 0; i < files.size(); i++) {
      Tag t = new Tag((String) files.elementAt(i));
      try {
        t.Read();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      System.out.println("Comienza guardado");
      TextField text;
      text = (TextField) this.get(controls_init+0);
      System.out.println("Title:" + text.getString());
      if (text.getString().compareTo("") != 0) {
        t.setAlbum(text.getString());
        System.out.println("Album <= " + text.getString());
      }

      text = (TextField) this.get(controls_init+1);
      System.out.println("Title:" + text.getString());
      if (text.getString().compareTo("") != 0) {
        t.setComposer(text.getString());
        System.out.println("Composer <= " + text.getString());
      }

      text = (TextField) this.get(controls_init+2);
      if (text.getString().compareTo("") != 0) {
        t.setArtist(text.getString());
        System.out.println("Artist <= " + text.getString());
      }

      text = (TextField) this.get(controls_init+3);
      if (text.getString().compareTo("") != 0) {
        t.setYear(text.getString());
        System.out.println("Year <= " + text.getString());
      }
      try {
        t.Save(true);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

}
TOP

Related Classes of displayables.DirectoryEditor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.