source: josm/trunk/src/org/openstreetmap/josm/gui/io/ChangesetCellRenderer.java@ 7001

Last change on this file since 7001 was 7001, checked in by Don-vip, 10 years ago

see #8465 - switch core to Java 7

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