1 19 24 25 package org.netbeans.swing.tabcontrol.plaf; 26 27 import java.awt.Component ; 28 import java.awt.Dimension ; 29 import java.awt.Graphics ; 30 import java.awt.Graphics2D ; 31 import java.awt.Insets ; 32 import java.awt.Polygon ; 33 import java.awt.Rectangle ; 34 import javax.swing.Icon ; 35 import javax.swing.JComponent ; 36 37 44 final class AquaEditorTabCellRenderer extends AbstractTabCellRenderer { 45 private static final AquaTabPainter AquaTabPainter = new AquaTabPainter(); 46 47 static final int TOP_INSET = 0; 48 static final int LEFT_INSET = 3; 49 static final int RIGHT_INSET = 6; 50 static final int BOTTOM_INSET = 2; 51 52 53 private static final ChicletWrapper chiclet = new ChicletWrapper(); 54 55 public AquaEditorTabCellRenderer() { 56 super(AquaTabPainter, AquaTabPainter, AquaTabPainter, 57 new Dimension (23, 8)); 58 } 59 60 protected int getCaptionYAdjustment() { 61 return 0; 62 } 63 64 protected int getIconYAdjustment() { 65 return -1; 66 } 67 68 public Dimension getPadding() { 69 Dimension d = super.getPadding(); 70 d.width = isShowCloseButton() && !Boolean.getBoolean("nb.tabs.suppressCloseButton") ? 26 : 13; 71 return d; 72 } 73 74 private static class AquaTabPainter implements TabPainter { 75 private static Insets insets = new Insets (TOP_INSET, LEFT_INSET, 76 BOTTOM_INSET, RIGHT_INSET); 77 78 public AquaTabPainter() { 79 } 80 81 public Insets getBorderInsets(Component c) { 82 boolean leftmost = ((AquaEditorTabCellRenderer) c).isLeftmost(); 83 84 if (leftmost) { 85 return new Insets (TOP_INSET, LEFT_INSET + 4, BOTTOM_INSET, 86 RIGHT_INSET); 87 } else { 88 return insets; 89 } 90 } 91 92 public void getCloseButtonRectangle(JComponent jc, Rectangle rect, 93 Rectangle bounds) { 94 boolean rightClip = ((AquaEditorTabCellRenderer) jc).isClipRight(); 95 boolean leftClip = ((AquaEditorTabCellRenderer) jc).isClipLeft(); 96 boolean notSupported = !((AbstractTabCellRenderer) jc).isShowCloseButton(); 97 if (leftClip || rightClip || notSupported) { 98 rect.x = -100; 99 rect.y = -100; 100 rect.width = 0; 101 rect.height = 0; 102 } else { 103 String iconPath = findIconPath((AquaEditorTabCellRenderer) jc); 104 Icon icon = TabControlButtonFactory.getIcon(iconPath); 105 int iconWidth = icon.getIconWidth(); 106 int iconHeight = icon.getIconHeight(); 107 rect.x = bounds.x + bounds.width - iconWidth - 2; 108 rect.y = bounds.y + (Math.max(0, bounds.height / 2 - iconHeight / 2)); 109 rect.width = iconWidth; 110 rect.height = iconHeight; 111 } 112 } 113 114 115 119 private String findIconPath( AquaEditorTabCellRenderer renderer ) { 120 if( renderer.inCloseButton() && renderer.isPressed() ) { 121 return "org/netbeans/swing/tabcontrol/resources/mac_close_pressed.png"; } 123 if( renderer.inCloseButton() ) { 124 return "org/netbeans/swing/tabcontrol/resources/mac_close_rollover.png"; } 126 return "org/netbeans/swing/tabcontrol/resources/mac_close_enabled.png"; } 128 129 private void paintCloseButton(Graphics g, JComponent c) { 130 if (((AbstractTabCellRenderer) c).isShowCloseButton()) { 131 132 Rectangle r = new Rectangle (0, 0, c.getWidth(), c.getHeight()); 133 Rectangle cbRect = new Rectangle (); 134 getCloseButtonRectangle((JComponent ) c, cbRect, r); 135 136 String iconPath = findIconPath( (AquaEditorTabCellRenderer)c ); 138 Icon icon = TabControlButtonFactory.getIcon( iconPath ); 139 icon.paintIcon(c, g, cbRect.x, cbRect.y); 140 } 141 } 142 143 public Polygon getInteriorPolygon(Component c) { 144 return new Polygon (new int[]{0, c.getWidth(), c.getWidth(), 0}, new int[]{ 145 0, 0, c.getHeight(), c.getHeight()}, 4); 146 } 147 148 public boolean isBorderOpaque() { 149 return false; 150 } 151 152 public void paintBorder(Component c, Graphics g, int x, int y, 153 int width, int height) { 154 paintCloseButton(g, (JComponent ) c); 155 } 156 157 158 public void paintInterior(Graphics g, Component c) { 159 if (true) { 160 Rectangle bds = c.getBounds(); 161 162 boolean rightmost = ((AquaEditorTabCellRenderer) c).isRightmost(); 163 boolean rightClip = ((AquaEditorTabCellRenderer) c).isClipRight(); 164 boolean sel = ((AquaEditorTabCellRenderer) c).isSelected(); 165 boolean active = ((AquaEditorTabCellRenderer) c).isActive(); 166 boolean pressed = ((AquaEditorTabCellRenderer) c).isPressed(); 167 boolean leftClip = ((AquaEditorTabCellRenderer) c).isClipLeft(); 168 boolean leftmost = ((AquaEditorTabCellRenderer) c).isLeftmost(); 169 boolean closing = pressed 170 && ((AquaEditorTabCellRenderer) c).inCloseButton(); 171 boolean attention = !pressed && !closing 172 && ((AquaEditorTabCellRenderer) c).isAttention(); 173 174 chiclet.setBounds(0, 0, bds.width, bds.height); 177 178 chiclet.setNotch(rightClip, leftClip); 179 int state = 0; 180 float leftarc = leftmost && !leftClip ? 0.5f : 0f; 181 float rightarc = rightmost && !rightClip ? 0.5f : 0f; 182 183 if (pressed && (rightClip || leftClip)) { 184 state |= GenericGlowingChiclet.STATE_PRESSED; 185 } 186 if (active) { 187 state |= GenericGlowingChiclet.STATE_ACTIVE; 188 } 189 if (sel) { 190 state |= GenericGlowingChiclet.STATE_SELECTED; 191 } 192 if (closing) { 193 state |= GenericGlowingChiclet.STATE_CLOSING; 194 } 195 if (attention) { 196 state |= GenericGlowingChiclet.STATE_ATTENTION; 197 } 198 chiclet.setArcs(leftarc, rightarc, leftarc, rightarc); 199 200 chiclet.setState(state); 201 chiclet.draw((Graphics2D ) g); 202 return; 203 } 204 } 205 206 public boolean supportsCloseButton(JComponent c) { 207 boolean leftClip = ((AquaEditorTabCellRenderer) c).isClipLeft(); 208 boolean rightClip = ((AquaEditorTabCellRenderer) c).isClipRight(); 209 boolean supported = ((AquaEditorTabCellRenderer) c).isShowCloseButton(); 210 return !leftClip && !rightClip && supported; 211 } 212 213 } 214 } 215 | Popular Tags |