ini.trakem2
Class Project

java.lang.Object
  extended by ini.trakem2.persistence.DBObject
      extended by ini.trakem2.Project

public class Project
extends DBObject

The top-level class in control.


Field Summary
 
Fields inherited from class ini.trakem2.persistence.DBObject
id, project
 
Constructor Summary
Project(long id, java.lang.String title)
          Constructor used by the Loader to find projects.
 
Method Summary
 boolean addUniqueType(TemplateThing tt)
          Returns false if the type exists already.
 void adjustProperties()
           
 Project createSubproject(java.awt.Rectangle roi, Layer first, Layer last)
          Create a new subproject for the given layer range and ROI.
 void decache(java.lang.Object ob)
           
 boolean destroy()
           
 void exportDTD(java.lang.StringBuilder sb_header, java.util.HashSet<java.lang.String> hs, java.lang.String indent)
          Export a complete DTD listing to export the project as XML.
 void exportXML(java.lang.StringBuilder sb, java.lang.String indent, java.lang.Object any)
          Subclasses can override this method to store the instance as XML.
 void exportXML(java.io.Writer writer, java.lang.String indent, java.lang.Object any)
          Export the main trakem2 tag wrapping four hierarchies (the project tag, the ProjectTree, and the Top Level LayerSet the latter including all Displayable objects) and a list of displays.
 ProjectThing find(long id)
          Find the ProjectThing instance with the given id.
 DBObject findById(long id)
           
 LayerThing findLayerThing(java.lang.Object ob)
          Find a LayerThing that contains the given object.
static Project findProject(Loader loader)
           
 ProjectThing findProjectThing(java.lang.Object ob)
          Find a ProjectThing that contains the given object.
 boolean getBooleanProperty(java.lang.String key)
           
 java.lang.String getDocType()
          Returns the String to be used as Document Type of the XML file, generated from the name of the root template thing.
 java.lang.String getInfo()
          Returns id and project name; this method is meant to be overriden by any of the subclasses.
 LayerTree getLayerTree()
           
 Loader getLoader()
           
 java.lang.String getMeaningfulTitle(Displayable d)
          Searches upstream in the Project tree for things that have a user-defined name, stops at the first and returns it along with all the intermediate ones that only have a type and not a title, appended.
 java.lang.String getMeaningfulTitle2(Displayable d)
           
static java.lang.String getName(java.lang.Class<?> c)
          Returns a user-understandable name for the given class.
 java.lang.String getParentTitle(Displayable d)
          Returns the title of the enclosing abstract node in the ProjectTree.
 java.util.TreeMap<java.lang.String,TPlugIn> getPlugins(java.lang.String menu)
           
static Project getProject(java.lang.String title)
           
static java.util.ArrayList<Project> getProjects()
          Return a copy of the list of all open projects.
 ProjectTree getProjectTree()
           
 java.util.HashMap<java.lang.String,java.lang.String> getPropertiesCopy()
           
 java.lang.String getProperty(java.lang.String key)
          Returns null if not defined.
 float getProperty(java.lang.String key, float default_value)
          Returns the default value if not defined, or if not a number or not parsable as a number.
 int getProperty(java.lang.String key, int default_value)
           
 LayerSet getRootLayerSet()
           
 LayerThing getRootLayerThing()
           
 ProjectThing getRootProjectThing()
           
 TemplateThing getRootTemplateThing()
           
 java.lang.String getShortMeaningfulTitle(Displayable d)
          Returns the first upstream user-defined name and type, and the id of the displayable tagged at the end.
 java.lang.String getShortMeaningfulTitle(ProjectThing thing, Displayable d)
           
 TemplateThing getTemplateThing(java.lang.String type)
          Returns the proper TemplateThing for the given type, complete with children and attributes if any.
 TemplateTree getTemplateTree()
           
 java.lang.String getTitle()
          Sublcasses can override this method to provide a proper String, otherwise calls toString()
static java.lang.String getType(java.lang.Class<?> c)
           
 java.lang.String[] getUniqueTypes()
          Returns a list of existing unique types in the template tree (thus the 'project' type is not included, nor the label).
 java.lang.String getUNUId()
          Return the Universal Near-Unique Id of this project, which may be null for non-FSLoader projects.
static boolean isBasicType(java.lang.String type)
          Returns true if the type is 'patch', 'layer', 'layer_set', 'profile', 'profile_list' 'pipe'.
 boolean isBeingDestroyed()
           
 boolean isInputEnabled()
           
