Fixes and enhancements.
- Added ability to change inner border width of console window. - Fixed a nasty bug that prevented key press handling. - Reset now clears the accumulator and index registers.
This commit is contained in:
1 parent
e012d97bb3
commit
c214cc9b43
10 files changed
+2682
-2504
No files matched your search
@@ -6,6 +6,7 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import com.grahamedgecombe.jterminal.JTerminal;
|
||||
import com.grahamedgecombe.jterminal.vt100.Vt100TerminalModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.BevelBorder;
|
||||
@@ -18,11 +19,20 @@ import javax.swing.border.Border;
|
||||
|
||||
public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
|
||||
private static final int DEFAULT_COLUMNS = 80;
|
||||
private static final int DEFAULT_ROWS = 24;
|
||||
private static final int DEFAULT_BORDER_WIDTH = 10;
|
||||
|
||||
private boolean hasInput = false;
|
||||
private char keyBuffer;
|
||||
|
||||
public Console() {
|
||||
super();
|
||||
public Console() {
|
||||
this(DEFAULT_COLUMNS, DEFAULT_ROWS);
|
||||
}
|
||||
|
||||
public Console(int columns, int rows) {
|
||||
super(new Vt100TerminalModel(columns, rows));
|
||||
setBorderWidth(DEFAULT_BORDER_WIDTH);
|
||||
addKeyListener(this);
|
||||
addMouseListener(this);
|
||||
Border emptyBorder = BorderFactory.createEmptyBorder(5, 5, 5, 0);
|
||||
@@ -31,6 +41,11 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
this.setBorder(compoundBorder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the console. This will cause the console to be cleared and the cursor returned to the
|
||||
* home position.
|
||||
*
|
||||
*/
|
||||
public void reset() {
|
||||
getModel().clear();
|
||||
getModel().setCursorColumn(0);
|
||||
@@ -39,28 +54,50 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
this.hasInput = false;
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent keyEvent) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
keyBuffer = keyEvent.getKeyChar();
|
||||
hasInput = true;
|
||||
|
||||
System.out.println("Key Pressed (0x" + Integer.toString((int)keyBuffer, 16) + ") : " + keyBuffer);
|
||||
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a key has been pressed since the last time input was read.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasInput() {
|
||||
return hasInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a Key Typed event.
|
||||
*
|
||||
* @param keyEvent The key event.
|
||||
*/
|
||||
public void keyTyped(KeyEvent keyEvent) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a Key Press event.
|
||||
*
|
||||
* @param keyEvent The key event.
|
||||
*/
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
keyBuffer = keyEvent.getKeyChar();
|
||||
hasInput = true;
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the most recently typed key from the single-char input buffer.
|
||||
*
|
||||
* @return The character typed.
|
||||
*/
|
||||
public char readInputChar() {
|
||||
hasInput = false;
|
||||
return this.keyBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a key release event.
|
||||
*
|
||||
* @param keyEvent The key event.
|
||||
*/
|
||||
public void keyReleased(KeyEvent keyEvent) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
|
||||
private JTextField aciaAddressField;
|
||||
private JTextField programLoadAddressField;
|
||||
private JTextField borderWidthField;
|
||||
|
||||
private int programLoadAddress = DEFAULT_PROGRAM_LOAD_ADDRESS;
|
||||
private int aciaAddress = DEFAULT_ACIA_ADDRESS;
|
||||
private int borderWidth = DEFAULT_BORDER_WIDTH;
|
||||
|
||||
public PreferencesDialog(Frame parent, boolean modal) {
|
||||
this.dialog = new JDialog(parent, modal);
|
||||
@@ -28,6 +30,9 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Validation of input.
|
||||
*/
|
||||
private void initComponents() {
|
||||
dialog.setTitle("Preferences");
|
||||
Container contents = dialog.getContentPane();
|
||||
@@ -40,12 +45,15 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
|
||||
final JLabel aciaAddressLabel = new JLabel("ACIA Address");
|
||||
final JLabel programLoadAddressLabel = new JLabel("Program Load Address");
|
||||
final JLabel borderWidthLabel = new JLabel("Console Border Width");
|
||||
|
||||
aciaAddressField = new JTextField(8);
|
||||
programLoadAddressField = new JTextField(8);
|
||||
borderWidthField = new JTextField(8);
|
||||
|
||||
aciaAddressLabel.setLabelFor(aciaAddressField);
|
||||
programLoadAddressLabel.setLabelFor(programLoadAddressField);
|
||||
borderWidthLabel.setLabelFor(borderWidthField);
|
||||
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
|
||||
@@ -66,6 +74,13 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
constraints.gridx = 1;
|
||||
settingsContainer.add(programLoadAddressField, constraints);
|
||||
|
||||
constraints.gridy = 2;
|
||||
constraints.gridx = 0;
|
||||
settingsContainer.add(borderWidthLabel, constraints);
|
||||
|
||||
constraints.gridx = 1;
|
||||
settingsContainer.add(borderWidthField, constraints);
|
||||
|
||||
JButton applyButton = new JButton("Apply");
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
|
||||
@@ -81,8 +96,11 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
programLoadAddress = hexToInt(programLoadAddressField.getText());
|
||||
aciaAddress = hexToInt(aciaAddressField.getText());
|
||||
borderWidth = Integer.parseInt(borderWidthField.getText());
|
||||
updateUi();
|
||||
notifyObservers();
|
||||
// TODO: Actually check to see if values have changed, don't assume.
|
||||
setChanged();
|
||||
PreferencesDialog.this.notifyObservers();
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
});
|
||||
@@ -96,6 +114,27 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
dialog.pack();
|
||||
}
|
||||
|
||||
public int getProgramStartAddress() {
|
||||
return programLoadAddress;
|
||||
}
|
||||
|
||||
public int getAciaAddress() {
|
||||
return aciaAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The width of the console border, in pixels.
|
||||
*/
|
||||
public int getBorderWidth() {
|
||||
return borderWidth;
|
||||
}
|
||||
|
||||
public void updateUi() {
|
||||
aciaAddressField.setText(intToHex(aciaAddress));
|
||||
programLoadAddressField.setText(intToHex(programLoadAddress));
|
||||
borderWidthField.setText(Integer.toString(borderWidth));
|
||||
}
|
||||
|
||||
private String intToHex(int i) {
|
||||
return String.format("%04x", i);
|
||||
}
|
||||
@@ -109,16 +148,4 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgramStartAddress() {
|
||||
return programLoadAddress;
|
||||
}
|
||||
|
||||
public int getAciaAddress() {
|
||||
return aciaAddress;
|
||||
}
|
||||
|
||||
public void updateUi() {
|
||||
aciaAddressField.setText(intToHex(aciaAddress));
|
||||
programLoadAddressField.setText(intToHex(programLoadAddress));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user