[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Feb 3 21:50:51 UTC 2011


gordonp
Thu Feb  3 16:50:50 EST 2011
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv20460/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentPane.java 
Log Message:
Fixes for font resizing, copying of data from Seahawk to the clipboard
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.33,1.34
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2010/05/13 16:12:19	1.33
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2011/02/03 21:50:50	1.34
@@ -31,9 +31,11 @@
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.DefaultHighlighter;
 import javax.swing.text.Highlighter;
+import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 import javax.swing.text.StyledDocument;
+import javax.swing.text.html.CSS;
 import javax.swing.text.html.HTML;
 import javax.swing.text.html.HTMLDocument;
 
@@ -81,6 +83,7 @@
 
     /** The name of the param in the stylesheet that will hold the Moby doc URL for XPointer usage */
     public final static String XSL_DOC_SOURCE_PARAM = "sourceURL";
+    public final static String XSL_DOC_FONTSIZE_PARAM = "fontSize";
 
     private JScrollPane scrollPane;
     protected JTabbedPane tabbedPane;
@@ -110,6 +113,7 @@
     private Map<String,Boolean> jobXPtrs = null;  // Map<xptr,has a HAS member>
     private List<AttributeSet> origStyles = null;
     private boolean firstDocRendering = true;
+    private String tempFontSize = null;
 
     // Next two items used for service wrapping
     private JMenuItem createServicePopupItem;
@@ -485,6 +489,20 @@
     }
 
     /**
+     * Used to temporarily change the font size of the displayed document.  
+     * Normally the SeahawkOptions values are used. 
+     *
+     * @param fontSize an absolute or relative font size as per HTML's basefont size specification.  If null, document default size is used.
+     */
+    public synchronized void setFontSize(String fontSize){
+	tempFontSize = fontSize == null ? "100%" : fontSize;
+	gotoURL(getCurrentURL(), false);
+	// Also notify filter widget since the text input field will need resizing
+	filterSearchWidget.fontSizeChanged(tempFontSize);
+	tempFontSize = null;
+    }
+
+    /**
      * This is the URLLoader callback method the MOBY data fetcher
      * will call when MOBY XML data is ready to be seen.
      */
@@ -534,7 +552,12 @@
 		}
 		
 		// Tell the stylesheet the URL of the moby data (it will create xpointers to it)
-		contentGUI.getTransformer().setParameter(XSL_DOC_SOURCE_PARAM, url.toString());
+		contentGUI.getTransformer().setParameter(XSL_DOC_SOURCE_PARAM, 
+							 url.toString());
+		//String fontSize = tempFontSize != null ? tempFontSize : SeahawkOptions.getFontSize();
+		//System.err.println("Font size for XML doc will be "+fontSize);
+		//contentGUI.getTransformer().setParameter(XSL_DOC_FONTSIZE_PARAM, 
+		//					 fontSize);
 		// Do the actual transformation
 		String htmlContents = "[Seahawk Internal Error]";
 		try{
@@ -542,6 +565,9 @@
 		    contentGUI.getTransformer().transform(new StreamSource(url.openStream()),
 							  new StreamResult(stringWriter));
 		    htmlContents = stringWriter.toString();
+		    if(htmlContents == null || htmlContents.length() == 0){
+			htmlContents = "[Empty]";
+		    }
 		    // NOTE: If you switch the registry in the middle of using Seahawk,
 		    // the following might fail on documents in the history, as they were
 		    // encoded according to a different registry than the current value of 
@@ -549,7 +575,9 @@
 		    // registries, there has to be a way to note the source registry for the data in the 
 		    // document (preferred), or we must maintain a hash of the document:registry mappings
 		    // for the session.
-		    htmlContents = HTMLUtils.encapsulateBinaryData(url, htmlContents, SeahawkOptions.getRegistry());
+		    else{
+			htmlContents = HTMLUtils.encapsulateBinaryData(url, htmlContents, SeahawkOptions.getRegistry());
+		    }
 		}
 		catch(TransformerException te){
 		    status.setText("Sorry!  Could not transform the MOBY data into presentation form");
@@ -710,6 +738,16 @@
 	    e.printStackTrace();
 	}
 
