FileDocCategorySizeDatePackage
Wizard.javaAPI DocAzureus 3.0.3.412559Tue May 08 19:02:34 BST 2007org.gudy.azureus2.ui.swt.wizard

Wizard

public class Wizard extends Object
author
Olivier

Fields Summary
private static final int
DEFAULT_WIDTH
List
listeners
com.aelitis.azureus.core.AzureusCore
azureus_core
Display
display
Shell
wizardWindow
Label
title
Label
currentInfo
Label
errorMessage
IWizardPanel
currentPanel
Composite
panel
org.eclipse.swt.graphics.Font
titleFont
protected Button
previous
protected Button
next
protected Button
finish
protected Button
cancel
Listener
closeCatcher
int
wizardHeight
Constructors Summary
public Wizard(com.aelitis.azureus.core.AzureusCore azureus_core, String keyTitle, boolean modal)

  
   
  
  			
  	 			
  	  
  
    this(azureus_core, modal);
    setTitleKey(keyTitle);
  
public Wizard(com.aelitis.azureus.core.AzureusCore azureus_core, String keyTitle)

		this(azureus_core, keyTitle, false);
	
public Wizard(com.aelitis.azureus.core.AzureusCore azureus_core)

		this(azureus_core, false);
	
public Wizard(com.aelitis.azureus.core.AzureusCore _azureus_core, boolean modal)

  	azureus_core	= _azureus_core;
    
  	int style = SWT.DIALOG_TRIM | SWT.RESIZE;
  	if (modal) {
  		style |= SWT.APPLICATION_MODAL;
  	}
    wizardWindow = ShellFactory.createMainShell(style);
    this.display 	= wizardWindow.getDisplay();

    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    wizardWindow.setLayout(layout);
    Utils.setShellIcon(wizardWindow);

    Composite cTitle = new Composite(wizardWindow, SWT.NULL);
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    cTitle.setBackground(white);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    cTitle.setLayoutData(gridData);
    GridLayout titleLayout = new GridLayout();
    titleLayout.numColumns = 1;
    cTitle.setLayout(titleLayout);
    title = new Label(cTitle, SWT.NULL);
    title.setBackground(white);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    title.setLayoutData(gridData);
    Font font = title.getFont();
    FontData[] data = font.getFontData();
    for(int i = 0 ; i < data.length ; i++) {
      data[i].setStyle(SWT.BOLD);
    }
    titleFont=new Font(display,data);
    title.setFont(titleFont);
    currentInfo = new Label(cTitle, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    currentInfo.setLayoutData(gridData);
    currentInfo.setBackground(white);
    errorMessage = new Label(cTitle, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    errorMessage.setLayoutData(gridData);
    errorMessage.setBackground(white);
    Color red = display.getSystemColor(SWT.COLOR_RED);
    errorMessage.setForeground(red);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    new Label(wizardWindow, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(gridData);

    panel = new Composite(wizardWindow, SWT.NULL);
    gridData = new GridData(GridData.FILL_BOTH);
    panel.setLayoutData(gridData);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    new Label(wizardWindow, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(gridData);

    Composite cButtons = new Composite(wizardWindow, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    cButtons.setLayoutData(gridData);
    GridLayout layoutButtons = new GridLayout();
    layoutButtons.numColumns = 5;
    cButtons.setLayout(layoutButtons);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    new Label(cButtons, SWT.NULL).setLayoutData(gridData);

    cancel = new Button(cButtons, SWT.PUSH);
    gridData = new GridData();
    gridData.widthHint = 90;
    gridData.horizontalAlignment = GridData.CENTER;
    cancel.setLayoutData(gridData);
    Messages.setLanguageText(cancel, "Button.cancel");
    
    previous = new Button(cButtons, SWT.PUSH);
    gridData = new GridData();
    gridData.widthHint = 90;
    gridData.horizontalAlignment = GridData.END;
    previous.setLayoutData(gridData);
    Messages.setLanguageText(previous, "wizard.previous");

    next = new Button(cButtons, SWT.PUSH);
    gridData = new GridData();
    gridData.widthHint = 90;
    gridData.horizontalAlignment = GridData.BEGINNING;
    next.setLayoutData(gridData);
    Messages.setLanguageText(next, "wizard.next");

    finish = new Button(cButtons, SWT.PUSH);
    gridData = new GridData();
    gridData.widthHint = 90;
    gridData.horizontalAlignment = GridData.CENTER;
    finish.setLayoutData(gridData);
    Messages.setLanguageText(finish, "wizard.finish");

    previous.addListener(SWT.Selection, new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event arg0) {
        clearPanel();
        currentPanel = currentPanel.getPreviousPanel();
        refresh();
      }
    });

    next.addListener(SWT.Selection, new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event arg0) {
        IWizardPanel nextPanel = currentPanel.getNextPanel();
        clearPanel();
        currentPanel = nextPanel;
        refresh();
      }
    });

    closeCatcher = new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event event) {
        event.doit = false;
      }
    };

    finish.addListener(SWT.Selection, new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
		public void handleEvent(Event arg0){
    		finishSelected();
		}
    });
    
    cancel.addListener(SWT.Selection, new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event arg0) {
        wizardWindow.dispose();
      }
    });

    wizardWindow.addDisposeListener(new DisposeListener() {
      public void widgetDisposed(DisposeEvent de) {
        onClose();
      }
    });
    
 	wizardWindow.addListener(SWT.Traverse, new Listener() {
 		
		public void handleEvent(Event e) {
			
			if ( e.character == SWT.ESC){
							
				if ( cancel.isEnabled()){
					
					wizardWindow.dispose();
				}
			}
		}
	});
 	
 	wizardHeight = wizardWindow.computeSize(DEFAULT_WIDTH,SWT.DEFAULT).y - 50;
 	wizardWindow.setSize(DEFAULT_WIDTH,400);

  