static boolean isLayerSetType(java.lang.String type)
           
static boolean isLayerType(java.lang.String type)
           
static boolean isProjectType(java.lang.String type)
           
 java.lang.Object makeObject(TemplateThing tt)
          Make an object of the type the TemplateThing can hold.
static Project newDBProject()
          Create a new PostgreSQL-based TrakEM2 project.
static Project newFSProject(java.lang.String arg)
          Creates a new project to be based on .xml and image files, not a database.
static Project newFSProject(java.lang.String arg, TemplateThing template_root)
           
static Project newFSProject(java.lang.String arg, TemplateThing template_root, java.lang.String storage_folder)
          Creates a new project to be based on .xml and image files, not a database.
static Project openDBProject()
          Open a TrakEM2 project from the database.
static Project openFSProject(java.lang.String path)
           
static Project openFSProject(java.lang.String path, boolean open_displays)
          Opens a project from an .xml file.
 void parseXMLOptions(java.util.HashMap<java.lang.String,java.lang.String> ht_attributes)
           
 void remove()
          Remove the project from the database and release memory.
 boolean remove(boolean check)
          Remove the project from the database and release memory.
 boolean remove(Displayable d)
          Removes an object from this Project.
 boolean removeAll(java.util.Set<Displayable> col)
          Calls Project.removeAll(col, null)
 boolean removeAll(java.util.Set<Displayable> col, javax.swing.tree.DefaultMutableTreeNode top_node)
          Remove any set of Displayable objects from the Layer, LayerSet and Project Tree as necessary.
 boolean removeProjectThing(java.lang.Object object, boolean check)
          Remove the ProjectThing that contains the given object, which will remove the object itself as well.
 boolean removeProjectThing(java.lang.Object object, boolean check, boolean remove_empty_parents, int levels)
          Remove the ProjectThing that contains the given object, which will remove the object itself as well.
 boolean removeUniqueType(java.lang.String type)
          Remove a unique type from the HashMap.
 void resetRootLayerThing(LayerThing lt, java.util.HashMap<Thing,java.lang.Boolean> ltree_exp)
          For undo purposes.
 void resetRootProjectThing(ProjectThing pt, java.util.HashMap<Thing,java.lang.Boolean> ptree_exp)
          For undo purposes.
 void resetRootTemplateThing(TemplateThing tt, java.util.HashMap<Thing,java.lang.Boolean> ttree_exp)
          For undo purposes.
 java.lang.String save()
          Save the project regardless of what getLoader().hasChanges() reports.
 java.lang.String saveAs(java.lang.String xml_path, boolean overwrite)
          This is not the saveAs used from the menus; this one is meant for programmatic access.
 void select(Displayable d)
          Find the node in any tree with a Thing that contains the given Displayable, and set it selected/highlighted, deselecting everything else first.
 void select(Layer layer)
          Find the node in the layer tree with a Thing that contains the given object, and set it selected/highlighted, deselecting everything else first.
 void setProperty(java.lang.String key, java.lang.String value)
           
 void setReceivesInput(boolean b)
          Tells the displays concerning this Project to accept/reject input.
 void setTempLoader(Loader loader)
           
 void setTitle(java.lang.String title)
           
 java.lang.String toString()
           
 boolean typeExists(java.lang.String type)
           
 boolean updateTypeName(java.lang.String old_type, java.lang.String new_type)
           
 
Methods inherited from class ini.trakem2.persistence.DBObject
addToDatabase, getId, getProject, getShortTitle, getUniqueIdentifier, removeFromDatabase, updateInDatabase, updateInDatabase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Project

public Project(long id,
               java.lang.String title)
Constructor used by the Loader to find projects. These projects contain no loader.

Method Detail

getPlugins

public java.util.TreeMap<java.lang.String,TPlugIn> getPlugins(java.lang.String menu)

getProject

public static Project getProject(java.lang.String title)

getProjects

public static java.util.ArrayList<Project> getProjects()
Return a copy of the list of all open projects.


newDBProject

public static Project newDBProject()
Create a new PostgreSQL-based TrakEM2 project.


openDBProject

public static Project openDBProject()
Open a TrakEM2 project from the database. Queries the database for existing projects and if more than one, asks which one to open.


newFSProject

public static Project newFSProject(java.lang.String arg)
Creates a new project to be based on .xml and image files, not a database. Images are left where they are, keeping the path to them. If the arg equals 'blank', then no template is asked for.


