KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > swing > SwingTabbedView


1 /*
2   Copyright (C) 2001-2002 Renaud Pawlak, Laurent Martelli
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui.swing;
19
20 import org.objectweb.jac.aspects.gui.ResourceManager;
21 import org.objectweb.jac.aspects.gui.TabsView;
22 import org.objectweb.jac.aspects.gui.View;
23 import java.awt.BorderLayout JavaDoc;
24 import java.awt.Component JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.Collection JavaDoc;
27 import javax.swing.JTabbedPane JavaDoc;
28
29 public class SwingTabbedView extends AbstractCompositeView implements TabsView
30 {
31     JTabbedPane JavaDoc tabbedPane;
32
33     public SwingTabbedView() {
34         setLayout(new BorderLayout JavaDoc());
35         tabbedPane = new JTabbedPane JavaDoc();
36         add(tabbedPane);
37     }
38
39     /*
40      * Add a tab
41      *
42      * @param extraInfos a String which is the title of the pane
43      */

44     public void addView(View view, Object JavaDoc extraInfos) {
45         addTab(view,(String JavaDoc)extraInfos,null);
46         view.setParentView(this);
47     }
48
49     public View getView(Object JavaDoc id) {
50         if (id instanceof String JavaDoc)
51             try {
52                 return (View)tabbedPane.getComponent(Integer.parseInt((String JavaDoc)id));
53             } catch (NumberFormatException JavaDoc e) {
54                 return (View)tabbedPane.getComponent(
55                     tabbedPane.indexOfTab((String JavaDoc)id));
56             }
57         else if (id instanceof Integer JavaDoc)
58             return (View)tabbedPane.getComponent(((Integer JavaDoc)id).intValue());
59         else
60             throw new RuntimeException JavaDoc("getView(): bad id "+id);
61     }
62
63     public void select(String JavaDoc tab) {
64         tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tab));
65     }
66
67     public Collection JavaDoc getViews() {
68         return Arrays.asList(tabbedPane.getComponents());
69     }
70
71     public void removeAllViews() {
72         close(true);
73         tabbedPane.removeAll();
74         validate();
75     }
76
77     public void addTab(View component, String JavaDoc category, String JavaDoc icon) {
78         tabbedPane.addTab(category,ResourceManager.getIcon(icon),
79                           (Component JavaDoc)component);
80         validate();
81     }
82 }
83
Popular Tags