1 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 45 public class ChangeScaleDialog extends Dialog implements SelectionListener { 46 static Category cat = Category.getInstance(ChangeScaleDialog.class 48 .getName()); 49 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 66 public ChangeScaleDialog(Shell shell, Size scale) { 67 super(shell); 68 this.scale = scale; 70 } 71 72 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 GridLayout gl = new GridLayout(); 84 gl.numColumns = 1; 85 shell.setLayout(gl); 86 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 GridLayout glC = new GridLayout(); 96 glC.numColumns = 2; 97 content.setLayout(glC); 98 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 GridLayout glB = new GridLayout(); 106 glB.numColumns = 4 ; 107 back.setLayout(glB); 108 109 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 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 new Label(back, SWT.NONE).setText("") ; 126 new Label(back, SWT.NONE).setText("") ; 127 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 147 public void widgetDefaultSelected(SelectionEvent arg0) { 148 } 149 150 153 public void widgetSelected(SelectionEvent e) { 154 if (e.getSource() == bOk) { 156 result = new Size(new Integer (this.widthText.getText()).intValue(), new Integer (this.heightText.getText()).intValue()) ; 157 shell.close() ; 158 return ; 159 } 160 if (e.getSource() == bCancel) { 162 result = null ; 163 shell.close() ; 164 return ; 165 } 166 } 167 } | Popular Tags |