KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > quickhelp > HelpListCellRenderer


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.quickhelp;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.Font JavaDoc;
24
25 import javax.swing.BorderFactory JavaDoc;
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.JLabel JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.ListCellRenderer JavaDoc;
30
31 import org.openharmonise.him.window.quickhelp.QuickHelpWindow.*;
32
33
34 /**
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class HelpListCellRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
41
42     
43     private Color JavaDoc m_selectedColor = new Color JavaDoc(173, 169, 143);
44     /**
45      *
46      */

47     public HelpListCellRenderer() {
48         super();
49         this.setOpaque(true);
50         String JavaDoc fontName = "Dialog";
51         int fontSize = 11;
52         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
53         this.setFont(font);
54     }
55
56     /* (non-Javadoc)
57      * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
58      */

59     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list,
60                                                   Object JavaDoc value,
61                                                   int index,
62                                                   boolean bIsSelected,
63                                                   boolean bCellHasFocus) {
64
65         QuickHelpWindow.HelpListItem listItem = (HelpListItem) value;
66         
67         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
68         for(int i=0; i<listItem.getDepth(); i++) {
69             sBuff.append(" ");
70         }
71         sBuff.append(listItem.getTitle());
72         this.setText(sBuff.toString());
73         if(bIsSelected) {
74             this.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
75             this.setBackground(m_selectedColor);
76         } else {
77             this.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
78             this.setBackground(Color.WHITE);
79         }
80         
81         return this;
82     }
83
84     /**
85      * @param arg0
86      */

87     private HelpListCellRenderer(String JavaDoc arg0) {
88         super(arg0);
89     }
90
91     /**
92      * @param arg0
93      * @param arg1
94      */

95     private HelpListCellRenderer(String JavaDoc arg0, int arg1) {
96         super(arg0, arg1);
97     }
98
99     /**
100      * @param arg0
101      */

102     private HelpListCellRenderer(Icon JavaDoc arg0) {
103         super(arg0);
104     }
105
106     /**
107      * @param arg0
108      * @param arg1
109      */

110     private HelpListCellRenderer(Icon JavaDoc arg0, int arg1) {
111         super(arg0, arg1);
112     }
113
114     /**
115      * @param arg0
116      * @param arg1
117      * @param arg2
118      */

119     private HelpListCellRenderer(String JavaDoc arg0, Icon JavaDoc arg1, int arg2) {
120         super(arg0, arg1, arg2);
121     }
122
123 }
124
Popular Tags