+	// Adjust font size if necessary in HTML docs
+	if((tempFontSize != null || !SeahawkOptions.getFontSize().equals("100%")) && 
+	   editorPane.getDocument() instanceof HTMLDocument){
+	    HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
+	    MutableAttributeSet attr = new SimpleAttributeSet();
+	    String fontSize = tempFontSize != null ? tempFontSize : SeahawkOptions.getFontSize();
+	    doc.getStyleSheet().addCSSAttribute(attr, CSS.Attribute.FONT_SIZE, fontSize);
+	    doc.setCharacterAttributes(0, editorPane.getDocument().getLength(), attr, false);
+	}
+
 	setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 
 	if(addToHistory){
@@ -854,6 +892,7 @@
      * PBE recorder.
      */
     public void exportDone(String valuePasted, String transformRuleURI){
+	System.err.println("Export done, notifying wrapping servlet (if any)");
 	if(cgiServlet != null && cgiServlet.getRecorder() != null && (cgiServlet.getRecorder() instanceof PBERecorder)){
 	    ((PBERecorder) cgiServlet.getRecorder()).dataCopied(getDraggedData(), valuePasted, transformRuleURI);
 	}
@@ -1124,6 +1163,8 @@
     public void hyperlinkUpdate(HyperlinkEvent he){
 	URL targetURL = he.getURL();
 	if(he.getEventType() == HyperlinkEvent.EventType.ACTIVATED){
+	    overHyperlink = true;
+	    lastHyperlinkHovered = targetURL;
 	    // Internal moby pseudo-URL
 	    if(targetURL == null){
 		String desc = he.getDescription();
@@ -1554,6 +1595,9 @@
 	}
 
         FilterSearch filter = filterHistory.get(getCurrentURL());
+	if(getCurrentDoc() == null){
+	    return;
+	}
 	filterableNodes = DataUtils.findFilteredNodes(getCurrentDoc(), filter, filterableNodes, filteredData, jobXPtrs,
                                                       currentSelectedData, currentSelectionXPath, apply);
  
@@ -1660,7 +1704,7 @@
 		    javax.swing.text.Element el = d.getElement(filterable);
 		    String fragment = d.getText(el.getStartOffset(),
 						el.getEndOffset() - el.getStartOffset());
-		    Matcher matcher = p.matcher(fragment);
+		    Matcher matcher = p.matcher(fragment.trim());
 		    while (matcher.find()) {
 			// Only count match if not already highlighted in a containing filterable node
 			// todo: in future, avoid looking in text bits already checked, for efficiency
@@ -1880,6 +1924,10 @@
 	    return;
 	}
 	else{  // keep track of the previous selection so we can use it once it's gone
+	    if(dragging){ //if a hyperlink is being dragged, don't highlight too
+		System.err.println("Ignoring highlight while dragging hyperlink");
+		return;
+	    }
 	    oldMark = mark;
 	    oldDot = dot;
 	}
@@ -1904,13 +1952,29 @@
 	    tab.getDisplay().setText("Use the file/globe icon at the bottom of this window to load data," +
 				     "or drag'n'drop/paste data from your desktop or Web browser.");
 	}
+	// Ctrl+C copy of selection if any
+	if(e.getKeyCode() == KeyEvent.VK_C && e.isControlDown() && selectedTextData != null){
+	    getTransferHandler().exportToClipboard(this, 
+						   Toolkit.getDefaultToolkit().getSystemClipboard(), 
+	    					   TransferHandler.COPY);
+	}
     }
 
     public void keyReleased(KeyEvent e){}
     public void keyTyped(KeyEvent e){}
 
+    public boolean isDraggingHyperlink(){
+	return dragging;
+    }
+
+    public String getSelectedText(){
+	return selectedTextData;
+    }
+
     public void paste(){
-	getTransferHandler().importData(this, Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this));
+	if(!dragging){ //don't allow drag onto self...
+	    getTransferHandler().importData(this, Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this));
+	}
     }
 
     public void mouseDragged(MouseEvent e){
@@ -1919,13 +1983,14 @@
 	    dragging = true;  // so we don't export many times in a row while dragging
 	    lastHyperlinkDragged = lastHyperlinkHovered;
 	    status.setText("Drop the hyperlink onto a Web form field to populate it");
-	    getTransferHandler().exportToClipboard(this, 
-						   Toolkit.getDefaultToolkit().getSystemClipboard(), 
-						   TransferHandler.COPY);
+	    System.err.println("Dragging initiated via mouseDragged for "+lastHyperlinkDragged);
+	    //getTransferHandler().exportToClipboard(this, 
+	    //				   Toolkit.getDefaultToolkit().getSystemClipboard(), 
+	    //					   TransferHandler.COPY);
 	    getTransferHandler().exportAsDrag(this, e, TransferHandler.COPY);
 	}
 	else if(!dragging){
-	    //System.err.println("Dragging with no hyperlink activated");
+	    System.err.println("Dragging with no hyperlink activated");
 	}
     }
 
@@ -1935,18 +2000,24 @@
 	// mouse button being down here.
 	if(overHyperlink && (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK){
 	    //System.err.println("Got wonky drag");
-	    lastHyperlinkDragged = lastHyperlinkHovered;
 	    status.setText("Drop the hyperlink onto a Web form field to populate it");
-	    //System.err.println("Dragging "+lastHyperlinkDragged);
-	    getTransferHandler().exportAsDrag(this, e, TransferHandler.COPY);
+	    if(lastHyperlinkDragged != lastHyperlinkHovered){
+		System.err.println("Dragging initiated via mouseMoved for "+lastHyperlinkDragged);
+		lastHyperlinkDragged = lastHyperlinkHovered;
+		//getTransferHandler().exportToClipboard(this, 
+		//				       Toolkit.getDefaultToolkit().getSystemClipboard(), 
+		//				       TransferHandler.COPY);
+		getTransferHandler().exportAsDrag(this, e, TransferHandler.COPY);
+	    }
 	}
 	else if(dragging){
+	    System.err.println("Dragging stopped...no mouse down on mouseMoved");
 	    dragging = false;
 	}
     }
 
     public void lostOwnership(Clipboard clipboard, Transferable contents){
-	//System.err.println("Lost clipboard ownership");
+	System.err.println("Lost clipboard ownership");
     }
 
 }




More information about the MOBY-guts mailing list