001: /*
002: * SimpleCloseTabbedPane.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
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 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, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing;
023:
024: import java.awt.Component;
025: import java.util.ArrayList;
026: import java.util.List;
027: import javax.swing.Icon;
028: import javax.swing.JTabbedPane;
029: import javax.swing.plaf.TabbedPaneUI;
030:
031: import org.underworldlabs.swing.plaf.CloseTabbedPaneUI;
032: import org.underworldlabs.swing.plaf.TabRollOverListener;
033: import org.underworldlabs.swing.plaf.TabRolloverEvent;
034:
035: /* ----------------------------------------------------------
036: * CVS NOTE: Changes to the CVS repository prior to the
037: * release of version 3.0.0beta1 has meant a
038: * resetting of CVS revision numbers.
039: * ----------------------------------------------------------
040: */
041:
042: /**
043: *
044: * @author Takis Diakoumis
045: * @version $Revision: 1.4 $
046: * @date $Date: 2006/05/14 06:56:07 $
047: */
048: public class SimpleCloseTabbedPane extends JTabbedPane {
049:
050: private List<TabRollOverListener> rollListeners;
051:
052: public SimpleCloseTabbedPane() {
053: this (TOP, SCROLL_TAB_LAYOUT);
054: }
055:
056: public SimpleCloseTabbedPane(int tabPlacement) {
057: this (tabPlacement, SCROLL_TAB_LAYOUT);
058: }
059:
060: public SimpleCloseTabbedPane(int tabPlacement, int tabLayoutPolicy) {
061: super (tabPlacement, tabLayoutPolicy);
062: }
063:
064: public void fireTabRollOver(TabRolloverEvent e) {
065: if (rollListeners == null || rollListeners.isEmpty()) {
066: return;
067: }
068:
069: for (int i = 0, k = rollListeners.size(); i < k; i++) {
070: rollListeners.get(i).tabRollOver(e);
071: }
072: }
073:
074: public void fireTabRollOverFinished(TabRolloverEvent e) {
075: if (rollListeners == null || rollListeners.isEmpty()) {
076: return;
077: }
078:
079: for (int i = 0, k = rollListeners.size(); i < k; i++) {
080: rollListeners.get(i).tabRollOverFinished(e);
081: }
082: }
083:
084: public void addTabRollOverListener(TabRollOverListener listener) {
085: if (rollListeners == null) {
086: rollListeners = new ArrayList<TabRollOverListener>();
087: }
088: rollListeners.add(listener);
089:
090: }
091:
092: public void removeTabRollOverListener(TabRollOverListener listener) {
093: if (rollListeners == null) {
094: return;
095: }
096: rollListeners.remove(listener);
097: }
098:
099: public void addTab(String title, Component component) {
100: addTab(title, null, component, null);
101: }
102:
103: public void addTab(String title, Icon icon, Component component) {
104: addTab(title, icon, component, null);
105: }
106:
107: public void addTab(String title, Icon icon, Component component,
108: String tip) {
109: // make sure the pane is visible - may have been empty
110: if (!isVisible()) {
111: setVisible(true);
112: }
113: super .addTab(title, icon, component, tip);
114: }
115:
116: public void insertTab(String title, Icon icon, Component component,
117: String tip, int index) {
118: // make sure the pane is visible - may have been empty
119: if (!isVisible()) {
120: setVisible(true);
121: }
122: super .insertTab(title, icon, component, tip, index);
123: }
124:
125: public void removeAll() {
126: super .removeAll();
127: setVisible(false);
128: }
129:
130: public void remove(int index) {
131: super .remove(index);
132: if (getTabCount() == 0) {
133: setVisible(false);
134: }
135: }
136:
137: public void remove(Component c) {
138: super .remove(c);
139: if (getTabCount() == 0) {
140: setVisible(false);
141: }
142: }
143:
144: protected CloseTabbedPaneUI tabUI;
145:
146: public TabbedPaneUI getUI() {
147: return tabUI;
148: }
149:
150: public void updateUI() {
151: tabUI = new CloseTabbedPaneUI();
152: setUI(tabUI);
153: }
154: /*
155: public void updateUI() {
156: setUI(new CloseTabbedPaneUI());
157: }
158: */
159: }
|