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

Last change on this file since 5704 was 5319, checked in by simon04, 12 years ago

fix #7835 - localize dates in UI

  • 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 {
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}
Note: See TracBrowser for help on using the repository browser.