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.Graphics ; 32 import java.awt.Insets ; 33 import java.awt.Rectangle ; 34 import java.util.HashMap ; 35 import java.util.Map ; 36 import javax.swing.Icon ; 37 import javax.swing.JComponent ; 38 import javax.swing.UIManager ; 39 import org.netbeans.swing.tabcontrol.TabDisplayer; 40 import javax.swing.plaf.ComponentUI ; 41 42 47 public final class MetalEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI { 48 49 private Rectangle scratch = new Rectangle (); 50 private static Map <Integer , String []> buttonIconPaths; 51 52 55 public MetalEditorTabDisplayerUI(TabDisplayer displayer) { 56 super(displayer); 57 } 58 59 protected TabCellRenderer createDefaultRenderer() { 60 return new MetalEditorTabCellRenderer(); 61 } 62 63 public static ComponentUI createUI(JComponent c) { 64 return new MetalEditorTabDisplayerUI((TabDisplayer) c); 65 } 66 67 public Dimension getMinimumSize(JComponent c) { 68 return new Dimension (80, 28); 69 } 70 71 public Dimension getPreferredSize(JComponent c) { 72 int prefHeight = 28; 73 Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics(); 74 if (g != null) { 75 FontMetrics fm = g.getFontMetrics(displayer.getFont()); 76 Insets ins = getTabAreaInsets(); 77 prefHeight = fm.getHeight() + ins.top + ins.bottom + 9; 78 } 79 return new Dimension (displayer.getWidth(), prefHeight); 80 } 81 82 protected int createRepaintPolicy () { 83 return TabState.REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE 84 | TabState.REPAINT_ALL_TABS_ON_SELECTION_CHANGE 85 | TabState.REPAINT_ON_MOUSE_PRESSED 86 | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED 87 | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON; 88 } 89 90 91 public Insets getTabAreaInsets() { 92 Insets results = super.getTabAreaInsets(); 93 results.bottom += 4; 94 results.right += 3; 95 return results; 96 } 97 98 public void install() { 99 super.install(); 100 displayer.setBackground(UIManager.getColor("control")); } 102 103 protected void paintAfterTabs(Graphics g) { 104 Rectangle r = new Rectangle (); 105 getTabsVisibleArea(r); 106 r.width = displayer.getWidth(); 107 g.setColor(displayer.isActive() ? 108 defaultRenderer.getSelectedActivatedBackground() : 109 defaultRenderer.getSelectedBackground()); 110 111 Insets ins = getTabAreaInsets(); 112 g.fillRect(r.x, r.y + r.height, r.x + r.width, 113 displayer.getHeight() - (r.y + r.height)); 114 115 g.setColor(UIManager.getColor("controlHighlight")); 117 int selEnd = 0; 118 int i = selectionModel.getSelectedIndex(); 119 if (i != -1) { 120 getTabRect(i, scratch); 121 if (scratch.width != 0) { 122 if (r.x < scratch.x) { 123 g.drawLine(r.x, displayer.getHeight() - ins.bottom, 124 scratch.x - 1, 125 displayer.getHeight() - ins.bottom); 126 } 127 if (scratch.x + scratch.width < r.x + r.width) { 128 selEnd = scratch.x + scratch.width; 129 g.drawLine(selEnd, displayer.getHeight() - ins.bottom, 130 r.x + r.width, 131 displayer.getHeight() - ins.bottom); 132 } 133 } else { 134 g.drawLine (0, displayer.getHeight() - ins.bottom, 136 displayer.getWidth(), displayer.getHeight() - ins.bottom); 137 } 138 g.setColor(UIManager.getColor("controlDkShadow")); g.drawLine(selEnd, displayer.getHeight() - 5, displayer.getWidth(), 140 displayer.getHeight() - 5); 141 return; 142 } 143 144 g.drawLine(r.x, displayer.getHeight() - ins.bottom, r.x + r.width, 145 displayer.getHeight() - ins.bottom); 146 147 g.setColor(UIManager.getColor("controlDkShadow")); g.drawLine(0, displayer.getHeight() - 5, displayer.getWidth(), 149 displayer.getHeight() - 5); 150 } 151 152 private static void initIcons() { 153 if( null == buttonIconPaths ) { 154 buttonIconPaths = new HashMap <Integer , String []>(7); 155 156 String [] iconPaths = new String [4]; 158 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths ); 163 164 iconPaths = new String [4]; 166 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths ); 171 172 iconPaths = new String [4]; 174 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_popup_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_popup_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_popup_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_popup_pressed.png"; buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths ); 179 180 iconPaths = new String [4]; 182 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_pressed.png"; buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths ); 187 188 iconPaths = new String [4]; 189 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_restore_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_restore_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_restore_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_restore_pressed.png"; buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths ); 194 } 195 } 196 197 public Icon getButtonIcon(int buttonId, int buttonState) { 198 Icon res = null; 199 initIcons(); 200 String [] paths = buttonIconPaths.get( buttonId ); 201 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 202 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 203 } 204 return res; 205 } 206 207 protected Rectangle getControlButtonsRectangle( Container parent ) { 208 Component c = getControlButtons(); 209 return new Rectangle ( parent.getWidth()-c.getWidth()-3, 3, c.getWidth(), c.getHeight() ); 210 } 211 } 212 | Popular Tags |