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

The following examples show how to use org.eclipse.swt.SWT#MODIFIER_MASK . 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: tracecompass   File: Histogram.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void mouseDown(final MouseEvent event) {
    if (fScaledData != null && event.button == 1 && fDragState == DRAG_NONE &&
            (fDataModel.getNbEvents() != 0 || fDataModel.getStartTime() < fDataModel.getEndTime())) {
        fDragState = DRAG_SELECTION;
        fDragButton = event.button;
        if ((event.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
            if (Math.abs(event.x - fScaledData.fSelectionBeginBucket) < Math.abs(event.x - fScaledData.fSelectionEndBucket)) {
                fScaledData.fSelectionBeginBucket = fScaledData.fSelectionEndBucket;
                fSelectionBegin = fSelectionEnd;
            }
            fSelectionEnd = getTimestamp(event.x);
            fScaledData.fSelectionEndBucket = event.x;
        } else {
            fSelectionBegin = Math.min(getTimestamp(event.x), getEndTime());
            fScaledData.fSelectionBeginBucket = event.x;
            fSelectionEnd = fSelectionBegin;
            fScaledData.fSelectionEndBucket = fScaledData.fSelectionBeginBucket;
        }
        updateStatusLine(fSelectionBegin, fSelectionEnd, getTimestamp(event.x));
        fCanvas.redraw();
        fTimeLineScale.redraw();
    }
}
 
Example 2
private boolean isUniversalKey(VerifyEvent event) {
	
	boolean result = false;
	if (result= (event.character == triggerChar && event.stateMask == triggerMask)) {
		if (triggerChar == '-') {
			uprefix = getTrigger(event.keyCode,event.stateMask);
			result = false;
		} else if (result = (event.character == uTriggerChar && (event.stateMask  & SWT.MODIFIER_MASK) == uTriggerMask)) {
			// the universal reset value
			uprefix = getTrigger(event.keyCode,event.stateMask);
		}
	} else if (triggerMask == 0) {
		// likely invoked by M-x universal-argument or from kbd macro 
		if (result = (event.character == uTriggerChar && (event.stateMask & SWT.MODIFIER_MASK) == uTriggerMask)){
			updatePrefix(' ');
		}
	}
	return result;
}
 
Example 3
@Override
protected void fill(Control control, MouseEvent event, Point pt) {
    TimeGraphControl timeGraphControl = (TimeGraphControl) control;
    if ((event.stateMask & SWT.MODIFIER_MASK) != SWT.SHIFT) {
        ILinkEvent linkEvent = timeGraphControl.getArrow(pt);
        if (linkEvent != null) {
            fillValues(linkEvent);
        }
    }
    if (getTipComposite().getChildren().length == 0) {
        ITimeGraphEntry entry = timeGraphControl.getEntry(pt);
        if (entry == null) {
            return;
        }
        fillValues(pt, timeGraphControl, entry);
        Iterable<IMarkerEvent> markers = getMarkers(timeGraphControl, entry, pt);
        int i = 0;
        for (IMarkerEvent marker : markers) {
            fillValues(MARKER_CATEGORY_PREFIX + i, marker);
            i++;
        }
    }
}
 
Example 4
/**
 * Disable eclipse traversal event, and dispatch into our Alt/Ctrl
 * handlers in place of it
 * 
 * @param e the trapped TraverseEvent
 */
protected void handleTraverseEvent(TraverseEvent e) {
	// setting detail to NONE but doit=true disables further processing
	e.detail = SWT.TRAVERSE_NONE;
	e.doit = true;

	Event ee = new Event();
	ee.character = e.character;
	ee.doit = true;
	ee.stateMask = (e.stateMask & SWT.MODIFIER_MASK);
	ee.keyCode = e.keyCode;

	ee.display = e.display;
	ee.widget = e.widget;	// will throw an exception if not valid
	ee.time = e.time;
	ee.data = e.data;

	switch (ee.stateMask) {
		case SWT.CONTROL:	// Emacs+ key binding forces CTRL 
			dispatchCtrl(new VerifyEvent(ee));
			break;
		case SWT.ALT:	// AFAIK MOD3 is always ALT
			dispatchAlt(new VerifyEvent(ee));
			break;
	}
}
 
Example 5
/**
 * charEvent fragment: only allow numbers or edits & escapes
 * @param event
 */
protected void numCharEvent(VerifyEvent event) {
	event.doit = false;
	switch (event.character) {
	case 0x0D: // CR - execute command (if complete) \r
	case 0x1B: // ESC - another way to leave
	case 0x08: // BS
	case 0x7F: // DEL
		super.charEvent(event);
		break;
	default:
		if (checkAlt(event)) {
			// enable history events
			if (dispatchAlt(event)) {
				event.doit = false;
				break;
			}
		} else if ((Character.isDigit(event.character) && ((event.stateMask & SWT.MODIFIER_MASK) == 0)) || ('-' == event.character)) { 
			// accept if plain number or minus				
			super.charEvent(event);
		} else {
			beep();
		}
	}
}
 
