001 /* 002 Copyright (C) 2001-2002 Renaud Pawlak, Laurent Martelli 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.gui.swing; 019 020 import org.objectweb.jac.aspects.gui.ResourceManager; 021 import org.objectweb.jac.aspects.gui.TabsView; 022 import org.objectweb.jac.aspects.gui.View; 023 import java.awt.BorderLayout; 024 import java.awt.Component; 025 import java.util.Arrays; 026 import java.util.Collection; 027 import javax.swing.JTabbedPane; 028 029 public class SwingTabbedView extends AbstractCompositeView implements TabsView 030 { 031 JTabbedPane tabbedPane; 032 033 public SwingTabbedView() { 034 setLayout(new BorderLayout()); 035 tabbedPane = new JTabbedPane(); 036 add(tabbedPane); 037 } 038 039 /* 040 * Add a tab 041 * 042 * @param extraInfos a String which is the title of the pane 043 */ 044 public void addView(View view, Object extraInfos) { 045 addTab(view,(String)extraInfos,null); 046 view.setParentView(this); 047 } 048 049 public View getView(Object id) { 050 if (id instanceof String) 051 try { 052 return (View)tabbedPane.getComponent(Integer.parseInt((String)id)); 053 } catch (NumberFormatException e) { 054 return (View)tabbedPane.getComponent( 055 tabbedPane.indexOfTab((String)id)); 056 } 057 else if (id instanceof Integer) 058 return (View)tabbedPane.getComponent(((Integer)id).intValue()); 059 else 060 throw new RuntimeException("getView(): bad id "+id); 061 } 062 063 public void select(String tab) { 064 tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tab)); 065 } 066 067 public Collection getViews() { 068 return Arrays.asList(tabbedPane.getComponents()); 069 } 070 071 public void removeAllViews() { 072 close(true); 073 tabbedPane.removeAll(); 074 validate(); 075 } 076 077 public void addTab(View component, String category, String icon) { 078 tabbedPane.addTab(category,ResourceManager.getIcon(icon), 079 (Component)component); 080 validate(); 081 } 082 }