Monitor the component's ancestor events so that the tool tip interval
can be registered and unregistered based on component visibility. git-svn-id: https://samskivert.googlecode.com/svn/trunk@311 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
//
|
//
|
||||||
// $Id: ToolTipManager.java,v 1.1 2001/08/22 08:15:39 shaper Exp $
|
// $Id: ToolTipManager.java,v 1.2 2001/08/23 00:16:21 shaper Exp $
|
||||||
|
|
||||||
package com.samskivert.swing;
|
package com.samskivert.swing;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
|
||||||
import com.samskivert.Log;
|
import com.samskivert.Log;
|
||||||
import com.samskivert.util.*;
|
import com.samskivert.util.*;
|
||||||
@@ -25,7 +26,7 @@ import com.samskivert.util.*;
|
|||||||
* as necessary, taking into account standard tool tip timing and
|
* as necessary, taking into account standard tool tip timing and
|
||||||
* semantics.
|
* semantics.
|
||||||
*/
|
*/
|
||||||
public class ToolTipManager implements Interval
|
public class ToolTipManager implements Interval, AncestorListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Construct a tool tip manager for the given observer.
|
* Construct a tool tip manager for the given observer.
|
||||||
@@ -34,13 +35,23 @@ public class ToolTipManager implements Interval
|
|||||||
*/
|
*/
|
||||||
public ToolTipManager (ToolTipObserver obs)
|
public ToolTipManager (ToolTipObserver obs)
|
||||||
{
|
{
|
||||||
|
// save off a reference to the observer
|
||||||
_obs = obs;
|
_obs = obs;
|
||||||
|
|
||||||
|
// set up our starting state
|
||||||
_lastmove = System.currentTimeMillis();
|
_lastmove = System.currentTimeMillis();
|
||||||
_fastshow = false;
|
_fastshow = false;
|
||||||
_tipdelay = TIP_INTERVAL;
|
_tipdelay = TIP_INTERVAL;
|
||||||
|
|
||||||
// register ourselves with the interval manager
|
// register the tip action interval immediately if the
|
||||||
IntervalManager.register(this, TIP_INTERVAL, null, true);
|
// component is already showing on-screen
|
||||||
|
JComponent target = _obs.getComponent();
|
||||||
|
if (target.isShowing()) {
|
||||||
|
registerInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
// listen to the view's ancestor events
|
||||||
|
target.addAncestorListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,6 +71,15 @@ public class ToolTipManager implements Interval
|
|||||||
handleTipAction();
|
handleTipAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the tip action interval with the interval manager.
|
||||||
|
*/
|
||||||
|
protected void registerInterval ()
|
||||||
|
{
|
||||||
|
// register ourselves with the interval manager
|
||||||
|
IntervalManager.register(this, TIP_INTERVAL, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle showing or hiding a tip as necessary.
|
* Handle showing or hiding a tip as necessary.
|
||||||
*/
|
*/
|
||||||
@@ -193,6 +213,25 @@ public class ToolTipManager implements Interval
|
|||||||
protected int _action;
|
protected int _action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** AncestorListener interface methods. */
|
||||||
|
|
||||||
|
public void ancestorAdded (AncestorEvent event)
|
||||||
|
{
|
||||||
|
if (_iid == -1) {
|
||||||
|
// register the tip action interval since we're now visible
|
||||||
|
registerInterval();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ancestorRemoved (AncestorEvent event)
|
||||||
|
{
|
||||||
|
// un-register the tip action interval since we're now hidden
|
||||||
|
IntervalManager.remove(_iid);
|
||||||
|
_iid = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ancestorMoved (AncestorEvent event) { }
|
||||||
|
|
||||||
/** Delay in milliseconds between intervals. */
|
/** Delay in milliseconds between intervals. */
|
||||||
protected static final int TIP_INTERVAL = 1000;
|
protected static final int TIP_INTERVAL = 1000;
|
||||||
|
|
||||||
@@ -218,4 +257,7 @@ public class ToolTipManager implements Interval
|
|||||||
|
|
||||||
/** The tool tip observer. */
|
/** The tool tip observer. */
|
||||||
protected ToolTipObserver _obs;
|
protected ToolTipObserver _obs;
|
||||||
|
|
||||||
|
/** The tip action interval id. */
|
||||||
|
protected int _iid = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
//
|
//
|
||||||
// $Id: ToolTipObserver.java,v 1.1 2001/08/22 08:15:39 shaper Exp $
|
// $Id: ToolTipObserver.java,v 1.2 2001/08/23 00:16:21 shaper Exp $
|
||||||
|
|
||||||
package com.samskivert.swing;
|
package com.samskivert.swing;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface to be implemented by container objects that would like
|
* An interface to be implemented by container objects that would like
|
||||||
* to be notified by the {@link ToolTipManager} when they should
|
* to be notified by the {@link ToolTipManager} when they should
|
||||||
@@ -23,4 +25,11 @@ public interface ToolTipObserver
|
|||||||
* observer is likely to want to repaint itself without the tip.
|
* observer is likely to want to repaint itself without the tip.
|
||||||
*/
|
*/
|
||||||
public void hideToolTip ();
|
public void hideToolTip ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the component associated with the observer so that the
|
||||||
|
* tool tip manager can restrict monitoring the component to when
|
||||||
|
* it's actually visible.
|
||||||
|
*/
|
||||||
|
public JComponent getComponent ();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user