* little refactoring of the cellrenderer that highlights crc32 patterns, made it more reusable
This commit is contained in:
parent
c871942f57
commit
4bbb189df6
|
@ -9,17 +9,29 @@ import javax.swing.table.DefaultTableCellRenderer;
|
|||
|
||||
|
||||
/**
|
||||
* DefaultTableCellRenderer that will highlight CRC32 patterns.
|
||||
* DefaultTableCellRenderer with highlighting of text patterns.
|
||||
*/
|
||||
class FileNameTableCellRenderer extends DefaultTableCellRenderer {
|
||||
class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
private final String pattern;
|
||||
private final String cssColor;
|
||||
private final String cssFontSize;
|
||||
|
||||
|
||||
public HighlightPatternCellRenderer(String pattern, String cssColor, String cssFontSize) {
|
||||
this.pattern = pattern;
|
||||
this.cssColor = cssColor;
|
||||
this.cssFontSize = cssFontSize;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
||||
|
||||
// highlight CRC32 checksum patterns by using a smaller font-size and changing the font-color to a dark green
|
||||
// do not change the font-color if cell is selected, because that would look ugly (imagine green text on blue background ...)
|
||||
String htmlText = value.toString().replaceAll("\\[(\\p{XDigit}{8})\\]", "[<span style='font-size: smaller;" + (!isSelected ? "color: #009900;" : "") + "'>$1</span>]");
|
||||
String htmlText = value.toString().replaceAll(pattern, "[<span style='font-size: " + cssFontSize + ";" + (!isSelected ? "color: " + cssColor + ";" : "") + "'>$1</span>]");
|
||||
|
||||
// use no-break, because we really don't want line-wrapping in our table cells
|
||||
setText("<html><nobr>" + htmlText + "</nobr></html>");
|
|
@ -44,7 +44,8 @@ class SfvTable extends JTable {
|
|||
|
||||
setUI(new DragDropRowTableUI());
|
||||
|
||||
setDefaultRenderer(String.class, new FileNameTableCellRenderer());
|
||||
// highlight CRC32 patterns in filenames in green and with smaller font-size
|
||||
setDefaultRenderer(String.class, new HighlightPatternCellRenderer("\\[(\\p{XDigit}{8})\\]", "#009900", "smaller"));
|
||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue