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 java.util.HashMap ; 28 import java.util.Map ; 29 import javax.swing.Icon ; 30 import javax.swing.JComponent ; 31 import org.netbeans.swing.tabcontrol.TabDisplayer; 32 33 import javax.swing.plaf.ComponentUI ; 34 35 40 public final class WinVistaEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI { 41 42 private static final Rectangle scratch5 = new Rectangle (); 43 private static Map <Integer , String []> buttonIconPaths; 44 45 public WinVistaEditorTabDisplayerUI(TabDisplayer displayer) { 46 super (displayer); 47 } 48 49 public static ComponentUI createUI(JComponent c) { 50 return new WinVistaEditorTabDisplayerUI ((TabDisplayer) c); 51 } 52 53 public Dimension getPreferredSize(JComponent c) { 54 int prefHeight = 22; 55 Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics(); 56 if (g != null) { 57 FontMetrics fm = g.getFontMetrics(displayer.getFont()); 58 Insets ins = getTabAreaInsets(); 59 prefHeight = fm.getHeight() + ins.top + ins.bottom + 6; 60 } 61 return new Dimension (displayer.getWidth(), prefHeight); 62 } 63 64 public void paintBackground (Graphics g) { 65 g.setColor (displayer.getBackground()); 66 g.fillRect (0, 0, displayer.getWidth(), displayer.getHeight()); 67 } 68 69 protected void paintAfterTabs(Graphics g) { 70 Rectangle r = new Rectangle (); 71 getTabsVisibleArea(r); 72 r.width = displayer.getWidth(); 73 74 Insets ins = getTabAreaInsets(); 75 76 int y = displayer.getHeight() - WinVistaEditorTabCellRenderer.BOTTOM_INSET; 77 int tabsWidth = getTabsAreaWidth(); 78 79 g.setColor(WinVistaEditorTabCellRenderer.getBorderColor()); 80 81 84 int last = scroll().getLastVisibleTab(tabsWidth); 86 int l = 0; 87 if (last >= 0) { 88 getTabRect(last, scratch5); 91 last = scratch5.x + scratch5.width; 92 } 93 g.drawLine(last, y - 1, displayer.getWidth(), y - 1); 96 } 97 98 protected TabCellRenderer createDefaultRenderer() { 99 return new WinVistaEditorTabCellRenderer(); 100 } 101 102 protected Rectangle getTabRectForRepaint( int tab, Rectangle rect ) { 103 Rectangle res = super.getTabRectForRepaint( tab, rect ); 104 res.x--; 107 res.width += 2; 108 return res; 109 } 110 111 private static void initIcons() { 112 if( null == buttonIconPaths ) { 113 buttonIconPaths = new HashMap <Integer , String []>(7); 114 115 String [] iconPaths = new String [4]; 117 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths ); 122 123 iconPaths = new String [4]; 125 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths ); 130 131 iconPaths = new String [4]; 133 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_popup_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 135 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_popup_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_popup_pressed.png"; buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths ); 138 139 iconPaths = new String [4]; 141 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 143 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_pressed.png"; buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths ); 146 147 iconPaths = new String [4]; 148 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_restore_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 150 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_restore_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_restore_pressed.png"; buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths ); 153 } 154 } 155 156 public Icon getButtonIcon(int buttonId, int buttonState) { 157 Icon res = null; 158 initIcons(); 159 String [] paths = buttonIconPaths.get( buttonId ); 160 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 161 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 162 } 163 return res; 164 } 165 } 166 | Popular Tags |