From 94290d46a0bb26070d58b5538a65d67f6f5a3b09 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 24 Mar 2008 09:44:23 +0000 Subject: [PATCH] * user proper table event to send a repaint request from the table model to the jtable * avoid null pointner exceptions --- .../sourceforge/filebot/ui/FileBotPanel.java | 2 +- .../ui/panel/sfv/ChecksumTableModel.java | 32 ++++++++++--------- .../filebot/ui/panel/sfv/SfvTable.java | 24 +++++++------- .../filebot/web/EpisodeListClient.java | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/FileBotPanel.java b/source/net/sourceforge/filebot/ui/FileBotPanel.java index 8d462dd5..7769913c 100644 --- a/source/net/sourceforge/filebot/ui/FileBotPanel.java +++ b/source/net/sourceforge/filebot/ui/FileBotPanel.java @@ -39,7 +39,7 @@ public class FileBotPanel extends JPanel { public static FileBotPanel forName(String name) { for (FileBotPanel panel : registry) { - if (name.equalsIgnoreCase(panel.getPanelName())) + if (panel.getPanelName().equalsIgnoreCase(name)) return panel; } diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableModel.java b/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableModel.java index 0a820d76..eb890862 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableModel.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableModel.java @@ -4,7 +4,6 @@ package net.sourceforge.filebot.ui.panel.sfv; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -12,7 +11,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.swing.event.TableModelEvent; import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableModel; import net.sourceforge.filebot.FileFormat; @@ -184,25 +185,13 @@ class ChecksumTableModel extends AbstractTableModel { return checksumMap; } - private PropertyChangeListener checksumListener = new PropertyChangeListener() { + private final PropertyChangeListener checksumListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { - propertyChangeSupport.firePropertyChange(evt); + fireTableChanged(new ChecksumTableModelEvent(ChecksumTableModel.this)); } }; - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - public static class Entry { @@ -241,4 +230,17 @@ class ChecksumTableModel extends AbstractTableModel { } } + + public static class ChecksumTableModelEvent extends TableModelEvent { + + public static final int CHECKSUM_PROGRESS = 10; + + + public ChecksumTableModelEvent(TableModel source) { + super(source); + type = CHECKSUM_PROGRESS; + } + + } + } diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java index 5aaaaa4a..1f4c3ab0 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java @@ -2,8 +2,6 @@ package net.sourceforge.filebot.ui.panel.sfv; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; import java.io.PrintStream; import java.text.SimpleDateFormat; @@ -14,10 +12,12 @@ import java.util.logging.Logger; import javax.swing.JTable; import javax.swing.ListSelectionModel; +import javax.swing.event.TableModelEvent; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import net.sourceforge.filebot.FileFormat; +import net.sourceforge.filebot.ui.panel.sfv.ChecksumTableModel.ChecksumTableModelEvent; import net.sourceforge.filebot.ui.panel.sfv.renderer.ChecksumTableCellRenderer; import net.sourceforge.filebot.ui.panel.sfv.renderer.StateIconTableCellRenderer; import net.sourceforge.filebot.ui.panel.sfv.renderer.TextTableCellRenderer; @@ -40,7 +40,6 @@ class SfvTable extends JTable implements TransferablePolicySupport, Saveable { public SfvTable() { final ChecksumTableModel model = (ChecksumTableModel) getModel(); - model.addPropertyChangeListener(repaintListener); setFillsViewportHeight(true); @@ -96,14 +95,7 @@ class SfvTable extends JTable implements TransferablePolicySupport, Saveable { ((ChecksumTableModel) getModel()).clear(); } - private PropertyChangeListener repaintListener = new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - repaint(); - } - }; - - + public TransferablePolicy getTransferablePolicy() { return transferablePolicy; } @@ -141,6 +133,16 @@ class SfvTable extends JTable implements TransferablePolicySupport, Saveable { } + @Override + public void tableChanged(TableModelEvent e) { + if (e.getType() == ChecksumTableModelEvent.CHECKSUM_PROGRESS) { + repaint(); + } else { + super.tableChanged(e); + } + } + + public void save(File file, int checksumColumnIndex) { try { PrintStream out = new PrintStream(file); diff --git a/source/net/sourceforge/filebot/web/EpisodeListClient.java b/source/net/sourceforge/filebot/web/EpisodeListClient.java index 93e39f3e..99b9b0b9 100644 --- a/source/net/sourceforge/filebot/web/EpisodeListClient.java +++ b/source/net/sourceforge/filebot/web/EpisodeListClient.java @@ -28,7 +28,7 @@ public abstract class EpisodeListClient { public static EpisodeListClient forName(String name) { for (EpisodeListClient client : registry) { - if (name.equalsIgnoreCase(client.getName())) + if (client.getName().equalsIgnoreCase(name)) return client; }