Major cleanup of Utils class.
[trakem2.git] / ini / trakem2 / tree / TemplateAttribute.java
blob7cf2a501dea424b15e167364b7697c885f5d88ec
1 /**
3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005,2006 Albert Cardona and Rodney Douglas.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
21 **/
23 package ini.trakem2.tree;
25 import ini.trakem2.persistence.DBObject;
26 import ini.trakem2.Project;
29 public final class TemplateAttribute extends DBObject implements Attribute {
31 private String title;
32 private Object object;
34 /** Construct a new attribute with the given title and the given object, which for example can be of class Thing. */
35 public TemplateAttribute(String title, Object object) {
36 super(null, -1);
37 this.title = title;
38 this.object = object;
41 /** Reconstruct a new attribute from the database. */
42 public TemplateAttribute(String title, Object object, Project project, long id) {
43 super(project, id);
44 this.title = title;
45 this.object = object;
48 /** WARNING: the object is not cloned. */
49 public TemplateAttribute clone(final Project pr, final boolean copy_id) {
50 final long nid = copy_id ? this.id : pr.getLoader().getNextId();
51 final TemplateAttribute copy = new TemplateAttribute(this.title, this.object, pr, nid);
52 return copy;
55 public void addToDatabase(Project project) {
56 this.project = project;
57 this.id = project.getLoader().getNextId();
58 super.addToDatabase();
61 public String getTitle() {
62 return this.title;
65 public void setObject(Object object) {
66 this.object = object;
69 public Thing getOwner() {
70 return null; // stupid java
73 public Object getObject() {
74 return this.object;
77 public long getObjectId() {
78 // default
79 return -1;
82 public String toString() {
83 if (null == object) {
84 return title + ": [empty]";
86 return title + ": " + object.toString();
89 public String getObjectString() { // dummy
90 return "";