1 19 24 25 package org.netbeans.swing.tabcontrol.plaf; 26 27 import java.awt.Component ; 28 import java.awt.Container ; 29 import java.awt.Dimension ; 30 import java.awt.FontMetrics ; 31 import java.awt.GradientPaint ; 32 import java.awt.Graphics ; 33 import java.awt.Graphics2D ; 34 import java.awt.Insets ; 35 import java.awt.Rectangle ; 36 import java.util.HashMap ; 37 import java.util.Map ; 38 import javax.swing.Icon ; 39 import javax.swing.JComponent ; 40 import javax.swing.UIManager ; 41 import org.netbeans.swing.tabcontrol.TabDisplayer; 42 43 import javax.swing.plaf.ComponentUI ; 44 45 50 public final class WinClassicEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI { 51 52 private static final Rectangle scratch5 = new Rectangle (); 53 private static Map <Integer , String []> buttonIconPaths; 54 55 private static boolean isGenericUI = !"Windows".equals( UIManager.getLookAndFeel().getID()); 57 58 61 public WinClassicEditorTabDisplayerUI(TabDisplayer displayer) { 62 super (displayer); 63 } 64 65 public static ComponentUI createUI(JComponent c) { 66 return new WinClassicEditorTabDisplayerUI ((TabDisplayer) c); 67 } 68 69 public Rectangle getTabRect(int idx, Rectangle rect) { 70 Rectangle r = super.getTabRect (idx, rect); 71 r.y = 0; 74 r.height = displayer.getHeight(); 75 return r; 76 } 77 78 public void install() { 79 super.install(); 80 if (!isGenericUI) { 81 displayer.setBackground( UIManager.getColor("tab_unsel_fill") ); 82 displayer.setOpaque(true); 83 } 84 } 85 86 public Dimension getPreferredSize(JComponent c) { 87 int prefHeight = 28; 88 Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics(); 89 if (g != null) { 90 FontMetrics fm = g.getFontMetrics(displayer.getFont()); 91 Insets ins = getTabAreaInsets(); 92 prefHeight = fm.getHeight() + ins.top + ins.bottom + (isGenericUI ? 5 : 6); 93 } 94 return new Dimension (displayer.getWidth(), prefHeight); 95 } 96 97 private void genericPaintAfterTabs (Graphics g) { 98 g.setColor (UIManager.getColor("controlShadow")); Insets ins = displayer.getInsets(); 100 Rectangle r = new Rectangle (); 101 getTabsVisibleArea(r); 102 r.width = displayer.getWidth(); 103 int selEnd = 0; 104 int last = getLastVisibleTab(); 105 if (last > -1) { 106 getTabRect (last, scratch5); 107 g.drawLine (scratch5.x + scratch5.width, displayer.getHeight() -1, 108 displayer.getWidth() - (ins.left + ins.right) - 4, 109 displayer.getHeight() - 1); 110 g.drawLine (0, displayer.getHeight() - 2, 2, displayer.getHeight() -2); 111 if ("GTK".equals(UIManager.getLookAndFeel().getID())) { 113 boolean sel = last == displayer.getSelectionModel().getSelectedIndex(); 114 int x = scratch5.x + scratch5.width; 116 g.setColor (sel ? UIManager.getColor("controlShadow") : 117 ColorUtil.adjustTowards(g.getColor(), 20, 118 UIManager.getColor("control"))); g.drawLine (x, 120 scratch5.y + 5, x, 121 scratch5.y + scratch5.height -2); 122 g.setColor (ColorUtil.adjustTowards(g.getColor(), 20, 123 UIManager.getColor("control"))); g.drawLine (x + 1, 125 scratch5.y + 6, x + 1, 126 scratch5.y + scratch5.height -2); 127 } 128 if ((tabState.getState(getFirstVisibleTab()) & TabState.CLIP_LEFT) 129 !=0 && getFirstVisibleTab() != 130 displayer.getSelectionModel().getSelectedIndex()) { 131 GradientPaint gp = ColorUtil.getGradientPaint( 134 0, displayer.getHeight() / 2, UIManager.getColor("control"), 135 0, displayer.getHeight(), UIManager.getColor("controlShadow")); 136 ((Graphics2D ) g).setPaint(gp); 137 g.drawLine (0, displayer.getHeight() / 2, 0, displayer.getHeight()); 138 } else { 139 g.setColor (UIManager.getColor("controlShadow")); 142 g.drawLine (0, displayer.getHeight(), 0, displayer.getHeight() - 2); 143 } 144 if ((tabState.getState(getLastVisibleTab()) & TabState.CLIP_RIGHT) != 0 145 && getLastVisibleTab() != 146 displayer.getSelectionModel().getSelectedIndex()) { 147 GradientPaint gp = ColorUtil.getGradientPaint( 148 0, displayer.getHeight() / 2, UIManager.getColor("control"), 149 0, displayer.getHeight(), UIManager.getColor("controlShadow")); 150 ((Graphics2D ) g).setPaint(gp); 151 getTabRect (getLastVisibleTab(), scratch5); 152 g.drawLine (scratch5.x + scratch5.width, displayer.getHeight() / 2, 153 scratch5.x + scratch5.width, displayer.getHeight()); 154 } 155 156 } else { 157 g.drawLine(r.x, displayer.getHeight() - ins.bottom, r.x + r.width - 4, 158 displayer.getHeight() - ins.bottom); 159 } 160 } 161 162 protected void paintAfterTabs(Graphics g) { 163 if (isGenericUI) { 164 genericPaintAfterTabs(g); 165 return; 166 } 167 Rectangle r = new Rectangle (); 168 getTabsVisibleArea(r); 169 r.width = displayer.getWidth(); 170 g.setColor(displayer.isActive() ? 171 defaultRenderer.getSelectedActivatedBackground() : 172 defaultRenderer.getSelectedBackground()); 173 174 Insets ins = getTabAreaInsets(); 175 ins.bottom++; 176 g.fillRect(r.x, r.y + r.height, r.x + r.width, 177 displayer.getHeight() - (r.y + r.height)); 178 179 g.setColor(UIManager.getColor("controlLtHighlight")); 181 int selEnd = 0; 182 int i = selectionModel.getSelectedIndex(); 183 if (i != -1) { 184 getTabRect(i, scratch5); 185 if (scratch5.width != 0) { 186 if (r.x < scratch5.x) { 187 g.drawLine(r.x, displayer.getHeight() - ins.bottom, 188 scratch5.x - 1, 189 displayer.getHeight() - ins.bottom); 190 } 191 if (scratch5.x + scratch5.width < r.x + r.width) { 192 selEnd = scratch5.x + scratch5.width; 193 if (!scroll().isLastTabClipped()) { 197 selEnd--; 198 } 199 g.drawLine(selEnd, displayer.getHeight() - ins.bottom, 200 r.x + r.width, 201 displayer.getHeight() - ins.bottom); 202 } 203 } 204 return; 205 } 206 207 g.drawLine(r.x, displayer.getHeight() - ins.bottom, r.x + r.width, 208 displayer.getHeight() - ins.bottom); 209 } 210 211 protected TabCellRenderer createDefaultRenderer() { 212 return new WinClassicEditorTabCellRenderer(); 213 } 214 215 private static void initIcons() { 216 if( null == buttonIconPaths ) { 217 buttonIconPaths = new HashMap <Integer , String []>(7); 218 219 String [] iconPaths = new String [4]; 221 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths ); 226 227 iconPaths = new String [4]; 229 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths ); 234 235 iconPaths = new String [4]; 237 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_popup_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_popup_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_popup_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_popup_pressed.png"; buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths ); 242 243 iconPaths = new String [4]; 245 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_maximize_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_maximize_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_maximize_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_maximize_pressed.png"; buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths ); 250 251 iconPaths = new String [4]; 252 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_restore_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_restore_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_restore_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_restore_pressed.png"; buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths ); 257 } 258 } 259 260 public Icon getButtonIcon(int buttonId, int buttonState) { 261 Icon res = null; 262 initIcons(); 263 String [] paths = buttonIconPaths.get( buttonId ); 264 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 265 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 266 } 267 return res; 268 } 269 270 protected Rectangle getControlButtonsRectangle( Container parent ) { 271 Component c = getControlButtons(); 272 return new Rectangle ( parent.getWidth()-c.getWidth()-4, 4, c.getWidth(), c.getHeight() ); 273 } 274 275 public Insets getTabAreaInsets() { 276 Insets retValue = super.getTabAreaInsets(); 277 retValue.right += 4; 278 return retValue; 279 } 280 } 281 | Popular Tags |