Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/bdgp/apps/dagedit/datamodel/Dbxref.java


1   package org.bdgp.apps.dagedit.datamodel;
2   
3   import javax.swing.undo.*;
4   import java.util.Hashtable;
5   import java.io.Serializable;
6   
7   public class Dbxref implements Cloneable, StateEditable,
8       Serializable, Comparable {
9   
10      public final static int UNKNOWN = -1;
11      public final static int ANATOMICAL = 0;
12      public final static int SYNONYM = 1;
13      public final static int DEFINITION = 2;
14      public final static int ANALOG = 3;
15  
16      protected String id;
17      protected String database;
18      protected String desc;
19  
20      protected int type;
21      protected Synonym targetSynonym;
22      private static int idgen = 0;
23      protected int privateid;
24  
25      public Dbxref(String database, String id) {
26    this(database, id, null, UNKNOWN, null);
27      }
28  
29      public Dbxref(String database, String id, int type) {
30    this(database, id, null, type, null);
31      }
32  
33      public static String getTypeStringFromInt(int type) {
34    if (type == Dbxref.ANATOMICAL)
35        return "anatomical";
36    else if (type == Dbxref.SYNONYM)
37        return "synonym";
38    else if (type == Dbxref.DEFINITION)
39        return "definition";
40    else if (type == Dbxref.ANALOG)
41        return "analog";
42    else
43        return null;
44      }
45  
46      public Dbxref(String database, String id, String desc, int type) {
47    this(database, id, desc, type, null);
48      }
49  
50      public Dbxref(String database, String id, String desc, int type,
51        Synonym targetSynonym) {
52    this.id = id;
53    this.database = database;
54    this.type = type;
55    this.desc = desc;
56    this.targetSynonym = targetSynonym;
57    privateid = idgen++;
58      }
59  
60      public void setDesc(String desc) {
61    this.desc = desc;
62      }
63  
64      public String getDesc() {
65    return desc;
66      }
67  
68      public void setType(int type) {
69    this.type = type;
70      }
71  
72      public int getType() {
73    return type;
74      }
75  
76      public void setSynonym(Synonym syn) {
77    targetSynonym = syn;
78      }
79  
80      public String getID() {
81    return id;
82      }
83  
84      public String getDatabase() {
85    return database;
86      }
87  
88      public void setID(String id) {
89    this.id = id;
90      }
91  
92      public void setDatabase(String database) {
93    this.database = database;
94      }
95  
96      public String toString() {
97    if (desc == null)
98        return database+":"+id;
99    else
100       return desc+" ("+database+":"+id+")";
101     }
102 
103     public int compareTo(Object o) {
104   return toString().compareToIgnoreCase(o.toString());
105     }
106 
107     public boolean equals(Object in) {
108   if (in instanceof Dbxref) {
109       return ((Dbxref) in).getDatabase().equals(database) &&
110     ((Dbxref) in).getID().equals(id) &&
111     ((Dbxref) in).getType() == type;
112   } else
113       return false;
114     }
115 
116     public Object clone() {
117   try {
118       return super.clone();
119   } catch (CloneNotSupportedException e) {
120       return null;
121   }
122     }
123 
124     public void storeState(Hashtable in) {
125   in.put("dbxref.type", new Integer(type));
126   if (targetSynonym != null)
127       in.put("dbxref.syn", targetSynonym);
128   in.put("dbxref.dbname", database);
129   if (desc != null)
130       in.put("dbxref.desc", desc);
131   in.put("dbxref.id", id);
132     }
133 
134     public void restoreState(Hashtable in) {
135   String storedDbname = (String) in.get("dbxref.dbname");
136   String storedID = (String) in.get("dbxref.id");
137   Integer storedType = (Integer) in.get("dbxref.type");
138   Synonym storedSyn = (Synonym) in.get("dbxref.syn");
139   String storedDesc = (String) in.get("dbxref.desc");
140   if (storedDbname != null)
141       database = storedDbname;
142   if (storedID != null)
143       id = storedID;
144   if (storedType != null)
145       type = storedType.intValue();
146   if (storedSyn != null)
147       targetSynonym = storedSyn;
148   if (storedDesc != null)
149       desc = storedDesc;
150     }
151 }