001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: package com.db.utils.heavytooltip;
034:
035: import java.awt.*;
036: import java.awt.event.*;
037: import javax.swing.*;
038: import java.util.*;
039:
040: // This code is repackaged after the code from Kovalan Muniandy
041: // Site http://www.cis.ohio-state.edu/~muniandy/
042: // Email muniandy@cis.ohio-state.edu
043:
044: public class ToolTipGenerator extends java.awt.event.MouseMotionAdapter {
045:
046: Timer timer = null;
047: ToolTipTrigger trigger = null;
048: Point pt = null;
049:
050: public ToolTipGenerator(ToolTipTrigger theTrigger, int delay) {
051:
052: super ();
053: timer = new Timer(delay);
054: timer.start();
055: trigger = theTrigger;
056:
057: }
058:
059: public void mouseMoved(MouseEvent e) {
060:
061: pt = e.getPoint();
062: timer.restart();
063:
064: }
065:
066: protected class Timer extends Thread implements Runnable {
067:
068: long WAIT_TIME = 0;
069: long last = -1;
070: Point lastPt = null;
071:
072: public Timer(long waitTime) {
073:
074: WAIT_TIME = waitTime;
075:
076: }
077:
078: public void run() {
079:
080: while (true) {
081: try {
082: long elapsed = -1;
083: if (last != -1 && null != lastPt) {
084: elapsed = System.currentTimeMillis() - last;
085: while (elapsed > 0 && pt != null) {
086: if (elapsed > WAIT_TIME) {
087: if (lastPt.equals(pt)) {
088: try {
089: trigger.startToolTip(pt);
090: } catch (Exception e) {
091: System.out
092: .println("Couldn't trigger tooltip: "
093: + e);
094: e.printStackTrace();
095: }
096: lastPt = pt = null;
097: }
098: } else
099: Thread.sleep(WAIT_TIME - elapsed);
100: elapsed = System.currentTimeMillis() - last;
101: }
102: }
103: lastPt = pt;
104: elapsed = System.currentTimeMillis() - last;
105: if (last != -1 && elapsed < WAIT_TIME)
106: Thread.sleep(WAIT_TIME - elapsed);
107: else
108: Thread.sleep(60000);
109: } catch (InterruptedException e) {
110: }
111: }
112:
113: }
114:
115: public void restart() {
116:
117: last = System.currentTimeMillis();
118: interrupt();
119:
120: }
121:
122: }
123:
124: }
|