* Saves the pattern as a text file
* @param filename the filename to save under
*/
public void savePattern(File file) throws IOException
{
BufferedWriter out = new BufferedWriter(new FileWriter(file));
if ((getProperties().size() > 0) || (getTitle() != null)) {
out.write("#\n");
if (getTitle() != null) {
out.write("# ");
out.write("Title: ");
out.write(getTitle());
out.write("\n");
}
Iterator<String> iter = getProperties().keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
if (!key.equals(TITLE)) {
String value = getProperty(key);
out.write("# ");
out.write(key);
out.write(": ");
out.write(value);
out.write("\n");
}
}
out.write("#\n");
out.write("\n");
}
String musicString = getMusicString();
while (musicString.length() > 0) {
if ((musicString.length() > 80) && (musicString.indexOf(' ', 80) > -1)) {
int indexOf80ColumnSpace = musicString.indexOf(' ', 80);
out.write(musicString.substring(0, indexOf80ColumnSpace));
out.newLine();
musicString = musicString.substring(indexOf80ColumnSpace, musicString.length());
} else {
out.write(musicString);
musicString = "";
}
}
out.close();
}