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 84 85 86
| import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Animation {
private static final int PAS = 2;
private static final int PAUSE = 5;
protected static void open(final Shell shell) {
final int x = (shell.getDisplay().getBounds().width - shell.getSize().x) / 2;
final int y = (shell.getDisplay().getBounds().height - shell.getSize().y) / 2;
shell.setLocation(x, shell.getDisplay().getBounds().height-100);
shell.setAlpha(0);
shell.open();
shell.getDisplay().syncExec(new Runnable() {
public void run() {
int currentY = shell.getDisplay().getBounds().height;
float step = 255f/((currentY-y)/PAS);
float alpha = 0f;
while (currentY>=y) {
shell.setLocation(x, currentY);
shell.setAlpha((int) alpha);
currentY = currentY - PAS;
try {
Thread.sleep(PAUSE);
} catch (InterruptedException e) {
// TODO Insérer le traitement de l'exception
}
alpha = alpha+step;
}
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new FillLayout());
Button bouton = new Button(shell, SWT.PUSH);
bouton.setText("Ouverture");
bouton.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent arg0) {
Shell fille = new Shell(shell, SWT.SHELL_TRIM);
fille.setLayout(new FillLayout());
Label label = new Label(fille, SWT.NONE);
label.setText("Coucou !");
fille.pack();
open(fille);
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} |
Partager