[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Sat Jul 28 03:43:24 UTC 2007


gordonp
Fri Jul 27 23:43:24 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv26872/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	FileAndTextTransferHandler.java 
Log Message:
Added support for passing data to the clipboard for appending, rather than just opening a new tab with the pasted data
moby-live/Java/src/main/ca/ucalgary/seahawk/gui FileAndTextTransferHandler.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/FileAndTextTransferHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/FileAndTextTransferHandler.java	2007/06/08 14:04:27	1.6
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/FileAndTextTransferHandler.java	2007/07/28 03:43:24	1.7
@@ -25,9 +25,18 @@
 public class FileAndTextTransferHandler extends TransferHandler {
     private DataFlavor fileFlavor, stringFlavor;
     private MobyContentGUI gui;
+    private boolean openDataInNewTab;
 
+    /**
+     * By default, opens pasted data in a new tab of the GUI
+     */
     public FileAndTextTransferHandler(MobyContentGUI mcg) {
+	this(mcg, true);
+    }
+
+    public FileAndTextTransferHandler(MobyContentGUI mcg, boolean openNewDataInNewTab) {
        gui = mcg;
+       openDataInNewTab = openNewDataInNewTab;
        fileFlavor = DataFlavor.javaFileListFlavor;
        stringFlavor = DataFlavor.stringFlavor;
     }
@@ -38,6 +47,20 @@
             return false;
         }
 
+	// The clipboard is a special case: we want to append data,
+	// not replace (also assuming you told us not to open data in a new tab).
+	MobyContentClipboard clipboard = null;
+	if(!openDataInNewTab){
+	    for(Component container = c;
+		container != null;
+		container = container.getParent()){
+		if(container instanceof MobyContentClipboard){
+		    clipboard = (MobyContentClipboard) container;
+		    break;
+		}
+	    }	    
+	}
+
         // Should be done in another thread to not block UI
         try {
             if (hasFileFlavor(t.getTransferDataFlavors())) {
@@ -48,12 +71,22 @@
 		    // Was it a shortcut file after all?
 		    if(u != null){
 			System.err.println("Dropped item appears to be a URL shortcut...");
-			gui.loadPaneFromURL(u, true);
+			if(clipboard != null){
+			    clipboard.addCollectionData(u);
+			}
+			else{
+			    gui.loadPaneFromURL(u, openDataInNewTab);
+			}
 		    }
 		    // Any other type of file is loaded as-is
 		    else{
 			System.err.println("Dropped item appears to be a file...");
-			gui.loadPaneFromURL(file.toURI().toURL(), true);
+			if(clipboard != null){
+			    clipboard.addCollectionData(file.toURI().toURL());
+			}
+			else{
+			    gui.loadPaneFromURL(file.toURI().toURL(), openDataInNewTab);
+			}
 		    }
                 }
                 return true;
@@ -74,16 +107,33 @@
                 }
                 if(u != null){
        	           System.err.println("Dropped item appears to be a URL...");
-                   gui.loadPaneFromURL(u, true);
+		   if(clipboard != null){
+		       clipboard.addCollectionData(u);
+		   }
+		   else{
+		       gui.loadPaneFromURL(u, openDataInNewTab);
+		   }
                    return true;
 	        }
 
+		// For the purposes of the clipboard, if it's not a URL, we want to parse
+		// the text fopr MOBY data, rather than display the HTML or RTF, etc.
+		if(clipboard != null){
+		    boolean PLAIN_TEXT = true;
+		    text = convertToString(t, PLAIN_TEXT);
+		}
+
 		// If the text looks like a MOBY XML payload, be nice and create
 		// the proper object to load
 		MobyContentInstance content = HTMLUtils.checkForMobyXML(text);
 		if(content != null){
 		    System.err.println("Dropped item appears to be moby xml...");
-		    gui.loadPaneFromObject(content, true);
+		    if(clipboard != null){
+			clipboard.addCollectionData(content);
+		    }
+		    else{
+			gui.loadPaneFromObject(content, openDataInNewTab);
+		    }
 		    return true;
 		}
 
@@ -117,7 +167,12 @@
 		    out.write(text.getBytes());
 		}
                 out.close();
-                gui.loadPaneFromURL(savedFile.toURI().toURL(), true);
+                if(clipboard != null){
+		    clipboard.addCollectionData(savedFile.toURI().toURL());
+		}
+		else{
+		    gui.loadPaneFromURL(savedFile.toURI().toURL(), openDataInNewTab);
+		}
                 return true;
             }
 	    else{




More information about the MOBY-guts mailing list