001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.dialogs.relation; 003 004import java.awt.Color; 005 006import javax.swing.JLabel; 007import javax.swing.JTable; 008import javax.swing.UIManager; 009import javax.swing.table.TableCellRenderer; 010 011import org.openstreetmap.josm.data.osm.OsmPrimitive; 012import org.openstreetmap.josm.gui.util.GuiHelper; 013 014/** 015 * This is the {@link TableCellRenderer} used in the tables of 016 * {@link org.openstreetmap.josm.gui.conflict.pair.relation.RelationMemberMerger}. 017 * @since 1790 018 */ 019public abstract class MemberTableCellRenderer extends JLabel implements TableCellRenderer { 020 public static final Color BGCOLOR_IN_JOSM_SELECTION = new Color(235, 255, 177); 021 022 public static final Color BGCOLOR_DOUBLE_ENTRY = new Color(254, 226, 214); 023 024 /** 025 * constructor 026 */ 027 protected MemberTableCellRenderer() { 028 setIcon(null); 029 setOpaque(true); 030 } 031 032 /** 033 * reset the renderer 034 */ 035 protected void reset() { 036 setBackground(UIManager.getColor("Table.background")); 037 setForeground(UIManager.getColor("Table.foreground")); 038 setBorder(null); 039 setIcon(null); 040 setToolTipText(null); 041 } 042 043 protected void renderBackgroundForeground(MemberTableModel model, OsmPrimitive primitive, boolean isSelected) { 044 Color bgc = UIManager.getColor("Table.background"); 045 if (isSelected) { 046 bgc = UIManager.getColor("Table.selectionBackground"); 047 } else if (primitive != null && model.isInJosmSelection(primitive)) { 048 bgc = BGCOLOR_IN_JOSM_SELECTION; 049 } else if (primitive != null && model.getNumMembersWithPrimitive(primitive) > 1) { 050 bgc = BGCOLOR_DOUBLE_ENTRY; 051 } 052 GuiHelper.setBackgroundReadable(this, bgc); 053 } 054 055 /** 056 * replies the model 057 * @param table the table 058 * @return the table model 059 */ 060 protected MemberTableModel getModel(JTable table) { 061 return (MemberTableModel) table.getModel(); 062 } 063}