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: TabbedPanelContentPanel.java,v 1.59 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel;
024:
025: import net.infonode.gui.ComponentPaintChecker;
026: import net.infonode.gui.draggable.DraggableComponentBoxAdapter;
027: import net.infonode.gui.draggable.DraggableComponentBoxEvent;
028: import net.infonode.gui.draggable.DraggableComponentEvent;
029: import net.infonode.gui.hover.HoverListener;
030: import net.infonode.gui.hover.panel.HoverableShapedPanel;
031: import net.infonode.gui.panel.BaseContainer;
032: import net.infonode.gui.panel.BaseContainerUtil;
033: import net.infonode.properties.gui.InternalPropertiesUtil;
034: import net.infonode.properties.propertymap.PropertyMapTreeListener;
035: import net.infonode.properties.propertymap.PropertyMapWeakListenerManager;
036: import net.infonode.tabbedpanel.internal.TabbedHoverUtil;
037: import net.infonode.util.Direction;
038: import net.infonode.util.ValueChange;
039:
040: import javax.swing.*;
041: import java.awt.*;
042: import java.awt.event.MouseEvent;
043: import java.util.ArrayList;
044: import java.util.Map;
045:
046: /**
047: * A TabbedPanelContentPanel is a component that holds a container for tab content
048: * components. It can be configured using properties that specifies the look for
049: * the content panel.
050: *
051: * @author $Author: jesper $
052: * @version $Revision: 1.59 $
053: * @see TabbedPanel
054: * @see Tab
055: */
056: public class TabbedPanelContentPanel extends BaseContainer {
057: private TabbedPanel tabbedPanel;
058: private HoverableShapedPanel shapedPanel;
059: private ComponentPaintChecker repaintChecker;
060:
061: private PropertyMapTreeListener propertiesListener = new PropertyMapTreeListener() {
062: public void propertyValuesChanged(Map changes) {
063: Map m = (Map) changes.get(tabbedPanel.getProperties()
064: .getContentPanelProperties().getMap());
065: if (m != null) {
066: if (m
067: .keySet()
068: .contains(
069: TabbedPanelContentPanelProperties.HOVER_LISTENER)) {
070: HoverListener oldHoverListener = shapedPanel
071: .getHoverListener();
072: shapedPanel
073: .setHoverListener((HoverListener) ((ValueChange) m
074: .get(TabbedPanelContentPanelProperties.HOVER_LISTENER))
075: .getNewValue());
076: }
077: }
078:
079: m = (Map) changes.get(tabbedPanel.getProperties()
080: .getContentPanelProperties()
081: .getComponentProperties().getMap());
082: if (m != null)
083: update();
084:
085: m = (Map) changes.get(tabbedPanel.getProperties()
086: .getContentPanelProperties()
087: .getShapedPanelProperties().getMap());
088: if (m != null)
089: update();
090:
091: m = (Map) changes.get(tabbedPanel.getProperties().getMap());
092: if (m != null
093: && m.keySet().contains(
094: TabbedPanelProperties.TAB_AREA_ORIENTATION)) {
095: shapedPanel
096: .setDirection(((Direction) ((ValueChange) m
097: .get(TabbedPanelProperties.TAB_AREA_ORIENTATION))
098: .getNewValue()).getNextCW());
099: }
100: }
101: };
102:
103: /**
104: * Constructs a TabbedPanelContentPanel
105: *
106: * @param tabbedPanel the TabbedPanel that this content panel should be the content
107: * area component for
108: * @param component a component used as container for the tabs' content components
109: */
110: public TabbedPanelContentPanel(final TabbedPanel tabbedPanel,
111: JComponent component) {
112: super (new BorderLayout());
113: this .tabbedPanel = tabbedPanel;
114:
115: shapedPanel = new HoverableShapedPanel(new BorderLayout(),
116: tabbedPanel.getProperties().getContentPanelProperties()
117: .getHoverListener(), tabbedPanel) {
118: public boolean acceptHover(ArrayList enterableHoverables) {
119: return TabbedHoverUtil.acceptTabbedPanelHover(
120: getTabbedPanel().getProperties()
121: .getHoverPolicy(), enterableHoverables,
122: getTabbedPanel(), this );
123: }
124:
125: protected void processMouseEvent(MouseEvent event) {
126: super .processMouseEvent(event);
127: if (getTabbedPanel().hasContentArea())
128: getTabbedPanel().doProcessMouseEvent(event);
129: else
130: doProcessMouseEvent(SwingUtilities
131: .convertMouseEvent(this , event,
132: TabbedPanelContentPanel.this ));
133: }
134:
135: protected void processMouseMotionEvent(MouseEvent event) {
136: super .processMouseMotionEvent(event);
137:
138: if (getTabbedPanel().hasContentArea())
139: getTabbedPanel().doProcessMouseMotionEvent(event);
140: else
141: doProcessMouseMotionEvent(SwingUtilities
142: .convertMouseEvent(this , event,
143: TabbedPanelContentPanel.this ));
144: }
145: };
146:
147: repaintChecker = new ComponentPaintChecker(shapedPanel);
148:
149: shapedPanel.add(component, BorderLayout.CENTER);
150: add(shapedPanel, BorderLayout.CENTER);
151: update();
152:
153: PropertyMapWeakListenerManager.addWeakTreeListener(tabbedPanel
154: .getProperties().getMap(), propertiesListener);
155:
156: tabbedPanel.getDraggableComponentBox().addListener(
157: new DraggableComponentBoxAdapter() {
158: public void changed(DraggableComponentBoxEvent event) {
159: if (event.getDraggableComponent() == null
160: || event.getDraggableComponentEvent()
161: .getType() == DraggableComponentEvent.TYPE_UNDEFINED) {
162: repaintBorder();
163: }
164: }
165: });
166:
167: tabbedPanel.addTabListener(new TabAdapter() {
168: public void tabAdded(TabEvent event) {
169: repaintBorder();
170: }
171:
172: public void tabRemoved(TabRemovedEvent event) {
173: repaintBorder();
174: }
175:
176: public void tabSelected(TabStateChangedEvent event) {
177: repaintBorder();
178: }
179:
180: public void tabDeselected(TabStateChangedEvent event) {
181: repaintBorder();
182: }
183:
184: public void tabDehighlighted(TabStateChangedEvent event) {
185: repaintBorder();
186: }
187:
188: public void tabHighlighted(TabStateChangedEvent event) {
189: repaintBorder();
190: }
191:
192: public void tabMoved(TabEvent event) {
193: repaintBorder();
194: }
195: });
196: }
197:
198: /**
199: * Gets the tabbed panel that this component is the content area component for
200: *
201: * @return the tabbed panel
202: */
203: public TabbedPanel getTabbedPanel() {
204: return tabbedPanel;
205: }
206:
207: /**
208: * Gets the properties for this component
209: *
210: * @return the properties for this TabbedPanelContentPanel
211: */
212: public TabbedPanelContentPanelProperties getProperties() {
213: return tabbedPanel.getProperties().getContentPanelProperties();
214: }
215:
216: private void update() {
217: getProperties().getComponentProperties().applyTo(shapedPanel);
218: InternalPropertiesUtil.applyTo(getProperties()
219: .getShapedPanelProperties(), shapedPanel, tabbedPanel
220: .getProperties().getTabAreaOrientation().getNextCW());
221: BaseContainerUtil.setForcedOpaque(this , getProperties()
222: .getShapedPanelProperties().getOpaque());
223: //setForcedOpaque(getProperties().getShapedPanelProperties().getOpaque());
224: }
225:
226: private void repaintBorder() {
227: if (repaintChecker.isPaintingOk()) {
228: final Rectangle r;
229:
230: Direction d = tabbedPanel.getProperties()
231: .getTabAreaOrientation();
232:
233: if (d == Direction.UP)
234: r = new Rectangle(0, 0, shapedPanel.getWidth(),
235: shapedPanel.getInsets().top);
236: else if (d == Direction.LEFT)
237: r = new Rectangle(0, 0, shapedPanel.getInsets().left,
238: shapedPanel.getHeight());
239: else if (d == Direction.DOWN)
240: r = new Rectangle(0, shapedPanel.getHeight()
241: - shapedPanel.getInsets().bottom - 1,
242: shapedPanel.getWidth(), shapedPanel.getHeight());
243: else
244: r = new Rectangle(shapedPanel.getWidth()
245: - shapedPanel.getInsets().right - 1, 0,
246: shapedPanel.getWidth(), shapedPanel.getHeight());
247:
248: shapedPanel.repaint(r);
249: }
250: }
251:
252: private void doProcessMouseEvent(MouseEvent event) {
253: processMouseEvent(event);
254: }
255:
256: private void doProcessMouseMotionEvent(MouseEvent event) {
257: processMouseMotionEvent(event);
258: }
259: }
|