mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-22 15:58:52 -05:00
* highlight embedded checksum in bold red on warning and error
This commit is contained in:
parent
051cf3362b
commit
c5f499b47f
@ -4,6 +4,8 @@ package net.sourceforge.filebot.ui.panel.sfv;
|
||||
|
||||
import static net.sourceforge.filebot.FileBotUtilities.EMBEDDED_CHECKSUM_PATTERN;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
@ -27,6 +29,9 @@ class ChecksumTable extends JTable {
|
||||
setDragEnabled(true);
|
||||
setUI(new DragDropRowTableUI());
|
||||
|
||||
// force white background (e.g. gtk-laf default table background is gray)
|
||||
setBackground(Color.WHITE);
|
||||
|
||||
// highlight CRC32 patterns in filenames in green and with smaller font-size
|
||||
setDefaultRenderer(String.class, new HighlightPatternCellRenderer(EMBEDDED_CHECKSUM_PATTERN));
|
||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconCellRenderer());
|
||||
|
@ -3,12 +3,15 @@ package net.sourceforge.filebot.ui.panel.sfv;
|
||||
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.EnumSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import net.sourceforge.filebot.ui.panel.sfv.ChecksumRow.State;
|
||||
|
||||
|
||||
/**
|
||||
* DefaultTableCellRenderer with highlighting of text patterns.
|
||||
@ -26,10 +29,11 @@ class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
||||
|
||||
// check for error or warning
|
||||
boolean isError = (EnumSet.of(State.ERROR, State.WARNING).contains(table.getValueAt(row, 0)));
|
||||
|
||||
boolean isWarning = (table.getValueAt(row, 0) == ChecksumRow.State.WARNING);
|
||||
|
||||
// highlight CRC32 checksum patterns by using a smaller font-size and changing the font-color to a dark green
|
||||
// highlight 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 ...)
|
||||
Matcher matcher = pattern.matcher(value.toString());
|
||||
|
||||
@ -37,7 +41,7 @@ class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
StringBuffer htmlText = new StringBuffer("<html><nobr>");
|
||||
|
||||
while (matcher.find()) {
|
||||
matcher.appendReplacement(htmlText, createReplacement(isSelected ? null : isWarning ? "#FF8C00" : "#009900", "smaller"));
|
||||
matcher.appendReplacement(htmlText, createReplacement(isSelected ? null : (isError ? "red" : "#009900"), "smaller", isError ? "bold" : null));
|
||||
}
|
||||
|
||||
matcher.appendTail(htmlText);
|
||||
@ -50,7 +54,7 @@ class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
}
|
||||
|
||||
|
||||
protected String createReplacement(String cssColor, String cssFontSize) {
|
||||
protected String createReplacement(String cssColor, String cssFontSize, String cssFontWeight) {
|
||||
// build replacement string like
|
||||
// e.g. <span style='font-size: smaller; color: #009900;'>$0</span>
|
||||
StringBuilder replacement = new StringBuilder(60);
|
||||
@ -65,6 +69,10 @@ class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
replacement.append("font-size:").append(cssFontSize).append(';');
|
||||
}
|
||||
|
||||
if (cssFontWeight != null) {
|
||||
replacement.append("font-weight:").append(cssFontWeight).append(';');
|
||||
}
|
||||
|
||||
return replacement.append("'>$0</span>").toString();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user