Mercurial > 510Connectbot
diff src/org/tn5250j/framework/tn5250/Screen5250.java @ 112:77ac18bc1b2f
cleanup java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 13:03:01 -0700 |
parents | 6a0ad4d384ea |
children | cb3b9b660b3d |
line wrap: on
line diff
--- a/src/org/tn5250j/framework/tn5250/Screen5250.java Wed Jun 18 13:00:19 2014 -0700 +++ b/src/org/tn5250j/framework/tn5250/Screen5250.java Wed Jun 18 13:03:01 2014 -0700 @@ -101,34 +101,27 @@ public Screen5250() { - //Added by Barry this.keybuf = new StringBuffer(); try { jbInit(); - } catch (Exception ex) { - Log.w(TAG,"In constructor: ", ex); + } + catch (Exception ex) { + Log.w(TAG, "In constructor: ", ex); } } void jbInit() throws Exception { - lastAttr = 32; - // default number of rows and columns numRows = 24; numCols = 80; - setCursor(1, 1); // set initial cursor position - oia = new ScreenOIA(this); oia.setKeyBoardLocked(true); - lenScreen = numRows * numCols; - - planes = new ScreenPlanes(this,numRows); - + planes = new ScreenPlanes(this, numRows); screenFields = new ScreenFields(this); strokenizer = new KeyStrokenizer(); } @@ -142,29 +135,23 @@ } protected final void setRowsCols(int rows, int cols) { - int oldRows = numRows; int oldCols = numCols; - // default number of rows and columns numRows = rows; numCols = cols; - lenScreen = numRows * numCols; - planes.setSize(rows); // If they are not the same then we need to inform the listeners that // the size changed. if (oldRows != numRows || oldCols != numCols) fireScreenSizeChanged(); - } public boolean isCursorActive() { return cursorActive; - } public boolean isCursorShown() { @@ -197,8 +184,7 @@ StringBuilder sb = new StringBuilder(); Rect workR = new Rect(); workR.setBounds(area); - Log.d(TAG,"Copying " + workR); - + Log.d(TAG, "Copying " + workR); // loop through all the screen characters to send them to the clip board int m = workR.x; int i = 0; @@ -207,9 +193,11 @@ while (workR.height-- > 0) { t = workR.width; i = workR.y; + while (t-- > 0) { // only copy printable characters (in this case >= ' ') char c = planes.getChar(getPos(m - 1, i - 1)); + if (c >= ' ' && (planes.screenExtended[getPos(m - 1, i - 1)] & EXTENDED_5250_NON_DSP) == 0) sb.append(c); @@ -218,9 +206,11 @@ i++; } + sb.append('\n'); m++; } + return sb.toString(); } @@ -231,40 +221,32 @@ * @see {@link #copyText(Rectangle)} */ public final void pasteText(String content, boolean special) { - Log.d(TAG,"Pasting, special:"+special); + Log.d(TAG, "Pasting, special:" + special); setCursorActive(false); - StringBuilder sb = new StringBuilder(content); StringBuilder pd = new StringBuilder(); - // character counters within the string to be pasted. int nextChar = 0; int nChars = sb.length(); - int lr = getRow(lastPos); int lc = getCol(lastPos); resetDirty(lastPos); - int cpos = lastPos; int length = getScreenLength(); - char c = 0; boolean setIt; - // save our current place within the FFT. screenFields.saveCurrentField(); for (int x = nextChar; x < nChars; x++) { - c = sb.charAt(x); if ((c == '\n') || (c == '\r')) { - - Log.i(TAG,"pasted cr-lf>" + pd + "<"); + Log.i(TAG, "pasted cr-lf>" + pd + "<"); pd.setLength(0); // if we read in a cr lf in the data stream we need to go // to the starting column of the next row and start from there - cpos = getPos(getRow(cpos)+1,lc); + cpos = getPos(getRow(cpos) + 1, lc); // If we go paste the end of the screen then let's start over from // the beginning of the screen space. @@ -272,7 +254,6 @@ cpos = 0; } else { - // we will default to set the character always. setIt = true; @@ -288,9 +269,11 @@ setDirty(cpos); screenFields.setCurrentFieldMDT(); } + // If we placed a character then we go to the next position. if (setIt) cpos++; + // we will append the information to our debug buffer. pd.append(c); } @@ -298,17 +281,14 @@ // if we have anything else not logged then log it out. if (pd.length() > 0) - Log.i(TAG,"pasted >" + pd + "<"); + Log.i(TAG, "pasted >" + pd + "<"); // restore out position within the FFT. screenFields.restoreCurrentField(); updateDirty(); - // restore our cursor position. setCursor(lr + 1, lc + 1); - setCursorActive(true); - } /** @@ -340,45 +320,38 @@ * @return vector string of numberic values */ public final Vector<Double> sumThem(boolean which, Rect area) { - StringBuilder sb = new StringBuilder(); Rect workR = new Rect(); workR.setBounds(area); - // gui.rubberband.reset(); // gui.repaint(); - - Log.d(TAG,"Summing"); - + Log.d(TAG, "Summing"); // obtain the decimal format for parsing DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); - DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); if (which) { dfs.setDecimalSeparator('.'); dfs.setGroupingSeparator(','); - } else { + } + else { dfs.setDecimalSeparator(','); dfs.setGroupingSeparator('.'); } df.setDecimalFormatSymbols(dfs); - Vector<Double> sumVector = new Vector<Double>(); - // loop through all the screen characters to send them to the clip board int m = workR.x; int i = 0; int t = 0; - double sum = 0.0; while (workR.height-- > 0) { t = workR.width; i = workR.y; + while (t-- > 0) { - // only copy printable numeric characters (in this case >= ' ') // char c = screen[getPos(m - 1, i - 1)].getChar(); char c = planes.getChar(getPos(m - 1, i - 1)); @@ -389,6 +362,7 @@ if (((c >= '0' && c <= '9') || c == '.' || c == ',' || c == '-')) { sb.append(c); } + i++; } @@ -397,21 +371,24 @@ sb.insert(0, '-'); sb.deleteCharAt(sb.length() - 1); } + try { Number n = df.parse(sb.toString()); // System.out.println(s + " " + n.doubleValue()); - sumVector.add(new Double(n.doubleValue())); sum += n.doubleValue(); - } catch (ParseException pe) { - Log.w(TAG,pe.getMessage() + " at " - + pe.getErrorOffset()); + } + catch (ParseException pe) { + Log.w(TAG, pe.getMessage() + " at " + + pe.getErrorOffset()); } } + sb.setLength(0); m++; } - Log.d(TAG,"" + sum); + + Log.d(TAG, "" + sum); return sumVector; } @@ -425,108 +402,119 @@ * @param pos */ public boolean moveCursor(int pos) { - if (!oia.isKeyBoardLocked()) { - if (pos < 0) return false; + // because getRowColFromPoint returns offset of 1,1 we need to // translate to offset 0,0 // pos -= (numCols + 1); - int g = planes.getWhichGUI(pos); // lets check for hot spots if (g >= BUTTON_LEFT && g <= BUTTON_LAST) { StringBuffer aid = new StringBuffer(); boolean aidFlag = true; + switch (g) { - case BUTTON_RIGHT: - case BUTTON_MIDDLE: - while (planes.getWhichGUI(--pos) != BUTTON_LEFT) { - } - case BUTTON_LEFT: - if (planes.getChar(pos) == 'F') { - pos++; - } else - aidFlag = false; - - if (planes.getChar(pos + 1) != '=' - && planes.getChar(pos + 1) != '.' - && planes.getChar(pos + 1) != '/') { - Log.d(TAG," Hotspot clicked!!! we will send characters " - + planes.getChar(pos) + " " + planes.getChar(pos+1)); - aid.append(planes.getChar(pos)); - aid.append(planes.getChar(pos + 1)); - } else { - Log.d(TAG," Hotspot clicked!!! we will send character " - + planes.getChar(pos)); - aid.append(planes.getChar(pos)); - } - break; - + case BUTTON_RIGHT: + case BUTTON_MIDDLE: + while (planes.getWhichGUI(--pos) != BUTTON_LEFT) { + } + + case BUTTON_LEFT: + if (planes.getChar(pos) == 'F') { + pos++; + } + else + aidFlag = false; + + if (planes.getChar(pos + 1) != '=' + && planes.getChar(pos + 1) != '.' + && planes.getChar(pos + 1) != '/') { + Log.d(TAG, " Hotspot clicked!!! we will send characters " + + planes.getChar(pos) + " " + planes.getChar(pos + 1)); + aid.append(planes.getChar(pos)); + aid.append(planes.getChar(pos + 1)); + } + else { + Log.d(TAG, " Hotspot clicked!!! we will send character " + + planes.getChar(pos)); + aid.append(planes.getChar(pos)); + } + + break; } + if (aidFlag) { switch (g) { - - case BUTTON_LEFT_UP: - case BUTTON_MIDDLE_UP: - case BUTTON_RIGHT_UP: - case BUTTON_ONE_UP: - case BUTTON_SB_UP: - case BUTTON_SB_GUIDE: - sessionVT.sendAidKey(AID_ROLL_UP); - break; - - case BUTTON_LEFT_DN: - case BUTTON_MIDDLE_DN: - case BUTTON_RIGHT_DN: - case BUTTON_ONE_DN: - case BUTTON_SB_DN: - case BUTTON_SB_THUMB: - - sessionVT.sendAidKey(AID_ROLL_DOWN); - break; - case BUTTON_LEFT_EB: - case BUTTON_MIDDLE_EB: - case BUTTON_RIGHT_EB: - StringBuffer eb = new StringBuffer(); - while (planes.getWhichGUI(pos--) != BUTTON_LEFT_EB) - ; - while (planes.getWhichGUI(pos++) != BUTTON_RIGHT_EB) { - eb.append(planes.getChar(pos)); - } - sessionVT.showURL(eb.toString()); - // take out the log statement when we are sure it is - // working - Log.i(TAG,"Send to external Browser: " + eb.toString()); - break; - - default: - int aidKey = Integer.parseInt(aid.toString()); - if (aidKey >= 1 && aidKey <= 12) - sessionVT.sendAidKey(0x30 + aidKey); - if (aidKey >= 13 && aidKey <= 24) - sessionVT.sendAidKey(0xB0 + (aidKey - 12)); + case BUTTON_LEFT_UP: + case BUTTON_MIDDLE_UP: + case BUTTON_RIGHT_UP: + case BUTTON_ONE_UP: + case BUTTON_SB_UP: + case BUTTON_SB_GUIDE: + sessionVT.sendAidKey(AID_ROLL_UP); + break; + + case BUTTON_LEFT_DN: + case BUTTON_MIDDLE_DN: + case BUTTON_RIGHT_DN: + case BUTTON_ONE_DN: + case BUTTON_SB_DN: + case BUTTON_SB_THUMB: + sessionVT.sendAidKey(AID_ROLL_DOWN); + break; + + case BUTTON_LEFT_EB: + case BUTTON_MIDDLE_EB: + case BUTTON_RIGHT_EB: + StringBuffer eb = new StringBuffer(); + + while (planes.getWhichGUI(pos--) != BUTTON_LEFT_EB) + ; + + while (planes.getWhichGUI(pos++) != BUTTON_RIGHT_EB) { + eb.append(planes.getChar(pos)); + } + + sessionVT.showURL(eb.toString()); + // take out the log statement when we are sure it is + // working + Log.i(TAG, "Send to external Browser: " + eb.toString()); + break; + + default: + int aidKey = Integer.parseInt(aid.toString()); + + if (aidKey >= 1 && aidKey <= 12) + sessionVT.sendAidKey(0x30 + aidKey); + + if (aidKey >= 13 && aidKey <= 24) + sessionVT.sendAidKey(0xB0 + (aidKey - 12)); } - } else { + } + else { if (screenFields.getCurrentField() != null) { int xPos = screenFields.getCurrentField().startPos(); + for (int x = 0; x < aid.length(); x++) { // System.out.println(sr + "," + (sc + x) + " " + // aid.charAt(x)); planes.setChar(xPos + x , aid.charAt(x)); } + // System.out.println(aid); screenFields.setCurrentFieldMDT(); sessionVT.sendAidKey(AID_ENTER); } - } + // return back to the calling routine that the cursor was not moved // but something else here was done like aid keys or the such return false; } + // this is a note to not execute this code here when we // implement // the remain after edit function option. @@ -536,12 +524,12 @@ // } else { goto_XY(pos); isInField(lastPos); - // return back to the calling object that the cursor was indeed // moved with in the screen object return true; // } } + return false; } @@ -562,19 +550,19 @@ */ private int getMnemonicValue(String mnem) { if (mnemonicMap.containsKey(mnem)) return mnemonicMap.get(mnem); + return 0; } protected void setPrehelpState(boolean setErrorCode, boolean lockKeyboard, - boolean unlockIfLocked) { + boolean unlockIfLocked) { if (oia.isKeyBoardLocked() && unlockIfLocked) oia.setKeyBoardLocked(false); else oia.setKeyBoardLocked(lockKeyboard); + bufferedKeys = null; oia.setKeysBuffered(false); - - } /** @@ -583,13 +571,13 @@ * @param activate */ public void setCursorActive(boolean activate) { - // System.out.println("cursor active " + updateCursorLoc + " " + // cursorActive + " " + activate); if (cursorActive && !activate) { setCursorOff(); cursorActive = activate; - } else { + } + else { if (!cursorActive && activate) { cursorActive = activate; setCursorOn(); @@ -609,12 +597,10 @@ * Set the cursor off */ public void setCursorOff() { - cursorShown = false; updateCursorLoc(); // System.out.println("cursor off " + updateCursorLoc + " " + // cursorActive); - } /** @@ -935,6 +921,7 @@ * @see #sendAid * */ + public synchronized void sendKeys(String text) { Log.d(TAG, "sendKeys() " + text); this.keybuf.append(text); @@ -951,8 +938,8 @@ setCursorActive(false); simulateMnemonic(getMnemonicValue(text)); setCursorActive(true); - - } else { + } + else { if (isStatusErrorCode()) { sessionVT.signalBell(); return; @@ -962,24 +949,26 @@ if (bufferedKeys == null) bufferedKeys = text; else bufferedKeys += text; + return; } - - } else { - + } + else { if (oia.isKeysBuffered()) { if (bufferedKeys != null) { text = bufferedKeys + text; } + // if (text.length() == 0) { oia.setKeysBuffered(false); // } bufferedKeys = null; - } + // check to see if position is in a field and if it is then change // current field to that field isInField(lastPos, true); + if (text.length() == 1 && !text.equals("[") && !text.equals("]")) { // setCursorOff2(); setCursorActive(false); @@ -987,33 +976,31 @@ setCursorActive(true); // setCursorOn2(); // System.out.println(" text one"); - - } else { - + } + else { strokenizer.setKeyStrokes(text); String s; boolean done = false; - // setCursorOff2(); setCursorActive(false); + while (!done) { // while (strokenizer.hasMoreKeyStrokes() && !keyboardLocked // && // !isStatusErrorCode() && !done) { if (strokenizer.hasMoreKeyStrokes()) { - // check to see if position is in a field and if it is // then change // current field to that field isInField(lastPos, true); s = strokenizer.nextKeyStroke(); + if (s.length() == 1) { // setCursorOn(); // if (!keysBuffered) { // System.out.println(" s two" + s); // setCursorOn(); // } - // try { new Thread().sleep(400);} catch // (InterruptedException ie) {} simulateKeyStroke(s.charAt(0)); @@ -1023,7 +1010,8 @@ // System.out.println(" s two" + s); // setCursorOn(); // } - } else { + } + else { simulateMnemonic(getMnemonicValue(s)); // if (!cursorActive && !keysBuffered) { // System.out.println(" m one"); @@ -1032,24 +1020,23 @@ } if (oia.isKeyBoardLocked()) { - bufferedKeys = strokenizer - .getUnprocessedKeyStroked(); + .getUnprocessedKeyStroked(); + if (bufferedKeys != null) { oia.setKeysBuffered(true); - } + done = true; } - } - else { // setCursorActive(true); // setCursorOn(); done = true; } } + setCursorActive(true); } } @@ -1099,7 +1086,6 @@ * @see #AID_PF24 */ public void sendAid(int aidKey) { - sessionVT.sendAidKey(aidKey); } @@ -1108,425 +1094,440 @@ * */ protected void resetError() { - restoreErrorLine(); setStatus(STATUS_ERROR_CODE, STATUS_VALUE_OFF, ""); - } protected boolean simulateMnemonic(int mnem) { - boolean simulated = false; switch (mnem) { - - case AID_CLEAR: - case AID_ENTER: - case AID_PF1: - case AID_PF2: - case AID_PF3: - case AID_PF4: - case AID_PF5: - case AID_PF6: - case AID_PF7: - case AID_PF8: - case AID_PF9: - case AID_PF10: - case AID_PF11: - case AID_PF12: - case AID_PF13: - case AID_PF14: - case AID_PF15: - case AID_PF16: - case AID_PF17: - case AID_PF18: - case AID_PF19: - case AID_PF20: - case AID_PF21: - case AID_PF22: - case AID_PF23: - case AID_PF24: - case AID_ROLL_DOWN: - case AID_ROLL_UP: - case AID_ROLL_LEFT: - case AID_ROLL_RIGHT: - - if (!screenFields.isCanSendAid()) { - displayError(ERR_ENTER_NO_ALLOWED); - } else - sendAid(mnem); - simulated = true; - - break; - case AID_HELP: - sessionVT.sendHelpRequest(); - simulated = true; - break; - - case AID_PRINT: - sessionVT.hostPrint(1); - simulated = true; - break; - - case BACK_SPACE: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - if (screenFields.getCurrentField().startPos() == lastPos) { - if (backspaceError) - displayError(ERR_CURSOR_PROTECTED); + case AID_CLEAR: + case AID_ENTER: + case AID_PF1: + case AID_PF2: + case AID_PF3: + case AID_PF4: + case AID_PF5: + case AID_PF6: + case AID_PF7: + case AID_PF8: + case AID_PF9: + case AID_PF10: + case AID_PF11: + case AID_PF12: + case AID_PF13: + case AID_PF14: + case AID_PF15: + case AID_PF16: + case AID_PF17: + case AID_PF18: + case AID_PF19: + case AID_PF20: + case AID_PF21: + case AID_PF22: + case AID_PF23: + case AID_PF24: + case AID_ROLL_DOWN: + case AID_ROLL_UP: + case AID_ROLL_LEFT: + case AID_ROLL_RIGHT: + if (!screenFields.isCanSendAid()) { + displayError(ERR_ENTER_NO_ALLOWED); + } + else + sendAid(mnem); + + simulated = true; + break; + + case AID_HELP: + sessionVT.sendHelpRequest(); + simulated = true; + break; + + case AID_PRINT: + sessionVT.hostPrint(1); + simulated = true; + break; + + case BACK_SPACE: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + if (screenFields.getCurrentField().startPos() == lastPos) { + if (backspaceError) + displayError(ERR_CURSOR_PROTECTED); + else { + gotoFieldPrev(); + goto_XY(screenFields.getCurrentField().endPos()); + updateDirty(); + } + } else { - gotoFieldPrev(); - goto_XY(screenFields.getCurrentField().endPos()); + screenFields.getCurrentField().getKeyPos(lastPos); + screenFields.getCurrentField().changePos(-1); + resetDirty(screenFields.getCurrentField().getCurrentPos()); + shiftLeft(screenFields.getCurrentField().getCurrentPos()); updateDirty(); + screenFields.setCurrentFieldMDT(); + simulated = true; } } else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case BACK_TAB: + if (screenFields.getCurrentField() != null + && screenFields.isCurrentFieldHighlightedEntry()) { + resetDirty(screenFields.getCurrentField().startPos); + gotoFieldPrev(); + updateDirty(); + } + else + gotoFieldPrev(); + + if (screenFields.isCurrentFieldContinued()) { + do { + gotoFieldPrev(); + } + while (screenFields.isCurrentFieldContinuedMiddle() + || screenFields.isCurrentFieldContinuedLast()); + } + + isInField(lastPos); + simulated = true; + break; + + case UP: + case MARK_UP: + process_XY(lastPos - numCols); + simulated = true; + break; + + case DOWN: + case MARK_DOWN: + process_XY(lastPos + numCols); + simulated = true; + break; + + case LEFT: + case MARK_LEFT: + process_XY(lastPos - 1); + simulated = true; + break; + + case RIGHT: + case MARK_RIGHT: + process_XY(lastPos + 1); + simulated = true; + break; + + case NEXTWORD: + gotoNextWord(); + simulated = true; + break; + + case PREVWORD: + gotoPrevWord(); + simulated = true; + break; + + case DELETE: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + resetDirty(lastPos); screenFields.getCurrentField().getKeyPos(lastPos); - screenFields.getCurrentField().changePos(-1); - resetDirty(screenFields.getCurrentField().getCurrentPos()); - shiftLeft(screenFields.getCurrentField().getCurrentPos()); + shiftLeft(screenFields.getCurrentFieldPos()); + screenFields.setCurrentFieldMDT(); updateDirty(); - screenFields.setCurrentFieldMDT(); + simulated = true; + } + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case TAB: + if (screenFields.getCurrentField() != null + && !screenFields.isCurrentFieldContinued()) { + if (screenFields.isCurrentFieldHighlightedEntry()) { + resetDirty(screenFields.getCurrentField().startPos); + gotoFieldNext(); + updateDirty(); + } + else + gotoFieldNext(); + } + else { + do { + gotoFieldNext(); + } + while (screenFields.getCurrentField() != null + && (screenFields.isCurrentFieldContinuedMiddle() || screenFields + .isCurrentFieldContinuedLast())); + } + + isInField(lastPos); + simulated = true; + break; + + case EOF: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + int where = endOfField(screenFields.getCurrentField() + .startPos(), true); + + if (where > 0) { + setCursor((where / numCols) + 1, (where % numCols) + 1); + } simulated = true; } - } else { - displayError(ERR_CURSOR_PROTECTED); - - } - break; - case BACK_TAB: - - if (screenFields.getCurrentField() != null - && screenFields.isCurrentFieldHighlightedEntry()) { - resetDirty(screenFields.getCurrentField().startPos); - gotoFieldPrev(); - updateDirty(); - } else - gotoFieldPrev(); - - if (screenFields.isCurrentFieldContinued()) { - do { - gotoFieldPrev(); - } while (screenFields.isCurrentFieldContinuedMiddle() - || screenFields.isCurrentFieldContinuedLast()); - } - isInField(lastPos); - simulated = true; - break; - case UP: - case MARK_UP: - process_XY(lastPos - numCols); - simulated = true; - break; - case DOWN: - case MARK_DOWN: - process_XY(lastPos + numCols); - simulated = true; - break; - case LEFT: - case MARK_LEFT: - process_XY(lastPos - 1); - simulated = true; - break; - case RIGHT: - case MARK_RIGHT: - process_XY(lastPos + 1); - simulated = true; - break; - case NEXTWORD: - gotoNextWord(); - simulated = true; - break; - case PREVWORD: - gotoPrevWord(); - simulated = true; - break; - case DELETE: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { + else { + displayError(ERR_CURSOR_PROTECTED); + } resetDirty(lastPos); - screenFields.getCurrentField().getKeyPos(lastPos); - shiftLeft(screenFields.getCurrentFieldPos()); - screenFields.setCurrentFieldMDT(); - updateDirty(); - simulated = true; - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case TAB: - - if (screenFields.getCurrentField() != null - && !screenFields.isCurrentFieldContinued()) { - if (screenFields.isCurrentFieldHighlightedEntry()) { - resetDirty(screenFields.getCurrentField().startPos); - gotoFieldNext(); + break; + + case ERASE_EOF: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + int where = lastPos; + resetDirty(lastPos); + + if (fieldExit()) { + screenFields.setCurrentFieldMDT(); + + if (!screenFields.isCurrentFieldContinued()) { + gotoFieldNext(); + } + else { + do { + gotoFieldNext(); + + if (screenFields.isCurrentFieldContinued()) + fieldExit(); + } + while (screenFields.isCurrentFieldContinuedMiddle() + || screenFields.isCurrentFieldContinuedLast()); + } + } + updateDirty(); - } else - gotoFieldNext(); - } else { - do { - gotoFieldNext(); - } while (screenFields.getCurrentField() != null - && (screenFields.isCurrentFieldContinuedMiddle() || screenFields - .isCurrentFieldContinuedLast())); - } - - isInField(lastPos); - simulated = true; - - break; - case EOF: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - int where = endOfField(screenFields.getCurrentField() - .startPos(), true); - if (where > 0) { - setCursor((where / numCols) + 1, (where % numCols) + 1); + goto_XY(where); + simulated = true; + } + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case ERASE_FIELD: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + int where = lastPos; + lastPos = screenFields.getCurrentField().startPos(); + resetDirty(lastPos); + + if (fieldExit()) { + screenFields.setCurrentFieldMDT(); + + if (!screenFields.isCurrentFieldContinued()) { + gotoFieldNext(); + } + else { + do { + gotoFieldNext(); + + if (screenFields.isCurrentFieldContinued()) + fieldExit(); + } + while (screenFields.isCurrentFieldContinuedMiddle() + || screenFields.isCurrentFieldContinuedLast()); + } + } + + updateDirty(); + goto_XY(where); + simulated = true; + } + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case INSERT: + // we toggle it + oia.setInsertMode(oia.isInsertMode() ? false : true); + break; + + case HOME: + + // position to the home position set + if (lastPos + numCols + 1 != homePos) { + goto_XY(homePos - numCols - 1); + // now check if we are in a field + isInField(lastPos); } - simulated = true; - } else { - displayError(ERR_CURSOR_PROTECTED); - } - resetDirty(lastPos); - - break; - case ERASE_EOF: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - int where = lastPos; - resetDirty(lastPos); - if (fieldExit()) { - screenFields.setCurrentFieldMDT(); - if (!screenFields.isCurrentFieldContinued()) { - gotoFieldNext(); - } else { - do { - gotoFieldNext(); - if (screenFields.isCurrentFieldContinued()) - fieldExit(); - } while (screenFields.isCurrentFieldContinuedMiddle() - || screenFields.isCurrentFieldContinuedLast()); + else + gotoField(1); + + break; + + case KEYPAD_0: + simulated = simulateKeyStroke('0'); + break; + + case KEYPAD_1: + simulated = simulateKeyStroke('1'); + break; + + case KEYPAD_2: + simulated = simulateKeyStroke('2'); + break; + + case KEYPAD_3: + simulated = simulateKeyStroke('3'); + break; + + case KEYPAD_4: + simulated = simulateKeyStroke('4'); + break; + + case KEYPAD_5: + simulated = simulateKeyStroke('5'); + break; + + case KEYPAD_6: + simulated = simulateKeyStroke('6'); + break; + + case KEYPAD_7: + simulated = simulateKeyStroke('7'); + break; + + case KEYPAD_8: + simulated = simulateKeyStroke('8'); + break; + + case KEYPAD_9: + simulated = simulateKeyStroke('9'); + break; + + case KEYPAD_PERIOD: + simulated = simulateKeyStroke('.'); + break; + + case KEYPAD_COMMA: + simulated = simulateKeyStroke(','); + break; + + case KEYPAD_MINUS: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + int s = screenFields.getCurrentField().getFieldShift(); + + if (s == 3 || s == 5 || s == 7) { + planes.setChar(lastPos, '-'); + resetDirty(lastPos); + advancePos(); + + if (fieldExit()) { + screenFields.setCurrentFieldMDT(); + + if (!screenFields.isCurrentFieldContinued()) { + gotoFieldNext(); + } + else { + do { + gotoFieldNext(); + } + while (screenFields + .isCurrentFieldContinuedMiddle() + || screenFields + .isCurrentFieldContinuedLast()); + } + + simulated = true; + updateDirty(); + + if (screenFields.isCurrentFieldAutoEnter()) + sendAid(AID_ENTER); + } } - } - updateDirty(); - goto_XY(where); - simulated = true; - - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case ERASE_FIELD: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - int where = lastPos; - lastPos = screenFields.getCurrentField().startPos(); - resetDirty(lastPos); - if (fieldExit()) { - screenFields.setCurrentFieldMDT(); - if (!screenFields.isCurrentFieldContinued()) { - gotoFieldNext(); - } else { - do { - gotoFieldNext(); - if (screenFields.isCurrentFieldContinued()) - fieldExit(); - } while (screenFields.isCurrentFieldContinuedMiddle() - || screenFields.isCurrentFieldContinuedLast()); + else { + displayError(ERR_FIELD_MINUS); } } - updateDirty(); - goto_XY(where); - simulated = true; - - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case INSERT: - // we toggle it - oia.setInsertMode(oia.isInsertMode() ? false : true); - break; - case HOME: - // position to the home position set - if (lastPos + numCols + 1 != homePos) { - goto_XY(homePos - numCols - 1); - // now check if we are in a field - isInField(lastPos); - } else - gotoField(1); - break; - case KEYPAD_0: - simulated = simulateKeyStroke('0'); - break; - case KEYPAD_1: - simulated = simulateKeyStroke('1'); - break; - case KEYPAD_2: - simulated = simulateKeyStroke('2'); - break; - case KEYPAD_3: - simulated = simulateKeyStroke('3'); - break; - case KEYPAD_4: - simulated = simulateKeyStroke('4'); - break; - case KEYPAD_5: - simulated = simulateKeyStroke('5'); - break; - case KEYPAD_6: - simulated = simulateKeyStroke('6'); - break; - case KEYPAD_7: - simulated = simulateKeyStroke('7'); - break; - case KEYPAD_8: - simulated = simulateKeyStroke('8'); - break; - case KEYPAD_9: - simulated = simulateKeyStroke('9'); - break; - case KEYPAD_PERIOD: - simulated = simulateKeyStroke('.'); - break; - case KEYPAD_COMMA: - simulated = simulateKeyStroke(','); - break; - case KEYPAD_MINUS: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - int s = screenFields.getCurrentField().getFieldShift(); - if (s == 3 || s == 5 || s == 7) { - planes.setChar(lastPos,'-'); - + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case FIELD_EXIT: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { resetDirty(lastPos); - advancePos(); - if (fieldExit()) { - screenFields.setCurrentFieldMDT(); - if (!screenFields.isCurrentFieldContinued()) { - gotoFieldNext(); - } else { - do { - gotoFieldNext(); - } while (screenFields - .isCurrentFieldContinuedMiddle() - || screenFields - .isCurrentFieldContinuedLast()); - } - simulated = true; - updateDirty(); - if (screenFields.isCurrentFieldAutoEnter()) - sendAid(AID_ENTER); - - } - } else { - displayError(ERR_FIELD_MINUS); - - } - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case FIELD_EXIT: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - resetDirty(lastPos); - - boolean autoFE = screenFields.isCurrentFieldAutoEnter(); - - if (fieldExit()) { - screenFields.setCurrentFieldMDT(); - if (!screenFields.isCurrentFieldContinued() && - !screenFields.isCurrentFieldAutoEnter()) { - gotoFieldNext(); - } else { - do { - gotoFieldNext(); - if (screenFields.isCurrentFieldContinued()) - fieldExit(); - } while (screenFields.isCurrentFieldContinuedMiddle() - || screenFields.isCurrentFieldContinuedLast()); - } - } - - updateDirty(); - simulated = true; - if (autoFE) - sendAid(AID_ENTER); - - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case FIELD_PLUS: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - resetDirty(lastPos); - - boolean autoFE = screenFields.isCurrentFieldAutoEnter(); - if (fieldExit()) { - screenFields.setCurrentFieldMDT(); - if (!screenFields.isCurrentFieldContinued() && - !screenFields.isCurrentFieldAutoEnter()) { - gotoFieldNext(); - } else { - do { - gotoFieldNext(); - } while (screenFields.isCurrentFieldContinuedMiddle() - || screenFields.isCurrentFieldContinuedLast()); - } - } - updateDirty(); - simulated = true; - - if (autoFE) - sendAid(AID_ENTER); - - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case FIELD_MINUS: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - int s = screenFields.getCurrentField().getFieldShift(); - if (s == 3 || s == 5 || s == 7) { - planes.setChar(lastPos, '-'); - - resetDirty(lastPos); - advancePos(); - boolean autoFE = screenFields.isCurrentFieldAutoEnter(); if (fieldExit()) { screenFields.setCurrentFieldMDT(); - if (!screenFields.isCurrentFieldContinued() - && !screenFields.isCurrentFieldAutoEnter()) { + + if (!screenFields.isCurrentFieldContinued() && + !screenFields.isCurrentFieldAutoEnter()) { + gotoFieldNext(); + } + else { + do { + gotoFieldNext(); + + if (screenFields.isCurrentFieldContinued()) + fieldExit(); + } + while (screenFields.isCurrentFieldContinuedMiddle() + || screenFields.isCurrentFieldContinuedLast()); + } + } + + updateDirty(); + simulated = true; + + if (autoFE) + sendAid(AID_ENTER); + } + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case FIELD_PLUS: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + resetDirty(lastPos); + boolean autoFE = screenFields.isCurrentFieldAutoEnter(); + + if (fieldExit()) { + screenFields.setCurrentFieldMDT(); + + if (!screenFields.isCurrentFieldContinued() && + !screenFields.isCurrentFieldAutoEnter()) { gotoFieldNext(); } else { @@ -1537,159 +1538,223 @@ || screenFields.isCurrentFieldContinuedLast()); } } + updateDirty(); simulated = true; + if (autoFE) sendAid(AID_ENTER); - + } + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case FIELD_MINUS: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + int s = screenFields.getCurrentField().getFieldShift(); + + if (s == 3 || s == 5 || s == 7) { + planes.setChar(lastPos, '-'); + resetDirty(lastPos); + advancePos(); + boolean autoFE = screenFields.isCurrentFieldAutoEnter(); + + if (fieldExit()) { + screenFields.setCurrentFieldMDT(); + + if (!screenFields.isCurrentFieldContinued() + && !screenFields.isCurrentFieldAutoEnter()) { + gotoFieldNext(); + } + else { + do { + gotoFieldNext(); + } + while (screenFields.isCurrentFieldContinuedMiddle() + || screenFields.isCurrentFieldContinuedLast()); + } + } + + updateDirty(); + simulated = true; + + if (autoFE) + sendAid(AID_ENTER); + } + else { + displayError(ERR_FIELD_MINUS); + } + } + else { + displayError(ERR_CURSOR_PROTECTED); + } + + break; + + case BOF: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + int where = screenFields.getCurrentField().startPos(); + + if (where > 0) { + goto_XY(where); + } + + simulated = true; } else { - displayError(ERR_FIELD_MINUS); - + displayError(ERR_CURSOR_PROTECTED); } - } - else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case BOF: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - int where = screenFields.getCurrentField().startPos(); - if (where > 0) { - goto_XY(where); + + resetDirty(lastPos); + break; + + case SYSREQ: + sessionVT.systemRequest(); + simulated = true; + break; + + case RESET: + if (isStatusErrorCode()) { + resetError(); + isInField(lastPos); + updateDirty(); } + else { + setPrehelpState(false, oia.isKeyBoardLocked(), false); + } + + simulated = true; + break; + + case ATTN: + sessionVT.sendAttentionKey(); simulated = true; - } else { - displayError(ERR_CURSOR_PROTECTED); - } - resetDirty(lastPos); - - break; - case SYSREQ: - sessionVT.systemRequest(); - simulated = true; - break; - case RESET: - if (isStatusErrorCode()) { - resetError(); - isInField(lastPos); - updateDirty(); - } else { - setPrehelpState(false, oia.isKeyBoardLocked(), false); - } - simulated = true; - break; - case ATTN: - sessionVT.sendAttentionKey(); - simulated = true; - break; - case DUP_FIELD: - if (screenFields.getCurrentField() != null - && screenFields.withinCurrentField(lastPos) - && !screenFields.isCurrentFieldBypassField()) { - - if (screenFields.isCurrentFieldDupEnabled()) { - resetDirty(lastPos); - screenFields.getCurrentField().setFieldChar(lastPos, - (char) 0x1C); - screenFields.setCurrentFieldMDT(); - gotoFieldNext(); - updateDirty(); - simulated = true; - } else { - displayError(ERR_DUP_KEY_NOT_ALLOWED); + break; + + case DUP_FIELD: + if (screenFields.getCurrentField() != null + && screenFields.withinCurrentField(lastPos) + && !screenFields.isCurrentFieldBypassField()) { + if (screenFields.isCurrentFieldDupEnabled()) { + resetDirty(lastPos); + screenFields.getCurrentField().setFieldChar(lastPos, + (char) 0x1C); + screenFields.setCurrentFieldMDT(); + gotoFieldNext(); + updateDirty(); + simulated = true; + } + else { + displayError(ERR_DUP_KEY_NOT_ALLOWED); + } + } + else { + displayError(ERR_CURSOR_PROTECTED); } - } else { - displayError(ERR_CURSOR_PROTECTED); - } - - break; - case NEW_LINE: - if (screenFields.getSize() > 0) { - int startRow = getRow(lastPos) + 1; - int startPos = lastPos; - - if (startRow == getRows()) - startRow = 0; - - setCursor(++startRow, 1); - - if (!isInField() && screenFields.getCurrentField() != null - && !screenFields.isCurrentFieldBypassField()) { - while (!isInField() - && screenFields.getCurrentField() != null + + break; + + case NEW_LINE: + if (screenFields.getSize() > 0) { + int startRow = getRow(lastPos) + 1; + int startPos = lastPos; + + if (startRow == getRows()) + startRow = 0; + + setCursor(++startRow, 1); + + if (!isInField() && screenFields.getCurrentField() != null && !screenFields.isCurrentFieldBypassField()) { - - // lets keep going - advancePos(); - - // Have we looped the screen? - if (lastPos == startPos) { - // if so then go back to starting point - goto_XY(startPos); - break; + while (!isInField() + && screenFields.getCurrentField() != null + && !screenFields.isCurrentFieldBypassField()) { + // lets keep going + advancePos(); + + // Have we looped the screen? + if (lastPos == startPos) { + // if so then go back to starting point + goto_XY(startPos); + break; + } } } } - } - simulated = true; - break; - case FAST_CURSOR_DOWN: - int rowNow = (getCurrentRow()-1) + 3; - if (rowNow > getRows()-1) - rowNow = rowNow - getRows(); - this.goto_XY(getPos(rowNow,getCurrentCol()-1)); - simulated = true; - break; - case FAST_CURSOR_UP: - rowNow = (getCurrentRow()-1) - 3; - if (rowNow < 0) - rowNow = (getRows()) + rowNow; - this.goto_XY(getPos(rowNow,getCurrentCol()-1)); - simulated = true; - break; - case FAST_CURSOR_LEFT: - int colNow = (getCurrentCol()-1) - 3; - rowNow = getCurrentRow()-1; - if (colNow <= 0) { - colNow = getColumns() + colNow; - rowNow--; - } - if (rowNow < 0) - rowNow = getRows() - 1; - - process_XY(getPos(rowNow,colNow)); - simulated = true; - break; - case FAST_CURSOR_RIGHT: - colNow = (getCurrentCol()-1) + 3; - rowNow = getCurrentRow()-1; - if (colNow >= getColumns()) { - colNow = colNow - getColumns(); - rowNow++; - } - if (rowNow > getRows() - 1) - rowNow = getRows() - rowNow; - - process_XY(getPos(rowNow,colNow)); - simulated = true; - break; - default: - Log.i(TAG," Mnemonic not supported " + mnem); - break; - + + simulated = true; + break; + + case FAST_CURSOR_DOWN: + int rowNow = (getCurrentRow() - 1) + 3; + + if (rowNow > getRows() - 1) + rowNow = rowNow - getRows(); + + this.goto_XY(getPos(rowNow, getCurrentCol() - 1)); + simulated = true; + break; + + case FAST_CURSOR_UP: + rowNow = (getCurrentRow() - 1) - 3; + + if (rowNow < 0) + rowNow = (getRows()) + rowNow; + + this.goto_XY(getPos(rowNow, getCurrentCol() - 1)); + simulated = true; + break; + + case FAST_CURSOR_LEFT: + int colNow = (getCurrentCol() - 1) - 3; + rowNow = getCurrentRow() - 1; + + if (colNow <= 0) { + colNow = getColumns() + colNow; + rowNow--; + } + + if (rowNow < 0) + rowNow = getRows() - 1; + + process_XY(getPos(rowNow, colNow)); + simulated = true; + break; + + case FAST_CURSOR_RIGHT: + colNow = (getCurrentCol() - 1) + 3; + rowNow = getCurrentRow() - 1; + + if (colNow >= getColumns()) { + colNow = colNow - getColumns(); + rowNow++; + } + + if (rowNow > getRows() - 1) + rowNow = getRows() - rowNow; + + process_XY(getPos(rowNow, colNow)); + simulated = true; + break; + + default: + Log.i(TAG, " Mnemonic not supported " + mnem); + break; } return simulated; } protected boolean simulateKeyStroke(char c) { - if (isStatusErrorCode() && !Character.isISOControl(c) && !keyProcessed) { if (resetRequired) return false; + resetError(); } @@ -1699,57 +1764,62 @@ boolean autoEnter = false; if (!Character.isISOControl(c)) { - if (screenFields.getCurrentField() != null && screenFields.withinCurrentField(lastPos) && !screenFields.isCurrentFieldBypassField()) { - if (screenFields.isCurrentFieldFER() && !screenFields.withinCurrentField(screenFields .getCurrentFieldPos()) - && lastPos == screenFields.getCurrentField().endPos() - && screenFields.getCurrentFieldPos() > screenFields - .getCurrentField().endPos()) { - + && lastPos == screenFields.getCurrentField().endPos() + && screenFields.getCurrentFieldPos() > screenFields + .getCurrentField().endPos()) { displayError(ERR_FIELD_EXIT_INVALID); feError = true; return false; } switch (screenFields.getCurrentFieldShift()) { - case 0: // Alpha shift - case 2: // Numeric Shift - case 4: // Kakana Shift - updateField = true; - break; - case 1: // Alpha Only - if (Character.isLetter(c) || c == ',' || c == '-' - || c == '.' || c == ' ') - updateField = true; - break; - case 3: // Numeric only - if (Character.isDigit(c) || c == '+' || c == ',' - || c == '-' || c == '.' || c == ' ') + case 0: // Alpha shift + case 2: // Numeric Shift + case 4: // Kakana Shift updateField = true; - else - numericError = true; - break; - case 5: // Digits only - if (Character.isDigit(c)) - updateField = true; - else - displayError(ERR_NUMERIC_09); - break; - case 7: // Signed numeric - if (Character.isDigit(c) || c == '+' || c == '-') - if (lastPos == screenFields.getCurrentField().endPos() - && (c != '+' && c != '-')) - displayError(ERR_INVALID_SIGN); + break; + + case 1: // Alpha Only + if (Character.isLetter(c) || c == ',' || c == '-' + || c == '.' || c == ' ') + updateField = true; + + break; + + case 3: // Numeric only + if (Character.isDigit(c) || c == '+' || c == ',' + || c == '-' || c == '.' || c == ' ') + updateField = true; else + numericError = true; + + break; + + case 5: // Digits only + if (Character.isDigit(c)) updateField = true; - else - displayError(ERR_NUMERIC_09); - break; + else + displayError(ERR_NUMERIC_09); + + break; + + case 7: // Signed numeric + if (Character.isDigit(c) || c == '+' || c == '-') + if (lastPos == screenFields.getCurrentField().endPos() + && (c != '+' && c != '-')) + displayError(ERR_INVALID_SIGN); + else + updateField = true; + else + displayError(ERR_NUMERIC_09); + + break; } if (updateField) { @@ -1764,29 +1834,26 @@ .endPos()) shiftRight(lastPos); else { - displayError(ERR_NO_ROOM_INSERT); updatePos = false; } - } if (updatePos) { screenFields.getCurrentField().getKeyPos( - getRow(lastPos), getCol(lastPos)); + getRow(lastPos), getCol(lastPos)); screenFields.getCurrentField().changePos(1); - - planes.setChar(lastPos,c); - + planes.setChar(lastPos, c); screenFields.setCurrentFieldMDT(); // if we have gone passed the end of the field then goto // the next field if (!screenFields.withinCurrentField(screenFields - .getCurrentFieldPos())) { + .getCurrentFieldPos())) { if (screenFields.isCurrentFieldAutoEnter()) { autoEnter = true; - } else if (!screenFields.isCurrentFieldFER()) + } + else if (!screenFields.isCurrentFieldFER()) gotoFieldNext(); else { // screenFields.getCurrentField().changePos(1); @@ -1799,28 +1866,29 @@ // if (feError) // displayError(ERR_FIELD_EXIT_INVALID); } - - } else + } + else setCursor(screenFields.getCurrentField() - .getCursorRow() + 1, screenFields - .getCurrentField().getCursorCol() + 1); - + .getCursorRow() + 1, screenFields + .getCurrentField().getCursorCol() + 1); } fireScreenChanged(); if (autoEnter) sendAid(AID_ENTER); - } else { + } + else { if (numericError) { displayError(ERR_NUMERIC_ONLY); } } - } else { + } + else { displayError(ERR_CURSOR_PROTECTED); } - } + return updatePos; } @@ -1859,7 +1927,6 @@ * */ private int endOfField(int pos, boolean posSpace) { - int endPos = screenFields.getCurrentField().endPos(); int fePos = endPos; // get the number of characters to the right @@ -1867,28 +1934,25 @@ // first lets get the real ending point without spaces and the such while (planes.getChar(endPos) <= ' ' && count-- > 0) { - endPos--; } if (endPos == fePos) { - return endPos; - } + screenFields.getCurrentField().getKeyPos(endPos); + if (posSpace) screenFields.getCurrentField().changePos(+1); + return screenFields.getCurrentFieldPos(); - } private boolean fieldExit() { - int pos = lastPos; boolean mdt = false; int end = endOfField(false); // get the ending position of the first // non blank character in field - ScreenField sf = screenFields.getCurrentField(); if (sf.isMandatoryEnter() && end == sf.startPos()) { @@ -1902,7 +1966,6 @@ // Maybe this should be changed to not update the current cursor position // of the field. int currentPos = sf.getCurrentPos(); - // get the number of characters to the right int count = (end - sf.startPos()) - sf.getKeyPos(pos); @@ -1926,6 +1989,7 @@ // place the count as -1. if (count == -1) { int s = sf.getFieldShift(); + if (s == 3 || s == 5 || s == 7) { mdt = true; } @@ -1934,26 +1998,23 @@ int adj = sf.getAdjustment(); if (adj != 0) { - switch (adj) { - - case 5: - rightAdjustField('0'); - sf.setRightAdjusted(); - break; - case 6: - rightAdjustField(' '); - sf.setRightAdjusted(); - - break; - case 7: - sf.setManditoryEntered(); - break; - + case 5: + rightAdjustField('0'); + sf.setRightAdjusted(); + break; + + case 6: + rightAdjustField(' '); + sf.setRightAdjusted(); + break; + + case 7: + sf.setManditoryEntered(); + break; } } else { - // we need to right adjust signed numeric fields as well. if (sf.isSignedNumeric()) { rightAdjustField(' '); @@ -1964,132 +2025,115 @@ } private void rightAdjustField(char fill) { - int end = endOfField(false); // get the ending position of the first // non blank character in field - // get the number of characters to the right int count = screenFields.getCurrentField().endPos() - end; // subtract 1 from count for signed numeric - note for later if (screenFields.getCurrentField().isSignedNumeric()) { - if (planes.getChar(end -1) != '-') + if (planes.getChar(end - 1) != '-') count--; } int pos = screenFields.getCurrentField().startPos(); while (count-- >= 0) { - shiftRight(pos); - planes.setChar(pos,fill); - + planes.setChar(pos, fill); setDirty(pos); - } - } private void shiftLeft(int sPos) { - int endPos = 0; - int pos = sPos; int pPos = sPos; - ScreenField sf = screenFields.getCurrentField(); int end; int count; + do { end = endOfField(pPos, false); // get the ending position of the // first // non blank character in field - count = (end - screenFields.getCurrentField().startPos()) - - screenFields.getCurrentField().getKeyPos(pPos); + - screenFields.getCurrentField().getKeyPos(pPos); // now we loop through and shift the remaining characters to the // left while (count-- > 0) { pos++; - planes.setChar(pPos,planes.getChar(pos)); + planes.setChar(pPos, planes.getChar(pos)); setDirty(pPos); pPos = pos; - } if (screenFields.isCurrentFieldContinued()) { gotoFieldNext(); + if (screenFields.getCurrentField().isContinuedFirst()) break; pos = screenFields.getCurrentField().startPos(); - planes.setChar(pPos,planes.getChar(pos)); + planes.setChar(pPos, planes.getChar(pos)); setDirty(pPos); - pPos = pos; - } - } while (screenFields.isCurrentFieldContinued() + } + while (screenFields.isCurrentFieldContinued() && !screenFields.getCurrentField().isContinuedFirst()); if (end >= 0 && count >= -1) { - endPos = end; - } else { + } + else { endPos = sPos; - } screenFields.setCurrentField(sf); - planes.setChar(endPos,initChar); + planes.setChar(endPos, initChar); setDirty(endPos); goto_XY(screenFields.getCurrentFieldPos()); sf = null; - } private void shiftRight(int sPos) { - int end = endOfField(true); // get the ending position of the first // non blank character in field int pos = end; int pPos = end; - int count = end - sPos; // now we loop through and shift the remaining characters to the right while (count-- > 0) { - pos--; planes.setChar(pPos, planes.getChar(pos)); setDirty(pPos); - pPos = pos; } } public int getRow(int pos) { - // if (pos == 0) // return 1; - int row = pos / numCols; if (row < 0) { - row = lastPos / numCols; } + if (row > (lenScreen / numCols) - 1) row = (lenScreen / numCols) - 1; return row; - } public int getCol(int pos) { int col = pos % (getColumns()); + if (col > 0) return col; + return 0; } @@ -2101,7 +2145,6 @@ * @return */ public int getPos(int row, int col) { - return (row * numCols) + col; } @@ -2112,10 +2155,8 @@ * @return int */ public int getCurrentPos() { - // return lastPos + numCols + 1; return lastPos + 1; - } /** @@ -2185,13 +2226,12 @@ homePos = lastPos + numCols + 1; pendingInsert = true; sessionVT.sendNegResponse2(ec); - } private void process_XY(int pos) { - if (pos < 0) pos = lenScreen + pos; + if (pos > lenScreen - 1) pos = pos - lenScreen; @@ -2213,19 +2253,21 @@ // other keys will reset the field position so that entering over the // last character will not cause an error but replace that character or // just plain move the cursor if the key was to do that. - ScreenField sf = screenFields.getCurrentField(); + if (feError) { feError = false; sf.changePos(-1); - } else { - if (sf != null&& sf.isFER()){ + } + else { + if (sf != null && sf.isFER()) { if ((sf.getCurrentPos() > sf.endPos())) { if (sf.withinField(pos)) { sf.getKeyPos(pos); return; } + sf.getKeyPos(sf.endPos()); } } @@ -2235,7 +2277,6 @@ } public boolean isUsingGuiInterface() { - return guiInterface; } @@ -2246,7 +2287,6 @@ */ protected boolean isInField() { - return isInField(lastPos, true); } @@ -2261,7 +2301,6 @@ * @return true or false */ public boolean isInField(int pos, boolean chgToField) { - return screenFields.isInField(pos, chgToField); } @@ -2275,7 +2314,6 @@ * @return true or false */ public boolean isInField(int pos) { - return screenFields.isInField(pos, true); } @@ -2289,7 +2327,6 @@ * @return true or false */ public boolean isInField(int row, int col) { - return isInField(row, col, true); } @@ -2315,7 +2352,6 @@ * @return int value of screen length */ public int getScreenLength() { - return lenScreen; } @@ -2325,9 +2361,7 @@ * @return number of rows */ public int getRows() { - return numRows; - } /** @@ -2336,9 +2370,7 @@ * @return number of columns */ public int getColumns() { - return numCols; - } /** @@ -2347,9 +2379,7 @@ * @return the cursor current row position 1,1 based */ public int getCurrentRow() { - return (lastPos / numCols) + 1; - } /** @@ -2358,9 +2388,7 @@ * @return the cursor current column position 1,1 based */ public int getCurrentCol() { - return (lastPos % numCols) + 1; - } /** @@ -2370,9 +2398,7 @@ * @return last position */ protected int getLastPos() { - return lastPos; - } /** @@ -2405,13 +2431,15 @@ for (int x = 0; x < lenScreen; x++) { c = planes.getChar(x); + // only draw printable characters (in this case >= ' ') if ((c >= ' ') && (!planes.isAttributePlace(x))) { sac[x] = c; // TODO: implement the underline check here // if (screen[x].underLine && c <= ' ') // sac[x] = '_'; - } else + } + else sac[x] = ' '; } @@ -2420,20 +2448,20 @@ public char[] getData(int startRow, int startCol, int endRow, int endCol, int plane) { try { - int from = getPos(startRow,startCol); - int to = getPos(endRow,endCol); + int from = getPos(startRow, startCol); + int to = getPos(endRow, endCol); + if (from > to) { - int f = from; to = f; from = f; } - return planes.getPlaneData(from,to,plane); + + return planes.getPlaneData(from, to, plane); } catch (Exception oe) { return null; } - } /** @@ -2458,11 +2486,11 @@ * @return The number of characters copied to the buffer * @throws OhioException */ + public synchronized int GetScreen(char buffer[], int bufferLength, int plane) // throws OhioException { { - return GetScreen(buffer,bufferLength,0,lenScreen,plane); - + return GetScreen(buffer, bufferLength, 0, lenScreen, plane); } /** @@ -2489,12 +2517,12 @@ * @return The number of characters copied to the buffer * @throws OhioException */ + public synchronized int GetScreen(char buffer[], int bufferLength, int from, - int length, int plane) + int length, int plane) // throws OhioException { { - - return planes.GetScreen(buffer,bufferLength, from, length, plane); + return planes.GetScreen(buffer, bufferLength, from, length, plane); } /** @@ -2523,13 +2551,14 @@ * @return The number of characters copied to the buffer. * @throws OhioException */ + public synchronized int GetScreen(char buffer[], int bufferLength, int row, - int col, int length, int plane) + int col, int length, int plane) // throws OhioException { { // Call GetScreen function after converting row and column to // a position. - return planes.GetScreen(buffer,bufferLength, row, col, length, plane); + return planes.GetScreen(buffer, bufferLength, row, col, length, plane); } /** @@ -2562,12 +2591,12 @@ * @return The number of characters copied to the buffer * @throws OhioException */ + public synchronized int GetScreenRect(char buffer[], int bufferLength, - int startPos, int endPos, int plane) + int startPos, int endPos, int plane) // throws OhioException { { return planes.GetScreenRect(buffer, bufferLength, startPos, endPos, plane); - } /** @@ -2602,14 +2631,14 @@ * @return The number characters copied to the buffer * @throws OhioException */ + public synchronized int GetScreenRect(char buffer[], int bufferLength, - int startRow, int startCol, - int endRow, int endCol, int plane) + int startRow, int startCol, + int endRow, int endCol, int plane) // throws OhioException { { - return planes.GetScreenRect(buffer, bufferLength, startRow, startCol, endRow, - endCol, plane); + endCol, plane); } public synchronized boolean[] getActiveAidKeys() { @@ -2618,7 +2647,6 @@ protected synchronized void setScreenData(String text, int location) { // throws OhioException { - if (location < 0 || location > lenScreen) { return; // throw new OhioException(sessionVT.getSessionConfiguration(), @@ -2626,13 +2654,13 @@ } int pos = location; - int l = text.length(); boolean updated = false; boolean flag = false; - int x =0; + int x = 0; + for (; x < l; x++) { - if (isInField(pos + x,true)) { + if (isInField(pos + x, true)) { if (!screenFields.getCurrentField().isBypassField()) { if (!flag) { screenFields.getCurrentField().setMDT(); @@ -2646,13 +2674,13 @@ setDirty(pos + x); } } - } + lastPos = pos + x; + if (updated) { fireScreenChanged(); } - } /** @@ -2682,10 +2710,12 @@ */ public void setField(int l, int c, char [] data) { ScreenField cf; + if (l >= 0) { int position = l * numCols + c; isInField(position, true); } + if ((data != null) && (data.length > 0)) { cf = screenFields.getCurrentField(); cf.setString(new String(data)); @@ -2693,6 +2723,7 @@ setDirty(lastPos); setDirty(lastPos + cf.getLength()); } + updateDirty(); } @@ -2704,7 +2735,6 @@ * @return true or false whether it was sucessful */ public boolean gotoField(int f) { - int sizeFields = screenFields.getSize(); if (f > sizeFields || f <= 0) @@ -2713,10 +2743,9 @@ screenFields.setCurrentField(screenFields.getField(f - 1)); while (screenFields.isCurrentFieldBypassField() && f < sizeFields) { - screenFields.setCurrentField(screenFields.getField(f++)); - } + return gotoField(screenFields.getCurrentField()); } @@ -2733,6 +2762,7 @@ goto_XY(f.startPos()); return true; } + return false; } @@ -2741,16 +2771,17 @@ * */ private void gotoNextWord() { - int pos = lastPos; if (planes.getChar(lastPos) > ' ') { advancePos(); + // get the next space character while (planes.getChar(lastPos) > ' ' && pos != lastPos) { advancePos(); } - } else + } + else advancePos(); // now that we are positioned on the next space character get the @@ -2758,7 +2789,6 @@ while (planes.getChar(lastPos) <= ' ' && pos != lastPos) { advancePos(); } - } /** @@ -2767,19 +2797,19 @@ * */ private void gotoPrevWord() { - int pos = lastPos; - changePos(-1); // position previous white space character while (planes.getChar(lastPos) <= ' ') { changePos(-1); + if (pos == lastPos) break; } changePos(-1); + // get the previous space character while (planes.getChar(lastPos) > ' ' && pos != lastPos) { changePos(-1); @@ -2787,7 +2817,6 @@ // and position one position more should give us the beginning of word advancePos(); - } /** @@ -2796,7 +2825,6 @@ * @see org.tn5250j.ScreenFields */ private void gotoFieldNext() { - if (screenFields.isCurrentFieldHighlightedEntry()) unsetFieldHighlighted(screenFields.getCurrentField()); @@ -2812,7 +2840,6 @@ * @see org.tn5250j.ScreenFields */ private void gotoFieldPrev() { - if (screenFields.isCurrentFieldHighlightedEntry()) unsetFieldHighlighted(screenFields.getCurrentField()); @@ -2820,7 +2847,6 @@ if (screenFields.isCurrentFieldHighlightedEntry()) setFieldHighlighted(screenFields.getCurrentField()); - } /* *** NEVER USED LOCALLY ************************************************** */ @@ -2860,29 +2886,27 @@ * @param lr */ protected void createWindow(int depth, int width, int type, boolean gui, - int monoAttr, int colorAttr, int ul, int upper, int ur, int left, - int right, int ll, int bottom, int lr) { - + int monoAttr, int colorAttr, int ul, int upper, int ur, int left, + int right, int ll, int bottom, int lr) { int c = getCol(lastPos); int w = 0; width++; - w = width; // set leading attribute byte // screen[lastPos].setCharAndAttr(initChar, initAttr, true); planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); setDirty(lastPos); - advancePos(); // set upper left // screen[lastPos].setCharAndAttr((char) ul, colorAttr, false); planes.setScreenCharAndAttr(lastPos, (char) ul, colorAttr, false); + if (gui) { // screen[lastPos].setUseGUI(UPPER_LEFT); planes.setUseGUI(lastPos, UPPER_LEFT); } + setDirty(lastPos); - advancePos(); // draw top row @@ -2890,120 +2914,119 @@ while (w-- >= 0) { // screen[lastPos].setCharAndAttr((char) upper, colorAttr, false); planes.setScreenCharAndAttr(lastPos, (char) upper, colorAttr, false); + if (gui) { // screen[lastPos].setUseGUI(UPPER); - planes.setUseGUI(lastPos,UPPER); + planes.setUseGUI(lastPos, UPPER); } + setDirty(lastPos); advancePos(); } // set upper right // screen[lastPos].setCharAndAttr((char) ur, colorAttr, false); - planes.setScreenCharAndAttr(lastPos,(char) ur, colorAttr, false); + planes.setScreenCharAndAttr(lastPos, (char) ur, colorAttr, false); if (gui) { // screen[lastPos].setUseGUI(UPPER_RIGHT); planes.setUseGUI(lastPos, UPPER_RIGHT); } + setDirty(lastPos); advancePos(); - // set ending attribute byte - planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); - + planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); setDirty(lastPos); - lastPos = ((getRow(lastPos) + 1) * numCols) + c; // now handle body of window while (depth-- > 0) { - // set leading attribute byte - planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); + planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); setDirty(lastPos); advancePos(); - // set left planes.setScreenCharAndAttr(lastPos, (char) left, colorAttr, false); if (gui) { - planes.setUseGUI(lastPos,GUI_LEFT); + planes.setUseGUI(lastPos, GUI_LEFT); } + setDirty(lastPos); advancePos(); - w = width; + // fill it in while (w-- >= 0) { // screen[lastPos].setCharAndAttr(initChar, initAttr, true); - planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); + planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); // screen[lastPos].setUseGUI(NO_GUI); - planes.setUseGUI(lastPos,NO_GUI); + planes.setUseGUI(lastPos, NO_GUI); setDirty(lastPos); advancePos(); } // set right // screen[lastPos].setCharAndAttr((char) right, colorAttr, false); - planes.setScreenCharAndAttr(lastPos,(char) right, colorAttr, false); + planes.setScreenCharAndAttr(lastPos, (char) right, colorAttr, false); + if (gui) { // screen[lastPos].setUseGUI(RIGHT); - planes.setUseGUI(lastPos,GUI_RIGHT); + planes.setUseGUI(lastPos, GUI_RIGHT); } setDirty(lastPos); advancePos(); - // set ending attribute byte // screen[lastPos].setCharAndAttr(initChar, initAttr, true); - planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); + planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); setDirty(lastPos); - lastPos = ((getRow(lastPos) + 1) * numCols) + c; } // set leading attribute byte // screen[lastPos].setCharAndAttr(initChar, initAttr, true); - planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); + planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); setDirty(lastPos); advancePos(); - // set lower left // screen[lastPos].setCharAndAttr((char) ll, colorAttr, false); - planes.setScreenCharAndAttr(lastPos,(char) ll, colorAttr, false); + planes.setScreenCharAndAttr(lastPos, (char) ll, colorAttr, false); + if (gui) { // screen[lastPos].setUseGUI(LOWER_LEFT); - planes.setUseGUI(lastPos,LOWER_LEFT); + planes.setUseGUI(lastPos, LOWER_LEFT); } + setDirty(lastPos); advancePos(); - w = width; // draw bottom row while (w-- >= 0) { - planes.setScreenCharAndAttr(lastPos,(char) bottom, colorAttr, false); + planes.setScreenCharAndAttr(lastPos, (char) bottom, colorAttr, false); + if (gui) { - planes.setUseGUI(lastPos,BOTTOM); + planes.setUseGUI(lastPos, BOTTOM); } + setDirty(lastPos); advancePos(); } // set lower right planes.setScreenCharAndAttr(lastPos, (char) lr, colorAttr, false); + if (gui) { - planes.setUseGUI(lastPos,LOWER_RIGHT); + planes.setUseGUI(lastPos, LOWER_RIGHT); } setDirty(lastPos); advancePos(); - // set ending attribute byte - planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); + planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); setDirty(lastPos); - } /** @@ -3019,9 +3042,8 @@ * @param sbSize */ protected void createScrollBar(int flag, int totalRowScrollable, - int totalColScrollable, int sliderRowPos, int sliderColPos, - int sbSize) { - + int totalColScrollable, int sliderRowPos, int sliderColPos, + int sbSize) { // System.out.println("Scrollbar flag: " + flag + // " scrollable Rows: " + totalRowScrollable + // " scrollable Cols: " + totalColScrollable + @@ -3030,28 +3052,27 @@ // " size: " + sbSize + // " row: " + getRow(lastPos) + // " col: " + getCol(lastPos)); - int sp = lastPos; int size = sbSize - 2; - - int thumbPos = (int) (size * ((float) sliderColPos / (float) totalColScrollable)); + int thumbPos = (int)(size * ((float) sliderColPos / (float) totalColScrollable)); // System.out.println(thumbPos); - planes.setScreenCharAndAttr(sp,' ', 32, false); - planes.setUseGUI(sp,BUTTON_SB_UP); - + planes.setScreenCharAndAttr(sp, ' ', 32, false); + planes.setUseGUI(sp, BUTTON_SB_UP); int ctr = 0; + while (ctr < size) { sp += numCols; - planes.setScreenCharAndAttr(sp,' ', 32, false); + planes.setScreenCharAndAttr(sp, ' ', 32, false); + if (ctr == thumbPos) - planes.setUseGUI(sp,BUTTON_SB_THUMB); + planes.setUseGUI(sp, BUTTON_SB_THUMB); else planes.setUseGUI(sp, BUTTON_SB_GUIDE); + ctr++; } + sp += numCols; - - planes.setScreenCharAndAttr(sp, ' ', 32, false); planes.setUseGUI(sp, BUTTON_SB_DN); } @@ -3068,27 +3089,27 @@ * @param title */ protected void writeWindowTitle(int pos, int depth, int width, - byte orientation, int monoAttr, int colorAttr, StringBuffer title) { - + byte orientation, int monoAttr, int colorAttr, StringBuffer title) { int len = title.length(); // get bit 0 and 1 for interrogation switch (orientation & 0xc0) { - case 0x40: // right - pos += (4 + width - len); - break; - case 0x80: // left - pos += 2; - break; - default: // center - // this is to place the position to the first text position of the - // window - // the position passed in is the first attribute position, the next - // is the border character and then there is another attribute after - // that. - pos += (3 + ((width / 2) - (len / 2))); - break; - + case 0x40: // right + pos += (4 + width - len); + break; + + case 0x80: // left + pos += 2; + break; + + default: // center + // this is to place the position to the first text position of the + // window + // the position passed in is the first attribute position, the next + // is the border character and then there is another attribute after + // that. + pos += (3 + ((width / 2) - (len / 2))); + break; } // if bit 2 is on then this is a footer @@ -3101,7 +3122,6 @@ for (int x = 0; x < len; x++) { planes.setChar(pos, title.charAt(x)); planes.setUseGUI(pos++, NO_GUI); - } } @@ -3119,7 +3139,6 @@ * @param bottomLine */ protected void rollScreen(int direction, int topLine, int bottomLine) { - // get the number of lines which are the last 5 bits /* int lines = direction & 0x7F; */ // get the direction of the roll which is the first bit @@ -3127,7 +3146,6 @@ // 1 - down int updown = direction & 0x80; final int lines = direction & 0x7F; - // calculate the reference points for the move. int start = this.getPos(topLine - 1, 0); int end = this.getPos(bottomLine - 1, numCols - 1); @@ -3136,53 +3154,62 @@ // System.out.println(" starting roll"); // dumpScreen(); switch (updown) { - case 0: - // Now round em up and head em UP. - for (int x = start; x < end + numCols; x++) { - if (x + lines * numCols >= lenScreen) { - //Clear at the end - planes.setChar(x, ' '); - } else { - planes.setChar(x, planes.getChar(x + lines * numCols )); + case 0: + + // Now round em up and head em UP. + for (int x = start; x < end + numCols; x++) { + if (x + lines * numCols >= lenScreen) { + //Clear at the end + planes.setChar(x, ' '); + } + else { + planes.setChar(x, planes.getChar(x + lines * numCols)); + } } - } - break; - case 1: - // Now round em up and head em DOWN. - for (int x = end + numCols; x > 0; x--) { - if ((x - lines * numCols ) < 0 ) { - //Do nothing ... tooo small!!! - } else { - planes.setChar(x - lines * numCols, planes.getChar(x)); - //and clear - planes.setChar(x, ' '); + + break; + + case 1: + + // Now round em up and head em DOWN. + for (int x = end + numCols; x > 0; x--) { + if ((x - lines * numCols) < 0) { + //Do nothing ... tooo small!!! + } + else { + planes.setChar(x - lines * numCols, planes.getChar(x)); + //and clear + planes.setChar(x, ' '); + } } - } - break; - default: - Log.w(TAG," Invalid roll parameter - please report this"); + + break; + + default: + Log.w(TAG, " Invalid roll parameter - please report this"); } + // System.out.println(" end roll"); // dumpScreen(); - } public void dumpScreen() { - StringBuffer sb = new StringBuffer(); char[] s = getScreenAsChars(); int c = getColumns(); int l = getRows() * c; int col = 0; + for (int x = 0; x < l; x++, col++) { sb.append(s[x]); + if (col == c) { sb.append('\n'); col = 0; } } - Log.i(TAG,sb.toString()); - + + Log.i(TAG, sb.toString()); } /** @@ -3196,16 +3223,11 @@ * @param fcw2 - Field control word 2 */ protected void addField(int attr, int len, int ffw1, int ffw2, int fcw1, - int fcw2) { - + int fcw2) { lastAttr = attr; - planes.setScreenCharAndAttr(lastPos, initChar, lastAttr, true); - setDirty(lastPos); - advancePos(); - ScreenField sf = null; // from 14.6.12 for Start of Field Order 5940 function manual @@ -3213,32 +3235,30 @@ // starting address plus 1. if (screenFields.existsAtPos(lastPos)) { screenFields.setCurrentFieldFFWs(ffw1, ffw2); - } else { + } + else { sf = screenFields.setField(attr, getRow(lastPos), getCol(lastPos), - len, ffw1, ffw2, fcw1, fcw2); + len, ffw1, ffw2, fcw1, fcw2); lastPos = sf.startPos(); int x = len; - boolean gui = guiInterface; + if (sf.isBypassField()) gui = false; while (x-- > 0) { - if (planes.getChar(lastPos) == 0) planes.setScreenCharAndAttr(lastPos, ' ', lastAttr, false); else - planes.setScreenAttr(lastPos,lastAttr); + planes.setScreenAttr(lastPos, lastAttr); if (gui) { - planes.setUseGUI(lastPos,FIELD_MIDDLE); + planes.setUseGUI(lastPos, FIELD_MIDDLE); } // now we set the field plane attributes - planes.setScreenFieldAttr(lastPos,ffw1); - + planes.setScreenFieldAttr(lastPos, ffw1); advancePos(); - } if (gui) @@ -3248,26 +3268,22 @@ if (lastPos > 0) planes.setUseGUI(lastPos - 1, FIELD_RIGHT); else - planes.setUseGUI(lastPos,FIELD_RIGHT); - + planes.setUseGUI(lastPos, FIELD_RIGHT); } else { - planes.setUseGUI(lastPos - 1,FIELD_ONE); + planes.setUseGUI(lastPos - 1, FIELD_ONE); } // screen[lastPos].setCharAndAttr(initChar,initAttr,true); setEndingAttr(initAttr); - lastPos = sf.startPos(); } // if (fcw1 != 0 || fcw2 != 0) { - // System.out.println("lr = " + lastRow + " lc = " + lastCol + " " + // sf.toString()); // } sf = null; - } @@ -3365,19 +3381,15 @@ * */ protected void drawFields() { - ScreenField sf; - int sizeFields = screenFields.getSize(); + for (int x = 0; x < sizeFields; x++) { - sf = screenFields.getField(x); if (!sf.isBypassField()) { int pos = sf.startPos(); - int l = sf.length; - boolean f = true; if (l >= lenScreen) @@ -3385,24 +3397,23 @@ if (l > 1) { while (l-- > 0) { - if (guiInterface && f) { - planes.setUseGUI(pos,FIELD_LEFT); + planes.setUseGUI(pos, FIELD_LEFT); f = false; - } else { - - planes.setUseGUI(pos,FIELD_MIDDLE); - + } + else { + planes.setUseGUI(pos, FIELD_MIDDLE); } if (guiInterface && l == 0) { - planes.setUseGUI(pos,FIELD_RIGHT); + planes.setUseGUI(pos, FIELD_RIGHT); } setDirty(pos++); } - } else { - planes.setUseGUI(pos,FIELD_ONE); + } + else { + planes.setUseGUI(pos, FIELD_ONE); } } } @@ -3419,9 +3430,7 @@ * @see org.tn5250j.ScreenField.java */ protected void drawField(ScreenField sf) { - int pos = sf.startPos(); - int x = sf.length; while (x-- > 0) { @@ -3429,7 +3438,6 @@ } updateDirty(); - } /** @@ -3439,18 +3447,16 @@ * Field to be highlighted */ protected void setFieldHighlighted(ScreenField sf) { - int pos = sf.startPos(); - int x = sf.length; int na = sf.getHighlightedAttr(); while (x-- > 0) { - planes.setScreenAttr(pos,na); + planes.setScreenAttr(pos, na); setDirty(pos++); } + fireScreenChanged(); - } /** @@ -3461,34 +3467,36 @@ * Field to be unhighlighted */ protected void unsetFieldHighlighted(ScreenField sf) { - int pos = sf.startPos(); - int x = sf.length; int na = sf.getAttr(); while (x-- > 0) { - planes.setScreenAttr(pos,na); + planes.setScreenAttr(pos, na); setDirty(pos++); } + fireScreenChanged(); - } protected void setChar(int cByte) { if (lastPos > 0) { lastAttr = planes.getCharAttr(lastPos - 1); } + if (cByte > 0 && (char)cByte < ' ') { planes.setScreenCharAndAttr(lastPos, (char) 0x00, 33, false); setDirty(lastPos); advancePos(); - } else { + } + else { planes.setScreenCharAndAttr(lastPos, (char) cByte, lastAttr, false); setDirty(lastPos); + if (guiInterface && !isInField(lastPos, false)) { planes.setUseGUI(lastPos, NO_GUI); } + advancePos(); } } @@ -3501,7 +3509,6 @@ protected void setAttr(int cByte) { lastAttr = cByte; - // int sattr = screen[lastPos].getCharAttr(); // System.out.println("changing from " + sattr + " to attr " + lastAttr // + @@ -3509,10 +3516,8 @@ // 1)); planes.setScreenCharAndAttr(lastPos, initChar, lastAttr, true); setDirty(lastPos); - advancePos(); int pos = lastPos; - int times = 0; // sattr = screen[lastPos].getCharAttr(); // System.out.println(" next position after change " + sattr + " last @@ -3523,15 +3528,16 @@ while (planes.getCharAttr(lastPos) != lastAttr && !planes.isAttributePlace(lastPos)) { - planes.setScreenAttr(lastPos, lastAttr); + if (guiInterface && !isInField(lastPos, false)) { int g = planes.getWhichGUI(lastPos); + if (g >= FIELD_LEFT && g <= FIELD_ONE) - planes.setUseGUI(lastPos,NO_GUI); + planes.setUseGUI(lastPos, NO_GUI); } + setDirty(lastPos); - times++; advancePos(); } @@ -3540,27 +3546,21 @@ // if (times > 200) // System.out.println(" setAttr = " + times + " start = " + (sr + 1) + // "," + (sc + 1)); - lastPos = pos; } protected void setScreenCharAndAttr(char right, int colorAttr, boolean isAttr) { - - planes.setScreenCharAndAttr(lastPos,right, colorAttr, isAttr); + planes.setScreenCharAndAttr(lastPos, right, colorAttr, isAttr); setDirty(lastPos); advancePos(); - } protected void setScreenCharAndAttr(char right, int colorAttr, - int whichGui, boolean isAttr) { - - planes.setScreenCharAndAttr(lastPos,right, colorAttr, isAttr); - planes.setUseGUI(lastPos,whichGui); - + int whichGui, boolean isAttr) { + planes.setScreenCharAndAttr(lastPos, right, colorAttr, isAttr); + planes.setUseGUI(lastPos, whichGui); setDirty(lastPos); advancePos(); - } /** @@ -3576,24 +3576,17 @@ } protected void setDirty(int pos) { - - int minr = Math.min(getRow(pos),getRow(dirtyScreen.x)); - int minc = Math.min(getCol(pos),getCol(dirtyScreen.x)); - - int maxr = Math.max(getRow(pos),getRow(dirtyScreen.y)); - int maxc = Math.max(getCol(pos),getCol(dirtyScreen.y)); - - int x1 = getPos(minr,minc); - int x2 = getPos(maxr,maxc); - - dirtyScreen.setBounds(x1,x2,0,0); - + int minr = Math.min(getRow(pos), getRow(dirtyScreen.x)); + int minc = Math.min(getCol(pos), getCol(dirtyScreen.x)); + int maxr = Math.max(getRow(pos), getRow(dirtyScreen.y)); + int maxc = Math.max(getCol(pos), getCol(dirtyScreen.y)); + int x1 = getPos(minr, minc); + int x2 = getPos(maxr, maxc); + dirtyScreen.setBounds(x1, x2, 0, 0); } private void resetDirty(int pos) { - - dirtyScreen.setBounds(pos,pos,0,0); - + dirtyScreen.setBounds(pos, pos, 0, 0); } /** @@ -3615,10 +3608,11 @@ * @param i */ protected void changePos(int i) { - lastPos += i; + if (lastPos < 0) lastPos = lenScreen + lastPos; + if (lastPos > lenScreen - 1) lastPos = lastPos - lenScreen; @@ -3626,11 +3620,9 @@ // lastCol + "," + ((lastPos) % numCols) + "," + // ((lastRow * numCols) + lastCol) + "," + // (lastPos)); - } protected void goHome() { - // now we try to move to first input field according to // 14.6 WRITE TO DISPLAY Command // ? If the WTD command is valid, after the command is processed, @@ -3640,16 +3632,17 @@ // - The start of the first non-bypass input field defined in the // format table // - A default starting address of row 1 column 1. - if (pendingInsert && homePos > 0) { setCursor(getRow(homePos), getCol(homePos)); isInField(); // we now check if we are in a field - } else { + } + else { if (!gotoField(1)) { homePos = getPos(1, 1); setCursor(1, 1); isInField(0, 0); // we now check if we are in a field - } else { + } + else { homePos = getPos(getCurrentRow(), getCurrentCol()); } } @@ -3657,6 +3650,7 @@ protected void setPendingInsert(boolean flag, int icX, int icY) { pendingInsert = flag; + if (pendingInsert) { homePos = getPos(icX, icY); } @@ -3677,7 +3671,6 @@ * @param line */ protected void setErrorLine(int line) { - planes.setErrorLine(line); } @@ -3704,51 +3697,47 @@ * @see #saveErrorLine() */ protected void restoreErrorLine() { - if (planes.isErrorLineSaved()) { planes.restoreErrorLine(); - fireScreenChanged(planes.getErrorLine()-1,0,planes.getErrorLine()-1,numCols - 1); + fireScreenChanged(planes.getErrorLine() - 1, 0, planes.getErrorLine() - 1, numCols - 1); } } protected void setStatus(byte attr, byte value, String s) { - // set the status area switch (attr) { - - case STATUS_SYSTEM: - if (value == STATUS_VALUE_ON) { - oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,ScreenOIA.OIA_LEVEL_INPUT_INHIBITED, s); - } - else { - oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED,ScreenOIA.OIA_LEVEL_NOT_INHIBITED,s); - } - break; - - case STATUS_ERROR_CODE: - if (value == STATUS_VALUE_ON) { - setPrehelpState(true, true, false); - oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_ERROR,s); - - sessionVT.signalBell(); - } else { - oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED, - ScreenOIA.OIA_LEVEL_NOT_INHIBITED); - setPrehelpState(false, true, true); - homePos = saveHomePos; - saveHomePos = 0; - pendingInsert = false; - } - break; - + case STATUS_SYSTEM: + if (value == STATUS_VALUE_ON) { + oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, ScreenOIA.OIA_LEVEL_INPUT_INHIBITED, s); + } + else { + oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED, ScreenOIA.OIA_LEVEL_NOT_INHIBITED, s); + } + + break; + + case STATUS_ERROR_CODE: + if (value == STATUS_VALUE_ON) { + setPrehelpState(true, true, false); + oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, + ScreenOIA.OIA_LEVEL_INPUT_ERROR, s); + sessionVT.signalBell(); + } + else { + oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED, + ScreenOIA.OIA_LEVEL_NOT_INHIBITED); + setPrehelpState(false, true, true); + homePos = saveHomePos; + saveHomePos = 0; + pendingInsert = false; + } + + break; } } protected boolean isStatusErrorCode() { - return oia.getLevel() == ScreenOIA.OIA_LEVEL_INPUT_ERROR; - } /** @@ -3757,10 +3746,8 @@ * clears/initializes the screen character array. */ protected void clearAll() { - lastAttr = 32; lastPos = 0; - clearTable(); clearScreen(); planes.setScreenAttr(0, initAttr); @@ -3771,7 +3758,6 @@ * Clear the fields table */ protected void clearTable() { - oia.setKeyBoardLocked(true); screenFields.clearFFT(); planes.initalizeFieldPlanes(); @@ -3784,11 +3770,11 @@ * */ protected void clearGuiStuff() { - for (int x = 0; x < lenScreen; x++) { - planes.setUseGUI(x,NO_GUI); + planes.setUseGUI(x, NO_GUI); } - dirtyScreen.setBounds(0,lenScreen - 1,0,0); + + dirtyScreen.setBounds(0, lenScreen - 1, 0, 0); } /** @@ -3796,19 +3782,14 @@ * to all the positions on the screen */ protected void clearScreen() { - planes.initalizePlanes(); - - dirtyScreen.setBounds(0,lenScreen - 1,0,0); - + dirtyScreen.setBounds(0, lenScreen - 1, 0, 0); oia.clearScreen(); - } protected void restoreScreen() { - lastAttr = 32; - dirtyScreen.setBounds(0,lenScreen - 1,0,0); + dirtyScreen.setBounds(0, lenScreen - 1, 0, 0); updateDirty(); } @@ -3833,51 +3814,60 @@ 0xd, // light magenta/purple 0x3, // brown 0xf // bright white - }; + }; + for (int r = startRow; r <= endRow; r++) { for (int c = startCol; c <= endCol; c++) { - int p = getPos(r,c); + int p = getPos(r, c); char ch = planes.getChar(p); char co = planes.getCharColor(p); char at = planes.getCharExtended(p); boolean ia = planes.isAttributePlace(p); + if (ch < ' ') ch = ' '; + int bg = vt320color[(co >> 8) & 0x0f] + 1; int fg = vt320color[co & 0x0f] + 1; int ul = at & EXTENDED_5250_UNDERLINE; int nd = at & EXTENDED_5250_NON_DSP; int vt_attr = (fg << VDUBuffer.COLOR_FG_SHIFT) + (bg << VDUBuffer.COLOR_BG_SHIFT); + if (ul > 0) vt_attr |= VDUBuffer.UNDERLINE; + if (ia || (nd > 0)) vt_attr |= VDUBuffer.INVISIBLE; + buffer.putChar(c, r, ch, vt_attr); } } + buffer.redrawPassthru(); - dirtyScreen.setBounds(lenScreen,0,0,0); + dirtyScreen.setBounds(lenScreen, 0, 0, 0); } /** * repaint the dirty part of the screen * */ + private synchronized void fireScreenChanged() { if (dirtyScreen.x > dirtyScreen.y) { - Log.i(TAG," x < y " + dirtyScreen); + Log.i(TAG, " x < y " + dirtyScreen); return; } + fireScreenChanged(getRow(dirtyScreen.x), getCol(dirtyScreen.x), getRow(dirtyScreen.y), getCol(dirtyScreen.y)); - } /** * update the cursor position * */ + private synchronized void fireCursorChanged() { int l = getRow(lastPos); int c = getCol(lastPos); - buffer.setCursorPosition(c,l); + buffer.setCursorPosition(c, l); } /** @@ -3902,21 +3892,23 @@ */ public void repaintScreen() { setCursorOff(); - dirtyScreen.setBounds(0,lenScreen - 1,0,0); + dirtyScreen.setBounds(0, lenScreen - 1, 0, 0); updateDirty(); + // restore statuses that were on the screen before resize if (oia.getLevel() == ScreenOIA.OIA_LEVEL_INPUT_ERROR) { oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_ERROR); + ScreenOIA.OIA_LEVEL_INPUT_ERROR); } if (oia.getLevel() == ScreenOIA.OIA_LEVEL_INPUT_INHIBITED) { oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); } if (oia.isMessageWait()) oia.setMessageLightOn(); + setCursorOn(); }