A Sound File Editor for Netbeans

by Rich Unger 





Listing One



Manifest-Version: 1.0

OpenIDE-Module: com.nuance.tools.prompt/1



OpenIDE-Module-Specification-Version: 1.0

OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.41

OpenIDE-Module-Module-Dependencies: org.openide.io

OpenIDE-Module-Localizing-Bundle: 

                     com/nuance/tools/prompt/resources/Bundle.properties

OpenIDE-Module-Layer: com/nuance/tools/prompt/resources/mf-layer.xml

Class-Path: docs/com-nuance-tools-prompt-edit.jar



Name: com/nuance/tools/prompt/PromptLoader.class

OpenIDE-Module-Class: Loader



Listing Two



# Bundle.properties

# moved from the module manifest, so they can be localized



OpenIDE-Module-Name=Prompt Editor

OpenIDE-Module-Short-Description=Prompt Editor

OpenIDE-Module-Long-Description=

             Use this module to record, play, crop and normalize audio files.

OpenIDE-Module-Implementation-Title=V-Builder

OpenIDE-Module-Implementation-Vendor=Nuance

OpenIDE-Module-Display-Category=V-Builder



Listing Three



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE filesystem PUBLIC '-//NetBeans//DTD Filesystem 1.0//EN' 

                            'http://www.netbeans.org/dtds/filesystem-1_0.dtd'>

<filesystem>

  <!-- The "File...New File" templates -->

  <folder name="Templates">

    <folder name="V-Builder">

      <!-- empty.prompt is a file in the same directory as this layer file -->

      <file name="untitled.prompt" url="empty.prompt">

        <attr name="template" 

              boolvalue="true"/>

        <attr name="SystemFileSystem.localizingBundle" 

              stringvalue="com.nuance.tools.prompt.Bundle" />

        <attr name="SystemFileSystem.icon" urlvalue=

             "nbresloc:/com/nuance/tools/prompt/resources/wavIconSmall.gif"/> 

        <attr name="templateWizardURL" urlvalue=

             "nbresloc:/com/nuance/tools/prompt/resources/templatesWav.html"/> 

      </file>

    </folder>

  </folder>

  <!-- register the JavaHelp help set -->

  <folder name="Services">

    <folder name="JavaHelp">

        <file name="com-nuance-tools-prompt-edit-helpset.xml">

        <![CDATA[<?xml version="1.0"?>

            <!DOCTYPE helpsetref PUBLIC

            "-//NetBeans//DTD JavaHelp Help Set Reference 1.0//EN"

            "http://www.netbeans.org/dtds/helpsetref-1_0.dtd">

            <helpsetref url="nbdocs:/com-nuance-tools-prompt-edit/

                                          com-nuance-tools-prompt-edit.hs"/>

        ]]>

        </file>

    </folder>

  </folder>

  <!-- make a menu item for the help set -->

  <folder name="Menu">

    <folder name="Help">

      <!-- Put "V-Builder" sub-menu before the "Help Contents" sub-menu -->

      <attr name="V-Builder/HelpShortcuts" boolvalue="true"/> 

      <folder name="V-Builder">

        <attr name="SystemFileSystem.icon" urlvalue=

              "nbresloc:/org/netbeans/modules/javahelp/resources/help.gif"/> 

        <file name="com-nuance-tools-prompt-edit-help-menu.xml">

          <![CDATA[<?xml version="1.0"?>

          <!DOCTYPE helpctx PUBLIC "-//NetBeans//DTD Help Context 1.0//EN"

          "http://www.netbeans.org/dtds/helpcontext-1_0.dtd">

          <helpctx id="com.nuance.tools.prompt.edit" showmaster="false"/>

          ]]>

          <attr name="SystemFileSystem.localizingBundle" 

                stringvalue="com.nuance.tools.prompt.resources.Bundle"/>

          <attr name="SystemFileSystem.icon" urlvalue=

               "nbresloc:/com/nuance/tools/prompt/resources/wavIconSmall.gif"/>

        </file>

      </folder>

    </folder>

  </folder>

</filesystem>





Listing Four



package com.nuance.tools.prompt;



import java.io.IOException;



