Java Code Examples for org.eclipse.swt.events.KeyEvent

The following examples show how to use org.eclipse.swt.events.KeyEvent. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
 */
public void keyReleased(KeyEvent e)
{
	if (!Helper.okToUse(fProposalShell))
	{
		return;
	}

	if (e.character == 0 && e.keyCode == SWT.MOD1)
	{
		// http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
	        int index = fProposalTable.getSelectionIndex();
		if (index >= 0)
		{
	            selectProposal(index, false, true);
                }
		// else
		// {
		// fProposalTable.setTopIndex(0);
		// }
	}
}
 
Example 2
Source Project: nebula   Source File: MonthCalendar.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
 */
public void keyReleased(KeyEvent e) {
	Day day = (Day) e.widget;
	Point coordinates = day.getMonthPosition();
	e.data = new MonthCalendarSelectedDay(day.getDate(), coordinates);

	for (Iterator<KeyListener> keyListenersIter = keyListeners.iterator(); keyListenersIter.hasNext();) {
		KeyListener listener = (KeyListener) keyListenersIter.next();
		listener.keyReleased(e);
	}

	// No need for this logic here yet, but leaving it commented
	// as a reminder...

	// if (!e.doit) return;
}
 
Example 3
Source Project: nebula   Source File: Day.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
	switch (e.keyCode) {
		case SWT.ARROW_LEFT:
			if (monthPosition.x > 0) {
				traverse(SWT.TRAVERSE_TAB_PREVIOUS);
			}
			return;
		case SWT.ARROW_RIGHT:
			if (monthPosition.x < 6) {
				traverse(SWT.TRAVERSE_TAB_NEXT);
			}
			return;
		case SWT.TAB:
			if ((e.stateMask & SWT.SHIFT) != 0) {
				traverse(SWT.TRAVERSE_TAB_PREVIOUS);
				return;
			}
			traverse(SWT.TRAVERSE_TAB_NEXT);
			return;
	}
}
 
Example 4
Source Project: nebula   Source File: RichTextEditor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Notify the registered {@link KeyListener} that a key was pressed.
 *
 * @param event
 *            The event to fire.
 */
public void notifyKeyPressed(final KeyEvent event) {
	checkWidget();
	if (event == null) {
		return;
	}

	if (event.display != null) {
		event.display.asyncExec(new Runnable() {
			@Override
			public void run() {
				doNotifyKeyPressed(event);
			}
		});
	}
	else {
		// no display in the event, fire the events synchronously
		doNotifyKeyPressed(event);
	}
}
 
Example 5
Source Project: nebula   Source File: RichTextEditor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Notify the registered {@link KeyListener} that a key was released.
 *
 * @param event
 *            The event to fire.
 */
public void notifyKeyReleased(final KeyEvent event) {
	checkWidget();
	if (event == null) {
		return;
	}

	if (event.display != null) {
		event.display.asyncExec(new Runnable() {
			@Override
			public void run() {
				doNotifyKeyReleased(event);
			}
		});
	}
	else {
		// no display in the event, fire the events synchronously
		doNotifyKeyReleased(event);
	}
}
 
Example 6
Source Project: neoscada   Source File: FilterFreeFormComposite.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void createComponents ()
{
    final FillLayout layout = new FillLayout ( SWT.VERTICAL );
    layout.marginHeight = 12;
    layout.marginWidth = 12;
    setLayout ( layout );

    final Text filterTextField = new Text ( this, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL );
    filterTextField.setText ( this.filter );
    filterTextField.addKeyListener ( new KeyAdapter () {
        @Override
        public void keyReleased ( final KeyEvent e )
        {
            verifyFilter ( filterTextField.getText () );
        }
    } );
}
 
Example 7
Source Project: neoscada   Source File: FilterAdvancedComposite.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private Text createAttributeText ( final String attribute )
{
    final Text t = new Text ( this, SWT.BORDER );
    final Fields field = Fields.byField ( attribute );
    if ( field == null )
    {
        t.setEditable ( true );
        t.setMessage ( Messages.custom_field );
    }
    else
    {
        t.setEditable ( false );
        t.setText ( field.getName () );
    }
    t.addKeyListener ( new KeyAdapter () {
        @Override
        public void keyReleased ( final KeyEvent e )
        {
            AssertionComposite.this.orCondition.updateFilter ();
        };
    } );
    final RowData rowData = new RowData ();
    rowData.width = 132;
    t.setLayoutData ( rowData );
    return t;
}
 
