Class Project

  • All Implemented Interfaces:
    IconProvider, java.lang.Comparable<Member>, java.lang.Iterable<Member>

    public class Project
    extends TaskGroup
    Projects simplify the management of multi-file projects.
    Author:
    Chris Jennings
    • Constructor Detail

      • Project

        public Project​(java.io.File baseFolder)
                throws java.io.IOException
        Opens an existing project. If the folder is not a project folder, throws an exception.
        Throws:
        java.io.IOException
    • Method Detail

      • open

        public static Project open​(java.io.File f)
                            throws java.io.IOException
        Opens an existing project, either from a project folder or from a project package file.
        Parameters:
        f - the project folder or package file to open
        Returns:
        the opened project
        Throws:
        java.io.IOException - if an error occurs while opening the project
      • getView

        public ProjectView getView()
        Returns the canonical ProjectView associated with this project, or null if no view is associated with it.
        Returns:
        the canonical project view displaying this project, or null
      • getURL

        public java.net.URL getURL()
        Description copied from class: Member
        Returns a project: URL that can be used to access this member whenever this project is the main open project. Returns null if the file has been deleted.
        Overrides:
        getURL in class Member
        Returns:
        a project URL for the file.
      • findMember

        public Member findMember​(java.lang.String path)
        Returns the Member instance pointed to by file or URL path in a string. This method is a scripting convenience that invokes either the findMember(java.io.File) or findMember(java.net.URL) method as appropriate.
        Parameters:
        path - a file path or project URL
        Returns:
        the project member described by the path, or null
        Since:
        3.4
      • findMember

        public Member findMember​(java.net.URL url)
        Returns the Member instance pointed to by a URL. The URL protocol must either be file: or project:. If the file specified by the URL is not part of the project, null is returned.
        Parameters:
        url - the URL to locate a project member for
        Returns:
        the project member described by the URL, or null
        Since:
        3.0
      • findMember

        public Member findMember​(java.io.File file)
        Returns the Member instance that represents a file in a project. If the file is not part of the project, then null is returned.
        Parameters:
        file - the file to locate in the project's member tree
        Returns:
        the project member for file, or null
      • isProjectFolder

        public static final boolean isProjectFolder​(java.io.File file)
                                             throws java.io.IOException
        Returns true if the specified file exists and is a project folder.
        Parameters:
        file - the file to test
        Returns:
        true if the file is a regular project folder
        Throws:
        java.lang.NullPointerException - if the file is null
        java.io.IOException
      • isProjectPackage

        public static final boolean isProjectPackage​(java.io.File file)
        Returns true if the specified file exists and is a packaged project container.
        Parameters:
        file - the file to test
        Returns:
        true if the file is a packaged project
        Throws:
        java.lang.NullPointerException - if the file is null
      • createProject

        public static java.io.File createProject​(java.io.File projectFolder,
                                                 java.lang.String projectName)
                                          throws java.io.IOException
        Creates a new project folder with the specified project name. The project will be created as a subfolder of projectFolder. The returned file can be used to create a Project instance for the new project using the Project(java.io.File) constructor.
        Parameters:
        projectFolder - the folder to create the project in
        projectName - the name of the new project
        Returns:
        the new project folder's file
        Throws:
        java.io.IOException - if the project folder does not exist, or if it exists but has a child with the same name as the project name, or if the project folder cannot be created for some reason
      • getIcon

        public ThemedIcon getIcon()
        Returns an icon that is appropriate for this member, in this case the standard icon for projects.
        Specified by:
        getIcon in interface IconProvider
        Overrides:
        getIcon in class Member
        Returns:
        an icon for this member
      • synchronizeAll

        public void synchronizeAll()
      • toPackage

        public void toPackage​(java.io.File pkg)
                       throws java.io.IOException
        Writes the contents of this project to a package project ("crate") file. A packaged project is essentially a ZIP archive that uses the file extension .seproject. When a packaged project is opened in the application, it will unpack the file to a temporary folder and open that folder as a project. When the project is closed, it will then copy the modified package back to the original package file. If a project was opened from a package file, then getPackageFile() will return a non-null value.
        Parameters:
        pkg - the file to write the package archive to
        Throws:
        java.io.IOException - if an I/O error occurs while writing the package file
      • unpackage

        public static java.io.File unpackage​(java.io.File pkg,
                                             java.io.File targetParent)
                                      throws java.io.IOException
        Unpack a project package file into a project folder. The project folder will be a subfolder of targetParent, which must be a folder.
        Parameters:
        pkg - the package file
        targetParent - the intended parent of the project folder
        Returns:
        the unpacked project folder
        Throws:
        java.io.IOException - if an error occurs while unpacking the package
      • getPackageFile

        public java.io.File getPackageFile()
        If this project is stored in a package, returns the package file. Otherwise, returns null.
        Returns:
        returns the package file for this project
      • close

        public void close()
        Closes the project. A project must be closed when no longer needed to make sure that any pending changes get written to the file system. If the project is a packaged type, then closing the project will also update the original package archive to reflect the current state of the project.
      • taskIterator

        public java.util.Iterator<Task> taskIterator()
        Returns an iterator over all task folders in the project, including the project itself.
        Returns:
        an iterator that iterates over all of the tasks in the project