package graphmatcher.test;
import graphmatcher.matcher.MatchingResult;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class TesterTableCellRenderer implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (value == null) {
return new JLabel();
}
if (value instanceof String) {
String graphName = (String) value;
return new JLabel(graphName);
}
MatchingResult matchingResult = (MatchingResult) value;
String matchedGraphName = matchingResult.getTemplate().toString();
JLabel result = new JLabel(matchedGraphName);
result.setToolTipText("Abstand: " + (1 - matchingResult.getQuality()));
if (column > 0 && matchedGraphName != null) {
result.setOpaque(true);
String graphName = (String) table.getModel().getValueAt(row, 0);
Color color;
if (graphName.substring(0, 4).equals(matchedGraphName.substring(0, 4))) {
if (isSelected) {
color = new Color(50, 200, 50);
} else {
color = Color.GREEN;
}
} else {
if (isSelected) {
color = new Color(200, 50, 50);
} else {
color = Color.RED;
}
}
result.setBackground(color);
}
return result;
}
}