Added:
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/model/TorrentEvent.java
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/model/TorrentStateListener.java
Modified:
/branches/nTorrent-0.5.x/plugins/ntorrent.torrentinfo/source/ntorrent/torrentinfo/TorrentInfoInstance.java
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/TorrentTableController.java
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/TorrentTableInterface.java
=======================================
--- /dev/null
+++
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/model/TorrentEvent.java
Wed Nov 11 00:11:26 2009
@@ -0,0 +1,24 @@
+package ntorrent.torrenttable.model;
+
+public class TorrentEvent {
+ public static final int UNKNOWN = -1;
+ public static final int TORRENT_OPEN = 100;
+ public static final int TORRENT_START = 1 + TORRENT_OPEN;
+ public static final int TORRENT_STOP = 1 + TORRENT_START;
+ public static final int TORRENT_CLOSE = 1 + TORRENT_STOP;
+ public static final int TORRENT_ERASE = 1 + TORRENT_CLOSE;
+
+ protected transient Torrent source;
+ protected int oldState;
+ protected int newState;
+
+ public TorrentEvent(Torrent source, int oldState, int newState) {
+ this.source = source;
+ this.oldState = oldState;
+ this.newState = newState;
+ }
+
+ public Torrent getSource() {
+ return this.source;
+ }
+}
=======================================
--- /dev/null
+++
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/model/TorrentStateListener.java
Wed Nov 11 00:11:26 2009
@@ -0,0 +1,5 @@
+package ntorrent.torrenttable.model;
+
+public interface TorrentStateListener {
+ public void torrentStateChanged(TorrentEvent event);
+}
=======================================
---
/branches/nTorrent-0.5.x/plugins/ntorrent.torrentinfo/source/ntorrent/torrentinfo/TorrentInfoInstance.java
Tue Oct 27 19:55:43 2009
+++
/branches/nTorrent-0.5.x/plugins/ntorrent.torrentinfo/source/ntorrent/torrentinfo/TorrentInfoInstance.java
Wed Nov 11 00:11:26 2009
@@ -36,13 +36,15 @@
import ntorrent.session.SessionInstance;
import ntorrent.torrenttable.TorrentTableInterface;
import ntorrent.torrenttable.model.Torrent;
+import ntorrent.torrenttable.model.TorrentEvent;
import ntorrent.torrenttable.model.TorrentSelectionListener;
+import ntorrent.torrenttable.model.TorrentStateListener;
/**
* @author Kim Eik
*
*/
-public class TorrentInfoInstance implements
SessionInstance,TorrentSelectionListener {
+public class TorrentInfoInstance implements
SessionInstance,TorrentSelectionListener, TorrentStateListener {
private final JTabbedPane tab;
private final JTextPane textPane = new JTextPane();
private final JScrollPane scrollpane = new JScrollPane(textPane);
@@ -88,51 +90,60 @@
//add this as a torrent selection listener
tc.addTorrentSelectionListener(this);
+
+ tc.addTorrentStateListener(this);
}
public void stop() {
started = false;
tc.removeTorrentSelectionListener(this);
+ tc.removeTorrentStateListener(this);
tab.removeTabAt(tab.indexOfComponent(scrollpane));
}
public synchronized void torrentsSelected(Torrent[] tor) {
//NO LONGER THREAD SAFE!
+ if (tor.length == 1) {
+ refreshState(tor[0]);
+ } else {
+ textPane.setText("");
+ }
+ }
+
+ protected void refreshState(Torrent torrent) {
textPane.setText("");
- if(tor.length == 1){
- String hash = tor[0].getHash();
-
- insertText(ResourcePool.getString("name", bundle, this)+":\n", BOLD);
- insertText("["+(d.is_open(hash) == 1 ?
- ResourcePool.getString("open", bundle, this) :
- ResourcePool.getString("closed", bundle, this))
- +"] - "+d.get_name(hash),null);
- insertText("\n\n"+ResourcePool.getString("hash", bundle, this)+":\n",
BOLD);
- insertText(hash, null);
- insertText("\n\n"+ResourcePool.getString("directory", bundle,
this)+":\n", BOLD);
- insertText(d.get_directory(hash), null);
- insertText("\n\n"+ResourcePool.getString("date-created", bundle,
this)+":\n", BOLD);
- insertText(new Date(d.get_creation_date(hash)*1000).toString(), null);
-
- String tiedToFile = d.get_tied_to_file(hash);
- if(tiedToFile.length() > 0){
- insertText("\n\n"+ResourcePool.getString("tied", bundle, this)+":\n",
BOLD);
- insertText(tiedToFile, null);
- }
-
- //add target free diskspace
- if (d.is_open(hash) > 0) {
- insertText("\n\n"+ResourcePool.getString("freediskspace", bundle,
this)+":\n", BOLD);
- long diskspace = d.get_free_diskspace(hash);
- NumberFormat formatter =
NumberFormat.getInstance(ResourcePool.getLocale());
- if (diskspace < 1024*1024) {
- insertText("" + formatter.format(diskspace / 1024) + "KB", null);
- } else {
- insertText("" + formatter.format(diskspace / 1024 / 1024)
- + "MB", null);
- }
- }
-
+
+ String hash = torrent.getHash();
+
+ insertText(ResourcePool.getString("name", bundle, this)+":\n", BOLD);
+ insertText("["+(d.is_open(hash) == 1 ?
+ ResourcePool.getString("open", bundle, this) :
+ ResourcePool.getString("closed", bundle, this))
+ +"] - "+d.get_name(hash),null);
+ insertText("\n\n"+ResourcePool.getString("hash", bundle, this)+":\n",
BOLD);
+ insertText(hash, null);
+ insertText("\n\n"+ResourcePool.getString("directory", bundle,
this)+":\n", BOLD);
+ insertText(d.get_directory(hash), null);
+ insertText("\n\n"+ResourcePool.getString("date-created", bundle,
this)+":\n", BOLD);
+ insertText(new Date(d.get_creation_date(hash)*1000).toString(), null);
+
+ String tiedToFile = d.get_tied_to_file(hash);
+ if(tiedToFile.length() > 0){
+ insertText("\n\n"+ResourcePool.getString("tied", bundle, this)+":\n",
BOLD);
+ insertText(tiedToFile, null);
+ }
+
+ //add target free diskspace
+ if (d.is_open(hash) > 0) {
+ insertText("\n\n"+ResourcePool.getString("freediskspace", bundle,
this)+":\n", BOLD);
+ long diskspace = d.get_free_diskspace(hash);
+ NumberFormat formatter =
NumberFormat.getInstance(ResourcePool.getLocale());
+ if (diskspace < 1024*1024) {
+ insertText("" + formatter.format(diskspace / 1024) + "KB", null);
+ } else {
+ insertText("" + formatter.format(diskspace / 1024 / 1024)
+ + "MB", null);
+ }
}
}
@@ -143,6 +154,13 @@
} catch (BadLocationException e) {
e.printStackTrace();
}
+ }
+
+ @Override
+ public void torrentStateChanged(TorrentEvent event) {
+ if (event.getSource() != null) {
+ refreshState(event.getSource());
+ }
}
}
=======================================
---
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/TorrentTableController.java
Wed Oct 21 21:55:15 2009
+++
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/TorrentTableController.java
Wed Nov 11 00:11:26 2009
@@ -32,7 +32,9 @@
import ntorrent.io.rtorrent.Download;
import ntorrent.io.xmlrpc.XmlRpcConnection;
import ntorrent.torrenttable.model.Torrent;
+import ntorrent.torrenttable.model.TorrentEvent;
import ntorrent.torrenttable.model.TorrentSelectionListener;
+import ntorrent.torrenttable.model.TorrentStateListener;
import ntorrent.torrenttable.model.TorrentTableModel;
import ntorrent.torrenttable.view.TorrentTable;
import ntorrent.torrenttable.view.TorrentTableJPopupMenu;
@@ -50,6 +52,7 @@
private final Vector<String> download_variable = new Vector<String>();
private final Vector<TorrentSelectionListener > torrentSelectionListeners
= new Vector<TorrentSelectionListener>();
+ private final Vector<TorrentStateListener> torrentStateListeners = new
Vector<TorrentStateListener>();
private SelectionValueInterface selectionMethod = null;
private boolean pause = false;
@@ -225,6 +228,12 @@
download_variable.setElementAt(view, 0);
controllerThread.interrupt();
}
+
+ protected void processEvent(TorrentEvent event) {
+ for (TorrentStateListener listener : torrentStateListeners) {
+ listener.torrentStateChanged(event);
+ }
+ }
public void torrentActionPerformed(final Torrent[] tor, final String
command) {
//invoking the commands asynchronously so the gui won't be blocked
@@ -237,25 +246,36 @@
String hash = t.getHash();
if(command.equals(mitems[0])){
//open
- if(!t.isStarted())
+ if(!t.isStarted()) {
d.open(hash);
+ processEvent(new TorrentEvent(t, TorrentEvent.UNKNOWN,
TorrentEvent.TORRENT_OPEN));
+ }
}else if(command.equals(mitems[1])){
//start
- if(!t.isStarted())
+ if(!t.isStarted()) {
d.start(hash);
+ processEvent(new TorrentEvent(t, TorrentEvent.UNKNOWN,
TorrentEvent.TORRENT_START));
+ }
}else if(command.equals(mitems[3]) ||
command.equals(mitems[4])){
boolean close = command.equals(mitems[4]);
//stop
- if(t.isStarted())
+ if(t.isStarted()) {
d.stop(hash);
+ processEvent(new TorrentEvent(t, TorrentEvent.TORRENT_START,
TorrentEvent.TORRENT_STOP));
+ }
//stop and close
- if(close);
+ if(close) {
d.close(hash);
+ processEvent(new TorrentEvent(t, TorrentEvent.UNKNOWN,
TorrentEvent.TORRENT_CLOSE));
+ }
}else if(command.equals(mitems[6])){
//erase
- if(t.isStarted())
+ if(t.isStarted()) {
d.stop(hash);
+ processEvent(new TorrentEvent(t, TorrentEvent.TORRENT_START,
TorrentEvent.TORRENT_STOP));
+ }
d.erase(hash);
+ processEvent(new TorrentEvent(t, TorrentEvent.TORRENT_STOP,
TorrentEvent.TORRENT_ERASE));
table.getSelectionModel().clearSelection();
}else if(command.equals(mitems[7])){
//check hash
@@ -337,4 +357,19 @@
}
return tor;
}
-}
+
+ @Override
+ public void addTorrentStateListener(TorrentStateListener listener) {
+ if (!torrentStateListeners.contains(listener)) {
+ torrentStateListeners.add(listener);
+ }
+
+ }
+
+ @Override
+ public void removeTorrentStateListener(TorrentStateListener listener) {
+ if (listener != null) {
+ torrentStateListeners.remove(listener);
+ }
+ }
+}
=======================================
---
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/TorrentTableInterface.java
Sat Mar 29 17:14:39 2008
+++
/branches/nTorrent-0.5.x/plugins/ntorrent.torrenttable/source/ntorrent/torrenttable/TorrentTableInterface.java
Wed Nov 11 00:11:26 2009
@@ -24,6 +24,7 @@
import ntorrent.torrenttable.model.Torrent;
import ntorrent.torrenttable.model.TorrentSelectionListener;
+import ntorrent.torrenttable.model.TorrentStateListener;
import ntorrent.torrenttable.model.TorrentTableActionListener;
import ntorrent.torrenttable.view.TorrentTable;
import ntorrent.torrenttable.viewmenu.ViewChangeListener;
@@ -41,4 +42,6 @@
public void setSelectionMethod(SelectionValueInterface i);
public void removeTorrentSelectionListener(TorrentSelectionListener
listener);
public Torrent[] getSelectedTorrents();
-}
+ public void addTorrentStateListener(TorrentStateListener listener);
+ public void removeTorrentStateListener(TorrentStateListener listener);
+}