Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying Unformatted screens as Input field #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/main/java/net/sf/f3270/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Terminal {
private final boolean showTerminalWindow;
private static final char MAINFRAME_BLANK_CHAR = '\u0000';
private static final char SINGLE_SPACE = ' ';
private static final String MASKED_VALUE = "****";

public Terminal(final String s3270Path, final String hostname, final int port, final TerminalType type,
final TerminalMode mode, final boolean showTerminalWindow) {
Expand Down Expand Up @@ -202,8 +203,23 @@ public void write(String label, String value, int skip, int matchNumber, MatchMo

public void write(FieldIdentifier fieldIdentifier, String value) {
assertConnected();
getInputField(fieldIdentifier).setValue(value);
commandIssued("write", null, buildParameters(fieldIdentifier, value));
InputField inputField = getInputField(fieldIdentifier);
inputField.setValue(value);
commandIssued("write", null, buildParameters(fieldIdentifier, getMaskedValueIfFieldIsHidden(inputField, value)));
}

public void write(FieldIdentifier fieldIdentifier, int lineNumber, String value) {
assertConnected();
InputField inputField = getInputField(fieldIdentifier);
if(!inputField.isMultiline()){
throw new RuntimeException("write method with Line Number can be used only with multi-line input field");
}
inputField.setValue(lineNumber, value);
commandIssued("write", null, buildParameters(fieldIdentifier, getMaskedValueIfFieldIsHidden(inputField, value)));
}

private String getMaskedValueIfFieldIsHidden(InputField inputField, String value) {
return inputField.isHidden()? MASKED_VALUE : value;
}

/**
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/net/sf/f3270/TerminalWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@

public class TerminalWindow {

private S3270 s3270;
private static final String MASKED_VALUE = "****";
private S3270 s3270;
private int currentWidth;
private int currentHeight;

private Style styleInputChanged;
private Style styleInput;
private Style styleHidden;
private Style styleBlack;

private Style styleCommand;
Expand Down Expand Up @@ -83,6 +85,7 @@ public TerminalWindow(final S3270 s3270) {
private void initializeStyles() {
styleInputChanged = createStyle(Color.black, Color.red, false);
styleInput = createStyle(Color.green, Color.black, false);
styleHidden= createStyle(Color.black, Color.black, false);
styleCommand = createStyle(Color.black, Color.white, false);
stylePunctuation = createStyle(Color.gray, Color.white, false);
styleReturn = createStyle(Color.magenta, Color.white, false);
Expand Down Expand Up @@ -159,6 +162,10 @@ private void updateFieldsTable() {

private Style getStyle(final Field f) {
final boolean isInput = f instanceof InputField;
if (f.isHidden()) {
return styleHidden;
}

if (isInput) {
final InputField inputField = (InputField) f;
if (inputField.isChanged()) {
Expand All @@ -182,13 +189,6 @@ private Style getStyle(final Field f) {
if (f.isIntensified()) {
foregroundColor = Color.white;
}

if (f.isHidden()) {
foregroundColor = Color.black;
backgroundColor = Color.black;
isUnderline = false;
}

return createStyle(foregroundColor, backgroundColor, isUnderline);
}

Expand Down Expand Up @@ -325,12 +325,17 @@ public Object getValueAt(final int rowIndex, final int columnIndex) {
.isChanged()) ? " *" : "");
}
if (columnIndex == 2) {
return "[" + f.getValue().replace('\u0000', ' ') + "]";
return getMaskedValueIfFieldIsHidden(f);
}
throw new RuntimeException("unknown column index "
+ columnIndex);
}

private String getMaskedValueIfFieldIsHidden(Field f) {
String value = f.isHidden() ? MASKED_VALUE : f.getValue().replace('\u0000', ' ');
return "[" + value + "]";
}

public boolean isCellEditable(final int rowIndex,
final int columnIndex) {
return columnIndex == 2;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/h3270/host/S3270Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private char[] decode(String line, final int y, final List<Field> fields) {

private Field createField(final byte startCode, final int startx, final int starty, final int endx, final int endy,
final int color, final int extHighlight) {
if ((startCode & Field.ATTR_PROTECTED) == 0) {
if ((startCode & Field.ATTR_PROTECTED) == 0 || !isFormatted) {
return new InputField(this, startCode, startx, starty, endx, endy, color, extHighlight);
} else {
return new Field(this, startCode, startx, starty, endx, endy, color, extHighlight);
Expand Down