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

The following examples show how to use org.eclipse.swt.SWT#CTRL . 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: 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 2
Source File: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	showPreview = (event.stateMask & SWT.CTRL) != 0 && (event.character == SWT.CR || event.character == SWT.LF);
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position = model.findPosition(new LinkedPosition(document, offset, 0,
				LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					// skip backspace at beginning of linked position
					event.doit = false;
				}
			} else /* event.character == SWT.DEL */{
				if (offset + 1 > position.getOffset() + position.getLength()) {
					// skip delete at end of linked position
					event.doit = false;
				}
			}
		}
	}
	return null; // don't change behavior
}
 
Example 3
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 4
Source File: SWTUtils.java    From ccu-historian with 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 5
Source File: SwtAppleCommander.java    From AppleCommander with GNU General Public License v2.0 6 votes vote down vote up
public void handleEvent(Event event) {
	if (event.type == SWT.KeyUp && (event.stateMask & SWT.CTRL) != 0) {
		switch (event.character) {
			case 0x01:		// CTRL+A
				showAboutAppleCommander();
				break;
			case 0x03:		// CTRL+C
				createDiskImage();
				break;
			case 0x0f:		// CTRL+O
				openFile();
				break;
			case 0x05:		// CTRL+E
				compareDiskImages();
				break;
		}
	}		
}
 
Example 6
Source File: TableTextCellEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
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 7
Source File: SpringConfigurationStyledText.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
	if (e.stateMask == SWT.CTRL) {
		switch (e.keyCode) {
		case 'a':
		case 'A':
			selectAll();
			break;
		case 'z':
		case 'Z':
			undo();
			break;
		case 'y':
		case 'Y':
			redo();
			break;
		default:
			break;
		}
	}else if((e.stateMask & SWT.CTRL) >0 && (e.stateMask & SWT.SHIFT) > 0){
		switch (e.keyCode) {
		case '?':
		case '/':
			commentEventHandler();
			break;
		}
	}
}
 
Example 8
Source File: AbstractMouseSelectionAction.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void run(NatTable natTable, MouseEvent event) {
   	withShiftMask = (event.stateMask & SWT.SHIFT) != 0;
   	withControlMask = (event.stateMask & SWT.CTRL) != 0;

   	gridColumnPosition = natTable.getColumnPositionByX(event.x);
   	gridRowPosition = natTable.getRowPositionByY(event.y);

   	natTable.forceFocus();
}
 
Example 9
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 10
Source File: FileViewerWindow.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 11
Source File: CustomPreviewTable.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void keyPressed( KeyEvent event )
{
	if ( ( event.stateMask == SWT.CTRL )
			&& ( event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT ) )
	{
		scrollTable( cnvCells.getHorizontalBar( ), event );
	}
	else if ( event.keyCode == SWT.PAGE_UP
			|| event.keyCode == SWT.PAGE_DOWN
			|| ( ( event.stateMask == SWT.CTRL ) && ( event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN ) ) )
	{
		scrollTable( cnvCells.getVerticalBar( ), event );
	}

}
 
Example 12
Source File: CTextCellEditor.java    From birt with Eclipse Public License 1.0 5 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 13
Source File: FullTraceHistogram.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@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 14
Source File: TmfMouseDragProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void mouseDown(MouseEvent e) {
    if ((getChartViewer().getWindowDuration() != 0) && ((e.button == 2) || (e.button == 1 && (e.stateMask & SWT.CTRL) != 0))) {
        fStartPosition = e.x;
        fIsUpdate = true;
    }
}
 
Example 15
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 16
Source File: AbstractKeySelectAction.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public void run(NatTable natTable, KeyEvent event) {
	if (!isStateMaskSpecified) {
		this.shiftMask = (event.stateMask & SWT.SHIFT) != 0;
		this.controlMask = (event.stateMask & SWT.CTRL) != 0;
	}
}
 
