mirror of
https://github.com/mitb-archive/filebot
synced 2025-01-08 12:28:04 -05:00
* little refactoring of the cellrenderer that highlights crc32 patterns, made it more reusable
This commit is contained in:
parent
c871942f57
commit
4bbb189df6
@ -9,9 +9,21 @@ 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
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||||
@ -19,7 +31,7 @@ class FileNameTableCellRenderer extends DefaultTableCellRenderer {
|
|||||||
|
|
||||||
// highlight CRC32 checksum patterns by using a smaller font-size and changing the font-color to a dark green
|
// 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 ...)
|
// 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
|
// use no-break, because we really don't want line-wrapping in our table cells
|
||||||
setText("<html><nobr>" + htmlText + "</nobr></html>");
|
setText("<html><nobr>" + htmlText + "</nobr></html>");
|
@ -44,7 +44,8 @@ class SfvTable extends JTable {
|
|||||||
|
|
||||||
setUI(new DragDropRowTableUI());
|
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(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||||
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user