/**
* Displays this wizard in the specified {@link Window} that is positioned relative to thespecified component.
* @param window the window that will contain the wizard.
* @param relativeTo the component used to position the window. If the component is <tt>null</tt>,the window will be centered on the desktop as per {@link JWindow#setLocationRelativeTo(java.awt.Component)}.
*/
private void showInWindow(Window window,Component relativeTo){
((RootPaneContainer)window).getContentPane().add(this);
window.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent e){
cancel();
}
}
);
WizardFrameCloser.bind(this,window);
window.pack();
window.setLocationRelativeTo(relativeTo);
window.setVisible(true);
window.toFront();
}

Example 8

From project freemind, under directory /freemind/accessories/plugins/dialogs/.

/**
* Creates an AWT frame suitable as a parent for AWT/Swing dialogs. <p> This method must be called from the SWT event thread. There must be an active shell associated with the environment's display. <p> The created frame is a non-visible child of the given shell and will be disposed when that shell is disposed. <p> This method is useful for creating a frame to parent any AWT/Swing dialogs created for use inside a SWT application. A modal AWT/Swing dialogs will behave better if its parent is set to the returned frame rather than to null or to an independently created {@link java.awt.Frame}. <p> The frame is positioned such that its child AWT dialogs are centered over the given parent shell's position <i>when this method is called</i>. If the parent frame is later moved, the child will no longer be properly positioned. For best results, create a new frame with this method immediately before creating and displaying each child AWT/Swing dialog. <p> As with any AWT window, the returned frame must be explicitly disposed.
* @param parent - the SWT parent shell of the shell that will contain the returned frame
* @return a {@link java.awt.Frame} to be used for parenting dialogs
* @exception SWTException <ul> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the SWT event thread </ul>
* @exception IllegalStateException if the current display has no shells
*/
public Frame createDialogParentFrame(final Shell parent){
if (parent == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
if (!this.display.equals(Display.getCurrent())) {
SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
}
final Shell shell=new Shell(parent,SWT.NO_TRIM | SWT.APPLICATION_MODAL);
final Composite composite=new Composite(shell,SWT.EMBEDDED);
final Frame frame=SWT_AWT.new_Frame(composite);
shell.setLocation(parent.getLocation());
if (Platform.isGtk()) {
shell.setSize(0,0);
shell.setVisible(true);
shell.setVisible(false);
}
shell.setSize(parent.getSize());
shell.setLayout(new FillLayout());
shell.layout();
frame.addWindowListener(new WindowAdapter(){
@Override public void windowClosed( final WindowEvent e){
if (!AwtEnvironment.this.display.isDisposed()) {
ThreadingHandler.getInstance().asyncExec(AwtEnvironment.this.display,new Runnable(){
public void run(){
shell.dispose();
}
}
);
}
}
}
);
return frame;
}

Example 61

From project OWASP-WebScarab, under directory /src/org/owasp/webscarab/ui/swing/editors/.