KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > wizards > ToolTipCombo


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 package org.netbeans.modules.web.wizards;
20
21 import java.awt.Component JavaDoc;
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JList JavaDoc;
27 import javax.swing.ListCellRenderer JavaDoc;
28
29 class ToolTipCombo extends JComboBox JavaDoc {
30
31     private final static boolean debug = false;
32
33     private static final long serialVersionUID = 1189442122448524856L;
34
35     ToolTipCombo(Object JavaDoc[] o) {
36     super(o);
37     this.setRenderer(new PathRenderer());
38     addItemListener(new ItemListener JavaDoc() {
39         public void itemStateChanged(ItemEvent JavaDoc evt) {
40             if(evt.getStateChange() == ItemEvent.SELECTED) {
41             setToolTipText(evt.getItem().toString());
42             }
43         }
44         });
45     if(o != null && o.length > 1)
46         setToolTipText(o[0].toString());
47     }
48         
49     private void log(String JavaDoc s) {
50     System.out.println("ToolTipCombo" + s);
51     }
52
53     class PathRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
54
55         private static final long serialVersionUID = 1323260132420573174L;
56         
57     public PathRenderer() {
58         setOpaque(true);
59     }
60
61     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list,
62                               Object JavaDoc value,
63                               int index,
64                               boolean isSelected,
65                               boolean cellHasFocus) {
66         
67         if(debug) log("::getListCellRendererComponent()"); //NOI18N
68
if(debug) log("\t" + value.toString()); //NOI18N
69
setText(value.toString());
70         setToolTipText(value.toString());
71         return this;
72     }
73     }
74 }
75
76
Popular Tags