p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Java Native Interfaces with SWT/JFace (http://p2p.wrox.com/forumdisplay.php?f=166)
-   -   List Viewer (http://p2p.wrox.com/showthread.php?t=28486)

thomas2078 April 23rd, 2005 01:32 AM

List Viewer
 

The "SampleListViewer" in Chapter 7 wants to import the class "com.asprise.swt.OptionPane", but I can't find this.
Any Idea where to look?

I tried to look on the website that is given in some examples: http://www.asprise.com/swt
but this is also not reachable. [?]


javapda May 27th, 2005 06:20 PM

[V] I had the same experience. Also, no luck finding it on the aprise site.

Interesting book though. [B)]


javapda May 27th, 2005 11:03 PM



Perhaps something like the following would suffice:



public class OptionPane {

    public static String showInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, Object initialValue) {
        boolean answer = MessageDialog.openQuestion(parentShell,dialogTitle ,dialogMessage);
        String result = null;
        if ( answer ) {
            result = (String)initialValue;
        }
        return result;
    }

}




jackwind December 7th, 2005 10:46 PM

Hi all

Below is the source code for OptionPane. http://www.asprise.com/swt is back now and you download the source code from it.

Sorry for any inconvenience caused.

Best regards.

Code:


/******************************************************************************
 * All Right Reserved.
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 *
 * Created on Feb 16, 2004 7:41:37 PM by JACK
 * $Id$
 *
 *****************************************************************************/

package com.asprise.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;

/**
 *
 */
public class OptionPane {


    public static String showInputDialog(Shell parent, String message, String title, String initialValue) {
        final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE);
        //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));

        if(title != null)
            shell.setText(title);

        GridLayout gridLayout = new GridLayout(1, false);
        shell.setLayout(gridLayout);

        Composite content = new Composite(shell, SWT.NULL);
        content.setLayout(new RowLayout());
        //content.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_CYAN));

        GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
        content.setLayoutData(gridData);

        (new Label(content, SWT.NULL)).setText(message);
        final Text text = new Text(content, SWT.SINGLE | SWT.BORDER);
        if(initialValue != null)
            text.setText(initialValue);

        Composite buttons =new Composite(shell, SWT.NULL);

        gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
        buttons.setLayoutData(gridData);

        FillLayout fillLayout = new FillLayout();
        fillLayout.spacing = 5;
        buttons.setLayout(fillLayout);

        final Button buttonOK = new Button(buttons, SWT.PUSH);
        final Button buttonCancel = new Button(buttons, SWT.PUSH);

        buttonOK.setText("OK");
        buttonCancel.setText("Cancel");


        final class DialogSelectionListener implements SelectionListener {
            public String returnText;

            public void widgetSelected(SelectionEvent e) {
                onSelected(e.widget);
            }
            public void widgetDefaultSelected(SelectionEvent e) {
                onSelected(e.widget);
            }

            private void onSelected(Widget widget) {
                if(widget == buttonOK)
                    returnText = text.getText();
                shell.dispose();
            }
        }

        DialogSelectionListener listener = new DialogSelectionListener();

        buttonCancel.addSelectionListener(listener);
        buttonOK.addSelectionListener(listener);

        shell.pack();

        // Center the shell.
        if(parent != null) {
            Rectangle parentBounds = parent.getBounds();
            Point shellSize = shell.getSize();
            shell.setLocation( parentBounds.x+(parentBounds.width-shellSize.x)/2, parentBounds.y+(parentBounds.height-shellSize.y)/2 );
        }

        shell.open();

        // Set up the event loop.
        while (!shell.isDisposed()) {
            if (!shell.getDisplay().readAndDispatch()) {
                // If no more entries in event queue
                shell.getDisplay().sleep();
            }
        }

        return listener.returnText;
    }
}



All times are GMT -4. The time now is 10:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.