1 19 24 25 package org.netbeans.swing.tabcontrol.plaf; 26 27 import java.awt.Color ; 28 import java.awt.Container ; 29 import java.awt.Dimension ; 30 import java.awt.Font ; 31 import java.awt.FontMetrics ; 32 import java.awt.Graphics ; 33 import java.awt.Insets ; 34 import java.awt.Rectangle ; 35 import org.netbeans.swing.tabcontrol.TabDisplayer; 36 import javax.swing.plaf.ComponentUI ; 37 import java.util.HashMap ; 38 import java.util.Map ; 39 import javax.swing.Icon ; 40 import javax.swing.JComponent ; 41 import javax.swing.UIManager ; 42 43 49 public class AquaEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI { 50 51 52 private Color lineMiddleColor = null; 53 54 private Color lineHlColor = null; 55 56 private static Map <Integer , String []> buttonIconPaths; 57 58 public AquaEditorTabDisplayerUI (TabDisplayer displayer) { 59 super (displayer); 60 } 61 62 public void install() { 63 super.install(); 64 scroll().setMinimumXposition(9); 65 } 66 67 protected TabCellRenderer createDefaultRenderer() { 68 return new AquaEditorTabCellRenderer(); 69 } 70 71 public Insets getTabAreaInsets() { 72 Insets result = super.getTabAreaInsets(); 73 result.bottom = 2; 74 return result; 75 } 76 77 public static ComponentUI createUI(JComponent c) { 78 return new AquaEditorTabDisplayerUI ((TabDisplayer) c); 79 } 80 81 protected boolean isAntialiased() { 82 return true; 83 } 84 85 protected Font createFont() { 86 return UIManager.getFont("Label.font"); } 88 89 protected int createRepaintPolicy () { 90 return TabState.REPAINT_SELECTION_ON_ACTIVATION_CHANGE 91 | TabState.REPAINT_ON_SELECTION_CHANGE 92 | TabState.REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA 93 | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON 94 | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED 95 | TabState.REPAINT_ON_MOUSE_PRESSED; 96 } 97 98 public Dimension getPreferredSize(JComponent c) { 99 int prefHeight = 28; 100 Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics(); 103 if (g != null) { 104 FontMetrics fm = g.getFontMetrics(displayer.getFont()); 105 Insets ins = getTabAreaInsets(); 106 prefHeight = fm.getHeight() + ins.top + ins.bottom + 7; 107 } 108 if (prefHeight % 2 == 0) { 109 prefHeight += 1; 110 } 111 return new Dimension (displayer.getWidth(), prefHeight); 112 } 113 114 protected void paintAfterTabs(Graphics g) { 115 118 int centerY = (((displayer.getHeight() - 119 (AquaEditorTabCellRenderer.TOP_INSET + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) 120 + AquaEditorTabCellRenderer.TOP_INSET - 1) + getTabAreaInsets().top + 1; 121 122 if (lineMiddleColor == null) { 123 lineMiddleColor = ColorUtil.getMiddle(UIManager.getColor("controlShadow"), 124 UIManager.getColor("control")); } 126 g.setColor (lineMiddleColor); 127 128 int rightLineStart = getTabsAreaWidth() - 13; 129 int rightLineEnd = displayer.getWidth() - 9; 130 131 if (displayer.getModel().size() > 0 && !scroll().isLastTabClipped()) { 132 int idx = scroll().getLastVisibleTab(displayer.getWidth()); 135 rightLineStart = scroll().getX(idx) + scroll().getW(idx); 136 } else if (displayer.getModel().size() == 0) { 137 rightLineStart = 6; 138 } 139 140 if (scroll().getOffset() >= 0) { 141 g.drawLine(6, centerY, 11, centerY); 143 } 144 g.drawLine(rightLineStart, centerY, rightLineEnd, centerY); 145 146 if (lineHlColor == null) { 147 lineHlColor = ColorUtil.getMiddle (lineMiddleColor, 148 UIManager.getColor("control")); 149 } 150 151 g.setColor (lineHlColor); g.drawLine(rightLineStart, centerY+1, rightLineEnd, centerY+1); 153 if (scroll().getOffset() > 0) { 154 g.drawLine(6, centerY+1, 11, centerY+1); 156 } 157 } 158 159 160 private static void initIcons() { 161 if( null == buttonIconPaths ) { 162 buttonIconPaths = new HashMap <Integer , String []>(7); 163 164 String [] iconPaths = new String [4]; 166 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths ); 171 172 iconPaths = new String [4]; 174 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths ); 179 180 iconPaths = new String [4]; 182 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_popup_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_popup_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_pressed.png"; buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths ); 187 188 iconPaths = new String [4]; 190 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_pressed.png"; buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths ); 195 196 iconPaths = new String [4]; 197 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_restore_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_restore_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_pressed.png"; buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths ); 202 } 203 } 204 205 public Icon getButtonIcon(int buttonId, int buttonState) { 206 Icon res = null; 207 initIcons(); 208 String [] paths = buttonIconPaths.get( buttonId ); 209 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 210 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 211 } 212 return res; 213 } 214 215 protected Rectangle getControlButtonsRectangle(Container parent) { 216 int centerY = (((displayer.getHeight() - (AquaEditorTabCellRenderer.TOP_INSET 217 + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) + AquaEditorTabCellRenderer.TOP_INSET) 218 + getTabAreaInsets().top; 219 220 int width = parent.getWidth(); 221 int height = parent.getHeight(); 222 int buttonsWidth = getControlButtons().getWidth(); 223 int buttonsHeight = getControlButtons().getHeight(); 224 return new Rectangle ( width-buttonsWidth-3, centerY-buttonsHeight/2, buttonsWidth, buttonsHeight ); 225 } 226 } 227 | Popular Tags |