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();