windowDefined = true;
   private boolean writeToDisplayStructuredField() {      boolean error = false;      boolean done = false;      int nextone;      try {         int length = (( bk.getNextByte() & 0xff )<< 8 | (bk.getNextByte() & 0xff));         while (!done) {            int s =    bk.getNextByte() & 0xff;            switch (s) {               case 0xD9:     // Class Type 0xD9 - Create Window                  switch (bk.getNextByte()) {//                     case 0x50:      // Define Selection Field////                        defineSelectionField(length);//                        done = true;//                        break;                     case 0x51:      // Create Window                        boolean cr = false;                        int rows = 0;                        int cols = 0;                        // pull down not supported yet                        if ((bk.getNextByte() & 0x80) == 0x80)                           cr = true;  // restrict cursor                        bk.getNextByte(); // get reserved field pos 6                        bk.getNextByte(); // get reserved field pos 7                        rows = bk.getNextByte(); // get window depth rows pos 8                        cols = bk.getNextByte(); // get window width cols pos 9                        length -= 9;                        if (length == 0) {                           done = true;//                           System.out.println("Create Window");//                           System.out.println("   restrict cursor " + cr);//                           System.out.println(" Depth = " + rows + " Width = " + cols);                           screen52.createWindow(rows,cols,1,true,32,58,                                             '.',                                             '.',                                             '.',                                             ':',                                             ':',                                             ':',                                             '.',                                             ':');                           break;                        }                        // pos 10 is Minor Structure                        int ml = 0;                        int type = 0;                        int lastPos = screen52.getLastPos();//                        if (cr)//                           screen52.setPendingInsert(true,//                                          screen52.getCurrentRow(),//                                          screen52.getCurrentCol());                        int mAttr = 0;                        int cAttr = 0;                        while (length > 0) {                           // get minor length                           ml = ( bk.getNextByte() & 0xff );                           length -= ml;                           // only normal windows are supported at this time                           type = bk.getNextByte();                           switch (type) {                              case 0x01 : // Border presentation                                 boolean gui = false;                                 if ((bk.getNextByte() & 0x80) == 0x80)                                    gui = true;                                 mAttr = bk.getNextByte();                                 cAttr = bk.getNextByte();                                 char ul = '.';                                 char upper = '.';                                 char ur = '.';                                 char left = ':';                                 char right = ':';                                 char ll = ':';                                 char bottom = '.';                                 char lr = ':';                                 // if minor length is greater than 5 then                                 //    the border characters are specified                                 if (ml > 5) {                                    ul = codePage.ebcdic2uni(bk.getNextByte());//                                    ul = getASCIIChar(bk.getNextByte());                                    if (ul == 0)                                       ul = '.';                                    upper = codePage.ebcdic2uni(bk.getNextByte());//                                    upper = getASCIIChar(bk.getNextByte());                                    if (upper == 0)                                       upper = '.';                                    ur = codePage.ebcdic2uni(bk.getNextByte());//                                    ur = getASCIIChar(bk.getNextByte());                                    if (ur == 0)                                       ur = '.';                                    left = codePage.ebcdic2uni(bk.getNextByte());//                                    left = getASCIIChar(bk.getNextByte());                                    if (left == 0)                                       left = ':';                                    right = codePage.ebcdic2uni(bk.getNextByte());//                                    right = getASCIIChar(bk.getNextByte());                                    if (right == 0)                                       right = ':';                                    ll = codePage.ebcdic2uni(bk.getNextByte());//                                    ll = getASCIIChar(bk.getNextByte());                                    if (ll == 0)                                       ll = ':';                                    bottom = codePage.ebcdic2uni(bk.getNextByte());//                                    bottom = getASCIIChar(bk.getNextByte());                                    if (bottom == 0)                                       bottom = '.';                                    lr = codePage.ebcdic2uni(bk.getNextByte());//                                    lr = getASCIIChar(bk.getNextByte());                                    if (lr == 0)                                       lr = ':';                                 }//                                 System.out.println("Create Window");//                                 System.out.println("   restrict cursor " + cr);//                                 System.out.println("   Depth = " + rows + " Width = " + cols);//                                 System.out.println("   type = " + type + " gui = " + gui);//                                 System.out.println("   mono attr = " + mAttr + " color attr = " + cAttr);//                                 System.out.println("   ul = " + ul + " upper = " + upper +//                                                         " ur = " + ur +//                                                         " left = " + left +//                                                         " right = " + right +//                                                         " ll = " + ll +//                                                         " bottom = " + bottom +//                                                         " lr = " + lr//                                                         );                                 screen52.createWindow(rows,cols,type,gui,mAttr,cAttr,                                                      ul,                                                      upper,                                                      ur,                                                      left,                                                      right,                                                      ll,                                                      bottom,                                                      lr);                              break;         //         //  The following shows the input for window with a title         //         //      +0000 019A12A0 00000400 00020411 00200107  ..........         //      +0010 00000018 00000011 06131500 37D95180  ...........R         //      +0020 00000A24 0D018023 23404040 40404040  ....؃         //      +0030 40211000 000000D7 C2C1D9C4 C5D4D67A   \uFFFD.....PBARDEMO:         //      +0040 40D79996 879985A2 A2408281 99408485   Progress bar de         //      +0050 94961108 1520D5A4 94828599 40968640  mo.Number of         //      +0060 8595A399 8985A24B 4B4B4B4B 4B7A2011  entries......:.         //      +0070 082E2040 404040F5 F0F06BF0 F0F02011  .    500,000.         //      +0080 091520C3 A4999985 95A34085 95A399A8  \uFFFDCurrent entry         //      +0090 4095A494 8285994B 4B4B7A20 11092E20   number...:.\uFFFD.         //      +00A0 40404040 4040F56B F0F0F020 110A1520        5,000.         //      +00B0 D9859481 89958995 87408595 A3998985  Remaining entrie         //      +00C0 A24B4B4B 4B4B4B7A 20110A2E 20404040  s......:..         //      +00D0 40F4F9F5 6BF0F0F0 20110C15 20E2A381   495,000..Sta         //      +00E0 99A340A3 8994854B 4B4B4B4B 4B4B4B4B  rt time.........         //      +00F0 4B4B4B4B 7A20110C 2F2040F7 7AF5F37A  ....:... 7:53:                              case 0x10 : // Window title/footer                                 byte orientation = bk.getNextByte();                                 mAttr = bk.getNextByte();                                 cAttr = bk.getNextByte();                                 //reserved                                 bk.getNextByte();                                 ml -= 6;                                 StringBuffer hfBuffer = new StringBuffer(ml);                                 while (ml-- > 0) {                                    //LDC - 13/02/2003 - Convert it to unicode                                    hfBuffer.append(codePage.ebcdic2uni(bk.getNextByte()));//                                    hfBuffer.append(getASCIIChar(bk.getNextByte()));                                 }                                 System.out.println(                                    " orientation " + Integer.toBinaryString(orientation) +                                    " mAttr " + mAttr +                                    " cAttr " + cAttr +                                    " Header/Footer " + hfBuffer);                                 screen52.writeWindowTitle(lastPos,                                                            rows,                                                            cols,                                                            orientation,                                                            mAttr,                                                            cAttr,                                                            hfBuffer);                                 break;                              default:                              System.out.println("Invalid Window minor structure");                              length = 0;                              done = true;                           }                        }                        done = true;                        break;                     case 0x53:      // Scroll Bar                        int sblen = 15;                        byte sbflag = bk.getNextByte();  // flag position 5                        bk.getNextByte();  // reserved position 6                        // position 7,8                        int totalRowScrollable =  (( bk.getNextByte() & 0xff )<< 8                                                | (bk.getNextByte() & 0xff));                        // position 9,10                        int totalColScrollable =  (( bk.getNextByte() & 0xff )<< 8                                                | (bk.getNextByte() & 0xff));                        // position 11,12                        int sliderRowPos =  (( bk.getNextByte() & 0xff )<< 8                                                | (bk.getNextByte() & 0xff));                        // position 13,14                        int sliderColPos =  (( bk.getNextByte() & 0xff )<< 8                                                | (bk.getNextByte() & 0xff));                        // position 15                        int sliderRC = bk.getNextByte();                        screen52.createScrollBar(sbflag,totalRowScrollable,                                                   totalColScrollable,                                                   sliderRowPos,                                                   sliderColPos,                                                   sliderRC);                        length -= 15;                        done = true;                        break;                     case 0x5B:      // Remove GUI ScrollBar field                        bk.getNextByte(); // reserved must be set to off pos 5                        bk.getNextByte(); // reserved must be set to zero pos 6                        done = true;                        break;                     case 0x5F:      // Remove All GUI Constructs//                        System.out.println("remove all gui contructs");                        int len = 4;                        int d = 0;                        length -= s;                        while (--len > 0)                           d = bk.getNextByte();//                        if (length > 0) {//                           len = (bk.getNextByte() & 0xff )<< 8;////                           while (--len > 0)//                              d = bk.getNextByte();//                        }                        screen52.clearGuiStuff();                        // per 14.6.13.4 documentation we should clear the                        //    format table after this command                        screen52.clearTable();                        done = true;                        break;                     case 0x60:      // Erase/Draw Grid Lines - not supported                                    // do not know what they are                                    // as of 03/11/2002 we should not be getting                                    // this anymore but I will leave it here                                    //  just in case.//                        System.out.println("erase/draw grid lines " + length);                        len = 6;                        d = 0;                        length -= 9;                        while (--len > 0)                           d = bk.getNextByte();                           if (length > 0) {                              len = (bk.getNextByte() & 0xff )<< 8;                           while (--len > 0) {                              d = bk.getNextByte();                           }                        }                        done = true;                        break;                     default:                        sendNegResponse(NR_REQUEST_ERROR,0x03,0x01,0x01,"invalid wtd structured field sub command "                                                   + bk.getByteOffset(-1));                        error = true;                        break;                  }                  break;               default:                  sendNegResponse(NR_REQUEST_ERROR,0x03,0x01,0x01,                              "invalid wtd structured field command "                               + bk.getByteOffset(-1));                  error = true;                  break;            }            if (error)               done = true;         }      }      catch (Exception e) {};      return error;   }