From 665f187ef1caef4c4aa0269a2e540a56200b323f Mon Sep 17 00:00:00 2001 From: Dominik Downarowicz Date: Wed, 16 Mar 2022 22:18:13 +0100 Subject: [PATCH] Changed Fields from Array to ArrayList --- pom.xml | 2 +- .../java/at/downardo/j3270Server/Looper.java | 8 +++- .../java/at/downardo/j3270Server/Screen.java | 10 +++-- .../downardo/j3270Server/example/Example.java | 38 +++++++++++++++++-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 72fadb3..3160579 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 at.downardo j3270Server - 0.0.5 + 0.0.6 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/Looper.java b/src/main/java/at/downardo/j3270Server/Looper.java index feadae0..5116330 100644 --- a/src/main/java/at/downardo/j3270Server/Looper.java +++ b/src/main/java/at/downardo/j3270Server/Looper.java @@ -47,11 +47,17 @@ public static Response HandleScreen(Screen screen, HashMap ru HashMap origValues = new HashMap(); HashMap fields = new HashMap(); - for(int i = 0; i < screen.getFields().length; i++) { + /*for(int i = 0; i < screen.getFields().length; i++) { if(screen.getFields()[i].getName() != "") { origValues.put(screen.getFields()[i].getName(), screen.getFields()[i].getContent()); fields.put(screen.getFields()[i].getName(), screen.getFields()[i]); } + }*/ + for(Field fld : screen.getFields()) { + if(fld.getName() != "") { + origValues.put(fld.getName(), fld.getContent()); + fields.put(fld.getName(), fld); + } } //Make our own field values map so we don't alter the caller's value diff --git a/src/main/java/at/downardo/j3270Server/Screen.java b/src/main/java/at/downardo/j3270Server/Screen.java index cc08c14..ca0454c 100644 --- a/src/main/java/at/downardo/j3270Server/Screen.java +++ b/src/main/java/at/downardo/j3270Server/Screen.java @@ -22,13 +22,17 @@ */ public class Screen { - private Field[] fields; + //private Field[] fields; + private ArrayList fields; - public Screen(Field[] _fields) { + /*public Screen(Field[] _fields) { + this.fields = _fields; + }*/ + public Screen(ArrayList _fields) { this.fields = _fields; } - public Field[] getFields() { + public ArrayList getFields() { return fields; } diff --git a/src/main/java/at/downardo/j3270Server/example/Example.java b/src/main/java/at/downardo/j3270Server/example/Example.java index 7ecef7b..ca76c25 100644 --- a/src/main/java/at/downardo/j3270Server/example/Example.java +++ b/src/main/java/at/downardo/j3270Server/example/Example.java @@ -12,6 +12,8 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import at.downardo.j3270Server.AIDClass.AID; @@ -42,7 +44,7 @@ public void run() { Telnet.NegotiateTelnet(out, in); EBCDIC.CODEPAGE = "CP1148"; - + /* Field[] fields = { new Field(0,0,"HALLO WELT TEST €", false, true, false, "", Field.Colour.Blue, Field.Highlight.Blink), new Field(1,0, "Name", false, true, false, ""), @@ -61,8 +63,27 @@ public void run() { new Field(6,0, "Test", false, false, false, ""), new Field(22,0, "", false, true, false, "errormsg", Field.Colour.Red), new Field(23,0, "PF3 Exit", false, true, false, "") - - }; + };*/ + ArrayList fields = new ArrayList(); + Collections.addAll(fields, + 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, "Age", false, true, false, ""), + new Field(2,13, "", true, false, false, "age", Field.Colour.Turquosie, Field.Highlight.ReverseVideo), + new Field(2,16, "", false, false, false), + new Field(3,0, "Company", false, true, false, ""), + new Field(3,13, "", true, false, false, "company", Field.Colour.Turquosie, Field.Highlight.ReverseVideo), + new Field(3,40, "", false, false, false), + new Field(4,0, "Password ", false, false, false, ""), + new Field(4, 13, "", true, false, true, "password"), + new Field(4,40, "",false,false,false), + new Field(5,0, "Test", false, true, false, ""), + new Field(6,0, "Test", false, false, false, ""), + new Field(22,0, "", false, true, false, "errormsg", Field.Colour.Red), + new Field(23,0, "PF3 Exit", false, true, false, "") + ); Validator nonBlank = new NonBlankValidator(); Validator isInteger = new IsIntegerValidator(); @@ -72,13 +93,22 @@ public void run() { screen1Rules.put("age", new FieldRule(false, "", isInteger, false)); screen1Rules.put("password", new FieldRule(false, "", nonBlank, true)); screen1Rules.put("company", new FieldRule(true, "Must be changed!", nonBlank, true)); - + /* Field[] fields2 = { new Field(0,0,"HALLO WELT TEST WORLD 2", 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, "") }; + */ + + ArrayList fields2 = new ArrayList(); + Collections.addAll(fields2, + new Field(0,0,"HALLO WELT TEST WORLD 2", 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, "") + ); Screen screen = new Screen(fields); Screen screen2 = new Screen(fields2);