use of electric.xml.Document in project blue by kunstmusik.
the class BlueData method load.
/**
* Utility method to load BlueData from File; does not alert user if upgrade
* happened from pre 0.94.0 file. Useful for scripting.
*
* @param f
* @return
* @throws Exception
*/
public static BlueData load(File f) throws Exception {
String text = TextUtilities.getTextFromFile(f);
BlueData tempData = null;
if (text.startsWith("<blueData")) {
Document d = new Document(text);
tempData = BlueData.loadFromXML(d.getElement("blueData"));
}
return tempData;
}
use of electric.xml.Document in project blue by kunstmusik.
the class BlueSystem method getCodeRepository.
public static File getCodeRepository() {
File repository = new File(blue.BlueSystem.getUserConfigurationDirectory() + File.separator + "codeRepository.xml");
if (!repository.exists()) {
System.out.println("Copying default code repository to user configuration directory");
try {
Document doc = new Document(BlueSystem.class.getResourceAsStream("codeRepository.xml"));
doc.write(repository);
} catch (ParseException | IOException ex) {
ExceptionHandler.printStackTrace(ex);
}
}
return repository;
}
use of electric.xml.Document in project blue by kunstmusik.
the class BlueSystem method getUserInstrumentLibrary.
public static InstrumentLibrary getUserInstrumentLibrary() {
if (userInstrumentLibrary == null) {
String userInstrFileName = BlueSystem.getUserConfigurationDirectory() + File.separator + "userInstrumentLibrary.xml";
File f = new File(userInstrFileName);
if (f.exists()) {
boolean error = false;
try {
Document doc = new Document(f);
userInstrumentLibrary = InstrumentLibrary.loadFromXML(doc.getRoot());
} catch (ParseException e1) {
e1.printStackTrace();
error = true;
} catch (Exception e) {
e.printStackTrace();
error = true;
}
if (error) {
JOptionPane.showMessageDialog(null, "There was an error loading " + f.getAbsolutePath() + "\nPlease fix this file or remove it and restart blue.", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
} else {
userInstrumentLibrary = new InstrumentLibrary();
}
}
return userInstrumentLibrary;
}
use of electric.xml.Document in project blue by kunstmusik.
the class OpenProjectAction method open.
public static void open(File selected) {
File absoluteSelected = selected.getAbsoluteFile();
File temp = absoluteSelected;
File backup = new File(absoluteSelected.getAbsolutePath() + "~");
boolean wasTempFile = false;
if (backup.exists() && backup.lastModified() > temp.lastModified()) {
String message = "A backup work file was found. This should only " + "occur if blue did not close successfully.\n\n" + "Would you like to open the backup file?\n\n" + "If you open the backup file, it will be required to " + "\"Save as\" the file to overwrite your old work.)";
NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(message, NotifyDescriptor.YES_NO_CANCEL_OPTION);
Object retVal = DialogDisplayer.getDefault().notify(descriptor);
if (retVal == NotifyDescriptor.YES_OPTION) {
temp = backup;
wasTempFile = true;
} else if (retVal == NotifyDescriptor.CANCEL_OPTION) {
return;
}
}
try {
String text = TextUtilities.getTextFromFile(temp);
BlueData tempData;
if (text.startsWith("<blueData")) {
Document d = new Document(text);
tempData = BlueData.loadFromXML(d.getElement("blueData"));
} else {
return;
// JOptionPane.showMessageDialog(this, BlueSystem.getString(
// "blue.pre94"));
//
// XMLSerializer xmlSer = new XMLSerializer();
// BufferedReader xmlIn = new BufferedReader(
// new StringReader(text));
//
// tempData = (BlueData) xmlSer.read(xmlIn);
//
// xmlIn.close();
// tempData.upgradeData();
}
// InstrumentLibrary iLibrary = tempData.getInstrumentLibrary();
//
// if (iLibrary != null) {
// tempData.normalizeArrangement();
// tempData.setInstrumentLibrary(null);
//
// // TODO - TRANSLATE
// String message = "This project contains an InstrumentLibrary \n" + "which is no longer being used in blue. The project's\n " + "orchestra will be updated to have individual copies of\n " + "each instrument from the library. \n\n" + "Upon saving, the InstrumentLibrary in this project will\n" + "no longer be accessible.\n\n" + "Would you like to import a copy of your library into " + "your user InstrumentLibrary?";
//
// int retVal = JOptionPane.showConfirmDialog(this, message);
//
// if (retVal == JOptionPane.YES_OPTION) {
// BlueSystem.getUserInstrumentLibrary().importLibrary(
// iLibrary);
// }
// }
BlueProject project;
if (wasTempFile) {
project = new BlueProject(tempData, null);
project.setTempFile(temp);
project.setOpenedFromTempFile(true);
} else {
project = new BlueProject(tempData, temp);
}
BlueProjectManager projectManager = BlueProjectManager.getInstance();
projectManager.setCurrentProject(project);
if (!temp.getAbsolutePath().endsWith("~")) {
RecentProjectsList.getInstance().addFile(temp.getAbsolutePath());
}
// this.blueDataFileArray.add(bdf);
temp = null;
// StatusBar.updateStatus(selected.getName() + " opened.");
checkDependencies(tempData);
} catch (FileNotFoundException fe) {
String message = "Error: Could not open " + temp.toString();
StatusDisplayer.getDefault().setStatusText(message);
NotifyDescriptor descriptor = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(descriptor);
} catch (Exception e) {
Exceptions.printStackTrace(e);
StatusDisplayer.getDefault().setStatusText("Error: Could not open " + temp.toString());
}
}
use of electric.xml.Document in project blue by kunstmusik.
the class RevertAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent actionEvent) {
BlueProject project = BlueProjectManager.getInstance().getCurrentProject();
if (project == null || project.getDataFile() == null) {
return;
}
int retVal = JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), BlueSystem.getString("message.file.revert.text"), BlueSystem.getString("message.file.revert.title"), JOptionPane.YES_NO_CANCEL_OPTION);
if (retVal == JOptionPane.YES_OPTION) {
try {
String text = TextUtilities.getTextFromFile(project.getDataFile());
BlueData tempData;
if (text.startsWith("<blueData")) {
Document d = new Document(text);
tempData = BlueData.loadFromXML(d.getElement("blueData"));
} else {
return;
}
project.setData(tempData);
BlueProjectManager.getInstance().setCurrentProject(project);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations