KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SDefaultListCellRenderer


1 /*
2  * $Id: SDefaultListCellRenderer.java,v 1.5 2005/02/11 16:53:21 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 /**
17  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
18  * @version $Revision: 1.5 $
19  */

20 public class SDefaultListCellRenderer extends SLabel implements SListCellRenderer {
21
22     /**
23      * Style class to use for the foreground for selected nodes.
24      */

25     protected String JavaDoc selectionStyle = null;
26
27     /**
28      * Style class to use for the foreground for non-selected nodes.
29      */

30     protected String JavaDoc nonSelectionStyle = null;
31
32     /**
33      * Create a SDefaultListCellRenderer with default properties.
34      */

35     public SDefaultListCellRenderer() {
36     }
37
38
39     /**
40      * Sets the style the cell is drawn with when the cell is selected.
41      */

42     public void setSelectionStyle(String JavaDoc newStyle) {
43         selectionStyle = newStyle;
44     }
45
46     /**
47      * Returns the style the cell is drawn with when the cell is selected.
48      */

49     public String JavaDoc getSelectionStyle() {
50         return selectionStyle;
51     }
52
53     /**
54      * Sets the style the cell is drawn with when the cell isn't selected.
55      */

56     public void setNonSelectionStyle(String JavaDoc newStyle) {
57         nonSelectionStyle = newStyle;
58     }
59
60     /**
61      * Returns the style the cell is drawn with when the cell isn't selected.
62      */

63     public String JavaDoc getNonSelectionStyle() {
64         return nonSelectionStyle;
65     }
66
67
68     public SComponent getListCellRendererComponent(SComponent list, Object JavaDoc value, boolean selected, int index) {
69         setText(null);
70         setIcon(null);
71
72         if (value == null)
73             setText("");
74         else if (value instanceof SIcon)
75             setIcon((SIcon) value);
76         else if (value instanceof SComponent) {
77             SComponent result = (SComponent) value;
78
79             if (selected && selectionStyle != null) {
80                 result.setStyle(selectionStyle);
81             } else {
82                 result.setStyle(nonSelectionStyle);
83             }
84
85             return result;
86         } else {
87             setText(value.toString());
88         }
89
90         if (selected && selectionStyle != null) {
91             setStyle(selectionStyle);
92         } else {
93             setStyle(nonSelectionStyle);
94         }
95
96         return this;
97     }
98 }
99
100
101
Popular Tags