Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Java Native Interfaces with SWT/JFace Discuss the book Professional Java Native Interfaces with SWT/JFace, by Jackwind Li Guojie, ISBN: 0-470-09459-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Java Native Interfaces with SWT/JFace section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 23rd, 2005, 01:32 AM
Registered User
 
Join Date: Apr 2005
Location: , , Germany.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Reply With Quote
  #2 (permalink)  
Old May 27th, 2005, 06:20 PM
Registered User
 
Join Date: May 2005
Location: Tucson, AZ, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Interesting book though.

Reply With Quote
  #3 (permalink)  
Old May 27th, 2005, 11:03 PM
Registered User
 
Join Date: May 2005
Location: Tucson, AZ, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default



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;
    }

}



Reply With Quote
  #4 (permalink)  
Old December 7th, 2005, 10:46 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;
    }
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Image Viewer pushpa ASP.NET 1.0 and 1.1 Basics 2 April 13th, 2007 05:56 PM
Document viewer baburman General .NET 4 November 2nd, 2006 05:12 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM
DLL Viewer qazi_nomi Classic ASP Professional 0 June 15th, 2004 06:25 AM



All times are GMT -4. The time now is 01:30 AM.


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