View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.table;
21  
22  import javax.swing.SwingUtilities;
23  
24  import org.xnap.event.StateEvent;
25  import org.xnap.event.StateListener;
26  import org.xnap.transfer.AbstractTransferManager;
27  import org.xnap.transfer.Transfer;
28  import org.xnap.transfer.TransferContainer;
29  
30  /***
31   * The model for the upload and download table.
32   *
33   * @see xnap.gui.TransferPanel
34   */
35  public class FilteredTransferTableModel extends TransferTableModel
36      implements StateListener {
37      
38      //--- Constant(s) ---
39  
40      //--- Data field(s) ---
41  
42      //--- Constructor(s) ---
43  
44      public FilteredTransferTableModel(AbstractTransferManager queue)
45  	{
46  		super(queue, false);
47      }
48  
49      //--- Method(s) ---
50  
51  	public void add(Transfer t)
52  	{
53  		t.addStateListener(this);
54  		if (t instanceof TransferContainer) {
55  			FilteredTransferContainerTreeTableNode node 
56  				= new FilteredTransferContainerTreeTableNode(this, t);
57  			add(node);
58  			node.addExistingChildren();
59  		}
60  		else {
61  			add(new TransferTreeTableNode(this, t));
62  		}
63  	}
64  
65  	public void remove(Transfer t)
66  	{
67  		t.removeStateListener(this);
68  		super.remove(t);
69  	}
70  
71  	/***
72  	 *  @see xnap.event.StateListener#stateChanged(xnap.event.StateEvent)
73  	 */
74  	public void stateChanged(StateEvent event) 
75  	{
76  		final Transfer t = (Transfer)event.getSource();
77  		if (t.isDone()) {
78  			Runnable runner = new Runnable() 
79  				{
80  					public void run()
81  					{
82  						remove(t);
83  					}
84  				};
85  			SwingUtilities.invokeLater(runner);
86  		}
87  	}
88  
89  }