[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Fri Mar 23 20:22:53 UTC 2007


gordonp
Fri Mar 23 16:22:53 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv20323/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentPane.java 
Log Message:
Added ability to paste data into Seahawk (as opposed to existing drag 'n' drop functionality), using ctrl-v, paste keyboard button and middle mouse button
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2007/02/08 16:59:57	1.4
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2007/03/23 20:22:52	1.5
@@ -24,38 +24,24 @@
 import ca.ucalgary.seahawk.util.MobyUtils;
 
 import javax.swing.*;
-import javax.swing.event.CaretEvent;
-import javax.swing.event.CaretListener;
-import javax.swing.event.HyperlinkEvent;
-import javax.swing.event.HyperlinkListener;
+import javax.swing.event.*;
 
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Point;
-import java.awt.print.Printable;
-import java.awt.print.PageFormat;
-import java.awt.print.PrinterException;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.StringWriter;
+import java.awt.print.*;
+import java.awt.event.*;
+import java.io.*;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.AbstractMap;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import java.util.Vector;
+import java.util.*;
 
 /**
  * Text area contained in a Seahawk GUI tab.  Displays HTML, RTF, text etc. using a JEditorPane.
  * Also provides link handling (including service options popup) and drag 'n' drop capabilities.
  */
 
-public class MobyContentPane extends JPanel implements Printable, CaretListener, HyperlinkListener, MouseListener, MobyRequestEventHandler{
+public class MobyContentPane extends JPanel implements Printable, CaretListener, HyperlinkListener, MouseListener, MobyRequestEventHandler, KeyListener{
     public static final String MOBY_SERVICE_POPUP_NAME = "seahawkServicePopup";
     public static final String WAITING_TAB_ICON_RESOURCE = "ca/ucalgary/seahawk/resources/images/hourglass.gif";
     public static final String FAILED_TAB_ICON_RESOURCE = "ca/ucalgary/seahawk/resources/images/failed.gif";
@@ -93,10 +79,13 @@
 	contentGUI = cGUI;
 	servicesGUI = sGUI;
 
+	// The next line is what provides the drag 'n' drop capability
+	addKeyListener(this);
 	setTransferHandler(new FileAndTextTransferHandler(cGUI));
 
 	// The following is a non-user editable pane for showing HTML
 	editorPane = new PrintableJEditorPane();
+	editorPane.addKeyListener(this);
 	editorPane.setTransferHandler(getTransferHandler());
 	//editorPane.setPreferredSize(parentComponent.getPreferredSize());
 	editorPane.setEditable(false);
@@ -883,9 +872,23 @@
 
     // MouseListener interface implementation
     public void mouseClicked(MouseEvent e){
+	// Allow middle button paste
+	if(e.getButton() == MouseEvent.BUTTON3 ||
+	   e.getButton() == MouseEvent.BUTTON2 && e.isAltDown()){
+	    paste();
+	}
     }
 
-    public void mouseEntered(MouseEvent e){}
+    /**
+     * Grabs the keyboard focus for the component if the mouse is over it,
+     * which eliminates the need for clicking before using keyboard shortcuts
+     * like Control-v to paste.
+     */
+    public void mouseEntered(MouseEvent e){
+	if(!requestFocusInWindow()){
+	    requestFocus();
+	}
+    }
     
     public void mouseExited(MouseEvent e){}
     
@@ -1067,4 +1070,25 @@
 
 	return scufl.toString();
     }
+
+    /**
+     * Implemented to provide paste functonality (control-v or the paste button on a Sun keyboard),
+     * since the editor panes are not editable and therefore by default do not respond to
+     * paste events.
+     */
+    public void keyPressed(KeyEvent e){
+	System.err.println("Key pressed " + e.getKeyChar());
+	if(e.getKeyCode() == KeyEvent.VK_PASTE ||
+	    e.getKeyCode() == KeyEvent.VK_V && e.isControlDown()){
+	    System.err.println("Paste (pressed)!");
+	    paste();
+	}
+    }
+
+    public void keyReleased(KeyEvent e){}
+    public void keyTyped(KeyEvent e){}
+
+    public void paste(){
+	getTransferHandler().importData(editorPane, java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this));
+    }
 }




More information about the MOBY-guts mailing list