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: TabbedHoverUtil.java,v 1.8 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel.internal;
024:
025: import net.infonode.tabbedpanel.TabbedPanel;
026: import net.infonode.tabbedpanel.TabbedPanelContentPanel;
027: import net.infonode.tabbedpanel.TabbedPanelHoverPolicy;
028:
029: import java.awt.*;
030: import java.util.ArrayList;
031:
032: /**
033: * @author johan
034: */
035: public class TabbedHoverUtil {
036:
037: public static boolean isDeepestHoverableTabbedPanel(
038: ArrayList enterables, TabbedPanel tp) {
039: Component c = (Component) enterables.get(0);
040: while (c != null) {
041: TabbedPanel tp2 = null;
042:
043: if (c instanceof TabbedPanel)
044: tp2 = (TabbedPanel) c;
045:
046: if (c instanceof TabbedPanelContentPanel)
047: tp2 = ((TabbedPanelContentPanel) c).getTabbedPanel();
048:
049: if (tp2 != null)
050: if (tp2 == tp)
051: return true;
052: else if (tp2.getProperties().getHoverPolicy() != TabbedPanelHoverPolicy.ALWAYS_AND_EXCLUDE)
053: return false;
054: /*if (c instanceof TabbedPanel)
055: if (c == tp)
056: return true;
057: else
058: return false;
059:
060: if (c instanceof TabbedPanelContentPanel)
061: if (((TabbedPanelContentPanel) c).getTabbedPanel() == tp)
062: return true;
063: else
064: return false;*/
065:
066: c = c.getParent();
067: }
068:
069: return true;
070: }
071:
072: public static boolean hasVisibleTabbedPanelChild(Component c) {
073: if (c instanceof TabbedPanel
074: && ((TabbedPanel) c).getProperties().getHoverPolicy() != TabbedPanelHoverPolicy.ALWAYS_AND_EXCLUDE)
075: return true;
076:
077: if (c instanceof Container) {
078: Container container = ((Container) c);
079: for (int i = 0; i < container.getComponentCount(); i++) {
080: if (container.getComponent(i).isVisible()
081: && hasVisibleTabbedPanelChild(container
082: .getComponent(i)))
083: return true;
084: }
085: }
086:
087: return false;
088: }
089:
090: public static boolean acceptTabbedPanelHover(
091: TabbedPanelHoverPolicy policy, ArrayList enterables,
092: TabbedPanel tp, Component c) {
093: if (policy == TabbedPanelHoverPolicy.NO_HOVERED_CHILD)
094: return isDeepestHoverableTabbedPanel(enterables, tp);
095:
096: if (policy == TabbedPanelHoverPolicy.NEVER)
097: return false;
098:
099: if (policy == TabbedPanelHoverPolicy.ALWAYS
100: || policy == TabbedPanelHoverPolicy.ALWAYS_AND_EXCLUDE)
101: return true;
102:
103: if (policy == TabbedPanelHoverPolicy.ONLY_WHEN_DEEPEST
104: && c != null)
105: return !hasVisibleTabbedPanelChild(c);
106:
107: return false;
108: }
109: }
|