001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: TitledTabDelayedMouseExitHoverAction.java,v 1.6 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel.hover;
024:
025: import net.infonode.gui.hover.HoverEvent;
026: import net.infonode.gui.hover.HoverListener;
027: import net.infonode.gui.hover.action.DelayedHoverExitAction;
028: import net.infonode.tabbedpanel.TabbedPanel;
029: import net.infonode.tabbedpanel.titledtab.TitledTab;
030: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
031:
032: import javax.swing.*;
033:
034: /**
035: * <p>
036: * TitledTabDelayedMouseExitHoverAction is an action that wraps a {@link HoverListener} and delays
037: * the mouse exit when a {@link TitledTab} is no longer hovered. The action is meant to be set
038: * as a {@link HoverListener} in the {@link TitledTabProperties}.
039: * </p>
040: *
041: * <p>
042: * If the TitledTab is hovered again before the delay has timed out, the timer is reset. If the
043: * TitledTab is removed before the delay has timed out the hover listener's mouseExit() will be
044: * called immediately.
045: * </p>
046: *
047: * @author johan
048: * @version $Revision: 1.6 $
049: * @see TitledTab
050: * @see TitledTabProperties
051: * @since ITP 1.3.0
052: */
053: public class TitledTabDelayedMouseExitHoverAction implements
054: HoverListener {
055: private DelayedHoverExitAction delayedAction;
056: private HoverListener hoverListener;
057:
058: /**
059: * Creates a TitledTabDelayedMouseExitHoverAction object with the given HoverListener as action
060: *
061: * @param delay delay in milliseconds before the hover listener is called when the
062: * titled tab is no longer hovered
063: * @param hoverListener reference to a HoverListener
064: */
065: public TitledTabDelayedMouseExitHoverAction(int delay,
066: HoverListener hoverListener) {
067: this .hoverListener = hoverListener;
068:
069: delayedAction = new DelayedHoverExitAction(new HoverListener() {
070: public void mouseEntered(HoverEvent event) {
071: getHoverListener().mouseEntered(event);
072: }
073:
074: public void mouseExited(HoverEvent event) {
075: getHoverListener().mouseExited(event);
076: }
077: }, delay);
078: }
079:
080: /**
081: * Gets the hover listener
082: *
083: * @return the hoverListener.
084: */
085: public HoverListener getHoverListener() {
086: return hoverListener;
087: }
088:
089: /**
090: * Gets the TitledTabProperties object for this action.
091: *
092: * @return reference to the TitledTabProperties or null
093: * if the delayed action is not a TitledTabHoverAction
094: */
095: public TitledTabProperties getTitledTabProperties() {
096: if (getHoverListener() instanceof TitledTabHoverAction)
097: return ((TitledTabHoverAction) getHoverListener())
098: .getTitledTabProperties();
099:
100: return null;
101: }
102:
103: public void mouseEntered(HoverEvent event) {
104: delayedAction.mouseEntered(event);
105: }
106:
107: public void mouseExited(HoverEvent event) {
108: final TitledTab tab = (TitledTab) event.getSource();
109: final TabbedPanel tp = tab.getTabbedPanel();
110:
111: delayedAction.mouseExited(event);
112:
113: SwingUtilities.invokeLater(new Runnable() {
114: public void run() {
115: if (tab.getTabbedPanel() != tp) {
116: delayedAction.forceExit(tab);
117: }
118: }
119: });
120: }
121: }
|