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 org.netbeans.swing.tabcontrol.TabDisplayer; 39 40 import javax.swing.plaf.ComponentUI ; 41 42 47 public final class GtkEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI { 48 49 private static Map <Integer , String []> buttonIconPaths; 50 51 54 public GtkEditorTabDisplayerUI(TabDisplayer displayer) { 55 super (displayer); 56 } 57 58 public static ComponentUI createUI(JComponent c) { 59 return new GtkEditorTabDisplayerUI ((TabDisplayer) c); 60 } 61 62 public Rectangle getTabRect(int idx, Rectangle rect) { 63 Rectangle r = super.getTabRect (idx, rect); 64 r.y = 0; 67 r.height = displayer.getHeight(); 68 return r; 69 } 70 71 public void install() { 72 super.install(); 73 } 74 75 public Dimension getPreferredSize(JComponent c) { 76 int prefHeight = 28; 77 Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics(); 78 if (g != null) { 79 FontMetrics fm = g.getFontMetrics(displayer.getFont()); 80 Insets ins = getTabAreaInsets(); 81 prefHeight = fm.getHeight() + ins.top + ins.bottom + 12; 82 } 83 return new Dimension (displayer.getWidth(), prefHeight); 84 } 85 86 protected void paintAfterTabs(Graphics g) { 87 } 88 89 protected TabCellRenderer createDefaultRenderer() { 90 return new GtkEditorTabCellRenderer(); 91 } 92 93 private static void initIcons() { 94 if( null == buttonIconPaths ) { 95 buttonIconPaths = new HashMap <Integer , String []>(7); 96 97 String [] iconPaths = new String [4]; 99 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths ); 104 105 iconPaths = new String [4]; 107 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_pressed.png"; buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths ); 112 113 iconPaths = new String [4]; 115 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_pressed.png"; buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths ); 120 121 iconPaths = new String [4]; 123 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_pressed.png"; buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths ); 128 129 iconPaths = new String [4]; 130 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_enabled.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_rollover.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_pressed.png"; buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths ); 135 } 136 } 137 138 public Icon getButtonIcon(int buttonId, int buttonState) { 139 Icon res = null; 140 initIcons(); 141 String [] paths = buttonIconPaths.get( buttonId ); 142 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 143 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 144 } 145 return res; 146 } 147 148 protected Rectangle getControlButtonsRectangle( Container parent ) { 149 Component c = getControlButtons(); 150 return new Rectangle ( parent.getWidth()-c.getWidth()-4, 4, c.getWidth(), c.getHeight() ); 151 } 152 153 public Insets getTabAreaInsets() { 154 Insets retValue = super.getTabAreaInsets(); 155 retValue.right += 4; 156 return retValue; 157 } 158 } 159 | Popular Tags |