1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Component;
|
---|
7 | import java.text.DateFormat;
|
---|
8 |
|
---|
9 | import javax.swing.ImageIcon;
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JList;
|
---|
12 | import javax.swing.ListCellRenderer;
|
---|
13 | import javax.swing.UIManager;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * A {@link ListCellRenderer} for the list of changesets in the upload dialog.
|
---|
20 | *
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public class ChangesetCellRenderer extends JLabel implements ListCellRenderer {
|
---|
24 | private ImageIcon icon ;
|
---|
25 | public ChangesetCellRenderer() {
|
---|
26 | icon = ImageProvider.get("data", "changeset");
|
---|
27 | setOpaque(true);
|
---|
28 | }
|
---|
29 |
|
---|
30 | protected String buildToolTipText(Changeset cs) {
|
---|
31 | StringBuilder sb = new StringBuilder();
|
---|
32 | sb.append("<html>");
|
---|
33 | sb.append("<strong>").append(tr("Changeset id:")).append("</strong>").append(cs.getId()).append("<br>");
|
---|
34 | if (cs.getCreatedAt() != null) {
|
---|
35 | sb.append("<strong>").append(tr("Created at:")).append("</strong>").append(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(cs.getCreatedAt())).append("<br>");
|
---|
36 | }
|
---|
37 | if (cs.get("comment") != null) {
|
---|
38 | sb.append("<strong>").append(tr("Changeset comment:")).append("</strong>").append(cs.get("comment")).append("<br>");
|
---|
39 | }
|
---|
40 | return sb.toString();
|
---|
41 | }
|
---|
42 |
|
---|
43 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
|
---|
44 | boolean cellHasFocus) {
|
---|
45 | Changeset cs = (Changeset)value;
|
---|
46 | if (isSelected) {
|
---|
47 | setForeground(UIManager.getColor("List.selectionForeground"));
|
---|
48 | setBackground(UIManager.getColor("List.selectionBackground"));
|
---|
49 | } else {
|
---|
50 | setForeground(UIManager.getColor("List.foreground"));
|
---|
51 | setBackground(UIManager.getColor("List.background"));
|
---|
52 | }
|
---|
53 | if (cs != null) {
|
---|
54 | setIcon(icon);
|
---|
55 | StringBuffer sb = new StringBuffer();
|
---|
56 | if (cs.get("comment") != null) {
|
---|
57 | sb.append(cs.getId()).append(" - ").append(cs.get("comment"));
|
---|
58 | } else if (cs.get("name") != null) {
|
---|
59 | sb.append(cs.getId()).append(" - ").append(cs.get("name"));
|
---|
60 | } else {
|
---|
61 | sb.append(tr("Changeset {0}", cs.getId()));
|
---|
62 | }
|
---|
63 | setText(sb.toString());
|
---|
64 | setToolTipText(buildToolTipText(cs));
|
---|
65 | } else {
|
---|
66 | setText(tr("No open changeset"));
|
---|
67 | }
|
---|
68 | return this;
|
---|
69 | }
|
---|
70 | }
|
---|