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: WindowTab.java,v 1.57 2007/01/28 21:25:10 jesper Exp $
023: package net.infonode.docking;
024:
025: import net.infonode.docking.internalutil.*;
026: import net.infonode.docking.properties.WindowTabProperties;
027: import net.infonode.docking.properties.WindowTabStateProperties;
028: import net.infonode.gui.ContainerList;
029: import net.infonode.gui.panel.DirectionPanel;
030: import net.infonode.gui.panel.SimplePanel;
031: import net.infonode.properties.propertymap.PropertyMap;
032: import net.infonode.properties.propertymap.PropertyMapListener;
033: import net.infonode.properties.propertymap.PropertyMapTreeListener;
034: import net.infonode.properties.propertymap.PropertyMapWeakListenerManager;
035: import net.infonode.tabbedpanel.titledtab.TitledTab;
036: import net.infonode.tabbedpanel.titledtab.TitledTabStateProperties;
037: import net.infonode.util.Direction;
038:
039: import javax.swing.*;
040: import java.awt.*;
041: import java.awt.event.MouseAdapter;
042: import java.awt.event.MouseEvent;
043: import java.util.Map;
044:
045: /**
046: * @author $Author: jesper $
047: * @version $Revision: 1.57 $
048: */
049: class WindowTab extends TitledTab {
050: private static final TitledTabStateProperties EMPTY_PROPERTIES = new TitledTabStateProperties();
051: private static final WindowTabProperties EMPTY_TAB_PROPERTIES = new WindowTabProperties();
052:
053: private static final ButtonInfo[] buttonInfos = {
054: new UndockButtonInfo(
055: WindowTabStateProperties.UNDOCK_BUTTON_PROPERTIES),
056: new DockButtonInfo(
057: WindowTabStateProperties.DOCK_BUTTON_PROPERTIES),
058: new MinimizeButtonInfo(
059: WindowTabStateProperties.MINIMIZE_BUTTON_PROPERTIES),
060: new RestoreButtonInfo(
061: WindowTabStateProperties.RESTORE_BUTTON_PROPERTIES),
062: new CloseButtonInfo(
063: WindowTabStateProperties.CLOSE_BUTTON_PROPERTIES) };
064:
065: private final DockingWindow window;
066: private AbstractButton[][] buttons = new AbstractButton[WindowTabState
067: .getStateCount()][];
068: private DirectionPanel[] buttonBoxes = new DirectionPanel[WindowTabState
069: .getStateCount()];
070: private DirectionPanel customComponents = new DirectionPanel();
071: private DirectionPanel highlightedFocusedPanel = new DirectionPanel() {
072: public Dimension getMinimumsize() {
073: return new Dimension(0, 0);
074: }
075: };
076: private WindowTabProperties windowTabProperties = new WindowTabProperties(
077: EMPTY_TAB_PROPERTIES);
078: private ContainerList tabComponentsList;
079: private boolean isFocused;
080:
081: private PropertyMapListener windowPropertiesListener = new PropertyMapListener() {
082: public void propertyValuesChanged(PropertyMap propertyObject,
083: Map changes) {
084: updateTabButtons(null);
085: }
086: };
087:
088: private PropertyMapTreeListener windowTabPropertiesListener = new PropertyMapTreeListener() {
089: public void propertyValuesChanged(Map changes) {
090: updateTabButtons(changes);
091: }
092: };
093:
094: WindowTab(DockingWindow window, boolean emptyContent) {
095: super (window.getTitle(), window.getIcon(), emptyContent ? null
096: : new SimplePanel(window), null);
097: this .window = window;
098:
099: for (int i = 0; i < WindowTabState.getStateCount(); i++) {
100: buttonBoxes[i] = new DirectionPanel() {
101: public Dimension getMinimumSize() {
102: return new Dimension(0, 0);
103: }
104: };
105: buttons[i] = new AbstractButton[buttonInfos.length];
106: }
107:
108: highlightedFocusedPanel.add(customComponents);
109: highlightedFocusedPanel
110: .add(buttonBoxes[WindowTabState.HIGHLIGHTED.getValue()]);
111: setHighlightedStateTitleComponent(highlightedFocusedPanel);
112: setNormalStateTitleComponent(buttonBoxes[WindowTabState.NORMAL
113: .getValue()]);
114:
115: addMouseListener(new MouseAdapter() {
116: public void mousePressed(MouseEvent e) {
117: getWindow().fireTabWindowMouseButtonEvent(e);
118: checkPopupMenu(e);
119: }
120:
121: public void mouseClicked(MouseEvent e) {
122: getWindow().fireTabWindowMouseButtonEvent(e);
123: }
124:
125: public void mouseReleased(MouseEvent e) {
126: getWindow().fireTabWindowMouseButtonEvent(e);
127: checkPopupMenu(e);
128: }
129:
130: private void checkPopupMenu(MouseEvent e) {
131: if (e.isPopupTrigger() && contains(e.getPoint())) {
132: WindowTab.this .window.showPopupMenu(e);
133: }
134: }
135:
136: });
137:
138: getProperties().addSuperObject(
139: windowTabProperties.getTitledTabProperties());
140:
141: PropertyMapWeakListenerManager.addWeakTreeListener(
142: windowTabProperties.getMap(),
143: windowTabPropertiesListener);
144:
145: PropertyMapWeakListenerManager.addWeakListener(this .window
146: .getWindowProperties().getMap(),
147: windowPropertiesListener);
148:
149: windowTabProperties.getTitledTabProperties()
150: .getHighlightedProperties().addSuperObject(
151: EMPTY_PROPERTIES);
152: }
153:
154: public void updateUI() {
155: super .updateUI();
156:
157: if (buttonBoxes != null)
158: for (int i = 0; i < WindowTabState.getStateCount(); i++)
159: if (buttonBoxes[i] != null)
160: SwingUtilities
161: .updateComponentTreeUI(buttonBoxes[i]);
162: }
163:
164: void setFocused(boolean focused) {
165: if (isFocused != focused) {
166: isFocused = focused;
167: TitledTabStateProperties properties = focused ? windowTabProperties
168: .getFocusedProperties()
169: : EMPTY_PROPERTIES;
170: windowTabProperties.getTitledTabProperties()
171: .getHighlightedProperties().getMap()
172: .replaceSuperMap(
173: windowTabProperties
174: .getTitledTabProperties()
175: .getHighlightedProperties()
176: .getMap().getSuperMap(),
177: properties.getMap());
178: highlightedFocusedPanel.remove(1);
179: highlightedFocusedPanel
180: .add(buttonBoxes[focused ? WindowTabState.FOCUSED
181: .getValue() : WindowTabState.HIGHLIGHTED
182: .getValue()]);
183: highlightedFocusedPanel.revalidate();
184: }
185: }
186:
187: void setProperties(WindowTabProperties properties) {
188: windowTabProperties.getMap().replaceSuperMap(
189: windowTabProperties.getMap().getSuperMap(),
190: properties.getMap());
191: }
192:
193: void unsetProperties() {
194: setProperties(EMPTY_TAB_PROPERTIES);
195: }
196:
197: void updateTabButtons(Map changes) {
198: WindowTabState[] states = WindowTabState.getStates();
199:
200: for (int i = 0; i < states.length; i++) {
201: WindowTabState state = states[i];
202: WindowTabStateProperties buttonProperties = state == WindowTabState.FOCUSED ? windowTabProperties
203: .getFocusedButtonProperties()
204: : state == WindowTabState.HIGHLIGHTED ? windowTabProperties
205: .getHighlightedButtonProperties()
206: : windowTabProperties
207: .getNormalButtonProperties();
208:
209: InternalDockingUtil.updateButtons(buttonInfos, buttons[i],
210: buttonBoxes[i], window, buttonProperties.getMap(),
211: changes);
212:
213: buttonBoxes[i]
214: .setDirection((state == WindowTabState.NORMAL ? getProperties()
215: .getNormalProperties()
216: : getProperties()
217: .getHighlightedProperties())
218: .getDirection());
219: }
220:
221: Direction dir = getProperties().getHighlightedProperties()
222: .getDirection();
223: highlightedFocusedPanel.setDirection(dir);
224: customComponents.setDirection(dir);
225: }
226:
227: DockingWindow getWindow() {
228: return window;
229: }
230:
231: void windowTitleChanged() {
232: setText(getWindow().getTitle());
233: setIcon(getWindow().getIcon());
234: }
235:
236: public String toString() {
237: return window != null ? window.toString() : null;
238: }
239:
240: void setContentComponent(Component component) {
241: ((SimplePanel) getContentComponent()).setComponent(component);
242: }
243:
244: java.util.List getCustomTabComponentsList() {
245: if (tabComponentsList == null)
246: tabComponentsList = new ContainerList(customComponents);
247:
248: return tabComponentsList;
249: }
250: }
|