Example 8
Source Project: neoscada   Source File: FilterAdvancedComposite.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private Text createValueText ()
{
    final Text t = new Text ( this, SWT.BORDER );
    t.setMessage ( Messages.argument );
    t.addKeyListener ( new KeyAdapter () {
        @Override
        public void keyReleased ( final KeyEvent e )
        {
            AssertionComposite.this.orCondition.updateFilter ();
        }
    } );
    final RowData rowData = new RowData ();
    rowData.width = 132;
    t.setLayoutData ( rowData );
    return t;
}
 
Example 9
Source Project: http4e   Source File: ParameterizeTextView.java    License: Apache License 2.0 6 votes vote down vote up
private StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
   final HConfiguration sourceConf = new HConfiguration(HContentAssistProcessor.PARAM_PROCESSOR);
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument1());

   sourceViewer.getControl().addKeyListener(new KeyAdapter() {

      public void keyPressed( KeyEvent e){
         // if ((e.character == ' ') && ((e.stateMask & SWT.CTRL) != 0)) {
         if (Utils.isAutoAssistInvoked(e)) {
            IContentAssistant ca = sourceConf.getContentAssistant(sourceViewer);
            ca.showPossibleCompletions();
         }
      }
   });

   return sourceViewer.getTextWidget();
}
 
Example 10
Source Project: http4e   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean isAutoAssistInvoked( KeyEvent e){
   if ((e.keyCode == 32) && ((e.stateMask & SWT.CTRL) != 0)) {
      return true;

   } else if (((e.keyCode == 32) && ((e.stateMask & SWT.COMMAND) != 0))) {
      return true;

   } else if ((e.character == ' ') && ((e.stateMask & SWT.CTRL) != 0)) {
      return true;

   } else if ((e.character == ' ') && ((e.stateMask & SWT.COMMAND) != 0)) {
      return true;

   }
   return false;

}
 
Example 11
Source Project: depan   Source File: SceneGrip.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
  switch (e.keyCode) {
    case SWT.SHIFT:
      this.keyShiftState = false;
      break;
    case SWT.CTRL:
      this.keyCtrlState = false;
      break;
    case SWT.ALT:
      this.keyAltState = false;
      break;
    default:
      break;
  }
}
 
Example 12
Source Project: depan   Source File: SceneGrip.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
  switch (event.keyCode) {
    case SWT.SHIFT:
      this.keyShiftState = true;
      break;
    case SWT.CTRL:
      this.keyCtrlState = true;
      break;
    case SWT.ALT:
      this.keyAltState = true;
      break;
    default:
      // uncaught key, transmit it to lower level for handling.
      scene.uncaughtKey(event, keyCtrlState, keyAltState,
          keyShiftState);
  }
}
 
Example 13
Source Project: statecharts   Source File: StyledTextCellEditor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Processes a key release event that occurred in this cell editor.
 * <p>
 * The <code>TextCellEditor</code> implementation of this framework method
 * ignores when the RETURN key is pressed since this is handled in
 * <code>handleDefaultSelection</code>. An exception is made for Ctrl+Enter
 * for multi-line texts, since a default selection event is not sent in this
 * case.
 * </p>
 * 
 * @param keyEvent
 *            the key event
 */
protected void keyReleaseOccured(KeyEvent keyEvent) {
	if (keyEvent.character == '\r') { // Return key
		// Enter is handled in handleDefaultSelection.
		// Do not apply the editor value in response to an Enter key event
		// since this can be received from the IME when the intent is -not-
		// to apply the value.
		// See bug 39074 [CellEditors] [DBCS] canna input mode fires bogus
		// event from Text Control
		//
		// An exception is made for Ctrl+Enter for multi-line texts, since
		// a default selection event is not sent in this case.
		if (text != null && !text.isDisposed()
				&& (text.getStyle() & SWT.MULTI) != 0) {
			if ((keyEvent.stateMask & SWT.CTRL) != 0) {
				super.keyReleaseOccured(keyEvent);
			}
		}
		return;
	}
	super.keyReleaseOccured(keyEvent);
}
 
