[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Sat Jun 16 00:24:01 UTC 2007


gordonp
Fri Jun 15 20:24:00 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv29030/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentPane.java 
Log Message:
Fixed HTML page loading..must use setPage(), not setText due to JEditorPane bug, fixed indetation, removed cruft code, improved preformatting
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.10,1.11
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2007/06/09 22:05:52	1.10
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2007/06/16 00:24:00	1.11
@@ -1,6 +1,7 @@
 
 package ca.ucalgary.seahawk.gui;
 
+// For external links
 import ca.ucalgary.seahawk.util.*;
 
 import org.biomoby.client.MobyRequest;
@@ -86,6 +87,7 @@
 	editorPane = new PrintableJEditorPane();
 	editorPane.addKeyListener(this);
 	editorPane.setTransferHandler(getTransferHandler());
+	//editorPane.setPreferredSize(parentComponent.getPreferredSize());
 	editorPane.setEditable(false);
 	editorPane.addMouseListener(this);
 	editorPane.addHyperlinkListener(this);
@@ -237,25 +239,23 @@
 		    return;
 		}
 		catch(Exception e){
-		    e.printStackTrace();
 		    status.setText("Note: There was an error transforming the MOBY data " +
 				   "into presentation form, it may not be displayed correctly");
 		    logger.error("Note: There was an error transforming the MOBY data " +
 				 "into presentation form, it may not be displayed correctly");
 		}
+		// Get rid of inter-tag whitespaces
+		htmlContents = htmlContents.replaceAll(">[ \\t\\r\\n]+<", "><");
+		int origHash = htmlContents.hashCode();
 		// Looks like tab-formatted text (at least 3 tabs)?
