org.eclipse.swt.events.KeyEvent Java Examples

The following examples show how to use org.eclipse.swt.events.KeyEvent. 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: SceneGrip.java    From depan with 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 #2
Source File: ScrollView.java    From tracecompass with 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 #3
Source File: RichTextEditor.java    From nebula with 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 #4
Source File: FilterFreeFormComposite.java    From neoscada with 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 #5
Source File: Day.java    From nebula with 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 #6
Source File: MonthCalendar.java    From nebula with 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 #7
Source File: FilterAdvancedComposite.java    From neoscada with 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 File: FilterAdvancedComposite.java    From neoscada with 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 File: RichTextEditor.java    From nebula with 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 #10
Source File: StyledTextCellEditor.java    From statecharts with 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 #11
Source File: ParameterizeTextView.java    From http4e with 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 #12
Source File: Utils.java    From http4e with 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 #13
Source File: SceneGrip.java    From depan with 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 #14
Source File: CompletionProposalPopup.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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 #15
Source File: MovablePanningSelectionTool.java    From erflute with 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 #16
Source File: TableKeyShortcutAdapter.java    From logbook with MIT License 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    String[] header = this.header;

    if (this.header == null) {
        header = Stream.of(this.table.getColumns()).map(c -> c.getText()).toArray(String[]::new);
    }

    if ((e.stateMask == SWT.CTRL) && (e.keyCode == 'c')) {
        TableToClipboardAdapter.copyTable(header, this.table);
    }
    if ((e.stateMask == SWT.CTRL) && (e.keyCode == 'a')) {
        this.table.selectAll();
    }
}
 
Example #17
Source File: AbapGitView.java    From ADT_Frontend with 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 #18
Source File: ExecuteCommandPopup.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
        executeCommandFromList(-1);
    } else if (((e.stateMask & SWT.ALT) == 0) && ((e.stateMask & SWT.CTRL) == 0) && ((e.stateMask & SWT.SHIFT) == 0)) {
        if(e.keyCode >= '0' && e.keyCode <= '9') { //check digit
            executeCommandFromList(e.keyCode - '0');
        } else if(e.keyCode >= 'a' && e.keyCode <= 'z') { //check character
            executeCommandFromList((e.keyCode - 'a') + ('9' - '0' + 1));
        }
    } else {
        //Activator.logError("keyPressed", null);
    }
}
 
Example #19
Source File: HistogramTextControl.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
    switch (event.character) {
        case SWT.CR:
            updateValue();
            break;
        default:
            break;
    }
}
 
Example #20
Source File: SimpleConfigurator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Control createDialogArea(final Composite parent) {
	final Composite parentPanel = (Composite) super.createDialogArea(parent);
	setLayout(parentPanel);
	// ensure vertical layout
	((RowLayout) parentPanel.getLayout()).type = SWT.VERTICAL;
	((RowLayout) parentPanel.getLayout()).spacing = 3;

	final KeyAdapter adp = new KeyAdapter() {

		@Override
		public void keyReleased(final KeyEvent e) {
			/*
			 * I don't like having different ways of checking for keypad enter and the normal one. Using the keyCode
			 * would be better, but I couldn't readily find the value for CR.
			 */
			if (e.keyCode == SWT.KEYPAD_CR || e.character == SWT.CR) {
				refresh(); // makeActionDoStuff();
			}
		}
	};

	this.line.createControl(parentPanel, adp);
	this.fill.createControl(parentPanel, adp);
	this.point.createControl(parentPanel, adp, this.build);
	// this.label.createControl(parentPanel, adp);
	// this.minScale.createControl(parentPanel, adp);
	// this.maxScale.createControl(parentPanel, adp);

	final Composite replaceComp = subpart(parentPanel, "Replace");
	this.replace = new Button(replaceComp, SWT.CHECK);
	replace.addSelectionListener(synchronize);
	replace.setSelection(true);

	refresh();

	return parentPanel;
}
 
Example #21
Source File: HopGuiKeyHandler.java    From hop with 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 #22
Source File: TrackerView.java    From BiglyBT with 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 #23
Source File: SBC_TagsOverview.java    From BiglyBT with 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 #24
Source File: XtextStyledTextCellEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void keyReleaseOccured(KeyEvent keyEvent) {
	if (keyEvent.character == '\u001b') { // ESC
		return;
	}
	super.keyReleaseOccured(keyEvent);
}
 
Example #25
Source File: WorkspaceWizardPage.java    From eclipse with 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 #26
Source File: RecordToSourceCoupler.java    From tlaplus with MIT License 5 votes vote down vote up
public void keyReleased(final KeyEvent event) {
	final int code = event.keyCode;
	
	if (code == SWT.CR) {
		performSourceCoupling(viewer.getSelection(), ((event.stateMask & SWT.MOD1) != 0), false);
	} else if ((code == SWT.KEYPAD_DIVIDE) && ((event.stateMask & SWT.ALT) != 0) && (viewer instanceof TreeViewer)) {
		((TreeViewer) viewer).collapseAll();
	} else if (observeArrowKeyEvents.get() && ((code == SWT.ARROW_UP) || (code == SWT.ARROW_DOWN))
			&& (viewer instanceof TreeViewer)) {
		performSourceCoupling(viewer.getSelection(), false, true);
	}
}
 
Example #27
Source File: ExecuteKeyListener.java    From http4e with 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();
   }
}
 
Example #28
Source File: ListDialogField.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles key events in the table viewer. Specifically when the delete key
 * is pressed.
 */
protected void handleKeyPressed(KeyEvent event) {
	if (event.character == SWT.DEL && event.stateMask == 0) {
		if (fRemoveButtonIndex != -1
				&& isButtonEnabled(fTable.getSelection(),
						fRemoveButtonIndex)) {
			managedButtonPressed(fRemoveButtonIndex);
		}
	}
}
 
Example #29
Source File: MovablePanningSelectionTool.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean handleKeyUp(final KeyEvent event) {
    if (event.keyCode == SWT.SHIFT) {
        shift = true;
    }

    return super.handleKeyUp(event);
}
 
Example #30
Source File: RenameRefactoringPage.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void createTxtNewName(Composite composite) {
	txtNewName = new Text(composite, SWT.BORDER);
	txtNewName.setText(refactoringInfo.getSelectedIdentifier());
	txtNewName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	txtNewName.selectAll();
	txtNewName.addKeyListener( new KeyAdapter() {
		public void keyReleased( final KeyEvent e ) {
			refactoringInfo.setNewName( txtNewName.getText() );
			validate();
		}
	} );
}