FileDocCategorySizeDatePackage
CategoryAdderWindow.javaAPI DocAzureus 3.0.3.44803Thu Feb 09 19:42:54 GMT 2006org.gudy.azureus2.ui.swt

CategoryAdderWindow

public class CategoryAdderWindow extends Object
author
Olivier

Fields Summary
private org.gudy.azureus2.core3.category.Category
newCategory
Constructors Summary
public CategoryAdderWindow(Display display)

      
    final Shell shell = org.gudy.azureus2.ui.swt.components.shell.ShellFactory.createShell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    shell.setText(MessageText.getString("CategoryAddWindow.title"));
    if(! Constants.isOSX) {
      shell.setImage(ImageRepository.getImage("azureus"));
    }
    GridLayout layout = new GridLayout();
    shell.setLayout(layout);

    Label label = new Label(shell, SWT.NONE);
    Messages.setLanguageText(label, "CategoryAddWindow.message");    
    GridData gridData = new GridData();
    gridData.widthHint = 200;
    label.setLayoutData(gridData);

    final Text category = new Text(shell, SWT.BORDER);
    gridData = new GridData();
    gridData.widthHint = 300;
    category.setLayoutData(gridData);

    Composite panel = new Composite(shell, SWT.NULL);
    final RowLayout rLayout = new RowLayout();
    rLayout.marginTop = 0;
    rLayout.marginLeft = 0;
    rLayout.marginBottom = 0;
    rLayout.marginRight = 0;
    try {
    	rLayout.fill = true;
    } catch (NoSuchFieldError e) {
    	// SWT 2.x
    }
    rLayout.spacing = ControlUtils.getButtonMargin();
    panel.setLayout(rLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = (Constants.isOSX) ? SWT.END : SWT.CENTER;
    panel.setLayoutData(gridData);

    Button ok;
    Button cancel;
    if(Constants.isOSX) {
        cancel = createAlertButton(panel, "Button.cancel");
        ok = createAlertButton(panel, "Button.ok");
    }
    else {
        ok = createAlertButton(panel, "Button.ok");
        cancel = createAlertButton(panel, "Button.cancel");
    }

    ok.addListener(SWT.Selection, new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event event) {
        try {
          if (category.getText() != "") {
           newCategory = CategoryManager.createCategory(category.getText());
          }
        	
        	shell.dispose();
        }
        catch (Exception e) {
        	Debug.printStackTrace( e );
        }
      }
    });
    cancel.addListener(SWT.Selection, new Listener() {
      /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event event) {
        shell.dispose();
      }
    });

    shell.setDefaultButton(ok);

    shell.pack();
    Utils.createURLDropTarget(shell, category);
    Utils.centreWindow(shell);
    shell.open();
    while (!shell.isDisposed())
      if (!display.readAndDispatch()) display.sleep();
  
Methods Summary
private static ButtoncreateAlertButton(Composite panel, java.lang.String localizationKey)

      final Button button = new Button(panel, SWT.PUSH);
      button.setText(MessageText.getString(localizationKey));
      final RowData rData = new RowData();
      rData.width = Math.max(
              ControlUtils.getDialogButtonMinWidth(),
              button.computeSize(SWT.DEFAULT,  SWT.DEFAULT).x
        );
      button.setLayoutData(rData);
      return button;
  
public org.gudy.azureus2.core3.category.CategorygetNewCategory()

    return newCategory;