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 |
|
---|
6 | import java.awt.Font;
|
---|
7 | import java.time.Instant;
|
---|
8 | import java.time.format.FormatStyle;
|
---|
9 |
|
---|
10 | import javax.swing.JComponent;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.UIManager;
|
---|
13 | import javax.swing.table.TableCellRenderer;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.data.osm.User;
|
---|
16 | import org.openstreetmap.josm.tools.Utils;
|
---|
17 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Superclass of changeset cell renderers.
|
---|
21 | * @since 7715
|
---|
22 | */
|
---|
23 | public abstract class AbstractCellRenderer extends JLabel implements TableCellRenderer {
|
---|
24 |
|
---|
25 | protected void reset(JComponent c, boolean tableFont) {
|
---|
26 | c.setBackground(UIManager.getColor("Table.background"));
|
---|
27 | c.setForeground(UIManager.getColor("Table.foreground"));
|
---|
28 | if (tableFont) {
|
---|
29 | c.setFont(UIManager.getFont("Table.font"));
|
---|
30 | }
|
---|
31 | c.setToolTipText(null);
|
---|
32 | c.setOpaque(true);
|
---|
33 | }
|
---|
34 |
|
---|
35 | protected void reset() {
|
---|
36 | reset(this, true);
|
---|
37 | }
|
---|
38 |
|
---|
39 | protected void renderColors(JComponent c, boolean isSelected) {
|
---|
40 | if (isSelected) {
|
---|
41 | c.setBackground(UIManager.getColor("Table.selectionBackground"));
|
---|
42 | c.setForeground(UIManager.getColor("Table.selectionForeground"));
|
---|
43 | } else {
|
---|
44 | c.setBackground(UIManager.getColor("Table.background"));
|
---|
45 | c.setForeground(UIManager.getColor("Table.foreground"));
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected void renderColors(boolean isSelected) {
|
---|
50 | renderColors(this, isSelected);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected void renderId(long id) {
|
---|
54 | setText(Long.toString(id));
|
---|
55 | setToolTipText(null);
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected void renderUser(User user) {
|
---|
59 | if (user == null || Utils.isStripEmpty(user.getName())) {
|
---|
60 | setFont(UIManager.getFont("Table.font").deriveFont(Font.ITALIC));
|
---|
61 | setText(tr("anonymous"));
|
---|
62 | } else {
|
---|
63 | setFont(UIManager.getFont("Table.font"));
|
---|
64 | setText(user.getName());
|
---|
65 | setToolTipText(user.getName());
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected void renderInstant(Instant d) {
|
---|
70 | if (d == null) {
|
---|
71 | setText("");
|
---|
72 | } else {
|
---|
73 | setText(DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(d));
|
---|
74 | }
|
---|
75 | setToolTipText(null);
|
---|
76 | }
|
---|
77 | }
|
---|