📄 dockedtabcontainer.java
字号:
if (components != null) { title = title.toUpperCase(); int tabCount = components.size(); for (int i = 0; i < tabCount; i++) { TabComponent tabComponent = components.get(i); String _title = tabComponent.getTitle(); if (_title != null && _title.toUpperCase().startsWith(title)) { return tabComponent; } } } return null; } /** * Minimises the tab from the panel at the specified index. * * @param the index to be removed */ protected void minimiseComponent(int position, int index) { TabPane tabPane = getTabPaneForPosition(position); if (tabPane != null && tabPane instanceof DockedTabPane) { ((DockedTabPane)tabPane).minimiseIndex(index); } } /** * Minimises the tab from the panel at the specified index. * * @param the index to be removed */ protected void minimiseComponent(TabComponent tabComponent) { if (minimisedComponents == null) { minimisedComponents = new ArrayList<TabComponent>(); } // add the component to the minimised cache minimisedComponents.add(tabComponent); if (buttonPanel == null) { buttonPanel = new ButtonPanel(); // add the button panel in the required position switch (orientation) { case WEST: add(buttonPanel, BorderLayout.WEST); break; case CENTER: add(buttonPanel, BorderLayout.SOUTH); break; case EAST: add(buttonPanel, BorderLayout.EAST); break; } } buttonPanel.addButton(tabComponent); validate(); repaint(); } /** * Removes the south tab pane component and * changes the state of the split pane. */ private void southPaneRemoved() { // store the current div location splitPane.storeDividerLocation(); // remove the south pane splitPane.setRightComponent(null); // set divider to 0 so it doesn't 'look' like a split pane splitPane.setDividerSize(0); southTabPane = null; } /** * Adds the south tab pane component and * changes the state of the split pane. */ private void southPaneCreated() { splitPane.setRightComponent(southTabPane); splitPane.restoreDividerLocation(); //splitPane.setDividerLocation(defaultDividerLocation);// if (orientation == SwingConstants.CENTER && scrollingTabPane != null) { splitPane.setDividerSize(ApplicationConstants.SPLIT_PANE_DIVIDER_SIZE);// } } /** * Removes the specified tab pane from this component. * * @param the tab pane to be removed */ protected void removeTabPane(DockedTabPane tabPane) { if (tabPane == northTabPane && orientation != SwingConstants.CENTER) { splitPane.setLeftComponent(null); northTabPane = null; // if we have a south pane, switch it if (southTabPane != null) { northTabPane = southTabPane; southPaneRemoved(); splitPane.setLeftComponent(northTabPane); } } else if (tabPane == southTabPane) { southPaneRemoved(); } // if they're both null and this is not the // center component - hide the split pane if (orientation != SwingConstants.CENTER && northTabPane == null && southTabPane == null) { splitPane.setVisible(false); // if the button panel is null also, remove this panel if (buttonPanel == null) { if (minimisedComponents != null) { minimisedComponents.clear(); minimisedComponents = null; } desktopMediator.removeDockedContainer(this); return; } } if (splitPane.isVisible()) { splitPane.validate(); } else { desktopMediator.resetPaneToPreferredSizes(orientation, false); } validate(); repaint(); } /** * Restores the specified tab component from a minimised state. * * @param the tab component to restore */ protected void restoreTabComponent(TabComponent tabComponent) { //boolean restore = false; minimisedComponents.remove(tabComponent); if (minimisedComponents.size() == 0) { remove(buttonPanel); buttonPanel = null; } if (orientation != SwingConstants.CENTER) { // a restored tab is always added to the north pane if (northTabPane == null) { northTabPane = new DockedTabPane(this); // check the split pane if (splitPane == null) { initSplitPane(); } else if (!splitPane.isVisible()) { splitPane.setVisible(true); } splitPane.setLeftComponent(northTabPane); desktopMediator.resetPaneToPreferredSizes(orientation, true); } northTabPane.addTab(tabComponent); northTabPane.setSelectedTab(tabComponent); } else { // for center only if (southTabPane == null) { southTabPane = new DockedTabPane(this); southPaneCreated(); } southTabPane.addTab(tabComponent); southTabPane.setSelectedTab(tabComponent); } validate(); repaint(); // fire the event fireTabRestored(new DockedTabEvent(tabComponent)); } /** * Initialises the state of the split pane component. */ private void initSplitPane() { splitPane = new TabContainerSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerSize(0); } /** * Indicates whether the tab pane in the specified * position is visible. * * @return <code>true | false</code> */ public boolean isTabPaneVisible(int position) { switch (position) { case SwingConstants.NORTH: case SwingConstants.NORTH_WEST: case SwingConstants.NORTH_EAST: return (northTabPane != null); case SwingConstants.SOUTH: case SwingConstants.SOUTH_WEST: case SwingConstants.SOUTH_EAST: return (southTabPane != null); } return (northTabPane != null || southTabPane != null); } /** * Returns if the tab with the specfied name is currently minimised. * * @param name - the component's name (tab title) */ public boolean isMinimised(String name) { if (minimisedComponents == null || minimisedComponents.isEmpty()) { return false; } for (int i = 0, k = minimisedComponents.size(); i < k; i++) { TabComponent tab = minimisedComponents.get(i); if (tab.getTitle().equals(name)) { return true; } } return false; } /** * Restores the tab component with the specified name. * * @param name - the component's name (tab title) */ public void restore(String name) { if (minimisedComponents == null || minimisedComponents.isEmpty()) { return; } for (int i = 0, k = minimisedComponents.size(); i < k; i++) { TabComponent tab = minimisedComponents.get(i); if (tab.getTitle().equals(name)) { restoreTabComponent(tab); return; } } } /** * Indicates whether the minimised tab button * panel is visible. * * @return <code>true | false</code> */ public boolean isButtonPanelVisible() { return buttonPanel != null; } /** * The button panel to containing the minimised tab buttons. */ private class ButtonPanel extends JPanel implements ActionListener { private int width; private int height; protected ButtonPanel() { super(new FlowLayout(FlowLayout.LEADING, 0, 2)); Font font = UIManager.getFont("Label.font"); FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(font); height = fm.getHeight() + 10; } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { return new Dimension(getWidth(), getHeight()); } public int getHeight() { if (orientation == CENTER) { return height; } else { return super.getHeight(); } } public int getWidth() { if (orientation == CENTER) { return super.getWidth(); } else { return height; } } protected void addButton(TabComponent tabComponent) { MinimiseTabButton button = new MinimiseTabButton(tabComponent); button.addActionListener(this); add(button); } public void actionPerformed(ActionEvent e) { MinimiseTabButton button = (MinimiseTabButton)e.getSource(); remove(button); restoreTabComponent(button.getTabComponent()); } } /** * Defines a minimised tab button. */ private class MinimiseTabButton extends JButton { private TabComponent tabComponent; protected MinimiseTabButton(TabComponent tabComponent) { this.setMargin(ApplicationConstants.EMPTY_INSETS); this.tabComponent = tabComponent; setToolTipText(tabComponent.getToolTip()); String titleText = tabComponent.getDisplayName(); // set the icon/text for this button switch (orientation) { case WEST: setIcon(new VerticalTextIcon(titleText, false)); break; case CENTER: setText(titleText); break; case EAST: setIcon(new VerticalTextIcon(titleText, true)); break; } } public int getHeight() { switch (orientation) { case WEST: return getIcon().getIconHeight() + 8; case EAST: return getIcon().getIconHeight() + 8; } return super.getHeight(); } public int getWidth() { switch (orientation) { case WEST: return getIcon().getIconWidth() + 8; case EAST: return getIcon().getIconWidth() + 8; } return super.getWidth(); } protected TabComponent getTabComponent() { return tabComponent; } } public DockedTabPane getNorthTabPane() { return northTabPane; } public DockedTabPane getSouthTabPane() { return southTabPane; } public ScrollingTabPane getScrollingTabPane() { return scrollingTabPane; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -