Search in sources :

Example 1 with Document

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;
}
Also used : Document(electric.xml.Document)

Example 2 with Document

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;
}
Also used : ParseException(electric.xml.ParseException) IOException(java.io.IOException) Document(electric.xml.Document) File(java.io.File)

Example 3 with Document

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;
}
Also used : ParseException(electric.xml.ParseException) Document(electric.xml.Document) File(java.io.File) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) ParseException(electric.xml.ParseException)

Example 4 with Document

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());
    }
}
Also used : BlueData(blue.BlueData) FileNotFoundException(java.io.FileNotFoundException) Document(electric.xml.Document) FileNotFoundException(java.io.FileNotFoundException) NotifyDescriptor(org.openide.NotifyDescriptor) PolyObject(blue.soundObject.PolyObject) SoundObject(blue.soundObject.SoundObject) AudioFile(blue.soundObject.AudioFile) File(java.io.File)

Example 5 with Document

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();
        }
    }
}
Also used : BlueData(blue.BlueData) BlueProject(blue.projects.BlueProject) Document(electric.xml.Document)

Aggregations

Document (electric.xml.Document)35 Element (electric.xml.Element)22 ParseException (electric.xml.ParseException)17 Vector (java.util.Vector)17 IOException (java.io.IOException)13 Elements (electric.xml.Elements)12 File (java.io.File)12 XmlRpcException (org.apache.xmlrpc.XmlRpcException)6 SoundObject (blue.soundObject.SoundObject)4 EffectOption (blue.tools.blueShare.effects.EffectOption)3 InstrumentOption (blue.tools.blueShare.instruments.InstrumentOption)3 SoundObjectOption (blue.tools.blueShare.soundObjects.SoundObjectOption)3 MissingResourceException (java.util.MissingResourceException)3 BlueData (blue.BlueData)2 UDOLibrary (blue.udo.UDOLibrary)2 FileOutputStream (java.io.FileOutputStream)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 SoundLayer (blue.SoundLayer)1 Library (blue.library.Library)1 Effect (blue.mixer.Effect)1