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: TabbedPanelTitledTabHoverAction.java,v 1.12 2005/04/20 15:43:28 johan 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.*;
028: import net.infonode.tabbedpanel.titledtab.TitledTab;
029: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
030:
031: /**
032: * <p>
033: * TabbedPanelTitledTabHoverAction is an action that makes it easy to change
034: * properties for a hovered {@link TabbedPanel} containing {@link TitledTab}s.
035: * The action is meant to be set as a {@link HoverListener} for the entire
036: * tabbed panel, the tab area, the tab area components area and/or the content
037: * area in their corresponding properties objects.
038: * </p>
039: *
040: * <p>
041: * The action can be configured to add the TitledTabProperties to all tabs or
042: * only the highlighted tab.
043: * </p>
044: *
045: * <p>
046: * This hover action contains a TabbedPanelProperties object that will be added
047: * as super object to the hovered tabbed panel and then automatically removed
048: * when the area is no longer hovered. It also contains a TitledTabProperties
049: * object that will be added as super object to all titled tabs in the hovered
050: * tabbed panel and then removed when the tabbed panel is no longer hovered.
051: * </p>
052: *
053: * <p>
054: * If a titled tab is added to the tabbed panel while the tabbed panel is
055: * hovered, the action will automatically add the TitledTabProperties to the
056: * titled tab. If a titled tab is removed while the tabbed panel is hovered, the
057: * properties will automatically be removed.
058: * </p>
059: *
060: * <p>
061: * <strong>Note: </strong> This action is not meant to be set as hover listener
062: * in the TitledTabProperties for a titled tab. For TitledTab, use
063: * {@link net.infonode.tabbedpanel.hover.TitledTabTabbedPanelHoverAction} instead.
064: * </p>
065: *
066: * @author johan
067: * @version $Revision: 1.12 $
068: * @see TabbedPanel
069: * @see TitledTab
070: * @see TabbedPanelProperties
071: * @see net.infonode.tabbedpanel.TabAreaProperties
072: * @see net.infonode.tabbedpanel.TabAreaComponentsProperties
073: * @see net.infonode.tabbedpanel.TabbedPanelContentPanelProperties
074: * @see net.infonode.tabbedpanel.hover.TitledTabTabbedPanelHoverAction
075: * @see TitledTabProperties
076: * @since ITP 1.3.0
077: */
078: public class TabbedPanelTitledTabHoverAction implements HoverListener {
079: private TabbedPanelProperties tabbedPanelProperties;
080: private TitledTabProperties titledTabProperties;
081: private boolean onlyHighlighted;
082:
083: private TabAdapter tabListener = new TabAdapter() {
084: public void tabAdded(TabEvent event) {
085: if (event.getTab() instanceof TitledTab) {
086: if (!onlyHighlighted
087: || (onlyHighlighted && event.getTab()
088: .isHighlighted())) {
089: ((TitledTab) event.getTab()).getProperties()
090: .addSuperObject(titledTabProperties);
091: }
092: }
093: }
094:
095: public void tabRemoved(TabRemovedEvent event) {
096: if (event.getTab() instanceof TitledTab)
097: ((TitledTab) event.getTab()).getProperties()
098: .removeSuperObject(titledTabProperties);
099: }
100:
101: public void tabHighlighted(TabStateChangedEvent event) {
102: if (event.getCurrentTab() != null
103: && event.getCurrentTab() instanceof TitledTab)
104: applyTitledTabProperties(event.getTabbedPanel(),
105: ((TitledTab) event.getCurrentTab()));
106: }
107:
108: public void tabDehighlighted(TabStateChangedEvent event) {
109: if (event.getPreviousTab() != null
110: && event.getPreviousTab() instanceof TitledTab)
111: removeTitledTabProperties(event.getTabbedPanel(),
112: ((TitledTab) event.getPreviousTab()));
113: }
114: };
115:
116: /**
117: * Creates a TabbedPanelTitledTabHoverAction containing an empty
118: * TabbedPanelProperties object and an empty TitledTabProperties object. The
119: * TitledTabProperties are only applied to the highlighted tab.
120: */
121: public TabbedPanelTitledTabHoverAction() {
122: this (false);
123: }
124:
125: /**
126: * Creates a TabbedPanelTitledTabHoverAction containing an empty
127: * TabbedPanelProperties object and an empty TitledTabProperties object.
128: *
129: * @param allTabs true if TitledTabProperties should be applied to all tabs,
130: * false if only to the highlighted tab
131: */
132: public TabbedPanelTitledTabHoverAction(boolean allTabs) {
133: this (new TabbedPanelProperties(), new TitledTabProperties(),
134: allTabs);
135: }
136:
137: /**
138: * Creates a TabbedPanelTitledTabHoverAction with the given
139: * TabbedPanelProperties object and the given TitledTabProperties object.
140: * The TitledTabProperties are only applied to the highlighted tab.
141: *
142: * @param tabbedPanelProperties reference to a TabbedPanelProperties object
143: * @param titledTabProperties reference to a TitledTabProperties object
144: */
145: public TabbedPanelTitledTabHoverAction(
146: TabbedPanelProperties tabbedPanelProperties,
147: TitledTabProperties titledTabProperties) {
148: this (tabbedPanelProperties, titledTabProperties, false);
149: }
150:
151: /**
152: * Creates a TabbedPanelTitledTabHoverAction with the given
153: * TabbedPanelProperties object and the given TitledTabProperties object.
154: *
155: * @param tabbedPanelProperties reference to a TabbedPanelProperties object
156: * @param titledTabProperties reference to a TitledTabProperties object
157: * @param allTabs true if TitledTabProperties should be applied to all tabs,
158: * false if only to the highlighted tab
159: */
160: public TabbedPanelTitledTabHoverAction(
161: TabbedPanelProperties tabbedPanelProperties,
162: TitledTabProperties titledTabProperties, boolean allTabs) {
163: this .tabbedPanelProperties = tabbedPanelProperties;
164: this .titledTabProperties = titledTabProperties;
165: this .onlyHighlighted = !allTabs;
166: }
167:
168: /**
169: * Gets the TitledTabProperties object for this action.
170: *
171: * @return reference to the TitledTabProperties
172: */
173: public TitledTabProperties getTitledTabProperties() {
174: return titledTabProperties;
175: }
176:
177: /**
178: * Gets the TabbedPanelProperties object for this action.
179: *
180: * @return reference to the TabbedPanelProperties
181: */
182: public TabbedPanelProperties getTabbedPanelProperties() {
183: return tabbedPanelProperties;
184: }
185:
186: public void mouseEntered(HoverEvent event) {
187: TabbedPanel tp = (TabbedPanel) event.getSource();
188: tp.getProperties().addSuperObject(tabbedPanelProperties);
189: tp.addTabListener(tabListener);
190: if (tp.getHighlightedTab() != null
191: && tp.getHighlightedTab() instanceof TitledTab)
192: applyTitledTabProperties(tp, ((TitledTab) tp
193: .getHighlightedTab()));
194: else
195: applyTitledTabProperties(tp, null);
196: }
197:
198: public void mouseExited(HoverEvent event) {
199: TabbedPanel tp = (TabbedPanel) event.getSource();
200: tp.getProperties().removeSuperObject(tabbedPanelProperties);
201: tp.removeTabListener(tabListener);
202: if (tp.getHighlightedTab() != null
203: && tp.getHighlightedTab() instanceof TitledTab)
204: removeTitledTabProperties(tp, ((TitledTab) tp
205: .getHighlightedTab()));
206: else
207: removeTitledTabProperties(tp, null);
208: }
209:
210: private void applyTitledTabProperties(TabbedPanel tabbedPanel,
211: TitledTab titledTab) {
212: if (onlyHighlighted) {
213: if (titledTab != null)
214: titledTab.getProperties().addSuperObject(
215: titledTabProperties);
216: } else {
217: for (int i = 0; i < tabbedPanel.getTabCount(); i++) {
218: Tab tab = tabbedPanel.getTabAt(i);
219: if (tab instanceof TitledTab)
220: ((TitledTab) tab).getProperties().addSuperObject(
221: titledTabProperties);
222: }
223: }
224: }
225:
226: private void removeTitledTabProperties(TabbedPanel tabbedPanel,
227: TitledTab titledTab) {
228: if (onlyHighlighted) {
229: if (titledTab != null)
230: titledTab.getProperties().removeSuperObject(
231: titledTabProperties);
232: } else {
233: for (int i = 0; i < tabbedPanel.getTabCount(); i++) {
234: Tab tab = tabbedPanel.getTabAt(i);
235: if (tab instanceof TitledTab)
236: ((TitledTab) tab).getProperties()
237: .removeSuperObject(titledTabProperties);
238: }
239: }
240: }
241: }
|