Skip to content

Commit

Permalink
Add support for extended field attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Downarowicz committed Feb 27, 2022
1 parent cfc2252 commit 25cedbb
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.downardo</groupId>
<artifactId>j3270Server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2</version>
<name>Java 3270 Server</name>
<packaging>jar</packaging>
<description>This libary allows the user to write servers for IBM 3270 Terminal emulators.</description>
Expand Down
127 changes: 127 additions & 0 deletions src/main/java/at/downardo/j3270Server/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
**/
package at.downardo.j3270Server;


/**
* Field is a field on the 3270 screen
* @author downarowiczd
Expand Down Expand Up @@ -43,6 +45,41 @@ public class Field {
public String Name;

public boolean Hidden;

public Colour colour;

public Highlight highlight;


public static enum Colour {
DefaultColour(0),
Blue(0xf1),
Red(0xf2),
Pink(0xf3),
Green(0xf4),
Turquosie(0xf5),
Yellow(0xf6),
White(0xf7);

public int value;
private Colour(int value) {
this.value = value;
}

}

public static enum Highlight {
DefaultHighlight(0),
Blink(0xf1),
ReverseVideo(0xf2),
Underscore(0xf4);


public int value;
private Highlight(int value) {
this.value = value;
}
}

/**
*
Expand All @@ -54,6 +91,54 @@ public class Field {
* @param hidden
* @param name
*/
public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name, Colour colour, Highlight highlight) {
Row = row;
Col = col;
Content = content;
Write = write;
Intense = intense;
Name = name;
Hidden = hidden;
this.colour = colour;
this.highlight = highlight;
}

public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, Colour colour, Highlight highlight) {
Row = row;
Col = col;
Content = content;
Write = write;
Intense = intense;
Name = "";
Hidden = hidden;
this.colour = colour;
this.highlight = highlight;
}

public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, Colour colour) {
Row = row;
Col = col;
Content = content;
Write = write;
Intense = intense;
Name = "";
Hidden = hidden;
this.colour = colour;
highlight = Highlight.DefaultHighlight;
}

public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name, Colour colour) {
Row = row;
Col = col;
Content = content;
Write = write;
Intense = intense;
Name = name;
Hidden = hidden;
this.colour = colour;
highlight = Highlight.DefaultHighlight;
}

public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name) {
Row = row;
Col = col;
Expand All @@ -62,6 +147,20 @@ public Field(int row, int col, String content, boolean write, boolean intense, b
Intense = intense;
Name = name;
Hidden = hidden;
this.colour = Colour.DefaultColour;
highlight = Highlight.DefaultHighlight;
}

public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden) {
Row = row;
Col = col;
Content = content;
Write = write;
Intense = intense;
Name = "";
Hidden = hidden;
this.colour = Colour.DefaultColour;
highlight = Highlight.DefaultHighlight;
}

/**
Expand Down Expand Up @@ -151,6 +250,34 @@ public int getRow() {
public void setRow(int row) {
Row = row;
}

/**
* @return the colour
*/
public Colour getColour() {
return colour;
}

/**
* @param colour the colour to set
*/
public void setColour(Colour colour) {
this.colour = colour;
}

/**
* @return the highlight
*/
public Highlight getHighlight() {
return highlight;
}

/**
* @param highlight the highlight to set
*/
public void setHighlight(Highlight highlight) {
this.highlight = highlight;
}



Expand Down
79 changes: 76 additions & 3 deletions src/main/java/at/downardo/j3270Server/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* Screen is an array of fields which compose a complete 3270 screen.
Expand Down Expand Up @@ -64,7 +66,7 @@ public static Response ShowScreen(Screen screen, HashMap<String, String> values,
buffer.write(_t);
}