Example 14
Source Project: tracecompass   Source File: ScrollView.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Add support for arrow key, scroll the ... scroll view. But you can
 * redefine this method for your convenience.
 *
 * @param event
 *            Keyboard event
 */
protected void keyPressedEvent(KeyEvent event) {
    switch (event.keyCode) {
    case SWT.ARROW_UP:
        scrollBy(0, -getVisibleHeight());
        break;
    case SWT.ARROW_DOWN:
        scrollBy(0, +getVisibleHeight());
        break;
    case SWT.ARROW_LEFT:
        scrollBy(-getVisibleWidth(), 0);
        break;
    case SWT.ARROW_RIGHT:
        scrollBy(+getVisibleWidth(), 0);
        break;
    default:
        break;
    }
}
 
Example 15
Source Project: hop   Source File: HopGuiKeyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void keyPressed( KeyEvent e ) {
  // TODO: allow for keyboard shortcut priorities for certain objects.
  //
  for ( Object parentObject : parentObjects ) {
    List<KeyboardShortcut> shortcuts = GuiRegistry.getInstance().getKeyboardShortcuts( parentObject.getClass().getName() );
    if (shortcuts!=null) {
      for ( KeyboardShortcut shortcut : shortcuts ) {
        if ( handleKey( parentObject, e, shortcut ) ) {
          return; // This key is handled.
        }
      }
    }
  }
}
 
Example 16
Source Project: hop   Source File: HopGuiKeyHandler.java    License: Apache License 2.0 5 votes vote down vote up
private boolean handleKey( Object parentObject, KeyEvent event, KeyboardShortcut shortcut ) {
  int keyCode = ( event.keyCode & SWT.KEY_MASK );
  boolean alt = ( event.stateMask & SWT.ALT ) != 0;
  boolean shift = ( event.stateMask & SWT.SHIFT ) != 0;
  boolean control = ( event.stateMask & SWT.CONTROL ) != 0;
  boolean command = ( event.stateMask & SWT.COMMAND ) != 0;

  boolean matchOS = Const.isOSX() == shortcut.isOsx();

  boolean keyMatch = keyCode == shortcut.getKeyCode();
  boolean altMatch = shortcut.isAlt() == alt;
  boolean shiftMatch = shortcut.isShift() == shift;
  boolean controlMatch = shortcut.isControl() == control;
  boolean commandMatch = shortcut.isCommand() == command;

  if ( matchOS && keyMatch && altMatch && shiftMatch && controlMatch && commandMatch ) {
    // This is the key: call the method to which the original key shortcut annotation belongs
    //
    try {
      Class<?> parentClass = parentObject.getClass();
      Method method = parentClass.getMethod( shortcut.getParentMethodName() );
      if ( method != null ) {
        method.invoke( parentObject );
        return true; // Stop looking after 1 execution
      }
    } catch ( Exception ex ) {
      LogChannel.UI.logError( "Error calling keyboard shortcut method on parent object " + parentObject.toString(), ex );
    }
  }
  return false;
}
 
Example 17
Source Project: hop   Source File: ControlSpaceKeyAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * PDI-1284 in chinese window, Ctrl-SPACE is reversed by system for input chinese character. use Ctrl-ALT-SPACE
 * instead.
 *
 * @param e
 * @return
 */
private boolean isHotKey( KeyEvent e ) {
  if ( System.getProperty( "user.language" ).equals( "zh" ) ) {
    return e.character == ' ' && ( ( e.stateMask & SWT.CONTROL ) != 0 ) && ( ( e.stateMask & SWT.ALT ) != 0 );
  } else if ( System.getProperty( "os.name" ).startsWith( "Mac OS X" ) ) {
    return e.character == ' ' && ( ( e.stateMask & SWT.MOD1 ) != 0 ) && ( ( e.stateMask & SWT.ALT ) == 0 );
  } else {
    return e.character == ' ' && ( ( e.stateMask & SWT.CONTROL ) != 0 ) && ( ( e.stateMask & SWT.ALT ) == 0 );
  }
}
 
Example 18
Source Project: nebula   Source File: InternalCompositeTable.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handle a keyPressed event on any row control.
 * 
 * @param sender
 *            The row that is sending the event
 * @param e
 *            the actual KeyEvent
 */
