mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-18 09:24:42 -04:00
keyboard works more intuitive
This commit is contained in:
parent
dd508b4aba
commit
af0173c7db
@ -33,9 +33,9 @@ public class Keyboard extends Node implements Element {
|
||||
private ObservableValue data;
|
||||
private ObservableValue clock;
|
||||
private ObservableValue select;
|
||||
private boolean lastClock;
|
||||
private int keyData;
|
||||
private boolean lastClock = false;
|
||||
private boolean sel;
|
||||
private int keyData;
|
||||
|
||||
/**
|
||||
* Creates a new terminal instance
|
||||
@ -43,7 +43,7 @@ public class Keyboard extends Node implements Element {
|
||||
* @param attributes the attributes
|
||||
*/
|
||||
public Keyboard(ElementAttributes attributes) {
|
||||
data = new ObservableValue("D", 16).setDescription(Lang.get("elem_Keyboard_pin_D"));
|
||||
data = new ObservableValue("D", 16, true).setDescription(Lang.get("elem_Keyboard_pin_D"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,19 +59,20 @@ public class Keyboard extends Node implements Element {
|
||||
|
||||
@Override
|
||||
public void readInputs() throws NodeException {
|
||||
KeyboardDialog kbd;
|
||||
synchronized (KEYBOARD_LOCK) {
|
||||
kbd = keyboardDialog;
|
||||
}
|
||||
boolean clockVal = clock.getBool();
|
||||
sel = select.getBool();
|
||||
if (!lastClock && clockVal) {
|
||||
KeyboardDialog kbd;
|
||||
synchronized (KEYBOARD_LOCK) {
|
||||
kbd = keyboardDialog;
|
||||
}
|
||||
if (kbd==null)
|
||||
keyData=0;
|
||||
else
|
||||
keyData = keyboardDialog.getChar();
|
||||
if (!lastClock && clockVal && sel) {
|
||||
if (kbd != null)
|
||||
kbd.consumeChar();
|
||||
}
|
||||
lastClock = clockVal;
|
||||
|
||||
if (sel && kbd!=null)
|
||||
keyData=kbd.getChar();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.neemann.digital.gui.components.terminal;
|
||||
|
||||
import de.neemann.digital.lang.Lang;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
@ -21,7 +23,7 @@ public class KeyboardDialog extends JDialog {
|
||||
* @param owner the owner frame
|
||||
*/
|
||||
public KeyboardDialog(Frame owner) {
|
||||
super(owner);
|
||||
super(owner, Lang.get("elem_Keyboard"), false);
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
|
||||
textLabel = new JLabel("Enter Text ");
|
||||
@ -42,6 +44,7 @@ public class KeyboardDialog extends JDialog {
|
||||
}
|
||||
});
|
||||
|
||||
setAlwaysOnTop(true);
|
||||
pack();
|
||||
setLocationRelativeTo(owner);
|
||||
}
|
||||
@ -53,15 +56,21 @@ public class KeyboardDialog extends JDialog {
|
||||
if (text.length() == 0)
|
||||
return 0;
|
||||
else {
|
||||
int c;
|
||||
return text.charAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* consumes the oldest char
|
||||
*/
|
||||
public void consumeChar() {
|
||||
if (text.length() > 0) {
|
||||
String t;
|
||||
synchronized (textLock) {
|
||||
c = text.charAt(0);
|
||||
text = text.substring(1);
|
||||
t = text;
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> textLabel.setText(t));
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user