Java Code Examples for org.eclipse.swt.SWT#CONTROL
The following examples show how to use
org.eclipse.swt.SWT#CONTROL .
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 |
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: HistoryMinibuffer.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * 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 3
Source File: SWTKey.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
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 4
Source File: ControlSpaceKeyAdapter.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: HopGuiKeyHandler.java From hop with Apache License 2.0 | 5 votes |
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 6
Source File: CellSelectionDragMode.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void mouseDown(NatTable natTable, MouseEvent event) { natTable.forceFocus(); shiftMask = ((event.stateMask & SWT.SHIFT) == SWT.SHIFT); controlMask = ((event.stateMask & SWT.CONTROL) == SWT.CONTROL); fireSelectionCommand(natTable, natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y), shiftMask, controlMask); }
Example 7
Source File: CellSelectionDragMode.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void mouseDown(NatTable natTable, MouseEvent event) { natTable.forceFocus(); shiftMask = ((event.stateMask & SWT.SHIFT) == SWT.SHIFT); controlMask = ((event.stateMask & SWT.CONTROL) == SWT.CONTROL); fireSelectionCommand(natTable, natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y), shiftMask, controlMask); }
Example 8
Source File: SWTZoomListenerManager.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public void handleEvent(Event event) { if(!this.control.isIgnoreEvents()) { if((event.stateMask & SWT.CONTROL) == SWT.CONTROL) { event.doit = false; this.onZoom(new UIZoomEvent(this.control, (event.count > 0 ? 1 : -1))); } } }
Example 9
Source File: RangeSlider.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override public int getStyle() { return super.getStyle() | orientation | (isSmooth ? SWT.SMOOTH : SWT.NONE) | // (isOn ? SWT.ON : SWT.NONE) | // (isFullSelection ? SWT.CONTROL : SWT.NONE) | // (isHighQuality ? SWT.HIGH : SWT.NONE); }
Example 10
Source File: InternalCompositeTable.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Handle a keyPressed event on any row control. * * @param sender * The row that is sending the event * @param e * the actual KeyEvent */ public void keyPressed(TableRow sender, KeyEvent e) { if (doMakeFocusedRowVisible()) return; if ((e.stateMask & SWT.CONTROL) != 0) { switch (e.keyCode) { case SWT.HOME: doFocusInitialRow(); return; case SWT.END: doFocusLastRow(); return; case SWT.INSERT: doInsertRow(); return; case SWT.DEL: doDeleteRow(); return; default: return; } } switch (e.keyCode) { case SWT.ARROW_UP: doRowUp(); return; case SWT.ARROW_DOWN: doRowDown(); return; case SWT.PAGE_UP: doPageUp(); return; case SWT.PAGE_DOWN: doPageDown(); return; } }
Example 11
Source File: ControlSpaceKeyAdapter.java From hop with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: ClipboardCopy.java From BiglyBT with GNU General Public License v2.0 | 4 votes |
public static void addCopyToClipMenu( final Control control, final copyToClipProvider provider ) { MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY ); if ( ml != null ){ control.removeMouseListener( ml ); } ml = new MouseAdapter() { @Override public void mouseDown( MouseEvent e ) { if ( control.isDisposed()){ return; } final String text = provider.getText(); if ( control.getMenu() != null || text == null || text.length() == 0 ){ return; } if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){ return; } final Menu menu = new Menu(control.getShell(),SWT.POP_UP); MenuItem item = new MenuItem( menu,SWT.NONE ); item.setData( MENU_ITEM_KEY, "" ); String msg_text_id; if ( provider instanceof copyToClipProvider2 ){ msg_text_id = ((copyToClipProvider2)provider).getMenuResource(); }else{ msg_text_id = "label.copy.to.clipboard"; } item.setText( MessageText.getString( msg_text_id )); item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent arg0) { new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()}); } }); control.setMenu( menu ); menu.addMenuListener( new MenuAdapter() { @Override public void menuHidden( MenuEvent arg0 ) { if ( control.getMenu() == menu ){ control.setMenu( null ); } } }); menu.setVisible( true ); } }; control.setData( MOUSE_LISTENER_KEY, ml ); control.addMouseListener( ml ); }
Example 13
Source File: TableViewSWT_Common.java From BiglyBT with GNU General Public License v2.0 | 4 votes |
private void handleSearchKeyPress(KeyEvent e) { TableViewSWTFilter<?> filter = tv.getSWTFilter(); if (filter == null || e.widget == filter.widget) { return; } String newText = null; // normal character: jump to next item with a name beginning with this character if (ASYOUTYPE_MODE == ASYOUTYPE_MODE_FIND) { if (System.currentTimeMillis() - filter.lastFilterTime > 3000) newText = ""; } if (e.keyCode == SWT.BS) { if (e.stateMask == SWT.CONTROL) { newText = ""; } else if (filter.nextText.length() > 0) { newText = filter.nextText.substring(0, filter.nextText.length() - 1); } } else if ((e.stateMask & ~SWT.SHIFT) == 0 && e.character > 32 && e.character != SWT.DEL) { newText = filter.nextText + String.valueOf(e.character); } if (newText == null) { return; } if (ASYOUTYPE_MODE == ASYOUTYPE_MODE_FILTER) { if (filter != null && filter.widget != null && !filter.widget.isDisposed()) { filter.widget.setFocus(); } tv.setFilterText(newText); // } else { // TableCellCore[] cells = getColumnCells("name"); // // //System.out.println(sLastSearch); // // Arrays.sort(cells, TableCellImpl.TEXT_COMPARATOR); // int index = Arrays.binarySearch(cells, filter.text, // TableCellImpl.TEXT_COMPARATOR); // if (index < 0) { // // int iEarliest = -1; // String s = filter.regex ? filter.text : "\\Q" + filter.text + "\\E"; // Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE); // for (int i = 0; i < cells.length; i++) { // Matcher m = pattern.matcher(cells[i].getText()); // if (m.find() && (m.start() < iEarliest || iEarliest == -1)) { // iEarliest = m.start(); // index = i; // } // } // // if (index < 0) // // Insertion Point (best guess) // index = -1 * index - 1; // } // // if (index >= 0) { // if (index >= cells.length) // index = cells.length - 1; // TableRowCore row = cells[index].getTableRowCore(); // int iTableIndex = row.getIndex(); // if (iTableIndex >= 0) { // setSelectedRows(new TableRowCore[] { // row // }); // } // } // filter.lastFilterTime = System.currentTimeMillis(); } e.doit = false; }
Example 14
Source File: JaretTable.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * Handle any key presses. * * @param event key event */ private void handleKeyPressed(KeyEvent event) { if ((event.stateMask & SWT.SHIFT) != 0 && Character.isISOControl(event.character)) { switch (event.keyCode) { case SWT.ARROW_RIGHT: selectRight(); break; case SWT.ARROW_LEFT: selectLeft(); break; case SWT.ARROW_DOWN: selectDown(); break; case SWT.ARROW_UP: selectUp(); break; default: // do nothing break; } } else if ((event.stateMask & SWT.CONTROL) != 0 && Character.isISOControl(event.character)) { // TODO keybindings hard coded is ok for now // System.out.println("keycode "+event.keyCode); switch (event.keyCode) { case 'c': copy(); break; case 'x': cut(); break; case 'v': paste(); break; case 'a': selectAll(); break; default: // do nothing break; } } else { _lastKeySelect = null; _firstKeySelect = null; switch (event.keyCode) { case SWT.ARROW_RIGHT: focusRight(); break; case SWT.ARROW_LEFT: focusLeft(); break; case SWT.ARROW_DOWN: focusDown(); break; case SWT.ARROW_UP: focusUp(); break; case SWT.TAB: focusRight(); break; case SWT.F2: // startEditing(_focussedRow, _focussedColumn, (char) 0); break; default: if (event.character == ' ' && isHierarchyColumn(_focussedRow, _focussedColumn)) { toggleExpanded(_focussedRow); } else if (!Character.isISOControl(event.character)) { // startEditing(event.character); } // do nothing break; } } }
Example 15
Source File: RangeSlider.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Constructs a new instance of this class given its parent and a style value * describing its behavior and appearance. * <p> * The style value is either one of the style constants defined in class * <code>SWT</code> which is applicable to instances of this class, or must be * built by <em>bitwise OR</em>'ing together (that is, using the * <code>int</code> "|" operator) two or more of those <code>SWT</code> style * constants. The class description lists the style constants that are * applicable to the class. Style bits are also inherited from superclasses. * </p> * * @param parent a composite control which will be the parent of the new * instance (cannot be null) * @param style the style of control to construct. Default style is HORIZONTAL * * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the * thread that created the parent</li> * </ul> * @see SWT#HORIZONTAL * @see SWT#VERTICAL * @see Widget#getStyle * */ public RangeSlider(final Composite parent, final int style) { super(parent, SWT.DOUBLE_BUFFERED | ((style & SWT.BORDER) == SWT.BORDER ? SWT.BORDER : SWT.NONE)); minimum = lowerValue = 0; maximum = upperValue = 100; listeners = new ArrayList<SelectionListener>(); increment = 1; pageIncrement = 10; slider = SWTGraphicUtil.createImageFromFile("images/slider-normal.png"); sliderHover = SWTGraphicUtil.createImageFromFile("images/slider-hover.png"); sliderDrag = SWTGraphicUtil.createImageFromFile("images/slider-drag.png"); sliderSelected = SWTGraphicUtil.createImageFromFile("images/slider-selected.png"); vSlider = SWTGraphicUtil.createImageFromFile("images/h-slider-normal.png"); vSliderHover = SWTGraphicUtil.createImageFromFile("images/h-slider-hover.png"); vSliderDrag = SWTGraphicUtil.createImageFromFile("images/h-slider-drag.png"); vSliderSelected = SWTGraphicUtil.createImageFromFile("images/h-slider-selected.png"); if ((style & SWT.VERTICAL) == SWT.VERTICAL) { orientation = SWT.VERTICAL; } else { orientation = SWT.HORIZONTAL; } isSmooth = (style & SWT.SMOOTH) == SWT.SMOOTH; isFullSelection = (style & SWT.CONTROL) == SWT.CONTROL; isHighQuality = (style & SWT.HIGH) == SWT.HIGH; isOn = (style & SWT.ON) == SWT.ON; selectedElement = isFullSelection ? BOTH : LOWER; addListener(SWT.Dispose, event -> { SWTGraphicUtil.safeDispose(slider); SWTGraphicUtil.safeDispose(sliderHover); SWTGraphicUtil.safeDispose(sliderDrag); SWTGraphicUtil.safeDispose(sliderSelected); SWTGraphicUtil.safeDispose(vSlider); SWTGraphicUtil.safeDispose(vSliderHover); SWTGraphicUtil.safeDispose(vSliderDrag); SWTGraphicUtil.safeDispose(vSliderSelected); }); addMouseListeners(); addListener(SWT.Resize, event -> { if (isHighQuality) { setTickFactors(); } else { tickFactor = ((orientation == SWT.HORIZONTAL ? getClientArea().width : getClientArea().height) - 20f) / tickDivisions; } }); addListener(SWT.FocusIn, e -> { hasFocus = true; redraw(); }); addListener(SWT.FocusOut, e -> { hasFocus = false; redraw(); }); addListener(SWT.KeyDown, event -> { handleKeyDown(event); }); addPaintListener(event -> { drawWidget(event); }); }
Example 16
Source File: ColumnReorderDragMode.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
protected void selectDragFocusColumn(ILayer natLayer, MouseEvent event, int focusedColumnPosition) { boolean shiftMask = (SWT.SHIFT & event.stateMask) != 0; boolean controlMask = (SWT.CONTROL & event.stateMask) != 0; natLayer.doCommand(new ViewportSelectColumnCommand(natLayer, focusedColumnPosition, shiftMask, controlMask)); }
Example 17
Source File: JaretTable.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Handle any key presses. * * @param event key event */ private void handleKeyPressed(KeyEvent event) { if ((event.stateMask & SWT.SHIFT) != 0 && Character.isISOControl(event.character)) { switch (event.keyCode) { case SWT.ARROW_RIGHT: selectRight(); break; case SWT.ARROW_LEFT: selectLeft(); break; case SWT.ARROW_DOWN: selectDown(); break; case SWT.ARROW_UP: selectUp(); break; default: // do nothing break; } } else if ((event.stateMask & SWT.CONTROL) != 0 && Character.isISOControl(event.character)) { // TODO keybindings hard coded is ok for now // System.out.println("keycode "+event.keyCode); switch (event.keyCode) { case 'c': copy(); break; case 'x': cut(); break; case 'v': paste(); break; case 'a': selectAll(); break; default: // do nothing break; } } else { _lastKeySelect = null; _firstKeySelect = null; switch (event.keyCode) { case SWT.ARROW_RIGHT: focusRight(); break; case SWT.ARROW_LEFT: focusLeft(); break; case SWT.ARROW_DOWN: focusDown(); break; case SWT.ARROW_UP: focusUp(); break; case SWT.TAB: focusRight(); break; case SWT.F2: // startEditing(_focussedRow, _focussedColumn, (char) 0); break; default: if (event.character == ' ' && isHierarchyColumn(_focussedRow, _focussedColumn)) { toggleExpanded(_focussedRow); } else if (!Character.isISOControl(event.character)) { // startEditing(event.character); } // do nothing break; } } }
Example 18
Source File: CTree.java From nebula with Eclipse Public License 2.0 | 4 votes |
protected void handleMouseEvents(Event event) { CTreeItem item = null; if (event.widget == body) { item = getItem(event.x, event.y); } else if (event.item instanceof CTreeItem) { item = (CTreeItem) event.item; } switch (event.type) { case SWT.MouseDoubleClick: if(item != null && (selectOnToggle || !item.isToggle(event.x, event.y))) { fireSelectionEvent(true); } break; case SWT.MouseDown: if(!hasFocus) setFocus(); if(item == null) { if(event.widget == body) { item = getItem(event.x, event.y); } else if(event.item instanceof CTreeItem) { item = (CTreeItem) event.item; } } switch(event.button) { // TODO - popup menu: not just for mouse down events! case 3: Menu menu = getMenu(); if ((menu != null) && ((menu.getStyle() & SWT.POP_UP) != 0)) { menu.setVisible(true); } case 1: if(selectOnToggle || !item.isToggle(event.x, event.y)) { if(selectOnTreeToggle || !item.isTreeToggle(event.x,event.y)) { if((event.stateMask & SWT.SHIFT) != 0) { if(shiftSel == null) { if(selection.isEmpty()) selection.add(item); shiftSel = (CTreeItem) selection.get(selection.size() - 1); } setSelection(shiftSel, item); } else if((event.stateMask & SWT.CONTROL) != 0) { toggleSelection(item); shiftSel = null; } else { setSelection(item); shiftSel = null; } } } break; } break; case SWT.MouseMove: // TODO: make toggles more dynamic break; case SWT.MouseUp: if(item.isToggle(event.x,event.y)) { boolean open = item.isOpen(event.x,event.y); if(item.isTreeToggle(event.x,event.y)) { // visibleItems = null; item.setExpanded(!open); fireTreeEvent(item, !open); } else { item.getCell(event.x, event.y).setOpen(!open); } } break; } }
Example 19
Source File: ColumnReorderDragMode.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
protected void selectDragFocusColumn(ILayer natLayer, MouseEvent event, int focusedColumnPosition) { boolean shiftMask = (SWT.SHIFT & event.stateMask) != 0; boolean controlMask = (SWT.CONTROL & event.stateMask) != 0; natLayer.doCommand(new ViewportSelectColumnCommand(natLayer, focusedColumnPosition, shiftMask, controlMask)); }
Example 20
Source File: ReportViewerKeyHandler.java From birt with Eclipse Public License 1.0 | 4 votes |
private boolean scrollIncrement( GraphicalEditPart part, KeyEvent event ) { if ( ( event.stateMask & SWT.CONTROL ) == 0 ) { return false; } if ( !( part.getViewer( ) instanceof DeferredGraphicalViewer ) ) { return false; } DeferredGraphicalViewer viewer = (DeferredGraphicalViewer) part.getViewer( ); FigureCanvas canvas = viewer.getFigureCanvas( ); int code = event.keyCode; int increment = 0; if ( code == SWT.ARROW_RIGHT ) { increment = canvas.getHorizontalBar( ).getSelection( ) + canvas.getHorizontalBar( ).getIncrement( ); } else if ( code == SWT.ARROW_LEFT ) { increment = canvas.getHorizontalBar( ).getSelection( ) - canvas.getHorizontalBar( ).getIncrement( ); } else if ( code == SWT.ARROW_DOWN ) { increment = canvas.getVerticalBar( ).getSelection( ) + canvas.getVerticalBar( ).getIncrement( ); } else if ( code == SWT.ARROW_UP ) { increment = canvas.getVerticalBar( ).getSelection( ) - canvas.getVerticalBar( ).getIncrement( ); } if ( code == SWT.ARROW_RIGHT || code == SWT.ARROW_LEFT ) { canvas.scrollToX( increment ); } if ( code == SWT.ARROW_UP || code == SWT.ARROW_DOWN ) { canvas.scrollToY( increment ); } return true; }