package edu.chl.proton.model;

import java.io.*;
import java.util.List;
import java.text.SimpleDateFormat;


/**
 * @author Stina Werme
 * Created by stinawerme on 01/05/17.
 */
public class File extends FileSystemEntity {

    private boolean isSaved;


    public File(String name) {
        this.setName(name);
    }

    protected void setIsSaved(boolean state) {
        isSaved = state;
    }

    protected boolean isSaved() {
        return isSaved;
    }

    protected void save(List<String> text) throws IOException {
        try {

            java.io.File file = new java.io.File(this.getPath());
            BufferedWriter out = new BufferedWriter(new FileWriter(file));
            System.out.println("hej");
            for(String line : text) {
                out.write(line);
                out.newLine();
            }
            out.close();
            setIsSaved(true);
        } catch (IOException e) {

        }
    }

    // TODO
    protected String lastEdited() {

        File file = new File("C:\\Myfile.txt");

        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

        return "sdf.format(file.lastModified())";
    }

    protected void remove() {
        this.getFile().delete();
    }

    // Aqcuires the text from the file we opened.
    protected void aqcuireText(){

        // This will reference one line at a time
        String line = null;

        try {
            // FileReader reads text files in the default encoding.
            FileReader fileReader =
                    new FileReader(file.getName());

            // Always wrap FileReader in BufferedReader.
            BufferedReader bufferedReader =
                    new BufferedReader(fileReader);

            while((line = bufferedReader.readLine()) != null) {
                lines.add(line);
            }

            // Close file.
            bufferedReader.close();
        }
        catch(FileNotFoundException ex) {
            System.out.println(
                    "Unable to open file '" +
                            file.getName() + "'");
        }
        catch(IOException ex) {
            System.out.println(
                    "Error reading file '"
                            + file.getName() + "'");
        }


    }

}


@@ -993,24 +993,32 @@
  %7B%0A%0A        
+java.io.
 File file = 
@@ -1025,29 +1025,30 @@
 new 
-File(%22C:%5C%5CMyfile.txt%22
+java.io.File(getName()
 );%0A%0A
@@ -1139,17 +1139,16 @@
  return 
-%22
 sdf.form
@@ -1170,17 +1170,16 @@
 ified())
-%22
 ;%0A    %7D%0A
@@ -1566,21 +1566,16 @@
 eReader(
-file.
 getName(
@@ -2066,21 +2066,16 @@
         
-file.
 getName(
@@ -2201,16 +2201,16 @@
 file '%22%0A
+
         
@@ -2231,21 +2231,16 @@
       + 
-file.
 getName(

Fix lastEdited