FileDocCategorySizeDatePackage
UpdateProgressWindow.javaAPI DocAzureus 3.0.3.48386Thu Feb 09 19:42:54 GMT 2006org.gudy.azureus2.ui.swt.update

UpdateProgressWindow

public class UpdateProgressWindow extends Object implements UpdateManagerListener
author
parg

Fields Summary
protected Display
display
protected Shell
window
protected org.eclipse.swt.custom.StyledText
text_area
protected UpdateManager
manager
protected ArrayList
current_instances
Constructors Summary
Methods Summary
protected voidaddInstance(UpdateCheckInstance instance)

		if ( !display.isDisposed()){
	
			display.asyncExec(
				new AERunnable()
				{
					public void 
					runSupport() 
					{
						if ( display.isDisposed() || window.isDisposed()){
							
							return;
						}
						
						if ( !current_instances.contains( instance )){
							
							current_instances.add( instance );
							
							log( instance, "added" );
							
							instance.addListener(
								new UpdateCheckInstanceListener()
								{
									public void
									cancelled(
										UpdateCheckInstance		instance )
									{
										log( instance, "cancelled" );
									}
									
									public void
									complete(
										UpdateCheckInstance		instance )
									{
										log( instance, "complete" );
									}
								});
							
							UpdateChecker[]	checkers = instance.getCheckers();
							
							for (int i=0;i<checkers.length;i++){
								
								final UpdateChecker	checker = checkers[i];
								
								log( checker, "added" );
								
								checker.addListener(
									new UpdateCheckerListener()
									{
										public void
										completed(
											UpdateChecker	checker )
										{
											log( checker, "completed" );
										}
											
										public void
										failed(
											UpdateChecker	checker )
										{
											log( checker, "failed" );
										}
									
										
										public void
										cancelled(
											UpdateChecker	checker )
										{
											log( checker, "cancelled" );
										}
									});
								
								checker.addProgressListener(
									new UpdateProgressListener()
									{
										public void
										reportProgress(
											String	str )
										{
											log( checker, "    " + str );
										}
									});
							}
						}
					}
				});
		}
	
public voidcheckInstanceCreated(UpdateCheckInstance instance)

		addInstance( instance );
	
protected voidlog(UpdateCheckInstance instance, java.lang.String str)

		String	name = instance.getName();
		
      	if ( MessageText.keyExists(name)){
           	
           	name = MessageText.getString( name );
        }
      	
		log( name + " - " + str );
	
protected voidlog(UpdateChecker checker, java.lang.String str)

		log( "    " + checker.getComponent().getName() + " - " + str );		
	
protected voidlog(java.lang.String str)

		try{
			if ( !display.isDisposed()){
				
				display.asyncExec(
						new AERunnable()
						{
							public void 
							runSupport() 
							{
								if ( !text_area.isDisposed()){
									
									text_area.append( str + "\n" );
								}
							}
						});
			}
		}catch( Throwable e ){
			
		}
	
public static voidshow(UpdateCheckInstance[] instances, Shell shell)

		if ( instances.length == 0){
			
			return;
		}
	
		new UpdateProgressWindow().showSupport(instances,shell);
	
protected voidshowSupport(UpdateCheckInstance[] instances, Shell shell)

	
	  
	
				
								 
	
	  	manager	= instances[0].getManager();
	  	
	  	display = shell.getDisplay();
	  	
	    window = org.gudy.azureus2.ui.swt.components.shell.ShellFactory.createShell(display,SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
	    Messages.setLanguageText(window,"updater.progress.window.title");
	    if(! Constants.isOSX) {
	      window.setImage(ImageRepository.getImage("azureus"));
	    }
	    FormLayout layout = new FormLayout();
	    try {
	      layout.spacing = 5;
	    } catch (NoSuchFieldError e) {
	      /* Ignore for Pre 3.0 SWT.. */
	    }
	    layout.marginHeight = 5;
	    layout.marginWidth = 5;
	    window.setLayout(layout);
	    FormData formData;
	    
	    	// text area
	    
	    text_area = new StyledText(window,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	       
	    text_area.setEditable(false);
	    
	    Button btnOk = new Button(window,SWT.PUSH);
	    Button btnAbort = new Button(window,SWT.PUSH);
	    
	            
	    formData = new FormData();
	    formData.left = new FormAttachment(0,0);
	    formData.right = new FormAttachment(100,0);
	    formData.top = new FormAttachment(0,0);   
	    formData.bottom = new FormAttachment(90,0);   
	    text_area.setLayoutData(formData);
	    
	    
	    	// label
	    
	    Label	info_label = new Label(window, SWT.NULL);
	    Messages.setLanguageText(info_label,"updater.progress.window.info");
	    formData = new FormData();
	    formData.top = new FormAttachment(text_area);    
	    formData.right = new FormAttachment(btnAbort);    
	    formData.left = new FormAttachment(0,0);    
	    info_label.setLayoutData( formData );    
	   
	    
	    	// abort button
	    
	    Messages.setLanguageText(btnAbort,"Button.abort");
	    formData = new FormData();
	    formData.right = new FormAttachment(btnOk);    
	    formData.bottom = new FormAttachment(100,0);    
	    formData.width = 70;
	    btnAbort.setLayoutData(formData);
	    btnAbort.addListener(
	    		SWT.Selection,
				new Listener() 
				{
				    public void 
					handleEvent(
						Event e) 
				    {
				    	manager.removeListener( UpdateProgressWindow.this  );
				    	
				    	for (int i=0;i<current_instances.size();i++){
				    		
				    		((UpdateCheckInstance)current_instances.get(i)).cancel();
				    	}
				    	
				    	window.dispose();
				   	}
				});
	    
	    	// ok button
	    
	    Messages.setLanguageText(btnOk,"Button.ok");
	    formData = new FormData();
	    formData.right = new FormAttachment(95,0);    
	    formData.bottom = new FormAttachment(100,0);    
	    formData.width = 70;
	    btnOk.setLayoutData(formData);
	    btnOk.addListener(
	    		SWT.Selection,
				new Listener() 
				{
	    			public void 
					handleEvent(
						Event e) 
	    			{
	    				manager.removeListener( UpdateProgressWindow.this  );
	    				
	    				window.dispose();
	    			}
			    });
	        
	    window.setDefaultButton( btnOk );
	    
	    window.addListener(SWT.Traverse, new Listener() {	
			public void handleEvent(Event e) {
				if ( e.character == SWT.ESC){
					
					manager.removeListener( UpdateProgressWindow.this  );
					
				    window.dispose();
				 }
			}
	    });
	    
	    manager.addListener( this );
	    
	    window.setSize(620,450);
	    window.layout();
	    
	    Utils.centreWindow( window );
	    
	    window.open();
	    
	    for (int i=0;i<instances.length;i++){
	    	
	    	addInstance( instances[i] );
	    }