1 /*
2  *  CVS: $Id: RunDialog.java,v 1.12 2004/07/25 21:40:56 marcus Exp $
3  * 
4  *  This file is part of zuul.
5  *
6  *  zuul is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10 *
11 *  zuul is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with zuul; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * 
20 *  Copyrigth 2004 by marcus, leh
21 * 
22 */
23package org.jzuul.gdk.swt;
24
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.events.DisposeEvent;
27import org.eclipse.swt.events.DisposeListener;
28import org.eclipse.swt.events.SelectionAdapter;
29import org.eclipse.swt.events.SelectionEvent;
30import org.eclipse.swt.events.SelectionListener;
31import org.eclipse.swt.layout.GridData;
32import org.eclipse.swt.layout.GridLayout;
33import org.eclipse.swt.widgets.Button;
34import org.eclipse.swt.widgets.Composite;
35import org.eclipse.swt.widgets.Dialog;
36import org.eclipse.swt.widgets.Display;
37import org.eclipse.swt.widgets.Label;
38import org.eclipse.swt.widgets.Shell;
39import org.eclipse.swt.widgets.Slider;
40import org.jzuul.engine.gui.utils.Util;
41
42/**
43 * RunDialog Class, the Dialog in which the options for 
44 * runnig jzuul can be spezified (multithreaded npcs and number
45 * of players)
46 * 
47 */
48public class RunDialog extends Dialog {
49
50    private Label numbers;
51    private Label numOfPlayers_label;
52
53    private Button threadedNPC_button;
54
55    private Slider slider;
56
57    private Button ok;
58
59    private Button cancel;
60
61    private RunValues runvalues;
62
63    /**
64     * @param arg0
65     */
66    public RunDialog(Shell shell) {
67        super(shell);
68        runvalues = new RunValues();
69    }
70
71    /**
72     * @param arg0
73     * @param arg1
74     */
75    public RunDialog(Shell shell, int style) {
76        super(shell, style);
77        runvalues = new RunValues();
78    }
79
80    public void setRunValues(RunValues runValues) {
81        this.runvalues = runValues;
82    }
83
84    public RunValues open() {
85        Shell parent = getParent();
86        final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
87        
88    
89        shell.setText(Messages.getString("ENGINE_OPTIONS")); //$NON-NLS-1$
90        shell.setImage(Util.getImagefromResource(parent.getDisplay(),"etc/artwork/jz.png")); //$NON-NLS-1$
91        shell.setLayout(new GridLayout(2, false));
92
93        threadedNPC_button = new Button(shell, SWT.CHECK);
94        threadedNPC_button.setSelection(runvalues.threadedNPCs);
95        threadedNPC_button.setText(Messages.getString("THREADED_NPCS")); //$NON-NLS-1$
96        threadedNPC_button.setToolTipText(Messages.getString("THREADED_TOOLTIP")); //$NON-NLS-1$
97        
98        final Button askPlayer = new Button(shell, SWT.CHECK);
99        askPlayer.setSelection(runvalues.askPlayerName);
00        askPlayer.setText(Messages.getString("ASK_PLAYER_NAME")); //$NON-NLS-1$
01        askPlayer.setToolTipText(Messages.getString("ASK_TOOLTIP")); //$NON-NLS-1$
02        
03        numOfPlayers_label = new Label(shell, SWT.NONE);
04        numOfPlayers_label.setText(Messages.getString("NUMBER_OF_PLAYERS")); //$NON-NLS-1$
05        
06        Composite comp = new Composite(shell,SWT.FILL);
07        comp.setLayout(new GridLayout(2,false));
08        slider = new Slider(comp, SWT.HORIZONTAL);
09        //slider.setSelection(runvalues.numOfPlayers);
10        slider.setMinimum(1);
11        slider.setMaximum(20);
12        slider.setPageIncrement(1);
13        slider.setIncrement(1);
14        slider.addSelectionListener(new SelectionAdapter(){
15
16            public void widgetSelected(SelectionEvent e) {
17                numbers.setText("" + slider.getSelection()); //$NON-NLS-1$
18                numbers.update();
19                if (slider.getSelection() == 1) {
20                    askPlayer.setSelection(false);
21                    askPlayer.setEnabled(true);
22                } else {
23                    askPlayer.setSelection(true);
24                    askPlayer.setEnabled(false);
25                }
26                shell.update();
27                System.err.println("Slider: " + slider.getSelection()); //$NON-NLS-1$
28            }
29
30            public void widgetDefaultSelected(SelectionEvent e) {
31                    //des g'hört so
32            }
33            
34        });
35        numbers = new Label(comp,SWT.NONE);
36        numbers.setText("  " +slider.getSelection()); //$NON-NLS-1$
37
38        ok = new Button(shell, SWT.NONE);
39        ok.setText(Messages.getString("OK")); //$NON-NLS-1$
40        ok.addSelectionListener(new SelectionListener() {
41
42            public void widgetSelected(SelectionEvent arg0) {
43                runvalues = new RunValues(threadedNPC_button.getSelection(),
44                        slider.getSelection(),askPlayer.getSelection());
45                shell.dispose();
46            }
47
48            public void widgetDefaultSelected(SelectionEvent arg0) {
49            }
50        });
51        GridData okDat = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
52        okDat.widthHint = 80;
53        ok.setLayoutData(okDat);
54
55        cancel = new Button(shell, SWT.NONE);
56        cancel.setText(Messages.getString("CANCEL")); //$NON-NLS-1$
57        cancel.addSelectionListener(new SelectionListener() {
58
59            public void widgetSelected(SelectionEvent arg0) {
60                shell.dispose();
61            }
62
63            public void widgetDefaultSelected(SelectionEvent arg0) {}
64        });
65        GridData cancelDat = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
66        cancelDat.widthHint = 80;
67        cancel.setLayoutData(cancelDat);
68
69        this.runvalues = null;
70        shell.pack();
71        shell.open();
72        Display display = parent.getDisplay();
73        while (!shell.isDisposed()) {
74            if (!display.readAndDispatch())
75                display.sleep();
76        }
77        return runvalues;
78    }
79}