-		if(htmlContents.indexOf('\t') != -1){
-		    htmlContents = htmlContents.replaceAll(">(([^<]*\t){3,}[^<]+)", "><pre>$1</pre>");
-		}
-		// Looks like formatting whitespace
-		else if(htmlContents.indexOf("       ") != -1){
-		    htmlContents = htmlContents.replaceAll(">([^<]+       [^<]+)<", "><pre>$1</pre><");
-		}
-		else{
+		htmlContents = htmlContents.replaceAll(">(([^<]*\t){3,}[^<]+)<", "><pre>$1</pre><");
+		// Looks like formatting whitespace?
+		htmlContents = htmlContents.replaceAll(">([^<]*       [^<]*)<", "><pre>$1</pre><");
+		// If no preformatting done, break up long DNA stretches
+		if(htmlContents.hashCode() == origHash){
 		    // Break up any really long DNA/AA stretches
-		    System.err.println("Trying to break up long streches");
-		    htmlContents = htmlContents.replaceAll("([a-zA-Z]{60})", "\n<br><tt>$1</tt>");
-		    htmlContents = htmlContents.replaceAll("([a-zA-Z]{60}</tt>)([a-zA-Z]{1,})", "$1\n<br><tt>$2</tt><br>\n");
+		    htmlContents = htmlContents.replaceAll("([a-zA-Z]{80})", "\n<br><tt>$1</tt>");
+		    htmlContents = htmlContents.replaceAll("([a-zA-Z]{80}</tt>)([a-zA-Z]{1,})", "$1\n<br><tt>$2</tt><br>\n");		 
 		}
 		// Otherwise assume it's formatted
 		resultBuffer.append(htmlContents);
@@ -284,10 +284,25 @@
 	    // Assume it's plain text, or whatever the JEditorPane can glean from the content-type
 	    // such as a remote HTML or RTF doc, because result buffer will be empty in condition below
 	    else{
+		//editorPane.setContentType("text/plain");
 		isContentsXML = false;
+		//editorPane.setFont(java.awt.Font.getFont("Monospaced"));
+		editorPane.setContentType("text/html");
+		String body = getInputStreamContents(url.openStream());
+		if(body.toLowerCase().indexOf("<html") != -1){
+		    resultBuffer = null;
+		}
+		else{
+		    resultBuffer = new StringBuffer("<html><body><pre>"+
+						    body.replaceAll("&", "&amp;").replaceAll("<","&lt;")+
+						    "</pre></body></html>");
+		}
 	    }
 
-	    if(resultBuffer.length() == 0){
+	    if(resultBuffer == null){ // only happens if the url is already an HTML doc
+		editorPane.setPage(url);
+	    }
+	    else if(resultBuffer.length() == 0){
 		// Attempt to use MobyClient to convert the url's data into a Moby object
 		// (e.g. if the file to load is an image, or a chromatogram) 
 		try{
@@ -309,21 +324,7 @@
 		    logger.error("Failure in loading MOBYfied binary data:\n" + e);
 		}
 		// Shouldn't get here unless either not binary, or the binary data load failed
-		editorPane.setContentType("text/html");
-		String body = getInputStreamContents(url.openStream());
-		// Is it already HTML?
-		if(body.toLowerCase().indexOf("<html") != -1){
-		    resultBuffer = new StringBuffer(body);
-		    editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, url);
-		}
-		// Otherwise it needs preformatting to get a fixed width font
-		else{
-		    //System.err.println("Is plain text");
-		    resultBuffer = new StringBuffer("<html><body><pre>"+
-						    body.replaceAll("&", "&amp;").replaceAll("<","&lt;")+
-						    "</pre></body></html>");
-		}
-		editorPane.setText(resultBuffer.toString());
+		editorPane.setPage(url);
 	    }
 	    else{
 		editorPane.setText(resultBuffer.toString());
@@ -332,8 +333,6 @@
 	    }
 	    // Regardless of the doc, scroll to a reference called "start:" if available.
 	    // By default the pane will annoyingly scroll to the bottom when new data is loaded.
-	    try{Thread.sleep(1000);} // Give it time to paint before scrolling
-	    catch(Exception te){}
 	    editorPane.scrollToReference("start");
 	}
 	catch (java.io.IOException ioe) {
@@ -403,13 +402,13 @@
 	tabbedPane.setTitleAt(tabbedPane.indexOfComponent(this), 
 			      ""+requestEvent.getID()+"-"+requestEvent.getService().getName());
 	setWaitScreen();
-	// Store the request being sent (w/ 2ndary params and all), 
-	// for reference (e.g. when exporting a workflow)
-	try{
-	    dataRecorder.saveInputData(requestEvent);
-	} catch(Exception e){
-	    e.printStackTrace();
-	}
+        // Store the request being sent (w/ 2ndary params and all),
+        // for reference (e.g. when exporting a workflow)
+        try{
+            dataRecorder.saveInputData(requestEvent);
+        } catch(Exception e){
+            e.printStackTrace();
+        }	
     }
 
     public void stop(MobyRequest request, int requestID){
@@ -495,17 +494,17 @@
     }
 
     public String toScufl() throws Exception{
-	URL[] historyToExport = (URL[]) history.toArray(new URL[history.size()]);
-	if(historyIndex != historyToExport.length-1){
-	    // Shorten the array if we aren't cuurently on the last doc (i.e. 
-	    // we don't want to export documents forward in the history)
-	    URL[] truncatedHistory = new URL[historyIndex];
-	    System.arraycopy(historyToExport, 0, truncatedHistory, 0, historyIndex);
-	    historyToExport = truncatedHistory;
-	}
-	ByteArrayOutputStream output = new ByteArrayOutputStream();
-	dataRecorder.exportWorkflow(historyToExport, output, DataRecorder.TAVERNA15);
-	return output.toString();
+        URL[] historyToExport = (URL[]) history.toArray(new URL[history.size()]);
+        if(historyIndex != historyToExport.length-1){
+            // Shorten the array if we aren't cuurently on the last doc (i.e.
+            // we don't want to export documents forward in the history)
+            URL[] truncatedHistory = new URL[historyIndex];
+            System.arraycopy(historyToExport, 0, truncatedHistory, 0, historyIndex);
+            historyToExport = truncatedHistory;
+        }
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        dataRecorder.exportWorkflow(historyToExport, output, DataRecorder.TAVERNA15);
+        return output.toString();
     }
 
     // Save the MOBY data to a file, then tell NewBrowser to load that local file URL
@@ -543,8 +542,8 @@
 	}
 
 	try {
-	    URL outputURL = dataRecorder.saveOutputData(mre);
-	    gotoURL(outputURL, true);
+            URL outputURL = dataRecorder.saveOutputData(mre);
+            gotoURL(outputURL, true);
 	} catch (Exception e) {
 	    failed("Could not write a local file");
 	    editorPane.setText("ERROR: Could not write temporary file for MOBY results: " + e);
@@ -554,31 +553,6 @@
 	succeeded(responseType);
     }
 
-    private String serviceToFilePrefix(MobyService service){
-	return service.getAuthority()+"_SEAHAWk_"+service.getName()+"_SEAHAWk_";
-    }
-
-    private MobyService filePrefixToService(String filename) throws Exception{
-	String tokens[] = filename.split("_SEAHAWk_");
-	if(tokens == null || tokens.length < 2){
-	    return null;
-	}
-
-	String auth = tokens[0];
-	String name = tokens[1];
-
-	if(name == null){
-	    return null;
-	}
-
-	MobyService service = new MobyService(name, auth);  // template
-        MobyService[] validServices = servicesGUI.getMobyCentralImpl().findService(service);
-	if(validServices == null || validServices.length == 0){
-	    return null;
-	}
-	return validServices[0];
-    }
-
     protected boolean hasContents(MobyContentInstance responses){
         MobyDataObjectSet retrievedObjects = responses.retrieveObjects();
 	return retrievedObjects != null && retrievedObjects.size() > 0;




More information about the MOBY-guts mailing list