IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SWT/JFace Java Discussion :

Ouverture "glissée" d'un shell


Sujet :

SWT/JFace Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Avril 2007
    Messages
    57
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 57
    Par défaut Ouverture "glissée" d'un shell
    Bonjour,

    Est ce possible en SWT d'ouvrir un shell avec un effet ? Dans mon appli, je souhaiterais ouvrir un shell de manière "glissé" ou "progressif" lorsque je clique sur un bouton. Comme je ne suis pas très clair , j'ai mis un exemple de ce que je recherchais en pièce jointe.

    Est ce faisable en SWT ou existe-t-il des bibliothèques open source le permettant ?

    Merci
    Images attachées Images attachées  

  2. #2
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Bonsoir,

    Bien sûr que c'est faisable

    Dans ce code, la fenêtre fille est centrée. Tu peux jouer sur la vitesse
    d'animation avec les constantes PAS et PAUSE...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    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 = 10;
        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.open();
     
            shell.getDisplay().syncExec(new Runnable() {
     
                public void run() {
                    int currentY = shell.getDisplay().getBounds().height;
                    while (currentY>=y) {
                        shell.setLocation(x, currentY);
                        currentY = currentY - PAS;
                        try {
                            Thread.sleep(PAUSE);
                        } catch (InterruptedException e) {
                            // TODO Insérer le traitement de l'exception
                        }
                    }
     
                }
            });
     
        }
     
        /**
         * @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();
        }
     
    }
    Laurent

  3. #3
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Et comme je suis un type sympa, la même version avec un effet de transparence

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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();
        }
     
    }

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut
    Citation Envoyé par meddle Voir le message
    Et comme je suis un type sympa, la même version avec un effet de transparence

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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();
        }
     
    }

    bonsoir est ce qu'on peut faire ceci avec un wizard ???
    comment faire si oui ??

    merci d'avance

  5. #5
    Membre confirmé
    Inscrit en
    Avril 2007
    Messages
    57
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 57
    Par défaut Je confirme à 200%, t'es un mec vraiment sympa :)
    Citation Envoyé par meddle Voir le message
    Bonsoir,

    Bien sûr que c'est faisable

    Dans ce code, la fenêtre fille est centrée. Tu peux jouer sur la vitesse
    d'animation avec les constantes PAS et PAUSE...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    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 = 10;
        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.open();
     
            shell.getDisplay().syncExec(new Runnable() {
     
                public void run() {
                    int currentY = shell.getDisplay().getBounds().height;
                    while (currentY>=y) {
                        shell.setLocation(x, currentY);
                        currentY = currentY - PAS;
                        try {
                            Thread.sleep(PAUSE);
                        } catch (InterruptedException e) {
                            // TODO Insérer le traitement de l'exception
                        }
                    }
     
                }
            });
     
        }
     
        /**
         * @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();
        }
     
    }
    Laurent
    Une ola pour Laurent

    Entre temps je m'étais fait quelque chose d'à peu près similaire (mais ce que tu as fait me parait plus propre) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    int hauteurPopUp = 28;
    int pause = 2;
    Shell shellFille = createShell(shellParent);
    popUp.setLocation(shellParent.getLocation().x+72, shellParent.getLocation().y-1);
    popUp.setSize(90, 1);
    popUp.open();
    for (int i=2; i < hauteurPopUp ; i++) {
    	popUp.setSize(90, i);
    	popUp.setLocation(shellParent.getLocation().x+72, shellParent.getLocation().y+(hauteurPopUp-i)-1);
    	popUp.redraw(shellParent.getLocation().x+72, shellParent.getLocation().y+(hauteurPopUp-i)-1, i, shellParent.getLocation().y+(hauteurPopUp-i)-1, true);
    	try {
    		Thread.sleep(pause);
    	} catch (InterruptedException e1) {}
    }
    popUp.pack();
    Par contre, tu as le même soucis que moi : le "coucou" du label n'est affiché qu'à la fin et pas pendant la "remontée"... Mais bon, avec un temps de pause rapide, on ne voit rien de toutes façons

    Tu utilises la méthode Shell.setAlpha, c'est à partir de quelle version de SWT ? Pour moi, ça ne fonctionne pas (version 3.2.2). Mais je vais chercher l'équivalent de ce pas...

    Merci encore !!!

  6. #6
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Cool

    Le shell.alpha c'est à partir de la version 3.4 de SWT (la dernière version stable)

    Pour le wizard par contre, je ne sais pas,

    Laurent

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo