Wizardpublic class Wizard extends Object
Fields Summary |
---|
private static final int | DEFAULT_WIDTH | List | listeners | com.aelitis.azureus.core.AzureusCore | azureus_core | Display | display | Shell | wizardWindow | Label | title | Label | currentInfo | Label | errorMessage | IWizardPanel | currentPanel | Composite | panel | org.eclipse.swt.graphics.Font | titleFont | protected Button | previous | protected Button | next | protected Button | finish | protected Button | cancel | Listener | closeCatcher | int | wizardHeight |
Constructors Summary |
---|
public Wizard(com.aelitis.azureus.core.AzureusCore azureus_core, String keyTitle, boolean modal)
this(azureus_core, modal);
setTitleKey(keyTitle);
| public Wizard(com.aelitis.azureus.core.AzureusCore azureus_core, String keyTitle)
this(azureus_core, keyTitle, false);
| public Wizard(com.aelitis.azureus.core.AzureusCore azureus_core)
this(azureus_core, false);
| public Wizard(com.aelitis.azureus.core.AzureusCore _azureus_core, boolean modal)
azureus_core = _azureus_core;
int style = SWT.DIALOG_TRIM | SWT.RESIZE;
if (modal) {
style |= SWT.APPLICATION_MODAL;
}
wizardWindow = ShellFactory.createMainShell(style);
this.display = wizardWindow.getDisplay();
GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
wizardWindow.setLayout(layout);
Utils.setShellIcon(wizardWindow);
Composite cTitle = new Composite(wizardWindow, SWT.NULL);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
cTitle.setBackground(white);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
cTitle.setLayoutData(gridData);
GridLayout titleLayout = new GridLayout();
titleLayout.numColumns = 1;
cTitle.setLayout(titleLayout);
title = new Label(cTitle, SWT.NULL);
title.setBackground(white);
gridData = new GridData(GridData.FILL_HORIZONTAL);
title.setLayoutData(gridData);
Font font = title.getFont();
FontData[] data = font.getFontData();
for(int i = 0 ; i < data.length ; i++) {
data[i].setStyle(SWT.BOLD);
}
titleFont=new Font(display,data);
title.setFont(titleFont);
currentInfo = new Label(cTitle, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
currentInfo.setLayoutData(gridData);
currentInfo.setBackground(white);
errorMessage = new Label(cTitle, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
errorMessage.setLayoutData(gridData);
errorMessage.setBackground(white);
Color red = display.getSystemColor(SWT.COLOR_RED);
errorMessage.setForeground(red);
gridData = new GridData(GridData.FILL_HORIZONTAL);
new Label(wizardWindow, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(gridData);
panel = new Composite(wizardWindow, SWT.NULL);
gridData = new GridData(GridData.FILL_BOTH);
panel.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_HORIZONTAL);
new Label(wizardWindow, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(gridData);
Composite cButtons = new Composite(wizardWindow, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cButtons.setLayoutData(gridData);
GridLayout layoutButtons = new GridLayout();
layoutButtons.numColumns = 5;
cButtons.setLayout(layoutButtons);
gridData = new GridData(GridData.FILL_HORIZONTAL);
new Label(cButtons, SWT.NULL).setLayoutData(gridData);
cancel = new Button(cButtons, SWT.PUSH);
gridData = new GridData();
gridData.widthHint = 90;
gridData.horizontalAlignment = GridData.CENTER;
cancel.setLayoutData(gridData);
Messages.setLanguageText(cancel, "Button.cancel");
previous = new Button(cButtons, SWT.PUSH);
gridData = new GridData();
gridData.widthHint = 90;
gridData.horizontalAlignment = GridData.END;
previous.setLayoutData(gridData);
Messages.setLanguageText(previous, "wizard.previous");
next = new Button(cButtons, SWT.PUSH);
gridData = new GridData();
gridData.widthHint = 90;
gridData.horizontalAlignment = GridData.BEGINNING;
next.setLayoutData(gridData);
Messages.setLanguageText(next, "wizard.next");
finish = new Button(cButtons, SWT.PUSH);
gridData = new GridData();
gridData.widthHint = 90;
gridData.horizontalAlignment = GridData.CENTER;
finish.setLayoutData(gridData);
Messages.setLanguageText(finish, "wizard.finish");
previous.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event arg0) {
clearPanel();
currentPanel = currentPanel.getPreviousPanel();
refresh();
}
});
next.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event arg0) {
IWizardPanel nextPanel = currentPanel.getNextPanel();
clearPanel();
currentPanel = nextPanel;
refresh();
}
});
closeCatcher = new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event event) {
event.doit = false;
}
};
finish.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event arg0){
finishSelected();
}
});
cancel.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event arg0) {
wizardWindow.dispose();
}
});
wizardWindow.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent de) {
onClose();
}
});
wizardWindow.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event e) {
if ( e.character == SWT.ESC){
if ( cancel.isEnabled()){
wizardWindow.dispose();
}
}
}
});
wizardHeight = wizardWindow.computeSize(DEFAULT_WIDTH,SWT.DEFAULT).y - 50;
wizardWindow.setSize(DEFAULT_WIDTH,400);
|
Methods Summary |
---|
public void | addListener(WizardListener l)
if (wizardWindow.isDisposed() && closeCatcher != null) {
l.closed();
}
listeners.add(l);
| private void | clearPanel()
Control[] controls = panel.getChildren();
for (int i = 0; i < controls.length; i++) {
if (controls[i] != null && !controls[i].isDisposed())
controls[i].dispose();
}
setTitle("");
setCurrentInfo("");
| private void | finishSelected()
if ( currentPanel.isFinishSelectionOK()){
wizardWindow.addListener(SWT.Close, closeCatcher);
clearPanel();
currentPanel = currentPanel.getFinishPanel();
refresh();
currentPanel.finish();
}
| public com.aelitis.azureus.core.AzureusCore | getAzureusCore()
return( azureus_core );
| public IWizardPanel | getCurrentPanel()
return currentPanel;
| public Display | getDisplay()
return display;
| public java.lang.String | getErrorMessage()
return errorMessage.getText();
| public Composite | getPanel()
return panel;
| public Shell | getWizardWindow()
return wizardWindow;
| private void | insureSize()
//panel.pack();
Point p = panel.computeSize(wizardWindow.getSize().x,SWT.DEFAULT);
int height = p.y + wizardHeight;
if(height > wizardWindow.getSize().y)
wizardWindow.setSize(p.x,height);
| public void | onClose()
if (titleFont != null && !titleFont.isDisposed()) {
titleFont.dispose();
titleFont=null;
}
for (int i=0;i<listeners.size();i++){
((WizardListener)listeners.get(i)).closed();
}
| private void | refresh()
if (currentPanel == null){
setDefaultButton();
return;
}
previous.setEnabled(currentPanel.isPreviousEnabled());
next.setEnabled(currentPanel.isNextEnabled());
finish.setEnabled(currentPanel.isFinishEnabled());
setDefaultButton();
currentPanel.show();
panel.layout();
panel.redraw();
insureSize();
| public void | removeListener(WizardListener l)
listeners.remove(l);
| public void | setCurrentInfo(java.lang.String currentInfo)
this.currentInfo.setText("\t" + currentInfo);
| private void | setDefaultButton()
if (!wizardWindow.isDisposed()){
display.asyncExec(new AERunnable() {
public void runSupport() {
if (!wizardWindow.isDisposed()){
Button default_button = null;
if ( next.isEnabled()){
default_button = next;
}else if ( finish.isEnabled()){
default_button = finish;
}else if ( previous.isEnabled()){
default_button = previous;
}else if ( cancel.isEnabled()){
default_button = cancel;
}
if ( default_button != null ){
wizardWindow.setDefaultButton( default_button );
}
}
}
});
}
| public void | setErrorMessage(java.lang.String errorMessage)
this.errorMessage.setText(errorMessage);
| public void | setFinishEnabled(boolean enabled)
this.finish.setEnabled(enabled);
setDefaultButton();
| public void | setFirstPanel(IWizardPanel panel)
this.currentPanel = panel;
refresh();
insureSize();
Utils.centreWindow( wizardWindow );
wizardWindow.open();
while (!wizardWindow.isDisposed()) {
try {
if (!display.readAndDispatch()) {
display.sleep();
}
} catch (Exception e) {
Debug.out(e);
}
}
| public void | setNextEnabled(boolean enabled)
this.next.setEnabled(enabled);
setDefaultButton();
| public void | setPreviousEnabled(boolean enabled)
this.previous.setEnabled(enabled);
setDefaultButton();
| public void | setTitle(java.lang.String title)
this.title.setText(title);
| public void | setTitleAsResourceID(java.lang.String id)
Messages.setLanguageText(title, id);
| public void | setTitleKey(java.lang.String key)
Messages.setLanguageText(wizardWindow, key);
| public void | switchToClose()
if (!wizardWindow.isDisposed()) {
display.asyncExec(new AERunnable() {
public void runSupport() {
if (closeCatcher != null && wizardWindow != null && !wizardWindow.isDisposed()) {
wizardWindow.removeListener(SWT.Close, closeCatcher);
cancel.setText(MessageText.getString("wizard.close"));
cancel.setEnabled(true);
setDefaultButton();
}
}
});
}
|
|