1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.changeset;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Component;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.JList;
|
---|
10 | import javax.swing.ListCellRenderer;
|
---|
11 | import javax.swing.UIManager;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | public class ChangesetListCellRenderer extends JLabel implements ListCellRenderer{
|
---|
17 |
|
---|
18 | public ChangesetListCellRenderer() {
|
---|
19 | setOpaque(true);
|
---|
20 | setIcon(ImageProvider.get("data", "changeset"));
|
---|
21 | }
|
---|
22 |
|
---|
23 | protected void renderColors(boolean selected) {
|
---|
24 | if (selected) {
|
---|
25 | setForeground(UIManager.getColor("List.selectionForeground"));
|
---|
26 | setBackground(UIManager.getColor("List.selectionBackground"));
|
---|
27 | } else {
|
---|
28 | setForeground(UIManager.getColor("List.foreground"));
|
---|
29 | setBackground(UIManager.getColor("List.background"));
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected void renderLabel(Changeset cs) {
|
---|
34 | StringBuffer sb = new StringBuffer();
|
---|
35 | if (cs.isIncomplete()) {
|
---|
36 | sb.append(tr("{0} [incomplete]", cs.getId()));
|
---|
37 | } else {
|
---|
38 | String comment = cs.get("comment");
|
---|
39 | sb.append(cs.getId());
|
---|
40 | sb.append(" - ");
|
---|
41 | sb.append(cs.isOpen() ? tr("open") : tr("closed"));
|
---|
42 | if (comment != null) {
|
---|
43 | sb.append(" - ").append("'").append(comment).append("'");
|
---|
44 | }
|
---|
45 | }
|
---|
46 | setText(sb.toString());
|
---|
47 | }
|
---|
48 |
|
---|
49 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
|
---|
50 | boolean cellHasFocus) {
|
---|
51 | Changeset cs = (Changeset)value;
|
---|
52 | renderColors(isSelected);
|
---|
53 | renderLabel(cs);
|
---|
54 | return this;
|
---|
55 | }
|
---|
56 | }
|
---|