Package org.eclipse.swt.events

Examples of org.eclipse.swt.events.KeyEvent


  public static String toString(Event event) {
    String toString = toString(event.type) + " [" + event.type + "]: "; //$NON-NLS-1$ //$NON-NLS-2$
    switch (event.type) {
    case SWT.KeyDown:
    case SWT.KeyUp:
      toString += new KeyEvent(event).toString();
      break;
    case SWT.MouseDown:
    case SWT.MouseUp:
    case SWT.MouseMove:
    case SWT.MouseEnter:
View Full Code Here


  public static String toString(Event event) {
    String toString = toString(event.type) + " [" + event.type + "]: "; //$NON-NLS-1$ //$NON-NLS-2$
    switch (event.type) {
    case SWT.KeyDown:
    case SWT.KeyUp:
      toString += new KeyEvent(event).toString();
      break;
    case SWT.MouseDown:
    case SWT.MouseUp:
    case SWT.MouseMove:
    case SWT.MouseEnter:
View Full Code Here

        if (shell == null || shell.isDisposed()) {
          Display.getDefault().removeFilter(SWT.KeyDown, this);
          e.doit = false;
          return;
        }
        KeyEvent ke = new KeyEvent(e);
        if ((ke.keyCode == SWT.ALT) || ke.keyCode == SWT.F10) {
          hideMenu();
          return;
        }
        getCurrentMenu().dealAltKeyEvent(ke);
View Full Code Here

        if (getShell() == null || getShell().isDisposed())
        {
          Display.getDefault().removeFilter(SWT.KeyDown, this);
          return;
        }
        KeyEvent ke = new KeyEvent(e);
        if (ke.keyCode == SWT.ALT || ke.keyCode == SWT.F10)
        {
          if (ke.keyCode == SWT.ALT) altKeyDown = true;
          nonAltKeyDown = false;
        }
        else
        {
          int ch = ke.keyCode;
          if (ch == 0) ch = ke.character;
          String pattern = "&" + (char) ch;
          if ((altKeyDown == true || trackItemIndex > -1) && popupMenu == null)
          {
            boolean flag = false;
            for (int i = 0; i < menu.getItemCount(); i++)
            {
              if (menu.getItem(i).getText().toLowerCase().indexOf(
                  pattern.toLowerCase()) > -1)
              {
                setSelection(i, true);
                Display.getDefault().asyncExec(new Runnable()
                {
                  public void run()
                  {
                    if (popupMenu != null) popupMenu.setSelection(0);
                  }
                });
                flag = true;
                break;
              }
            }
            if (!flag && ch < 256)
            {
              trackItemIndex = -1;
              refresh();
              altKeyDown = false;
              nonAltKeyDown = true;
              return;
            }
          }
          else if (popupMenu != null)
          {
            if (popupMenu.getCurrentMenu() != null) popupMenu.getCurrentMenu()
                .dealAltKeyEvent(ke);
            else
              popupMenu.dealAltKeyEvent(ke);
          }
          nonAltKeyDown = true;
        }
        if (ke.keyCode == KEY_RIGHT && trackItemIndex > -1)
        {
          if (popupMenu == null || popupMenu.getCurrentMenu() == null
              || popupMenu.getCurrentMenu().isSubMenuEnd())
          {
            refresh();
            int index = drawCommands.size();
            if (chevronStartItem != null) index = menu.indexOf(chevronStartItem) + 1;
            if (++trackItemIndex == index) trackItemIndex = 0;
            if (!selected)
            {
              refresh();
              drawCommand(trackItemIndex, true);
            }
            else
            {
              if (popupMenu != null)
              {
                popupMenu.hideMenu();
                popupMenu = null;
              }
              refresh();
              drawCommand(trackItemIndex, true);
              if (!isShowMenu() && selected)
              {
                final MenuDrawCommand command = (MenuDrawCommand) drawCommands
                    .get(trackItemIndex);
                Display.getDefault().asyncExec(new Runnable()
                {
                  public void run()
                  {
                    showMenu(command);
                  }
                });
              }
              return;
            }
          }
          else
          {
            popupMenu.getCurrentMenu().subMenuSelected();
          }
        }
        if (ke.keyCode == KEY_LEFT && trackItemIndex > -1)
        {
          if (popupMenu == null || popupMenu.getCurrentMenu() == null
              || popupMenu.getCurrentMenu() == popupMenu)
          {
            refresh();
            if (--trackItemIndex == -1)
            {
              if (chevronStartItem != null) trackItemIndex = menu
                  .indexOf(chevronStartItem);
              else
                trackItemIndex = drawCommands.size() - 1;
            }
            if (!selected)
            {
              refresh();
              drawCommand(trackItemIndex, true);
            }
            else
            {
              if (popupMenu != null)
              {
                popupMenu.hideMenu();
                popupMenu = null;
              }
              refresh();
              drawCommand(trackItemIndex, true);
              if (!isShowMenu() && selected)
              {
                final MenuDrawCommand command = (MenuDrawCommand) drawCommands
                    .get(trackItemIndex);
                Display.getDefault().asyncExec(new Runnable()
                {
                  public void run()
                  {
                    showMenu(command);
                  }
                });
              }
              return;
            }
          }
          else
          {
            popupMenu.getCurrentMenu().parentMenuSelected();
          }
        }
        if ((ke.keyCode == KEY_DOWN || ke.keyCode == KEY_UP) && trackItemIndex > -1)
        {
          if (!selected)
          {
            selected = true;
            refresh();
            if (!isShowMenu() && selected)
            {
              final MenuDrawCommand command = (MenuDrawCommand) drawCommands
                  .get(trackItemIndex);
              Display.getDefault().asyncExec(new Runnable()
              {
                public void run()
                {
                  showMenu(command);
                }
              });
            }
          }
          else
          {
            if (popupMenu != null)
            {
              if (popupMenu.getCurrentMenu() == null)
              {
                popupMenu.setSelection(0);
              }
              else
              {
                if (ke.keyCode == KEY_DOWN) popupMenu.getCurrentMenu()
                    .downSelected();
                else
                  popupMenu.getCurrentMenu().upSelected();
              }
            }
          }
        }
        if (ke.keyCode == SWT.ESC)
        {
          if (selected == false)
          {
            refresh();
            trackItemIndex = -1;
          }
          else
          {
            if (popupMenu == null || popupMenu.getCurrentMenu() == null
                || popupMenu.getCurrentMenu() == popupMenu)
            {
              selected = false;
              refresh();
              drawCommand(trackItemIndex, false);
              if (popupMenu != null)
              {
                popupMenu.hideMenu();
                popupMenu = null;
              }
            }
            else
            {
              popupMenu.getCurrentMenu().parentMenuSelected();
            }
          }
        }
        if (ke.keyCode == SWT.CR)
        {
          if (popupMenu != null && popupMenu.getCurrentMenu() != null)
          {
            popupMenu.getCurrentMenu().handleSelectedEvent();
          }
          else
          {
            if (popupMenu == null && trackItemIndex != -1 && selected == false)
            {
              selected = true;
              refresh();
              drawCommand(trackItemIndex, true);
              if (!isShowMenu() && selected)
              {
                showMenu((MenuDrawCommand) drawCommands.get(trackItemIndex));
              }
            }
          }
        }
      }
    };
    Display.getDefault().addFilter(SWT.KeyDown, keyDownListener);

    final Listener keyUpListener = new Listener()
    {

      public void handleEvent(Event e)
      {
        MenuHolder holder = MenuHolderManager.getActiveHolder();
        if (holder != null && holder != MenuBar.this) return;
        if (getShell() == null || getShell().isDisposed())
        {
          Display.getDefault().removeFilter(SWT.KeyUp, this);
          return;
        }
        KeyEvent ke = new KeyEvent(e);
        if ((ke.keyCode == SWT.ALT || ke.keyCode == SWT.F10) && !nonAltKeyDown)
        {
          if (drawCommands.size() > 0)
          {
            // If no item is currently tracked then...
View Full Code Here

        {
          Display.getDefault().removeFilter(SWT.KeyDown, this);
          e.doit = false;
          return;
        }
        KeyEvent ke = new KeyEvent(e);
        if ((ke.keyCode == SWT.ALT) || ke.keyCode == SWT.F10)
        {
          hideMenu();
          return;
        }
View Full Code Here

    fControlListener= new Listener() {
      public void handleEvent(Event e) {
        if (! getControl().isFocusControl())
          return; //SWT.TRAVERSE_MNEMONIC events can also come in to inactive widgets
        VerifyEvent verifyEvent= new VerifyEvent(e);
        KeyEvent keyEvent= new KeyEvent(e);
        switch (e.type) {
          case SWT.Traverse :

            if (DEBUG)
              dump("before traverse", e, verifyEvent); //$NON-NLS-1$
View Full Code Here

  private KeyEvent initPortsTextListener() {
    portsTextListener = new PortsTextValidationListener();
    Event ev = new Event();
    ev.widget = mock(Text.class);
    ev.doit = true;
    return new KeyEvent(ev);
  }
View Full Code Here

    return new KeyEvent(ev);
  }
 
  @Test
  public void portsTextTraversesOnTab() throws Exception {
    KeyEvent e = initPortsTextListener();
    e.keyCode = SWT.TAB;
    Shell shell = mock(Shell.class);
    when(((Control)e.getSource()).getShell()).thenReturn(shell);
    when(shell.traverse(SWT.TRAVERSE_TAB_NEXT)).thenReturn(true);

    portsTextListener.keyPressed(e);
    assertFalse(e.doit);
  }
View Full Code Here

    assertFalse(e.doit);
  }
 
  @Test
  public void portsTextTraversesOnEnter() throws Exception {
    KeyEvent e = initPortsTextListener();
    e.keyCode = SWT.CR;
    Shell shell = mock(Shell.class);
    when(((Control)e.getSource()).getShell()).thenReturn(shell);
    when(shell.traverse(SWT.TRAVERSE_RETURN)).thenReturn(true);

    portsTextListener.keyPressed(e);
    assertFalse(e.doit);
  }
View Full Code Here

    assertFalse(e.doit);
  }

  @Test
  public void portsTextInsertsNewLineOnCtrlEnter() throws Exception {
    KeyEvent e = initPortsTextListener();
    e.character = SWT.CR;
    e.keyCode = SWT.CR;
    e.stateMask = SWT.MOD1; // is Ctrl on most platforms
    when(((Text)e.widget).getText()).thenReturn("1,");
    when(((Text)e.widget).getCaretPosition()).thenReturn(2);
View Full Code Here

TOP

Related Classes of org.eclipse.swt.events.KeyEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.