1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.changeset;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trc;
|
---|
6 |
|
---|
7 | import java.awt.Component;
|
---|
8 | import java.awt.Font;
|
---|
9 | import java.text.SimpleDateFormat;
|
---|
10 | import java.util.Date;
|
---|
11 |
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JTable;
|
---|
14 | import javax.swing.UIManager;
|
---|
15 | import javax.swing.table.TableCellRenderer;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
18 | import org.openstreetmap.josm.data.osm.User;
|
---|
19 |
|
---|
20 | public class ChangesetCacheTableCellRenderer extends JLabel implements TableCellRenderer{
|
---|
21 |
|
---|
22 | public ChangesetCacheTableCellRenderer() {
|
---|
23 | setOpaque(true);
|
---|
24 | }
|
---|
25 |
|
---|
26 | protected void reset() {
|
---|
27 | setBackground(UIManager.getColor("Table.background"));
|
---|
28 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
29 | setFont(UIManager.getFont("Table.font"));
|
---|
30 | setToolTipText("");
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected void renderColors(boolean isSelected) {
|
---|
34 | if (isSelected) {
|
---|
35 | setBackground(UIManager.getColor("Table.selectionBackground"));
|
---|
36 | setForeground(UIManager.getColor("Table.selectionForeground"));
|
---|
37 | } else {
|
---|
38 | setBackground(UIManager.getColor("Table.background"));
|
---|
39 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected void renderId(Changeset cs) {
|
---|
44 | setText(Integer.toString(cs.getId()));
|
---|
45 | setToolTipText("");
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected void renderUploadComment(Changeset cs) {
|
---|
49 | String comment = cs.get("comment");
|
---|
50 | if (comment == null || comment.trim().equals("")) {
|
---|
51 | setText(trc("changeset.upload-comment", "empty"));
|
---|
52 | setFont(UIManager.getFont("Table.font").deriveFont(Font.ITALIC));
|
---|
53 | } else {
|
---|
54 | setText(comment);
|
---|
55 | setToolTipText(comment);
|
---|
56 | setFont(UIManager.getFont("Table.font"));
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | protected void renderOpen(Changeset cs) {
|
---|
61 | if (cs.isOpen()) {
|
---|
62 | setText(trc("changeset.state", "Open"));
|
---|
63 | } else {
|
---|
64 | setText(trc("changeset.state", "Closed"));
|
---|
65 | }
|
---|
66 | setToolTipText("");
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected void renderUser(Changeset cs) {
|
---|
70 | User user = cs.getUser();
|
---|
71 | if (user == null || user.getName().trim().equals("")) {
|
---|
72 | setFont(UIManager.getFont("Table.font").deriveFont(Font.ITALIC));
|
---|
73 | setText(tr("anonymous"));
|
---|
74 | } else {
|
---|
75 | setFont(UIManager.getFont("Table.font"));
|
---|
76 | setText(user.getName());
|
---|
77 | setToolTipText(user.getName());
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected void renderDate(Date d) {
|
---|
82 | if (d == null) {
|
---|
83 | setText("");
|
---|
84 | } else {
|
---|
85 | setText(new SimpleDateFormat().format(d));
|
---|
86 | }
|
---|
87 | setToolTipText("");
|
---|
88 | }
|
---|
89 |
|
---|
90 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
91 | int row, int column) {
|
---|
92 | if (value == null)
|
---|
93 | return this;
|
---|
94 | reset();
|
---|
95 | renderColors(isSelected);
|
---|
96 | Changeset cs = (Changeset)value;
|
---|
97 | switch(column) {
|
---|
98 | case 0: /* id */ renderId(cs); break;
|
---|
99 | case 1: /* upload comment */ renderUploadComment(cs); break;
|
---|
100 | case 2: /* open/closed */ renderOpen(cs); break;
|
---|
101 | case 3: /* user */ renderUser(cs); break;
|
---|
102 | case 4: /* created at */ renderDate(cs.getCreatedAt()); break;
|
---|
103 | case 5: /* closed at */ renderDate(cs.getClosedAt()); break;
|
---|
104 | }
|
---|
105 | return this;
|
---|
106 | }
|
---|
107 | }
|
---|