Example 17
Source File: SDPrintDialogUI.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void contentsMouseDownEvent(MouseEvent event) {

    computeStepXY();
    int x1 = (int) ((event.x / fOverviewCanvas.getZoomValue()) / fStepX);
    int x2 = (int) ((event.y / fOverviewCanvas.getZoomValue()) / fStepY);

    int oldPage = fPageNum;

    fPageNum = x1 + x2 * getNbRow() + 1;

    if (fPageNum > maxNumOfPages()) {
        fPageNum = oldPage;
        return;
    }

    if (!fAreaSelection) {
        fFirstPage = fPageNum;
    }

    if ((fPageNum != -1) && (fMultiSelection)) {
        Arrays.sort(fPagesList);
        int pos = Arrays.binarySearch(fPagesList, fPageNum);
        if (pos < 0) {
            addToPagesList(fPageNum);
        } else {
            removeFromPagesList(fPageNum);
        }
    } else if ((fPageNum != -1) && (fAreaSelection) && (fFirstPage != -1)) {

        fPagesList = new int[0];

        int line1 = fFirstPage / getNbRow();
        int row1 = fFirstPage % getNbRow();
        if (row1 != 0) {
            line1++;
        } else {
            row1 = getNbRow();
        }

        int line2 = fPageNum / getNbRow();
        int row2 = fPageNum % getNbRow();
        if (row2 != 0) {
            line2++;
        } else {
            row2 = getNbRow();
        }

        int temp;
        if (line1 > line2) {
            temp = line2;
            line2 = line1;
            line1 = temp;
        }

        if (row1 > row2) {
            temp = row2;
            row2 = row1;
            row1 = temp;
        }

        for (int i = row1 - 1; i < row2; i++) {
            for (int j = line1 - 1; j < line2; j++) {
                addToPagesList(i + j * getNbRow() + 1);
            }
        }
    } else {
        fPagesList = new int[1];
        fPagesList[0] = fPageNum;
    }
    if ((event.stateMask & SWT.CTRL) != 0) {
        fMultiSelection = true;
    }
    displayPageNum();
    redraw();
}
 
Example 18
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@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 19
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean isQuoting(VerifyEvent event){
	return (event.data instanceof Character && (Character)event.data == QUOTING && (event.stateMask & SWT.CTRL) != 0);
}
 
Example 20
Source File: GLScene.java    From depan with Apache License 2.0 4 votes vote down vote up
/**
 * A key stroke was received by the OpenGL canvas but it wasn't used by the
 * previous layers.  Give someone else a chance to use it.
 * 
 * This is intended to be overridden, and {@code super.uncaughtKey()}
 * should be the final statement of such methods.  Normally, this is the
 * "last gasp" key handler.
 */
public void uncaughtKey(KeyEvent event,
    boolean keyCtrlState, boolean keyAltState, boolean keyShiftState) {

  switch (event.keyCode) {
    case SWT.ARROW_UP:
      if ((event.stateMask & SWT.CTRL) != 0) {
        rotateCamera(-0.5f, 0.0f, 0.0f);
      } else {
        pedestalCamera(-5.0f);
      }
      break;
    case SWT.ARROW_DOWN:
      if ((event.stateMask & SWT.CTRL) != 0) {
        rotateCamera(0.5f, 0.0f, 0.0f);
      } else {
        pedestalCamera(5.0f);
      }
      break;

    case SWT.ARROW_LEFT:
      if ((event.stateMask & SWT.CTRL) != 0) {
        rotateCamera(0.0f, 0.0f, -0.5f);
      } else {
        truckCamera(-5.0f);
      }
      break;
    case SWT.ARROW_RIGHT:
      if ((event.stateMask & SWT.CTRL) != 0) {
        rotateCamera(0.0f, 0.0f, 0.5f);
      } else {
        truckCamera(5.0f);
      }
      break;

    case SWT.PAGE_UP:
      zoomCamera(5.0f);
      break;
    case SWT.PAGE_DOWN:
      zoomCamera(-5.0f);
      break;
    case SWT.HOME:
      homeCamera();
      break;

    default:
      logUncaughtKey(event.keyCode, event.character, keyCtrlState, keyAltState, keyShiftState);
  }

}