Java Code Examples for org.eclipse.swt.SWT#MouseMove

The following examples show how to use org.eclipse.swt.SWT#MouseMove . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CTree.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void handleEvent(Event event) {
	switch (event.type) {
	case SWT.FocusIn:
	case SWT.FocusOut:
		handleFocus(event.type);
		break;
	case SWT.MouseDoubleClick:
	case SWT.MouseDown:
	case SWT.MouseMove:
	case SWT.MouseUp:
		handleMouseEvents(event);
		break;
	case SWT.Traverse:
		handleTraverse(event);
		break;
	}
}
 
Example 2
Source File: SWTSkinUtils.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleEvent(Event event) {
	Control control = (Control) event.widget;

	SWTSkinObject skinObject = (SWTSkinObject) control.getData("SkinObject");

	if (event.type == SWT.MouseMove) {
		if (bOver) {
			return;
		}
		System.out.println(System.currentTimeMillis() + ": " + skinObject
				+ "-- OVER");
		bOver = true;
		skinObject.switchSuffix("-over", 2, true);

	} else {
		bOver = false;
		System.out.println(System.currentTimeMillis() + ": " + skinObject
				+ "-- NOOVER");
		skinObject.switchSuffix("", 2, true);
	}

}
 
Example 3
Source File: SwtBotWorkbenchActions.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static void openPreferencesDialogViaEvents(SWTBot bot) {
  Display display = bot.getDisplay();
  Event event = new Event();

  // Move to the "Apple" menu item (it catches 0, 0)
  event.type = SWT.MouseMove;
  event.x = 0;
  event.y = 0;
  display.post(event);

  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Click
  event.type = SWT.MouseDown;
  event.button = 1;
  display.post(event);
  bot.sleep(SwtBotTestingUtilities.EVENT_DOWN_UP_DELAY_MS);
  event.type = SWT.MouseUp;
  display.post(event);

  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Right to the "Eclipse" menu item
  SwtBotTestingUtilities.sendKeyDownAndUp(bot, SWT.ARROW_RIGHT, '\0');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Down two to the "Preferences..." menu item
  SwtBotTestingUtilities.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  SwtBotTestingUtilities.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Press enter
  SwtBotTestingUtilities.sendKeyDownAndUp(bot, 0, '\r');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);
}
 
Example 4
Source File: SwtBotWorkbenchActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static void openPreferencesDialogViaEvents(SWTBot bot) {
  Display display = bot.getDisplay();
  Event ev = new Event();

  // Move to the "Apple" menu item (it catches 0, 0)
  ev.type = SWT.MouseMove;
  ev.x = 0;
  ev.y = 0;
  display.post(ev);

  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Click
  ev.type = SWT.MouseDown;
  ev.button = 1;
  display.post(ev);
  bot.sleep(SwtBotUtils.EVENT_DOWN_UP_DELAY_MS);
  ev.type = SWT.MouseUp;
  display.post(ev);

  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Right to the "Eclipse" menu item
  SwtBotUtils.sendKeyDownAndUp(bot, SWT.ARROW_RIGHT, '\0');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Down two to the "Preferences..." menu item
  SwtBotUtils.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  SwtBotUtils.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);

  // Press enter
  SwtBotUtils.sendKeyDownAndUp(bot, 0, '\r');
  bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS);
}
 
Example 5
Source File: Java2DDisplaySurface.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dispatchMouseEvent(final int swtMouseEvent) {
	final int x = mousePosition.x;
	final int y = mousePosition.y;
	for (final IEventLayerListener gl : listeners) {
		switch (swtMouseEvent) {
			case SWT.MouseDown:
				gl.mouseDown(x, y, 1);
				break;
			case SWT.MouseUp:
				gl.mouseUp(x, y, 1);
				break;
			case SWT.MouseMove:
				gl.mouseMove(x, y);
				break;
			case SWT.MouseEnter:
				gl.mouseEnter(x, y);
				break;
			case SWT.MouseExit:
				gl.mouseExit(x, y);
				break;
			case SWT.MenuDetect:
				gl.mouseMenu(x, y);
				break;
		}
	}
}
 
Example 6
Source File: FlatButton.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleEvent(final Event e) {
	switch (e.type) {
		case SWT.MouseExit:
			doHover(false);
			break;
		case SWT.MouseMove:
			break;
		case SWT.MouseEnter:
		case SWT.MouseHover:
			doHover(true);
			e.doit = true;
			break;
		case SWT.MouseUp:
			if (e.button == 1 && getClientArea().contains(e.x, e.y)) {
				doButtonUp();
			}
			break;
		case SWT.MouseDown:
			if (e.button == 1 && getClientArea().contains(e.x, e.y)) {
				doButtonDown();
			}
			break;
		default:
			;
	}
}
 
