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

The following examples show how to use org.eclipse.swt.SWT#CR . 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: ChatControl.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
  switch (e.keyCode) {
    case SWT.CR:
    case SWT.KEYPAD_CR:
      String message = getInputText().trim();

      if (message.length() > 0) {
        ChatControl.this.notifyMessageEntered(message);

        sendMessage(message);
      }

      e.doit = false;
  }
}
 
Example 2
Source File: ChatControl.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
  switch (e.keyCode) {
    case SWT.CR:
    case SWT.KEYPAD_CR:
      /*
       * We do not want the ENTER to be inserted
       */
      e.doit = false;
      return;
    default:
      determineCurrentState();
      break;
  }

  ChatControl.this.notifyCharacterEntered(e.character);
}
 
Example 3
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 4
Source File: NebulaToolbar.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles key released event.
 * 
 * @param e KeyEvent
 */
private void handleKeyReleased(KeyEvent e)
{
	if (selectedItemIndex == -1)
	{
		return;
	}

	if (e.keyCode == ' ' || e.keyCode == SWT.CR || e.keyCode == SWT.LF || e.keyCode == SWT.KEYPAD_CR)
	{
		items[selectedItemIndex].setPushedDown(false);
		items[selectedItemIndex].setHovered(false);

		redraw();

		SelectionListener selectionListener = items[selectedItemIndex].getSelectionListener();

		if (selectionListener == null)
		{
			return;
		}

		Event event = new Event();
		event.widget = this;

		selectionListener.widgetSelected(new SelectionEvent(event));
	}
}
 
Example 5
Source File: SimpleConfigurator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Control createDialogArea(final Composite parent) {
	final Composite parentPanel = (Composite) super.createDialogArea(parent);
	setLayout(parentPanel);
	// ensure vertical layout
	((RowLayout) parentPanel.getLayout()).type = SWT.VERTICAL;
	((RowLayout) parentPanel.getLayout()).spacing = 3;

	final KeyAdapter adp = new KeyAdapter() {

		@Override
		public void keyReleased(final KeyEvent e) {
			/*
			 * I don't like having different ways of checking for keypad enter and the normal one. Using the keyCode
			 * would be better, but I couldn't readily find the value for CR.
			 */
			if (e.keyCode == SWT.KEYPAD_CR || e.character == SWT.CR) {
				refresh(); // makeActionDoStuff();
			}
		}
	};

	this.line.createControl(parentPanel, adp);
	this.fill.createControl(parentPanel, adp);
	this.point.createControl(parentPanel, adp, this.build);
	// this.label.createControl(parentPanel, adp);
	// this.minScale.createControl(parentPanel, adp);
	// this.maxScale.createControl(parentPanel, adp);

	final Composite replaceComp = subpart(parentPanel, "Replace");
	this.replace = new Button(replaceComp, SWT.CHECK);
	replace.addSelectionListener(synchronize);
	replace.setSelection(true);

	refresh();

	return parentPanel;
}
 
Example 6
Source File: HistogramTextControl.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
    switch (event.character) {
        case SWT.CR:
            updateValue();
            break;
        default:
            break;
    }
}
 
Example 7
Source File: AddRowOnEnterCellNavigationStrategyTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_findSelectedCell_not_add_a_new_input_on_Enter_if_not_on_first_column() throws Exception {
    when(currentSelectedCell.getNeighbor(anyInt(), anyBoolean())).thenReturn(null);
    when(currentSelectedCell.getColumnIndex()).thenReturn(1);
    final Event event = new Event();
    event.keyCode = SWT.CR;
    cellNavigationStrategy.findSelectedCell(viewer, currentSelectedCell, event);
    verify(controller, never()).add(viewer);
}
 
Example 8
Source File: AddExternalResourceDialog.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Called for many widgets.
 *
 * @param event the event
 * @return true, if successful
 */
@Override
public boolean verifyKeyChecks(VerifyEvent event) {
  if (event.keyCode == SWT.CR || event.keyCode == SWT.TAB)
    return true;

  if (Character.isJavaIdentifierPart(event.character) || event.character == '.')
    return true;

  if ((event.widget == xrUrlUI || event.widget == xrUrlSuffixUI)
          && (event.character == '/' || event.character == ':'))
    return true;
  return false;
}
 
Example 9
Source File: UniversalMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.KeyHandlerMinibuffer#getResult(Binding, KeySequence, String)
 */
@Override
protected IBindingResult getResult(final Binding binding, final KeySequence trigger, String triggerString) {

	// key character is only > 0 if it is stand alone
	int charpoint = getKeyCharacter();
	String character = null;
	if (binding == null && charpoint > 0 && triggerCount < 2) {
		if (charpoint == SWT.CR || charpoint == SWT.LF) {
			character = getEol();
		} else if (charpoint == SWT.BS) {
			character = new String(Character.toChars(charpoint));
		} else if ((Character.isWhitespace(charpoint)) || (charpoint > ' ')) {
			character = new String(Character.toChars(charpoint));
		}
	}
	if (countBuf.length() > 0) {
		try {
			if (countBuf.length() == 1 && countBuf.charAt(0)== '-') {
				;	// just use argument Count
			} else {
				setArgumentCount(Integer.parseInt(countBuf.toString()));
			}
		} catch (NumberFormatException e) {
				// bad count
				setArgumentCount(1);
		}
	}
	final String key = character;
	final boolean notNumeric = countBuf.length() == 0 && argumentCount == 4;	// flag whether a number was entered into the minibuffer

	return new IUniversalResult() {
		public Binding getKeyBinding() { return binding; }
		public String getKeyString() { return key; }
		public int getCount() { return argumentCount; }
		public boolean isNumeric() { return !notNumeric; }
		public KeySequence getTrigger() { return trigger; }
	};
}
 
Example 10
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void processKeyDown( int keyCode )
{
	switch ( keyCode )
	{
		case SWT.ESC :
			break;
		case SWT.CR :
		case SWT.KEYPAD_CR :
			doToggleDropDown( );
			break;
		case SWT.HOME :
			select( 0 );
			break;
		case SWT.END :
			select( context.getBitmaps( ).size( ) - 1 );
			break;
		case SWT.ARROW_LEFT :
			select( context.getIndex( ) - 1 );
			break;
		case SWT.ARROW_RIGHT :
			select( context.getIndex( ) + 1 );
			break;
		case SWT.ARROW_UP :
			select( context.getIndex( ) - columns );
			break;
		case SWT.ARROW_DOWN :
			select( context.getIndex( ) + columns );
			break;
	}

}
 
Example 11
Source File: EmacsPlusUtils.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
public static String normalizeCharacter(int keyCode) {
	String result = null;
	if (keyCode < ' ') {
		switch (keyCode) {
		case SWT.CR:
			result = N_RET;
			break;
		case SWT.LF:
			result = N_NEW;
			break;
		case '\t':
			result = N_TAB;
			break;
		case '\f':
			result = N_FF;
			break;
		case '\b':
			result = N_BS;
			break;
		default:
			result = N_GEN + keyCode;
		}
	} else {
		result = String.valueOf((char)keyCode);
	}
	return result;
}
 
Example 12
Source File: LocalizedNumberEditorComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void keyPressed( KeyEvent e )
{
	if ( e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR )
	{
		if ( bTextModified )
		{
			bTextModified = false;
			fireEvent( );
		}
	}
}
 
Example 13
Source File: CharriageColumnViewerEditorActivationStrategy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected boolean enterKeyPressed(final ColumnViewerEditorActivationEvent event) {
    final EventObject sourceEvent = event.sourceEvent;
    //event must not be cancelled
    if (sourceEvent instanceof KeyEvent && ((KeyEvent) sourceEvent).doit) {
        return event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR;
    }
    return false;
}
 
Example 14
Source File: AddRowOnEnterCellNavigationStrategyTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_findSelectedCell_add_a_new_input_on_Enter_if_below_row_not_exists() throws Exception {
    when(currentSelectedCell.getNeighbor(anyInt(), anyBoolean())).thenReturn(null);
    final Event event = new Event();
    event.keyCode = SWT.CR;
    cellNavigationStrategy.findSelectedCell(viewer, currentSelectedCell, event);
    verify(controller).add(viewer);
}
 
Example 15
Source File: TextAssist.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return a listener for the keydown event
 */
private Listener createKeyDownListener() {
	return new Listener() {
		@Override
		public void handleEvent(final Event event) {
			switch (event.keyCode) {
				case SWT.ARROW_DOWN:
					int index = (table.getSelectionIndex() + 1) % table.getItemCount();
					table.setSelection(index);
					event.doit = false;
					break;
				case SWT.ARROW_UP:
					index = table.getSelectionIndex() - 1;
					if (index < 0) {
						index = table.getItemCount() - 1;
					}
					table.setSelection(index);
					event.doit = false;
					break;
				case SWT.CR:
				case SWT.KEYPAD_CR:
					if (popup.isVisible() && table.getSelectionIndex() != -1) {
						text.setText(table.getSelection()[0].getText());
						popup.setVisible(false);
					}
					break;
				case SWT.ESC:
					popup.setVisible(false);
					break;
			}
		}
	};
}
 