newFSProject

public static Project newFSProject(java.lang.String arg,
                                   TemplateThing template_root)

newFSProject

public static Project newFSProject(java.lang.String arg,
                                   TemplateThing template_root,
                                   java.lang.String storage_folder)
Creates a new project to be based on .xml and image files, not a database. Images are left where they are, keeping the path to them. If the arg equals 'blank', then no template is asked for; if template_root is not null that is used; else, a template file is asked for.


openFSProject

public static Project openFSProject(java.lang.String path)

openFSProject

public static Project openFSProject(java.lang.String path,
                                    boolean open_displays)
Opens a project from an .xml file. If the path is null it'll be asked for. Only one project may be opened at a time.


setTempLoader

public void setTempLoader(Loader loader)

getLoader

public final Loader getLoader()

save

public java.lang.String save()
Save the project regardless of what getLoader().hasChanges() reports.


saveAs

public java.lang.String saveAs(java.lang.String xml_path,
                               boolean overwrite)
This is not the saveAs used from the menus; this one is meant for programmatic access.


destroy

public boolean destroy()

isBeingDestroyed

public boolean isBeingDestroyed()

remove

public void remove()
Remove the project from the database and release memory.


remove

public boolean remove(boolean check)
Remove the project from the database and release memory.

Overrides:
remove in class DBObject

setTitle

public void setTitle(java.lang.String title)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getTitle

public java.lang.String getTitle()
Description copied from class: DBObject
Sublcasses can override this method to provide a proper String, otherwise calls toString()

Overrides:
getTitle in class DBObject

getTemplateTree

public TemplateTree getTemplateTree()

getLayerTree

public LayerTree getLayerTree()

getProjectTree

public ProjectTree getProjectTree()

makeObject

public java.lang.Object makeObject(TemplateThing tt)
Make an object of the type the TemplateThing can hold.


isBasicType

public static boolean isBasicType(java.lang.String type)
Returns true if the type is 'patch', 'layer', 'layer_set', 'profile', 'profile_list' 'pipe'.


isProjectType

public static boolean isProjectType(java.lang.String type)

isLayerSetType

public static boolean isLayerSetType(java.lang.String type)

isLayerType

public static boolean isLayerType(java.lang.String type)

removeProjectThing

public boolean removeProjectThing(java.lang.Object object,
                                  boolean check)
Remove the ProjectThing that contains the given object, which will remove the object itself as well.


removeProjectThing

public boolean removeProjectThing(java.lang.Object object,
                                  boolean check,
                                  boolean remove_empty_parents,
                                  int levels)
Remove the ProjectThing that contains the given object, which will remove the object itself as well.


select

public void select(Layer layer)
Find the node in the layer tree with a Thing that contains the given object, and set it selected/highlighted, deselecting everything else first.


select

public void select(Displayable d)
Find the node in any tree with a Thing that contains the given Displayable, and set it selected/highlighted, deselecting everything else first.


find

public ProjectThing find(long id)
Find the ProjectThing instance with the given id.


findById

public DBObject findById(long id)

findLayerThing

public LayerThing findLayerThing(java.lang.Object ob)
Find a LayerThing that contains the given object.


findProjectThing

public ProjectThing findProjectThing(java.lang.Object ob)
Find a ProjectThing that contains the given object.


decache

public void decache(java.lang.Object ob)

getRootProjectThing

public ProjectThing getRootProjectThing()

getRootLayerSet

public LayerSet getRootLayerSet()

getParentTitle

public java.lang.String getParentTitle(Displayable d)
Returns the title of the enclosing abstract node in the ProjectTree.


getMeaningfulTitle2

public java.lang.String getMeaningfulTitle2(Displayable d)

getMeaningfulTitle

public java.lang.String getMeaningfulTitle(Displayable d)
Searches upstream in the Project tree for things that have a user-defined name, stops at the first and returns it along with all the intermediate ones that only have a type and not a title, appended.


getShortMeaningfulTitle

public java.lang.String getShortMeaningfulTitle(Displayable d)
Returns the first upstream user-defined name and type, and the id of the displayable tagged at the end. If no user-defined name is found, then the type is prepended to the id.


getShortMeaningfulTitle

public java.lang.String getShortMeaningfulTitle(ProjectThing thing,
                                                Displayable d)

getType

public static java.lang.String getType(java.lang.Class<?> c)

getTemplateThing

