From a5e762ba4ab82f0c6ef71d853c5103f19bbf8e22 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 11 Oct 2012 08:10:20 -0400 Subject: [PATCH] Tweak canFork description --- src/com/gitblit/client/NameRenderer.java | 70 ++++++++++++++++------------------- 1 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/com/gitblit/client/NameRenderer.java b/src/com/gitblit/client/NameRenderer.java index ce04255..4cbb590 100644 --- a/src/com/gitblit/client/NameRenderer.java +++ b/src/com/gitblit/client/NameRenderer.java @@ -18,11 +18,10 @@ import java.awt.Color; import java.awt.Component; -import javax.swing.ImageIcon; +import javax.swing.JList; import javax.swing.JTable; +import javax.swing.ListCellRenderer; import javax.swing.table.DefaultTableCellRenderer; - -import com.gitblit.models.RepositoryModel; /** * Repository name cell renderer. This renderer shows the group name in a gray @@ -31,30 +30,19 @@ * @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 boolean displayIcon; - - private final ImageIcon blankIcon; - - private final ImageIcon subscribedIcon; + private final String groupSpan; public NameRenderer() { - this(false); + this(Color.gray, CORNFLOWER); } - public NameRenderer(boolean showIcon) { - this(Color.gray, new Color(0x00, 0x69, 0xD6), showIcon); - } - - private NameRenderer(Color group, Color repo, boolean showIcon) { - blankIcon = new ImageIcon(getClass().getResource("/blank.png")); - subscribedIcon = new ImageIcon(getClass().getResource("/bullet_feed.png")); - displayIcon = showIcon; + private NameRenderer(Color group, Color repo) { groupSpan = "<span style='color:" + getHexColor(group) + "'>"; setForeground(repo); } @@ -71,27 +59,33 @@ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (value instanceof RepositoryModel) { - RepositoryModel model = (RepositoryModel) value; - String name = value.toString(); - int lastSlash = name.lastIndexOf('/'); - if (!isSelected && lastSlash > -1) { - String group = name.substring(0, lastSlash + 1); - String repo = name.substring(lastSlash + 1); - setText("<html><body>" + groupSpan + group + "</span>" + repo); - } else { - this.setText(name); - } - if (displayIcon) { - if (model.subscribed) { - setIcon(subscribedIcon); - } else { - setIcon(blankIcon); - } - } + 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 { - this.setText(value.toString()); + 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) { + String group = name.substring(0, lastSlash + 1); + String repo = name.substring(lastSlash + 1); + setText("<html><body>" + groupSpan + group + "</span>" + repo); + } else { + this.setText(name); + } + } } \ No newline at end of file -- Gitblit v1.9.1