for(int _t : Screen.sf(fld.isWrite(), fld.isIntense(), fld.isHidden())){
for(int _t : Screen.buildField(fld)){
buffer.write(_t);
}

Expand Down Expand Up @@ -143,7 +145,7 @@ public static int[] sba(int row, int col) {
* @param hidden
* @return
*/
public static int[] sf(boolean write, boolean intense, boolean hidden) {
/* public static int[] sf(boolean write, boolean intense, boolean hidden) {
int[] _return = new int[2];
_return[0] = 0x1d;
Expand All @@ -168,7 +170,9 @@ public static int[] sf(boolean write, boolean intense, boolean hidden) {
return _return;
}
}*/



/**
* ic is the "insert cursor" 3270 command. This function will include the appropriate SBA command
Expand Down Expand Up @@ -209,6 +213,75 @@ public static int[] getPos(int row, int col) {

return _return;
}
/**
* Will return either an sf or sfe command depending for the field
* @param f
* @return
*/
public static int[] buildField(Field f) {
List<Integer> _return = new ArrayList<Integer>();

if(f.getColour() == Field.Colour.DefaultColour && f.getHighlight() == Field.Highlight.DefaultHighlight) {
_return.add(0x1d); //sf - "start field"
_return.add(sfAttribute(f.isWrite(), f.isIntense(), f.isHidden()));

return Util.convertIntegers(_return);
}

_return.add(0x29); //sfe - "start field extended"
int paramCount = 1;
if(f.getColour() != Field.Colour.DefaultColour) {
paramCount++;
}
if(f.getHighlight() != Field.Highlight.DefaultHighlight) {
paramCount++;
}
_return.add(paramCount);

//Write the basic field attribute
_return.add(0xc0);
_return.add(sfAttribute(f.isWrite(), f.isIntense(), f.isHidden()));

if(f.getHighlight() != Field.Highlight.DefaultHighlight) {
_return.add(0x41);
_return.add(f.getHighlight().value);
}

if(f.getColour() != Field.Colour.DefaultColour) {
_return.add(0x42);
_return.add(f.getColour().value);
}

return Util.convertIntegers(_return);

}


public static int sfAttribute(boolean write, boolean intense, boolean hidden) {
int _return = 0;;


if(!write) {
_return |= 1 << 5;
}else {
_return |= 1;
}

if(intense) {
_return |= 1 << 3;
}

if(hidden) {
_return |= 1 << 3;
_return |= 1 << 2;
}


_return = Util.codes[_return];

return _return;

}


}
4 changes: 2 additions & 2 deletions src/main/java/at/downardo/j3270Server/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Util {
* @param integers
* @return
*/
/*

public static int[] convertIntegers(List<Integer> integers)
{
int[] ret = new int[integers.size()];
Expand All @@ -61,7 +61,7 @@ public static int[] convertIntegers(List<Integer> integers)
}
return ret;
}
*/



/**
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/at/downardo/j3270Server/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,23 @@ public void run() {
EBCDIC.CODEPAGE = "CP1148";

Field[] fields = {
new Field(0,0,"HALLO WELT TEST €", false, true, false, ""),
new Field(1,0, "Name ....", false, true, false, ""),
new Field(1,13, "", true, false, false, "name"),
new Field(0,0,"HALLO WELT TEST €", false, true, false, "", Field.Colour.Blue, Field.Highlight.Blink),
new Field(1,0, "Name", false, true, false, ""),
new Field(1,13, "", true, false, false, "name", Field.Colour.Turquosie, Field.Highlight.ReverseVideo),
new Field(1,40, "", false, false, false),
new Field(2,0, "Password ", false, false, false, ""),
new Field(2, 13, "", true, false, true, "password"),
new Field(2, 13, "", true, false, true, "password", Field.Colour.DefaultColour, Field.Highlight.ReverseVideo),
new Field(2,40, "",false,false,false),
new Field(3,0, "Test", false, true, false, ""),
new Field(4,0, "Test", false, false, false, ""),
new Field(22,0, "", false, true, false, "errormsg"),
new Field(22,0, "", false, true, false, "errormsg", Field.Colour.Red),
new Field(23,0, "PF3 Exit", false, true, false, "")

};

Field[] fields2 = {
new Field(0,0,"HALLO WELT TEST WORLD 2", false, true, false, ""),
new Field(1,0, "Name ....", false, true, false, ""),
new Field(1,0, "Name", false, true, false, ""),
new Field(22,0, "", false, true, false, "errormsg"),
new Field(1,13, "", false, false, false, "")
};
Expand All @@ -68,7 +70,6 @@ public void run() {
fieldValues.put("errormsg", "");
while(true) {
Response r = Screen.ShowScreen(screen, fieldValues, 1, 14, out, in);
System.out.println(fieldValues.get("errormsg"));

if(r.AID == AID.AIDPF3) {
break;
Expand Down

0 comments on commit 25cedbb

Please sign in to comment.