1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| public class ListLanguage
{
private static Logger log = Logger.getLogger(ListLanguage.class.getName());
private Display display;
private Shell shell;
public ListLanguage(Display display){
this.display = display;
}
public void start()
{
shell = new Shell(display);
shell.setText("Language");
Label label = new Label (shell, SWT.WRAP);
label.setText ("Please select language");
final Combo combo = new Combo (shell, SWT.READ_ONLY);
combo.setItems (new String [] {"English", "French"});
combo.setSize (200, 200);
final int insetX = 4, insetY = 4;
FormLayout formLayout = new FormLayout ();
formLayout.marginWidth = insetX;
formLayout.marginHeight = insetY;
shell.setLayout (formLayout);
Point size = label.computeSize (SWT.DEFAULT, SWT.DEFAULT);
final FormData labelData = new FormData (size.x, SWT.DEFAULT);
labelData.left = new FormAttachment (0, 0);
labelData.right = new FormAttachment (100, 0);
label.setLayoutData (labelData);
shell.addListener (SWT.Resize, new Listener () {
public void handleEvent (Event e) {
Rectangle rect = shell.getClientArea ();
labelData.width = rect.width - insetX * 2;
shell.layout ();
}
});
FormData listData = new FormData ();
listData.left = new FormAttachment (0, 0);
listData.right = new FormAttachment (100, 0);
listData.top = new FormAttachment (label, insetY);
combo.setLayoutData (listData);
combo.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e)
{
int index = combo.getSelectionIndex();
Language.getInstance().setLocal(index);
Load load = new Load(shell.getDisplay());
load.start();
shell.close();
}
});
// this.shell.getDisplay()
// Center IHM
shell.setLocation( (this.shell.getDisplay().getClientArea().width/2),
(this.shell.getDisplay().getClientArea().height/2));
shell.pack ();
shell.setSize(220, 101);
shell.open ();
while (!shell.isDisposed ()) {
if (!this.shell.getDisplay().readAndDispatch ()) this.shell.getDisplay().sleep ();
}
log.debug("display list language screen");
this.shell.getDisplay().dispose ();
}
} |
Partager