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

The following examples show how to use org.eclipse.swt.SWT#COMMAND . 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: GuiMenuWidgets.java    From hop with Apache License 2.0 6 votes vote down vote up
public static int getAccelerator( KeyboardShortcut shortcut ) {
  int a = 0;
  a += shortcut.getKeyCode();
  if ( shortcut.isControl() ) {
    a += SWT.CONTROL;
  }
  if ( shortcut.isShift() ) {
    a += SWT.SHIFT;
  }
  if ( shortcut.isAlt() ) {
    a += SWT.ALT;
  }
  if ( shortcut.isCommand() ) {
    a += SWT.COMMAND;
  }
  return a;
}
 
Example 2
Source File: PyAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the modifier string for the given SWT modifier
 * modifier bits.
 *
 * @param stateMask the SWT modifier bits
 * @return the modifier string
 */
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 3
Source File: PyAction.java    From Pydev with 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 4
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with 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
 * @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 5
Source File: PeerCharacterCloser.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private boolean isModifierKey(int keyCode)
{
	// TODO Add more non alphanumeric keys we should skip!
	switch (keyCode)
	{
		case SWT.SHIFT:
		case SWT.BS:
		case SWT.CR:
		case SWT.DEL:
		case SWT.ESC:
		case SWT.LF:
		case SWT.TAB:
		case SWT.CTRL:
		case SWT.COMMAND:
		case SWT.ALT:
		case SWT.ARROW_DOWN:
		case SWT.ARROW_LEFT:
		case SWT.ARROW_RIGHT:
		case SWT.ARROW_UP:
			return true;
	}
	return false;
}
 
Example 6
Source File: KeyStateManager.java    From ldparteditor with MIT License 6 votes vote down vote up
private static String[] getStrings(int keyCode, int stateMask) {
    final boolean ctrlPressed = (stateMask & SWT.CTRL) != 0;
    final boolean altPressed = (stateMask & SWT.ALT) != 0;
    final boolean shiftPressed = (stateMask & SWT.SHIFT) != 0;
    final boolean cmdPressed = (stateMask & SWT.COMMAND) != 0;
    String[] s = new String[2];
    final StringBuilder sb = new StringBuilder();
    sb.append(keyCode);
    sb.append(ctrlPressed ? "+Ctrl" : ""); //$NON-NLS-1$//$NON-NLS-2$
    sb.append(altPressed ? "+Alt" : ""); //$NON-NLS-1$//$NON-NLS-2$
    sb.append(shiftPressed ? "+Shift" : ""); //$NON-NLS-1$//$NON-NLS-2$
    sb.append(cmdPressed ? "+Cmd" : ""); //$NON-NLS-1$//$NON-NLS-2$
    s[0] = sb.toString();
    Event event = new Event();
    event.keyCode = keyCode;
    if (ctrlPressed) event.stateMask = event.stateMask | SWT.CTRL;
    if (altPressed) event.stateMask = event.stateMask | SWT.ALT;
    if (shiftPressed) event.stateMask = event.stateMask | SWT.SHIFT;
    if (cmdPressed) event.stateMask = event.stateMask | SWT.COMMAND;
    s[1] = KeyBoardHelper.getKeyString(event);
    return s;
}
 
Example 7
Source File: KeyStateManager.java    From ldparteditor with MIT License 6 votes vote down vote up
/**
 * Sets the state of released and pressed keys
 *
 * @param keyCode
 *            the code to evaluate
 * @param isPressed
 *            {@code true} on {@code SWT.KeyDown} events
 */
public void setKeyState(int keyCode, boolean isPressed) {
    switch (keyCode) {
    case SWT.ALT:
        altPressed = isPressed;
        break;
    case SWT.SHIFT:
        shiftPressed = isPressed;
        break;
    case SWT.CTRL:
        ctrlPressed = isPressed;
        break;
    case SWT.COMMAND:
        cmdPressed = isPressed;
        break;
    }
}
 
Example 8
Source File: SWTKey.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public UIKeyCombination getCombination(int keyCode, int stateMask) {
	UIKeyCombination keyCombination = new UIKeyCombination();
	if((stateMask & keyCode) == 0) {
		if((stateMask & SWT.ALT) != 0) {
			keyCombination.getKeys().add(UIKey.ALT);
		}
		if((stateMask & SWT.SHIFT) != 0) {
			keyCombination.getKeys().add(UIKey.SHIFT);
		}
		if((stateMask & SWT.CONTROL) != 0) {
			keyCombination.getKeys().add(UIKey.CONTROL);
		}
		if((stateMask & SWT.COMMAND) != 0) {
			keyCombination.getKeys().add(UIKey.COMMAND);
		}
	}
	
	UIKey principalKey = this.getKey(keyCode);
	if(!keyCombination.contains(principalKey)) {
		keyCombination.getKeys().add(principalKey);
	}
	
	return keyCombination;
}
 