public TemplateThing getTemplateThing(java.lang.String type)
Returns the proper TemplateThing for the given type, complete with children and attributes if any.


getUniqueTypes

public java.lang.String[] getUniqueTypes()
Returns a list of existing unique types in the template tree (thus the 'project' type is not included, nor the label). The basic types are guaranteed to be present even if there are no instances in the template tree.


removeUniqueType

public boolean removeUniqueType(java.lang.String type)
Remove a unique type from the HashMap. Basic types can't be removed.


typeExists

public boolean typeExists(java.lang.String type)

addUniqueType

public boolean addUniqueType(TemplateThing tt)
Returns false if the type exists already.


updateTypeName

public boolean updateTypeName(java.lang.String old_type,
                              java.lang.String new_type)

exportXML

public void exportXML(java.lang.StringBuilder sb,
                      java.lang.String indent,
                      java.lang.Object any)
Description copied from class: DBObject
Subclasses can override this method to store the instance as XML.

Overrides:
exportXML in class DBObject

exportXML

public void exportXML(java.io.Writer writer,
                      java.lang.String indent,
                      java.lang.Object any)
               throws java.lang.Exception
Export the main trakem2 tag wrapping four hierarchies (the project tag, the ProjectTree, and the Top Level LayerSet the latter including all Displayable objects) and a list of displays.

Throws:
java.lang.Exception

exportDTD

public void exportDTD(java.lang.StringBuilder sb_header,
                      java.util.HashSet<java.lang.String> hs,
                      java.lang.String indent)
Export a complete DTD listing to export the project as XML.


getDocType

public java.lang.String getDocType()
Returns the String to be used as Document Type of the XML file, generated from the name of the root template thing.


getName

public static java.lang.String getName(java.lang.Class<?> c)
Returns a user-understandable name for the given class.


getInfo

public java.lang.String getInfo()
Description copied from class: DBObject
Returns id and project name; this method is meant to be overriden by any of the subclasses.

Overrides:
getInfo in class DBObject

findProject

public static Project findProject(Loader loader)

setReceivesInput

public void setReceivesInput(boolean b)
Tells the displays concerning this Project to accept/reject input.


isInputEnabled

public boolean isInputEnabled()

createSubproject

public Project createSubproject(java.awt.Rectangle roi,
                                Layer first,
                                Layer last)
Create a new subproject for the given layer range and ROI. Create a new Project using the given project as template. This means the DTD of the given project is copied, as well as the storage and mipmaps folders; everything else is empty in the new project.


parseXMLOptions

public void parseXMLOptions(java.util.HashMap<java.lang.String,java.lang.String> ht_attributes)

getPropertiesCopy

public java.util.HashMap<java.lang.String,java.lang.String> getPropertiesCopy()

getProperty

public java.lang.String getProperty(java.lang.String key)
Returns null if not defined.


getProperty

public float getProperty(java.lang.String key,
                         float default_value)
Returns the default value if not defined, or if not a number or not parsable as a number.


getProperty

public int getProperty(java.lang.String key,
                       int default_value)

getBooleanProperty

public boolean getBooleanProperty(java.lang.String key)

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)

adjustProperties

public void adjustProperties()

getUNUId

public java.lang.String getUNUId()
Return the Universal Near-Unique Id of this project, which may be null for non-FSLoader projects.


remove

public final boolean remove(Displayable d)
Removes an object from this Project.


removeAll

public final boolean removeAll(java.util.Set<Displayable> col)
Calls Project.removeAll(col, null)


removeAll

public final boolean removeAll(java.util.Set<Displayable> col,
                               javax.swing.tree.DefaultMutableTreeNode top_node)
Remove any set of Displayable objects from the Layer, LayerSet and Project Tree as necessary. ASSUMES there aren't any nested LayerSet objects in @param col.


resetRootProjectThing

public void resetRootProjectThing(ProjectThing pt,
                                  java.util.HashMap<Thing,java.lang.Boolean> ptree_exp)
For undo purposes.


resetRootTemplateThing

public void resetRootTemplateThing(TemplateThing tt,
                                   java.util.HashMap<Thing,java.lang.Boolean> ttree_exp)
For undo purposes.


resetRootLayerThing

public void resetRootLayerThing(LayerThing lt,
                                java.util.HashMap<Thing,java.lang.Boolean> ltree_exp)
For undo purposes.


getRootTemplateThing

public TemplateThing getRootTemplateThing()

getRootLayerThing

public LayerThing getRootLayerThing()