1 19 20 package org.netbeans.swing.tabcontrol.plaf; 21 22 import java.awt.Dimension ; 23 import java.awt.FontMetrics ; 24 import java.awt.Graphics ; 25 import java.awt.Insets ; 26 import java.awt.Rectangle ; 27 import org.netbeans.swing.tabcontrol.TabDisplayer; 28 29 import javax.swing.plaf.ComponentUI ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 import javax.swing.Icon ; 33 import javax.swing.JComponent ; 34 import javax.swing.UIManager ; 35 36 41 public final class WinXPEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI { 42 43 private static final Rectangle scratch5 = new Rectangle (); 44 private static Map <Integer , String []> buttonIconPaths; 45 46 public WinXPEditorTabDisplayerUI(TabDisplayer displayer) { 47 super (displayer); 48 } 49 50 public static ComponentUI createUI(JComponent c) { 51 return new WinXPEditorTabDisplayerUI ((TabDisplayer) c); 52 } 53 54 public Dimension getPreferredSize(JComponent c) { 55 int prefHeight = 24; 56 Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics(); 57 if (g != null) { 58 FontMetrics fm = g.getFontMetrics(displayer.getFont()); 59 Insets ins = getTabAreaInsets(); 60 prefHeight = fm.getHeight() + ins.top + ins.bottom + 8; 61 } 62 return new Dimension (displayer.getWidth(), prefHeight); 63 } 64 65 public void paintBackground (Graphics g) { 66 g.setColor (displayer.getBackground()); 67 g.fillRect (0, 0, displayer.getWidth(), displayer.getHeight()); 68 } 69 70 protected void paintAfterTabs(Graphics g) { 71 Rectangle r = new Rectangle (); 72 getTabsVisibleArea(r); 73 r.width = displayer.getWidth(); 74 75 Insets ins = getTabAreaInsets(); 76 77 int y = displayer.getHeight() - WinXPEditorTabCellRenderer.BOTTOM_INSET; 78 int selEnd = 0; 81 int i = selectionModel.getSelectedIndex(); 82 g.setColor(WinXPEditorTabCellRenderer.getSelectedTabBottomLineColor()); 83 g.drawLine(0, y + 1, displayer.getWidth(), y + 1); 84 85 87 int tabsWidth = getTabsAreaWidth(); 92 boolean needSplitLine = i != -1 && ((i 93 < scroll().getLastVisibleTab(tabsWidth) || i 94 <= scroll().getLastVisibleTab(tabsWidth) 95 && !scroll().isLastTabClipped()) 96 && i >= scroll().getFirstVisibleTab(tabsWidth)); 97 98 g.setColor(UIManager.getColor("controlLtHighlight")); 99 if (needSplitLine) { 100 getTabRect(i, scratch5); 102 if (scratch5.width != 0) { 104 if (r.x < scratch5.x) { 106 g.drawLine(r.x, y, scratch5.x + 1, y); 107 } 108 if (scratch5.x + scratch5.width < r.x + r.width) { 110 selEnd = scratch5.x + scratch5.width; 112 if (!scroll().isLastTabClipped()) { 116 selEnd--; 117 } 118 g.drawLine(selEnd, y, r.x + r.width, y); 121 } 122 } 123 } else { 124 g.drawLine(r.x, y, r.x + r.width, y); 127 } 128 129 g.setColor(WinXPEditorTabCellRenderer.getBorderColor()); 132 g.drawLine(0, y - 1, 0, displayer.getHeight()); 133 g.drawLine(displayer.getWidth() - 1, y - 1, displayer.getWidth() - 1, 134 displayer.getHeight()); 135 136 139 int last = scroll().getLastVisibleTab(tabsWidth); 141 int l = 0; 142 if (last >= 0) { 143 getTabRect(last, scratch5); 146 last = scratch5.x + scratch5.width; 147 } 148 g.drawLine(last, y - 1, displayer.getWidth(), y - 1); 151 } 152 153 protected TabCellRenderer createDefaultRenderer() { 154 return new WinXPEditorTabCellRenderer(); 155 } 156 157 private static void initIcons() { 158 if( null == buttonIconPaths ) { 159 buttonIconPaths = new HashMap <Integer , String []>(7); 160 161 String [] iconPaths = new String [4]; 163 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths ); 168 169 iconPaths = new String [4]; 171 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths ); 176 177 iconPaths = new String [4]; 179 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_popup_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_popup_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_popup_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_popup_pressed.png"; buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths ); 184 185 iconPaths = new String [4]; 187 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_pressed.png"; buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths ); 192 193 iconPaths = new String [4]; 194 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_restore_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_restore_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_restore_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_restore_pressed.png"; buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths ); 199 } 200 } 201 202 public Icon getButtonIcon(int buttonId, int buttonState) { 203 Icon res = null; 204 initIcons(); 205 String [] paths = buttonIconPaths.get( buttonId ); 206 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 207 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 208 } 209 return res; 210 } 211 } 212 | Popular Tags |