2009-02-15 07:20:43 -05:00
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.ui.sfv;
|
2009-02-15 07:20:43 -05:00
|
|
|
|
|
|
|
|
2009-05-17 13:22:44 -04:00
|
|
|
import static java.awt.Font.*;
|
2014-07-29 02:45:15 -04:00
|
|
|
import static net.filebot.util.ui.SwingUI.*;
|
2009-02-15 12:58:32 -05:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Component;
|
2009-08-10 07:46:24 -04:00
|
|
|
import java.io.FileNotFoundException;
|
2009-02-15 07:20:43 -05:00
|
|
|
|
|
|
|
import javax.swing.JTable;
|
|
|
|
import javax.swing.SwingWorker;
|
|
|
|
import javax.swing.SwingWorker.StateValue;
|
|
|
|
import javax.swing.table.DefaultTableCellRenderer;
|
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.filebot.util.ExceptionUtilities;
|
2009-02-15 07:20:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
public class ChecksumCellRenderer extends DefaultTableCellRenderer {
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
private final SwingWorkerCellRenderer progressRenderer = new SwingWorkerCellRenderer();
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-08-10 12:20:18 -04:00
|
|
|
private final Color verificationForeground = new Color(0x009900);
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-08-10 07:46:24 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
@Override
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
|
boolean pendingWorker = false;
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
if (value instanceof SwingWorker) {
|
|
|
|
if (((SwingWorker<?, ?>) value).getState() != StateValue.PENDING)
|
|
|
|
return progressRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
pendingWorker = true;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
// ignore focus
|
|
|
|
super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
// check row state for ERROR
|
2009-02-15 12:58:32 -05:00
|
|
|
boolean isError = (table.getValueAt(row, 0) == ChecksumRow.State.ERROR);
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 12:58:32 -05:00
|
|
|
// if row state is ERROR and if we are not selected use text color RED,
|
|
|
|
// else use default table colors
|
2009-08-10 12:20:18 -04:00
|
|
|
setForeground(isSelected ? table.getSelectionForeground() : isError ? Color.RED : isVerificationColumn(table, column) ? verificationForeground : table.getForeground());
|
2009-02-15 07:20:43 -05:00
|
|
|
setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 12:58:32 -05:00
|
|
|
// use BOLD font on ERROR
|
|
|
|
setFont(getFont().deriveFont(isError ? BOLD : PLAIN));
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
if (pendingWorker) {
|
|
|
|
setText("Pending...");
|
|
|
|
} else if (value == null && !isSelected) {
|
|
|
|
setBackground(derive(table.getGridColor(), 0.1f));
|
2009-08-10 07:46:24 -04:00
|
|
|
} else if (value instanceof FileNotFoundException) {
|
|
|
|
setText("File not found");
|
2009-02-15 07:20:43 -05:00
|
|
|
} else if (value instanceof Throwable) {
|
|
|
|
setText(ExceptionUtilities.getRootCauseMessage((Throwable) value));
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
return this;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-08-10 12:20:18 -04:00
|
|
|
|
|
|
|
private boolean isVerificationColumn(JTable table, int column) {
|
|
|
|
ChecksumTableModel model = (ChecksumTableModel) table.getModel();
|
|
|
|
int modelColumn = table.getColumnModel().getColumn(column).getModelIndex();
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-08-10 12:20:18 -04:00
|
|
|
return model.isVerificationColumn(modelColumn);
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
}
|