📄 abstracttabpane.java
字号:
int sameTitleIndex = _tabComponent.getSameTitleIndex(); if (sameTitleIndex > 0) { counterIndex = Math.max(counterIndex, sameTitleIndex); } else { counterIndex = 1; } } } } if (counterIndex > 0) { counterIndex++; tabComponent.setSameTitleIndex(counterIndex); return " [" + counterIndex + "]"; } } return null; } /** * Sets the tool tip at index to toolTipText which can be null. * An internal exception is raised if there is no tab at that index. * * @param the tab index where the tool tip should be set * @param the tool tip text to be displayed in the tab */ public void setToolTipTextAt(int index, String toolTipText) { if (components == null || components.isEmpty()) { throw new IndexOutOfBoundsException("Tab pane is empty."); } TabComponent tabComponent = components.get(index); tabComponent.setToolTip(toolTipText); //TODO: implement property change event stuff } /** * Sets the tool tip for the specified component to toolTipText * which can be null. An internal exception is raised if there * is no tab for the specified component. * * @param the component where the tool tip should be set * @param the tool tip text to be displayed in the tab */ public void setToolTipTextForComponent(Component component, String toolTipText) { int index = indexOfComponent(component); if (index == -1) { throw new IndexOutOfBoundsException("Tab pane component not found."); } setToolTipTextAt(index, toolTipText); } /** * Returns the index of the tab for the specified component. * * @param the component * @return of the index of component or -1 if not found */ public int indexOfComponent(Component component) { if (components == null || components.isEmpty()) { return -1; } for (int i = 0, k = components.size(); i < k; i++) { TabComponent tabComponent = components.get(i); if (tabComponent.getComponent() == component) { return i; } } return -1; } /** * Removes the tab with the specified name from the pane. * * @param the name */ public void closeTabComponent(String name) { int index = indexOfTab(name); if (index != -1) { removeIndex(index); } } /** * Returns the index of the tab for the specified title. * * @param the title * @return of the index of component or -1 if not found */ public int indexOfTab(String title) { if (components == null || components.isEmpty()) { return -1; } for (int i = 0, k = components.size(); i < k; i++) { TabComponent tabComponent = components.get(i); if (tabComponent.getTitle().equals(title)) { return i; } } return -1; } /** * Sets the specified panel as the actual tab display. * * @param the panel displaying the actual tabs */ protected void setTabPanel(JPanel panel) { add(panel, BorderLayout.NORTH); } public void addTab(String title, Component component) { addTab(-1, title, null, component, null); } public void addTab(String title, Icon icon, Component component) { addTab(-1, title, icon, component, null); } public void addTab(int position, String title, Icon icon, Component component, String tip) { addTab(new TabComponent(position, component, title, icon, tip)); } /** * Adds the specified tab component to the pane. * * @param the component to be added */ public abstract void addTab(TabComponent tabComponent); /** * Returns the tab component at the specified index. * * @param the index of the component * @return the component at the specified index */ protected TabComponent getTabComponentAt(int index) { if (index < 0) { return null; } return components.get(index); } /** * Returns the tab count for this component. * * @return the tab count */ public int getTabCount() { if (components != null) { return components.size(); } return 0; } /** * Notifies all registered listeners of a tab minimised event. * * @param the event */ protected void fireTabMinimised(DockedTabEvent e) { parent.fireTabMinimised(e); } /** * Notifies all registered listeners of a tab restored event. * * @param the event */ protected void fireTabRestored(DockedTabEvent e) { parent.fireTabRestored(e); } /** * Notifies all registered listeners of a tab selected event. * * @param the event */ protected void fireTabSelected(DockedTabEvent e) { TabComponent tabComponent = (TabComponent)e.getSource(); if (tabComponent.getComponent() instanceof TabView) { ((TabView)tabComponent.getComponent()).tabViewSelected(); } parent.fireTabSelected(e); } /** * Notifies all registered listeners of a tab deselected event. * * @param the event */ protected void fireTabDeselected(DockedTabEvent e) { parent.fireTabDeselected(e); } /** * Notifies all registered listeners of a tab closed event. * * @param the event */ protected void fireTabClosed(DockedTabEvent e) { /* TabComponent tabComponent = (TabComponent)e.getSource(); if (tabComponent.getComponent() instanceof DockedTabView) { ((DockedTabView)tabComponent.getComponent()).tabViewClosing(); } */ parent.fireTabClosed(e); } /** * Sets the selected tab component as that specified. * * @param the tab component to set selected */ public void setSelectedTab(TabComponent tabComponent) { setSelectedIndex(components.indexOf(tabComponent)); focusGained(); } /** * Sets the selected index to that specified. * * @param the index to set selected */ public void setSelectedIndex(int index) { if (index == -1) { return; } if (selectedIndex != -1) { // fire the deselected event TabComponent tabComponent = components.get(selectedIndex); if (tabComponent.getComponent() instanceof TabView) { TabView dockedView = (TabView)tabComponent.getComponent(); if (dockedView.tabViewDeselected()) { fireTabDeselected(new DockedTabEvent(tabComponent)); } else { return; } } } selectedIndex = index; TabComponent tabComponent = components.get(index); cardLayout.show(componentPanel, tabComponent.getLayoutName()); } /** * Removes the tab from the panel at the specified index. * * @param the index to be removed */ protected abstract void removeIndex(int index); /** * Checks whether a close of the panel will not be * vetoed by the panel itself. * * @param the tab component to be closed * @return true if ok to close, false otherwise */ protected boolean okToClose(TabComponent tabComponent) { if (tabComponent.getComponent() instanceof TabView) { TabView dockedView = (TabView)tabComponent.getComponent(); return dockedView.tabViewClosing(); } return true; } /** * Returns the tab components within list. * * @return the tab components */ public List<TabComponent> getTabComponents() { return components; } /** * Returns the currently selected index or -1 if nothing is selected. * * @return the currently selected index */ public int getSelectedIndex() { return selectedIndex; } /** * Returns the currently selected tab component * or null if nothing is selected. * * @return the currently selected tab component */ public TabComponent getSelectedComponent() { if (selectedIndex == -1) { return null; } else { return components.get(selectedIndex); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -