使用Display.map隐藏带有子shell的父shell

时间:2013-09-27 09:26:51

标签: java shell swt jface

如何使用Diplay.map方法使用子shell隐藏父shell。 我想隐藏父shell,直到浏览器进度监听器没有完成。但我没有得到理想的输出。任何人都可以帮助我将子shell正确地放在父shell上,同时保持其边框和标题栏区域

 package browserapp; 




    public class MyBrowser_1 {
/**
 * Runs the application
 */
Shell child=null;
Display display = new Display();
protected boolean done;
public void run() {

    final Shell shell = new Shell(display);
    shell.setText("Simple Browser");
    createContents(shell);

    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}


/**
 * Creates the main window's contents
 * 
 * @param shell the main window
 */
private void createContents(final Shell shell) 
{
    shell.setLayout(new FormLayout());

    // Create the composite to hold the buttons and text field
    Composite controls = new Composite(shell, SWT.NONE);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    controls.setLayoutData(data);

    // Create the web browser
    final SafeMaskBrowser  browser = new SafeMaskBrowser(shell, SWT.NONE);
    //shell.setMaximized(true);
    child=new Shell(shell, SWT.NO_TRIM|SWT.RESIZE);


    System.out.println(shell.getClientArea().x + " " + shell.getClientArea().y);
    System.out.println(shell.getShell().getSize().x + " " + 
            shell.getShell().getSize().y);
    System.out.println(shell.getLocation().x+ " " + shell.getLocation().y);
    System.out.println(shell.getSize());
    //child.setBounds(shell.getLocation().x, shell.getLocation().y,  
            shell.getSize().x, shell.getSize().y);
    //child.setLocation(shell.getLocation().x,shell.getLocation().y+55);
    //child.setSize(shell.getSize());

    child.open();
    display.map(shell, child, shell.getLocation());
    shell.addListener(SWT.Resize|SWT.DRAG, new Listener() {

        @Override
        public void handleEvent(Event event) 
        {


      //child.setLocation(shell.getLocation().x,shell.getLocation().y+55);

    child.setSize(shell.getSize());

        }
    });

    //child.setBounds(shell.getClientArea());
    browser.addProgressListener(new ProgressListener() 
    {
        public void completed(ProgressEvent event)
        {
            child.setVisible(false);
        }
        public void changed(ProgressEvent event) 
        {

            int progressWorked=0;
            if (event.total == 0)
                return;

            done = (event.current == event.total);
            int percentProgress = event.current * 100 / event.total;
            System.out.println("Loading...");

            if (done) 
            {
                progressWorked = 0;
                System.out.println("Loading completed...");

                //maskPage(browser, maskedMap);

            } else if (progressWorked == 0) 
            {

                progressWorked = percentProgress;
            } else 
            {

                progressWorked = event.current;
            }
        }
    });

    data = new FormData();
    data.top = new FormAttachment(controls);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    // Create the controls and wire them to the browser
    controls.setLayout(new GridLayout(7, false));

    // Create the back button
    Button button = new Button(controls, SWT.PUSH);
    button.setText("Back");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.back();
        }
    });

    // Create the forward button
    button = new Button(controls, SWT.PUSH);
    button.setText("Forward");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.forward();
        }
    });

    // Create the refresh button
    button = new Button(controls, SWT.PUSH);
    button.setText("Refresh");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.refresh();
        }
    });

    // Create the stop button
    button = new Button(controls, SWT.PUSH);
    button.setText("Stop");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.stop();
        }
    });

    // Create the address entry field and set focus to it
    final Text url = new Text(controls, SWT.BORDER);
    url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    url.setText("https://netbanking.hdfcbank.com/netbanking/");
    url.setFocus();

    // Create the go button
    button = new Button(controls, SWT.PUSH);
    button.setText("Go");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.setUrl(url.getText());
        }
    });

    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, false);
    Label status = new Label(controls, SWT.BORDER);
    status.setLayoutData(gridData2);
    // Allow users to hit enter to go to the typed URL
    shell.setDefaultButton(button);
}




/**
 * The application entry point
 * 
 * @param args the command line arguments
 */
public static void main(String[] args) {
    MyBrowser_1 browser=new MyBrowser_1();
    browser.run();


}
    }

0 个答案:

没有答案