Example 16
Source File: LabResultEditingSupport.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void setUpCellEditor(ColumnViewer viewer){
	// set up validation of the cell editors
	textCellEditor = new TextCellEditor((Composite) viewer.getControl());
	
	textCellEditor.addListener(new ICellEditorListener() {
		@Override
		public void editorValueChanged(boolean oldValidState, boolean newValidState){
			if (newValidState) {
				textCellEditor.getControl()
					.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
			} else {
				textCellEditor.getControl()
					.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
			}
		}
		
		@Override
		public void cancelEditor(){
			textCellEditor.getControl()
				.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		}
		
		@Override
		public void applyEditorValue(){
			textCellEditor.getControl()
				.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		}
	});
	
	focusCell =
		new TreeViewerFocusCellManager((TreeViewer) viewer, new FocusCellHighlighter(viewer) {
		
		});
		
	ColumnViewerEditorActivationStrategy actSupport =
		new ColumnViewerEditorActivationStrategy(viewer) {
			@Override
			protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event){
				return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
					|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
					|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
						&& event.keyCode == SWT.CR)
					|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
						&& event.keyCode == SWT.KEYPAD_CR)
					|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
			}
		};
	
	TreeViewerEditor.create((TreeViewer) viewer, focusCell, actSupport,
		ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
}
 
Example 17
Source File: ModulaQuickOutlineDialog.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    
    XdsElementPatternFilter patternFilter = new XdsElementPatternFilter();
    filteredTree = new MyFilteredTree(composite, patternFilter);
    treeViewer = filteredTree.getViewer();
    treeViewer.setUseHashlookup(true);
    treeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    editor = (ITextEditor) WorkbenchUtils.getActiveEditor(false);
   
    contentProvider = new ModulaOutlinePageContentProvider(editor, filter);
    treeViewer.setContentProvider(contentProvider);

    XdsElementLabelProvider labelProvider = new XdsElementLabelProvider();
    IBaseLabelProvider decoratedLabelProvider = new DelegatingDecoratedXdsElementLabelProvider(labelProvider);
    treeViewer.setLabelProvider(decoratedLabelProvider);
    treeViewer.setComparator(new OutlineSorter(labelProvider));
    
    treeViewer.setAutoExpandLevel(0);
    try {
    	treeViewer.getControl().setRedraw(false);
    	treeViewer.setInput(editor.getEditorInput());
    }
    finally {
    	treeViewer.getControl().setRedraw(true);
    }
    
    treeViewer.getTree().addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            handleTreeSelection(e);
        }        
    });
    
    Listener eventListener = new Listener() {
        @Override
        public void handleEvent(Event event) {
            if (event.type == SWT.KeyDown && event.character == SWT.CR) {
                handleTreeSelection();
            }
        }
    };
    
    treeViewer.getTree().addListener (SWT.Collapse, eventListener);
    treeViewer.getTree().addListener (SWT.Expand, eventListener);
    treeViewer.getTree().addListener (SWT.KeyDown, eventListener);
    treeViewer.getTree().addListener (SWT.MouseUp, eventListener);
    treeViewer.getTree().addListener (SWT.MouseDoubleClick, eventListener);
    
    IDialogSettings settings = getDialogSettings();
    if (settings != null) {
        sortAlph = settings.getBoolean(getClass().getName() + DLG_SORT_ALPH);
    }


    return composite;
}
 
Example 18
Source File: MovablePanningSelectionTool.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean handleKeyDown(KeyEvent event) {
	int dx = 0;
	int dy = 0;

	if (event.keyCode == SWT.SHIFT) {
		shift = true;
	}

	if (event.keyCode == SWT.ARROW_DOWN) {
		dy = 1;

	} else if (event.keyCode == SWT.ARROW_LEFT) {
		dx = -1;

	} else if (event.keyCode == SWT.ARROW_RIGHT) {
		dx = 1;

	} else if (event.keyCode == SWT.ARROW_UP) {
		dy = -1;
	}

	NodeElementEditPart targetEditPart = null;

	Object model = this.getCurrentViewer().getContents().getModel();

	ERDiagram diagram = null;
	if (model instanceof ERModel) {
		diagram = ((ERModel) model).getDiagram();
	}
	if (model instanceof ERDiagram) {
		diagram = (ERDiagram) model;
	}

	if (diagram != null) {

		List selectedObject = this.getCurrentViewer().getSelectedEditParts();
		if (!selectedObject.isEmpty()) {

			CompoundCommand command = new CompoundCommand();

			for (Object object : selectedObject) {

				if (object instanceof ERTableEditPart
						|| object instanceof NoteEditPart) {
					NodeElementEditPart editPart = (NodeElementEditPart) object;
					targetEditPart = editPart;

					NodeElement nodeElement = (NodeElement) editPart.getModel();

					MoveElementCommand moveElementCommand = new MoveElementCommand(
							diagram, editPart.getFigure().getBounds(),
							nodeElement.getX() + dx, nodeElement.getY() + dy,
							nodeElement.getWidth(), nodeElement.getHeight(),
							nodeElement);

					command.add(moveElementCommand);
				}
			}

			this.getCurrentViewer().getEditDomain().getCommandStack().execute(
					command.unwrap());
		}
	}


	if (event.keyCode == SWT.CR && targetEditPart != null) {
		Request request = new Request();
		request.setType(RequestConstants.REQ_OPEN);
		targetEditPart.performRequest(request);
	}

	return super.handleKeyDown(event);
}
 
