FileDocCategorySizeDatePackage
TorrentInfoView.javaAPI DocAzureus 3.0.3.424205Sun Aug 12 10:51:50 BST 2007org.gudy.azureus2.ui.swt.views

TorrentInfoView

public class TorrentInfoView extends AbstractIView

Fields Summary
private static final String
TEXT_PREFIX
private org.gudy.azureus2.core3.download.DownloadManager
download_manager
private org.gudy.azureus2.core3.download.DownloadManager
core_data_source
private org.gudy.azureus2.plugins.download.Download
plugin_data_source
private org.eclipse.swt.widgets.Composite
outer_panel
private org.eclipse.swt.graphics.Font
headerFont
private ExternalCell[]
cells
private ExternalRow
external_row
Constructors Summary
protected TorrentInfoView(org.gudy.azureus2.core3.download.DownloadManager _download_manager)

	
	
	
				 
	
		download_manager	= _download_manager;
		
		core_data_source = download_manager;
		
	    try{
	    	plugin_data_source = DownloadManagerImpl.getDownloadStatic(download_manager);
	        
	    }catch( Throwable e ){
	    }
	
Methods Summary
public voiddelete()

		super.delete();
		
		if ( headerFont != null ){
			
			headerFont.dispose();
		}
		
		if ( cells != null ){
			
			for (int i=0;i<cells.length;i++){
				
				ExternalCell	cell = cells[i];
				
				cell.dispose();
			}
		}
	
public org.eclipse.swt.widgets.CompositegetComposite()

		return outer_panel;
	
public java.lang.StringgetData()

		return( "GeneralView.section.info" );
	
public java.lang.StringgetFullTitle()

		return MessageText.getString("GeneralView.section.info");
	
