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 data;
|
||||||
private ObservableValue clock;
|
private ObservableValue clock;
|
||||||
private ObservableValue select;
|
private ObservableValue select;
|
||||||
private boolean lastClock;
|
private boolean lastClock = false;
|
||||||
private int keyData;
|
|
||||||
private boolean sel;
|
private boolean sel;
|
||||||
|
private int keyData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new terminal instance
|
* Creates a new terminal instance
|
||||||
@ -43,7 +43,7 @@ public class Keyboard extends Node implements Element {
|
|||||||
* @param attributes the attributes
|
* @param attributes the attributes
|
||||||
*/
|
*/
|
||||||
public Keyboard(ElementAttributes 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
|
@Override
|
||||||
@ -59,19 +59,20 @@ public class Keyboard extends Node implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readInputs() throws NodeException {
|
public void readInputs() throws NodeException {
|
||||||
|
KeyboardDialog kbd;
|
||||||
|
synchronized (KEYBOARD_LOCK) {
|
||||||
|
kbd = keyboardDialog;
|
||||||
|
}
|
||||||
boolean clockVal = clock.getBool();
|
boolean clockVal = clock.getBool();
|
||||||
sel = select.getBool();
|
sel = select.getBool();
|
||||||
if (!lastClock && clockVal) {
|
if (!lastClock && clockVal && sel) {
|
||||||
KeyboardDialog kbd;
|
if (kbd != null)
|
||||||
synchronized (KEYBOARD_LOCK) {
|
kbd.consumeChar();
|
||||||
kbd = keyboardDialog;
|
|
||||||
}
|
|
||||||
if (kbd==null)
|
|
||||||
keyData=0;
|
|
||||||
else
|
|
||||||
keyData = keyboardDialog.getChar();
|
|
||||||
}
|
}
|
||||||
lastClock = clockVal;
|
lastClock = clockVal;
|
||||||
|
|
||||||
|
if (sel && kbd!=null)
|
||||||
|
keyData=kbd.getChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.neemann.digital.gui.components.terminal;
|
package de.neemann.digital.gui.components.terminal;
|
||||||
|
|
||||||
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
@ -21,7 +23,7 @@ public class KeyboardDialog extends JDialog {
|
|||||||
* @param owner the owner frame
|
* @param owner the owner frame
|
||||||
*/
|
*/
|
||||||
public KeyboardDialog(Frame owner) {
|
public KeyboardDialog(Frame owner) {
|
||||||
super(owner);
|
super(owner, Lang.get("elem_Keyboard"), false);
|
||||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
|
|
||||||
textLabel = new JLabel("Enter Text ");
|
textLabel = new JLabel("Enter Text ");
|
||||||
@ -42,6 +44,7 @@ public class KeyboardDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setAlwaysOnTop(true);
|
||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo(owner);
|
setLocationRelativeTo(owner);
|
||||||
}
|
}
|
||||||
@ -53,15 +56,21 @@ public class KeyboardDialog extends JDialog {
|
|||||||
if (text.length() == 0)
|
if (text.length() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
int c;
|
return text.charAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* consumes the oldest char
|
||||||
|
*/
|
||||||
|
public void consumeChar() {
|
||||||
|
if (text.length() > 0) {
|
||||||
String t;
|
String t;
|
||||||
synchronized (textLock) {
|
synchronized (textLock) {
|
||||||
c = text.charAt(0);
|
|
||||||
text = text.substring(1);
|
text = text.substring(1);
|
||||||
t = text;
|
t = text;
|
||||||
}
|
}
|
||||||
SwingUtilities.invokeLater(() -> textLabel.setText(t));
|
SwingUtilities.invokeLater(() -> textLabel.setText(t));
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user