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

Last change on this file since 4932 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • 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.SimpleDateFormat;
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 {@see 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 SimpleDateFormat df =new SimpleDateFormat();
36 sb.append("<strong>").append(tr("Created at:")).append("</strong>").append(df.format(cs.getCreatedAt())).append("<br>");
37 }
38 if (cs.get("comment") != null) {
39 sb.append("<strong>").append(tr("Changeset comment:")).append("</strong>").append(cs.get("comment")).append("<br>");
40 }
41 return sb.toString();
42 }
43
44 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
45 boolean cellHasFocus) {
46 Changeset cs = (Changeset)value;
47 if (isSelected) {
48 setForeground(UIManager.getColor("List.selectionForeground"));
49 setBackground(UIManager.getColor("List.selectionBackground"));
50 } else {
51 setForeground(UIManager.getColor("List.foreground"));
52 setBackground(UIManager.getColor("List.background"));
53 }
54 if (cs != null) {
55 setIcon(icon);
56 StringBuffer sb = new StringBuffer();
57 if (cs.get("comment") != null) {
58 sb.append(cs.getId()).append(" - ").append(cs.get("comment"));
59 } else if (cs.get("name") != null) {
60 sb.append(cs.getId()).append(" - ").append(cs.get("name"));
61 } else {
62 sb.append(tr("Changeset {0}", cs.getId()));
63 }
64 setText(sb.toString());
65 setToolTipText(buildToolTipText(cs));
66 } else {
67 setText(tr("No open changeset"));
68 }
69 return this;
70 }
71}
Note: See TracBrowser for help on using the repository browser.