Files
notizheftanzeiger/Notebook.pde

77 lines
2.0 KiB
Plaintext

class Notebook {
String notebookpath;
String[] imagepaths;
String dateText;
int year;
int id;
Notebook(int id_, String notebookpath_, String[] imagepaths_) {
id = id_;
notebookpath = dataPath("") + "/Notizhefte/" + notebookpath_;
imagepaths = Arrays.copyOfRange(imagepaths_, 1, imagepaths_.length-1);
String[] separated = notebookpath_.split("-");
dateText = (getMonth(int(separated[1])) + " " + separated[0]);
year = int(separated[0]);
}
}
String getMonth(int id) {
switch(id) {
case(1):
return("January");
case(2):
return("February");
case(3):
return("March");
case(4):
return("April");
case(5):
return("May");
case(6):
return("June");
case(7):
return("July");
case(8):
return("August");
case(9):
return("September");
case(10):
return("October");
case(11):
return("November");
case(12):
return("December");
default:
return " ";
}
}
ArrayList<Notebook> notebooks = new ArrayList<Notebook>();
void createNotebooks() {
File datafolder = new File(dataPath("") + "/Notizhefte");
String[] notebooknames = datafolder.list();
notebooknames = sort(notebooknames);
int notebookID = 0;
for (int i = 0; i < notebooknames.length; i++) {
File notebookfolder = new File(dataPath("") + "/Notizhefte/" + notebooknames[i]);
if (notebookfolder.list() != null) {
String[] imagenames = notebookfolder.list();
List<String> strings = Arrays.asList(imagenames);
Collections.sort(strings, new Comparator<String>() {
public int compare(String o1, String o2) {
return extractInt(o1) - extractInt(o2);
}
int extractInt(String s) {
String num = s.replaceAll("\\D", "");
return num.isEmpty() ? 0 : Integer.parseInt(num);
}
}
);
imagenames = strings.toArray(imagenames);
notebooks.add(new Notebook(notebookID, notebooknames[i], imagenames));
notebookID ++;
}
}
}