diff --git a/pom.xml b/pom.xml index be0f67d..90cf02c 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 at.downardo j3270Server - 0.0.1-SNAPSHOT + 0.0.2 Java 3270 Server jar This libary allows the user to write servers for IBM 3270 Terminal emulators. diff --git a/src/main/java/at/downardo/j3270Server/Field.java b/src/main/java/at/downardo/j3270Server/Field.java index 3c9624a..d785992 100644 --- a/src/main/java/at/downardo/j3270Server/Field.java +++ b/src/main/java/at/downardo/j3270Server/Field.java @@ -6,6 +6,8 @@ **/ package at.downardo.j3270Server; + + /** * Field is a field on the 3270 screen * @author downarowiczd @@ -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; + } + } /** * @@ -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; @@ -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; } /** @@ -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; + } diff --git a/src/main/java/at/downardo/j3270Server/Screen.java b/src/main/java/at/downardo/j3270Server/Screen.java index d264ed1..65626c4 100644 --- a/src/main/java/at/downardo/j3270Server/Screen.java +++ b/src/main/java/at/downardo/j3270Server/Screen.java @@ -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. @@ -64,7 +66,7 @@ public static Response ShowScreen(Screen screen, HashMap values, buffer.write(_t); } - for(int _t : Screen.sf(fld.isWrite(), fld.isIntense(), fld.isHidden())){ + for(int _t : Screen.buildField(fld)){ buffer.write(_t); } @@ -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; @@ -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 @@ -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 _return = new ArrayList(); + + 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; + + } } diff --git a/src/main/java/at/downardo/j3270Server/Util.java b/src/main/java/at/downardo/j3270Server/Util.java index 114202c..cb7a6e7 100644 --- a/src/main/java/at/downardo/j3270Server/Util.java +++ b/src/main/java/at/downardo/j3270Server/Util.java @@ -51,7 +51,7 @@ public class Util { * @param integers * @return */ - /* + public static int[] convertIntegers(List integers) { int[] ret = new int[integers.size()]; @@ -61,7 +61,7 @@ public static int[] convertIntegers(List integers) } return ret; } - */ + /** diff --git a/src/main/java/at/downardo/j3270Server/example/Example.java b/src/main/java/at/downardo/j3270Server/example/Example.java index 3dd6dbb..7e1298f 100644 --- a/src/main/java/at/downardo/j3270Server/example/Example.java +++ b/src/main/java/at/downardo/j3270Server/example/Example.java @@ -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, "") }; @@ -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;