-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegionListCellRenderer.java
More file actions
67 lines (52 loc) · 2.29 KB
/
Copy pathRegionListCellRenderer.java
File metadata and controls
67 lines (52 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.SpringLayout;
/**
*
* @author Juanjo Vega
*/
public class RegionListCellRenderer extends JPanel implements ListCellRenderer {
private static final long serialVersionUID = -1043924962165633428L;
private JLabel jlIndex = new JLabel();
private JLabel jlThumbnail = new JLabel();
private JLabel jlInfo = new JLabel();
public RegionListCellRenderer() {
super();
jlIndex.setHorizontalTextPosition(JLabel.LEFT);
jlInfo.setHorizontalTextPosition(JLabel.LEFT);
jlIndex.setVerticalTextPosition(JLabel.CENTER);
jlInfo.setVerticalTextPosition(JLabel.CENTER);
SpringLayout layout = new SpringLayout();
setLayout(layout);
add(jlIndex);
add(jlThumbnail);
add(jlInfo);
// Horizontal layout.
layout.putConstraint(SpringLayout.WEST, jlIndex, 5, SpringLayout.WEST, this);
layout.putConstraint(SpringLayout.WEST, jlThumbnail, 5, SpringLayout.EAST, jlIndex);
layout.putConstraint(SpringLayout.WEST, jlInfo, 5, SpringLayout.EAST, jlThumbnail);
layout.putConstraint(SpringLayout.SOUTH, this, 0, SpringLayout.SOUTH, jlThumbnail);
// Vertical centering according to icon.
layout.putConstraint(SpringLayout.VERTICAL_CENTER, jlIndex, 0, SpringLayout.VERTICAL_CENTER, jlThumbnail);
layout.putConstraint(SpringLayout.VERTICAL_CENTER, jlInfo, 0, SpringLayout.VERTICAL_CENTER, jlThumbnail);
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
ThumbnailItem item = (ThumbnailItem) value;
jlIndex.setText("<html><b>" + index/*nformatter.format(index)*/ + ": </b></html>");
jlThumbnail.setIcon(new ImageIcon(item.getThumbnail()));
jlInfo.setText("<html>" + item.toString() + "</html>");
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
return this;
}
}