Example 19
Source File: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void verifyKey(VerifyEvent event) {
    try {
        if (event.character != '\0') { // Printable character

            if (Character.isLetter(event.character)
                    && (event.stateMask == 0 || (event.stateMask & SWT.SHIFT) != 0)
                    || Character.isWhitespace(event.character)) {
                //it's a valid letter without any stateMask (so, just entering regular text or upper/lowercase -- if shift is there).
                if (!isSelectedRangeEditable()) {
                    getTextWidget().setCaretOffset(getDocument().getLength());
                }
            }

            if (!isSelectedRangeEditable()) {
                event.doit = false;
                return;
            }

            if (event.character == SWT.CR || event.character == SWT.LF) {

                //if we had an enter with the shift pressed and we're in a completion, we must stop it
                if (inCompletion && (event.stateMask & SWT.SHIFT) != 0) {
                    //Work-around the fact that hide() is a protected method.
                    Method hideMethod = getHideMethod();
                    if (hideMethod != null) {
                        hideMethod.invoke(ScriptConsoleViewer.this.fContentAssistant);
                    }
                }

                if (!inCompletion) {
                    //in a new line, always set the caret to the end of the document (if not in completion)
                    //(note that when we make a hide in the previous 'if', it will automatically exit the
                    //completion mode (so, it'll also get into this part of the code)
                    getTextWidget().setCaretOffset(getDocument().getLength());
                }
                return;
            }

            if (event.character == SWT.ESC) {
                if (!inCompletion) {
                    //while in a completion, esc won't clear the line (just stop the completion)
                    listener.setCommandLine("");
                }
                return;
            }
        } else { //not printable char
            if (isCaretInEditableRange()) {
                if (!inCompletion && event.keyCode == SWT.PAGE_UP) {
                    event.doit = false;
                    List<String> commandsToExecute = ScriptConsoleHistorySelector.select(history);
                    if (commandsToExecute != null) {
                        //remove the current command (substituted by the one gotten from page up)
                        listener.setCommandLine("");
                        IDocument d = getDocument();
                        //Pass them all at once (let the document listener separate the command in lines).
                        d.replace(d.getLength(), 0, StringUtils.join("\n", commandsToExecute) + "\n");
                    }
                    return;
                }
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 20
Source File: LineSeriesMarkerSheet.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void handleEventCanvasMarkers( Event event )
{
	switch ( event.type )
	{
		case SWT.KeyDown :
		{
			if ( event.keyCode == SWT.ARROW_LEFT )
			{
				if ( iSelectedIndex - 1 >= 0 )
				{
					iSelectedIndex--;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_RIGHT )
			{
				if ( iSelectedIndex + 1 < getMarkers( ).size( ) )
				{
					iSelectedIndex++;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_UP )
			{
				if ( iSelectedIndex - MARKER_ROW_MAX_NUMBER >= 0 )
				{
					iSelectedIndex -= MARKER_ROW_MAX_NUMBER;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_DOWN )
			{
				if ( iSelectedIndex + MARKER_ROW_MAX_NUMBER < getMarkers( ).size( ) )
				{
					iSelectedIndex += MARKER_ROW_MAX_NUMBER;
					setEnabledState( );
				}
			}
			
			else if ( event.keyCode == SWT.CR
					|| event.keyCode == SWT.KEYPAD_CR )
			{
				currentMarkerEditor.setFocus( );
			}
			else if ( event.keyCode == SWT.ESC )
			{
				cnvMarkers.getShell( ).close( );
			}
			break;
		}
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvMarkers.redraw( );
			}
			break;
		}
		case SWT.Paint :
			paintControl( new PaintEvent( event ) );
			break;
		case SWT.MouseDown :
			mouseDown( new MouseEvent( event ) );
			break;
	}
}