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

The following examples show how to use org.eclipse.swt.SWT#ALT . 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 check out the related API usage on the sidebar.
Example 1
Source Project: openstock   File: SWTUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 2
Source Project: Pydev   File: PyAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Maps the localized modifier name to a code in the same
 * manner as #findModifier.
 *
 * @param modifierName the modifier name
 * @return the SWT modifier bit, or <code>0</code> if no match was found
 */
public static int findLocalizedModifier(String modifierName) {
    if (modifierName == null) {
        return 0;
    }

    if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.CTRL))) {
        return SWT.CTRL;
    }
    if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.SHIFT))) {
        return SWT.SHIFT;
    }
    if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.ALT))) {
        return SWT.ALT;
    }
    if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.COMMAND))) {
        return SWT.COMMAND;
    }

    return 0;
}
 
Example 3
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 4
Source Project: e4macs   File: SearchMinibuffer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.WithMinibuffer#handleKey(org.eclipse.swt.events.VerifyEvent)
 */
@Override
protected void handleKey(VerifyEvent event) {
	boolean isQuoting = quoting;
	try {
		if (isQuoting) {
			event.data = QUOTING;
		}
		if (event.keyCode != SWT.ALT) {
			// ignore naked alt
			setYanked(false);
		}
		setSearching(true);
		super.handleKey(event);
	} finally  {
		if (isQuoting){
			quoting = false;
		}
		setWasYanked(yanked);
		setSearching(false);
	}
}
 
Example 5
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 6
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 7
/**
 * Adapt the prefix display in the minibuffer to the actual key binding
 * 
 * @param keyCode
 * @param stateMask
 * @return the trigger string
 */
public String getTrigger(int keyCode, int stateMask) {
	StringBuilder result = new StringBuilder();
	String c = new String(Character.toChars(keyCode));
	switch (stateMask) {
	case SWT.CTRL:
		result.append(CPREFIX);
		result.append(c);
		break;
	case SWT.ALT:
		result.append(MPREFIX);
		result.append(c);
		break;
	case SWT.CTRL|SWT.ALT:
		result.append(CPREFIX);
		result.append(MPREFIX);
		result.append(c);
		break;
	default:
		result.append(KeyStroke.getInstance(stateMask,keyCode).format());
	}
	if (result.length() > 0) {
		result.append(' ');
	}
	return result.toString();
}
 
Example 8
/**
 * Maps the localized modifier name to a code in the same
 * manner as #findModifier.
 *
 * @param modifierName the modifier name
 * @return the SWT modifier bit, or <code>0</code> if no match was found
 * @since 2.1.1
 */
public static int findLocalizedModifier(String modifierName) {
	if (modifierName == null)
		return 0;

	if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.CTRL)))
		return SWT.CTRL;
	if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.SHIFT)))
		return SWT.SHIFT;
	if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.ALT)))
		return SWT.ALT;
	if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.COMMAND)))
		return SWT.COMMAND;

	return 0;
}
 
Example 9
/**
 * Returns the modifier string for the given SWT modifier
 * modifier bits.
 *
 * @param stateMask	the SWT modifier bits
 * @return the modifier string
 * @since 2.1.1
 */
public static String getModifierString(int stateMask) {
	String modifierString= ""; //$NON-NLS-1$
	if ((stateMask & SWT.CTRL) == SWT.CTRL)
		modifierString= appendModifierString(modifierString, SWT.CTRL);
	if ((stateMask & SWT.ALT) == SWT.ALT)
		modifierString= appendModifierString(modifierString, SWT.ALT);
	if ((stateMask & SWT.SHIFT) == SWT.SHIFT)
		modifierString= appendModifierString(modifierString, SWT.SHIFT);
	if ((stateMask & SWT.COMMAND) == SWT.COMMAND)
		modifierString= appendModifierString(modifierString,  SWT.COMMAND);

	return modifierString;
}
 
Example 10
Source Project: hop   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 11
/**
 * The toolbar command handler contains the global toolbar
 * actions. The intent is that the listener is then added to 
 * multiple visual components.
 */
