FileDocCategorySizeDatePackage
StringListChooser.javaAPI DocAzureus 3.0.3.45469Thu Feb 09 19:42:56 GMT 2006org.gudy.azureus2.ui.swt.components

StringListChooser

public class StringListChooser extends Object

Fields Summary
private org.eclipse.swt.widgets.Display
display
private org.eclipse.swt.widgets.Shell
shell
private org.eclipse.swt.widgets.Label
label
private org.eclipse.swt.widgets.Combo
combo
private String
result
Constructors Summary
public StringListChooser(org.eclipse.swt.widgets.Shell parentShell)

    result = null;
    
    display = parentShell.getDisplay();
    if(display == null || display.isDisposed()) return;
    display.syncExec(new Runnable() {
      public void run() {
       createShell(parentShell); 
      }
    });
  
Methods Summary
public voidaddOption(java.lang.String option)

    Utils.execSWTThread(new AERunnable() {    
      public void runSupport() {
        if(display == null || display.isDisposed()) return;
        combo.add(option);
        if(combo.getItemCount() == 1) {
          combo.setText(option);
        }
      }    
    });
  
private voidcreateShell(org.eclipse.swt.widgets.Shell parentShell)

      
    shell = ShellFactory.createShell(display,SWT.APPLICATION_MODAL | SWT.BORDER | SWT.TITLE | SWT.CLOSE);
    if(!Constants.isOSX) {
      shell.setImage(ImageRepository.getImage("azureus"));
    }
    
    GridLayout layout = new GridLayout();    
    layout.numColumns = 2;
    shell.setLayout(layout);
    GridData data;
    
    label = new Label(shell,SWT.WRAP);
    
    combo = new Combo(shell,SWT.READ_ONLY);
    
    Button ok = new Button(shell,SWT.PUSH);
    ok.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event arg0) {
       result = combo.getText();
       shell.dispose();       
      }
    });
    ok.setText(MessageText.getString("Button.ok"));
    
    Button cancel = new Button(shell,SWT.PUSH);
    cancel.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event arg0) {
    	  
    	  result = null;
       
       shell.dispose();       
      }
    });
    cancel.setText(MessageText.getString("Button.cancel"));
    
    
    shell.addListener(SWT.Dispose,new Listener() {
      public void handleEvent(Event arg0) {
      }
    });
    
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = 30;
    label.setLayoutData(data);
    
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    combo.setLayoutData(data);
        
    data = new GridData();
    data.widthHint = 80;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    data.verticalAlignment = SWT.END;
    data.horizontalAlignment = SWT.END;
    ok.setLayoutData(data);
    
    data = new GridData();
    data.grabExcessVerticalSpace = true;
    data.verticalAlignment = SWT.END;
    data.widthHint = 80;    
    cancel.setLayoutData(data);
    
    shell.setSize(300,150);
    shell.layout();
    
    Utils.centerWindowRelativeTo(shell,parentShell);
    
  
public java.lang.Stringopen()

    if(display == null || display.isDisposed()) return null;    
    Utils.execSWTThread(new AERunnable() {    
      public void 
      runSupport() 
      {
        if(display == null || display.isDisposed()) {
        	return;    
        }
    	  try{
    		  shell.open();
    	    while (!shell.isDisposed())
    	      if (!display.readAndDispatch()) display.sleep();
    		  
    	  }catch( Throwable e ){
    		  
    		  Debug.printStackTrace( e );
    	  }
      }    
    });
    
    return result;
  
public voidsetText(java.lang.String text)

  	Utils.execSWTThread(new AERunnable() {    
      public void runSupport() {
        if(display == null || display.isDisposed()) return;
        label.setText(text.replaceAll("&", "&&"));
      }    
    });
  
public voidsetTitle(java.lang.String title)

    Utils.execSWTThread(new AERunnable() {    
      public void runSupport() {
        if(display == null || display.isDisposed()) return;
        shell.setText(title);
      }    
    });