01: /*
02: * SwingML
03: * Copyright (C) 2002 Robert J. Morris.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the
17: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18: * Boston, MA 02111-1307, USA.
19: *
20: * Authors:
21: * Robert J. Morris <robertj@morris.net>
22: *
23: * Oct 8, 2002 10:09:40 PM
24: */
25: package org.swingml.component;
26:
27: import java.awt.Component;
28:
29: import javax.swing.JTabbedPane;
30: import javax.swing.event.ChangeEvent;
31: import javax.swing.event.ChangeListener;
32:
33: import org.swingml.Constants;
34: import org.swingml.XMLTranslatable;
35: import org.swingml.event.EventHandler;
36: import org.swingml.model.JTabbedPaneModel;
37:
38: /**
39: *
40: * <p>Supports the XMLTranslatable interface to provide feedback during a POST
41: * operation.</p>
42: */
43: public class JTabbedPaneComponent extends JTabbedPane implements
44: XMLTranslatable, ChangeListener {
45:
46: private EventHandler eventHandler = EventHandler.getInstance();
47: private JTabbedPaneModel m_model = null;
48: private int m_current = 0;
49:
50: /**
51: * Creates an instance of the JTabbedPaneComponent class.
52: *
53: * @param model A valid instance of a JTabbedPaneModel class.
54: * provides the necessary information to intialize
55: * new instance of the JTabbedPaneComponent class.
56: */
57: public JTabbedPaneComponent(JTabbedPaneModel aModel) {
58: super ();
59: this .m_model = aModel;
60: this .m_current = this .m_model.getCurrent();
61: super .setName(this .m_model.getName());
62: super .setToolTipText(this .m_model.getTooltip());
63: super .addChangeListener(this );
64: }
65:
66: /**
67: * Adds a new tab to the component. Makes sure that the
68: * current tab specified by the JTabbedPaneModel object used
69: * to create this instance is used to set the current
70: * tab index when it is available.
71: *
72: * @param tabName The name of the tab to add.
73: * @param component The component to add to the tabbed pane.
74: */
75: public Component add(String aTabName, Component aComponent) {
76: Component theRetComp = super .add(aTabName, aComponent);
77: if (super .getComponentCount() >= (this .m_current + 1)) {
78: super .setSelectedIndex(this .m_current);
79: }
80: return theRetComp;
81: }
82:
83: /**
84: * @see org.swingml.XMLTranslatable#getXMLValue()
85: */
86: public String getXMLValue() {
87: return Integer.toString(super .getSelectedIndex());
88: }
89:
90: // ChangeListener Realization
91: public void stateChanged(ChangeEvent aEvt) {
92: this.eventHandler.handleEvent(this.m_model,
93: Constants.TAB_STATE_CHANGED, this);
94: }
95: }
|