Example 7
Source File: SWTOpenGLDisplaySurface.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dispatchMouseEvent(final int swtMouseEvent) {
	final GamaPoint p = renderer.getCameraHelper().getMousePosition();
	final int x = (int) p.x;
	final int y = (int) p.y;
	for (final IEventLayerListener gl : listeners) {
		switch (swtMouseEvent) {
			case SWT.MouseDown:
				gl.mouseDown(x, y, 1);
				break;
			case SWT.MouseUp:
				gl.mouseUp(x, y, 1);
				break;
			case SWT.MouseMove:
				gl.mouseMove(x, y);
				break;
			case SWT.MouseEnter:
				gl.mouseEnter(x, y);
				break;
			case SWT.MouseExit:
				gl.mouseExit(x, y);
				break;
			case SWT.MenuDetect:
				gl.mouseMenu(x, y);
				break;
		}
	}
}
 
Example 8
Source File: InformationPresenterControlManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
    switch (event.type) {
        case SWT.Activate:
        case SWT.MouseVerticalWheel:
        case SWT.MouseUp:
        case SWT.MouseDown:
        case SWT.FocusOut:
            IInformationControl iControl = fInformationControl;
            if (iControl != null && !iControl.isFocusControl()) {
                hideInformationControl();
            }
            break;

        case SWT.MouseMove:
        case SWT.MouseEnter:
        case SWT.MouseExit:
            handleMouseMove(event);
            break;

        case SWT.KeyDown:
            if (event.keyCode == SWT.ESC) {
                hideInformationControl();

            } else if (fActivateEditorBinding != null
                    && KeyBindingHelper.matchesKeybinding(event.keyCode, event.stateMask,
                            fActivateEditorBinding)) {
                hideInformationControl(true, true);
            }
            break;
    }
}
 
Example 9
Source File: CTree.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void handleMouseEvents(Event event) {
		CTreeItem item = null;
		if (event.widget == body) {
			item = getItem(event.x, event.y);
		} else if (event.item instanceof CTreeItem) {
			item = (CTreeItem) event.item;
		}
		
		switch (event.type) {
		case SWT.MouseDoubleClick:
			if(item != null && (selectOnToggle || !item.isToggle(event.x, event.y))) {
				fireSelectionEvent(true);
			}
			break;
		case SWT.MouseDown:
			if(!hasFocus) setFocus();
			if(item == null) {
				if(event.widget == body) {
					item = getItem(event.x, event.y);
				} else if(event.item instanceof CTreeItem) {
					item = (CTreeItem) event.item;
				}
			}
			switch(event.button) {
			// TODO - popup menu: not just for mouse down events!
			case 3:
				Menu menu = getMenu();
				if ((menu != null) && ((menu.getStyle() & SWT.POP_UP) != 0)) {
					menu.setVisible(true);
				}
			case 1:
				if(selectOnToggle || !item.isToggle(event.x, event.y)) {
					if(selectOnTreeToggle || !item.isTreeToggle(event.x,event.y)) {
						if((event.stateMask & SWT.SHIFT) != 0) {
							if(shiftSel == null) {
								if(selection.isEmpty()) selection.add(item);
								shiftSel = (CTreeItem) selection.get(selection.size() - 1);
							}
							setSelection(shiftSel, item);
						} else if((event.stateMask & SWT.CONTROL) != 0) {
							toggleSelection(item);
							shiftSel = null;
						} else {
							setSelection(item);
							shiftSel = null;
						}
					}
				}
				break;
			}
			break;
		case SWT.MouseMove:
			// TODO: make toggles more dynamic
			break;
		case SWT.MouseUp:
			if(item.isToggle(event.x,event.y)) {
				boolean open = item.isOpen(event.x,event.y);
				if(item.isTreeToggle(event.x,event.y)) {
//					visibleItems = null;
					item.setExpanded(!open);
					fireTreeEvent(item, !open);
				} else {
					item.getCell(event.x, event.y).setOpen(!open);
				}
			}
			break;
		}

	}
 