Example 9
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 10
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 11
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
public String toString() {
	String result = null;
	if (cmdId != null) {
		result = cmdId;
		if (params != null) {
			try {
				@SuppressWarnings("unchecked")
				Set<String> keySet = (Set<String>)params.keySet();
				for (String key : keySet) {
					result += ' ' + key + '=' + params.get(key);
				}
			} catch (Exception e) {}
		}
	} else if (event != null) {
		if (event.stateMask != 0) {
			char c = (char)event.keyCode;
			if ((event.stateMask & SWT.SHIFT) != 0) {
				char uc = Character.toUpperCase(c);
				if (c == uc) {
					result = SHIFT_STR + c;
				} else {
					result = Character.toString(uc);
				}
			} else {
				result = Character.toString(c);
			}
			result = ((event.stateMask & SWT.CTRL) == 0 ? EmacsPlusUtils.EMPTY_STR : CTRL_STR)
			+ ((event.stateMask & SWT.COMMAND) == 0 ? EmacsPlusUtils.EMPTY_STR : CMD_STR)
			+ ((event.stateMask & SWT.ALT) == 0 ? EmacsPlusUtils.EMPTY_STR : ALT_STR)
			+ result;
		} else {
			result = EmacsPlusUtils.normalizeCharacter(event.character);
		}
	} else if (isExit()) {
		result = EXIT_STR;
	}
	return result;
}
 
Example 12
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 13
Source File: KbdMacroExecuteHandler.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
	 * Create the Runnable for posting a key event
	 * 
	 * @param event
	 * @param editor
	 * @return the Runnable
	 */
	private Runnable getKeyRunner(final KbdEvent event, ITextEditor editor) {
		final KbdMacroExecuteHandler executeHandler = this;
		return new Runnable() {
			Event ee = event.getEvent();
			
			public void run() {
				if (executeHandler.isInterrupted()){
					return;
				}
				// to support internal Emacs+ control sequences in minibuffer commands:
				// The .post event ignores the stateMask, so force CTRL/ALT/Shift keys manually when required
				Event shiftless = null;
				Event ctrlless = null;
				Event altless = null;
				Event cmdless = null;
				Display display = PlatformUI.getWorkbench().getDisplay();
				try {
					if (ee.stateMask != 0) {
						if ((ee.stateMask & SWT.SHIFT) != 0){
							shiftless = KbdMacroExecuteHandler.this.maskEvent(SWT.SHIFT);
							display.post(shiftless);
						}			
						if ((ee.stateMask & SWT.CTRL) != 0) {
							ctrlless = KbdMacroExecuteHandler.this.maskEvent(SWT.CTRL);
							display.post(ctrlless);
						}
						if ((ee.stateMask & SWT.ALT) != 0) {
							altless = KbdMacroExecuteHandler.this.maskEvent(SWT.ALT);
							display.post(altless);
						}
						if ((ee.stateMask & SWT.COMMAND) != 0) {
							cmdless = KbdMacroExecuteHandler.this.maskEvent(SWT.COMMAND);
							display.post(cmdless);
						}
					}
					ee.doit = true;
					ee.type = SWT.KeyDown;					
					executeHandler.setKeyEvent(ee);
					display.post(ee);
//					System.out.println("post " + ee.character);					
				} finally {
					if (ee.stateMask != 0) {
						if (shiftless != null) {
							shiftless.type = SWT.KeyUp;
							shiftless.doit = true;
							display.post(shiftless);
						}
						if (ctrlless != null) {
							ctrlless.type = SWT.KeyUp;
							ctrlless.doit = true;
							display.post(ctrlless);
						}
						if (altless != null) {
							altless.type = SWT.KeyUp;
							altless.doit = true;
							display.post(altless);
						}
						if (cmdless != null) {
							cmdless.type = SWT.KeyUp;
							cmdless.doit = true;
							display.post(cmdless);
						}						
					}
				}
			}
		};		
	}
 
Example 14
Source File: KbdMacroExecuteHandler.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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));
}
 
Example 15
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Is this a Ctrl VerifyEvent we want to handle
 * 
 * @param event
 * @return true if yes, else false
 */
boolean checkControl(VerifyEvent event) {
	return (event.stateMask & SWT.CTRL) != 0 && ((event.stateMask & SWT.ALT) == 0 && (!isMac() || (event.stateMask & SWT.COMMAND) == 0))
	&& handlesCtrl();
}
 
Example 16
Source File: WithMinibuffer.java    From e4macs with 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 17
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Is this a Ctrl Alt VerifyEvent we want to handle
 * 
 * @param event
 * @return true if yes, else false
 */
boolean checkAltCtrl(VerifyEvent event) {
	int sm = event.stateMask & SWT.MODIFIER_MASK;
	return (sm == (SWT.ALT | SWT.CTRL) || (isMac() && sm == (SWT.COMMAND | SWT.CTRL)));
}