1 19 20 package org.netbeans.modules.options.advanced; 21 22 import java.awt.Color ; 23 import java.awt.Cursor ; 24 import java.awt.Font ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.FocusEvent ; 27 import java.awt.event.FocusListener ; 28 import java.awt.event.KeyEvent ; 29 import java.awt.event.MouseEvent ; 30 import java.awt.event.MouseListener ; 31 import javax.swing.AbstractAction ; 32 import javax.swing.Icon ; 33 import javax.swing.JComponent ; 34 import javax.swing.JLabel ; 35 import javax.swing.KeyStroke ; 36 import javax.swing.UIManager ; 37 import javax.swing.border.CompoundBorder ; 38 import javax.swing.border.EmptyBorder ; 39 import org.netbeans.modules.options.ui.DashedBorder; 40 import org.netbeans.modules.options.ui.TabbedPanel; 41 import org.netbeans.modules.options.ui.TabbedPanelModel; 42 43 44 47 public class WhiteTabbedPanel extends TabbedPanel { 48 49 50 public WhiteTabbedPanel ( 51 TabbedPanelModel model, 52 int expansionPolicy 53 ) { 54 super (model, expansionPolicy, false); 55 setBackground (Color.white); 56 } 57 58 protected JComponent createTitleComponent ( 59 String name, 60 String toolTip, 61 final int index 62 ) { 63 final JLabel l = new JLabel ( 64 name, 65 isExpanded (index) ? 66 (Icon ) UIManager.get ("Tree.expandedIcon"): 67 (Icon ) UIManager.get ("Tree.collapsedIcon"), 68 JLabel.LEFT 69 ); 70 l.setToolTipText (toolTip); 71 l.setFont (l.getFont ().deriveFont (Font.BOLD)); 72 l.setBackground (Color.white); 73 l.setForeground (Color.black); 74 l.setOpaque (true); 75 l.addMouseListener (new Listener1 ()); 76 l.putClientProperty ("index", Integer.valueOf(index)); 77 l.setFocusable (true); 78 l.setFocusTraversalKeysEnabled (true); 79 l.getActionMap ().put ( 80 "SPACE", 81 new AbstractAction () { 82 public void actionPerformed (ActionEvent e) { 83 if (getSelectedIndex () != index) 84 setSelectedIndex (index); 85 else 86 setSelectedIndex (-1); 87 } 88 } 89 ); 90 l.getInputMap ().put ( 91 KeyStroke.getKeyStroke (KeyEvent.VK_SPACE, 0), 92 "SPACE" 93 ); 94 l.setCursor (Cursor.getPredefinedCursor (Cursor.HAND_CURSOR)); 95 l.setBorder (new EmptyBorder (1, 3, 1, 1)); 96 l.addFocusListener (new FocusListener () { 97 public void focusGained (FocusEvent e) { 98 l.setBorder (new CompoundBorder ( 99 new DashedBorder (), 100 new EmptyBorder (0, 2, 0, 0) 101 )); 102 } 103 public void focusLost (FocusEvent e) { 104 l.setBorder (new EmptyBorder (1, 3, 1, 1)); 105 } 106 }); 107 return l; 108 } 109 110 private class Listener1 implements MouseListener { 111 112 public void mouseClicked (MouseEvent e) { 113 if (!(e.getSource () instanceof JLabel )) return; 114 JLabel l = (JLabel ) e.getSource (); 115 int i = ((Integer ) l.getClientProperty ("index")).intValue (); 116 if (i == getSelectedIndex ()) { 117 if (getExpansionPolicy () == EXPAND_SOME) 118 setSelectedIndex (-1); 119 } else 120 setSelectedIndex (i); 121 } 122 123 public void mousePressed (MouseEvent e) {} 124 public void mouseReleased (MouseEvent e) {} 125 public void mouseEntered (MouseEvent e) {} 126 public void mouseExited (MouseEvent e) {} 127 }; 128 } | Popular Tags |