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

The following examples show how to use org.eclipse.swt.SWT#MouseDown . 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: AnnotationExpansionControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void defaultSelected(MouseEvent e) {
	if (fInput.fAnnotationListener != null) {
		Event swtEvent= new Event();
		swtEvent.type= SWT.MouseDown;
		swtEvent.display= e.display;
		swtEvent.widget= e.widget;
		swtEvent.time= e.time;
		swtEvent.data= e.data;
		swtEvent.x= e.x;
		swtEvent.y= e.y;
		swtEvent.button= e.button;
		swtEvent.stateMask= e.stateMask;
		swtEvent.count= e.count;
		VerticalRulerEvent event= new VerticalRulerEvent(fAnnotation, swtEvent);
		fInput.fAnnotationListener.annotationDefaultSelected(event);
	}

	dispose();
}
 
Example 2
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.MouseDown :
			int iRow = ( event.y - MARGIN ) / CELL_WIDTH;
			int iCol = ( event.x - MARGIN ) / CELL_HEIGHT;
			select( iRow, iCol );
			break;
		case SWT.KeyDown :
			processKeyDown( event.keyCode );
			break;

	}

	super.handleEvent( event );
}
 
Example 3
Source File: FillChooserComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.Paint :
			paintControl( new PaintEvent( event ) );
			break;
		case SWT.FocusIn :
			redraw( );
			break;
		case SWT.KeyDown :
			keyDown( event );
			break;
		case SWT.MouseDown :
			if ( !bEnabled )
			{
				return;
			}
			fireHandleEvent( MOUSE_CLICKED_EVENT );
			setColorToModel( this.getColorAt( event.x, event.y ) );
			cmpDropDown.getShell( ).close( );
			break;
	}

}
 
Example 4
Source File: ImportSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(Event event) {

  if (event.widget == addButton) {
    handleAdd();
  } else if (event.widget == removeButton) {
    handleRemove();
  } else if (event.widget == setDataPathButton) {
    handleSetDataPath();
  } else if (event.type == SWT.MouseDown && event.button == 3) {
    handleTableContextMenuRequest(event);
  } else if (event.type == SWT.MouseHover && !bDisableToolTipHelp) {
    handleTableHoverHelp(event);
  } else if (event.type == SWT.KeyUp) {
    if (event.character == SWT.DEL) {
      handleRemove();
    }
  } else if (event.widget == importTable && event.type == SWT.Selection) {
    enable();
  }
}
 
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: 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 7
Source File: AbstractVTestCase.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void mouseDown(int button) {
	mouseDowns.add(button);
	Event event = new Event();
	event.type = SWT.MouseDown;
	event.button = button;
	// event.stateMask = stateMask;
	// event.data = VTracker.getActiveControl();
	display.post(event);
	pause(delay);
}
 
Example 8
Source File: XViewerEditAdapter.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public XViewerEditAdapter(XViewerControlFactory factory, XViewerConverter converter) {
   this.factory = factory;
   this.converter = converter;
   this.orientationStyle = SWT.RIGHT;

   this.swtEvent = SWT.MouseDown;
}
 
Example 9
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 10
Source File: SWTSkinTabSet.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
private void addMouseListener(SWTSkinObject tab, Control control) {
	if (tabMouseListener == null) {
		tabMouseListener = new Listener() {
			boolean bDownPressed = false;

			@Override
			public void handleEvent(Event event) {
				if (event.type == SWT.MouseDown) {
					bDownPressed = true;
					return;
				} else if (!bDownPressed) {
					return;
				}

				bDownPressed = false;

				Control control = (Control) event.widget;
				setActiveTab((SWTSkinObjectTab) control.getData("Tab"), true);
			}
		};
	}

	control.setData("Tab", tab);
	control.addListener(SWT.MouseUp, tabMouseListener);
	control.addListener(SWT.MouseDown, tabMouseListener);

	if (control instanceof Composite) {
		Control[] children = ((Composite) control).getChildren();
		for (int i = 0; i < children.length; i++) {
			addMouseListener(tab, children[i]);
		}
	}
}
 
Example 11
Source File: Utils.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void addSafeMouseUpListener(Control control, Listener mouseDownListener,
		Listener mouseUpListener) {
	Listener l = new Listener() {
		boolean isMouseDown = false;

		@Override
		public void handleEvent(Event e) {
			switch (e.type) {
				case SWT.MouseDown:
					isMouseDown = true;
					if (mouseDownListener != null) {
						mouseDownListener.handleEvent(e);
					}
					break;
				case SWT.MouseExit:
					isMouseDown = false;
					break;
				case SWT.MouseUp:
					if (!isMouseDown) {
						return;
					}
					if (e.widget instanceof Control) {
						Point size = ((Control) e.widget).getSize();
						Rectangle bounds = new Rectangle(0, 0, size.x, size.y);
						
						if (!bounds.contains(e.x, e.y)) {
							return;
						}
					}
					mouseUpListener.handleEvent(e);
					break;
			}
		}
	};
	control.addListener(SWT.MouseDown, l);
	control.addListener(SWT.MouseUp, l);
	control.addListener(SWT.MouseExit, l);
}
 
