bOk = false;
shell = new Shell(display,SWT.APPLICATION_MODAL | SWT.TITLE | SWT.CLOSE);
shell.setText(MessageText.getString("PasswordWindow.title"));
if(! Constants.isOSX) {
shell.setImage(ImageRepository.getImage("azureus"));
}
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = true;
shell.setLayout(layout);
Label label = new Label(shell,SWT.NONE);
label.setText(MessageText.getString("PasswordWindow.passwordprotected"));
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
label.setLayoutData(gridData);
final Text password = new Text(shell,SWT.BORDER);
password.setEchoChar('*");
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
password.setLayoutData(gridData);
Button ok = new Button(shell,SWT.PUSH);
ok.setText(MessageText.getString("Button.ok"));
gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
gridData.widthHint = 70;
ok.setLayoutData(gridData);
shell.setDefaultButton(ok);
ok.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
try {
SHA1Hasher hasher = new SHA1Hasher();
byte[] passwordText = password.getText().getBytes();
byte[] encoded = hasher.calculateHash(passwordText);
byte[] correct = COConfigurationManager.getByteParameter("Password",
"".getBytes());
boolean same = true;
for (int i = 0; i < correct.length; i++) {
if (correct[i] != encoded[i])
same = false;
}
if (same) {
bOk = same;
shell.dispose();
} else {
close();
}
} catch (Exception e) {
Debug.printStackTrace(e);
}
}
});
Button cancel = new Button(shell,SWT.PUSH);
cancel.setText(MessageText.getString("Button.cancel"));
gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
gridData.widthHint = 70;
cancel.setLayoutData(gridData);
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) {
close();
}
});
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
window = null;
class_sem.releaseAllWaiters();
}
});
shell.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE) {
close();
e.doit = false;
}
}
});
shell.addListener(SWT.Close,new Listener() {
public void handleEvent(Event arg0) {
close();
}
});
shell.pack();
Utils.centreWindow(shell);
shell.open();