public void keyPressed(TableRow sender, KeyEvent e) {
	if (doMakeFocusedRowVisible()) return;
	
	if ((e.stateMask & SWT.CONTROL) != 0) {
		switch (e.keyCode) {
		case SWT.HOME:
               doFocusInitialRow();
			return;
		case SWT.END:
               doFocusLastRow();
			return;
		case SWT.INSERT:
               doInsertRow();
			return;
		case SWT.DEL:
               doDeleteRow();
			return;
		default:
			return;
		}
	}
	switch (e.keyCode) {
	case SWT.ARROW_UP:
           doRowUp();
		return;
	case SWT.ARROW_DOWN:
           doRowDown();
		return;
	case SWT.PAGE_UP:
           doPageUp();
		return;
	case SWT.PAGE_DOWN:
           doPageDown();
		return;
	}
}
 
Example 19
Source Project: nebula   Source File: AbstractSelectableRow.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void keyReleased(KeyEvent e) {
		// Don't want to hard-code key bindings.  Clients override this method?
		
//	      if (e.character == SWT.DEL && e.stateMask == 0) {
//	          deleteSelectedObject();
//	       }
//	       if (e.character == SWT.CR && e.stateMask == 0) {
//	          runDoubleClickOpenAction();
//	       }
	}
 
Example 20
Source Project: erflute   Source File: MovablePanningSelectionTool.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean handleKeyUp(KeyEvent event) {
    if (event.keyCode == SWT.SHIFT) {
        shift = true;
    }
    return super.handleKeyUp(event);
}
 
Example 21
Source Project: nebula   Source File: DayEditor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void keyReleased(KeyEvent e) {
	for (Iterator<KeyListener> i = keyListeners.iterator(); i.hasNext();) {
		KeyListener keyListener = i.next();
		keyListener.keyReleased(e);
		if (!e.doit)
			return;
	}
}
 
Example 22
Source Project: nebula   Source File: TimeSlot.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
	switch (e.keyCode) {
	case SWT.ARROW_LEFT:
		traverse(SWT.TRAVERSE_TAB_PREVIOUS);
		return;
	case SWT.ARROW_RIGHT:
		traverse(SWT.TRAVERSE_TAB_NEXT);
		return;
	}
}
 
Example 23
/**
 * Processes a key stroke while the info popup is up.
 * 
 * @param e
 *            the verify event describing the key stroke
 * @return <code>true</code> if processing can be stopped
 */
private boolean contextInfoPopupKeyPressed(KeyEvent e)
{
	char key = e.character;
	if (key == 0)
	{
		switch (e.keyCode)
		{
			case SWT.ARROW_LEFT:
			case SWT.ARROW_RIGHT:
			case SWT.ARROW_UP:
			case SWT.ARROW_DOWN:
				validateContextInformation();
				break;
			default:
				if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2
						&& e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
				{
					hideContextInfoPopup();
				}
				break;
		}

	}
	else if (key == SWT.ESC)
	{
		e.doit = false;
		hideContextInfoPopup();
	}
	else
	{
		validateContextInformation();
	}
	return true;
}
 
Example 24
Source Project: nebula   Source File: NebulaToolbar.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles key released event.
 * 
 * @param e KeyEvent
 */
private void handleKeyReleased(KeyEvent e)
{
	if (selectedItemIndex == -1)
	{
		return;
	}

	if (e.keyCode == ' ' || e.keyCode == SWT.CR || e.keyCode == SWT.LF || e.keyCode == SWT.KEYPAD_CR)
	{
		items[selectedItemIndex].setPushedDown(false);
		items[selectedItemIndex].setHovered(false);

		redraw();

		SelectionListener selectionListener = items[selectedItemIndex].getSelectionListener();

		if (selectionListener == null)
		{
			return;
		}

		Event event = new Event();
		event.widget = this;

		selectionListener.widgetSelected(new SelectionEvent(event));
	}
}
 
Example 25
/**
 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
 */
@Override
public void keyReleased(KeyEvent e) {
  if (e.widget == mTableViewer.getTable()) {
    if (e.character == SWT.DEL) {
      removePropertyItems();
    }
    if (e.character == ' ') {
      IStructuredSelection selection = (IStructuredSelection) mTableViewer.getSelection();

      ResolvableProperty prop = (ResolvableProperty) selection.getFirstElement();
      openPropertyItemEditor(prop);
    }
  }
}
 