public voidinitialize(org.eclipse.swt.widgets.Composite composite)

		ScrolledComposite sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL );
		sc.setExpandHorizontal(true);
		sc.setExpandVertical(true);
		GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
		sc.setLayoutData(gridData);	
		
		outer_panel = sc;
		
		Composite panel = new Composite(sc, SWT.NULL);
		
		sc.setContent( panel );
		
		
		
		GridLayout  layout = new GridLayout();
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		layout.numColumns = 1;
		panel.setLayout(layout);

		//int userMode = COConfigurationManager.getIntParameter("User Mode");

			// header 
		
		Composite cHeader = new Composite(panel, SWT.BORDER);
		GridLayout configLayout = new GridLayout();
		configLayout.marginHeight = 3;
		configLayout.marginWidth = 0;
		cHeader.setLayout(configLayout);
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
		cHeader.setLayoutData(gridData);
		
		Display d = panel.getDisplay();
		cHeader.setBackground(d.getSystemColor(SWT.COLOR_LIST_SELECTION));
		cHeader.setForeground(d.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
		
		Label lHeader = new Label(cHeader, SWT.NULL);
		lHeader.setBackground(d.getSystemColor(SWT.COLOR_LIST_SELECTION));
		lHeader.setForeground(d.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
		FontData[] fontData = lHeader.getFont().getFontData();
		fontData[0].setStyle(SWT.BOLD);
		int fontHeight = (int)(fontData[0].getHeight() * 1.2);
		fontData[0].setHeight(fontHeight);
		headerFont = new Font(d, fontData);
		lHeader.setFont(headerFont);
		lHeader.setText( " " + MessageText.getString( "authenticator.torrent" ) + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
		gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
		lHeader.setLayoutData(gridData);
		
		Composite gTorrentInfo = new Composite(panel, SWT.NULL);
		gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
		gTorrentInfo.setLayoutData(gridData);
		layout = new GridLayout();
		layout.numColumns = 2;
		gTorrentInfo.setLayout(layout);

			// torrent encoding
		
		
		Label label = new Label(gTorrentInfo, SWT.NULL);
		gridData = new GridData();
		label.setLayoutData( gridData );
		label.setText( MessageText.getString( TEXT_PREFIX + "torrent.encoding" ) + ": " );

		TOTorrent	torrent = download_manager.getTorrent();
		label = new Label(gTorrentInfo, SWT.NULL);
		gridData = new GridData();
		
		label.setLayoutData( gridData );
		label.setText(torrent==null?"":LocaleTorrentUtil.getCurrentTorrentEncoding( torrent ));
		
			// trackers
		
		label = new Label(gTorrentInfo, SWT.NULL);
		gridData = new GridData();
		label.setLayoutData( gridData );
		label.setText( MessageText.getString( "MyTrackerView.tracker" ) + ": " );

		String	trackers = "";
		
		if ( torrent != null ){
			
			TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
			
			TOTorrentAnnounceURLSet[]	sets = group.getAnnounceURLSets();
			
			List	tracker_list = new ArrayList();
			
			URL	url = torrent.getAnnounceURL();
			
			tracker_list.add( url.getHost() + (url.getPort()==-1?"":(":"+url.getPort())));
				
			for (int i=0;i<sets.length;i++){
										
				TOTorrentAnnounceURLSet	set = sets[i];
				
				URL[]	urls = set.getAnnounceURLs();
				
				for (int j=0;j<urls.length;j++){
				
					url = urls[j];
					
					String	str = url.getHost() + (url.getPort()==-1?"":(":"+url.getPort()));
					
					if ( !tracker_list.contains(str )){
						
						tracker_list.add(str);
					}
				}
			}
				
			TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
			
			URL	active_url = null;
			
			if ( announcer != null ){
				
				active_url = announcer.getTrackerUrl();
				
			}else{
				
				TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
				
				if ( scrape != null ){
					
					active_url = scrape.getURL();
				}
			}
			
			if ( active_url == null ){
				
				active_url = torrent.getAnnounceURL();
			}
			
			trackers = active_url.getHost() + (active_url.getPort()==-1?"":(":"+active_url.getPort()));
		
			tracker_list.remove( trackers );
			
			if ( tracker_list.size() > 0 ){
				
				trackers += " (";
				
				for (int i=0;i<tracker_list.size();i++){
					
					trackers += (i==0?"":", ") + tracker_list.get(i);
				}
				
				trackers += ")";
			}
		}
		
		label = new Label(gTorrentInfo, SWT.NULL);
		gridData = new GridData();
		label.setLayoutData( gridData );
		label.setText( trackers );

		
			// columns
				 
		Group gColumns = new Group(panel, SWT.NULL);
		Messages.setLanguageText(gColumns, TEXT_PREFIX + "columns" );
		gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
		gColumns.setLayoutData(gridData);
		layout = new GridLayout();
		layout.numColumns = 4;
		gColumns.setLayout(layout);
		
		Map	usable_cols = new HashMap();
		
		TableColumnManager col_man = TableColumnManager.getInstance();
		
		TableColumnCore[][] cols_sets = {
				col_man.getAllTableColumnCoreAsArray( TableManager.TABLE_MYTORRENTS_INCOMPLETE ),
				col_man.getAllTableColumnCoreAsArray( TableManager.TABLE_MYTORRENTS_COMPLETE ),
		};
				
		for (int i=0;i<cols_sets.length;i++){
			
			int	position_base 			= i==0?0:1000;
			int position_invisible_base	= i==0?10000:20000;

			TableColumnCore[]	cols = cols_sets[i];
			
			for (int j=0;j<cols.length;j++){
				
				TableColumnCore	col = cols[j];
			
				if ( usable_cols.containsKey( col.getClass())){
					
					continue;
				}
				
				ExternalCell	ext_cell = null;
				
				int	position = col.getPosition();
				
				if ( position == -1 ){
					
					position = position_invisible_base++;
					
				}else{
					position = position_base + position;
				}
								
				List	refresh_listeners = col.getCellRefreshListeners();
				
				if ( refresh_listeners.size() > 0 ){
				
					TableCellRefreshListener tcrl	= (TableCellRefreshListener)refresh_listeners.get(0);
										
					ext_cell = new ExternalCell( col, tcrl, position );
					
				}else{
										
					List	add_listeners = col.getCellAddedListeners();

					if ( add_listeners.size() > 0 ){
						
						TableCellAddedListener tcal = (TableCellAddedListener)add_listeners.get(0);
						
							// see if we can prod the cell into identifying its refresh listener
						
						ext_cell =  new ExternalCell( col, null, position );
						
						try{
							tcal.cellAdded( ext_cell );
							
							List	l = ext_cell.getRefreshListeners();
							
							if ( l.size() > 0 ){
								
								TableCellRefreshListener tcrl = (TableCellRefreshListener)l.get(0);
								
								ext_cell.setTarget( tcrl );
								
							}else{
								
								// System.out.println( "not usable (add->no listener) col: " + col.getName());
		
								ext_cell.dispose();
								
								ext_cell = null;
							}
						}catch(	Throwable e ){
								
							ext_cell.dispose();
							
							ext_cell = null;
							
							// System.out.println( "not usable (add) col: " + col.getName() + " - " + e.getMessage());
						}
					}else{
						
						// System.out.println( "not usable col: " + col.getName() + " - no listeners" );

					}
				}

				if ( ext_cell != null ){
						
					try{
						ext_cell.refresh();
						
						usable_cols.put( col.getClass(), ext_cell );
						
						// System.out.println( "usable col:" + col.getName());
						
					}catch( Throwable e ){
						
						ext_cell.dispose();
						
						// System.out.println( "not usable (refresh) col: " + col.getName() + " - " + e.getMessage());
					}
				}
			}
		}
		
		Collection values = usable_cols.values();
		
		cells = new ExternalCell[values.size()];
		
		values.toArray( cells );
		
		Arrays.sort( 
				cells,
				new Comparator()
				{
					public int
					compare(
						Object	o1,
						Object	o2 )
					{
						ExternalCell	c1 = (ExternalCell)o1;
						ExternalCell	c2 = (ExternalCell)o2;
						
						return( c1.getPosition() - c2.getPosition());
					}
				});
						
		for (int i=0;i<cells.length;i++){
			
			ExternalCell	cell = cells[i];
			
			label = new Label(gColumns, SWT.NULL);
			gridData = new GridData();
			if ( i%2 == 1 ){
				gridData.horizontalIndent = 16;
			}
			label.setLayoutData( gridData );
			label.setText( cell.getName() + ": " );

			label = new Label(gColumns, SWT.NULL);
			cell.setLabel( label );
			gridData = new GridData();
			gridData = new GridData( GridData.FILL_HORIZONTAL);
			
			label.setLayoutData( gridData );
		}
		
		refresh();
		
		sc.setMinSize( panel.computeSize( SWT.DEFAULT, SWT.DEFAULT ));
	
public voidrefresh()

		if ( cells != null ){
			
			for (int i=0;i<cells.length;i++){
				
				ExternalCell	cell = cells[i];
				try {cell.refresh();}
				catch (Exception e) {Debug.printStackTrace(e, "Error refreshing cell: " + cells[i].getName());}
			}
		}