FileDocCategorySizeDatePackage
AssociationChecker.javaAPI DocAzureus 3.0.3.45958Sun May 06 17:06:48 BST 2007org.gudy.azureus2.ui.swt.associations

AssociationChecker

public class AssociationChecker extends Object
author
parg

Fields Summary
protected org.gudy.azureus2.platform.PlatformManager
platform
protected Display
display
protected Shell
shell
Constructors Summary
protected AssociationChecker(org.gudy.azureus2.platform.PlatformManager _platform)

		platform	= _platform;
		
		display = SWTThread.getInstance().getDisplay();
							
		if ( display.isDisposed()){
								
			return;
		}
							
		Utils.execSWTThread(
				new AERunnable()
				{
					public void
					runSupport()
					{
						check();
					}
				});
	
Methods Summary
protected voidcheck()

		if (display.isDisposed())
			return;

 		shell = new Shell (display,SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 	
 		if(! Constants.isOSX) {
 		  shell.setImage(ImageRepository.getImage("azureus"));
 		}
	 	shell.setText(MessageText.getString("dialog.associations.title"));
		
	 	GridLayout layout = new GridLayout();
	 	layout.numColumns = 3;
	        
	 	shell.setLayout (layout);
    
	 	GridData gridData;
    
	 		// text
	 	
		Label user_label = new Label(shell,SWT.NULL);
		Messages.setLanguageText(user_label, "dialog.associations.prompt");
		gridData = new GridData(GridData.FILL_BOTH);
		gridData.horizontalSpan = 3;
		user_label.setLayoutData(gridData);


	    final Button checkBox = new Button(shell, SWT.CHECK);
	    checkBox.setSelection(true);
		gridData = new GridData(GridData.FILL_BOTH);
		gridData.horizontalSpan = 3;
		checkBox.setLayoutData(gridData);
		Messages.setLanguageText(checkBox, "dialog.associations.askagain"); 
		
		// line
		
		Label labelSeparator = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
		gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 3;
		labelSeparator.setLayoutData(gridData);

			// buttons
			
		new Label(shell,SWT.NULL);

		Button bYes = new Button(shell,SWT.PUSH);
	 	bYes.setText(MessageText.getString("Button.yes"));
	 	gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
	 	gridData.grabExcessHorizontalSpace = true;
	 	gridData.widthHint = 70;
	 	bYes.setLayoutData(gridData);
	 	bYes.addListener(SWT.Selection,new Listener() {
	  		public void handleEvent(Event e) {
		 		close(true, checkBox.getSelection());
	   		}
		 });
    
	 	Button bNo = new Button(shell,SWT.PUSH);
	 	bNo.setText(MessageText.getString("Button.no"));
	 	gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
	 	gridData.grabExcessHorizontalSpace = false;
	 	gridData.widthHint = 70;
	 	bNo.setLayoutData(gridData);    
	 	bNo.addListener(SWT.Selection,new Listener() {
	 		public void handleEvent(Event e) {
		 		close(false, checkBox.getSelection());
	   		}
	 	});

	 	bYes.setFocus();
		shell.setDefaultButton( bYes );
		
		shell.addListener(SWT.Traverse, new Listener() {	
			public void handleEvent(Event e) {
				if ( e.character == SWT.ESC){
					close( false, true );
				}
			}
		});

	
	 	shell.pack ();
	 	
		Utils.centreWindow( shell );

		shell.open ();
		
    while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	
public static voidcheckAssociations()

  
		try{
	
		    PlatformManager	platform  = PlatformManagerFactory.getPlatformManager();
		    
		    if ( platform.hasCapability(PlatformManagerCapabilities.RegisterFileAssociations) ){
	    	
		    	if ( COConfigurationManager.getBooleanParameter( "config.interface.checkassoc")){
		    		
		    		if ( !platform.isApplicationRegistered()){
		    		
		    			new AssociationChecker(  platform );
		    		}
		    	}
		    }
		}catch( Throwable e ){
			
			// Debug.printStackTrace( e );
		}
	
protected voidclose(boolean ok, boolean check_on_startup)

    	if ( check_on_startup != COConfigurationManager.getBooleanParameter( "config.interface.checkassoc" )){
    		
    		COConfigurationManager.setParameter( "config.interface.checkassoc",check_on_startup );
    		
    		COConfigurationManager.save();
    	}

 		if ( ok ){
 			
 			try{				
 				platform.registerApplication();
 				
 			}catch( PlatformManagerException e ){
 				
 				Debug.printStackTrace( e );
 			}
 		}
 		
 		shell.dispose();