MessageBoxWindowpublic class MessageBoxWindow extends Object
Fields Summary |
---|
public static final String | ICON_ERROR | public static final String | ICON_WARNING | public static final String | ICON_INFO | private Shell | shell | private org.gudy.azureus2.core3.util.AESemaphore | result_sem | private volatile int | result | private volatile boolean | result_set |
Constructors Summary |
---|
protected MessageBoxWindow(String id, int options, boolean remember_decision, boolean default_is_yes, Display display, String icon, String title, String message)
shell = new Shell(display,SWT.APPLICATION_MODAL | SWT.TITLE | SWT.CLOSE );
shell.setText( title );
if(! Constants.isOSX) {
shell.setImage(ImageRepository.getImage("azureus"));
}
GridLayout layout = new GridLayout();
layout.numColumns = 3;
shell.setLayout(layout);
// image and text
Label label = new Label(shell,SWT.NONE);
Image image = ImageRepository.getImage(icon);
if ( image != null ){
label.setImage( image );
}
// buffered label handles & in the text properly
BufferedLabel msg_label = new BufferedLabel(shell,SWT.WRAP);
msg_label.setText(message);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
msg_label.setLayoutData(gridData);
// remember decision
final Button checkBox;
if ( remember_decision ){
checkBox = new Button(shell, SWT.CHECK);
checkBox.setSelection(false);
checkBox.setText( MessageText.getString( "MessageBoxWindow.rememberdecision" ));
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
checkBox.setLayoutData(gridData);
}else{
checkBox = null;
Label pad = new Label( shell, SWT.NULL );
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
pad.setLayoutData(gridData);
}
// line
Label labelSeparator = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
labelSeparator.setLayoutData(gridData);
// buttons
label = new Label(shell,SWT.NULL);
final int yes_option = options & ( SWT.OK | SWT.YES );
Button bYes = new Button(shell,SWT.PUSH);
bYes.setText(MessageText.getString( yes_option==SWT.YES?"Button.yes":"Button.ok"));
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) {
setResult( id, yes_option, checkBox==null?false:checkBox.getSelection());
}
});
final int no_option = options & ( SWT.CANCEL | SWT.NO );
Button bNo = new Button(shell,SWT.PUSH);
bNo.setText(MessageText.getString(no_option==SWT.NO?"Button.no":"Button.cancel"));
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) {
setResult( id, no_option, checkBox==null?false:checkBox.getSelection());
}
});
shell.setDefaultButton( default_is_yes?bYes:bNo );
shell.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event e) {
if ( e.character == SWT.ESC){
setResult( id, SWT.NULL, false );
}
}
});
shell.addListener(
SWT.Close,
new Listener()
{
public void
handleEvent(
Event arg0)
{
setResult( id, SWT.NULL, false );
}
});
shell.pack ();
Utils.centreWindow( shell );
shell.open();
(default_is_yes?bYes:bNo).setFocus();
while( !shell.isDisposed()) {
if (!display.readAndDispatch()){
display.sleep();
}
}
|
Methods Summary |
---|
protected void | close()
if ( !shell.isDisposed()){
shell.dispose();
}
| protected int | getResult()
result_sem.reserve();
return( result );
| public static int | open(java.lang.String id, int options, int remember_map, boolean default_is_yes, Display display, java.lang.String icon, java.lang.String title, java.lang.String message)
int remembered = RememberedDecisionsManager.getRememberedDecision(id,
remember_map);
if ( remembered > 0 ){
return( remembered );
}
return( new MessageBoxWindow( id, options, remember_map != SWT.NULL, default_is_yes, display, icon, title, message ).getResult());
| protected void | setResult(java.lang.String id, int option, boolean remember)
if ( !result_set ){
result = option;
result_set = true;
if ( remember ){
RememberedDecisionsManager.setRemembered(id, result);
}
result_sem.release();
close();
}
|
|