Example 6
Source Project: e4macs   File: YesNoMinibuffer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Read a yes or no string
 * 
 * @see com.mulgasoft.emacsplus.minibuffer.WithMinibuffer#charEvent(org.eclipse.swt.events.VerifyEvent)
 */
protected void charEvent(VerifyEvent event) {
	event.doit = false;
	switch (event.character) {
	case 0x0D: // CR - execute command (if complete) \r
	case 0x1B: // ESC - another way to leave
	case 0x08: // BS
	case 0x7F: // DEL
		super.charEvent(event);
		break;
	default:
		if (immediately && (YESORNO_Y.equalsIgnoreCase(String.valueOf(event.character))  || YESORNO_N.equalsIgnoreCase(String.valueOf(event.character) ))) {
			// respond immediately to a character
			super.charEvent(event);
			executeCR(event);
		} else if (!immediately && Character.isLetter(event.character) && ((event.stateMask & SWT.MODIFIER_MASK) == 0)) {
			// accept if plain letter
			super.charEvent(event);
		} else {
			beep();
		}
	}
}
 
Example 7
@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 8
Source Project: BiglyBT   File: FilesView.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) {
		FilesViewMenuUtil.rename(tv, tv.getSelectedDataSources(true), true, false,false);
		e.doit = false;
	}
}
 
