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
|
public class TestHideComposite {
private static Composite rootComposite;
private static Composite svgStaticComp;
private static Composite svgDynamicComp;
private static boolean isRemote = false;
/**
* TODO : Description de la méthode <code>main</code>.
* @param args
*/
public static void main(final String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(600, 600);
shell.setLayout(new GridLayout());
Composite boutonComposite = new Composite(shell, SWT.BORDER);
boutonComposite.setLayout(new GridLayout());
boutonComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
Button switchBtn = new Button(boutonComposite, SWT.PUSH);
switchBtn.setText("SWITCH");
switchBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
}
@Override
public void widgetSelected(final SelectionEvent e) {
switchComposite();
}
});
rootComposite = new Composite(shell, SWT.BORDER);
// composite BLEU , le principal
rootComposite.setBackground(new Color(null, 0, 0, 255));
rootComposite.setLayout(new GridLayout(2, false));
rootComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
svgStaticComp = new Composite(rootComposite, SWT.NONE);
GridData dataStatic = new GridData(SWT.FILL, SWT.NONE, true, false);
dataStatic.exclude = false;
svgStaticComp.setLayoutData(dataStatic);
// composite VERT
svgStaticComp.setBackground(new Color(null, 0, 255, 0));
svgDynamicComp = new Composite(rootComposite, SWT.NONE);
GridData dataDyn = new GridData(SWT.FILL, SWT.NONE, true, false);
dataDyn.exclude = true;
svgDynamicComp.setLayoutData(dataDyn);
// composite ROUGE
svgDynamicComp.setBackground(new Color(null, 255, 0, 0));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
private static void switchComposite() {
isRemote = !isRemote;
GridData dataDyn = (GridData) svgDynamicComp.getLayoutData();
GridData dataStatic = (GridData) svgStaticComp.getLayoutData();
dataDyn.exclude = !isRemote;
svgDynamicComp.setVisible(isRemote);
dataStatic.exclude = isRemote;
svgStaticComp.setVisible(!isRemote);
rootComposite.layout(false);
}
} |
Partager