[MOBY-guts] biomoby commit
Eddie Kawas
kawas at pub.open-bio.org
Thu Mar 16 15:20:44 UTC 2006
kawas
Thu Mar 16 10:20:44 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared
In directory pub.open-bio.org:/tmp/cvs-serv4016/org/biomoby/client/ui/graphical/applets/shared
Modified Files:
Construct.java MobyTree.java
Log Message:
abilitiy to use the new rdf or not (i.e. backwards compatible).
moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared Construct.java,1.3,1.4 MobyTree.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/Construct.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/Construct.java 2005/09/30 14:44:58 1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/Construct.java 2006/03/16 15:20:44 1.4
@@ -1,5 +1,7 @@
package org.biomoby.client.ui.graphical.applets.shared;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
@@ -10,6 +12,7 @@
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.ibm.lsid.LSID;
/*
*
@@ -64,10 +67,11 @@
// create an empty model
Model model = new ModelMem();
- InputStream in = new URL(url).openStream();
-
+ InputStream ins = new URL(url).openStream();
+ BufferedInputStream in = new BufferedInputStream(ins);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
// read the RDF/XML data
- model.read(new InputStreamReader(in), "");
+ model.read(reader, "");
StmtIterator iter;
Statement stmt;
@@ -145,10 +149,24 @@
String sub = stmt.getSubject().getURI();
String obj = stmt.getObject().toString();
- if (sub != null)
- sub = sub.substring(sub.indexOf("#") + 1, sub.length());
- if (obj!= null)
- obj = obj.substring(obj.indexOf("#") + 1, obj.length());
+ if (sub != null) {
+ if (sub.indexOf("#") > 0)
+ sub = sub.substring(sub.indexOf("#") + 1, sub.length());
+ try {
+ LSID lsid = new LSID(sub);
+ sub = lsid.getObject();
+ } catch (Exception e) {
+ }
+ }
+ if (obj!= null) {
+ if (obj.indexOf("#") > 0)
+ obj = obj.substring(obj.indexOf("#") + 1, obj.length());
+ try {
+ LSID lsid = new LSID(obj);
+ obj = lsid.getObject();
+ } catch (Exception e) {
+ }
+ }
if (stmt.getPredicate().getURI().indexOf(property) > 0) {
//System.out.println(obj);
@@ -184,4 +202,9 @@
return homes;
}
+
+ public static void main(String[] args) {
+ Construct c = new Construct("http://biomoby.org/RESOURCES/MOBY-S/Objects");
+ System.out.println(c.createHomes("subClassOf"));
+ }
}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/MobyTree.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/MobyTree.java 2005/10/12 17:57:54 1.4
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/MobyTree.java 2006/03/16 15:20:44 1.5
@@ -15,6 +15,8 @@
import javax.swing.JTree;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
@@ -48,7 +50,9 @@
private HashMap hashmap; // will contain the nodes
private String rdf = "";
String name = "";
+ private boolean done = false;
private static final boolean DEBUG = false;
+ private String last = "";
/**
* A moby tree is constructed with the root node labeled as 'name'<p>
* and the material for the tree taken from the RDF located at
@@ -77,7 +81,7 @@
* the url rdf. The tree is created by looking for the property property<p>
* @param canEdit - if true then nodes in tree can be edited, otherwise they cannot.
* @param rdf - the url of the RDF describing Moby Objects, Services, Service Types, and Namespaces
- * @param name - the name of the root node in the tree.
+ * @param name - the name of the root node in the tree, which is present in the rdf document.
* @param property - the property to parse the rdf document and base a tree on
*/
public MobyTree(boolean canEdit, String rdf, String name, String property) {
@@ -106,7 +110,21 @@
tree.setEditable(canEdit);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setShowsRootHandles(true);
-
+ tree.addTreeSelectionListener(new TreeSelectionListener() {
+ public void valueChanged(TreeSelectionEvent evt) {
+ // Get all nodes whose selection status has changed
+ TreePath[] paths = evt.getPaths();
+ // Iterate through all affected nodes
+ for (int i = 0; i < paths.length; i++) {
+ if (evt.isAddedPath(i)) {
+ last = (String)paths[i]
+ .getLastPathComponent().toString();
+ } else {
+ //TODO necessary?
+ }
+ }
+ }
+ });
}
/*
@@ -317,11 +335,12 @@
public void makeObjectTree(String name) {
// create nodes with Object root and its children
Household h = (Household) hashmap.get(name);
-
+ // TODO catch null pointers here
if (DEBUG)
System.out.println(h.toString());
fillSubTree(null, h.getChildren(), this);
+ done = true;
}
/**
@@ -344,9 +363,11 @@
}
public void reload(String name) {
+ done = false;
hashmap = new Construct(rdf).createHomes();
makeObjectTree(name);
this.refreshTree(name);
+ done = true;
}
public void collapseMobyTree() {
@@ -354,10 +375,19 @@
tree.collapseRow(0);
}
+ public boolean done(){
+ return done;
+ }
+
+
+ public String getLastSelected(){
+ return last;
+ }
+
public static void main(String[] args) {
JFrame frame = new JFrame();
- MobyTree tree = new MobyTree(false, "http://localhost:8080/RESOURCES/MOBY-S/Objects", "Object");
- tree.makeObjectTree("Object");
+ MobyTree tree = new MobyTree(false, "http://biomoby.org/RESOURCES/MOBY-S/Objects", "DNASequence", "subClassOf");
+ tree.makeObjectTree("DNASequence");
tree.setPreferredSize(new Dimension(400, 400));
// Add button to the frame
frame.getContentPane().add(tree, BorderLayout.CENTER);
More information about the MOBY-guts
mailing list