41 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
42 |
import java.io.Serializable; |
import java.io.Serializable; |
43 |
import javax.swing.border.Border; |
import javax.swing.border.Border; |
44 |
|
import javax.swing.border.EmptyBorder; |
45 |
|
|
46 |
|
|
47 |
/** |
/** |
48 |
* DefaultListCellRenderer |
* DefaultListCellRenderer. This class is responsible for rendering list |
49 |
|
* cells. |
50 |
* |
* |
51 |
* @author Andrew Selkirk |
* @author Andrew Selkirk |
52 |
* @version 1.0 |
* @version 1.0 |
53 |
*/ |
*/ |
54 |
public class DefaultListCellRenderer |
public class DefaultListCellRenderer extends JLabel implements ListCellRenderer, |
55 |
extends JLabel implements ListCellRenderer, Serializable |
Serializable |
56 |
{ |
{ |
57 |
static final long serialVersionUID = 7708947179685189462L; |
static final long serialVersionUID = 7708947179685189462L; |
58 |
|
|
64 |
} |
} |
65 |
} |
} |
66 |
|
|
67 |
/** noFocusBorder */ |
/** |
68 |
protected static Border noFocusBorder = null; // TODO |
* This border is used whenever renderer doesn't have a focus. |
69 |
|
*/ |
70 |
|
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); |
71 |
|
|
72 |
/** |
/** |
73 |
* getListCellRendererComponent |
* getListCellRendererComponent |
74 |
* |
* |
75 |
* @param list TODO |
* @param list JList list for the 'value' |
76 |
* @param value TODO |
* @param value object that should be rendered in the cell |
77 |
* @param index TODO |
* @param index index of the cell |
78 |
* @param isSelected TODO |
* @param isSelected draw cell highlighted if isSelected is true |
79 |
* @param cellHasFocus TODO |
* @param cellHasFocus draw focus rectangle around cell if the cell has |
80 |
|
* focus |
81 |
* |
* |
82 |
* @return Component |
* @return Component that will be painted to the desired cell. |
83 |
*/ |
*/ |
84 |
public Component getListCellRendererComponent(JList list, Object value, |
public Component getListCellRendererComponent(JList list, Object value, |
85 |
int index, boolean isSelected, |
int index, boolean isSelected, |
91 |
|
|
92 |
if (isSelected) |
if (isSelected) |
93 |
{ |
{ |
94 |
setBackground(list.getSelectionBackground()); |
setBackground(list.getSelectionBackground()); |
95 |
setForeground(list.getSelectionForeground()); |
setForeground(list.getSelectionForeground()); |
96 |
} |
} |
97 |
else |
else |
98 |
{ |
{ |
99 |
setBackground(list.getBackground()); |
setBackground(list.getBackground()); |
100 |
setForeground(list.getForeground()); |
setForeground(list.getForeground()); |
101 |
} |
} |
102 |
|
|
103 |
setEnabled(list.isEnabled()); |
setEnabled(list.isEnabled()); |
104 |
setFont(list.getFont()); |
setFont(list.getFont()); |
105 |
|
|
106 |
|
// Use focusCellHighlightBorder when renderer has focus and |
107 |
|
// noFocusBorder otherwise |
108 |
|
|
109 |
|
if (cellHasFocus) |
110 |
|
setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); |
111 |
|
else |
112 |
|
setBorder(noFocusBorder); |
113 |
|
|
114 |
return this; |
return this; |
115 |
} |
} |
116 |
|
|
117 |
public void validate() {} |
public void validate() |
118 |
public void revalidate() {} |
{ |
119 |
public void repaint(long tm, int x, int y, int w, int h) {} |
} |
120 |
public void repaint(Rectangle rect) {} |
|
121 |
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue){} |
public void revalidate() |
122 |
public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {} |
{ |
123 |
public void firePropertyChange(String propertyName, char oldValue, char newValue) {} |
} |
124 |
public void firePropertyChange(String propertyName, short oldValue, short newValue) {} |
|
125 |
public void firePropertyChange(String propertyName, int oldValue, int newValue) {} |
public void repaint(long tm, int x, int y, int w, int h) |
126 |
public void firePropertyChange(String propertyName, long oldValue, long newValue) {} |
{ |
127 |
public void firePropertyChange(String propertyName, float oldValue, float newValue) {} |
} |
128 |
public void firePropertyChange(String propertyName, double oldValue, double newValue) {} |
|
129 |
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {} |
public void repaint(Rectangle rect) |
130 |
|
{ |
131 |
|
} |
132 |
|
|
133 |
|
protected void firePropertyChange(String propertyName, Object oldValue, |
134 |
|
Object newValue) |
135 |
|
{ |
136 |
|
} |
137 |
|
|
138 |
|
public void firePropertyChange(String propertyName, byte oldValue, |
139 |
|
byte newValue) |
140 |
|
{ |
141 |
|
} |
142 |
|
|
143 |
|
public void firePropertyChange(String propertyName, char oldValue, |
144 |
|
char newValue) |
145 |
|
{ |
146 |
|
} |
147 |
|
|
148 |
|
public void firePropertyChange(String propertyName, short oldValue, |
149 |
|
short newValue) |
150 |
|
{ |
151 |
|
} |
152 |
|
|
153 |
|
public void firePropertyChange(String propertyName, int oldValue, |
154 |
|
int newValue) |
155 |
|
{ |
156 |
|
} |
157 |
|
|
158 |
|
public void firePropertyChange(String propertyName, long oldValue, |
159 |
|
long newValue) |
160 |
|
{ |
161 |
|
} |
162 |
|
|
163 |
|
public void firePropertyChange(String propertyName, float oldValue, |
164 |
|
float newValue) |
165 |
|
{ |
166 |
|
} |
167 |
|
|
168 |
|
public void firePropertyChange(String propertyName, double oldValue, |
169 |
|
double newValue) |
170 |
|
{ |
171 |
|
} |
172 |
|
|
173 |
|
public void firePropertyChange(String propertyName, boolean oldValue, |
174 |
|
boolean newValue) |
175 |
|
{ |
176 |
|
} |
177 |
} |
} |