001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client.ui;
029
030import com.google.gwt.event.dom.client.MouseOutEvent;
031import com.google.gwt.event.dom.client.MouseOutHandler;
032import com.google.gwt.event.dom.client.MouseOverEvent;
033import com.google.gwt.event.dom.client.MouseOverHandler;
034import com.google.gwt.user.client.Timer;
035
036/**
037 * On hover intent handler.<p>
038 *
039 * @since 8.0.0
040 */
041public abstract class A_CmsHoverHandler implements MouseOutHandler, MouseOverHandler {
042
043    /** Timer to achieve the hover intent effect. */
044    protected Timer m_timer;
045
046    /**
047     * @see com.google.gwt.event.dom.client.MouseOutHandler#onMouseOut(com.google.gwt.event.dom.client.MouseOutEvent)
048     */
049    public final void onMouseOut(MouseOutEvent event) {
050
051        if (m_timer != null) {
052            m_timer.cancel();
053            m_timer = null;
054        } else {
055            onHoverOut(event);
056        }
057    }
058
059    /**
060     * @see com.google.gwt.event.dom.client.MouseOverHandler#onMouseOver(com.google.gwt.event.dom.client.MouseOverEvent)
061     */
062    public final void onMouseOver(final MouseOverEvent event) {
063
064        if (m_timer != null) {
065            return;
066        }
067        m_timer = new Timer() {
068
069            /**
070             * @see com.google.gwt.user.client.Timer#run()
071             */
072            @Override
073            public void run() {
074
075                m_timer = null;
076                onHoverIn(event);
077            }
078        };
079        m_timer.schedule(100);
080    }
081
082    /**
083     * Will be executed for starting the hover effect.<p>
084     *
085     * @param event the mouse event
086     */
087    protected abstract void onHoverIn(MouseOverEvent event);
088
089    /**
090     * Will be executed for finishing the hover effect.<p>
091     *
092     * @param event the mouse event
093     */
094    protected abstract void onHoverOut(MouseOutEvent event);
095}