KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > options > advanced > WhiteTabbedPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.options.advanced;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Cursor JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.FocusEvent JavaDoc;
27 import java.awt.event.FocusListener JavaDoc;
28 import java.awt.event.KeyEvent JavaDoc;
29 import java.awt.event.MouseEvent JavaDoc;
30 import java.awt.event.MouseListener JavaDoc;
31 import javax.swing.AbstractAction JavaDoc;
32 import javax.swing.Icon JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.KeyStroke JavaDoc;
36 import javax.swing.UIManager JavaDoc;
37 import javax.swing.border.CompoundBorder JavaDoc;
38 import javax.swing.border.EmptyBorder JavaDoc;
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 /**
45  * @author Jan Jancura
46  */

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 JavaDoc createTitleComponent (
59         String JavaDoc name,
60         String JavaDoc toolTip,
61         final int index
62     ) {
63         final JLabel JavaDoc l = new JLabel JavaDoc (
64             name,
65             isExpanded (index) ?
66                 (Icon JavaDoc) UIManager.get ("Tree.expandedIcon"):
67                 (Icon JavaDoc) 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 JavaDoc () {
82                 public void actionPerformed (ActionEvent JavaDoc 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 JavaDoc (1, 3, 1, 1));
96         l.addFocusListener (new FocusListener JavaDoc () {
97             public void focusGained (FocusEvent JavaDoc e) {
98                 l.setBorder (new CompoundBorder JavaDoc (
99                     new DashedBorder (),
100                     new EmptyBorder JavaDoc (0, 2, 0, 0)
101                 ));
102             }
103             public void focusLost (FocusEvent JavaDoc e) {
104                 l.setBorder (new EmptyBorder JavaDoc (1, 3, 1, 1));
105             }
106         });
107         return l;
108     }
109     
110     private class Listener1 implements MouseListener JavaDoc {
111         
112         public void mouseClicked (MouseEvent JavaDoc e) {
113             if (!(e.getSource () instanceof JLabel JavaDoc)) return;
114             JLabel JavaDoc l = (JLabel JavaDoc) e.getSource ();
115             int i = ((Integer JavaDoc) 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 JavaDoc e) {}
124         public void mouseReleased (MouseEvent JavaDoc e) {}
125         public void mouseEntered (MouseEvent JavaDoc e) {}
126         public void mouseExited (MouseEvent JavaDoc e) {}
127     };
128 }
Popular Tags