From 4bbb189df60b511e53d5cbc3eca3d8f5321e2c35 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 14 Oct 2008 17:33:38 +0000 Subject: [PATCH] * little refactoring of the cellrenderer that highlights crc32 patterns, made it more reusable --- ....java => HighlightPatternCellRenderer.java} | 18 +++++++++++++++--- .../filebot/ui/panel/sfv/SfvTable.java | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) rename source/net/sourceforge/filebot/ui/panel/sfv/{FileNameTableCellRenderer.java => HighlightPatternCellRenderer.java} (57%) diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/FileNameTableCellRenderer.java b/source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java similarity index 57% rename from source/net/sourceforge/filebot/ui/panel/sfv/FileNameTableCellRenderer.java rename to source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java index f37b5666..b31400cb 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/FileNameTableCellRenderer.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java @@ -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})\\]", "[$1]"); + String htmlText = value.toString().replaceAll(pattern, "[$1]"); // use no-break, because we really don't want line-wrapping in our table cells setText("" + htmlText + ""); diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java index 208da7c6..dc51e1c7 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java @@ -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()); }