예제 #1
0
파일: SWTEvents.java 프로젝트: xored/rcptt
 public Event createEvent(Widget w) {
   Event e = new Event();
   e.widget = w;
   e.display = display;
   e.time = (int) System.currentTimeMillis();
   return e;
 }
        public void mouseDown(MouseEvent e) {
          Event event = new Event();
          event.display = e.display;
          event.x = e.x;
          event.y = e.y;
          event.widget = content;
          event.time = e.time;

          SelectionEvent selection = new SelectionEvent(event);
          selectionListener.widgetSelected(selection);
        }
예제 #3
0
파일: SWTEvents.java 프로젝트: xored/rcptt
 public void sendEventRaw(final int event, Event e) {
   // Update timestamp if last was the same.
   if (e.time == 0) {
     e.time = (int) System.currentTimeMillis();
   }
   if (e.time == lastStamp) {
     e.time++;
   }
   lastStamp = e.time;
   e.widget.notifyListeners(event, e);
 }
예제 #4
0
  @Test
  public void testUntypedEventConstructor() {
    Event event = new Event();
    event.display = display;
    event.widget = mock(Widget.class);
    event.time = 9;
    event.data = new Object();

    TestTypedEvent typedEvent = new TestTypedEvent(event);

    assertSame(event.widget, typedEvent.getSource());
    EventTestHelper.assertFieldsEqual(typedEvent, event);
  }
예제 #5
0
파일: SWTEvents.java 프로젝트: xored/rcptt
 public Event createMouseEvent(
     Display display, Widget widget, int x, int y, int button, int stateMask, int count) {
   Event event = new Event();
   event.time = (int) System.currentTimeMillis();
   event.widget = widget;
   event.display = display;
   event.x = x;
   event.y = y;
   event.button = button;
   event.stateMask = stateMask;
   event.count = count;
   return event;
 }
  private static void click(final MenuItem menuItem) {
    final Event event = new Event();
    event.time = (int) System.currentTimeMillis();
    event.widget = menuItem;
    event.display = menuItem.getDisplay();
    event.type = SWT.Selection;

    UIThreadRunnable.asyncExec(
        menuItem.getDisplay(),
        new VoidResult() {
          public void run() {
            menuItem.notifyListeners(SWT.Selection, event);
          }
        });
  }
예제 #7
0
  void listEvent(Event event) {
    switch (event.type) {
      case SWT.Dispose:
        if (getShell() != popup.getParent()) {
          String[] items = list.getItems();
          int selectionIndex = list.getSelectionIndex();
          popup = null;
          list = null;
          createPopup(items, selectionIndex);
        }
        break;
      case SWT.FocusIn:
        {
          handleFocus(SWT.FocusIn);
          break;
        }
      case SWT.MouseUp:
        {
          if (event.button != 1) return;
          dropDown(false);
          break;
        }
      case SWT.Selection:
        {
          int index = list.getSelectionIndex();
          if (index == -1) return;
          text.setText(list.getItem(index));
          //    text.selectAll ();
          list.setSelection(index);
          //    list.forceFocus();

          Event e = new Event();
          e.time = event.time;
          e.stateMask = event.stateMask;
          e.doit = event.doit;
          notifyListeners(SWT.Selection, e);
          event.doit = e.doit;
          break;
        }
      case SWT.Traverse:
        {
          switch (event.detail) {
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_ESCAPE:
            case SWT.TRAVERSE_ARROW_PREVIOUS:
            case SWT.TRAVERSE_ARROW_NEXT:
              event.doit = false;
              break;
          }
          Event e = new Event();
          e.time = event.time;
          e.detail = event.detail;
          e.doit = event.doit;
          e.character = event.character;
          e.keyCode = event.keyCode;
          notifyListeners(SWT.Traverse, e);
          event.doit = e.doit;
          event.detail = e.detail;
          break;
        }
      case SWT.KeyUp:
        {
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyUp, e);
          break;
        }

      case SWT.KeyDown:
        {
          if (event.character == SWT.ESC) {
            // Escape key cancels popup list
            dropDown(false);
          }
          if ((event.stateMask & SWT.ALT) != 0
              && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) {
            dropDown(false);
          }
          if (event.character == SWT.CR) {
            // Enter causes default selection
            dropDown(false);
            Event e = new Event();
            e.time = event.time;
            e.stateMask = event.stateMask;
            notifyListeners(SWT.DefaultSelection, e);
          }
          // At this point the widget may have been disposed.
          // If so, do not continue.
          if (isDisposed()) break;
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyDown, e);
          break;
        }
    }
  }
예제 #8
0
  void textEvent(Event event) {
    switch (event.type) {
      case SWT.FocusIn:
        {
          handleFocus(SWT.FocusIn);
          break;
        }
      case SWT.KeyDown:
        {
          if (event.character == SWT.CR) {
            dropDown(false);
            Event e = new Event();
            e.time = event.time;
            e.stateMask = event.stateMask;
            notifyListeners(SWT.DefaultSelection, e);
          }
          // At this point the widget may have been disposed.
          // If so, do not continue.
          if (isDisposed()) break;

          if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) {
            event.doit = false;
            if ((event.stateMask & SWT.ALT) != 0) {
              boolean dropped = isDropped();
              text.selectAll();
              if (!dropped) setFocus();
              dropDown(!dropped);
              break;
            }

            int oldIndex = getSelectionIndex();
            if (event.keyCode == SWT.ARROW_UP && popup.isVisible()) {
              select(Math.max(oldIndex - 1, 0));
            } else if (popup.isVisible()) {
              select(Math.min(oldIndex + 1, getItemCount() - 1));
            }
            if (oldIndex != getSelectionIndex()) {
              Event e = new Event();
              e.time = event.time;
              e.stateMask = event.stateMask;
              notifyListeners(SWT.Selection, e);
            }
            // At this point the widget may have been disposed.
            // If so, do not continue.
            if (isDisposed()) break;
          }

          // Further work : Need to add support for incremental search in
          // pop up list as characters typed in text widget

          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyDown, e);
          break;
        }
      case SWT.KeyUp:
        {
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyUp, e);
          break;
        }
      case SWT.Modify:
        {
          list.deselectAll();
          Event e = new Event();
          e.time = event.time;
          notifyListeners(SWT.Modify, e);
          break;
        }

      case SWT.MouseDown:
        {
          if (event.button != 1) return;
          if (text.getEditable()) return;
          boolean dropped = isDropped();
          text.selectAll();
          if (!dropped) setFocus();
          dropDown(!dropped);
          break;
        }

      case SWT.MouseUp:
        {
          if (event.button != 1) return;
          if (text.getEditable()) return;
          text.selectAll();
          break;
        }

      case SWT.Traverse:
        {
          switch (event.detail) {
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_ARROW_PREVIOUS:
            case SWT.TRAVERSE_ARROW_NEXT:
              // The enter causes default selection and
              // the arrow keys are used to manipulate the list contents so
              // do not use them for traversal.
              event.doit = false;
              break;
          }

          Event e = new Event();
          e.time = event.time;
          e.detail = event.detail;
          e.doit = event.doit;
          e.character = event.character;
          e.keyCode = event.keyCode;
          notifyListeners(SWT.Traverse, e);
          event.doit = e.doit;
          event.detail = e.detail;
          break;
        }
    }
  }