Example 26
Source Project: ADT_Frontend   Source File: AbapGitView.java    License: MIT License 5 votes vote down vote up
private void addKeyListeners() {
	this.viewer.getTable().addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			//add key listener for text copy
			if (e.keyCode == KEY_STROKE_COPY.getNaturalKey() && e.stateMask == KEY_STROKE_COPY.getModifierKeys()) {
				copy();
			}
		}
	});
}
 
Example 27
Source Project: BiglyBT   Source File: TrackerView.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public TableViewSWT<TrackerPeerSource>
initYourTableView()
{
	registerPluginViews();

	tv = TableViewFactory.createTableViewSWT(
			PLUGIN_DS_TYPE,
			TableManager.TABLE_TORRENT_TRACKERS,
			getPropertiesPrefix(),
			basicItems,
			basicItems[0].getName(),
			SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL );

	tv.addLifeCycleListener(this);
	tv.addMenuFillListener(this);
	tv.addTableDataSourceChangedListener(this, true);
	tv.addSelectionListener(this, false);

	tv.addKeyListener(
		new KeyAdapter(){
			@Override
			public void
			keyPressed(
				KeyEvent e )
			{
				if ( e.stateMask == 0 && e.keyCode == SWT.DEL ){

					removeTrackerPeerSources(tv.getSelectedDataSources().toArray());
					
					e.doit = false;
				}
			}});
	
	return tv;
}
 
Example 28
Source Project: BiglyBT   Source File: SBC_TagsOverview.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	if (e.keyCode == SWT.F2 && (e.stateMask & SWT.MODIFIER_MASK) == 0) {
		Object[] selectedDataSources = tv.getSelectedDataSources(true);
		if (selectedDataSources.length == 1 && (selectedDataSources[0] instanceof Tag)) {
			Tag tag = (Tag) selectedDataSources[0];
			if (!tag.getTagType().isTagTypeAuto()) {
				TagUIUtils.openRenameTagDialog(tag);
				e.doit = false;
			}
		}
	}
}
 
Example 29
Source Project: eclipse   Source File: WorkspaceWizardPage.java    License: Apache License 2.0 5 votes vote down vote up
private void createTargetTextField() {
  target = new Text(container, SWT.BORDER);
  setAutoCompletion();
  target.addKeyListener(new KeyAdapter() {
    @Override
    public void keyReleased(KeyEvent ke) {
      if (ke.keyCode == '\r' && (ke.stateMask & SWT.SHIFT) != 0 && !target.getText().isEmpty()) {
        addTarget();
      }
    }
  });
  target.addModifyListener(e -> updateControls());
}
 
Example 30
Source Project: http4e   Source File: ExecuteKeyListener.java    License: Apache License 2.0 5 votes vote down vote up
public void keyReleased( KeyEvent e){
   // String string = "";// e.type == SWT.KeyDown ? "DOWN:" : "UP  :";
   // string += " stateMask=0x" + Integer.toHexString(e.stateMask) +
   // Snippet25.stateMask(e.stateMask) + ",";
   // string += " keyCode=0x" + Integer.toHexString(e.keyCode) + " " +
   // Snippet25.keyCode(e.keyCode) + ",";
   // string += " character=0x" + Integer.toHexString(e.character) + " " +
   // Snippet25.character(e.character);
   // if (e.keyLocation != 0) {
   // string += " location=";
   // if (e.keyLocation == SWT.LEFT)
   // string += "LEFT";
   // if (e.keyLocation == SWT.RIGHT)
   // string += "RIGHT";
   // if (e.keyLocation == SWT.KEYPAD)
   // string += "KEYPAD";
   //
   // }

   if ((e.stateMask & CTRL) != 0 && (e.stateMask & SHIFT) != 0 && e.keyCode == 'r') {
      // System.out.println(string);
      // model.fireExecute(new ModelEvent(ModelEvent.PARAMS_FOCUS_LOST,
      // model));
      // model.fireExecute(new ModelEvent(ModelEvent.REQUEST_START, model));
      cmd.execute();
   }
}