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

Last change on this file since 11386 was 10242, checked in by Don-vip, 8 years ago

sonar - pmd:InsufficientStringBufferDeclaration - Insufficient String Buffer Declaration

  • Property svn:eol-style set to native
File size: 2.7 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;
17import org.openstreetmap.josm.tools.date.DateUtils;
18
19/**
20 * A {@link ListCellRenderer} for the list of changesets in the upload dialog.
21 *
22 * @since 2115
23 */
24public class ChangesetCellRenderer extends JLabel implements ListCellRenderer<Changeset> {
25 private final ImageIcon icon;
26
27 /**
28 * Constructs a new {@code ChangesetCellRenderer}.
29 */
30 public ChangesetCellRenderer() {
31 icon = ImageProvider.get("data", "changeset");
32 setOpaque(true);
33 }
34
35 protected String buildToolTipText(Changeset cs) {
36 StringBuilder sb = new StringBuilder(64);
37 sb.append("<html><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(
40 DateUtils.formatDateTime(cs.getCreatedAt(), DateFormat.SHORT, DateFormat.SHORT)).append("<br>");
41 }
42 if (cs.get("comment") != null) {
43 sb.append("<strong>").append(tr("Changeset comment:")).append("</strong>").append(cs.get("comment")).append("<br>");
44 }
45 return sb.toString();
46 }
47
48 @Override
49 public Component getListCellRendererComponent(JList<? extends Changeset> list, Changeset cs, int index, boolean isSelected,
50 boolean cellHasFocus) {
51 if (isSelected) {
52 setForeground(UIManager.getColor("List.selectionForeground"));
53 setBackground(UIManager.getColor("List.selectionBackground"));
54 } else {
55 setForeground(UIManager.getColor("List.foreground"));
56 setBackground(UIManager.getColor("List.background"));
57 }
58 if (cs != null) {
59 setIcon(icon);
60 StringBuilder sb = new StringBuilder();
61 if (cs.get("comment") != null) {
62 sb.append(cs.getId()).append(" - ").append(cs.get("comment"));
63 } else if (cs.get("name") != null) {
64 sb.append(cs.getId()).append(" - ").append(cs.get("name"));
65 } else {
66 sb.append(tr("Changeset {0}", cs.getId()));
67 }
68 setText(sb.toString());
69 setToolTipText(buildToolTipText(cs));
70 } else {
71 setText(tr("No open changeset"));
72 }
73 return this;
74 }
75}
Note: See TracBrowser for help on using the repository browser.