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

The following examples show how to use org.eclipse.swt.SWT#LF . 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
@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 2
/**
 * Examines a string and returns the first line delimiter found.
 */
private static String getLineDelimiterUsed(IJavaElement elem) throws JavaModelException {
    ICompilationUnit cu = (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
    if (cu != null && cu.exists()) {
        IBuffer buf = cu.getBuffer();
        int length = buf.getLength();
        for (int i = 0; i < length; i++) {
            char ch = buf.getChar(i);
            if (ch == SWT.CR) {
                if (i + 1 < length) {
                    if (buf.getChar(i + 1) == SWT.LF) {
                        return "\r\n";
                    }
                }
                return "\r";
            } else if (ch == SWT.LF) {
                return "\n";
            }
        }
    }
    return System.getProperty("line.separator", "\n");
}
 
Example 3
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 Project: e4macs   File: BaseYankHandler.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Conditionally remove all EOLs from the end of the paste string
 * 
 * @param text
 * @param stripEol
 * @return String
 */
protected String convertDelimiters(String text, boolean stripEol) {
	String result = super.convertDelimiters(text);
	int len;
	if (stripEol && text != null && (len = text.length()) > 0) {
		for (int i = len-1; i >= 0; i--) {
			char c = text.charAt(i);
			if (c == SWT.CR) {
				continue;
			} else if (c == SWT.LF) {
				continue;
			}
			if (i+1 != len) {
				result = text.substring(0, i+1);	
			}
			break;
		}
	}
	return result;
}
 
Example 5
Source Project: nebula   File: NebulaToolbar.java    License: 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 6
/**
 * On paste, Eclipse StyledText converts EOLs to the buffer local value
 * Provide the same feature for yank
 *  
 * @param text
 * @return text with line delimiters converted to buffer local value
 */
protected String convertDelimiters(String text) {
	String result = text;
	int len;
	if (text != null && (len = text.length()) > 0) {
		String eol = getLineDelimiter();
		StringBuilder dest = new StringBuilder(len);
		boolean atEol = false;
		for (int i = 0; i < len; i++) {
			char c = text.charAt(i);
			if (c == SWT.CR) {
				if (atEol) {
					dest.append(eol);						
				}
				atEol = true;
				continue;
			} else if (c == SWT.LF) {
				atEol = false;
				dest.append(eol);
				continue;
			}
			if (atEol) {
				atEol = false;
				dest.append(eol);
			}
			dest.append(c);
		}
		if (atEol) {
			dest.append(eol);
		}
		result = dest.toString();
	}
	return result;
}
 
Example 7
/**
 * @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 8
Source Project: e4macs   File: EmacsPlusUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static String normalizeString(String message, int count) {
	
	String result = message;
	if (message != null && message.length() > 0){
		StringBuilder originalBuf = new StringBuilder(message);
		StringBuilder normalizedBuf = new StringBuilder(message.length());
		int mLen = (count > 0 ? Math.min(count, message.length()) : message.length());
		for (int i=0; i < mLen; i++) {
			String charac;
			int ocp = originalBuf.codePointAt(i);
			if (ocp < ' ') {
				switch (ocp) {
				case SWT.CR:
					charac = N_RET;
					break;
				case SWT.LF:
					charac = N_NEW;
					break;
				case '\t':
					charac = N_TAB;
					break;
				case '\f':
					charac = N_FF;
					break;
				case '\b':
					charac = N_BS;
					break;
				default:
					charac = N_GEN + ocp;
				} 
			} else {
				charac = String.valueOf(originalBuf.charAt(i));
			}
			normalizedBuf.append(charac);
		}
		result = normalizedBuf.toString();
	}
	return result;
}
 
Example 9
Source Project: e4macs   File: EmacsPlusUtils.java    License: 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 10
Source Project: typescript.java   File: RenameLinkedMode.java    License: MIT License 4 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	fShowPreview = (event.stateMask & SWT.CTRL) != 0
			&& (event.character == SWT.CR || event.character == SWT.LF);
	return super.doExit(model, event, offset, length);
}
 
Example 11
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	fShowPreview= (event.stateMask & SWT.CTRL) != 0
					&& (event.character == SWT.CR || event.character == SWT.LF);
	return super.doExit(model, event, offset, length);
}
 
Example 12
@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 13
Source Project: Pydev   File: PyUnitView.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
    if (e.widget == tree && (e.keyCode == SWT.LF || e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR)) {
        onTriggerGoToTest();
    }
}