| 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.Component;
|
|---|
| 7 |
|
|---|
| 8 | import javax.swing.JLabel;
|
|---|
| 9 | import javax.swing.JTable;
|
|---|
| 10 | import javax.swing.UIManager;
|
|---|
| 11 | import javax.swing.table.TableCellRenderer;
|
|---|
| 12 |
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
|
|---|
| 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * The table cell renderer used in the changeset content table, except for the "name"
|
|---|
| 18 | * column in which we use a {@see OsmPrimitivRenderer}.
|
|---|
| 19 | *
|
|---|
| 20 | */
|
|---|
| 21 | public class ChangesetContentTableCellRenderer extends JLabel implements TableCellRenderer{
|
|---|
| 22 |
|
|---|
| 23 | public ChangesetContentTableCellRenderer() {
|
|---|
| 24 | setOpaque(true);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | protected void reset() {
|
|---|
| 28 | setBackground(UIManager.getColor("Table.background"));
|
|---|
| 29 | setForeground(UIManager.getColor("Table.foreground"));
|
|---|
| 30 | setFont(UIManager.getFont("Table.font"));
|
|---|
| 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(HistoryOsmPrimitive primitive) {
|
|---|
| 44 | setText(Long.toString(primitive.getId()));
|
|---|
| 45 | setToolTipText("");
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | protected void renderModificationType(ChangesetModificationType type) {
|
|---|
| 49 | switch(type) {
|
|---|
| 50 | case CREATED: setText(tr("Created")); break;
|
|---|
| 51 | case UPDATED: setText(tr("Updated")); break;
|
|---|
| 52 | case DELETED: setText(tr("Deleted")); break;
|
|---|
| 53 | }
|
|---|
| 54 | setToolTipText("");
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
|---|
| 58 | int row, int column) {
|
|---|
| 59 | if (value == null)
|
|---|
| 60 | return this;
|
|---|
| 61 | reset();
|
|---|
| 62 | renderColors(isSelected);
|
|---|
| 63 | switch(column) {
|
|---|
| 64 | case 0:
|
|---|
| 65 | ChangesetModificationType type = (ChangesetModificationType)value;
|
|---|
| 66 | renderModificationType(type);
|
|---|
| 67 | break;
|
|---|
| 68 | case 1:
|
|---|
| 69 | HistoryOsmPrimitive primitive = (HistoryOsmPrimitive)value;
|
|---|
| 70 | renderId(primitive);
|
|---|
| 71 | break;
|
|---|
| 72 | default:
|
|---|
| 73 | /* do nothing */
|
|---|
| 74 | }
|
|---|
| 75 | return this;
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|