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