KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > loadprofile > gui > ChangeScaleDialog


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.loadprofile.gui;
24
25 import org.apache.log4j.Category;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.events.SelectionListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Dialog;
34 import org.eclipse.swt.widgets.Display;
35 import org.eclipse.swt.widgets.Label;
36 import org.eclipse.swt.widgets.Shell;
37 import org.eclipse.swt.widgets.Text;
38
39 /**
40  * This class is the dialog which permit to change scales
41  *
42  * @author JC Meillaud
43  * @author A Peyrard
44  */

45 public class ChangeScaleDialog extends Dialog implements SelectionListener {
46     // logger
47
static Category cat = Category.getInstance(ChangeScaleDialog.class
48             .getName());
49     // information we need to change scale
50
private Size scale;
51     private Text widthText;
52     private Text heightText;
53     private Button bOk;
54     private Button bCancel;
55     private Size result ;
56     private Shell shell ;
57
58     /**
59      * Build a new change scale dialog
60      *
61      * @param shell
62      * The shell to open the dialog
63      * @param scale
64      * The current scale
65      */

66     public ChangeScaleDialog(Shell shell, Size scale) {
67         super(shell);
68         // init infos
69
this.scale = scale;
70     }
71
72     /**
73      * Open the dialog
74      *
75      * @return The size edited or null if canceled
76      */

77     public Size open() {
78         this.shell = new Shell(getParent(), SWT.DIALOG_TRIM
79                 | SWT.APPLICATION_MODAL);
80         shell.setText("Change the current Scale");
81         shell.setSize(300, 150);
82         // set the layout of the shell
83
GridLayout gl = new GridLayout();
84         gl.numColumns = 1;
85         shell.setLayout(gl);
86         // create two composite one for the entry
87
Composite content = new Composite(shell, SWT.FLAT);
88         GridData gdC = new GridData();
89         gdC.grabExcessHorizontalSpace = true;
90         gdC.grabExcessVerticalSpace = true;
91         gdC.verticalAlignment = GridData.FILL;
92         gdC.horizontalAlignment = GridData.FILL;
93         content.setLayoutData(gdC);
94         // set the layout of content
95
GridLayout glC = new GridLayout();
96         glC.numColumns = 2;
97         content.setLayout(glC);
98         // back menu to put the two buttons
99
Composite back = new Composite(shell, SWT.FLAT);
100         GridData gdB = new GridData();
101         gdB.grabExcessHorizontalSpace = true;
102         gdB.horizontalAlignment = GridData.FILL;
103         content.setLayoutData(gdB);
104         // set the layout
105
GridLayout glB = new GridLayout();
106         glB.numColumns = 4 ;
107         back.setLayout(glB);
108
109         // widht setter
110
Label lWidth = new Label(content, SWT.NONE);
111         lWidth.setText("Width (nb sec) : ");
112         this.widthText = new Text(content, SWT.BORDER);
113         this.widthText.setText(Long.toString(this.scale.getWidth()));
114         this.widthText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
115
116         // height setter
117
Label lHeight = new Label(content, SWT.NONE);
118         lHeight.setText("Height (nb behaviors) : ");
119         this.heightText = new Text(content, SWT.BORDER);
120         this.heightText.setText(Long.toString(this.scale.getHeight()));
121         this.heightText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
122
123         // add the buttons
124
// add separator
125
new Label(back, SWT.NONE).setText("") ;
126         new Label(back, SWT.NONE).setText("") ;
127         // add the buttons
128
this.bOk = new Button(back, SWT.PUSH);
129         this.bOk.setText("OK");
130         this.bCancel = new Button(back, SWT.PUSH);
131         this.bCancel.setText("CANCEL");
132         this.bOk.addSelectionListener(this);
133         this.bCancel.addSelectionListener(this);
134
135         shell.open();
136         Display display = getParent().getDisplay();
137         while (!shell.isDisposed()) {
138             if (!display.readAndDispatch())
139                 display.sleep();
140         }
141         return result ;
142     }
143     
144     /**
145      * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
146      */

147     public void widgetDefaultSelected(SelectionEvent arg0) {
148     }
149     
150     /**
151      * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
152      */

153     public void widgetSelected(SelectionEvent e) {
154         // BUTTON OK
155
if (e.getSource() == bOk) {
156             result = new Size(new Integer JavaDoc(this.widthText.getText()).intValue(), new Integer JavaDoc(this.heightText.getText()).intValue()) ;
157             shell.close() ;
158             return ;
159         }
160         // BUTTON CANCEL
161
if (e.getSource() == bCancel) {
162             result = null ;
163             shell.close() ;
164             return ;
165         }
166     }
167 }
Popular Tags