| | |
| | | import java.awt.Color;
|
| | | import java.awt.Component;
|
| | |
|
| | | import javax.swing.JList;
|
| | | import javax.swing.JTable;
|
| | | import javax.swing.ListCellRenderer;
|
| | | import javax.swing.table.DefaultTableCellRenderer;
|
| | |
|
| | | /**
|
| | |
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | public class NameRenderer extends DefaultTableCellRenderer {
|
| | | public class NameRenderer extends DefaultTableCellRenderer implements ListCellRenderer {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | final String groupSpan;
|
| | | private static final Color CORNFLOWER = new Color(0x00, 0x69, 0xD6);
|
| | |
|
| | | private final String groupSpan;
|
| | |
|
| | | public NameRenderer() {
|
| | | this(Color.gray, new Color(0x00, 0x69, 0xD6));
|
| | | this(Color.gray, CORNFLOWER);
|
| | | }
|
| | |
|
| | | public NameRenderer(Color group, Color repo) {
|
| | | private NameRenderer(Color group, Color repo) {
|
| | | groupSpan = "<span style='color:" + getHexColor(group) + "'>";
|
| | | setForeground(repo);
|
| | | }
|
| | |
| | | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
| | | boolean hasFocus, int row, int column) {
|
| | | super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
| | | setValue(value == null ? "" : value, isSelected);
|
| | | return this;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Component getListCellRendererComponent(JList list, Object value, int index,
|
| | | boolean isSelected, boolean cellHasFocus) {
|
| | | setValue(value == null ? "" : value, isSelected);
|
| | | if (isSelected) {
|
| | | setBackground(list.getSelectionBackground());
|
| | | setForeground(list.getSelectionForeground());
|
| | | } else {
|
| | | setBackground(list.getBackground());
|
| | | setForeground(CORNFLOWER);
|
| | | }
|
| | | return this;
|
| | | }
|
| | |
|
| | | private void setValue(Object value, boolean isSelected) {
|
| | | String name = value.toString();
|
| | | int lastSlash = name.lastIndexOf('/');
|
| | | if (!isSelected && lastSlash > -1) {
|
| | |
| | | } else {
|
| | | this.setText(name);
|
| | | }
|
| | | return this;
|
| | | }
|
| | | } |