1 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 ; 24 import java.awt.Component ; 25 import java.util.Arrays ; 26 import java.util.Collection ; 27 import javax.swing.JTabbedPane ; 28 29 public class SwingTabbedView extends AbstractCompositeView implements TabsView 30 { 31 JTabbedPane tabbedPane; 32 33 public SwingTabbedView() { 34 setLayout(new BorderLayout ()); 35 tabbedPane = new JTabbedPane (); 36 add(tabbedPane); 37 } 38 39 44 public void addView(View view, Object extraInfos) { 45 addTab(view,(String )extraInfos,null); 46 view.setParentView(this); 47 } 48 49 public View getView(Object id) { 50 if (id instanceof String ) 51 try { 52 return (View)tabbedPane.getComponent(Integer.parseInt((String )id)); 53 } catch (NumberFormatException e) { 54 return (View)tabbedPane.getComponent( 55 tabbedPane.indexOfTab((String )id)); 56 } 57 else if (id instanceof Integer ) 58 return (View)tabbedPane.getComponent(((Integer )id).intValue()); 59 else 60 throw new RuntimeException ("getView(): bad id "+id); 61 } 62 63 public void select(String tab) { 64 tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tab)); 65 } 66 67 public Collection 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 category, String icon) { 78 tabbedPane.addTab(category,ResourceManager.getIcon(icon), 79 (Component )component); 80 validate(); 81 } 82 } 83 | Popular Tags |