SimpleTextEntryWindowpublic class SimpleTextEntryWindow extends org.gudy.azureus2.ui.swt.pluginsimpl.AbstractUISWTInputReceiver
Fields Summary |
---|
private Display | display |
Constructors Summary |
---|
public SimpleTextEntryWindow(Display display)
this.display = display;
|
Methods Summary |
---|
private static Button | createAlertButton(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;
| protected void | promptForInput()
final Shell shell = org.gudy.azureus2.ui.swt.components.shell.ShellFactory.createShell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
if (this.title != null) {
shell.setText(this.title);
}
if(!Constants.isOSX) {
shell.setImage(ImageRepository.getImage("azureus"));
}
GridLayout layout = new GridLayout();
shell.setLayout(layout);
// Default width hint is 330.
int width_hint = (this.width_hint == -1) ? 330 : this.width_hint;
// Process any messages.
Label label = null;
GridData gridData = null;
for (int i=0; i<this.messages.length; i++) {
label = new Label(shell, SWT.NONE);
label.setText(this.messages[i]);
// 330 is the current default width.
gridData = new GridData();
gridData.widthHint = width_hint;
label.setLayoutData(gridData);
}
// We may, at a later date, allow more customisable behaviour w.r.t. to this.
// (e.g. "Should we wrap this, should we provide H_SCROLL capabilities" etc.)
int text_entry_flags = SWT.BORDER;
if (this.multiline_mode) {
text_entry_flags |= SWT.MULTI | SWT.V_SCROLL | SWT.WRAP;
}
else {
text_entry_flags |= SWT.SINGLE;
}
// Create Text object with pre-entered text.
final Text text_entry = new Text(shell, text_entry_flags);
if (this.preentered_text != null) {
text_entry.setText(this.preentered_text);
if (this.select_preentered_text) {
text_entry.selectAll();
}
}
// TAB will take them out of the text entry box.
text_entry.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
e.doit = true;
}
}
});
// Default behaviour - single mode results in default height of 1 line,
// multiple lines has default height of 3.
int line_height = this.line_height;
if (line_height == -1) {
line_height = (this.multiline_mode) ? 3 : 1;
}
gridData = new GridData();
gridData.widthHint = width_hint;
gridData.minimumHeight = text_entry.getLineHeight() * line_height;
gridData.heightHint = gridData.minimumHeight;
text_entry.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 = createAlertButton(panel, "Button.ok");
Button cancel = createAlertButton(panel, "Button.cancel");
ok.addListener(SWT.Selection, new Listener() {
private void showError(String text) {
String error_title = SimpleTextEntryWindow.this.title;
if (error_title == null) {error_title = "";}
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText(error_title);
mb.setMessage(text);
mb.open();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event event) {
try {
String entered_data = text_entry.getText();
if (!SimpleTextEntryWindow.this.maintain_whitespace) {
entered_data = entered_data.trim();
}
if (!SimpleTextEntryWindow.this.allow_empty_input && entered_data.length() == 0) {
showError(MessageText.getString("UI.cannot_submit_blank_text"));
return;
}
UIInputValidator validator = SimpleTextEntryWindow.this.validator;
if (validator != null) {
String validate_result = validator.validate(entered_data);
if (validate_result != null) {
showError(MessageText.getString(validate_result));
return;
}
}
SimpleTextEntryWindow.this.recordUserInput(entered_data);
}
catch (Exception e) {
Debug.printStackTrace(e);
SimpleTextEntryWindow.this.recordUserAbort();
}
shell.dispose();
}
});
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) {
SimpleTextEntryWindow.this.recordUserAbort();
shell.dispose();
}
});
shell.setDefaultButton(ok);
shell.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event e) {
if ( e.character == SWT.ESC){
SimpleTextEntryWindow.this.recordUserAbort();
shell.dispose();
}
}
});
shell.pack();
Utils.createURLDropTarget(shell, text_entry);
Utils.centreWindow(shell);
shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch()) display.sleep();
|
|