Example 10
Source File: VTracker.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void handleEvent(Event event) {
	switch (event.type){
	case SWT.Traverse:
		lastTraverse = event.detail;
		if(SWT.TRAVERSE_TAB_NEXT == event.detail || SWT.TRAVERSE_TAB_PREVIOUS == event.detail) {
			if(focusControl != null) {
				event.doit = true;
				focusControl.handleEvent(event);
				if(event.doit) {
					Composite comp = focusControl.getWidget();
					if(SWT.TRAVERSE_TAB_NEXT == event.detail) {
						setFocusToNext(comp);
					} else {
						setFocusToPrev(comp);
					}
				}
			}
		}
		break;
	case SWT.FocusIn:
		setFocusControl(getVControl(event.widget));
		break;
	case SWT.MouseDown:
		mouseButton = event.button;
		mouseDown = new Point(event.x, event.y);
		if(activeControl != null && activeControl.setState(VControl.STATE_MOUSE_DOWN, true)) {
			activeControl.redraw();
		}
		break;
	case SWT.MouseMove:
		if(panels.containsKey(event.widget)) {
			VControl vcontrol = panels.get(event.widget).getControl(event.x, event.y, true);
			if(vcontrol != activeControl && (vcontrol == null || vcontrol.isEnabled())) {
				activate(vcontrol);
			}
		} else if(activeControl != null && event.widget != activeControl.getControl()) {
			activeControl.deactivate();
			activeControl = null;
		}
		break;
	case SWT.MouseUp:
		mouseButton = -1;
		mouseDown = null;
		if(activeControl != null && activeControl.setState(VControl.STATE_MOUSE_DOWN, false)) {
			activeControl.redraw();
		}
		break;
	}
}
 
Example 11
Source File: AnalogTimePicker.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void createContents() {
	setLayout(new BaseLayout());

	dialPanel = new VPanel(this, SWT.NONE);
	dialPanel.setLayout(new DialLayout());

	timeAmPm = new VButton(dialPanel, SWT.NO_FOCUS);
	timeAmPm.setText("PM"); //$NON-NLS-1$
	timeAmPm.setForeground(
			getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
	timeAmPm.setMargins(4, 4);
	timeAmPm.setEnabled(!dialPanel.hasStyle(CDT.READ_ONLY));
	tapl = event -> {
		if (event.widget == null) {
			Calendar tmpcal = cdt.getCalendarInstance();
			tmpcal.set(Calendar.AM_PM,
					tmpcal.get(Calendar.AM_PM) == 0 ? 1 : 0);
			setSelection(tmpcal.getTime());
			cdt.fireSelectionChanged(Calendar.AM_PM);
		}
	};
	timeAmPm.addListener(SWT.Selection, tapl);
	timeAmPm.addListener(SWT.MouseWheel, tapl);

	Listener listener = event -> {
		if (cdt.getEditable()) {
			switch (event.type) {
			case SWT.Deactivate:
				if (VTracker.isMouseDown()) {
					handleMouseUp();
					overHour = overMin = overSec = false;
					redraw();
				}
				break;
			case SWT.MouseDown:
				handleMouseDown();
				break;
			case SWT.MouseMove:
				handleMouseMove(event.x, event.y);
				break;
			case SWT.MouseUp:
				handleMouseUp();
				break;
			case SWT.MouseWheel:
				handleMouseWheel(event.count);
				break;
			}
		}
	};

	dialPanel.addListener(SWT.Deactivate, listener);
	dialPanel.addListener(SWT.MouseDown, listener);
	dialPanel.addListener(SWT.MouseMove, listener);
	dialPanel.addListener(SWT.MouseUp, listener);
	dialPanel.addListener(SWT.MouseWheel, listener);

	dialPanel.setPainter(new AnalogClockPainter(cdt, this));
}
 
Example 12
Source File: TableCombo.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 13
Source File: DragButtonMouseEvents.java    From codeexamples-eclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static void main(String[] args) {
  Display display = new Display();
  final Shell shell = new Shell(display);
  final Composite composite = new Composite(shell, SWT.NONE);
  composite.setEnabled(false);
  composite.setLayout(new FillLayout());
  Button button = new Button(composite, SWT.PUSH);
  button.setText("Button");
  composite.pack();
  composite.setLocation(10, 10);
  final Point[] offset = new Point[1];
  Listener listener = new Listener() {
    public void handleEvent(Event event) {
      switch (event.type) {
      case SWT.MouseDown:
        Rectangle rect = composite.getBounds();
        if (rect.contains(event.x, event.y)) {
          Point pt1 = composite.toDisplay(0, 0);
          Point pt2 = shell.toDisplay(event.x, event.y);
          offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y);
        }
        break;
      case SWT.MouseMove:
        if (offset[0] != null) {
          Point pt = offset[0];
          composite.setLocation(event.x - pt.x, event.y - pt.y);
        }
        break;
      case SWT.MouseUp:
        offset[0] = null;
        break;
      }
    }
  };
  shell.addListener(SWT.MouseDown, listener);
  shell.addListener(SWT.MouseUp, listener);
  shell.addListener(SWT.MouseMove, listener);
  shell.setSize(300, 300);
  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
      display.sleep();
  }
  display.dispose();
}
 
Example 14
Source File: TableCombo.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 15
Source File: FakeTooltip.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public void hide() {
	show = false;
	Event event = new Event();
	event.type = SWT.MouseMove;
	tableListener.handleEvent(event);
}