Example 12
Source File: LineSeriesMarkerSheet.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void handleEventCanvasMarkers( Event event )
{
	switch ( event.type )
	{
		case SWT.KeyDown :
		{
			if ( event.keyCode == SWT.ARROW_LEFT )
			{
				if ( iSelectedIndex - 1 >= 0 )
				{
					iSelectedIndex--;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_RIGHT )
			{
				if ( iSelectedIndex + 1 < getMarkers( ).size( ) )
				{
					iSelectedIndex++;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_UP )
			{
				if ( iSelectedIndex - MARKER_ROW_MAX_NUMBER >= 0 )
				{
					iSelectedIndex -= MARKER_ROW_MAX_NUMBER;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_DOWN )
			{
				if ( iSelectedIndex + MARKER_ROW_MAX_NUMBER < getMarkers( ).size( ) )
				{
					iSelectedIndex += MARKER_ROW_MAX_NUMBER;
					setEnabledState( );
				}
			}
			
			else if ( event.keyCode == SWT.CR
					|| event.keyCode == SWT.KEYPAD_CR )
			{
				currentMarkerEditor.setFocus( );
			}
			else if ( event.keyCode == SWT.ESC )
			{
				cnvMarkers.getShell( ).close( );
			}
			break;
		}
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvMarkers.redraw( );
			}
			break;
		}
		case SWT.Paint :
			paintControl( new PaintEvent( event ) );
			break;
		case SWT.MouseDown :
			mouseDown( new MouseEvent( event ) );
			break;
	}
}
 
Example 13
Source File: CustomChooserComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void handleEventCanvasSelection( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusIn :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.FocusOut :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.KeyDown :
		{
			// 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 )
			{
				toggleDropDown( );
			}
			break;
		}
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_ESCAPE :
					getShell( ).close( );
					break;
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvSelection.redraw( );
			}
			break;
		}
		case SWT.MouseDown :
			toggleDropDown( );
			break;
	}
}
 
Example 14
Source File: DeviceTemplateChooser.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
private void createDeviceTemplateList2(SWTSkinObjectContainer soList) {
	DeviceTemplate[] devices = mf.getDeviceTemplates();

	if (devices.length == 0) {
		noDevices();
		return;
	}

	Arrays.sort(devices, new Comparator<DeviceTemplate>() {
		@Override
		public int compare(DeviceTemplate o1, DeviceTemplate o2) {
			return o1.getName().compareToIgnoreCase(o2.getName());
		}
	});

	Composite parent = soList.getComposite();
	if (parent.getChildren().length > 0) {
		Utils.disposeComposite(parent, false);
	}

	SWTSkin skin = skinnedDialog.getSkin();

	RowLayout layout = new RowLayout(SWT.HORIZONTAL);
	layout.spacing = 0;
	layout.marginLeft = layout.marginRight = 0;
	layout.wrap = true;
	layout.justify = true;
	layout.fill = true;
	parent.setLayout(layout);


	Listener clickListener = new Listener() {
		boolean down = false;

		@Override
		public void handleEvent(Event event) {
			if (event.type == SWT.MouseDown) {
				down = true;
			} else if (event.type == SWT.MouseUp && down) {
				Widget widget = (event.widget instanceof Label)
						? ((Label) event.widget).getParent() : event.widget;
				selectedDeviceTemplate = (DeviceTemplate) widget.getData("obj");
				if (selectedDeviceTemplate == null) {
					Debug.out("selectedDeviceTemplate is null!");
				}
				skinnedDialog.close();
				down = false;
			}
		}
	};

	for (DeviceTemplate deviceTemplate : devices) {
		if (deviceTemplate.isAuto()) {
			continue;
		}
		String iconURL = null; // deviceTemplate.getIconURL();
		TranscodeChooser.addImageBox(parent, clickListener, null, deviceTemplate,
				iconURL, deviceTemplate.getName());
	}

	SWTSkinObjectText soTitle = (SWTSkinObjectText) skin.getSkinObject("title");
	if (soTitle != null) {
		soTitle.setTextID("devices.choose.device.title");
	}

	SWTSkinObjectText soSubTitle = (SWTSkinObjectText) skin.getSkinObject("subtitle");
	if (soSubTitle != null) {
		soSubTitle.setTextID("label.clickone");
	}

	Shell shell = skinnedDialog.getShell();
	Point computeSize = shell.computeSize(shell.getSize().x, SWT.DEFAULT, true);
	shell.setSize(computeSize);
	UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
	if (uiFunctionsSWT != null) {
		Shell mainShell = uiFunctionsSWT.getMainShell();
		Utils.centerWindowRelativeTo(shell, mainShell);
	}
}
 
Example 15
Source File: CCombo.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructs a new instance of this class given its parent
 * and a style value describing its behavior and appearance.
 * <p>
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together 
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a widget which will be the parent of the new instance (cannot be null)
 * @param style the style of widget to construct
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 * </ul>
 *
 * @see SWT#BORDER
 * @see SWT#READ_ONLY
 * @see SWT#FLAT
 * @see Widget#getStyle()
 */
