/** * Distribution License: * BibleDesktop is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 2 as published by * the Free Software Foundation. This program is distributed in the hope * that it will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * The License is available on the internet at: * http://www.gnu.org/copyleft/gpl.html * or by writing to: * Free Software Foundation, Inc. * 59 Temple Place - Suite 330 * Boston, MA 02111-1307, USA * * Copyright: 2005 * The copyright to this program is held by it's authors. * * ID: $Id: URIToolTip.java 1966 2010-1-11 01:15:14Z lanyjie $ */ package org.crosswire.bibledesktop.display; import java.util.EventListener; import javax.swing.ToolTipManager; //import javax.swing.JToolTip; /** * Implement URIEventListener to recieve URIEvents whenever someone activates an * URI. * * @see gnu.gpl.License for license details.
* The copyright to this program is held by it's authors. * @author Yingjie Lan [lanyjie at yahoo dot com] */ public class URIToolTip implements URIEventListener { int formerInitialDelay; int formerDismissDelay; int myInitialDelay=2000; int myDismissDelay=60000; /** * The component, the txtView in * basic/TextPaneBookDataDisplay.java */ JComponent comp; /** * The most recent interested event, which is used * for content retrieving. */ URIEvent event; /** * ctor: after creation, add this as a listener to * a BookDataDisplay, for example: * basic/TextPaneBookDataDisplay.java * * This class can also have a list of URIEvent * content retrievers, who specialize in retrieving * the content of a URI request and may also perform * some kind of processing, such as converting * to html (return a string if success, null o/w): * * Such specialized retrievers will have two methods: * public boolean handles(String protocol); * public String retrieve(URIEvent evt); */ public URIToolTip(JComponent comp){ this.comp = comp; } /** * This is only called when the component needs to * display the tip; note we delay this expensive * operation until needed; a typical use is to * have it in the getToolTipText() method of the * managed component: * * public String getToolTipText(){ * return uritip.retrieve(); * } */ public String retrieve(){ if event==null: return null; //TODO: retreives the content of the URI return event.toString(); //dummy impl. } /** * This method is called to indicate that an URI can be processed. * * @param ev * Describes the URI */ void activateURI(URIEvent ev){ if(!interested(ev)) return; } /** * This method is called to indicate that the mouse has entered the URI. * * @param ev * Describes the URI */ void enterURI(URIEvent ev){ if(!interested(ev)) return; // Get current delay formerInitialDelay = ToolTipManager.sharedInstance().getInitialDelay(); // Show tool tips soon enough ToolTipManager.sharedInstance().setInitialDelay(myInitialDelay); // Get current delay formerDismissDelay = ToolTipManager.sharedInstance().getDismissDelay(); // Set delay longer enough ToolTipManager.sharedInstance().setDismissDelay(myDismissDelay); event = ev; //register event // Enable tool tips for the entire application // ToolTipManager.sharedInstance().setEnabled(true); } /** * This method is called to indicate that the mouse has left the URI. * * @param ev * Describes the URI */ void leaveURI(URIEvent ev){ if(!interested(ev)) return; // Disable tool tips for the entire application // ToolTipManager.sharedInstance().setEnabled(false); ToolTipManager.sharedInstance().setInitialDelay(formerInitialDelay); ToolTipManager.sharedInstance().setDismissDelay(formerDismissDelay); event = null;//clear event } boolean interested(URIEvent ev){ return false; //tell if it is interested in ev } }