public Listener createToolbarCommandHandler() {
	return new Listener() {
		public void handleEvent(Event event) {
			if (event.type == SWT.KeyUp) {
				if ((event.stateMask & SWT.CTRL) != 0) {	// CTRL+key
					switch (event.character) {
						case CTRL_C:
							getContentTypeAdapter().copy();
							break;
						case CTRL_A:
							getContentTypeAdapter().selectAll();
							break;
						case CTRL_P:
							getContentTypeAdapter().print();
							break;
					}
				} else if ((event.stateMask & SWT.ALT) == 0) { // key alone
					switch (event.keyCode) {
						case SWT.F2:	// the "native" file format (image, text, etc)
							getNativeFilterAdapter().display();
							setFilterToolItemSelection(true, false, false);
							break;
						case SWT.F3:	// Hex format
							getHexFilterAdapter().display();
							setFilterToolItemSelection(false, true, false);
							break;
						case SWT.F4:	// "Raw" hex format
							getRawDumpFilterAdapter().display();
							setFilterToolItemSelection(false, false, true);
							break;
					}
				}
			}
		}
	};
}
 
Example 12
Source Project: tlaplus   File: RecordToSourceCoupler.java    License: 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 13
@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 14
Source Project: e4macs   File: WithMinibuffer.java    License: Eclipse Public License 1.0 4 votes vote down vote up
protected void charEvent(VerifyEvent event) {

		switch (event.character) {

		case 0x0D: // CR - execute command (if complete) \r
			if (isQuoting(event)) {
				event.doit = false;
				dispatchCtrl(event);
				break;
			}
			executeCR(event);
			break;
		case 0x1B: // ESC - another way to leave
			// TODO - could also be ^[
			KbdMacroSupport.getInstance().exitWhenDefining();				
			leave(true);
			event.doit = false;
			break;

		case 0x08: // BS
			backSpaceChar(event);
			break;
		case 0x7F: // DEL
			deleteChar(event);
			break;
		case SWT.TAB: // disable after tab traversal interception
			if (handlesTab()){
				dispatchTab(event);
			}
			event.doit = false;
			break;
			//case '?': // ? completion disabled as its used as a simple wildcard
		case ' ': // space completion
			if (isCompleting()) {
				showCompletions();
				event.doit = false;
				break;
			}
		default:
			// If we're on a mac, then treat ALT & COMMAND the same in the minibuffer
			boolean ismac = isMac();
			// mask away any extraneous modifier characters for any direct equality tests. see SWT.MODIFIER_MASK
			// make ALT and COMMAND behave equivalently on the mac for Ctrl or Alt dispatch
			int sm = event.stateMask & SWT.MODIFIER_MASK;
			if (checkControl(event)) {
				if (dispatchCtrl(event)) {
					event.doit = false;
					break;
				} 
			} else if (checkAlt(event)) {
				if (dispatchAlt(event)) {
					event.doit = false;
					break;
				}
			} else if (checkAltCtrl(event) && dispatchAltCtrl(event)) {
					event.doit = false;
					break;
			} else {
				// SWT.ALT | SWT.CTRL covers AltGraph - used in international keyboards (see Eclipse bug 43049)
				// Also special chars on MacOs (see Eclipse bug 272994)					
				// Although, testing on a mac shows that the Option-<char>, comes in as keyCode == 0 and no modifiers
				boolean special = (ismac ? ((sm == (SWT.ALT | SWT.SHIFT)) || sm == SWT.ALT) : sm == (SWT.ALT | SWT.CTRL));
				// but if the key has a command binding associated, then leave and process 
				if (special && hasBinding(event)) {
					ITextEditor ed = editor;					
					leave();
					executeBinding(ed,event);
					event.doit = false;
				} else if (sm == 0 || sm == SWT.SHIFT || special) {
					event.doit = false;
					if (event.keyCode != 0 || (ismac && event.character != 0)) {
						addIt(event);
					}
				}
			}
		}
	}
 
