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: TitledTabTabbedPanelHoverAction.java,v 1.5 2005/02/16 11:28:14 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.tabbedpanel.TabAdapter;
028: import net.infonode.tabbedpanel.TabStateChangedEvent;
029: import net.infonode.tabbedpanel.TabbedPanel;
030: import net.infonode.tabbedpanel.TabbedPanelProperties;
031: import net.infonode.tabbedpanel.titledtab.TitledTab;
032: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
033:
034: /**
035: * <p>
036: * TitledTabTabbedPanelHoverAction is an action that makes it easy to change
037: * properties for a hovered {@link TitledTab} and the {@link TabbedPanel} it is a
038: * member of. The action is meant to be set as a {@link HoverListener} for a
039: * TitledTab in the
040: * {@link net.infonode.tabbedpanel.titledtab.TitledTabProperties}.
041: * </p>
042: *
043: * <p>
044: * The action can be configured to add the TabbedPanelProperties only when the
045: * highlighted TitledTab is hovered or when any of the TitledTabs are hovered.
046: * </p>
047: *
048: * <p>
049: * This hover action contains a TitledTabProperties object that will be added as
050: * super object to the hovered titled tab and then automatically removed when
051: * the titled tab is no longer hovered. It also contains a TabbedPanelProperties
052: * object that will be added as super object to the tabbed panel that the
053: * hovered titled tab is a member of. The TabbedPanelProperties are
054: * automatically removed from the tabbed panel if the hovered titled tab is
055: * removed.
056: * </p>
057: *
058: * <p>
059: * <strong>Note: </strong> This action is not meant to be set as hover listener
060: * for a Tabbed Panel (or any of its areas). For TabbedPanel, use
061: * {@link net.infonode.tabbedpanel.hover.TabbedPanelTitledTabHoverAction} instead.
062: * </p>
063: *
064: * @author johan
065: * @version $Revision: 1.5 $
066: * @see TabbedPanel
067: * @see TitledTab
068: * @see net.infonode.tabbedpanel.titledtab.TitledTabProperties
069: * @see TabbedPanelProperties
070: * @see net.infonode.tabbedpanel.hover.TabbedPanelTitledTabHoverAction
071: * @since ITP 1.3.0
072: */
073: public class TitledTabTabbedPanelHoverAction implements HoverListener {
074: private TabbedPanelProperties tabbedPanelProperties;
075: private TitledTabProperties titledTabProperties;
076:
077: private boolean applied = false;
078: private boolean onlyHighlighted;
079:
080: private TabAdapter tabListener = new TabAdapter() {
081: public void tabHighlighted(TabStateChangedEvent event) {
082: if (event.getCurrentTab() != null && onlyHighlighted)
083: applyTabbedPanel(event.getCurrentTab().getTabbedPanel());
084: }
085:
086: public void tabDehighlighted(TabStateChangedEvent event) {
087: if (event.getPreviousTab() != null && onlyHighlighted)
088: removeTabbedPanel(event.getPreviousTab()
089: .getTabbedPanel());
090: }
091: };
092:
093: /**
094: * Creates a TitledTabTabbedPanelHoverAction containing an empty
095: * TitledTabProperties object and an empty TabbedPanelProperties object. The
096: * TabbedPanelProperties are only applied when the highlighted tab is
097: * hovered.
098: */
099: public TitledTabTabbedPanelHoverAction() {
100: this (new TitledTabProperties(), new TabbedPanelProperties());
101: }
102:
103: /**
104: * Creates a TitledTabTabbedPanelHoverAction containing an empty
105: * TitledTabProperties object and an empty TabbedPanelProperties object.
106: *
107: * @param allTabs true if the TabbedPanelProperties should be applied to the
108: * tabbed panel when a tab is hovered, false if it should only be
109: * applied when the the highlighted tab is hovered
110: */
111: public TitledTabTabbedPanelHoverAction(boolean allTabs) {
112: this (new TitledTabProperties(), new TabbedPanelProperties(),
113: allTabs);
114: }
115:
116: /**
117: * Creates a TitledTabTabbedPanelHoverAction containing with the given
118: * TitledTabProperties object and the given TabbedPanelProperties object.
119: * The TabbedPanelProperties are only applied when the highlighted tab is
120: * hovered.
121: *
122: * @param titledTabProperties reference to a TitledTabProperties object
123: * @param tabbedPanelProperties reference to a TabbedPanelProperties object
124: */
125: public TitledTabTabbedPanelHoverAction(
126: TitledTabProperties titledTabProperties,
127: TabbedPanelProperties tabbedPanelProperties) {
128: this (titledTabProperties, tabbedPanelProperties, false);
129: }
130:
131: /**
132: * Creates a TitledTabTabbedPanelHoverAction containing with the given
133: * TitledTabProperties object and the given TabbedPanelProperties object.
134: *
135: * @param titledTabProperties reference to a TitledTabProperties object
136: * @param tabbedPanelProperties reference to a TabbedPanelProperties object
137: * @param allTabs true if the TabbedPanelProperties should be applied to the
138: * tabbed panel when a tab is hovered, false if it should only be
139: * applied when the the highlighted tab is hovered
140: */
141: public TitledTabTabbedPanelHoverAction(
142: TitledTabProperties titledTabProperties,
143: TabbedPanelProperties tabbedPanelProperties, boolean allTabs) {
144: this .titledTabProperties = titledTabProperties;
145: this .tabbedPanelProperties = tabbedPanelProperties;
146: this .onlyHighlighted = !allTabs;
147: }
148:
149: /**
150: * Gets the TitledTabProperties object for this action.
151: *
152: * @return reference to the TitledTabProperties
153: */
154: public TitledTabProperties getTitledTabProperties() {
155: return titledTabProperties;
156: }
157:
158: /**
159: * Gets the TabbedPanelProperties object for this action.
160: *
161: * @return reference to the TabbedPanelProperties
162: */
163: public TabbedPanelProperties getTabbedPanelProperties() {
164: return tabbedPanelProperties;
165: }
166:
167: public void mouseEntered(HoverEvent event) {
168: TitledTab tab = (TitledTab) event.getSource();
169: if (onlyHighlighted) {
170: tab.addTabListener(tabListener);
171: if (tab.isHighlighted())
172: applyTabbedPanel(tab.getTabbedPanel());
173: } else {
174: applyTabbedPanel(tab.getTabbedPanel());
175: }
176:
177: tab.getProperties().addSuperObject(titledTabProperties);
178: }
179:
180: public void mouseExited(HoverEvent event) {
181: TitledTab tab = (TitledTab) event.getSource();
182: removeTabbedPanel(tab.getTabbedPanel());
183: if (onlyHighlighted)
184: tab.removeTabListener(tabListener);
185: tab.getProperties().removeSuperObject(titledTabProperties);
186: }
187:
188: private void applyTabbedPanel(TabbedPanel tabbedPanel) {
189: if (!applied) {
190: tabbedPanel.getProperties().addSuperObject(
191: tabbedPanelProperties);
192: applied = true;
193: }
194: }
195:
196: private void removeTabbedPanel(TabbedPanel tabbedPanel) {
197: if (applied) {
198: tabbedPanel.getProperties().removeSuperObject(
199: tabbedPanelProperties);
200: applied = false;
201: }
202: }
203: }
|