source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheTableCellRenderer.java@ 6087

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

see #8902 - string.equals("") => string.isEmpty() (patch by shinigami)

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.changeset;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trc;
6
7import java.awt.Component;
8import java.awt.Font;
9import java.text.DateFormat;
10import java.util.Date;
11
12import javax.swing.JLabel;
13import javax.swing.JTable;
14import javax.swing.UIManager;
15import javax.swing.table.TableCellRenderer;
16
17import org.openstreetmap.josm.data.osm.Changeset;
18import org.openstreetmap.josm.data.osm.User;
19
20public 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().isEmpty()) {
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().isEmpty()) {
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(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(d));
86 }
87 setToolTipText("");
88 }
89
90 @Override
91 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
92 int row, int column) {
93 if (value == null)
94 return this;
95 reset();
96 renderColors(isSelected);
97 Changeset cs = (Changeset)value;
98 switch(column) {
99 case 0: /* id */ renderId(cs); break;
100 case 1: /* upload comment */ renderUploadComment(cs); break;
101 case 2: /* open/closed */ renderOpen(cs); break;
102 case 3: /* user */ renderUser(cs); break;
103 case 4: /* created at */ renderDate(cs.getCreatedAt()); break;
104 case 5: /* closed at */ renderDate(cs.getClosedAt()); break;
105 }
106 return this;
107 }
108}
Note: See TracBrowser for help on using the repository browser.