Example 15
@Override
public void verifyKey(VerifyEvent event) {

    if (!event.doit)
        return;

    if (event.character == 0) {

        switch (event.keyCode) {

            case SWT.ARROW_DOWN:
                //special case: 
                //if there's a key dialog with a table shown, set its focus when down is pressed
                synchronized (lock) {
                    KeyAssistDialog tempKeyAssistDialog = this.keyAssistDialog;
                    if (tempKeyAssistDialog != null) {
                        Table completionsTable = this.keyAssistDialog.getCompletionsTable();
                        if (completionsTable != null && !completionsTable.isDisposed()) {
                            completionsTable.setFocus();
                            completionsTable.setSelection(0);
                            event.doit = false;
                            break;
                        }
                    }
                }
                // ALT, CTRL, ARROW_LEFT, ARROW_RIGHT == leave
            case SWT.ARROW_LEFT:
            case SWT.ARROW_RIGHT:
            case SWT.HOME:
            case SWT.END:
            case SWT.PAGE_DOWN:
            case SWT.PAGE_UP:
            case SWT.ARROW_UP:
                leave();
                break;

        }

        // event.character != 0
    } else {

        switch (event.character) {

        // ESC = quit
            case 0x1B:
                leave();
                event.doit = false;
                break;

            //CR = exec and quit
            case 0x0D:
                boolean executed = doExec();
                event.doit = false;
                if (!executed) {
                    return; //we don't want to update the status
                }
                break;

            // backspace    and delete
            case 0x08:
            case 0x7F:
                removeLastCharSearch();
                event.doit = false;
                break;

            default:
                if (event.stateMask == 0 || event.stateMask == SWT.SHIFT || event.stateMask == (SWT.ALT | SWT.CTRL)) { // SWT.ALT | SWT.CTRL covers AltGr (see bug 43049)
                    event.doit = false;
                    if (addCharSearch(event.character)) {
                        //ok, triggered some automatic action (does not need enter)
                        executed = doExec();
                        if (!executed) {
                            return; //we don't want to update the status
                        }

                    }
                }
                break;
        }
    }
    updateStatus();
}
 
Example 16
Source Project: e4macs   File: WithMinibuffer.java    License: Eclipse Public License 1.0 4 votes vote down vote up
protected void noCharEvent(VerifyEvent event) {

		switch (event.keyCode) {
		case SWT.CTRL:	
			if (handlesCtrl()) {
				break;
			}
			closeDialog();	// else close dialog and leave 
			leave();
			break;
		case SWT.ALT:
			if (handlesAlt()) {
				break;
			}
			closeDialog();	// else close dialog and leave 
			leave();
			break;
		case SWT.PAGE_DOWN:	// leave
		case SWT.PAGE_UP:
		case SWT.ARROW_DOWN:
		case SWT.ARROW_UP:
			leave();
			break;

			// minimal support for in line editing
		case SWT.HOME:
			getMB().toBegin();
			event.doit = false;
			break;

		case SWT.END:
			getMB().toEnd();
			event.doit = false;
			break;

		case SWT.ARROW_LEFT:
			getMB().toLeft();
			event.doit = false;
			break;

		case SWT.ARROW_RIGHT:
			getMB().toRight();			
			event.doit = false;
			break;
		}
	}
 
