/* (swing1.1.1beta2) */ package jp.gr.java_conf.tame.swing.panel; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.basic.BasicTabbedPaneUI; import javax.swing.plaf.metal.MetalTabbedPaneUI; /** * @version 1.0 07/09/99 */ public class SingleRowTabbedPaneUI extends MetalTabbedPaneUI { protected ActionListener[] buttonListeners; public void installUI(JComponent c) { this.tabPane = (JTabbedPane)c; c.setLayout(createLayoutManager()); installDefaults(); installComponents(); installListeners(); installKeyboardActions(); runCount = 1; selectedRun = 0; } public void uninstallUI(JComponent c) { uninstallComponents(); super.uninstallUI(c); } protected LayoutManager createLayoutManager() { return new SingleRowTabbedLayout(tabPane); } protected void installComponents() { JButton[] buttons = ((SingleRowTabbedPane)tabPane).getButtons(); for (int i=0;i h) || !((SingleRowTabbedPane)tabPane).isVisibleTab(selectedIndex) ) { g.drawLine(x, y+h-1, x+w-1, y+h-1); } else { Rectangle selRect = rects[selectedIndex]; g.drawLine(x, y+h-1, selRect.x, y+h-1); if (selRect.x + selRect.width < x + w - 2) { g.drawLine(selRect.x + selRect.width, y+h-1, x+w-1, y+h-1); } } } protected Insets getTabAreaInsets(int tabPlacement) { SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane; Dimension d = stabPane.getButtonPreferredSize(); int n = stabPane.getButtonCount(); int buttonPlacement = stabPane.getButtonPlacement(); Insets currentInsets = new Insets(0,0,0,0); if (tabPlacement == TOP) { currentInsets.top = tabAreaInsets.top; currentInsets.bottom = tabAreaInsets.bottom; } else { currentInsets.top = tabAreaInsets.bottom; currentInsets.bottom = tabAreaInsets.top; } if (buttonPlacement == RIGHT) { currentInsets.left = tabAreaInsets.left; currentInsets.right = tabAreaInsets.right + n * d.width; } else { currentInsets.left = tabAreaInsets.left + n * d.width; currentInsets.right = tabAreaInsets.right; } return currentInsets; } protected int lastTabInRun(int tabCount, int run) { SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane; return stabPane.getVisibleStartIndex() + stabPane.getVisibleCount() -1; } protected void ensureCurrentLayout() { SingleRowTabbedLayout layout = (SingleRowTabbedLayout)tabPane.getLayout(); layout.calculateLayoutInfo(); setButtonsEnabled(); } protected void setButtonsEnabled() { SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane; int visibleCount = stabPane.getVisibleCount(); int visibleStartIndex = stabPane.getVisibleStartIndex(); JButton[] buttons = stabPane.getButtons(); boolean lEnable = 0 < visibleStartIndex; boolean rEnable = visibleStartIndex + visibleCount < tabPane.getTabCount(); for (int i=0;i returnAt) { break; } else { visibleCount++; rect.y = y; } } stabPane.setVisibleCount(visibleCount); stabPane.setVisibleStartIndex(visibleStartIndex); } } // // Listener // protected class ShiftTabs implements ActionListener { SingleRowTabbedPane sPane; public void actionPerformed(ActionEvent e) { sPane = getTabbedPane(); int index = getStartIndex(); sPane.setVisibleStartIndex(index); sPane.repaint(); } //public abstract int getStartIndex(); protected int getStartIndex() { return 0; // first tab } protected int getStartIndex(int lastIndex) { Insets insets = sPane.getInsets(); Insets tabAreaInsets = getTabAreaInsets(sPane.getTabPlacement()); int width = sPane.getSize().width - (insets.left + insets.right) - (tabAreaInsets.left + tabAreaInsets.right); int index; Rectangle[] rects = getRects(); for (index=lastIndex;0<=index;index--) { width -= rects[index].width; if (width < 0) { break; } } return ++index; } } }