Methods Summary
public voidaddListener(WizardListener l)

  	if (wizardWindow.isDisposed() && closeCatcher != null) {
  		l.closed();
  	}
  	listeners.add(l);
  
private voidclearPanel()

    Control[] controls = panel.getChildren();
    for (int i = 0; i < controls.length; i++) {
      if (controls[i] != null && !controls[i].isDisposed())
        controls[i].dispose();
    }
    setTitle("");
    setCurrentInfo("");
  
private voidfinishSelected()

	   if ( currentPanel.isFinishSelectionOK()){      			   
		   wizardWindow.addListener(SWT.Close, closeCatcher);
		   clearPanel();
		   currentPanel = currentPanel.getFinishPanel();
		   refresh();
		   currentPanel.finish();
	   }
  
public com.aelitis.azureus.core.AzureusCoregetAzureusCore()

  	return( azureus_core );
  
public IWizardPanelgetCurrentPanel()

return
Returns the currentPanel.

    return currentPanel;
  
public DisplaygetDisplay()

    return display;
  
public java.lang.StringgetErrorMessage()

    return errorMessage.getText();
  
public CompositegetPanel()

    return panel;
  
public ShellgetWizardWindow()

    return wizardWindow;
  
private voidinsureSize()

  	//panel.pack();
  	Point p = panel.computeSize(wizardWindow.getSize().x,SWT.DEFAULT);
  	int height = p.y + wizardHeight;
  	if(height > wizardWindow.getSize().y)
  		wizardWindow.setSize(p.x,height);
  
public voidonClose()

  	if (titleFont != null && !titleFont.isDisposed()) {
  		titleFont.dispose();
  		titleFont=null;
  	}
  	
  	for (int i=0;i<listeners.size();i++){
  		
  		((WizardListener)listeners.get(i)).closed();
  	}
  
private voidrefresh()

    if (currentPanel == null){
    	
    	setDefaultButton();
    	
      	return;
    }
    
    previous.setEnabled(currentPanel.isPreviousEnabled());
    
    next.setEnabled(currentPanel.isNextEnabled());
    
    finish.setEnabled(currentPanel.isFinishEnabled());
    
	setDefaultButton();	
    currentPanel.show();
    panel.layout();
    panel.redraw();
    insureSize();
  
public voidremoveListener(WizardListener l)

  	listeners.remove(l);
  
public voidsetCurrentInfo(java.lang.String currentInfo)

    this.currentInfo.setText("\t" + currentInfo);
  
private voidsetDefaultButton()

		if (!wizardWindow.isDisposed()){
		
		 	display.asyncExec(new AERunnable() {
				public void runSupport() {
		 	
					if (!wizardWindow.isDisposed()){
					  	Button	default_button = null;
					  	
						if ( next.isEnabled()){
					    	
							default_button = next;
							
						}else if ( finish.isEnabled()){
						
							default_button = finish;
							
						}else if ( previous.isEnabled()){
							
							default_button = previous;
							
						}else if ( cancel.isEnabled()){
							
							default_button	= cancel;
						}
						
						if ( default_button != null ){
						
							wizardWindow.setDefaultButton( default_button );
						}
					}
		 	}
		});
	 }
  
public voidsetErrorMessage(java.lang.String errorMessage)

    this.errorMessage.setText(errorMessage);
  
public voidsetFinishEnabled(boolean enabled)

    this.finish.setEnabled(enabled);
	setDefaultButton();
  
public voidsetFirstPanel(IWizardPanel panel)

    this.currentPanel = panel;
    refresh();
    insureSize();
    Utils.centreWindow( wizardWindow );
    wizardWindow.open();
    
    while (!wizardWindow.isDisposed()) {
    	try {
  			if (!display.readAndDispatch()) {
  				display.sleep();
  			}
    	} catch (Exception e) {
    		Debug.out(e);
    	}
		}
  
public voidsetNextEnabled(boolean enabled)

    this.next.setEnabled(enabled);
	setDefaultButton();
  
public voidsetPreviousEnabled(boolean enabled)

    this.previous.setEnabled(enabled);
	setDefaultButton();
  
public voidsetTitle(java.lang.String title)

    this.title.setText(title);
  
public voidsetTitleAsResourceID(java.lang.String id)

  	Messages.setLanguageText(title, id);
  
public voidsetTitleKey(java.lang.String key)

    Messages.setLanguageText(wizardWindow, key);
  
public voidswitchToClose()

    if (!wizardWindow.isDisposed()) {
	    display.asyncExec(new AERunnable() {
	       public void runSupport() {
	        if (closeCatcher != null && wizardWindow != null && !wizardWindow.isDisposed()) {
	          wizardWindow.removeListener(SWT.Close, closeCatcher);
	          cancel.setText(MessageText.getString("wizard.close"));
	          cancel.setEnabled(true);
			  setDefaultButton();
	        }
	      }
	    });
    }