Example 9
@Override
public void mouseDown(MouseEvent event) {
    if (fScaledData != null && fDragState == DRAG_NONE && fDataModel.getStartTime() < fDataModel.getEndTime()) {
        if (event.button == 2 || (event.button == 1 && (event.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL)) {
            fDragState = DRAG_RANGE;
            fDragButton = event.button;
            int center = (int) (((fRangeStartTime + fRangeDuration / 2) - fScaledData.fFirstBucketTime) / fScaledData.fBucketDuration);
            fStartDelta = center - event.x;
            fMouseMoved = false;
            return;
        } else if (event.button == 3) {
            fDragState = DRAG_ZOOM;
            fDragButton = event.button;
            long time = Math.min(getTimestamp(event.x), getEndTime());
            if ((event.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
                if (time < fRangeStartTime + fRangeDuration / 2) {
                    fRangeStartTime = fRangeStartTime + fRangeDuration;
                }
            } else {
                fRangeStartTime = time;
            }
            fRangeDuration = time - fRangeStartTime;
            fCanvas.redraw();
            return;
        }
    }
    super.mouseDown(event);
}
 
Example 10
/**
 * @see com.mulgasoft.emacsplus.minibuffer.WithMinibuffer#noCharEvent(org.eclipse.swt.events.VerifyEvent)
 */
protected void noCharEvent(VerifyEvent event) {
	// process if unicode or more than just modifier keys
	if (((event.keyCode & SWT.KEYCODE_BIT) != 0) || (event.keyCode & SWT.MODIFIER_MASK) == 0) {
		if (processKey(event)) {
			leave();
		}
	} else {
		event.doit = false;
	}
}
 
Example 11
private void updateCursor(int x, int stateMask) {
    // if Wait cursor not active, check for the need to change the cursor
    if (getCursor() == fWaitCursor) {
        return;
    }
    Cursor cursor = null;
    if (fDragState == DRAG_SPLIT_LINE) {
    } else if (fDragState == DRAG_SELECTION) {
        cursor = fResizeCursor;
    } else if (fDragState == DRAG_TRACE_ITEM) {
        cursor = fDragCursor;
    } else if (fDragState == DRAG_ZOOM) {
        cursor = fZoomCursor;
    } else if ((stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
        cursor = fDragCursor;
    } else if ((stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
        cursor = fResizeCursor;
    } else if (!isOverSplitLine(x)) {
        long selectionBegin = fTimeProvider.getSelectionBegin();
        long selectionEnd = fTimeProvider.getSelectionEnd();
        int xBegin = getXForTime(selectionBegin);
        int xEnd = getXForTime(selectionEnd);
        if (Math.abs(x - xBegin) < SNAP_WIDTH || Math.abs(x - xEnd) < SNAP_WIDTH) {
            cursor = fResizeCursor;
        }
    }
    if (getCursor() != cursor) {
        setCursor(cursor);
    }
}
 
Example 12
Source Project: e4macs   File: UniversalHandler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private Event makeEvent(IUniversalResult ua) {
	Event result = new Event();
	KeySequence keys = ua.getTrigger();
	if (keys != null) {
		Trigger[] triggers = keys.getTriggers();
		if (triggers[0] instanceof KeyStroke) {	// really, all it can be anyway
			KeyStroke ks = (KeyStroke)triggers[triggers.length - 1];
			result.keyCode = ks.getNaturalKey();
			result.stateMask = ks.getModifierKeys() & SWT.MODIFIER_MASK;
		}
	}
	return result;
}
 
Example 13
private boolean altIsBeingHeld(MouseEvent event) {
   return ((event.stateMask & SWT.MODIFIER_MASK) == SWT.ALT);
}
 
Example 14
private boolean controlBeingHeld(MouseEvent event) {
   return ((event.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL);
}
 
Example 15
@Override
public void mouseScrolled(MouseEvent e) {
    if (fDragState != DRAG_NONE || e.count == 0) {
        return;
    }

    /*
     * On some platforms the mouse scroll event is sent to the control that has
     * focus even if it is not under the cursor. Handle the event only if over the
     * time graph control.
     */
    Point size = getSize();
    Rectangle bounds = new Rectangle(0, 0, size.x, size.y);
    if (!bounds.contains(e.x, e.y)) {
        return;
    }

    boolean horizontalZoom = false;
    boolean horizontalScroll = false;
    boolean verticalZoom = false;
    boolean verticalScroll = false;

    // over the time graph control
    if ((e.stateMask & SWT.MODIFIER_MASK) == (SWT.SHIFT | SWT.CTRL)) {
        verticalZoom = true;
    } else if (e.x < fTimeProvider.getNameSpace()) {
        // over the name space
        verticalScroll = true;
    } else {
        // over the state area
        if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
            // over the state area, CTRL pressed
            horizontalZoom = true;
        } else if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
            // over the state area, SHIFT pressed
            horizontalScroll = true;
        } else {
            // over the state area, no modifier pressed
            verticalScroll = true;
        }
    }
    if (verticalZoom) {
        fVerticalZoomAlignEntry = getVerticalZoomAlignCursor(e.y);
        verticalZoom(e.count > 0);
        if (fVerticalZoomAlignEntry != null) {
            setElementPosition(fVerticalZoomAlignEntry.getKey(), fVerticalZoomAlignEntry.getValue());
        }
    } else if (horizontalZoom && fTimeProvider.getTime0() != fTimeProvider.getTime1()) {
        zoom(e.count > 0);
    } else if (horizontalScroll) {
        horizontalScroll(e.count > 0);
    } else if (verticalScroll) {
        setTopIndex(getTopIndex() - e.count);
    }
}
 
Example 16
public void verifyKey(VerifyEvent event) {
	// any key press that is not a modifier combo ends the compound change
	final int maskWithoutShift= SWT.MODIFIER_MASK & ~SWT.SHIFT;
	if ((event.keyCode & SWT.MODIFIER_MASK) == 0 && (event.stateMask & maskWithoutShift) == 0)
		fireEndCompoundEdit();
}
 
Example 17
/**
 * @see com.mulgasoft.emacsplus.execute.IEmacsPlusConsoleKey#handleKey(org.eclipse.swt.events.VerifyEvent, org.eclipse.ui.console.TextConsoleViewer)
 */
public void handleKey(VerifyEvent event, TextConsoleViewer viewer) {

	// mask away any extraneous modifier characters for any direct equality tests. see SWT.MODIFIER_MASK
	int sm = event.stateMask & SWT.MODIFIER_MASK;
	if (viewer != null && (sm == 0 || sm == SWT.SHIFT)) {// && 'i' == event.character) {
		int offset;
		boolean reactivate = false;
		switch (event.character){
		case 'i':	// insert
		case 'y':
		case ' ':
			reactivate = true;
		case '\r':
		case '\n':
			event.doit = false;
			offset = getLineOffset(viewer);
			if (offset >= 0) {
				KilledText kill = offsetHash.get(offset);
				if (kill != null) {
					insertFromBrowseRing(kill.text);
				}
			}
			if (reactivate) {
				EmacsPlusConsole.getInstance().setFocus(false);
			}
			break;
		case 'n':	// next
			event.doit = false;
			browseRing(viewer,FORWARD);
			break;
		case 'p':	// previous
			event.doit = false;
			browseRing(viewer,BACKWARD);
			break;
		case 'g':	// refresh
			event.doit = false;
			updateBrowseRing();
			break;
		case 'q':	// quit
			activateEditor();
			break;
		case 'U':	// undo
			event.doit = false;
			undoEditor();
			break;
		}
	}
}
 
Example 18
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 19
private boolean isSpecial(VerifyEvent event) {
	return ((event.stateMask & SWT.MODIFIER_MASK) == 0 && 
			((event.keyCode == SWT.ALT ) || (event.keyCode == SWT.CTRL) || (event.keyCode == SWT.SHIFT)));
}
 
Example 20
Source Project: e4macs   File: WithMinibuffer.java    License: 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)));
}