本文整理汇总了Java中com.googlecode.lanterna.input.KeyType类的典型用法代码示例。如果您正苦于以下问题:Java KeyType类的具体用法?Java KeyType怎么用?Java KeyType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyType类属于com.googlecode.lanterna.input包,在下文中一共展示了KeyType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: processInput
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public synchronized boolean processInput() throws IOException {
boolean gotInput = false;
KeyStroke keyStroke = readKeyStroke();
if(keyStroke != null) {
gotInput = true;
do {
if (keyStroke.getKeyType() == KeyType.EOF) {
throw new EOFException();
}
boolean handled = handleInput(keyStroke);
if(!handled) {
handled = fireUnhandledKeyStroke(keyStroke);
}
dirty = handled || dirty;
keyStroke = pollInput();
} while(keyStroke != null);
}
return gotInput;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:21,代码来源:AbstractTextGUI.java
示例2: stopScreen
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public synchronized void stopScreen() throws IOException {
if(!isStarted) {
return;
}
//Drain the input queue
KeyStroke keyStroke;
do {
keyStroke = pollInput();
}
while(keyStroke != null && keyStroke.getKeyType() != KeyType.EOF);
getTerminal().exitPrivateMode();
isStarted = false;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:17,代码来源:TerminalScreen.java
示例3: readInput
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
private KeyStroke readInput(boolean blocking) throws IOException {
synchronized(readMutex) {
if(!keyQueue.isEmpty())
return keyQueue.poll();
KeyStroke key = inputDecoder.getNextCharacter(blocking);
if (key != null && key.getKeyType() == KeyType.CursorLocation) {
TerminalPosition reportedTerminalPosition = inputDecoder.getLastReportedTerminalPosition();
if (reportedTerminalPosition != null)
onResized(reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());
return pollInput();
} else {
return key;
}
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:18,代码来源:StreamBasedTerminal.java
示例4: handleKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
Runnable selectedItem = getSelectedItem();
KeyType keyType = keyStroke.getKeyType();
if (selectedItem != null
&& (keyType == KeyType.Enter || (keyType == KeyType.Character && keyStroke.getCharacter() == ' '))) {
selectedItem.run();
return Result.HANDLED;
}
if (keyType == KeyType.Character) {
selectItem(keyStroke.getCharacter());
}
if (keyType == KeyType.Escape) {
closeListener.run();
return Result.HANDLED;
}
return super.handleKeyStroke(keyStroke);
}
开发者ID:BrunoEberhard,项目名称:minimal-j,代码行数:19,代码来源:MenuItemListBox.java
示例5: createKeyInputAwarePrinter
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
public static SessionStatePrinter createKeyInputAwarePrinter(Collection<KeyStrokeBinding> bindings) {
return new SessionStatePrinter() {
private Thread t;
{
t = new Thread(() -> {
while (!isShutdown()) {
try {
KeyStroke keyStroke = readKeyInput();
if (keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.Character
&& keyStroke.getCharacter().equals('c')) {
shutdown();
System.exit(0);
} else {
bindings.forEach(binding -> {
if (keyStroke.equals(binding.getKeyStroke())) {
binding.getBinding().run();
}
});
}
} catch (Throwable e) {
LOGGER.error("Unexpected error when reading user input", e);
}
}
});
t.setDaemon(true);
t.start();
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
}
@Override
public void shutdown() {
if (!isShutdown()) {
super.shutdown();
t.interrupt();
}
}
};
}
开发者ID:atomashpolskiy,项目名称:bt,代码行数:41,代码来源:SessionStatePrinter.java
示例6: handleKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
Object selectedItem = getSelectedItem();
if(selectedItem != null &&
(keyStroke.getKeyType() == KeyType.Enter ||
(keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' '))) {
((Runnable)selectedItem).run();
return Result.HANDLED;
}
return super.handleKeyStroke(keyStroke);
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:13,代码来源:ActionListBox.java
示例7: handleKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
if(keyStroke.getKeyType() == KeyType.Enter) {
action.run();
return Result.HANDLED;
}
return super.handleKeyStroke(keyStroke);
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:9,代码来源:Button.java
示例8: handleKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public synchronized Result handleKeyStroke(KeyStroke keyStroke) {
if(keyStroke.getKeyType() == KeyType.Enter ||
(keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ')) {
if(itemStatus.get(getSelectedIndex()))
itemStatus.set(getSelectedIndex(), Boolean.FALSE);
else
itemStatus.set(getSelectedIndex(), Boolean.TRUE);
return Result.HANDLED;
}
return super.handleKeyStroke(keyStroke);
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:13,代码来源:CheckBoxList.java
示例9: handleKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
if((keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ') ||
keyStroke.getKeyType() == KeyType.Enter) {
setChecked(!isChecked());
return Result.HANDLED;
}
return super.handleKeyStroke(keyStroke);
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:10,代码来源:CheckBox.java
示例10: handleInput
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public boolean handleInput(KeyStroke key) {
if(key.getKeyType() == KeyType.Escape) {
close();
return true;
}
return super.handleInput(key);
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:9,代码来源:AbstractWindow.java
示例11: handleKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public synchronized Result handleKeyStroke(KeyStroke keyStroke) {
if(keyStroke.getKeyType() == KeyType.Enter ||
(keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ')) {
checkedIndex = getSelectedIndex();
invalidate();
return Result.HANDLED;
}
return super.handleKeyStroke(keyStroke);
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:11,代码来源:RadioBoxList.java
示例12: readKeyStroke
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
protected synchronized KeyStroke readKeyStroke() throws IOException {
KeyStroke keyStroke = super.pollInput();
if(eofWhenNoWindows && keyStroke == null && windows.isEmpty()) {
return new KeyStroke(KeyType.EOF);
}
else if(keyStroke != null) {
return keyStroke;
}
else {
return super.readKeyStroke();
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:14,代码来源:MultiWindowTextGUI.java
示例13: filter
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
private KeyStroke filter(KeyStroke keyStroke) throws IOException {
if(keyStroke == null) {
return null;
}
else if(keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.ArrowLeft) {
if(viewportTopLeft.getColumn() > 0) {
viewportTopLeft = viewportTopLeft.withRelativeColumn(-1);
refresh();
}
return null;
}
else if(keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.ArrowRight) {
if(viewportTopLeft.getColumn() + viewportSize.getColumns() < getTerminalSize().getColumns()) {
viewportTopLeft = viewportTopLeft.withRelativeColumn(1);
refresh();
}
return null;
}
else if(keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.ArrowUp) {
if(viewportTopLeft.getRow() > 0) {
viewportTopLeft = viewportTopLeft.withRelativeRow(-1);
realScreen.scrollLines(0,viewportSize.getRows()-1,-1);
refresh();
}
return null;
}
else if(keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.ArrowDown) {
if(viewportTopLeft.getRow() + viewportSize.getRows() < getTerminalSize().getRows()) {
viewportTopLeft = viewportTopLeft.withRelativeRow(1);
realScreen.scrollLines(0,viewportSize.getRows()-1,1);
refresh();
}
return null;
}
return keyStroke;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:37,代码来源:VirtualScreen.java
示例14: pollInput
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public KeyStroke pollInput() {
if(disposed) {
return new KeyStroke(KeyType.EOF);
}
KeyStroke keyStroke = swingTerminal.pollInput();
if(autoCloseTrigger == AutoCloseTrigger.CloseOnEscape &&
keyStroke != null &&
keyStroke.getKeyType() == KeyType.Escape) {
dispose();
}
return keyStroke;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:14,代码来源:SwingTerminalFrame.java
示例15: VirtualScreenTest
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
public VirtualScreenTest(String[] args) throws InterruptedException, IOException {
Screen screen = new TestTerminalFactory(args).createScreen();
screen = new VirtualScreen(screen);
screen.startScreen();
TextGraphics textGraphics = screen.newTextGraphics();
textGraphics.setBackgroundColor(TextColor.ANSI.GREEN);
textGraphics.fillTriangle(new TerminalPosition(40, 0), new TerminalPosition(25,19), new TerminalPosition(65, 19), ' ');
textGraphics.setBackgroundColor(TextColor.ANSI.RED);
textGraphics.drawRectangle(TerminalPosition.TOP_LEFT_CORNER, screen.getTerminalSize(), ' ');
screen.refresh();
while(true) {
KeyStroke keyStroke = screen.pollInput();
if(keyStroke != null) {
if(keyStroke.getKeyType() == KeyType.Escape) {
break;
}
}
else if(screen.doResizeIfNecessary() != null) {
screen.refresh();
}
else {
Thread.sleep(1);
}
}
screen.stopScreen();
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:29,代码来源:VirtualScreenTest.java
示例16: main
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
Terminal terminal = new TestTerminalFactory(args).createTerminal();
if(terminal instanceof SwingTerminalFrame) {
((SwingTerminalFrame) terminal).setAutoCloseTrigger(SwingTerminalFrame.AutoCloseTrigger.DoNotAutoClose);
}
boolean normalTerminal = true;
printNormalTerminalText(terminal);
KeyStroke keyStroke = null;
while(keyStroke == null || keyStroke.getKeyType() != KeyType.Escape) {
keyStroke = terminal.pollInput();
if(keyStroke != null && keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ') {
normalTerminal = !normalTerminal;
if(normalTerminal) {
terminal.exitPrivateMode();
printNormalTerminalText(terminal);
}
else {
terminal.enterPrivateMode();
printPrivateModeTerminalText(terminal);
}
}
else {
Thread.sleep(1);
}
}
if(!normalTerminal) {
terminal.exitPrivateMode();
}
terminal.putCharacter('\n');
if(terminal instanceof SwingTerminalFrame) {
((SwingTerminalFrame) terminal).dispose();
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:34,代码来源:PrivateModeTest.java
示例17: writeInputMapping
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
private void writeInputMapping() {
final Properties inputMappings = new Properties();
for (final Input input : Input.values()) {
final Iterable<Entry<KeyStroke, Input>> keyStrokes = Iterables.filter(keyMappings.entrySet(),
entry -> input == entry.getValue());
inputMappings.put(input.name(),
Joiner.on(",").join(Iterables.transform(keyStrokes, keyStroke -> KeyStrokes.toString(keyStroke.getKey()))));
}
try (final BufferedWriter writer = Files.newWriter(INPUT_MAPPING_FILE, Charsets.UTF_8)) {
final String comments = " Use this file to customize the your mappings.\n"
+ " One command can be mapped to multiple input. Multiple inputs has to be separated by comma (,).\n"
+ " For a key combination with [Ctrl] prefix the input with \"Ctrl+\". For a key combination with [Alt] prefix the input with \"Alt+\".\n"
+ " Each combination of \"Ctrl+\" and \"Alt+\" is possible.\n"
+ " An input is a printable character in lowercase or uppercase or one of the following special keys (note that not all keyboards support all special keys):\n"
+ " "
+ Joiner.on(",")
.join(Iterables
.transform(
Iterables.filter(Arrays.asList(KeyType.values()),
keyType -> keyType != KeyType.Character && keyType != KeyType.Unknown
&& keyType != KeyType.CursorLocation && keyType != KeyType.EOF),
Enum::name))
+ "," + KeyStrokes.SPACE + "\n" + "";
inputMappings.store(writer, comments);
} catch (final Exception exception) {
throw new RuntimeException("Unable to write input mapping file.", exception);
}
}
开发者ID:klaushauschild1984,项目名称:ff7rl,代码行数:29,代码来源:InputMapping.java
示例18: keyStrokesTestDataProvider
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@DataProvider
public Object[][] keyStrokesTestDataProvider() {
return new Object[][] { { new KeyStroke(KeyType.Enter), "Enter", },
{ new KeyStroke(KeyType.ArrowDown, true, false), "Ctrl+ArrowDown", },
{ new KeyStroke(KeyType.Escape, false, true), "Alt+Escape", },
{ new KeyStroke(' ', true, true), "Ctrl+Alt+Space", }, { new KeyStroke('w', false, false), "w", },
{ new KeyStroke('A', true, false), "Ctrl+A", }, { new KeyStroke('s', false, true), "Alt+s", },
{ new KeyStroke('D', true, true), "Ctrl+Alt+D", }, };
}
开发者ID:klaushauschild1984,项目名称:ff7rl,代码行数:10,代码来源:KeyStrokesTest.java
示例19: handleInput
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
@Override
public boolean handleInput(KeyStroke key) {
if(key.getKeyType() == KeyType.MouseEvent) {
MouseAction mouseAction = (MouseAction)key;
TerminalPosition localCoordinates = fromGlobal(mouseAction.getPosition());
Interactable interactable = interactableLookupMap.getInteractableAt(localCoordinates);
interactable.handleKeyStroke(key);
}
else if(focusedInteractable != null) {
Interactable next = null;
Interactable.FocusChangeDirection direction = Interactable.FocusChangeDirection.TELEPORT; //Default
Interactable.Result result = focusedInteractable.handleKeyStroke(key);
if(!enableDirectionBasedMovements) {
if(result == Interactable.Result.MOVE_FOCUS_DOWN || result == Interactable.Result.MOVE_FOCUS_RIGHT) {
result = Interactable.Result.MOVE_FOCUS_NEXT;
}
else if(result == Interactable.Result.MOVE_FOCUS_UP || result == Interactable.Result.MOVE_FOCUS_LEFT) {
result = Interactable.Result.MOVE_FOCUS_PREVIOUS;
}
}
switch (result) {
case HANDLED:
return true;
case UNHANDLED:
//Filter the event recursively through all parent containers until we hit null; give the containers
//a chance to absorb the event
Container parent = focusedInteractable.getParent();
while(parent != null) {
if(parent.handleInput(key)) {
return true;
}
parent = parent.getParent();
}
return false;
case MOVE_FOCUS_NEXT:
next = contentHolder.nextFocus(focusedInteractable);
if(next == null) {
next = contentHolder.nextFocus(null);
}
direction = Interactable.FocusChangeDirection.NEXT;
break;
case MOVE_FOCUS_PREVIOUS:
next = contentHolder.previousFocus(focusedInteractable);
if(next == null) {
next = contentHolder.previousFocus(null);
}
direction = Interactable.FocusChangeDirection.PREVIOUS;
break;
case MOVE_FOCUS_DOWN:
next = interactableLookupMap.findNextDown(focusedInteractable);
direction = Interactable.FocusChangeDirection.DOWN;
if(next == null && !strictFocusChange) {
next = contentHolder.nextFocus(focusedInteractable);
direction = Interactable.FocusChangeDirection.NEXT;
}
break;
case MOVE_FOCUS_LEFT:
next = interactableLookupMap.findNextLeft(focusedInteractable);
direction = Interactable.FocusChangeDirection.LEFT;
break;
case MOVE_FOCUS_RIGHT:
next = interactableLookupMap.findNextRight(focusedInteractable);
direction = Interactable.FocusChangeDirection.RIGHT;
break;
case MOVE_FOCUS_UP:
next = interactableLookupMap.findNextUp(focusedInteractable);
direction = Interactable.FocusChangeDirection.UP;
if(next == null && !strictFocusChange) {
next = contentHolder.previousFocus(focusedInteractable);
direction = Interactable.FocusChangeDirection.PREVIOUS;
}
break;
}
if(next != null) {
setFocusedInteractable(next, direction);
}
return true;
}
return false;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:81,代码来源:AbstractBasePane.java
示例20: main
import com.googlecode.lanterna.input.KeyType; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
boolean useAnsiColors = false;
boolean useFilled = false;
boolean slow = false;
for(String arg: args) {
if(arg.equals("--ansi-colors")) {
useAnsiColors = true;
}
if(arg.equals("--filled")) {
useFilled = true;
}
if(arg.equals("--slow")) {
slow = true;
}
}
Screen screen = new TestTerminalFactory(args).createScreen();
screen.startScreen();
TextGraphics textGraphics = new ScreenTextGraphics(screen);
Random random = new Random();
long startTime = System.currentTimeMillis();
while(System.currentTimeMillis() - startTime < 1000 * 20) {
KeyStroke keyStroke = screen.pollInput();
if(keyStroke != null && keyStroke.getKeyType() == KeyType.Escape) {
break;
}
screen.doResizeIfNecessary();
TerminalSize size = textGraphics.getSize();
TextColor color;
if(useAnsiColors) {
color = TextColor.ANSI.values()[random.nextInt(TextColor.ANSI.values().length)];
}
else {
//Draw a rectangle in random indexed color
color = new TextColor.Indexed(random.nextInt(256));
}
TerminalPosition topLeft = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows()));
TerminalSize rectangleSize = new TerminalSize(random.nextInt(size.getColumns() - topLeft.getColumn()), random.nextInt(size.getRows() - topLeft.getRow()));
textGraphics.setBackgroundColor(color);
if(useFilled) {
textGraphics.fillRectangle(topLeft, rectangleSize, ' ');
}
else {
textGraphics.drawRectangle(topLeft, rectangleSize, ' ');
}
screen.refresh(Screen.RefreshType.DELTA);
if(slow) {
Thread.sleep(500);
}
}
screen.stopScreen();
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:56,代码来源:ScreenRectangleTest.java
注:本文中的com.googlecode.lanterna.input.KeyType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论