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

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

fix #21427 - further simplify UploadDialog (patch by marcello, modified)

  • The dialog was simplified by combining the function of two radiobuttons and one combobox into one combobox.
  • When an open changeset was selected on tab 2, existing tags on the open changeset could overwrite the data the user entered on tab 1. The user might spot this by looking closely at the tag table on tab 2, but then he may not. This non-obvious behaviour was removed.
  • The exception thrown when closing an already closed changeset was fixed.
  • More cosmetic changes to the dialog.
  • Maybe also a solution to #19319, #21387 (added revalidate()).
  • Property svn:eol-style set to native
File size: 3.1 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.time.Instant;
8import java.time.format.FormatStyle;
9
10import javax.swing.ImageIcon;
11import javax.swing.JLabel;
12import javax.swing.JList;
13import javax.swing.ListCellRenderer;
14import javax.swing.UIManager;
15
16import org.openstreetmap.josm.data.osm.Changeset;
17import org.openstreetmap.josm.tools.ImageProvider;
18import org.openstreetmap.josm.tools.Utils;
19import org.openstreetmap.josm.tools.date.DateUtils;
20
21/**
22 * A {@link ListCellRenderer} for the list of changesets in the upload dialog.
23 *
24 * @since 2115
25 */
26public class ChangesetCellRenderer extends JLabel implements ListCellRenderer<Changeset> {
27 private final ImageIcon icon;
28
29 /**
30 * Constructs a new {@code ChangesetCellRenderer}.
31 */
32 public ChangesetCellRenderer() {
33 icon = ImageProvider.get("data", "changeset");
34 setOpaque(true);
35 }
36
37 protected String buildToolTipText(Changeset cs) {
38 StringBuilder sb = new StringBuilder(64);
39 sb.append("<html><strong>").append(tr("Changeset id:")).append("</strong>").append(cs.getId()).append("<br>");
40 Instant createdDate = cs.getCreatedAt();
41 if (createdDate != null) {
42 sb.append("<strong>").append(tr("Created at:")).append("</strong>").append(
43 DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(createdDate)).append("<br>");
44 }
45 String comment = cs.getComment();
46 if (!comment.isEmpty()) {
47 sb.append("<strong>").append(tr("Changeset comment:")).append("</strong>")
48 .append(Utils.escapeReservedCharactersHTML(comment)).append("<br>");
49 }
50 return sb.toString();
51 }
52
53 @Override
54 public Component getListCellRendererComponent(JList<? extends Changeset> list, Changeset cs, int index, boolean isSelected,
55 boolean cellHasFocus) {
56 if (isSelected) {
57 setForeground(UIManager.getColor("List.selectionForeground"));
58 setBackground(UIManager.getColor("List.selectionBackground"));
59 } else {
60 setForeground(UIManager.getColor("List.foreground"));
61 setBackground(UIManager.getColor("List.background"));
62 }
63 if (cs != null) {
64 setIcon(icon);
65 if (cs.getId() == 0) {
66 setText("New changeset");
67 } else {
68 StringBuilder sb = new StringBuilder();
69 String comment = cs.getComment();
70 if (!comment.isEmpty()) {
71 sb.append(cs.getId()).append(" - ").append(comment);
72 } else if (cs.get("name") != null) {
73 sb.append(cs.getId()).append(" - ").append(cs.get("name"));
74 } else {
75 sb.append(tr("Changeset {0}", cs.getId()));
76 }
77 setText(sb.toString());
78 }
79 setToolTipText(buildToolTipText(cs));
80 } else {
81 setIcon(null);
82 setText("");
83 }
84 return this;
85 }
86}
Note: See TracBrowser for help on using the repository browser.