Example 17
Source Project: pentaho-kettle   File: JobGraph.java    License: Apache License 2.0 4 votes vote down vote up
public void keyPressed( KeyEvent e ) {

    // Delete
    if ( e.keyCode == SWT.DEL ) {
      List<JobEntryCopy> copies = jobMeta.getSelectedEntries();
      if ( copies != null && copies.size() > 0 ) {
        delSelected();
      }
    }

    if ( e.keyCode == SWT.F1 ) {
      spoon.browseVersionHistory();
    }

    // CTRL-UP : allignTop();
    if ( e.keyCode == SWT.ARROW_UP && ( e.stateMask & SWT.MOD1 ) != 0 ) {
      alligntop();
    }
    // CTRL-DOWN : allignBottom();
    if ( e.keyCode == SWT.ARROW_DOWN && ( e.stateMask & SWT.MOD1 ) != 0 ) {
      allignbottom();
    }
    // CTRL-LEFT : allignleft();
    if ( e.keyCode == SWT.ARROW_LEFT && ( e.stateMask & SWT.MOD1 ) != 0 ) {
      allignleft();
    }
    // CTRL-RIGHT : allignRight();
    if ( e.keyCode == SWT.ARROW_RIGHT && ( e.stateMask & SWT.MOD1 ) != 0 ) {
      allignright();
    }
    // ALT-RIGHT : distributeHorizontal();
    if ( e.keyCode == SWT.ARROW_RIGHT && ( e.stateMask & SWT.ALT ) != 0 ) {
      distributehorizontal();
    }
    // ALT-UP : distributeVertical();
    if ( e.keyCode == SWT.ARROW_UP && ( e.stateMask & SWT.ALT ) != 0 ) {
      distributevertical();
    }
    // ALT-HOME : snap to grid
    if ( e.keyCode == SWT.HOME && ( e.stateMask & SWT.ALT ) != 0 ) {
      snaptogrid( ConstUI.GRID_SIZE );
    }
    // CTRL-W or CTRL-F4 : close tab
    if ( ( e.keyCode == 'w' && ( e.stateMask & SWT.MOD1 ) != 0 )
      || ( e.keyCode == SWT.F4 && ( e.stateMask & SWT.MOD1 ) != 0 ) ) {
      spoon.tabCloseSelected();
    }
  }
 
Example 18
/**
 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
 */
public void keyPressed(KeyEvent e)
{
	// Only act on typed characters and ignore modifier-only events
	if (e.character == 0 && (e.keyCode & SWT.KEYCODE_BIT) == 0)
	{
		return;
	}

	if (e.character != 0 && (e.stateMask == SWT.ALT))
		return;

	// Only act on characters that are trigger candidates. This
	// avoids computing the model selection on every keystroke
	boolean validAssistLocation = false;

	if (computeAllAutoActivationTriggers().indexOf(e.character) < 0)
	{
		StyledText styledText = (StyledText) e.widget;
		validAssistLocation = isValidAutoAssistLocation(e, styledText);
		if (!validAssistLocation)
		{
			stop();
			return;
		}
	}

	int showStyle;
	int pos = fContentAssistSubjectControlAdapter.getSelectedRange().x;
	char[] activation;

	activation = fContentAssistSubjectControlAdapter.getCompletionProposalAutoActivationCharacters(
			ContentAssistant.this, pos);

	if ((contains(activation, e.character) || validAssistLocation) && !isProposalPopupActive())
	{
		showStyle = SHOW_PROPOSALS;
		fProposalPopup.setActivationKey(e.character);
	}
	else
	{
		activation = fContentAssistSubjectControlAdapter.getContextInformationAutoActivationCharacters(
				ContentAssistant.this, pos);
		if ((contains(activation, e.character) || validAssistLocation) && !isContextInfoPopupActive())
		{
			showStyle = SHOW_CONTEXT_INFO;
		}
		else
		{
			stop();
			return;
		}
	}

	if (fThread != null && fThread.isAlive())
	{
		reset(showStyle);
	}
	else
	{
		start(showStyle);
	}
}
 
Example 19
Source Project: e4macs   File: WithMinibuffer.java    License: Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Is this an Alt VerifyEvent we want to handle
 * 
 * @param event
 * @return true if yes, else false
 */
boolean checkAlt(VerifyEvent event) {
	return ((event.stateMask & SWT.ALT) != 0 || (isMac() && (event.stateMask & SWT.COMMAND) != 0)) && (event.stateMask & SWT.CTRL) == 0 
	&& handlesAlt();
}
 
Example 20
/**
 * Check if this is one of the manually CTRL/ALT/Command/Shift keys from the .post call above
 * keyCode is a simple state key and is included in contained event's stateMask
 * 
 * @param keyCode from the verify key event
 * @return true if it is ours
 */
private boolean isSpecial(int keyCode) {
	return (((keyCode == SWT.ALT ) || (keyCode == SWT.COMMAND ) || (keyCode == SWT.CTRL) || (keyCode == SWT.SHIFT)) && ((keyCode & stateMask) != 0));
}