1 19 24 25 package org.netbeans.core.windows.view.ui.tabcontrol; 26 27 import java.util.List ; 28 import java.util.Arrays ; 29 import javax.swing.JComponent ; 30 import javax.swing.event.ChangeListener ; 31 import org.netbeans.swing.tabcontrol.ComponentConverter; 32 import org.netbeans.swing.tabcontrol.TabData; 33 import org.netbeans.swing.tabcontrol.TabbedContainer; 34 import org.netbeans.swing.tabcontrol.TabDataModel; 35 import org.netbeans.modules.openide.explorer.TabbedContainerBridge; 36 37 45 public class TabbedContainerBridgeImpl extends TabbedContainerBridge { 46 47 48 public TabbedContainerBridgeImpl() { 49 } 50 51 public void attachSelectionListener(JComponent jc, ChangeListener listener) { 52 TabbedContainer cont = (TabbedContainer) jc; 53 cont.getSelectionModel().addChangeListener(listener); 54 } 55 56 public JComponent createTabbedContainer() { 57 return new TabbedContainer(TabbedContainer.TYPE_TOOLBAR); 58 } 59 60 public void detachSelectionListener(JComponent jc, ChangeListener listener) { 61 TabbedContainer cont = (TabbedContainer) jc; 62 cont.getSelectionModel().removeChangeListener(listener); 63 } 64 65 public Object [] getItems(JComponent jc) { 66 TabbedContainer cont = (TabbedContainer) jc; 67 List l = cont.getModel().getTabs(); 68 Object [] items = new Object [l.size()]; 69 for (int i=0; i < items.length; i++) { 70 items[i] = ((TabData) l.get(i)).getUserObject(); 71 } 72 return items; 73 } 74 75 public Object getSelectedItem(JComponent jc) { 76 Object result = null; 77 TabbedContainer cont = (TabbedContainer) jc; 78 int i = cont.getSelectionModel().getSelectedIndex(); 79 if (i != -1) { 80 result = cont.getModel().getTab(i).getUserObject(); 81 } 82 return result; 83 } 84 85 public void setSelectedItem(JComponent jc, Object selection) { 86 TabbedContainer cont = (TabbedContainer) jc; 87 TabDataModel mdl = cont.getModel(); 88 int max = mdl.size(); 89 for (int i=0; i < max; i++) { 90 TabData td = mdl.getTab(i); 91 if (td.getUserObject() == selection) { 92 cont.getSelectionModel().setSelectedIndex(i); 93 break; 94 } 95 } 96 } 97 98 public boolean setSelectionByName(JComponent jc, String tabname) { 99 TabbedContainer cont = (TabbedContainer) jc; 100 TabDataModel mdl = cont.getModel(); 101 int max = mdl.size(); 102 for (int i=0; i < max; i++) { 103 TabData td = mdl.getTab(i); 104 if (tabname.equals(td.getText())) { 105 cont.getSelectionModel().setSelectedIndex(i); 106 return true; 107 } 108 } 109 return false; 110 } 111 112 public String getCurrentSelectedTabName(JComponent jc) { 113 TabbedContainer cont = (TabbedContainer) jc; 114 int sel = cont.getSelectionModel().getSelectedIndex(); 115 if (sel != -1) { 116 TabData td = cont.getModel().getTab(sel); 117 return td.getText(); 118 } 119 return null; 120 } 121 122 public void setInnerComponent(JComponent jc, JComponent inner) { 123 TabbedContainer cont = (TabbedContainer) jc; 124 ComponentConverter cc = new ComponentConverter.Fixed (inner); 125 cont.setComponentConverter(cc); 126 } 127 128 public JComponent getInnerComponent(JComponent jc) { 129 TabbedContainer cont = (TabbedContainer) jc; 130 return (JComponent ) cont.getComponentConverter().getComponent(null); 131 } 132 133 public void setItems(JComponent jc, Object [] objects, String [] titles) { 134 TabbedContainer cont = (TabbedContainer) jc; 135 assert objects.length == titles.length; 136 TabData[] td = new TabData [objects.length]; 137 for (int i=0; i < objects.length; i++) { 138 td[i] = new TabData (objects[i], null, titles[i], null); 139 } 140 cont.getModel().setTabs(td); 141 } 142 143 } 144 | Popular Tags |