diff options
Diffstat (limited to 'libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java')
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java | 144 |
1 files changed, 93 insertions, 51 deletions
diff --git a/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java index 44e302b0188..7073086aae5 100644 --- a/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -28,7 +28,7 @@ permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of7 the license of that +independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not @@ -132,11 +132,17 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { if (++currentScrollLocation >= tabCount) currentScrollLocation = tabCount - 1; - if (currentScrollLocation == tabCount - 1) - incrButton.setEnabled(false); + + int width = 0; + for (int i = currentScrollLocation - 1; i < tabCount; i++) + width += rects[i].width; + if (width < viewport.getWidth()) + // FIXME: Still getting mouse events after the button is disabled. + // incrButton.setEnabled(false); + currentScrollLocation--; else if (! decrButton.isEnabled()) decrButton.setEnabled(true); - tabPane.layout(); + tabPane.revalidate(); tabPane.repaint(); return; } @@ -148,7 +154,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants decrButton.setEnabled(false); else if (! incrButton.isEnabled()) incrButton.setEnabled(true); - tabPane.layout(); + tabPane.revalidate(); tabPane.repaint(); return; } @@ -160,7 +166,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants // e.g. in the inset area. if (index != -1 && tabPane.isEnabledAt(index)) tabPane.setSelectedIndex(index); - tabPane.layout(); + tabPane.revalidate(); tabPane.repaint(); } } @@ -168,7 +174,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants /** * This class handles PropertyChangeEvents fired from the JTabbedPane. */ - protected class PropertyChangeHandler implements PropertyChangeListener + public class PropertyChangeHandler implements PropertyChangeListener { /** * This method is called whenever one of the properties of the JTabbedPane @@ -269,18 +275,16 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - width = calculateMaxTabWidth(tabPlacement) * tabPane.getTabCount(); - calcRect = tabPane.getParent().getBounds(); - width = Math.max(width, componentWidth); + int min = calculateMaxTabWidth(tabPlacement); + width = Math.max(min, componentWidth); int tabAreaHeight = preferredTabAreaHeight(tabPlacement, width); height = tabAreaHeight + componentHeight; } else { - height = calculateMaxTabHeight(tabPlacement) * tabPane.getTabCount(); - calcRect = tabPane.getParent().getBounds(); - height = Math.max(height, componentHeight); + int min = calculateMaxTabHeight(tabPlacement); + height = Math.max(min, componentHeight); int tabAreaWidth = preferredTabAreaWidth(tabPlacement, height); width = tabAreaWidth + componentWidth; @@ -454,7 +458,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { for (int j = first; j <= last; j++) rects[j].y += (runCount - i) * maxTabHeight - + (runCount - i) * tabRunOverlay; + - (runCount - i) * tabRunOverlay; } if (tabPlacement == SwingConstants.BOTTOM) @@ -810,7 +814,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants */ protected void rotateTabRuns(int tabPlacement, int selectedRun) { - if (selectedRun == 1 || selectedRun == -1) + if (runCount == 1 || selectedRun == 1 || selectedRun == -1) return; int[] newTabRuns = new int[tabRuns.length]; int currentRun = selectedRun; @@ -1025,6 +1029,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { super.layoutContainer(pane); int tabCount = tabPane.getTabCount(); + Point p = null; if (tabCount == 0) return; int tabPlacement = tabPane.getTabPlacement(); @@ -1083,20 +1088,21 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width); int h = Math.max(rects[tabC].height, tabAreaRect.height); - Point p = findPointForIndex(currentScrollLocation); + p = findPointForIndex(currentScrollLocation); // we want to cover that entire space so that borders that run under // the tab area don't show up when we move the viewport around. panel.setSize(w + p.x, h + p.y); } - viewport.setViewPosition(findPointForIndex(currentScrollLocation)); + viewport.setViewPosition(p); + viewport.repaint(); } } /** * This class handles ChangeEvents from the JTabbedPane. */ - protected class TabSelectionHandler implements ChangeListener + public class TabSelectionHandler implements ChangeListener { /** * This method is called whenever a ChangeEvent is fired from the @@ -1257,16 +1263,32 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants /** This array keeps track of which tabs are in which run. See above. */ protected int[] tabRuns; - /** Deprecated. This is the keystroke for moving down. */ + /** + * This is the keystroke for moving down. + * + * @deprecated 1.3 + */ protected KeyStroke downKey; - /** Deprecated. This is the keystroke for moving left. */ + /** + * This is the keystroke for moving left. + * + * @deprecated 1.3 + */ protected KeyStroke leftKey; - /** Deprecated. This is the keystroke for moving right. */ + /** + * This is the keystroke for moving right. + * + * @deprecated 1.3 + */ protected KeyStroke rightKey; - /** Deprecated. This is the keystroke for moving up. */ + /** + * This is the keystroke for moving up. + * + * @deprecated 1.3 + */ protected KeyStroke upKey; /** The listener that listens for focus events. */ @@ -1446,6 +1468,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants incrButton = createIncreaseButton(); decrButton = createDecreaseButton(); viewport = new ScrollingViewport(); + viewport.setLayout(null); panel = new ScrollingPanel(); viewport.setView(panel); tabPane.add(incrButton); @@ -1690,6 +1713,8 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants Rectangle ir = new Rectangle(); Rectangle tr = new Rectangle(); + boolean isScroll = tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT; + // Please note: the ordering of the painting is important. // we WANT to paint the outermost run first and then work our way in. int tabCount = tabPane.getTabCount(); @@ -1702,17 +1727,33 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants for (int i = 0; i < runCount; i++) { int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1; - if (first == tabCount) + if (isScroll) + first = currentScrollLocation; + else if (first == tabCount) first = 0; int last = lastTabInRun(tabCount, currRun); + if (isScroll) + { + for (int k = first; k < tabCount; k++) + { + if (rects[k].x + rects[k].width - rects[first].x > viewport + .getWidth()) + { + last = k; + break; + } + } + } + for (int j = first; j <= last; j++) { - if (j != selectedIndex) + if (j != selectedIndex || isScroll) paintTab(g, tabPlacement, rects, j, ir, tr); } - currRun = getNextTabRun(currRun); + currRun = getPreviousTabRun(currRun); } - paintTab(g, tabPlacement, rects, selectedIndex, ir, tr); + if (! isScroll) + paintTab(g, tabPlacement, rects, selectedIndex, ir, tr); } /** @@ -1975,7 +2016,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int x, int y, int w, int h, boolean isSelected) { Color saved = g.getColor(); - + if (! isSelected || tabPlacement != SwingConstants.TOP) { g.setColor(shadow); @@ -2030,7 +2071,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { Color bg = tabPane.getBackgroundAt(tabIndex); if (bg == null) - bg = tabPane.getBackground(); + bg = Color.GRAY; g.setColor(bg); } @@ -2083,14 +2124,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int diff = 0; - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.x; - } - if (tabPlacement == SwingConstants.TOP) { + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.x; + } + g.drawLine(x, y, startgap - diff, y); g.drawLine(endgap - diff, y, x + w, y); } @@ -2123,14 +2164,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int diff = 0; - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.y; - } - if (tabPlacement == SwingConstants.LEFT) { + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.y; + } + g.drawLine(x, y, x, startgap - diff); g.drawLine(x, endgap - diff, x, y + h); } @@ -2162,14 +2203,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int diff = 0; - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.x; - } - if (tabPlacement == SwingConstants.BOTTOM) { + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.x; + } + g.setColor(shadow); g.drawLine(x + 1, y + h - 1, startgap - diff, y + h - 1); g.drawLine(endgap - diff, y + h - 1, x + w - 1, y + h - 1); @@ -2209,14 +2250,15 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int endgap = rects[selectedIndex].y + rects[selectedIndex].height; int diff = 0; - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.y; - } if (tabPlacement == SwingConstants.RIGHT) { + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.y; + } + g.setColor(shadow); g.drawLine(x + w - 1, y + 1, x + w - 1, startgap - diff); g.drawLine(x + w - 1, endgap - diff, x + w - 1, y + h - 1); |