import org.openide.actions.*;

import org.openide.filesystems.FileObject;

import org.openide.filesystems.FileUtil;

import org.openide.loaders.DataObjectExistsException;

import org.openide.loaders.ExtensionList;

import org.openide.loaders.FileEntry;

import org.openide.loaders.MultiDataObject;

import org.openide.loaders.MultiFileLoader;

import org.openide.util.NbBundle;

import org.openide.util.actions.SystemAction;



/**  Recognizes .prompt and .wav files as a single DataObject.

 * .prompt files are the primary file objects. @author Rich Unger

 */

public class PromptLoader extends MultiFileLoader {

    public static final String PROP_EXTENSIONS = "extensions"; // NOI18N

    public static final String WAV_EXTENSION = "wav";

    public static final String INFO_FILE_EXTENSION = "prompt";

    private static final long serialVersionUID = -4579746482156153693L;

    public PromptLoader() {

        super("com.nuance.tools.prompt.PromptDataObject");

    }

    protected String defaultDisplayName () {

        return NbBundle.getMessage(PromptLoader.class, "LBL_loaderName");

    }

    protected SystemAction[] defaultActions () {

        return new SystemAction[] {

            SystemAction.get (OpenAction.class),

            SystemAction.get (FileSystemAction.class), null,

            SystemAction.get (CutAction.class),

            SystemAction.get (CopyAction.class),

            SystemAction.get (PasteAction.class), null,

            SystemAction.get (DeleteAction.class),

            SystemAction.get (RenameAction.class), null,

            SystemAction.get (PropertiesAction.class),

        };

    }

    protected MultiDataObject createMultiObject (FileObject primaryFile)

    throws DataObjectExistsException, IOException {

        return new PromptDataObject(primaryFile, this);

    }

    /** For a given file find the primary file. @param fo the file to find 

     * the primary file for @return the primary file for this file or null 

     * if this file is not recognized by this loader.

     */

    protected FileObject findPrimaryFile(FileObject fo) {

        // never recognize folders.

        if (fo.isFolder()) return null;

        String ext = fo.getExt();

        if (ext.equalsIgnoreCase(WAV_EXTENSION)) {

            FileObject info = FileUtil.findBrother(fo, INFO_FILE_EXTENSION);

            if(info != null) {

                return info;

            } 

            else {

                try {

                    info = fo.getParent().createData(

                            fo.getName(), INFO_FILE_EXTENSION);

                    return info;

                } catch(IOException ioe) {

                    // could not create .prompt file, 

                    // so cannot recognize .wav file

                    return null;

                }

            }

        }

        if (getExtensions().isRegistered(fo)) {

            return fo;

        }

        return null;

    }

    /** Create the primary file entry. Primary files are the property files 

     * (which contain the prompt's * description and recording instructions).

     * @param primaryFile primary file recognized by this loader

     * @return primary entry for that file

     */

    protected MultiDataObject.Entry createPrimaryEntry(

            MultiDataObject obj, FileObject primaryFile) {

        return new FileEntry(obj, primaryFile);

    }

    /** Create a secondary file entry.

     * Secondary files are wav files, which should also be retained (so, not a

     * FileEntry.Numb object)

     * @param secondaryFile secondary file to create entry for

     * @return the entry

     */

    protected MultiDataObject.Entry createSecondaryEntry(

            MultiDataObject obj, FileObject secondaryFile) {

        return new FileEntry(obj, secondaryFile);

    }

    /** @return The list of extensions this loader recognizes. */

    public ExtensionList getExtensions() {

        ExtensionList extensions =(ExtensionList)getProperty(PROP_EXTENSIONS);

        if (extensions == null) {

            extensions = new ExtensionList();

            extensions.addExtension(INFO_FILE_EXTENSION);

            extensions.addExtension(WAV_EXTENSION);

            putProperty(PROP_EXTENSIONS, extensions, false);

        }

        return extensions;

    }

    /** Sets the extension list for this data loader.

     * @param ext new list of extensions.

     */

    public void setExtensions(ExtensionList ext) {

        putProperty(PROP_EXTENSIONS, ext, true);

    }

}











1



