1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import java.awt.*; 11 12 import javax.swing.plaf.basic.*; 13 import javax.swing.plaf.*; 14 import javax.swing.*; 15 import java.util.Set ; 16 import java.util.TreeSet ; 17 import java.awt.event.*; 18 19 import com.sun.java.swing.plaf.windows.TMSchema.*; 20 import com.sun.java.swing.plaf.windows.XPStyle.Skin; 21 22 23 33 public class WindowsTabbedPaneUI extends BasicTabbedPaneUI { 34 38 private static Set managingFocusForwardTraversalKeys; 39 40 44 private static Set managingFocusBackwardTraversalKeys; 45 46 private boolean contentOpaque = true; 47 48 protected void installDefaults() { 49 super.installDefaults(); 50 contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque"); 51 52 if (managingFocusForwardTraversalKeys==null) { 54 managingFocusForwardTraversalKeys = new TreeSet (); 55 managingFocusForwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); 56 } 57 tabPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, managingFocusForwardTraversalKeys); 58 if (managingFocusBackwardTraversalKeys==null) { 60 managingFocusBackwardTraversalKeys = new TreeSet (); 61 managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); 62 } 63 tabPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, managingFocusBackwardTraversalKeys); 64 } 65 66 protected void uninstallDefaults() { 67 tabPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); 70 tabPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); 71 super.uninstallDefaults(); 72 } 73 74 public static ComponentUI createUI(JComponent c) { 75 return new WindowsTabbedPaneUI(); 76 } 77 78 protected void setRolloverTab(int index) { 79 if (XPStyle.getXP() != null) { 81 int oldRolloverTab = getRolloverTab(); 82 super.setRolloverTab(index); 83 Rectangle r1 = null; 84 Rectangle r2 = null; 85 if ( (oldRolloverTab >= 0) && 86 (oldRolloverTab < tabPane.getTabCount()) ) { 87 r1 = getTabBounds(tabPane, oldRolloverTab); 88 } 89 if (index >= 0) { 90 r2 = getTabBounds(tabPane, index); 91 } 92 if (r1 != null) { 93 if (r2 != null) { 94 tabPane.repaint(r1.union(r2)); 95 } else { 96 tabPane.repaint(r1); 97 } 98 } else if (r2 != null) { 99 tabPane.repaint(r2); 100 } 101 } 102 } 103 104 protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) { 105 XPStyle xp = XPStyle.getXP(); 106 if (xp != null && (contentOpaque || tabPane.isOpaque())) { 107 Skin skin = xp.getSkin(tabPane, Part.TABP_PANE); 108 if (skin != null) { 109 Insets insets = tabPane.getInsets(); 110 Insets tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets"); 113 int x = insets.left; 114 int y = insets.top; 115 int w = tabPane.getWidth() - insets.right - insets.left; 116 int h = tabPane.getHeight() - insets.top - insets.bottom; 117 118 if (tabPlacement == LEFT || tabPlacement == RIGHT) { 120 int tabWidth = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); 121 if (tabPlacement == LEFT) { 122 x += (tabWidth - tabAreaInsets.bottom); 123 } 124 w -= (tabWidth - tabAreaInsets.bottom); 125 } else { 126 int tabHeight = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); 127 if (tabPlacement == TOP) { 128 y += (tabHeight - tabAreaInsets.bottom); 129 } 130 h -= (tabHeight - tabAreaInsets.bottom); 131 } 132 133 paintRotatedSkin(g, skin, tabPlacement, x, y, w, h, null); 134 return; 135 } 136 } 137 super.paintContentBorder(g, tabPlacement, selectedIndex); 138 } 139 140 protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, 141 int x, int y, int w, int h, boolean isSelected ) { 142 if (XPStyle.getXP() == null) { 143 super.paintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); 144 } 145 } 146 147 protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, 148 int x, int y, int w, int h, boolean isSelected ) { 149 XPStyle xp = XPStyle.getXP(); 150 if (xp != null) { 151 Part part; 152 153 int tabCount = tabPane.getTabCount(); 154 int tabRun = getRunForTab(tabCount, tabIndex); 155 if (tabRuns[tabRun] == tabIndex) { 156 part = Part.TABP_TABITEMLEFTEDGE; 157 } else if (tabCount > 1 && lastTabInRun(tabCount, tabRun) == tabIndex) { 158 part = Part.TABP_TABITEMRIGHTEDGE; 159 if (isSelected) { 160 if (tabPlacement == TOP || tabPlacement == BOTTOM) { 162 w++; 163 } else { 164 h++; 165 } 166 } 167 } else { 168 part = Part.TABP_TABITEM; 169 } 170 171 State state = State.NORMAL; 172 if (isSelected) { 173 state = State.SELECTED; 174 } else if (tabIndex == getRolloverTab()) { 175 state = State.HOT; 176 } 177 178 paintRotatedSkin(g, xp.getSkin(tabPane, part), tabPlacement, x, y, w, h, state); 179 } else { 180 super.paintTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); 181 } 182 } 183 184 private void paintRotatedSkin(Graphics g, Skin skin, int tabPlacement, 185 int x, int y, int w, int h, State state) { 186 Graphics2D g2d = (Graphics2D)g.create(); 187 g2d.translate(x, y); 188 switch (tabPlacement) { 189 case RIGHT: g2d.translate(w, 0); 190 g2d.rotate(Math.toRadians(90.0)); 191 skin.paintSkin(g2d, 0, 0, h, w, state); 192 break; 193 194 case LEFT: g2d.scale(-1.0, 1.0); 195 g2d.rotate(Math.toRadians(90.0)); 196 skin.paintSkin(g2d, 0, 0, h, w, state); 197 break; 198 199 case BOTTOM: g2d.translate(0, h); 200 g2d.scale(-1.0, 1.0); 201 g2d.rotate(Math.toRadians(180.0)); 202 skin.paintSkin(g2d, 0, 0, w, h, state); 203 break; 204 205 case TOP: 206 default: skin.paintSkin(g2d, 0, 0, w, h, state); 207 } 208 g2d.dispose(); 209 } 210 } 211 212 | Popular Tags |