public CCombo (Composite parent, int style) {
	super (parent, style = checkStyle (style));
	
	int textStyle = SWT.SINGLE;
	if ((style & SWT.READ_ONLY) != 0) textStyle |= SWT.READ_ONLY;
	if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT;
	text = new Text (this, textStyle);
	int arrowStyle = SWT.ARROW | SWT.DOWN;
	if ((style & SWT.FLAT) != 0) arrowStyle |= SWT.FLAT;
	arrow = new Button (this, arrowStyle);

	listener = new Listener () {
		public void handleEvent (Event event) {
			if (popup == event.widget) {
				popupEvent (event);
				return;
			}
			if (text == event.widget) {
				textEvent (event);
				return;
			}
			if (list == event.widget) {
				listEvent (event);
				return;
			}
			if (arrow == event.widget) {
				arrowEvent (event);
				return;
			}
			if (CCombo.this == event.widget) {
				comboEvent (event);
				return;
			}

		}
	};
	
	
	int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize};
	for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
	
	int [] textEvents = {SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn, SWT.FocusOut};
	for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
	
	int [] arrowEvents = {SWT.Selection, SWT.FocusIn, SWT.FocusOut};
	for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
	
	createPopup(null, -1);
	initAccessible();
	
}
 
Example 16
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 17
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 18
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 19
Source File: BidiLayout.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void addListeners() {
	listener = new Listener() {

		@Override
		public void handleEvent(Event event) {
			switch (event.type) {
			case SWT.MouseDown: handleMouseDown(event); break;
			case SWT.KeyDown: handleKeyDown(event); break;
			}

		}
	};
	addAndReorderListener(SWT.KeyDown, listener);
	styledText.addListener(SWT.MouseDown, listener);
	addAndReorderListener(SWT.Show, listener);

	styledText.addKeyListener(new KeyListener() {
		@Override
		public void keyReleased(KeyEvent keyEvent) {
			if ((keyEvent.keyCode == 'u') &&
					((keyEvent.stateMask & SWT.CTRL) != 0)){
				setPush(true);
				keyEvent.doit = false;
			}else if ((keyEvent.keyCode == 'o') &&
					((keyEvent.stateMask & SWT.CTRL) != 0)) {
				setPush(false);
				keyEvent.doit = false;
			} else if ((keyEvent.keyCode == 't') &&
					((keyEvent.stateMask & SWT.CTRL) != 0)){
				switchAutoPush();
				keyEvent.doit = false;
			} else if (isPushMode && (keyEvent.keyCode == SWT.HOME || keyEvent.keyCode==SWT.END)){
				int carPos = getCaretOffset();
				setPush(false);
				setCaretOffset(carPos);
			}
		}

		@Override
		public void keyPressed(KeyEvent e) {
		}
	});
}
 
Example 20
Source File: MarkerEditorComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusOut :
			focusLost( new FocusEvent( event ) );
			break;

		case SWT.FocusIn:
			focusedComposite = event.widget;
			break;
			
		case SWT.MouseDown :
			mouseDown( new MouseEvent( event ) );
			break;

		case SWT.Selection :
			widgetSelected( new SelectionEvent( event ) );
			break;

		case SWT.KeyDown :
			if ( event.keyCode == SWT.ESC )
			{
				getShell( ).close( );
			}
			else if ( event.widget == cmpType )
			{
				int newIndex;
				if ( event.keyCode == SWT.ARROW_LEFT )
				{
					if ( markerTypeIndex - 1 >= 0 )
					{
						newIndex = markerTypeIndex - 1;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
				else if ( event.keyCode == SWT.ARROW_RIGHT )
				{
					if ( markerTypeIndex + 1 < typeNameSet.length )
					{
						newIndex = markerTypeIndex + 1;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
				else if ( event.keyCode == SWT.ARROW_UP )
				{
					if ( markerTypeIndex - MARKER_ROW_MAX_NUMBER >= 0 )
					{
						newIndex = markerTypeIndex
								- MARKER_ROW_MAX_NUMBER;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
				else if ( event.keyCode == SWT.ARROW_DOWN )
				{
					if ( markerTypeIndex + MARKER_ROW_MAX_NUMBER < typeNameSet.length )
					{
						newIndex = markerTypeIndex
								+ MARKER_ROW_MAX_NUMBER;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
			}
			break;

		case SWT.Traverse :
			// Indicates getting focus control rather than
			// cursor control
			if ( event.detail == SWT.TRAVERSE_TAB_NEXT
					|| event.detail == SWT.TRAVERSE_TAB_PREVIOUS )
			{
				event.doit = true;
				isPressingKey = true;
			}
			else if ( event.keyCode == getMnemonicByText( grpSize.getText( ) ) )
			{
				updateIsPressingKey( iscMarkerSize );
			}
			else if ( event.keyCode == getMnemonicByText( btnOutline.getButton( )
					.getText( ) ) )
			{
				updateIsPressingKey( btnOutline );
			}
			else if ( event.keyCode == getMnemonicByText( btnMarkerVisible.getButton( )
					.getText( ) ) )
			{
				updateIsPressingKey( btnMarkerVisible );
			}
	}
}