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: TabWindowHoverAction.java,v 1.4 2007/01/28 21:25:10 jesper Exp $
023: package net.infonode.docking;
024:
025: import net.infonode.docking.properties.ViewTitleBarProperties;
026: import net.infonode.gui.hover.HoverEvent;
027: import net.infonode.gui.hover.HoverListener;
028: import net.infonode.tabbedpanel.*;
029: import net.infonode.tabbedpanel.hover.TabbedPanelTitledTabHoverAction;
030: import net.infonode.tabbedpanel.hover.TitledTabTabbedPanelHoverAction;
031: import net.infonode.tabbedpanel.titledtab.TitledTab;
032: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
033:
034: /**
035: * <p>
036: * TabWindowHoverAction is a hover action that makes it easy to change properties for a tab window
037: * and the title bar in the view.
038: * </p>
039: *
040: * <p>
041: * This action contains a titled tab proeprties object, a tabbed panel properties object and a view
042: * title bar properties object. Those objects are automatically added/removed as superobject to the
043: * currently hovered tab window if this action is set as a hover listener in the titled tab properties
044: * and the content panel properties for the tabbed panel.
045: * </p>
046: *
047: * <p>
048: * Example:
049: * <pre>
050: * rootWindowProperties.getTabWindowProperties().getTabbedPanelProperties().getContentPanelProperties().setHoverListener(tabWindowHoverAction);<br>
051: * rootWindowProperties.getTabWindowProperties().getTabProperties().getTitledTabProperties().setHoverListener(tabWindowHoverAction);
052: * </pre>
053: * </p>
054: *
055: * @author johan
056: * @since IDW 1.4.0
057: */
058: public class TabWindowHoverAction implements HoverListener {
059: private TabbedPanelProperties tabbedPanelProperties;
060: private TitledTabProperties titledTabProperties;
061: private ViewTitleBarProperties viewTitleBarProperties;
062:
063: private TabbedPanelTitledTabHoverAction tpTabAction;
064: private TitledTabTabbedPanelHoverAction tabTpAction;
065:
066: private boolean titleBarPropsAdded = false;
067:
068: private TabListener tabListener = new TabAdapter() {
069: public void tabSelected(TabStateChangedEvent event) {
070: if (event.getTab() != null) {
071: DockingWindow w = ((WindowTab) event.getTab())
072: .getWindow();
073: if (!titleBarPropsAdded && w instanceof View)
074: addViewTitleBarProperties((View) w);
075: }
076: }
077:
078: public void tabDeselected(TabStateChangedEvent event) {
079: if (event.getTab() != null) {
080: DockingWindow w = ((WindowTab) event.getTab())
081: .getWindow();
082: if (titleBarPropsAdded && w instanceof View)
083: removeViewTitleBarProperties((View) w);
084: }
085: }
086: };
087:
088: /**
089: * Creates an empty tab window hover action object.
090: */
091: public TabWindowHoverAction() {
092: this (new TabbedPanelProperties(), new TitledTabProperties(),
093: new ViewTitleBarProperties());
094: }
095:
096: public TabWindowHoverAction(
097: TabbedPanelProperties tabbedPanelProperties,
098: TitledTabProperties titledTabProperties,
099: ViewTitleBarProperties viewTitleBarProperties) {
100: this .tabbedPanelProperties = tabbedPanelProperties;
101: this .titledTabProperties = titledTabProperties;
102: this .viewTitleBarProperties = viewTitleBarProperties;
103:
104: tpTabAction = new TabbedPanelTitledTabHoverAction(
105: tabbedPanelProperties, titledTabProperties);
106: tabTpAction = new TitledTabTabbedPanelHoverAction(
107: titledTabProperties, tabbedPanelProperties);
108: }
109:
110: /**
111: * Returns this action's tabbed panel properties
112: *
113: * @return tabbed panel properties
114: */
115: public TabbedPanelProperties getTabbedPanelProperties() {
116: return tabbedPanelProperties;
117: }
118:
119: /**
120: * Returns this action's titled tab properties
121: *
122: * @return titled tab properties
123: */
124: public TitledTabProperties getTitledTabProperties() {
125: return titledTabProperties;
126: }
127:
128: /**
129: * Returns this action's view title bar properties
130: *
131: * @return view title bar properties
132: */
133: public ViewTitleBarProperties getViewTitleBarProperties() {
134: return viewTitleBarProperties;
135: }
136:
137: public void mouseEntered(HoverEvent event) {
138: if (event.getSource() instanceof TabbedPanel) {
139: TabbedPanel tp = (TabbedPanel) event.getSource();
140: tp.addTabListener(tabListener);
141: if (tp.getSelectedTab() != null) {
142: DockingWindow w = ((WindowTab) tp.getSelectedTab())
143: .getWindow();
144: if (w instanceof View)
145: addViewTitleBarProperties((View) w);
146: }
147:
148: tpTabAction.mouseEntered(event);
149: } else if (event.getSource() instanceof TitledTab) {
150: WindowTab tab = (WindowTab) event.getSource();
151: tab.addTabListener(tabListener);
152: if (tab.isSelected() && tab.getWindow() instanceof View)
153: addViewTitleBarProperties((View) tab.getWindow());
154:
155: tabTpAction.mouseEntered(event);
156: }
157: }
158:
159: public void mouseExited(HoverEvent event) {
160: if (event.getSource() instanceof TabbedPanel) {
161: TabbedPanel tp = (TabbedPanel) event.getSource();
162: tp.removeTabListener(tabListener);
163: if (titleBarPropsAdded && tp.getSelectedTab() != null) {
164: DockingWindow w = ((WindowTab) tp.getSelectedTab())
165: .getWindow();
166: if (w instanceof View)
167: removeViewTitleBarProperties((View) w);
168: }
169:
170: tpTabAction.mouseExited(event);
171: } else if (event.getSource() instanceof TitledTab) {
172: WindowTab tab = (WindowTab) event.getSource();
173: tab.removeTabListener(tabListener);
174: if (titleBarPropsAdded && tab.getWindow() instanceof View)
175: removeViewTitleBarProperties((View) tab.getWindow());
176:
177: tabTpAction.mouseExited(event);
178: }
179: }
180:
181: private void addViewTitleBarProperties(View view) {
182: view.getViewProperties().getViewTitleBarProperties()
183: .addSuperObject(viewTitleBarProperties);
184: titleBarPropsAdded = true;
185: }
186:
187: private void removeViewTitleBarProperties(View view) {
188: view.getViewProperties().getViewTitleBarProperties()
189: .removeSuperObject(viewTitleBarProperties);
190: titleBarPropsAdded = false;
191: }
192: }
|