⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generalview.java

📁 Azureus is a powerful, full-featured, cross-platform java BitTorrent client
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	    GC gcImage = new GC(aImage);
	    gcImage.setForeground(Colors.grey);
	    gcImage.drawRectangle(0, 0, bounds.width-1, bounds.height-1);
	    int allMin = 0;
	    int allMax = 0;
	    int total = 0;
	    String sTotal = "000"; //$NON-NLS-1$
	    if (available != null) {
	      int xMax = bounds.width - 2;
	      int yMax = bounds.height - 2;
	      if (xMax < 10 || yMax < 5)
	        return;
	
	      allMin = available.length==0?0:available[0];
	      allMax = available.length==0?0:available[0];
	      int nbPieces = available.length;
	      for (int i = 0; i < nbPieces; i++) {
	        if (available[i] < allMin)
	          allMin = available[i];
	        if (available[i] > allMax)
	          allMax = available[i];
	      }
	      int maxAboveMin = allMax - allMin;
	      if (maxAboveMin == 0) {
	        // all the same.. easy paint
	        gcImage.setBackground(Colors.blues[allMin == 0 ? Colors.BLUES_LIGHTEST : Colors.BLUES_DARKEST]);
	        gcImage.fillRectangle(1, 1, xMax, yMax);
	      } else {
	        for (int i = 0; i < nbPieces; i++) {
	          if (available[i] > allMin)
	            total++;
	        }
	        total = (total * 1000) / nbPieces;
	        sTotal = "" + total;
	        if (total < 10) sTotal = "0" + sTotal;
	        if (total < 100) sTotal = "0" + sTotal;
	  
	        for (int i = 0; i < xMax; i++) {
	          int a0 = (i * nbPieces) / xMax;
	          int a1 = ((i + 1) * nbPieces) / xMax;
	          if (a1 == a0)
	            a1++;
	          if (a1 > nbPieces)
	            a1 = nbPieces;
	          int max = 0;
	          int min = available[a0];
	          int Pi = 1000;
	          for (int j = a0; j < a1; j++) {
	            if (available[j] > max)
	              max = available[j];
	            if (available[j] < min)
	              min = available[j];
	            Pi *= available[j];
	            Pi /= (available[j] + 1);
	          }
	          int pond = Pi;
	          if (max == 0)
	            pond = 0;
	          else {
	            int PiM = 1000;
	            for (int j = a0; j < a1; j++) {
	              PiM *= (max + 1);
	              PiM /= max;
	            }
	            pond *= PiM;
	            pond /= 1000;
	            pond *= (max - min);
	            pond /= 1000;
	            pond += min;
	          }
	          int index;
	          if (pond <= 0 || allMax == 0) {
	            index = 0;
	          } else {
	            // we will always have allMin, so subtract that
	            index = (pond - allMin) * (Colors.BLUES_DARKEST - 1) / maxAboveMin + 1;
	            // just in case?
	            if (index > Colors.BLUES_DARKEST) {
	              index = Colors.BLUES_DARKEST;
	            }
	          }
	            
	          gcImage.setBackground(Colors.blues[index]);
	          gcImage.fillRectangle(i+1, 1, 1, yMax);
	        }
	      }
	    }
	    gcImage.dispose();
	    if (availabilityPercent == null || availabilityPercent.isDisposed()) {
	      gc.dispose();
	      return;
	    }
	    availabilityPercent.setText(allMin + "." + sTotal);
	    gc.drawImage(aImage, bounds.x, bounds.y);
	    gc.dispose();
  	}finally{
  		
  		this_mon.exit();
  	}
  }

  public void updatePiecesInfo(boolean bForce) {
  	try{
  		this_mon.enter();
  
	    if (display == null || display.isDisposed())
	      return;
	
	    if (piecesImage == null || piecesImage.isDisposed())
	      return;
	    
	    DiskManager	dm = manager.getDiskManager();

	    boolean valid = !bForce;
	    
        boolean[] new_pieces = new boolean[manager.getNbPieces()];
	        	
	    if ( dm != null ){
	      		      	
	      	DiskManagerPiece[]	dm_pieces = dm.getPieces();
	      	
	 		for (int i=0;i<pieces.length;i++){
	      		 	
	 			new_pieces[i] = dm_pieces[i].getDone();
	       }
	    }

	    if ( pieces == null ){
	    	
	    	valid	= false;
	    	
	    }else{
	    	
		    for (int i = 0; i < pieces.length; i++) {
		    
		    	if (pieces[i] != new_pieces[i]){
		    		
		            valid = false;
		            
		            break;
		        }
		    }
	    }

	    pieces	= new_pieces;
	    
	    if (!valid) {
	      Rectangle bounds = piecesImage.getClientArea();
	      GC gc = new GC(piecesImage);
	      if (pImage != null && !pImage.isDisposed())
	        pImage.dispose();
	      int xMax = bounds.width - 2;
	      int yMax = bounds.height - 2 - 6;
	      if (xMax < 10 || yMax < 5)
	        return;
	      pImage = new Image(display, bounds.width, bounds.height);
	      GC gcImage = new GC(pImage);
	      gcImage.setForeground(Colors.grey);
	      gcImage.drawRectangle(0, 0, bounds.width-1, bounds.height-1);
	      gcImage.drawLine(1,6,xMax,6);
	
	      int total = 0;
	      if (pieces != null && pieces.length != 0) {
	        int nbPieces = pieces.length;
	        for (int i = 0; i < nbPieces; i++) {
	          if (pieces[i])
	            total++;
	        }
	        for (int i = 0; i < xMax; i++) {
	          int a0 = (i * nbPieces) / xMax;
	          int a1 = ((i + 1) * nbPieces) / xMax;
	          if (a1 == a0)
	            a1++;
	          if (a1 > nbPieces)
	            a1 = nbPieces;
	          int nbAvailable = 0;
	          for (int j = a0; j < a1; j++) {
	            if (pieces[j]) {
	              nbAvailable++;
	            }
	            int index = (nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0);
	            gcImage.setBackground(Colors.blues[index]);
	            gcImage.fillRectangle(i+1,7,1,yMax);
	          }
	        }
	  
	        total = (total * 1000) / nbPieces;
	      }
	      
	      	// no dm -> all pieces false -> total is not correct in above code
	      	// so grab value from stats (download is in stopped state)
	      
	      if ( dm == null ){
	      	
	        total = manager.getStats().getDownloadCompleted(true);	
	      }
	      
	      // draw file % bar above
	      int limit = (xMax * total) / 1000;
	      gcImage.setBackground(Colors.colorProgressBar);
	      gcImage.fillRectangle(1,1,limit,5);
	      if (limit < xMax) {
	        gcImage.setBackground(Colors.blues[Colors.BLUES_LIGHTEST]);
	        gcImage.fillRectangle(limit+1,1,xMax-limit,5);
	      }
	      
	
	      gcImage.dispose();
	
	      if (piecesPercent != null && !piecesPercent.isDisposed())
	        piecesPercent.setText((total / 10) + "." + (total % 10) + " %"); //$NON-NLS-1$ //$NON-NLS-2$
	
	      if (pImage == null || pImage.isDisposed()) {
	        gc.dispose();
	        return;
	      }
	      gc.drawImage(pImage, bounds.x, bounds.y);
	      gc.dispose();
	    }
  	}finally{
  		
  		this_mon.exit();
  	}
  }

  public void setTime(String elapsed, String remaining) {
    timeElapsed.setText( elapsed );
    timeRemaining.setText( remaining);
  }

  public void 
  setStats(
  	String dl, String ul, 
	String dls, String uls,
	String ts, 
	String dl_speed, String ul_speed,
	String s, 
	String p,
	String hash_fails,
	String share_ratio) 
  {
    if (display == null || display.isDisposed())
      return;
    
	download.setText( dl );
	downloadSpeed.setText( dls );
	upload.setText( ul );
	uploadSpeed.setText( uls );
	totalSpeed.setText( ts );
	
	if ( !maxDLSpeed.getText().equals( dl_speed )){
		
		maxDLSpeed.setText( dl_speed );
	}
	
	if ( !maxULSpeed.getText().equals( ul_speed )){
		
		maxULSpeed.setText( ul_speed );
	}
	seeds.setText( s);
	peers.setText( p); 
	hashFails.setText( hash_fails);
	shareRatio.setText( share_ratio);     
  }

  public void setTracker( DownloadManager	_manager ){
    if (display == null || display.isDisposed())
      return;
    
    String	status 	= _manager.getTrackerStatus();
    int		time	= _manager.getTrackerTime();
     
    TRTrackerClient	trackerClient = _manager.getTrackerClient();
	
	tracker.setText( status);
		
	if ( time < 0 ){
		
		trackerUpdateIn.setText( MessageText.getString("GeneralView.label.updatein.querying"));
		
	}else{
 	    
		trackerUpdateIn.setText(  TimeFormatter.formatColon( time )); 
	}
    
    boolean	update_state;
    
    String trackerURL = null;
    
    if ( trackerClient != null ){
    	
    	URL	temp = trackerClient.getTrackerUrl();
    	
    	if ( temp != null ){
    		
    		trackerURL	= temp.toString();
    	}
    }
    
    if ( trackerURL == null ){
    	
       	TOTorrent	torrent = _manager.getTorrent();
       	
       	if( torrent != null ){
       		
       		trackerURL = torrent.getAnnounceURL().toString();
       	}
    }
    
    if ( trackerURL != null ){
    	
		trackerUrlValue.setText( trackerURL);
				
		if((trackerURL.startsWith("http://")||trackerURL.startsWith("https://"))) {
		  trackerUrlValue.setForeground(Colors.blue);
		  trackerUrlValue.setCursor(Cursors.handCursor);
		  Messages.setLanguageText(trackerUrlValue, "GeneralView.label.trackerurlopen.tooltip", true);
		} else {
		  trackerUrlValue.setForeground(null);
		  trackerUrlValue.setCursor(null);
		  Messages.setLanguageText(trackerUrlValue, null);	
		  trackerUrlValue.setToolTipText(null);
		}
   	}
    
    if ( trackerClient != null ){
    	
    	update_state = ((SystemTime.getCurrentTime()/1000 - trackerClient.getLastUpdateTime() >= TRTrackerClient.REFRESH_MINIMUM_SECS ));
    	
    }else{
    	update_state = false;
    }
    
    if ( updateButton.getEnabled() != update_state ){
    
    	updateButton.setEnabled( update_state );
    }
  }

  public void setInfos(
    final String _fileName,
	final String _encoding,
    final String _fileSize,
    final String _path,
    final String _hash,
    final int _pieceNumber,
    final String _pieceLength,
    final String _comment,
	final String _creation_date ) {
    if (display == null || display.isDisposed())
      return;
    display.asyncExec(new AERunnable(){
      public void runSupport() {
		fileName.setText(_fileName + (_encoding==null?"":(" [" + _encoding + "]")));
		fileSize.setText( _fileSize);
		saveIn.setText( _path);
		hash.setText( _hash);
		pieceNumber.setText( "" + _pieceNumber); //$NON-NLS-1$
		pieceSize.setText( _pieceLength);

		String	old_comment = comment.getText();
	
		comment.setText( _comment);
	
		if ( _comment != null && !old_comment.equals( _comment )){

			String	lc = _comment.toLowerCase();
			
			final int	http_pos = lc.indexOf( "http" );
			
			if ( http_pos != -1 ){
				
				comment.setCursor(Cursors.handCursor);
				
				comment.setForeground(Colors.blue);
				 
				comment.addMouseListener(new MouseAdapter() {
					public void 
					mouseUp(
						MouseEvent event) 
					{        
			          if(event.button == 1) {
			          	
			  	        String url = comment.getText().substring( http_pos );
			  	        
			  	        for (int i=0;i<url.length();i++){
			  	        	
			  	        	if ( Character.isWhitespace( url.charAt(i))){
			  	        		
			  	        		url = url.substring( 0, i );
			  	        		
			  	        		break;
			  	        	}
			  	        }
			  	    
			  	        Program.launch(url); 
			          }
					}
				});
			}
		}

		creation_date.setText( _creation_date );
      }
    });
  }
 

  public void parameterChanged(String parameterName) {
    graphicsUpdate = COConfigurationManager.getIntParameter("Graphics Update");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -