Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] shell events


Events can represent a state transition that is occurring but has not yet happened.  For example, on a mouse down event, if you look at the modifiers mask, the mouse button is not yet pressed.  On mouse up, the button is still pressed.  So the same thing applies here.  If you want to know what is the next active shell, you could try something else like a Display filter to catch all shells being activated.

Please ask usage questions on the newsgroup.

-Randy




Thomas Braun <mail@xxxxxxxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

05/18/2005 05:44 PM

Please respond to
"Eclipse Platform SWT component developers list."

To
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
cc
Subject
Re: [platform-swt-dev] shell events





I'm sorry Yu, but you are wrong. If the listener receives the
SWT.Deactivate event the Event.widget field contains the deactivated shell
and Display.getActiveShell returns the now deactivated shell...

I remodified the code with a more detailed output:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;


public class Main
{
    public static void main(String[] args)
    {
        final Display display = new Display();
        final Shell shell1 = new Shell(display);
        shell1.setText("shell 1");
        shell1.setBounds(0, 50, 200, 100);
        final MyListener listener = new MyListener();
        shell1.addListener(SWT.Activate, listener);
        shell1.addListener(SWT.Deactivate, listener);
        final Shell shell2 = new Shell(display);
        shell2.setText("shell 2");
        shell2.setBounds(250, 50, 200, 100);
        shell2.addListener(SWT.Activate, listener);
        shell2.addListener(SWT.Deactivate, listener);
        shell1.open();
        shell2.open();
        while (!shell1.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

class MyListener implements Listener
{
    public void handleEvent(Event e)
    {
        if (e.type == SWT.Activate) {
            System.out.println(((Shell) e.widget).getText() +
                " activated");
        }
        else if (e.type == SWT.Deactivate) {
            System.out.println(((Shell) e.widget).getText() +
                " deactivated");
        }
        System.out.println(e.display.getActiveShell().getText() +
            " is now active\n");
    }
}

Yu.You@xxxxxxxxx schrieb:
> I see. It is because you used typed event handlers.  Please use untyped event handler.  see the example I modified. It works.
>
> import org.eclipse.swt.events.ShellAdapter;
> import org.eclipse.swt.events.ShellEvent;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Listener;
> import org.eclipse.swt.widgets.Event;
>
>
> public class Main
> {
>                  public static void main(String[] args)
>                  {
>                                   final Display display = new Display();
>
>                                   final Shell shell1 = new Shell(display);
>                                   shell1.setText("shell 1");
>                                   shell1.setBounds(0, 50, 200, 100);
>                                   final MyListener listener = new MyListener();
>                                   shell1.addListener(SWT.Activate, listener);
>                                   shell1.addListener(SWT.Deactivate, listener);
>
>                                   final Shell shell2 = new Shell(display);
>                                   shell2.setText("shell 2");
>                                   shell2.setBounds(250, 50, 200, 100);
>                                   shell2.addListener(SWT.Activate, listener);
>                                   shell2.addListener(SWT.Deactivate, listener);
>
>                                   shell1.open();
>                                   shell2.open();
>                                   while (!shell1.isDisposed()) {
>                                                    if (!display.readAndDispatch())
>                                                                     display.sleep();
>                                   }
>                                   display.dispose();
>                  }
> }
>
> class MyListener implements Listener {
>                  public void handleEvent(Event e)
>                  {
>                                   if(e.type==SWT.Activate)
>                                                    System.out.println("\n" + e.display.getActiveShell().
>                                   getText() + " is active");
>                                   if(e.type==SWT.Deactivate)
>                                                    System.out.println("\n" + e.display.getActiveShell().
>                                   getText() + " is deactived");
>                                  
>                  }
>
> }
>
>
> -----Original Message-----
> From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx]On Behalf Of ext Thomas Braun
> Sent: Tuesday, May 17, 2005 4:42 PM
> To: Eclipse Platform SWT component developers list.
> Subject: Re: [platform-swt-dev] shell events
>
>
> I am using Display.getActiveShell(), but it does NOT return the correct result.
>
> I wrote an example application (attached) creating two shells. To each
> shell I add a shell listener. The methods shellActivated and
> shellDeactivated write to System.out which method was invoked and the title
> of the now active shell (received by calling Display.getActiveShell). The
> result looks like that:
>
> shell 1 activated
> shell 1 is active
>
> shell 1 deactivated
> shell 1 is active      <-- here is the error; which shell is really active?
>
> shell 2 activated
> shell 2 is active
>
> Tested with SWT 3.1 M7 on a Windows XP SP2 machine.
>
> Thanks,
> Tom
>
> Yu.You@xxxxxxxxx schrieb:
>
>>use Display.getActiveShell();
>>
>>Yu
>>
>>-----Original Message-----
>>From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx]On Behalf Of ext Thomas Braun
>>Sent: Saturday, May 07, 2005 11:36 AM
>>To: Eclipse Platform SWT component developers list.
>>Subject: [platform-swt-dev] shell events
>>
>>
>>Hello,
>>
>>I have noticed that if a get ShellDeactivated event from a ShellListener
>>and I ask the display for the active shell while the event is processed, I
>>get the shell which has been deactivated and not the shell which is now the
>>active one.
>>Is that a correct behaviour? What have I to do, if I want to know which
>>shell is now active?
>>
>>Thanks,
>>Tom
>>_______________________________________________
>>platform-swt-dev mailing list
>>platform-swt-dev@xxxxxxxxxxx
>>https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>>
>
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top