├── src ├── test │ ├── resources │ │ ├── keystore.jks │ │ ├── login-welcome-screen.txt │ │ ├── user-menu-screen.txt │ │ ├── user-menu-screen-m5.txt │ │ └── login.yml │ └── java │ │ └── net │ │ └── infordata │ │ └── em │ │ ├── XI5250CrtTest.java │ │ ├── UnlockWaiter.java │ │ └── XICrtIT.java └── main │ ├── resources │ └── net │ │ └── infordata │ │ └── em │ │ ├── crt5250 │ │ └── resources │ │ │ ├── 3dFx.gif │ │ │ ├── Copy.gif │ │ │ ├── Logo.gif │ │ │ ├── Paste.gif │ │ │ ├── Print.gif │ │ │ ├── CapsLock.gif │ │ │ ├── RefCursor.gif │ │ │ ├── ShiftDown.gif │ │ │ ├── Res.properties │ │ │ └── Res_it.properties │ │ └── tn5250 │ │ └── resources │ │ ├── Flash.gif │ │ ├── Connect.gif │ │ ├── InFrame.gif │ │ ├── Message.gif │ │ ├── Disconnect.gif │ │ ├── HelpState.gif │ │ ├── SnapShot.gif │ │ ├── NormalLockState.gif │ │ ├── XI5250Emulator_16.gif │ │ ├── XI5250Emulator_32.gif │ │ ├── TemporaryLockState.gif │ │ ├── Res.properties │ │ └── Res_it.properties │ └── java │ └── net │ └── infordata │ └── em │ ├── ExceptionHandler.java │ ├── util │ ├── XICommand.java │ └── XIUtil.java │ ├── crt5250 │ ├── XI5250FieldSaver.java │ ├── XI5250BaseField.java │ ├── XI5250FieldPaintAdapter.java │ ├── XI5250CrtAdapter.java │ ├── XI5250FieldAdapter.java │ ├── XI5250FieldPaintListener.java │ ├── XI5250FieldListener.java │ ├── XI5250CrtListener.java │ ├── XI5250FieldPaintEvent.java │ ├── XI5250FieldEvent.java │ ├── XIImagesBdl.java │ ├── XI5250CrtEvent.java │ └── XI5250CrtBeanInfo.java │ ├── tn5250 │ ├── XIReadScreenCmd.java │ ├── XIReadImmediateCmd.java │ ├── XI5250Exception.java │ ├── XIClearFmtTableCmd.java │ ├── XISaveScreenCmd.java │ ├── XI5250EmulatorAdapter.java │ ├── XI5250Ord.java │ ├── XIReadFieldsCmd.java │ ├── XIWdsfOrd.java │ ├── XIReadMdtFieldsCmd.java │ ├── XIWriteErrorCodeCmd.java │ ├── XIRestoreScreenCmd.java │ ├── XI5250Cmd.java │ ├── XIClearUnitCmd.java │ ├── XISBAOrd.java │ ├── XIWEAOrd.java │ ├── XIICOrd.java │ ├── XIMCOrd.java │ ├── XIRollCmd.java │ ├── XIClearUnitAltCmd.java │ ├── XI5250EmulatorListener.java │ ├── XI5250EmulatorMemento.java │ ├── XIRAOrd.java │ ├── XIWriteToDisplayCmd.java │ ├── XIEAOrd.java │ ├── XISOHOrd.java │ ├── XITDOrd.java │ ├── XIQueryCmd.java │ ├── XISFOrd.java │ ├── XI5250EmulatorEvent.java │ ├── Test.java │ ├── XI5250EmulatorBeanInfo.java │ ├── XIImagesBdl.java │ ├── XIDataOrd.java │ ├── XICCCmd.java │ ├── XIFieldTo5250Stream.java │ ├── XI5250EmulatorCtrl.java │ ├── XI5250CmdList.java │ └── XI5250OrdList.java │ ├── tn5250ext │ ├── XIImage.java │ ├── XI5250PanelConnection.java │ ├── XI5250AppletExt.java │ ├── XI5250FieldConnection.java │ ├── XI5250EmulatorExtBeanInfo.java │ ├── XI5250EmulatorExt.java │ ├── XIHintWindow.java │ ├── PSHBTNCHCHandler.java │ ├── Test.java │ └── XI5250SimplePanelsDispatcher.java │ ├── tnprot │ └── XITelnetEmulator.java │ └── crt │ └── XICrtBeanInfo.java ├── .github ├── maven-central-deploy.sh ├── semver-check.sh ├── fix-docs-version.sh ├── settings.xml └── workflows │ └── release.yml ├── .travis.yml ├── README.md └── .gitignore /src/test/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/test/resources/keystore.jks -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/3dFx.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/3dFx.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/Copy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/Copy.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/Logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/Logo.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/Flash.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/Flash.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/Paste.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/Paste.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/Print.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/Print.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/Connect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/Connect.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/InFrame.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/InFrame.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/Message.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/Message.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/CapsLock.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/CapsLock.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/RefCursor.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/RefCursor.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/ShiftDown.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/crt5250/resources/ShiftDown.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/Disconnect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/Disconnect.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/HelpState.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/HelpState.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/SnapShot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/SnapShot.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/NormalLockState.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/NormalLockState.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/XI5250Emulator_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/XI5250Emulator_16.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/XI5250Emulator_32.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/XI5250Emulator_32.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/TemporaryLockState.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/xtn5250/HEAD/src/main/resources/net/infordata/em/tn5250/resources/TemporaryLockState.gif -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/Res.properties: -------------------------------------------------------------------------------- 1 | # crt5250 2 | 3 | TXT_Copy = Copy 4 | TXT_Options = &Options 5 | TXT_RefCursor = Ref. cursor 6 | TXT_Exit = Exit 7 | TXT_Paste = Paste 8 | TXT_Edit = &Edit 9 | TXT_3dFx = 3dFx 10 | 11 | TXT_Print = Print 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/crt5250/resources/Res_it.properties: -------------------------------------------------------------------------------- 1 | # crt5250 2 | 3 | TXT_Copy = Copia 4 | TXT_Options = &Opzioni 5 | TXT_RefCursor = Cursore di riferimento 6 | TXT_Exit = Chiudi 7 | TXT_Paste = Incolla 8 | TXT_Edit = &Modifica 9 | TXT_3dFx = 3dFx 10 | 11 | TXT_Print = Stampa pannello 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em; 2 | 3 | /** 4 | * Interface to be invoked when some exceptional case arises. 5 | */ 6 | public interface ExceptionHandler { 7 | 8 | /** 9 | * Method invoked when an {@link Exception} is thrown. 10 | * 11 | * @param ex Exception thrown while connected to the terminal server. 12 | */ 13 | void onException(Throwable ex); 14 | 15 | /** 16 | * Method invoked when connection is closed by terminal server. 17 | */ 18 | void onConnectionClosed(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /.github/maven-central-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script takes care of deploying tagged versions to maven central and updating the pom.xml 4 | # version with next development version. 5 | # 6 | # Required environment variables: GPG_SECRET_KEYS, GPG_OWNERTRUST, GPG_EXECUTABLE 7 | 8 | set -eo pipefail 9 | 10 | echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --batch --import 11 | echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --batch --import-ownertrust 12 | mvn -e -X --batch-mode deploy -Prelease -DskipTests --settings .github/settings.xml 13 | -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/Res.properties: -------------------------------------------------------------------------------- 1 | # tn5250 2 | 3 | TXT_Copy = Copy 4 | TXT_Options = &Options 5 | TXT_RefCursor = Ref. cursor 6 | TXT_Exit = Exit 7 | TXT_Paste = Paste 8 | TXT_Edit = &Edit 9 | TXT_3dFx = 3dFx 10 | 11 | TXT_About = About 12 | 13 | TXT_ConfirmExit = Confirm exit 14 | 15 | TXT_Communications = &Communications 16 | TXT_Connect = Connect 17 | TXT_Disconnect = Disconnect 18 | 19 | TXT_ConfirmDisconnect = Close connection 20 | TXT_HostNameInput = Enter host-name or ip-address 21 | 22 | TXT_InFrame = Emulator in window 23 | 24 | TXT_SnapShot = Snap-shot 25 | TXT_Print = Print 26 | 27 | -------------------------------------------------------------------------------- /src/main/resources/net/infordata/em/tn5250/resources/Res_it.properties: -------------------------------------------------------------------------------- 1 | # tn5250 2 | 3 | TXT_Copy = Copia 4 | TXT_Options = &Opzioni 5 | TXT_RefCursor = Cursore di riferimento 6 | TXT_Exit = Chiudi 7 | TXT_Paste = Incolla 8 | TXT_Edit = &Modifica 9 | TXT_3dFx = 3dFx 10 | 11 | TXT_About = Informazioni 12 | 13 | TXT_ConfirmExit = Confermi chiusura 14 | 15 | TXT_Communications = &Collegamento 16 | TXT_Connect = Connetti 17 | TXT_Disconnect = Disconnetti 18 | 19 | TXT_ConfirmDisconnect = Chiudo connessione 20 | TXT_HostNameInput = Immetti nome host o indirizzo IP 21 | 22 | TXT_InFrame = Emulatore in finestra 23 | 24 | TXT_SnapShot = Foto pannello 25 | TXT_Print = Stampa pannello 26 | 27 | -------------------------------------------------------------------------------- /.github/semver-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script checks that the version number of the release is an expected one, and avoid erroneous releases which don't follow semver 4 | set -eo pipefail 5 | 6 | git fetch --tags --quiet 7 | VERSION="$1" 8 | PREV_VERSION=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`) 9 | PREV_VERSION=${PREV_VERSION#v} 10 | PREV_MAJOR="${PREV_VERSION%%.*}" 11 | PREV_VERSION="${PREV_VERSION#*.}" 12 | PREV_MINOR="${PREV_VERSION%%.*}" 13 | PREV_PATCH="${PREV_VERSION#*.}" 14 | if [[ "$PREV_VERSION" == "$PREV_PATCH" ]]; then 15 | PREV_PATCH="0" 16 | fi 17 | 18 | [[ "$VERSION" == "$PREV_MAJOR.$PREV_MINOR.$((PREV_PATCH + 1))" || "$VERSION" == "$PREV_MAJOR.$((PREV_MINOR + 1))" || "$VERSION" == "$((PREV_MAJOR + 1)).0" ]] 19 | -------------------------------------------------------------------------------- /.github/fix-docs-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script takes care of setting proper version in docs. 4 | # 5 | set -eo pipefail 6 | 7 | VERSION=$1 8 | 9 | update_file_versions() { 10 | local VERSION="$1" 11 | local FILE="$2" 12 | sed -i "s/xtn5250\(.*\):.*'/xtn5250\1:${VERSION}'/g" "${FILE}" 13 | sed -i "/xtn5250*<\/artifactId>$/{N;s/xtn5250\(.*\)<\/artifactId>\n .*<\/version>/jxtn5250\1<\/artifactId>\n ${VERSION}<\/version>/}" "${FILE}" 14 | } 15 | 16 | update_file_versions ${VERSION} README.md 17 | 18 | git add README.md 19 | git config --local user.email "$(git log --format='%ae' HEAD^!)" 20 | git config --local user.name "$(git log --format='%an' HEAD^!)" 21 | git commit -m "[skip ci] Updated docs artifacts versions" 22 | git push origin HEAD:master -------------------------------------------------------------------------------- /.github/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | ossrh 9 | ${env.SONATYPE_USERNAME} 10 | ${env.SONATYPE_PASSWORD} 11 | 12 | 13 | 14 | 15 | 16 | ossrh 17 | 18 | true 19 | 20 | 21 | ${env.GPG_EXECUTABLE} 22 | ${env.GPG_PASSPHRASE} 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/util/XICommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | !!V 07/07/98 rel. 1.07 - creation. 20 | */ 21 | 22 | 23 | package net.infordata.em.util; 24 | 25 | 26 | /** 27 | */ 28 | public interface XICommand { 29 | 30 | /** 31 | */ 32 | public void execute(); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | # we use this distro to avoid issue when installing oraclejdk8 3 | dist: trusty 4 | jdk: oraclejdk8 5 | cache: 6 | directories: 7 | - "$HOME/.m2" 8 | before_deploy: 9 | - mvn --batch-mode versions:set -DnewVersion=${TRAVIS_TAG:1} 10 | - mvn clean package -DskipTests 11 | deploy: 12 | provider: releases 13 | api_key: 14 | secure: Uy78ZqKuAC4Jm0fTcKEfHbY+ArSKNd2Tta/zvOpmv4ieKyCjzlwKdZztH86j8acdVjP1XCnDBaodwb/mjkRuIvvfAYHS6ZdOOaKB7KtUf3HR923XvkSSu/iHD53t1XvvcCEm+KaPYlesixqp0/mABEovTbIWTS2AOzeO0npehjVBY/qf9cIaNiWTolvJIZ9zxNEaNfz+Aimhqv05UH9REHR3Kav79vbebG5gpSzML0hKDeqCUUAfiFym+sQoJ9NKf8fBsEKBkF6vND63z80DisiX6qKL6dTaikZur5lDSeZX1wHEqnfIevZ3eV16Mf7wlCkETpN/i/qbUFmptILtgHdKKKGHyD145MwDjWG0UjNBFQiPCSaZuhoDuk9trk/vFTKWBLZgTRKVZKN7SFFkFKEZ43TuRimZH8cVDN+9QFoTv0vVVTuyfXng7slzjT+cVFcUpW6AL2TjAvDVJ6R39FGEmDcd+V1dCTEuPUeFSuYqgVT3Y70+5gNZnjyhDSu29SZHDrlYuYoWy0GU+uqzScI5ryPj07zzIJXuk7lp7Pycf0CTapxQ/i/ReD1jzmWVpAhyW7TeI60EWgKZaxd33+4GCfgDh4GU4ceNVtoNJieVAM311uLS0fdIXCIKwoqVZrMgNXbc2qiJDekMe3A+s1P+fgxZfbqKcdCr3XkUJrM= 15 | file_glob: true 16 | file: target/xtn5250-*.jar 17 | skip_cleanup: true 18 | on: 19 | tags: true 20 | repo: Blazemeter/xtn5250 21 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldSaver.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | 03/03/98 rel. _.___- SWING and reorganization. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.crt5250; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * Interface that must be implemented to save XI5250 field status. 29 | * 30 | * @see XI5250Field#saveTo 31 | * 32 | * @author Valentino Proietti - Infordata S.p.A. 33 | */ 34 | public interface XI5250FieldSaver { 35 | 36 | void write(XI5250Field aField, String aStr) throws IOException; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250BaseField.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 03/03/98 rel. _.___- SWING and reorganization. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.crt5250; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * Common base interface for XI5250FieldsList and XI5250Field. 29 | * Only for possible future implementations. 30 | * 31 | * @author Valentino Proietti - Infordata S.p.A. 32 | */ 33 | public interface XI5250BaseField { 34 | 35 | void init(); 36 | 37 | void saveTo(XI5250FieldSaver aSaver) throws IOException; 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIReadScreenCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 read screen command 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIReadScreenCmd extends XI5250Cmd { 33 | 34 | @Override 35 | protected void readFrom5250Stream(InputStream inStream) throws IOException { 36 | } 37 | 38 | @Override 39 | protected void execute() { 40 | ivEmulator.send5250Screen(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldPaintAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 27/05/97 rel. 1.00 - first release. 19 | 03/03/98 rel. _.___- SWING and reorganization. 20 | *** 21 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | 25 | package net.infordata.em.crt5250; 26 | 27 | 28 | /** 29 | * XI5250FieldPaintListener adapter. 30 | * @see XI5250FieldPaintListener 31 | */ 32 | public class XI5250FieldPaintAdapter implements XI5250FieldPaintListener { 33 | 34 | 35 | /** 36 | */ 37 | public void fieldPaint(XI5250FieldPaintEvent e) { 38 | } 39 | 40 | 41 | /** 42 | */ 43 | public void rowPaint(XI5250FieldPaintEvent e) { 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIReadImmediateCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Read Immediate 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIReadImmediateCmd extends XI5250Cmd { 33 | 34 | @Override 35 | protected void readFrom5250Stream(InputStream inStream) throws IOException { 36 | } 37 | 38 | @Override 39 | protected void execute() { 40 | ivEmulator.send5250Data(0x00, ivEmulator.isMasterMDTSet(), false); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250Exception.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | /** 25 | * Used internally.
It is raised if an error is detected while reading and parsing the 5250 26 | * stream. 27 | * 28 | * @author Valentino Proietti - Infordata S.p.A. 29 | */ 30 | public class XI5250Exception extends Exception { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | private final int ivErrorCode; 35 | 36 | public XI5250Exception(String s, int errorCode) { 37 | super(s); 38 | ivErrorCode = errorCode; 39 | } 40 | 41 | public final int getErrorCode() { 42 | return ivErrorCode; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIClearFmtTableCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.InputStream; 25 | 26 | /** 27 | * Clear Format Table 28 | * 29 | * @author Valentino Proietti - Infordata S.p.A. 30 | */ 31 | public class XIClearFmtTableCmd extends XI5250Cmd { 32 | 33 | @Override 34 | protected void readFrom5250Stream(InputStream inStream) { 35 | } 36 | 37 | @Override 38 | protected void execute() { 39 | ivEmulator.setState(XI5250Emulator.ST_NORMAL_LOCKED); 40 | ivEmulator.ivPendingCmd = null; 41 | 42 | ivEmulator.setDefAttr(0x20); 43 | ivEmulator.removeFields(); 44 | ivEmulator.setErrorRow(ivEmulator.getCrtSize().height - 1); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XISaveScreenCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Save screen command 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XISaveScreenCmd extends XI5250Cmd { 33 | 34 | @Override 35 | protected void readFrom5250Stream(InputStream inStream) throws IOException { 36 | } 37 | 38 | @Override 39 | protected void execute() { 40 | int pos = (ivEmulator.ivSavedScreensIdx++) % ivEmulator.ivSavedScreens.length; 41 | ivEmulator.ivSavedScreens[pos] = ivEmulator.createMemento(); 42 | 43 | ivEmulator.send5250SavedScreen(pos); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/infordata/em/XI5250CrtTest.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em; 2 | 3 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; 4 | 5 | import java.awt.Rectangle; 6 | import net.infordata.em.crt5250.XI5250Crt; 7 | import net.infordata.em.crt5250.XI5250Field; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | 12 | public class XI5250CrtTest { 13 | 14 | private static final int COLUMNS = 80; 15 | private static final int ROWS = 24; 16 | private XI5250Crt xi5250Crt; 17 | 18 | @Before 19 | public void setup() { 20 | xi5250Crt = new XI5250Crt(); 21 | xi5250Crt.setCrtSize(COLUMNS, ROWS); 22 | buildScreen(); 23 | } 24 | 25 | private void buildScreen() { 26 | 27 | XI5250Field field1 = new XI5250Field(xi5250Crt, 2, 2, 9, 1); 28 | XI5250Field field2 = new XI5250Field(xi5250Crt, 3, 4, 4, 1); 29 | XI5250Field field3 = new XI5250Field(xi5250Crt, 2, 6, 9, 1); 30 | xi5250Crt.addField(field1); 31 | xi5250Crt.addField(field2); 32 | xi5250Crt.addField(field3); 33 | xi5250Crt.drawString("********", 2, 2); 34 | xi5250Crt.drawString("TEST", 3, 4); 35 | xi5250Crt.drawString("********", 2, 6); 36 | } 37 | 38 | @Test 39 | public void shouldMatchObtainedTextWithStringSelectedAreaWhenGetStringSelectedArea() { 40 | xi5250Crt.setSelectedArea(new Rectangle(3, 4, 4, 1)); 41 | assertThat(xi5250Crt.getStringSelectedArea()).isEqualTo("TEST"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250CrtAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 03/03/98 rel. _.___- SWING and reorganization. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.crt5250; 24 | 25 | /** 26 | * XI5250CrtListener adapter. 27 | * @see XI5250CrtListener 28 | * 29 | * @author Valentino Proietti - Infordata S.p.A. 30 | */ 31 | public class XI5250CrtAdapter implements XI5250CrtListener { 32 | 33 | public void fieldActivated(XI5250CrtEvent e) { 34 | } 35 | 36 | public void fieldDeactivated(XI5250CrtEvent e) { 37 | } 38 | 39 | public void sizeChanged(XI5250CrtEvent e) { 40 | } 41 | 42 | public void keyEvent(XI5250CrtEvent e) { 43 | } 44 | 45 | public void mouseEntersField(XI5250CrtEvent e) { 46 | } 47 | 48 | public void mouseExitsField(XI5250CrtEvent e) { 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250EmulatorAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | /** 25 | * XI5250EmulatorListener adapter. 26 | * 27 | * @author Valentino Proietti - Infordata S.p.A. 28 | */ 29 | public class XI5250EmulatorAdapter implements XI5250EmulatorListener { 30 | 31 | public void connecting(XI5250EmulatorEvent e) { 32 | } 33 | 34 | public void connected(XI5250EmulatorEvent e) { 35 | } 36 | 37 | public void disconnected(XI5250EmulatorEvent e) { 38 | } 39 | 40 | public void stateChanged(XI5250EmulatorEvent e) { 41 | } 42 | 43 | public void newPanelReceived(XI5250EmulatorEvent e) { 44 | } 45 | 46 | public void fieldsRemoved(XI5250EmulatorEvent e) { 47 | } 48 | 49 | public void dataSended(XI5250EmulatorEvent e) { 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 14/05/97 rel. 0.96d- removed SIZE_CHANGED. 19 | 27/05/97 rel. 1.00 - first release. 20 | 03/03/98 rel. _.___- SWING and reorganization. 21 | *** 22 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 23 | */ 24 | 25 | package net.infordata.em.crt5250; 26 | 27 | /** 28 | * XI5250FieldListener adapter. 29 | * @see XI5250FieldListener 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XI5250FieldAdapter implements XI5250FieldListener { 33 | 34 | public void activated(XI5250FieldEvent e) { 35 | } 36 | 37 | public void deactivated(XI5250FieldEvent e) { 38 | } 39 | 40 | public void valueChanged(XI5250FieldEvent e) { 41 | } 42 | 43 | public void enabledStateChanged(XI5250FieldEvent e) { 44 | } 45 | 46 | public void keyEvent(XI5250FieldEvent e) { 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xtn5250 2 | 3 | This is a fork of [xtn5250 emulator](https://sourceforge.net/projects/xtn5250/) which allows connecting to emulate TN5250 terminals. 4 | 5 | ## Usage 6 | 7 | To run the emulator in GUI mode just run the generated jar with something like `java -jar xtn5250.jar` (requires [JRE8+](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)) 8 | 9 | To use the emulator as maven dependency include in `pom.xml`: 10 | 11 | ```xml 12 | 13 | com.blazemeter 14 | xtn5250 15 | 3.2.4 16 | 17 | ``` 18 | 19 | >Check latest version in [releases](https://github.com/blazemeter/xtn5250/releases). 20 | 21 | An example usage can be found in [TerminalClientTest](src/test/java/net/infordata/em/TerminalClientTest.java). 22 | 23 | ## Build 24 | 25 | To build the project is required [JDK8+](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html), [maven](https://maven.apache.org/) 3.3+. 26 | 27 | Then just run `mvn clean install` and the library will be built and installed in the local maven repository. 28 | 29 | ## Release 30 | 31 | To release the project, define the version to be released by checking included changes since last release and following [semantic versioning](https://semver.org/). 32 | Then, create a [release](https://github.com/blazemeter/xtn5250/releases) (including `v` as prefix, e.g. `v0.1`), this will trigger a Travis build which will publish the jars to the created github release. 33 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250Ord.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * Abstract base class for all 5250 Orders 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public abstract class XI5250Ord { 33 | 34 | protected XI5250Emulator ivEmulator; 35 | 36 | 37 | protected void init(XI5250Emulator aEmulator) { 38 | ivEmulator = aEmulator; 39 | } 40 | 41 | /** 42 | * @param inStream the stream from where to read the order from. 43 | * @throws XI5250Exception raised if order parameters are wrong. 44 | * @throws IOException raised when there is an input/output problem. 45 | */ 46 | protected abstract void readFrom5250Stream(InputStream inStream) 47 | throws IOException, XI5250Exception; 48 | 49 | 50 | protected abstract void execute(); 51 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIReadFieldsCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Read fields 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIReadFieldsCmd extends XICCCmd { 33 | 34 | @Override 35 | protected void readFrom5250Stream(InputStream inStream) 36 | throws IOException, XI5250Exception { 37 | readCC(inStream); 38 | } 39 | 40 | @Override 41 | protected void execute() { 42 | ivEmulator.ivPendingCmd = this; 43 | executeCC1(); 44 | executeCC2(); 45 | } 46 | 47 | @Override 48 | protected void executePending(int anAidCode, boolean isMasked) { 49 | ivEmulator.setState(XI5250Emulator.ST_TEMPORARY_LOCK); 50 | ivEmulator.send5250Data(anAidCode, ivEmulator.isMasterMDTSet() && !isMasked, false); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIWdsfOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * WDSF - Write to Display Structured Field 29 | * TODO 30 | * 31 | * see: http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/co2e2001/15.6.13?DT=19950629163252 32 | * 33 | * @author Valentino Proietti - Infordata S.p.A. 34 | */ 35 | public class XIWdsfOrd extends XI5250Ord { 36 | 37 | @Override 38 | protected void readFrom5250Stream(InputStream inStream) 39 | throws IOException, XI5250Exception { 40 | throw new XI5250Exception("Not supported", XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 41 | } 42 | 43 | @Override 44 | protected void execute() { 45 | throw new IllegalStateException("Not supported"); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return super.toString(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XIImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250ext; 23 | 24 | import java.awt.*; 25 | 26 | import javax.swing.*; 27 | 28 | /** 29 | * @author Valentino Proietti - Infordata S.p.A. 30 | */ 31 | public class XIImage extends JComponent { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | private Image ivImage; 36 | 37 | public XIImage(Image anImage) { 38 | setImage(anImage); 39 | } 40 | 41 | public void setImage(Image anImage) { 42 | if (anImage == ivImage) 43 | return; 44 | 45 | ivImage = anImage; 46 | repaint(); 47 | } 48 | 49 | @Override 50 | public void update(Graphics gr) { 51 | paint(gr); 52 | } 53 | 54 | @Override 55 | public void paintComponent(Graphics gr) { 56 | Dimension dim = getSize(); 57 | 58 | if (ivImage != null) 59 | gr.drawImage(ivImage, 0, 0, dim.width, dim.height, this); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIReadMdtFieldsCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Read MDT fields command 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIReadMdtFieldsCmd extends XICCCmd { 33 | 34 | @Override 35 | protected void readFrom5250Stream(InputStream inStream) 36 | throws IOException, XI5250Exception { 37 | readCC(inStream); 38 | } 39 | 40 | @Override 41 | protected void execute() { 42 | ivEmulator.ivPendingCmd = this; 43 | executeCC1(); 44 | executeCC2(); 45 | } 46 | 47 | @Override 48 | protected void executePending(int anAidCode, boolean isMasked) { 49 | ivEmulator.setState(XI5250Emulator.ST_TEMPORARY_LOCK); 50 | ivEmulator.send5250Data(anAidCode, 51 | ivEmulator.isMasterMDTSet() && !isMasked, true); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIWriteErrorCodeCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 12/05/97 rel. 0.95d- setDefAttr() to 0x20. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | /** 29 | * 5250 Write error code command 30 | * 31 | * @author Valentino Proietti - Infordata S.p.A. 32 | */ 33 | public class XIWriteErrorCodeCmd extends XI5250Cmd { 34 | 35 | protected XI5250OrdList ivOrdList; 36 | 37 | @Override 38 | protected void readFrom5250Stream(InputStream inStream) 39 | throws IOException, XI5250Exception { 40 | ivOrdList = ivEmulator.createOrdList(ivEmulator); 41 | ivOrdList.readFrom5250Stream(inStream); 42 | } 43 | 44 | @Override 45 | protected void execute() { 46 | ivEmulator.setState(XI5250Emulator.ST_PRE_HELP); 47 | 48 | ivEmulator.setDefAttr(0x20); 49 | 50 | ivEmulator.setSBA(0, ivEmulator.getErrorRow()); 51 | ivOrdList.execute(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIRestoreScreenCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Restore screen command 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIRestoreScreenCmd extends XI5250Cmd { 33 | 34 | protected int ivPos; 35 | 36 | @Override 37 | protected void readFrom5250Stream(InputStream inStream) 38 | throws IOException, XI5250Exception { 39 | ivPos = inStream.read(); 40 | if (ivPos == -1) 41 | throw new XI5250Exception("Restore screen position required", 42 | XI5250Emulator.ERR_INVALID_COMMAND); 43 | } 44 | 45 | @Override 46 | protected void execute() { 47 | try { 48 | XI5250EmulatorMemento mm = ivEmulator.ivSavedScreens[ivPos]; 49 | 50 | ivEmulator.restoreMemento(mm); 51 | } 52 | catch (ArrayIndexOutOfBoundsException ex) { 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250Cmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * Abstract class for all 5250 commands 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public abstract class XI5250Cmd { 33 | 34 | protected XI5250Emulator ivEmulator; 35 | 36 | protected void init(XI5250Emulator aEmulator) { 37 | ivEmulator = aEmulator; 38 | } 39 | 40 | /** 41 | * @param inStream stream to read from 42 | * @throws IOException raised when there is some communication error. 43 | * @throws XI5250Exception raised if command parameters are wrong. 44 | */ 45 | protected abstract void readFrom5250Stream(InputStream inStream) 46 | throws IOException, XI5250Exception; 47 | 48 | protected abstract void execute(); 49 | 50 | 51 | protected void executePending(int anAidCode, boolean isMasked) { 52 | throw new RuntimeException("executePending() not supported"); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: publish release 2 | on: 3 | release: 4 | types: [ published ] 5 | jobs: 6 | release: 7 | runs-on: ubuntu-latest 8 | concurrency: blazemeter_test 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Setup Java 1.8 12 | uses: actions/setup-java@v1 13 | with: 14 | java-version: 1.8 15 | - name: Get version 16 | id: version 17 | run: echo "release_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV 18 | - name: Check version 19 | run: .github/semver-check.sh ${{ env.release_version }} 20 | - name: set maven project version 21 | run: mvn --batch-mode --no-transfer-progress versions:set -DnewVersion=${{ env.release_version }} --settings .github/settings.xml 22 | - name: package release 23 | run: mvn --batch-mode --no-transfer-progress clean package --settings .github/settings.xml 24 | - name: Upload built jar into release 25 | uses: svenstaro/upload-release-action@v2 26 | with: 27 | repo_token: ${{ secrets.GITHUB_TOKEN }} 28 | file: target/*.jar 29 | file_glob: true 30 | tag: ${{ github.ref }} 31 | - name: publish to Nexus 32 | run: .github/maven-central-deploy.sh 33 | env: 34 | GPG_SECRET_KEYS: ${{ secrets.GPG_SECRET_KEYS }} 35 | GPG_OWNERTRUST: ${{ secrets.GPG_OWNERTRUST }} 36 | GPG_EXECUTABLE: gpg 37 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 38 | SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 39 | SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 40 | - name: update docs version 41 | run: .github/fix-docs-version.sh ${{ env.release_version }} 42 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIClearUnitCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 14/07/97 rel. 1.02 - added support for 27x132 terminal type (IBM-3477-FC). 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Clear unit command 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIClearUnitCmd extends XI5250Cmd { 33 | 34 | @Override 35 | protected void readFrom5250Stream(InputStream inStream) { 36 | } 37 | 38 | @Override 39 | protected void execute() { 40 | ivEmulator.setState(XI5250Emulator.ST_NORMAL_LOCKED); 41 | ivEmulator.ivPendingCmd = null; 42 | 43 | ivEmulator.setCrtSize(80, 24); 44 | 45 | ivEmulator.setDefAttr(0x20); 46 | ivEmulator.clear(); 47 | ivEmulator.removeFields(); 48 | ivEmulator.setErrorRow(ivEmulator.getCrtSize().height - 1); 49 | 50 | // switch back to the previous used font 51 | if (ivEmulator.ivPrevFont != null) { 52 | ivEmulator.setFont(ivEmulator.ivPrevFont); 53 | ivEmulator.ivPrevFont = null; 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldPaintListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 27/05/97 rel. 1.00 - first release. 19 | 03/03/98 rel. _.___- SWING and reorganization. 20 | *** 21 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | package net.infordata.em.crt5250; 25 | 26 | import java.util.EventListener; 27 | 28 | /** 29 | * Useful to add some paint over a field. 30 | * 31 | * @author Valentino Proietti - Infordata S.p.A. 32 | */ 33 | public interface XI5250FieldPaintListener extends EventListener { 34 | 35 | /** 36 | * One event for paint, the bounding rectangle is setted as the clip region. Coordinate are 37 | * relative to the field bounding rectangle 38 | * 39 | * @param e triggered event. 40 | * @see XI5250Field#getBoundingRect 41 | */ 42 | void fieldPaint(XI5250FieldPaintEvent e); 43 | 44 | /** 45 | * One event for each row that makes up the field (a field can be splitted over multiple rows) 46 | * Coordinate are relative to the field bounding rectangle 47 | * 48 | * @param e triggered event. 49 | * @see XI5250Field#getRowsRects 50 | */ 51 | void rowPaint(XI5250FieldPaintEvent e); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XISBAOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 SBA Order 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XISBAOrd extends XI5250Ord { 33 | 34 | protected int ivRow, ivCol; 35 | 36 | @Override 37 | protected void readFrom5250Stream(InputStream inStream) throws IOException, XI5250Exception { 38 | ivRow = Math.max(0, inStream.read()); 39 | ivCol = Math.max(0, inStream.read()); 40 | // Cannot deal with real dimensions, since they can be not applied yet 41 | if (ivRow <= 0 || ivRow > XI5250Emulator.MAX_ROWS || 42 | ivCol <= 0 || ivCol > XI5250Emulator.MAX_COLS) 43 | throw new XI5250Exception("Invalid screen coord: " + ivRow + "," + ivCol, 44 | XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 45 | } 46 | 47 | @Override 48 | protected void execute() { 49 | ivEmulator.setSBA(ivCol - 1, ivRow - 1); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return super.toString() + " [" + ivRow + "," + ivCol + "]"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIWEAOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import net.infordata.em.tnprot.XITelnet; 28 | 29 | /** 30 | * WEA - Write extended attribute 31 | * TODO 32 | * 33 | * see: http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/co2e2001/15.6.11?DT=19950629163252 34 | * 35 | * @author Valentino Proietti - Infordata S.p.A. 36 | */ 37 | public class XIWEAOrd extends XI5250Ord { 38 | 39 | protected byte ivAttributeType; 40 | protected byte ivAttribute; 41 | 42 | @Override 43 | protected void readFrom5250Stream(InputStream inStream) 44 | throws IOException, XI5250Exception { 45 | // If not in enhanced mode ... 46 | throw new XI5250Exception("Not supported", XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 47 | } 48 | 49 | 50 | @Override 51 | protected void execute() { 52 | //TODO 53 | throw new IllegalStateException("Not supported"); 54 | } 55 | 56 | 57 | @Override 58 | public String toString() { 59 | return super.toString() + " [" + XITelnet.toHex(ivAttributeType) + "," + 60 | XITelnet.toHex(ivAttribute) + "]"; 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIICOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 IC Order 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIICOrd extends XI5250Ord { 33 | 34 | protected int ivRow, ivCol; 35 | 36 | @Override 37 | protected void readFrom5250Stream(InputStream inStream) throws IOException, XI5250Exception { 38 | ivRow = Math.max(0, inStream.read()); 39 | ivCol = Math.max(0, inStream.read()); 40 | // Cannot deal with real dimensions, since they can be not applied yet 41 | if (ivRow <= 0 || ivRow > XI5250Emulator.MAX_ROWS || 42 | ivCol <= 0 || ivCol > XI5250Emulator.MAX_COLS) 43 | throw new XI5250Exception("Invalid screen coord: " + ivRow + "," + ivCol, 44 | XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 45 | } 46 | 47 | @Override 48 | protected void execute() { 49 | ivEmulator.setCursorPos(ivCol - 1, ivRow - 1); 50 | ivEmulator.ivCmdList.ivICOrderExecuted = true; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return super.toString() + " [" + ivRow + "," + ivCol + "]"; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 14/05/97 rel. 0.96d- removed SIZE_CHANGED. 19 | 27/05/97 rel. 1.00 - first release. 20 | 03/03/98 rel. _.___- SWING and reorganization. 21 | *** 22 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 23 | */ 24 | 25 | package net.infordata.em.crt5250; 26 | 27 | import java.util.EventListener; 28 | 29 | /** 30 | * Listener for XI5250FieldEvent. 31 | * 32 | * @author Valentino Proietti - Infordata S.p.A. 33 | */ 34 | public interface XI5250FieldListener extends EventListener { 35 | 36 | /** 37 | * Input cursor enters in the field area 38 | * 39 | * @param e triggered event. 40 | */ 41 | void activated(XI5250FieldEvent e); 42 | 43 | /** 44 | * Input cursor exits from the input area 45 | * 46 | * @param e triggered event. 47 | */ 48 | void deactivated(XI5250FieldEvent e); 49 | 50 | /** 51 | * Field value is changed 52 | * 53 | * @param e triggered event. 54 | */ 55 | void valueChanged(XI5250FieldEvent e); 56 | 57 | /** 58 | * Field enabled state is changed using setEnabled method 59 | * 60 | * @param e triggered event. 61 | * @see XI5250Field#setEnabled 62 | * @see XI5250Field#isEnabled 63 | */ 64 | void enabledStateChanged(XI5250FieldEvent e); 65 | 66 | void keyEvent(XI5250FieldEvent e); 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIMCOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * MC - Move cursor 29 | * 30 | * see: http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/co2e2001/15.6.6?DT=19950629163252 31 | 32 | * @author Valentino Proietti - Infordata S.p.A. 33 | */ 34 | public class XIMCOrd extends XI5250Ord { 35 | 36 | protected int ivRow, ivCol; 37 | 38 | @Override 39 | protected void readFrom5250Stream(InputStream inStream) 40 | throws IOException, XI5250Exception { 41 | ivRow = Math.max(0, inStream.read()); 42 | ivCol = Math.max(0, inStream.read()); 43 | // Cannot deal with real dimensions, since they can be not applied yet 44 | if (ivRow <= 0 || ivRow > XI5250Emulator.MAX_ROWS || 45 | ivCol <= 0 || ivCol > XI5250Emulator.MAX_COLS) 46 | throw new XI5250Exception("Invalid screen coord: " + ivRow + "," + ivCol, 47 | XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 48 | } 49 | 50 | @Override 51 | protected void execute() { 52 | ivEmulator.setCursorPos(ivCol - 1, ivRow - 1); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return super.toString() + " [" + ivRow + "," + ivCol + "]"; 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIRollCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 Roll command 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIRollCmd extends XI5250Cmd { 33 | 34 | boolean ivDown; 35 | int ivNRows; 36 | int ivTopRow; 37 | int ivBottomRow; 38 | 39 | @Override 40 | protected void readFrom5250Stream(InputStream inStream) 41 | throws IOException, XI5250Exception { 42 | int[] bb = new int[3]; 43 | int i; 44 | 45 | for (i = 0; i < 3 && (bb[i] = inStream.read()) >= 0; i++) 46 | ; 47 | 48 | if (i < 3) 49 | throw new XI5250Exception("Roll parameter missing", 50 | XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 51 | 52 | ivDown = ((bb[0] & 0x80) != 0); 53 | 54 | ivNRows = (bb[0] & 0x1F); 55 | 56 | ivTopRow = bb[1]; 57 | ivBottomRow = bb[2]; 58 | 59 | if (ivTopRow > ivBottomRow) 60 | throw new XI5250Exception("TopRow greater then BottomRow", 61 | XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 62 | } 63 | 64 | @Override 65 | protected void execute() { 66 | ivEmulator.scroll(ivDown, ivTopRow - 1, ivBottomRow, ivNRows); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250CrtListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /** 18 | !!V 03/03/98 rel. _.___- SWING and reorganization. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.crt5250; 24 | 25 | import java.util.EventListener; 26 | 27 | /** 28 | * XI5250CrtEvent listener 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public interface XI5250CrtListener extends EventListener { 33 | 34 | /** 35 | * @param e generated event. 36 | * @see XI5250CrtEvent#FIELD_ACTIVATED 37 | */ 38 | void fieldActivated(XI5250CrtEvent e); 39 | 40 | /** 41 | * @param e generated event. 42 | * @see XI5250CrtEvent#FIELD_DEACTIVATED 43 | */ 44 | void fieldDeactivated(XI5250CrtEvent e); 45 | 46 | /** 47 | * @param e generated event. 48 | * @see XI5250CrtEvent#SIZE_CHANGED 49 | */ 50 | void sizeChanged(XI5250CrtEvent e); 51 | 52 | /** 53 | * @param e generated event. 54 | * @see XI5250CrtEvent#KEY_EVENT 55 | */ 56 | void keyEvent(XI5250CrtEvent e); 57 | 58 | /** 59 | * @param e generated event. 60 | * @see XI5250CrtEvent#MOUSE_ENTERS_FIELD 61 | */ 62 | void mouseEntersField(XI5250CrtEvent e); 63 | 64 | /** 65 | * @param e generated event. 66 | * @see XI5250CrtEvent#MOUSE_EXITS_FIELD 67 | */ 68 | void mouseExitsField(XI5250CrtEvent e); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/resources/login-welcome-screen.txt: -------------------------------------------------------------------------------- 1 | Sign On 2 | System . . . . . : TESTSYS 3 | Subsystem . . . . : TESTS 4 | Display . . . . . : TESTDISPLY 5 | 6 | User . . . . . . . . . . . . . . 7 | Password . . . . . . . . . . . . 8 | Program/procedure . . . . . . . . 9 | Menu . . . . . . . . . . . . . . 10 | Current library . . . . . . . . . 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | (C) COPYRIGHT IBM CORP. 1980, 2013. 25 | -------------------------------------------------------------------------------- /src/test/resources/user-menu-screen.txt: -------------------------------------------------------------------------------- 1 | MAIN IBM i Main Menu 2 | System: TESTSYS 3 | Select one of the following: 4 | 5 | 1. User tasks 6 | 2. Office tasks 7 | 8 | 4. Files, libraries, and folders 9 | 10 | 6. Communications 11 | 12 | 8. Problem handling 13 | 9. Display a menu 14 | 10. Information Assistant options 15 | 11. IBM i Access tasks 16 | 17 | 90. Sign off 18 | 19 | Selection or command 20 | ===> 21 | 22 | F3=Exit F4=Prompt F9=Retrieve F12=Cancel F13=Information Assistant 23 | F23=Set initial menu 24 | (C) COPYRIGHT IBM CORP. 1980, 2013. 25 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIClearUnitAltCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 14/07/97 rel. 1.02 - added support for 27x132 terminal type (IBM-3477-FC). 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.awt.Font; 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | 29 | /** 30 | * Clear Unit Alternative 31 | * 32 | * @author Valentino Proietti - Infordata S.p.A. 33 | */ 34 | public class XIClearUnitAltCmd extends XI5250Cmd { 35 | 36 | protected int ivPar; 37 | 38 | @Override 39 | protected void readFrom5250Stream(InputStream inStream) throws IOException, XI5250Exception { 40 | ivPar = Math.max(0, inStream.read()); 41 | if (ivPar != 0x00 && ivPar != 0x80) 42 | throw new XI5250Exception("Invalid clear unit param: " + ivPar, 43 | XI5250Emulator.ERR_INVALID_CLEAR_UNIT_ALT); 44 | } 45 | 46 | @Override 47 | protected void execute() { 48 | ivEmulator.setState(XI5250Emulator.ST_NORMAL_LOCKED); 49 | ivEmulator.ivPendingCmd = null; 50 | 51 | if (ivEmulator.ivPrevFont == null) { 52 | Font ft = ivEmulator.getFont(); 53 | ivEmulator.ivPrevFont = new Font(ft.getName(), ft.getStyle(), ft.getSize()); 54 | } 55 | 56 | ivEmulator.setCrtSize(132, 27); 57 | 58 | ivEmulator.setDefAttr(0x20); 59 | ivEmulator.clear(); 60 | ivEmulator.removeFields(); 61 | ivEmulator.setErrorRow(ivEmulator.getCrtSize().height - 1); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250EmulatorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.util.EventListener; 25 | 26 | /** 27 | * Listener for XI5250EmulatorEvent. 28 | * 29 | * @author Valentino Proietti - Infordata S.p.A. 30 | */ 31 | public interface XI5250EmulatorListener extends EventListener { 32 | 33 | /** 34 | * @param e emulator event. 35 | * @see XI5250EmulatorEvent#CONNECTING 36 | */ 37 | void connecting(XI5250EmulatorEvent e); 38 | 39 | 40 | /** 41 | * @param e emulator event. 42 | * @see XI5250EmulatorEvent#CONNECTED 43 | */ 44 | void connected(XI5250EmulatorEvent e); 45 | 46 | 47 | /** 48 | * @param e emulator event. 49 | * @see XI5250EmulatorEvent#DISCONNECTED 50 | */ 51 | void disconnected(XI5250EmulatorEvent e); 52 | 53 | 54 | /** 55 | * @param e emulator event. 56 | * @see XI5250EmulatorEvent#STATE_CHANGED 57 | */ 58 | void stateChanged(XI5250EmulatorEvent e); 59 | 60 | 61 | /** 62 | * @param e emulator event. 63 | * @see XI5250EmulatorEvent#NEW_PANEL_RECEIVED 64 | */ 65 | void newPanelReceived(XI5250EmulatorEvent e); 66 | 67 | 68 | /** 69 | * @param e emulator event. 70 | * @see XI5250EmulatorEvent#FIELDS_REMOVED 71 | */ 72 | void fieldsRemoved(XI5250EmulatorEvent e); 73 | 74 | 75 | /** 76 | * @param e emulator event. 77 | * @see XI5250EmulatorEvent#DATA_SENDED 78 | */ 79 | void dataSended(XI5250EmulatorEvent e); 80 | 81 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XI5250PanelConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250ext; 23 | 24 | import java.awt.Component; 25 | import java.awt.Point; 26 | 27 | /** 28 | * Connect an AWT Component to the XI5250EmulatorExt panel 29 | * moving and resizing the Component as the font size changes. 30 | *
31 |  *   new XI5250PanelConnection(this, new XIImage(logo), 29, 12, 20, 10);
32 |  * 
33 | * 34 | * @author Valentino Proietti - Infordata S.p.A. 35 | */ 36 | public class XI5250PanelConnection { 37 | 38 | private Component ivComponent; 39 | 40 | private int ivCol; 41 | private int ivRow; 42 | private int ivNCols; 43 | private int ivNRows; 44 | 45 | public XI5250PanelConnection(XI5250PanelHandler aPanelHndl, 46 | Component aComponent, 47 | int aCol, int aRow, 48 | int aNCols, int aNRows) { 49 | ivCol = aCol; 50 | ivRow = aRow; 51 | ivNCols = aNCols; 52 | ivNRows = aNRows; 53 | ivComponent = aComponent; 54 | aPanelHndl.connect(this); 55 | } 56 | 57 | protected void recalcBounds(XI5250EmulatorExt aEm) { 58 | Point pt = aEm.toPoints(ivCol, ivRow); 59 | 60 | ivComponent.setBounds(pt.x, pt.y, 61 | ivNCols * aEm.getCharSize().width, 62 | ivNRows * aEm.getCharSize().height); 63 | } 64 | 65 | public final Component getComponent() { 66 | return ivComponent; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XI5250AppletExt.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package net.infordata.em.tn5250ext; 18 | 19 | import net.infordata.em.tn5250.XI5250Applet; 20 | 21 | public class XI5250AppletExt extends XI5250Applet { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @Override 26 | protected XI5250EmulatorExt createEmulator() { 27 | return new XI5250EmulatorExt(); 28 | } 29 | 30 | @Override 31 | public void init() { 32 | super.init(); 33 | final boolean pPSHBTNCHC = "true".equalsIgnoreCase(getParameter("PSHBTNCHC")); 34 | if (pPSHBTNCHC) { 35 | XI5250EmulatorExt emext = getEmulatorExt(); 36 | PanelsDispatcher disp = new PanelsDispatcher(); 37 | disp.setEmulator(emext); 38 | new PSHBTNCHCHandler(disp); 39 | } 40 | } 41 | 42 | public final XI5250EmulatorExt getEmulatorExt() { 43 | return (XI5250EmulatorExt)super.getEmulator(); 44 | } 45 | 46 | private static class PanelsDispatcher extends XI5250PanelsDispatcher { 47 | 48 | private XI5250PanelHandler ivHandler; 49 | 50 | @Override 51 | public synchronized void addPanelHandler(XI5250PanelHandler panel) { 52 | if (ivHandler != null) 53 | throw new IllegalArgumentException("Handler already setted"); 54 | ivHandler = panel; 55 | } 56 | 57 | @Override 58 | protected synchronized XI5250PanelHandler getCurrentPanelHandler() { 59 | return ivHandler; 60 | } 61 | 62 | @Override 63 | public synchronized void removePanelHandler(XI5250PanelHandler panel) { 64 | if (ivHandler != panel) 65 | throw new IllegalArgumentException("Not the registered handler " + panel); 66 | ivHandler = null; 67 | } 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250EmulatorMemento.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import net.infordata.em.crt5250.XI5250CrtBuffer; 25 | import net.infordata.em.crt5250.XI5250FieldsList; 26 | 27 | /** 28 | * Used to store, without exposing it, the internal state of XI5250Emulator. 29 | * 30 | * @see XI5250Emulator#createMemento 31 | * @author Valentino Proietti - Infordata S.p.A. 32 | */ 33 | public class XI5250EmulatorMemento { 34 | 35 | protected XI5250FieldsList ivFields; 36 | 37 | protected int ivFunctionKeysMask; 38 | 39 | protected XI5250Cmd ivPendingCmd; 40 | 41 | protected int ivState; 42 | protected int ivPrevState; 43 | 44 | protected int ivCol; 45 | protected int ivRow; 46 | 47 | protected int ivErrorRow; 48 | 49 | // from super classes 50 | protected XI5250CrtBuffer ivCrtBuffer; 51 | 52 | public XI5250EmulatorMemento(XI5250FieldsList aFieldList, 53 | int aFunctionKeysMask, XI5250Cmd aPendingCmd, 54 | int aState, int aPrevState, 55 | int aCol, int aRow, 56 | int aErrorRow, 57 | XI5250CrtBuffer aCrtBuffer) { 58 | ivFields = aFieldList; 59 | 60 | ivFunctionKeysMask = aFunctionKeysMask; 61 | 62 | ivPendingCmd = aPendingCmd; 63 | 64 | ivState = aState; 65 | ivPrevState = aPrevState; 66 | 67 | ivCol = aCol; 68 | ivRow = aRow; 69 | 70 | ivErrorRow = aErrorRow; 71 | 72 | ivCrtBuffer = aCrtBuffer; 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldPaintEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 27/05/97 rel. 1.00 - first release. 19 | 03/03/98 rel. _.___- SWING and reorganization. 20 | *** 21 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | package net.infordata.em.crt5250; 25 | 26 | import java.awt.Graphics; 27 | import java.util.EventObject; 28 | 29 | /** 30 | * XI5250Field painting event. 31 | * 32 | * @author Valentino Proietti - Infordata S.p.A. 33 | */ 34 | public class XI5250FieldPaintEvent extends EventObject { 35 | 36 | private static final long serialVersionUID = 1L; 37 | 38 | /** 39 | * Paint at field level can be added. 40 | */ 41 | public static final int FIELD_PAINT = 0; 42 | /** 43 | * Paint at field singol row level can be added. 44 | */ 45 | public static final int ROW_PAINT = 1; 46 | 47 | private static final String[] cvIdDescr = {"FIELD_PAINT", 48 | "ROW_PAINT"}; 49 | private int ivId; 50 | private Graphics ivGr; 51 | 52 | public XI5250FieldPaintEvent(int aId, XI5250Field aField, Graphics aGr) { 53 | super(aField); 54 | ivId = aId; 55 | ivGr = aGr; 56 | } 57 | 58 | public int getID() { 59 | return ivId; 60 | } 61 | 62 | /** 63 | * Returns the Graphics that can be used to paint. 64 | * 65 | * @return the Graphics that can be used to paint. 66 | */ 67 | public Graphics getGraphics() { 68 | return ivGr; 69 | } 70 | 71 | public XI5250Field getField() { 72 | return (XI5250Field)getSource(); 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return super.toString() + "[" + cvIdDescr[ivId] + "," + getSource() + "]"; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIRAOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * 5250 RA Order 29 | * 30 | * @author Valentino Proietti - Infordata S.p.A. 31 | */ 32 | public class XIRAOrd extends XI5250Ord { 33 | 34 | protected int ivEndRow, ivEndCol; 35 | protected char ivChar; 36 | 37 | @Override 38 | protected void readFrom5250Stream(InputStream inStream) throws IOException, XI5250Exception { 39 | ivEndRow = Math.max(0, inStream.read()); 40 | ivEndCol = Math.max(0, inStream.read()); 41 | ivChar = ivEmulator.getTranslator().toChar((byte)Math.max(0, inStream.read())); 42 | // Cannot deal with real dimensions, since they can be not applied yet 43 | if (ivEndRow <= 0 || ivEndRow > XI5250Emulator.MAX_ROWS || 44 | ivEndCol <= 0 || ivEndCol > XI5250Emulator.MAX_COLS) 45 | throw new XI5250Exception("Invalid screen coord: " + ivEndRow + "," + ivEndCol, 46 | XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 47 | } 48 | 49 | @Override 50 | protected void execute() { 51 | int start = ivEmulator.toLinearPos(ivEmulator.getSBACol(), ivEmulator.getSBARow()); 52 | int end = ivEmulator.toLinearPos(ivEndCol - 1, ivEndRow - 1); 53 | StringBuilder str = new StringBuilder(end - start + 1); 54 | for (int i = 0; i < (end - start + 1); i++) 55 | str.append(ivChar); 56 | 57 | ivEmulator.drawString(str.toString(), ivEmulator.getSBACol(), ivEmulator.getSBARow()); 58 | ivEmulator.setSBA(ivEmulator.getSBA() + (end - start + 1)); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return super.toString() + 64 | " [" + ivEndRow + "," + ivEndCol + ",'" + ivChar + "'" + "]"; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tnprot/XITelnetEmulator.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 14/05/97 rel. 1.00a- ... 19 | 03/03/98 rel. _.___- SWING and reorganization. 20 | *** 21 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | 25 | package net.infordata.em.tnprot; 26 | 27 | 28 | import java.io.IOException; 29 | 30 | 31 | /** 32 | * Interface that must be implemented by an emulator to receive notification from XITelnet. 33 | * 34 | * @author Valentino Proietti - Infordada S.p.A. 35 | * @see XITelnet 36 | */ 37 | public interface XITelnetEmulator { 38 | 39 | /** 40 | * @see XITelnet#connecting 41 | */ 42 | void connecting(); 43 | 44 | /** 45 | * @see XITelnet#connected 46 | */ 47 | void connected(); 48 | 49 | /** 50 | * @param remote whether the disconnection was caused by a local disconnect, or by the terminal 51 | * server. 52 | * @see XITelnet#disconnected(boolean) 53 | */ 54 | void disconnected(boolean remote); 55 | 56 | /** 57 | * @param ex exception throw when communicating with terminal server. 58 | * @see XITelnet#caughtIOException 59 | */ 60 | void caughtIOException(IOException ex); 61 | 62 | /** 63 | * @param buf bytes received from the terminal server. 64 | * @param len number of bytes received. 65 | * @see XITelnet#receivedData 66 | */ 67 | void receivedData(byte[] buf, int len); 68 | 69 | /** 70 | * @see XITelnet#receivedEOR 71 | */ 72 | void receivedEOR(); 73 | 74 | /** 75 | * @param aIACOpt option of the IAC 76 | * @param aIACStr body of the IAC 77 | * @see XITelnet#unhandledRequest 78 | */ 79 | void unhandledRequest(byte aIACOpt, String aIACStr); 80 | 81 | 82 | /** 83 | * @param aIACOpt IAC option that changed 84 | * @see XITelnet#localFlagsChanged 85 | */ 86 | void localFlagsChanged(byte aIACOpt); 87 | 88 | 89 | /** 90 | * @param aIACOpt IAC option that changed 91 | * @see XITelnet#remoteFlagsChanged 92 | */ 93 | void remoteFlagsChanged(byte aIACOpt); 94 | 95 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIWriteToDisplayCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.util.Iterator; 27 | 28 | import net.infordata.em.crt5250.XI5250Field; 29 | 30 | /** 31 | * 5250 write to display command 32 | * 33 | * @author Valentino Proietti - Infordata S.p.A. 34 | */ 35 | public class XIWriteToDisplayCmd extends XICCCmd { 36 | 37 | protected XI5250OrdList ivOrdList; 38 | 39 | @Override 40 | protected void readFrom5250Stream(InputStream inStream) 41 | throws IOException, XI5250Exception { 42 | readCC(inStream); 43 | 44 | ivOrdList = ivEmulator.createOrdList(ivEmulator); 45 | ivOrdList.readFrom5250Stream(inStream); 46 | } 47 | 48 | @Override 49 | protected void execute() { 50 | executeCC1(); 51 | 52 | // if format table is going to be altered then enter NORMAL_LOCKED state 53 | if (ivOrdList.isOrderPresent(XI5250Emulator.ORD_SF) || 54 | ivOrdList.isOrderPresent(XI5250Emulator.ORD_SOH)) { 55 | ivEmulator.setState(XI5250Emulator.ST_NORMAL_LOCKED); 56 | } 57 | 58 | ivOrdList.execute(); 59 | 60 | if (ivEmulator.getState() != XI5250Emulator.ST_NORMAL_UNLOCKED) { 61 | //if (!ivOrdList.isOrderPresent(XI5250Emulator.ORD_IC)) 62 | if (!ivEmulator.ivCmdList.ivICOrderExecuted) { 63 | // search first not bypass field 64 | XI5250Field field; 65 | boolean found = false; 66 | for (Iterator e = ivEmulator.getFields().iterator(); e.hasNext(); ) { 67 | field = e.next(); 68 | if (!field.isBypassField()) { 69 | ivEmulator.setCursorPos(field.getCol(), field.getRow()); 70 | found = true; 71 | break; 72 | } 73 | } 74 | 75 | if (!found) 76 | ivEmulator.setCursorPos(0, 0); 77 | } 78 | } 79 | 80 | executeCC2(); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIEAOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import net.infordata.em.tnprot.XITelnet; 28 | 29 | /** 30 | * EA - Erase to address TODO 31 | * 32 | * see: http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/co2e2001/15.6.8?DT=19950629163252 33 | * 34 | * @author Valentino Proietti - Infordata S.p.A. 35 | */ 36 | public class XIEAOrd extends XI5250Ord { 37 | 38 | protected int ivRow; 39 | protected int ivCol; 40 | protected int ivLen; 41 | 42 | protected byte[] ivAttributeTypes; 43 | 44 | /** 45 | * @param inStream the stream from where to read the order from. 46 | * @throws XI5250Exception raised if order parameters are wrong. 47 | * @throws IOException raised when there is an input/output problem. 48 | */ 49 | @Override 50 | protected void readFrom5250Stream(InputStream inStream) 51 | throws IOException, XI5250Exception { 52 | byte[] buf = new byte[3]; 53 | if (inStream.read(buf) < buf.length) { 54 | throw new XI5250Exception("EOF reached", XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 55 | } 56 | ivRow = XITelnet.toInt(buf[0]); 57 | ivCol = XITelnet.toInt(buf[1]); 58 | ivLen = XITelnet.toInt(buf[2]); 59 | 60 | if (ivLen < 2 || ivLen > 5) { 61 | throw new XI5250Exception("Invalid len: " + ivLen, XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 62 | } 63 | ivLen--; 64 | ivAttributeTypes = new byte[ivLen]; 65 | if (inStream.read(ivAttributeTypes) < ivLen) { 66 | throw new XI5250Exception("EOF reached", XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 67 | } 68 | } 69 | 70 | @Override 71 | protected void execute() { 72 | //TODO 73 | throw new IllegalStateException("Not supported"); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return super.toString() + " [" + ivRow + "," + ivCol + "," + ivLen + "," + ",[" + 79 | XITelnet.toHex(ivAttributeTypes) + "]" + "]"; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XISOHOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import net.infordata.em.tnprot.XITelnet; 28 | 29 | /** 30 | * 5250 SOH Order 31 | * @author Valentino Proietti - Infordata S.p.A. 32 | */ 33 | public class XISOHOrd extends XI5250Ord { 34 | 35 | protected byte[] ivData; 36 | protected int ivLen; 37 | 38 | @Override 39 | protected void readFrom5250Stream(InputStream inStream) 40 | throws IOException, XI5250Exception { 41 | int i = 0; 42 | int bb; 43 | 44 | ivLen = inStream.read(); 45 | if (ivLen > 0) { 46 | ivData = new byte[ivLen]; 47 | for (i = 0; (i < ivLen) && ((bb = inStream.read()) != -1); i++) 48 | ivData[i] = (byte)bb; 49 | } 50 | // parameters check 51 | if (ivLen < 0 || ivLen > 7 || i < ivLen) 52 | throw new XI5250Exception("Bad SOH Order", XI5250Emulator.ERR_INVALID_SOH_LENGTH); 53 | } 54 | 55 | @Override 56 | protected void execute() { 57 | // I didn' t found them on docs, but i need them 58 | ivEmulator.ivCmdList.ivICOrderExecuted = false; 59 | ivEmulator.removeFields(); 60 | 61 | ivEmulator.ivPendingCmd = null; 62 | 63 | if (ivLen >= 2) { 64 | // resequencing byte present 65 | if (ivLen >= 3) { 66 | // error line address present 67 | if (ivLen >= 4) { 68 | ivEmulator.setErrorRow(ivData[3] - 1); 69 | // function keys mask present 70 | if (ivLen >= 7) { 71 | int xx = XITelnet.toInt(ivData[4]) << 16 | 72 | XITelnet.toInt(ivData[5]) << 8 | 73 | XITelnet.toInt(ivData[6]); 74 | 75 | ivEmulator.setFunctionKeysMask(xx); 76 | } 77 | } 78 | } 79 | } 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | String str = ""; 85 | for (int i = 0; i < ivLen; i++) 86 | str += XITelnet.toHex(ivData[i]) + ","; 87 | return super.toString() + " [" + ivLen + ",[" + str + "]]"; 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XI5250FieldConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250ext; 23 | 24 | import java.awt.Component; 25 | import java.awt.Point; 26 | import java.awt.Rectangle; 27 | 28 | import net.infordata.em.crt5250.XI5250Field; 29 | 30 | /** 31 | * Connect an AWT Component to a XI5250Field 32 | * moving and resizing the Component as the field grows or shrinks. 33 | * 34 | * @author Valentino Proietti - Infordata S.p.A. 35 | */ 36 | public class XI5250FieldConnection { 37 | private Component ivComponent; 38 | 39 | private int ivColsDelta; 40 | private int ivRowsDelta; 41 | private int ivNCols; 42 | private int ivNRows; 43 | 44 | public XI5250FieldConnection(XI5250PanelHandler aPanelHndl, XI5250Field aField, 45 | Component aComponent, 46 | int aColsDelta, int aRowsDelta, 47 | int aNCols, int aNRows) { 48 | ivColsDelta = aColsDelta; 49 | ivRowsDelta = aRowsDelta; 50 | ivNCols = aNCols; 51 | ivNRows = aNRows; 52 | ivComponent = aComponent; 53 | aPanelHndl.connect(aField, this); 54 | } 55 | 56 | public XI5250FieldConnection(XI5250PanelHandler aPanelHndl, 57 | XI5250Field aField, 58 | Component aComponent) { 59 | this(aPanelHndl, aField, aComponent, 0, 0, 1, 1); 60 | } 61 | 62 | protected void recalcBounds(XI5250EmulatorExt aEm, XI5250Field aField) { 63 | Rectangle[] rcts = aField.getRows(); 64 | // use the last row 65 | Rectangle rct = rcts[rcts.length - 1]; 66 | 67 | int bufPos = aEm.toLinearPos(rct.x + rct.width, rct.y); 68 | bufPos += aEm.toLinearPos(ivColsDelta, ivRowsDelta); 69 | 70 | Point pt = aEm.toPoints(aEm.toColPos(bufPos), aEm.toRowPos(bufPos)); 71 | 72 | ivComponent.setBounds(pt.x, pt.y, 73 | ivNCols * aEm.getCharSize().width, 74 | ivNRows * aEm.getCharSize().height); 75 | } 76 | 77 | public final Component getComponent() { 78 | return ivComponent; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XITDOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import net.infordata.em.crt5250.XIEbcdicTranslator; 28 | import net.infordata.em.tnprot.XITelnet; 29 | 30 | /** 31 | * TD - Transparent data 32 | * 33 | * see: http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/co2e2001/15.6.10?DT=19950629163252 34 | * 35 | * @author Valentino Proietti - Infordata S.p.A. 36 | */ 37 | public class XITDOrd extends XI5250Ord { 38 | 39 | protected String ivData; 40 | protected int ivLen; 41 | 42 | @Override 43 | protected void readFrom5250Stream(InputStream inStream) 44 | throws IOException, XI5250Exception { 45 | 46 | byte[] buf = new byte[2]; 47 | if (inStream.read(buf) < buf.length) { 48 | throw new XI5250Exception("EOF reached", XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 49 | } 50 | ivLen = (XITelnet.toInt(buf[0]) << 8) | XITelnet.toInt(buf[1]); 51 | // Cannot deal with real dimensions, since they can be not applied yet 52 | if (ivLen < 0 || ivLen > (XI5250Emulator.MAX_ROWS * XI5250Emulator.MAX_COLS)) { 53 | throw new XI5250Exception("Invalid len", XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 54 | } 55 | 56 | buf = new byte[ivLen]; 57 | int count = inStream.read(buf); 58 | if (count < buf.length) { 59 | throw new XI5250Exception("EOF reached, requested: " + ivLen + 60 | " readden:" + count, XI5250Emulator.ERR_INVALID_ROW_COL_ADDR); 61 | } 62 | XIEbcdicTranslator translator = ivEmulator.getTranslator(); 63 | StringBuilder sb = new StringBuilder(ivLen); 64 | for (int i = 0; i < count; i++) { 65 | sb.append(translator.toChar(buf[i])); 66 | } 67 | ivData = sb.toString(); 68 | 69 | } 70 | 71 | @Override 72 | protected void execute() { 73 | ivEmulator.drawString(ivData, ivEmulator.getSBACol(), ivEmulator.getSBARow()); 74 | ivEmulator.setSBA(ivEmulator.getSBA() + ivData.length()); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return super.toString() + " [" + ivLen + ",\"" + ivData + "\"" + "]"; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt/XICrtBeanInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package net.infordata.em.crt; 18 | 19 | import java.beans.BeanInfo; 20 | import java.beans.IntrospectionException; 21 | import java.beans.Introspector; 22 | import java.beans.PropertyDescriptor; 23 | import java.beans.SimpleBeanInfo; 24 | 25 | public class XICrtBeanInfo extends SimpleBeanInfo { 26 | Class beanClass = XICrt.class; 27 | String iconColor16x16Filename; 28 | String iconColor32x32Filename; 29 | String iconMono16x16Filename; 30 | String iconMono32x32Filename; 31 | 32 | 33 | public XICrtBeanInfo() { 34 | } 35 | 36 | @Override 37 | public PropertyDescriptor[] getPropertyDescriptors() { 38 | try { 39 | PropertyDescriptor _cursorVisible = new PropertyDescriptor("cursorVisible", beanClass, "isCursorVisible", "setCursorVisible"); 40 | 41 | PropertyDescriptor _font = new PropertyDescriptor("font", beanClass, "getFont", "setFont"); 42 | 43 | PropertyDescriptor[] pds = new PropertyDescriptor[] { 44 | _cursorVisible, 45 | _font, 46 | }; 47 | return pds; 48 | } 49 | catch (IntrospectionException ex) { 50 | ex.printStackTrace(); 51 | return null; 52 | } 53 | } 54 | 55 | @Override 56 | public java.awt.Image getIcon(int iconKind) { 57 | switch (iconKind) { 58 | case BeanInfo.ICON_COLOR_16x16: 59 | return iconColor16x16Filename != null ? loadImage(iconColor16x16Filename) : null; 60 | case BeanInfo.ICON_COLOR_32x32: 61 | return iconColor32x32Filename != null ? loadImage(iconColor32x32Filename) : null; 62 | case BeanInfo.ICON_MONO_16x16: 63 | return iconMono16x16Filename != null ? loadImage(iconMono16x16Filename) : null; 64 | case BeanInfo.ICON_MONO_32x32: 65 | return iconMono32x32Filename != null ? loadImage(iconMono32x32Filename) : null; 66 | } 67 | return null; 68 | } 69 | 70 | @Override 71 | public BeanInfo[] getAdditionalBeanInfo() { 72 | Class superclass = beanClass.getSuperclass(); 73 | try { 74 | BeanInfo superBeanInfo = Introspector.getBeanInfo(superclass); 75 | return new BeanInfo[] { superBeanInfo }; 76 | } 77 | catch (IntrospectionException ex) { 78 | ex.printStackTrace(); 79 | return null; 80 | } 81 | } 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250FieldEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 14/05/97 rel. 0.96d- removed SIZE_CHANGED. 19 | 27/05/97 rel. 1.00 - first release. 20 | 03/03/98 rel. _.___- SWING and reorganization. 21 | *** 22 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 23 | */ 24 | 25 | package net.infordata.em.crt5250; 26 | 27 | import java.awt.event.KeyEvent; 28 | import java.util.EventObject; 29 | 30 | /** 31 | * XI5250Field notification event. 32 | * 33 | * @author Valentino Proietti - Infordata S.p.A. 34 | */ 35 | public class XI5250FieldEvent extends EventObject { 36 | 37 | private static final long serialVersionUID = 1L; 38 | 39 | /** 40 | * The field has been activated (ie. the cursor enters the field area) 41 | */ 42 | public static final int ACTIVATED = 0; 43 | /** 44 | * The field has been deactivated (ie. the cursor exits the field area) 45 | */ 46 | public static final int DEACTIVATED = 1; 47 | /** 48 | * The field value has been changed. 49 | */ 50 | public static final int VALUE_CHANGED = 2; 51 | /** 52 | * The field enabled state has changed. 53 | */ 54 | public static final int ENABLED_STATE_CHANGED = 3; 55 | public static final int KEY_EVENT = 4; 56 | 57 | private static final String[] cvIdDescr = {"ACTIVATED", 58 | "DEACTIVATED", 59 | "VALUE_CHANGED", 60 | "ENABLED_STATE_CHANGED", 61 | "KEY_EVENT"}; 62 | 63 | private int ivId; 64 | private KeyEvent ivKeyEvent; 65 | 66 | public XI5250FieldEvent(int aId, XI5250Field aField) { 67 | super(aField); 68 | ivId = aId; 69 | } 70 | 71 | public XI5250FieldEvent(int aId, XI5250Field aField, KeyEvent ke) { 72 | this(aId, aField); 73 | ivKeyEvent = ke; 74 | } 75 | 76 | public final int getID() { 77 | return ivId; 78 | } 79 | 80 | public final XI5250Field getField() { 81 | return (XI5250Field)getSource(); 82 | } 83 | 84 | public final KeyEvent getKeyEvent() { 85 | return ivKeyEvent; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return super.toString() + "[" + cvIdDescr[ivId] + "," + getSource() + "]"; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIQueryCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import net.infordata.em.crt5250.XIEbcdicTranslator; 28 | 29 | /** 30 | * 5250 Query command. 31 | * 32 | * @author Valentino Proietti - Infordata S.p.A. 33 | */ 34 | public class XIQueryCmd extends XI5250Cmd { 35 | protected int[] ivPar = new int[5]; 36 | 37 | @Override 38 | protected void readFrom5250Stream(InputStream inStream) throws IOException { 39 | for (int i = 0; i < 5; i++) 40 | ivPar[i] = inStream.read(); 41 | 42 | if (ivPar[0] != 0x00 || ivPar[1] != 0x05 || 43 | ivPar[2] != 0xD9 || ivPar[3] != 0x70 || 44 | ivPar[4] != 0x00) 45 | ; //!!V gestire errori 46 | } 47 | 48 | @Override 49 | protected void execute() { 50 | XIEbcdicTranslator trans = ivEmulator.getTranslator(); 51 | // see rfc 1205 52 | byte[] buf = { 53 | (byte)0x00, (byte)0x00, 54 | (byte)0x88, 55 | (byte)0x00, (byte)0x3A, 56 | (byte)0xD9, 57 | (byte)0x70, 58 | (byte)0x80, 59 | (byte)0x06, (byte)0x00, // any other 5250 emulator 60 | (byte)0x01, (byte)0x01, (byte)0x00, // version 61 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, 62 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, 63 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, 64 | (byte)0x01, 65 | trans.toEBCDIC('5'), (byte)trans.toEBCDIC('2'), (byte)trans.toEBCDIC('5'), (byte)trans.toEBCDIC('1'), // 5251 66 | trans.toEBCDIC('0'), (byte)trans.toEBCDIC('1'), (byte)trans.toEBCDIC('1'), 67 | (byte)0x02, (byte)0x00, // keyboard 68 | (byte)0x00, 69 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, // S/N 70 | (byte)0x01, (byte)0x00, // max input fields 71 | (byte)0x00, (byte)0x00, (byte)0x00, 72 | (byte)0x01, // Row 1 e col 1 support 73 | (byte)(0x03 | 0x40), // 24x80 and 27x132 color supported 74 | (byte)0x00, // reserved 75 | (byte)0x00, 76 | (byte)0x00, //0x07, // enhanced mode ?? 77 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, 78 | (byte)0x00, (byte)0x00, (byte)0x00}; 79 | 80 | ivEmulator.send5250Packet((byte)0x00, (byte)0x00, buf); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XISFOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 04/06/97 rel. 1.00b- uses XI5250Emulator create5250Field factory method. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | import net.infordata.em.tnprot.XITelnet; 29 | 30 | /** 31 | * 5250 SF Order 32 | * 33 | * @author Valentino Proietti - Infordata S.p.A. 34 | */ 35 | public class XISFOrd extends XI5250Ord { 36 | 37 | protected byte[] FFW = new byte[2]; 38 | protected byte[] FCW = new byte[2]; 39 | protected byte ivScreenAttr; 40 | protected int ivFieldLen; 41 | 42 | @Override 43 | protected void readFrom5250Stream(InputStream inStream) throws IOException { 44 | byte bb; 45 | 46 | inStream.mark(1); 47 | bb = (byte) Math.max(0, inStream.read()); 48 | // check if FFW is present 49 | if ((bb & 0xC0) == 0x40) { 50 | FFW[0] = bb; 51 | FFW[1] = (byte) Math.max(0, inStream.read()); 52 | 53 | inStream.mark(1); 54 | bb = (byte) Math.max(0, inStream.read()); 55 | // check if FCW is present 56 | if ((bb & 0xC0) == 0x80) { 57 | FCW[0] = bb; 58 | FCW[1] = (byte) Math.max(0, inStream.read()); 59 | } else { 60 | inStream.reset(); 61 | } 62 | } else { 63 | inStream.reset(); 64 | } 65 | 66 | ivScreenAttr = (byte) Math.max(0, inStream.read()); 67 | ivFieldLen = (Math.max(0, inStream.read()) << 8) + Math.max(0, inStream.read()); 68 | //!!V effettuare check dei parametri 69 | } 70 | 71 | @Override 72 | protected void execute() { 73 | if (ivScreenAttr != 0) { 74 | ivEmulator.drawString(String.valueOf(XI5250Emulator.ATTRIBUTE_PLACE_HOLDER), 75 | ivEmulator.getSBACol(), ivEmulator.getSBARow(), 76 | ivScreenAttr); 77 | ivEmulator.setSBA(ivEmulator.getSBA() + 1); 78 | } 79 | 80 | // -1 to force attribute reload 81 | ivEmulator.addField(ivEmulator.create5250Field(FFW.clone(), 82 | FCW.clone(), 83 | ivEmulator.getSBACol(), 84 | ivEmulator.getSBARow(), 85 | ivFieldLen, -1)); 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return super.toString() + " [FFW=[" + XITelnet.toHex(FFW[0]) + "," + 91 | XITelnet.toHex(FFW[1]) + "]," + 92 | "FCW=[" + XITelnet.toHex(FCW[0]) + "," + 93 | XITelnet.toHex(FCW[1]) + "]," + 94 | XITelnet.toHex(ivScreenAttr) + "," + ivFieldLen + "]"; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XIImagesBdl.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | !!V 15/06/99 rel. 1.13 - creation. 20 | */ 21 | package net.infordata.em.crt5250; 22 | 23 | import java.awt.Image; 24 | import java.util.HashMap; 25 | import java.util.ListResourceBundle; 26 | import java.util.Map; 27 | 28 | import javax.swing.Icon; 29 | import javax.swing.ImageIcon; 30 | 31 | import net.infordata.em.util.XIUtil; 32 | 33 | /** 34 | * The image bundle. 35 | * 36 | * @author Valentino Proietti - Infordata S.p.A. 37 | */ 38 | public class XIImagesBdl extends ListResourceBundle { 39 | 40 | private static XIImagesBdl cvImagesBdl; 41 | 42 | private static Object[][] cvContents; 43 | 44 | static { 45 | cvContents = new Object[][]{ 46 | {"ShiftDown", 47 | XIUtil.createImage( 48 | XIImagesBdl.class, "resources/ShiftDown.gif")}, 49 | {"CapsLock", 50 | XIUtil.createImage( 51 | XIImagesBdl.class, "resources/CapsLock.gif")}, 52 | {"3dFx", 53 | XIUtil.createImage( 54 | XIImagesBdl.class, "resources/3dFx.gif")}, 55 | {"Copy", 56 | XIUtil.createImage( 57 | XIImagesBdl.class, "resources/Copy.gif")}, 58 | {"Paste", 59 | XIUtil.createImage( 60 | XIImagesBdl.class, "resources/Paste.gif")}, 61 | {"RefCursor", 62 | XIUtil.createImage( 63 | XIImagesBdl.class, "resources/RefCursor.gif")}, 64 | {"Print", 65 | XIUtil.createImage( 66 | XIImagesBdl.class, "resources/Print.gif")}, 67 | {"Logo", 68 | XIUtil.createImage( 69 | XIImagesBdl.class, "resources/Logo.gif")}, 70 | }; 71 | } 72 | 73 | private XIImagesBdl() { 74 | } 75 | 76 | public static XIImagesBdl getImagesBdl() { 77 | if (cvImagesBdl == null) { 78 | cvImagesBdl = new XIImagesBdl(); 79 | } 80 | 81 | return cvImagesBdl; 82 | } 83 | 84 | @Override 85 | public Object[][] getContents() { 86 | return cvContents; 87 | } 88 | 89 | public final Image getImage(String anImageName) { 90 | return ((ImageIcon) getIcon(anImageName)).getImage(); 91 | } 92 | 93 | private Map ivIcons = new HashMap<>(); 94 | 95 | public synchronized final Icon getIcon(String anImageName) { 96 | Icon icon = ivIcons.get(anImageName); 97 | if (icon == null) { 98 | icon = new ImageIcon((Image) getObject(anImageName)); 99 | ivIcons.put(anImageName, icon); 100 | } 101 | return icon; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XI5250EmulatorExtBeanInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 09/09/97 rel. 1.04c- creation. 19 | 24/09/97 rel. 1.05 - DNCX project. 20 | *** 21 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | 25 | package net.infordata.em.tn5250ext; 26 | 27 | 28 | import java.beans.BeanInfo; 29 | import java.beans.IntrospectionException; 30 | import java.beans.Introspector; 31 | import java.beans.PropertyDescriptor; 32 | import java.beans.SimpleBeanInfo; 33 | 34 | 35 | public class XI5250EmulatorExtBeanInfo extends SimpleBeanInfo { 36 | Class beanClass = XI5250EmulatorExt.class; 37 | String iconColor16x16Filename; 38 | String iconColor32x32Filename; 39 | String iconMono16x16Filename; 40 | String iconMono32x32Filename; 41 | 42 | 43 | public XI5250EmulatorExtBeanInfo() { 44 | } 45 | 46 | @Override 47 | public PropertyDescriptor[] getPropertyDescriptors() { 48 | try { 49 | PropertyDescriptor _hintOnActiveField = 50 | new PropertyDescriptor("hintOnActiveField", beanClass, 51 | "isHintOnActiveField", "setHintOnActiveField"); 52 | 53 | PropertyDescriptor _showHints = 54 | new PropertyDescriptor("showHints", beanClass, "getShowHints", 55 | "setShowHints"); 56 | 57 | PropertyDescriptor[] pds = new PropertyDescriptor[] { 58 | _hintOnActiveField, 59 | _showHints, 60 | }; 61 | return pds; 62 | } 63 | catch (IntrospectionException ex) { 64 | ex.printStackTrace(); 65 | return null; 66 | } 67 | } 68 | 69 | @Override 70 | public java.awt.Image getIcon(int iconKind) { 71 | switch (iconKind) { 72 | case BeanInfo.ICON_COLOR_16x16: 73 | return iconColor16x16Filename != null ? loadImage(iconColor16x16Filename) : null; 74 | case BeanInfo.ICON_COLOR_32x32: 75 | return iconColor32x32Filename != null ? loadImage(iconColor32x32Filename) : null; 76 | case BeanInfo.ICON_MONO_16x16: 77 | return iconMono16x16Filename != null ? loadImage(iconMono16x16Filename) : null; 78 | case BeanInfo.ICON_MONO_32x32: 79 | return iconMono32x32Filename != null ? loadImage(iconMono32x32Filename) : null; 80 | } 81 | return null; 82 | } 83 | 84 | @Override 85 | public BeanInfo[] getAdditionalBeanInfo() { 86 | Class superclass = beanClass.getSuperclass(); 87 | try { 88 | BeanInfo superBeanInfo = Introspector.getBeanInfo(superclass); 89 | return new BeanInfo[] { superBeanInfo }; 90 | } 91 | catch (IntrospectionException ex) { 92 | ex.printStackTrace(); 93 | return null; 94 | } 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250EmulatorEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.util.EventObject; 25 | 26 | /** 27 | * XI5250Emulator notification event. 28 | * 29 | * @author Valentino Proietti - Infordata S.p.A. 30 | */ 31 | public class XI5250EmulatorEvent extends EventObject { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Fired just before trying to connect. 37 | */ 38 | public static final int CONNECTING = 0; 39 | /** 40 | * Connection established. 41 | */ 42 | public static final int CONNECTED = 1; 43 | /** 44 | * Connection closed. 45 | */ 46 | public static final int DISCONNECTED = 2; 47 | /** 48 | * Internal state is changed. 49 | */ 50 | public static final int STATE_CHANGED = 3; 51 | /** 52 | * A new 5250 panel has been received and it is ready for the user. 53 | */ 54 | public static final int NEW_PANEL_RECEIVED = 4; 55 | /** 56 | * Fields removed. 57 | */ 58 | public static final int FIELDS_REMOVED = 5; 59 | /** 60 | * Data have been sended (ie. an aid-code was pressed) 61 | */ 62 | public static final int DATA_SENDED = 6; 63 | 64 | protected static final String[] cvIdDescr = {"CONNECTING", 65 | "CONNECTED", 66 | "DISCONNECTED", 67 | "STATE_CHANGED", 68 | "NEW_PANEL_RECEIVED", 69 | "FIELDS_REMOVED", 70 | "DATA_SENDED"}; 71 | 72 | protected int ivId; 73 | protected byte ivAidCode; 74 | 75 | public XI5250EmulatorEvent(int aId, XI5250Emulator aEm) { 76 | super(aEm); 77 | ivId = aId; 78 | } 79 | 80 | public XI5250EmulatorEvent(int aId, XI5250Emulator aEm, byte anAidCode) { 81 | this(aId, aEm); 82 | ivAidCode = anAidCode; 83 | } 84 | 85 | public int getID() { 86 | return ivId; 87 | } 88 | 89 | public XI5250Emulator get5250Emulator() { 90 | return (XI5250Emulator)getSource(); 91 | } 92 | 93 | /** 94 | * The aid code (DATA_SENDED event) 95 | * 96 | * @return The aid code (DATA_SENDED event). 97 | */ 98 | public byte getAidCode() { 99 | return ivAidCode; 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return super.toString() + "[" + cvIdDescr[ivId] + "]"; 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /src/test/java/net/infordata/em/UnlockWaiter.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em; 2 | 3 | import net.infordata.em.tn5250.XI5250EmulatorEvent; 4 | import net.infordata.em.tn5250.XI5250EmulatorListener; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.concurrent.*; 9 | 10 | public class UnlockWaiter implements XI5250EmulatorListener { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(UnlockWaiter.class); 13 | private static final int STABLE_PERIOD_MILLIS = 1000; 14 | 15 | private final CountDownLatch lock = new CountDownLatch(1); 16 | private final TerminalClient client; 17 | private final ScheduledExecutorService stableTimeoutExecutor; 18 | private ScheduledFuture stableTimeoutTask; 19 | private boolean ended; 20 | private boolean isInputInhibited; 21 | 22 | 23 | public UnlockWaiter(TerminalClient client, ScheduledExecutorService stableTimeoutExecutor) { 24 | this.client = client; 25 | this.stableTimeoutExecutor = stableTimeoutExecutor; 26 | client.addEmulatorListener(this); 27 | isInputInhibited = client.isKeyboardLocked(); 28 | if (!isInputInhibited) { 29 | LOG.debug("Start stable period since input is not inhibited"); 30 | startStablePeriod(); 31 | } 32 | } 33 | 34 | private synchronized void startStablePeriod() { 35 | if (ended) { 36 | return; 37 | } 38 | endStablePeriod(); 39 | stableTimeoutTask = stableTimeoutExecutor 40 | .schedule(lock::countDown, STABLE_PERIOD_MILLIS, TimeUnit.MILLISECONDS); 41 | } 42 | 43 | private synchronized void endStablePeriod() { 44 | if (stableTimeoutTask != null) { 45 | stableTimeoutTask.cancel(false); 46 | } 47 | } 48 | 49 | public void await(long timeoutMillis) throws InterruptedException, TimeoutException { 50 | try { 51 | if (!lock.await(timeoutMillis, TimeUnit.MILLISECONDS)) { 52 | throw new TimeoutException(); 53 | } 54 | } finally { 55 | cancelWait(); 56 | client.removeEmulatorListener(this); 57 | } 58 | } 59 | 60 | private synchronized void cancelWait() { 61 | ended = true; 62 | lock.countDown(); 63 | endStablePeriod(); 64 | } 65 | 66 | @Override 67 | public void connecting(XI5250EmulatorEvent event) { 68 | } 69 | 70 | @Override 71 | public void connected(XI5250EmulatorEvent event) { 72 | } 73 | 74 | @Override 75 | public void disconnected(XI5250EmulatorEvent event) { 76 | } 77 | 78 | @Override 79 | public synchronized void stateChanged(XI5250EmulatorEvent event) { 80 | boolean wasInputInhibited = isInputInhibited; 81 | isInputInhibited = client.isKeyboardLocked(); 82 | if (isInputInhibited != wasInputInhibited) { 83 | if (isInputInhibited) { 84 | LOG.debug("Cancel stable period since input has been inhibited"); 85 | endStablePeriod(); 86 | } else { 87 | LOG.debug("Start stable period since input is no longer inhibited"); 88 | startStablePeriod(); 89 | } 90 | } 91 | } 92 | 93 | @Override 94 | public void newPanelReceived(XI5250EmulatorEvent event) { 95 | } 96 | 97 | @Override 98 | public void fieldsRemoved(XI5250EmulatorEvent event) { 99 | } 100 | 101 | @Override 102 | public void dataSended(XI5250EmulatorEvent event) { 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250CrtEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 03/03/98 rel. _.___- SWING and reorganization. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.crt5250; 24 | 25 | import java.awt.event.KeyEvent; 26 | import java.util.EventObject; 27 | 28 | public class XI5250CrtEvent extends EventObject { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * A field has been activated. 34 | */ 35 | public static final int FIELD_ACTIVATED = 0; 36 | /** 37 | * A field has been deactivated. 38 | */ 39 | public static final int FIELD_DEACTIVATED = FIELD_ACTIVATED + 1; 40 | /** 41 | * The crt real-size is changed (ie. the font size is changed) (this event is posted). 42 | */ 43 | public static final int SIZE_CHANGED = FIELD_ACTIVATED + 2; 44 | /** 45 | * A key has been pressed. 46 | * !!! Use this event instead of AWT KeyEvent !!!. 47 | */ 48 | public static final int KEY_EVENT = FIELD_ACTIVATED + 3; 49 | /** 50 | * Mouse enters the field area. 51 | */ 52 | public static final int MOUSE_ENTERS_FIELD = FIELD_ACTIVATED + 4; 53 | /** 54 | * Mouse exits from a field area. 55 | */ 56 | public static final int MOUSE_EXITS_FIELD = FIELD_ACTIVATED + 5; 57 | 58 | 59 | private static final String[] cvIdDescr = {"FIELD_ACTIVATED", 60 | "FIELD_DEACTIVATED", 61 | "SIZE_CHANGED", 62 | "KEY_EVENT", 63 | "MOUSE_ENTERS_FIELD", 64 | "MOUSE_EXITS_FIELD"}; 65 | 66 | private int ivId; 67 | private XI5250Field ivField; 68 | private KeyEvent ivKeyEvent; 69 | 70 | protected XI5250CrtEvent(int aId, XI5250Crt aCrt, XI5250Field aField, 71 | KeyEvent aKeyEvent) { 72 | super(aCrt); 73 | ivId = aId; 74 | ivField = aField; 75 | ivKeyEvent = aKeyEvent; 76 | } 77 | 78 | public XI5250CrtEvent(int aId, XI5250Crt aCrt, XI5250Field aField) { 79 | this(aId, aCrt, aField, null); 80 | } 81 | 82 | public final int getID() { 83 | return ivId; 84 | } 85 | 86 | public final XI5250Crt getCrt() { 87 | return (XI5250Crt)getSource(); 88 | } 89 | 90 | public final XI5250Field getField() { 91 | return ivField; 92 | } 93 | 94 | public final KeyEvent getKeyEvent() { 95 | return ivKeyEvent; 96 | } 97 | 98 | @Override 99 | public String toString() { 100 | return super.toString() + "[" + cvIdDescr[getID()] + "," + ivField + "]"; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XI5250EmulatorExt.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 09/09/97 rel. 1.04c- creation. 19 | 24/09/97 rel. 1.05 - DNCX project. 20 | *** 21 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | package net.infordata.em.tn5250ext; 25 | 26 | import java.io.Serializable; 27 | import java.util.ArrayList; 28 | import java.util.Iterator; 29 | 30 | import net.infordata.em.tn5250.XI5250Emulator; 31 | 32 | /** 33 | * THE 5250 EMULATOR extension. 34 | * 35 | * @author Valentino Proietti - Infordata S.p.A. 36 | */ 37 | public class XI5250EmulatorExt extends XI5250Emulator implements Serializable { 38 | 39 | private static final long serialVersionUID = 1L; 40 | 41 | private boolean ivShowHints = true; 42 | private boolean ivHintOnActiveField = false; 43 | 44 | transient private ArrayList ivDispatchers = 45 | new ArrayList<>(); 46 | 47 | public static final String SHOW_HINTS = "showHints"; 48 | public static final String HINT_ON_ACTIVE_FIELD = "hintOnActiveField"; 49 | 50 | public XI5250EmulatorExt() { 51 | } 52 | 53 | protected synchronized void addDispatcher(XI5250PanelsDispatcher aDispatcher) { 54 | if (!ivDispatchers.contains(aDispatcher)) 55 | ivDispatchers.add(aDispatcher); 56 | } 57 | 58 | protected synchronized void removeDispatcher(XI5250PanelsDispatcher aDispatcher) { 59 | ivDispatchers.remove(aDispatcher); 60 | } 61 | 62 | protected synchronized void refreshHint() { 63 | XI5250PanelsDispatcher disp; 64 | XI5250PanelHandler hndl; 65 | for (Iterator en = ivDispatchers.iterator(); en.hasNext(); ) { 66 | disp = en.next(); 67 | hndl = disp.getCurrentPanelHandler(); 68 | 69 | if (hndl != null) 70 | hndl.refreshHint(); 71 | } 72 | } 73 | 74 | /** 75 | * Enables or disables the fields hints showing (default true). 76 | * @param aFlag true to enable showing hints, false to disable. 77 | */ 78 | public void setShowHints(boolean aFlag) { 79 | if (ivShowHints == aFlag) 80 | return; 81 | 82 | boolean oldShowHints = ivShowHints; 83 | ivShowHints = aFlag; 84 | 85 | firePropertyChange(SHOW_HINTS, oldShowHints, ivShowHints); 86 | } 87 | 88 | public boolean getShowHints() { 89 | return ivShowHints; 90 | } 91 | 92 | public void setHintOnActiveField(boolean aFlag) { 93 | if (ivHintOnActiveField == aFlag) 94 | return; 95 | 96 | boolean oldHintOnActiveField = ivHintOnActiveField; 97 | ivHintOnActiveField = aFlag; 98 | 99 | firePropertyChange(HINT_ON_ACTIVE_FIELD, 100 | oldHintOnActiveField, ivHintOnActiveField); 101 | } 102 | 103 | public boolean isHintOnActiveField() { 104 | return ivHintOnActiveField; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XIHintWindow.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | package net.infordata.em.tn5250ext; 23 | 24 | import java.awt.*; 25 | import java.awt.event.*; 26 | 27 | import javax.swing.*; 28 | 29 | import net.infordata.em.util.*; 30 | 31 | public class XIHintWindow extends JWindow { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | private Component ivComponent; 36 | 37 | private WinAdapter ivWinAdapter = new WinAdapter(); 38 | 39 | public XIHintWindow(XIHint aHint, Component aComponent) { 40 | 41 | super(XIUtil.getFrame(aComponent)); 42 | 43 | if (aHint == null || aComponent == null) { 44 | throw new IllegalArgumentException(); 45 | } 46 | 47 | addComponentListener(new CompAdapter()); 48 | 49 | Point vLocation; 50 | 51 | ivComponent = aComponent; 52 | 53 | vLocation = ivComponent.getLocationOnScreen(); 54 | vLocation.y += ivComponent.getSize().height + 4; 55 | 56 | setLocation(vLocation); 57 | 58 | getContentPane().setBackground(new Color(255, 250, 180)); 59 | 60 | getContentPane().add(aHint); 61 | setSize(aHint.getPreferredSize()); 62 | } 63 | 64 | /** 65 | * Visibile solo se la frame associata attiva 66 | * 67 | * @param b true to set visible, false to set invisible. 68 | */ 69 | @Override 70 | public void setVisible(boolean b) { 71 | //!!V TODO dovrebbe essere visibile solo se la frame alla quale � associato 72 | super.setVisible(b); 73 | } 74 | 75 | class CompAdapter extends ComponentAdapter { 76 | 77 | @Override 78 | public void componentResized(ComponentEvent aEvent) { 79 | if (aEvent.getSource() == getParent()) { 80 | setVisible(false); 81 | } 82 | } 83 | 84 | @Override 85 | public void componentMoved(ComponentEvent aEvent) { 86 | if (aEvent.getSource() == getParent()) { 87 | setVisible(false); 88 | } 89 | } 90 | 91 | @Override 92 | public void componentShown(ComponentEvent aEvent) { 93 | if (aEvent.getSource() == XIHintWindow.this) { 94 | Frame frm = (Frame) getParent(); 95 | frm.addComponentListener(this); 96 | frm.addWindowListener(ivWinAdapter); 97 | } 98 | } 99 | 100 | @Override 101 | public void componentHidden(ComponentEvent aEvent) { 102 | if (aEvent.getSource() == XIHintWindow.this) { 103 | Frame frm = (Frame) getParent(); 104 | frm.removeWindowListener(ivWinAdapter); 105 | frm.removeComponentListener(this); 106 | } 107 | } 108 | } 109 | 110 | class WinAdapter extends WindowAdapter { 111 | 112 | @Override 113 | public void windowDeactivated(WindowEvent aEvent) { 114 | setVisible(false); 115 | } 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/crt5250/XI5250CrtBeanInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | package net.infordata.em.crt5250; 19 | 20 | import java.beans.BeanInfo; 21 | import java.beans.IntrospectionException; 22 | import java.beans.Introspector; 23 | import java.beans.PropertyDescriptor; 24 | import java.beans.SimpleBeanInfo; 25 | 26 | public class XI5250CrtBeanInfo extends SimpleBeanInfo { 27 | Class beanClass = XI5250Crt.class; 28 | String iconColor16x16Filename; 29 | String iconColor32x32Filename; 30 | String iconMono16x16Filename; 31 | String iconMono32x32Filename; 32 | 33 | 34 | public XI5250CrtBeanInfo() { 35 | } 36 | 37 | @Override 38 | public PropertyDescriptor[] getPropertyDescriptors() { 39 | try { 40 | PropertyDescriptor _defBackground = new PropertyDescriptor("defBackground", beanClass, "getDefBackground", "setDefBackground"); 41 | 42 | PropertyDescriptor _defFieldsBorderStyle = new PropertyDescriptor("defFieldsBorderStyle", beanClass, "getDefFieldsBorderStyle", "setDefFieldsBorderStyle"); 43 | 44 | PropertyDescriptor _font = new PropertyDescriptor("font", beanClass, null, "setFont"); 45 | 46 | PropertyDescriptor _insertState = new PropertyDescriptor("insertState", beanClass, "isInsertState", "setInsertState"); 47 | 48 | PropertyDescriptor _referenceCursor = new PropertyDescriptor("referenceCursor", beanClass, "isReferenceCursor", "setReferenceCursor"); 49 | 50 | PropertyDescriptor _codePage = new PropertyDescriptor("codePage", beanClass, "getCodePage", "setCodePage"); 51 | 52 | PropertyDescriptor[] pds = new PropertyDescriptor[] { 53 | _defBackground, 54 | _defFieldsBorderStyle, 55 | _font, 56 | _insertState, 57 | _referenceCursor, 58 | _codePage, 59 | }; 60 | return pds; 61 | } 62 | catch (IntrospectionException ex) { 63 | ex.printStackTrace(); 64 | return null; 65 | } 66 | } 67 | 68 | @Override 69 | public java.awt.Image getIcon(int iconKind) { 70 | switch (iconKind) { 71 | case BeanInfo.ICON_COLOR_16x16: 72 | return iconColor16x16Filename != null ? loadImage(iconColor16x16Filename) : null; 73 | case BeanInfo.ICON_COLOR_32x32: 74 | return iconColor32x32Filename != null ? loadImage(iconColor32x32Filename) : null; 75 | case BeanInfo.ICON_MONO_16x16: 76 | return iconMono16x16Filename != null ? loadImage(iconMono16x16Filename) : null; 77 | case BeanInfo.ICON_MONO_32x32: 78 | return iconMono32x32Filename != null ? loadImage(iconMono32x32Filename) : null; 79 | } 80 | return null; 81 | } 82 | 83 | @Override 84 | public BeanInfo[] getAdditionalBeanInfo() { 85 | Class superclass = beanClass.getSuperclass(); 86 | try { 87 | BeanInfo superBeanInfo = Introspector.getBeanInfo(superclass); 88 | return new BeanInfo[] { superBeanInfo }; 89 | } 90 | catch (IntrospectionException ex) { 91 | ex.printStackTrace(); 92 | return null; 93 | } 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/test/resources/user-menu-screen-m5.txt: -------------------------------------------------------------------------------- 1 | -------------------- z/OS 2.05.00 TIME SHARING OPTION ------------------------- 2 | 3 | 4 | ENTER LOGON PARAMETERS BELOW: 5 | 6 | USERID ===> TPXQA05 MSGCLASS ===> 7 | 8 | SOURCE ===> U49IPG00 UNIT ===> SYSDA 9 | 10 | PROCEDURE ===> PROC394 TIME ===> 0000 11 | 12 | REGION ===> 0004096 DEST ===> 13 | 14 | ACCT NMBR ===> 1 15 | 16 | PERFORM ===> 000 GROUP ===> OMVSGRP 17 | 18 | ENTER AN 'S' BEFORE EACH OPTION DESIRED BELOW: 19 | 20 | S -NOMAIL S -NONOTICE S -RECOVER -RECONNECT -NEW PSWD 21 | 22 | USER KEYS ===> 23 | SECLABEL ===> 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/Test.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em.tn5250; 2 | 3 | import java.awt.event.WindowAdapter; 4 | import java.awt.event.WindowEvent; 5 | import java.lang.reflect.InvocationTargetException; 6 | 7 | import javax.swing.SwingUtilities; 8 | import javax.swing.UIManager; 9 | 10 | import net.infordata.em.crt5250.XI5250Field; 11 | import net.infordata.em.crt5250.XIEbcdicTranslator; 12 | 13 | public class Test { 14 | 15 | private Test() { } 16 | 17 | private static void usageError(String msg) { 18 | System.err.println(msg); 19 | System.err.println("Usage: [-3dFX] [-altFKeyRemap] [-cp codepage] host-name"); 20 | System.err.println("Supported code pages:"); 21 | for (String cp : XIEbcdicTranslator.getRegisteredTranslators().keySet()) { 22 | System.err.println(" " + cp + 23 | (XI5250Emulator.DEFAULT_CODE_PAGE.equalsIgnoreCase(cp)? " default" : "")); 24 | } 25 | System.exit(1); 26 | } 27 | 28 | /* 29 | * Used only for test purposes. 30 | */ 31 | public static void main(String[] args) { 32 | 33 | boolean pUse3dFX = false; 34 | boolean pAltFKeyRemap = false; 35 | 36 | String arg; 37 | String pHost = null; 38 | boolean expectCP = false; 39 | String cp = null; 40 | for (String arg1 : args) { 41 | arg = arg1; 42 | if (arg.startsWith("-")) { 43 | if ("-3dfx".equalsIgnoreCase(arg)) { 44 | pUse3dFX = true; 45 | } else if ("-altFKeyRemap".equalsIgnoreCase(arg)) { 46 | pAltFKeyRemap = true; 47 | } else if ("-cp".equalsIgnoreCase(arg)) { 48 | expectCP = true; 49 | } else { 50 | usageError("Wrong option: " + arg); 51 | } 52 | } else if (expectCP) { 53 | expectCP = false; 54 | if (XIEbcdicTranslator.getTranslator(arg) == null) { 55 | usageError("Unknown codepage: " + arg); 56 | } 57 | cp = arg; 58 | } else { 59 | if (pHost == null) { 60 | pHost = arg; 61 | } else { 62 | usageError("Too many host names."); 63 | } 64 | } 65 | } 66 | if (expectCP) 67 | usageError("A code page is expected"); 68 | 69 | final boolean altFKeyRemap = pAltFKeyRemap; 70 | final boolean use3dFX = pUse3dFX; 71 | final String host = pHost; 72 | final String codePage = cp; 73 | try { 74 | SwingUtilities.invokeAndWait(() -> { 75 | XI5250Emulator em = new XI5250Emulator(); 76 | em.setTerminalType("IBM-3477-FC"); 77 | em.setKeyboardQueue(true); 78 | 79 | em.setAltFKeyRemap(altFKeyRemap); 80 | em.setCodePage(codePage); 81 | 82 | if (host != null) { 83 | em.setHost(host); 84 | em.setActive(true); 85 | } 86 | 87 | XI5250Frame frm = new XI5250Frame("tn5250" + " " + 88 | XI5250Emulator.VERSION, em); 89 | frm.addWindowListener(new WindowAdapter() { 90 | @Override 91 | public void windowClosed(WindowEvent e) { 92 | System.exit(0); 93 | } 94 | }); 95 | 96 | //3D FX 97 | if (use3dFX) { 98 | em.setDefFieldsBorderStyle(XI5250Field.LOWERED_BORDER); 99 | em.setDefBackground(UIManager.getColor("control")); 100 | } 101 | 102 | frm.centerOnScreen(70); 103 | frm.setVisible(true); 104 | }); 105 | } 106 | catch (InterruptedException | InvocationTargetException ex) { 107 | ex.printStackTrace(); 108 | } 109 | 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/test/java/net/infordata/em/XICrtIT.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em; 2 | 3 | import static org.assertj.swing.fixture.Containers.showInFrame; 4 | import static org.assertj.swing.timing.Pause.pause; 5 | 6 | import com.google.common.io.Resources; 7 | import java.awt.Dimension; 8 | import java.awt.Frame; 9 | import java.awt.Point; 10 | import java.io.IOException; 11 | import java.nio.charset.StandardCharsets; 12 | import net.infordata.em.crt.XICrt; 13 | import org.assertj.swing.exception.WaitTimedOutError; 14 | import org.assertj.swing.fixture.FrameFixture; 15 | import org.assertj.swing.timing.Condition; 16 | import org.junit.Before; 17 | import org.junit.experimental.categories.Category; 18 | import org.junit.Test; 19 | 20 | @Category(XICrtIT.class) 21 | public class XICrtIT { 22 | 23 | private static final Dimension M5_SIZE = new Dimension(132, 27); 24 | private static final Dimension M2_SIZE = new Dimension(80, 24); 25 | private static final long TIMEOUT_MILLIS = 5000; 26 | private static final String M5_FILE_NAME = "user-menu-screen-m5.txt"; 27 | private static final String M2_FILE_NAME = "user-menu-screen.txt"; 28 | private FrameFixture frame; 29 | private XICrt crt; 30 | private int m5FontSize; 31 | private int m2FontSize; 32 | 33 | @Before 34 | public void setup() { 35 | crt = new XICrt(); 36 | frame = showInFrame(crt); 37 | initializeFontSizes(); 38 | } 39 | 40 | private void initializeFontSizes() { 41 | Dimension currentScreenSize = frame.target().getToolkit().getScreenSize(); 42 | String stringScreenSize = currentScreenSize.width + "x" + currentScreenSize.height; 43 | switch (stringScreenSize) { 44 | case "1280x720": 45 | m5FontSize = 15; 46 | m2FontSize = 25; 47 | break; 48 | case "1920x1080": 49 | m5FontSize = 24; 50 | m2FontSize = 38; 51 | break; 52 | case "2560x1440": 53 | m5FontSize = 32; 54 | m2FontSize = 50; 55 | break; 56 | case "3840x2160": 57 | m5FontSize = 48; 58 | m2FontSize = 50; 59 | break; 60 | default: 61 | throw new UnsupportedOperationException(String.format("Size [%s] is not supported", 62 | stringScreenSize)); 63 | } 64 | } 65 | 66 | @Test 67 | public void shouldProperlyRecFontSizeWhenResizeAndCrtSizeChanges() throws IOException { 68 | setScreenText(M5_SIZE, M5_FILE_NAME); 69 | Dimension screenSize = frame.target().getToolkit().getScreenSize(); 70 | frame.moveTo(new Point(0, 0)); 71 | frame.resizeTo(screenSize); 72 | waitForFontSize(m5FontSize); 73 | setScreenText(M2_SIZE, M2_FILE_NAME); 74 | waitForFontSize(m2FontSize); 75 | } 76 | 77 | private void setScreenText(Dimension crtSize, String fileName) throws IOException { 78 | String[] screenText = 79 | Resources.toString(Resources.getResource(fileName), StandardCharsets.UTF_8).split("\n"); 80 | crt.setCrtSize(crtSize.width, crtSize.height); 81 | for (int i = 0; i < crtSize.height; i++) { 82 | crt.drawString(screenText[i], 1, i + 1); 83 | } 84 | } 85 | 86 | private void waitForFontSize(int expectedSize) { 87 | try { 88 | pause(new Condition("waiting for font size to be " + expectedSize) { 89 | @Override 90 | public boolean test() { 91 | return crt.getFont().getSize() == expectedSize; 92 | } 93 | }, TIMEOUT_MILLIS); 94 | } catch (WaitTimedOutError e) { 95 | throw new WaitTimedOutError( 96 | e.getMessage() + String.format(" instead of %s", crt.getFont().getSize())); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250EmulatorBeanInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | 19 | package net.infordata.em.tn5250; 20 | 21 | import java.beans.BeanInfo; 22 | import java.beans.IntrospectionException; 23 | import java.beans.Introspector; 24 | import java.beans.PropertyDescriptor; 25 | import java.beans.SimpleBeanInfo; 26 | 27 | public class XI5250EmulatorBeanInfo extends SimpleBeanInfo { 28 | Class beanClass = XI5250Emulator.class; 29 | String iconColor16x16Filename = "resources/XI5250Emulator_16.gif"; 30 | String iconColor32x32Filename = "resources/XI5250Emulator_32.gif"; 31 | String iconMono16x16Filename; 32 | String iconMono32x32Filename; 33 | 34 | 35 | public XI5250EmulatorBeanInfo() { 36 | } 37 | 38 | @Override 39 | public PropertyDescriptor[] getPropertyDescriptors() { 40 | try { 41 | PropertyDescriptor _active = 42 | new PropertyDescriptor("active", beanClass, "isActive", "setActive"); 43 | 44 | PropertyDescriptor _host = 45 | new PropertyDescriptor("host", beanClass, "getHost", "setHost"); 46 | 47 | PropertyDescriptor _keyboardQueue = 48 | new PropertyDescriptor("keyboardQueue", beanClass, 49 | "isKeyboardQueue", "setKeyboardQueue"); 50 | 51 | PropertyDescriptor _terminalType = 52 | new PropertyDescriptor("terminalType", beanClass, 53 | "getTerminalType", "setTerminalType"); 54 | 55 | PropertyDescriptor _altFKeyRemap = 56 | new PropertyDescriptor("altFKeyRemap", beanClass, 57 | "getAltFKeyRemap", "setAltFKeyRemap"); 58 | 59 | PropertyDescriptor[] pds = new PropertyDescriptor[] { 60 | _active, 61 | _host, 62 | _keyboardQueue, 63 | _terminalType, 64 | _altFKeyRemap, 65 | }; 66 | return pds; 67 | } 68 | catch (IntrospectionException ex) { 69 | ex.printStackTrace(); 70 | return null; 71 | } 72 | } 73 | 74 | @Override 75 | public java.awt.Image getIcon(int iconKind) { 76 | switch (iconKind) { 77 | case BeanInfo.ICON_COLOR_16x16: 78 | return iconColor16x16Filename != null ? loadImage(iconColor16x16Filename) : null; 79 | case BeanInfo.ICON_COLOR_32x32: 80 | return iconColor32x32Filename != null ? loadImage(iconColor32x32Filename) : null; 81 | case BeanInfo.ICON_MONO_16x16: 82 | return iconMono16x16Filename != null ? loadImage(iconMono16x16Filename) : null; 83 | case BeanInfo.ICON_MONO_32x32: 84 | return iconMono32x32Filename != null ? loadImage(iconMono32x32Filename) : null; 85 | } 86 | return null; 87 | } 88 | 89 | @Override 90 | public BeanInfo[] getAdditionalBeanInfo() { 91 | Class superclass = beanClass.getSuperclass(); 92 | try { 93 | BeanInfo superBeanInfo = Introspector.getBeanInfo(superclass); 94 | return new BeanInfo[] { superBeanInfo }; 95 | } 96 | catch (IntrospectionException ex) { 97 | ex.printStackTrace(); 98 | return null; 99 | } 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/PSHBTNCHCHandler.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em.tn5250ext; 2 | 3 | import java.awt.Font; 4 | import java.awt.Insets; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.awt.event.KeyEvent; 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | 12 | import javax.swing.JButton; 13 | 14 | import net.infordata.em.crt.XICrt; 15 | import net.infordata.em.crt5250.XI5250Field; 16 | 17 | /** 18 | */ 19 | public class PSHBTNCHCHandler extends XI5250PanelHandler { 20 | 21 | private PSHBTNCHCHandler.FontsCache ivFontsCache; 22 | private List ivButtons = new ArrayList(); 23 | 24 | public PSHBTNCHCHandler(XI5250PanelsDispatcher disp) { 25 | super(disp, ""); 26 | } 27 | 28 | @Override 29 | protected void sizeChanged() { 30 | super.sizeChanged(); 31 | final XI5250EmulatorExt em = getEmulator(); 32 | for (JButton btn : ivButtons) { 33 | btn.setFont(ivFontsCache.getFont( 34 | Math.max(1, em.getFont().getSize() - 2))); 35 | } 36 | } 37 | 38 | @Override 39 | protected boolean detailedTest() { 40 | return true; 41 | } 42 | 43 | @Override 44 | protected void start() { 45 | ivButtons.clear(); 46 | final XI5250EmulatorExt em = getEmulator(); 47 | final int crtWidth = em.getCrtSize().width; 48 | for (Iterator e = getFields().iterator(); e.hasNext(); ) { 49 | final XI5250Field field = e.next(); 50 | if (field.isIOOnly()) { 51 | final int col = field.getCol() - 1; 52 | final int row = field.getRow(); 53 | if (col >= 0 && 54 | "<".equals(em.getString(col, row, 1))) { 55 | final int len; 56 | { 57 | final int fieldEnd = col + field.getLength(); 58 | String str = em.getString(fieldEnd + 1, row, crtWidth - fieldEnd); 59 | int idx = str.indexOf(">"); 60 | len = (idx < 0) ? -1 : idx + 2 + 1; 61 | } 62 | if (len > 0) { 63 | final String txt = em.getString(col + 1, row, len - 2); 64 | JButton btn = new JButton(txt); 65 | if (ivFontsCache == null) 66 | ivFontsCache = new FontsCache(btn.getFont()); 67 | btn.setFont(ivFontsCache.getFont(Math.max(1, em.getFont().getSize() - 2))); 68 | btn.setMargin(new Insets(2, 2, 2, 2)); 69 | btn.setFocusable(false); 70 | btn.addActionListener(new ActionListener() { 71 | public void actionPerformed(ActionEvent e) { 72 | em.setCursorPos(field.getCol(), field.getRow()); 73 | em.requestFocusInWindow(); 74 | em.processRawKeyEvent(new KeyEvent(em, KeyEvent.KEY_PRESSED, 0, 75 | 0, KeyEvent.VK_ENTER, (char)KeyEvent.VK_ENTER)); 76 | } 77 | }); 78 | ivButtons.add(btn); 79 | new XI5250PanelConnection(this, 80 | btn, col, row, len, 1); 81 | } 82 | } 83 | } 84 | } 85 | } 86 | 87 | @Override 88 | protected void stop() { 89 | ivButtons.clear(); 90 | } 91 | 92 | /////// 93 | 94 | private static class FontsCache { 95 | 96 | private Font[] ivFonts = new Font[XICrt.MAX_FONT_SIZE - XICrt.MIN_FONT_SIZE + 1]; 97 | private Font ivFont; 98 | 99 | 100 | public FontsCache(Font font) { 101 | ivFont = font; 102 | } 103 | 104 | 105 | public Font getFont(int size) { 106 | if (ivFonts[size - XICrt.MIN_FONT_SIZE] == null) { 107 | ivFonts[size - XICrt.MIN_FONT_SIZE] = 108 | new Font(ivFont.getName(), 109 | ivFont.getStyle(), 110 | size); 111 | } 112 | return ivFonts[size - XICrt.MIN_FONT_SIZE]; 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIImagesBdl.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | 07/07/98 rel. 1.07 - Uses XIUtil.createImage(), the old approach doesn' t 21 | work at design time. 22 | 15/06/99 rel. 1.13 - Introduced crt5250 bundle. 23 | */ 24 | 25 | package net.infordata.em.tn5250; 26 | 27 | import java.awt.Image; 28 | import java.util.HashMap; 29 | import java.util.ListResourceBundle; 30 | import java.util.Map; 31 | 32 | import javax.swing.Icon; 33 | import javax.swing.ImageIcon; 34 | 35 | import net.infordata.em.util.XIUtil; 36 | 37 | /** 38 | * The image bundle. 39 | * 40 | * @author Valentino Proietti - Infordata S.p.A. 41 | */ 42 | public class XIImagesBdl extends ListResourceBundle { 43 | 44 | private static XIImagesBdl cvImagesBdl; 45 | 46 | private static Object[][] cvContents; 47 | 48 | static { 49 | Object[][] contents = new Object[][] { 50 | {"TemporaryLock", 51 | XIUtil.createImage( 52 | XIImagesBdl.class, "resources/TemporaryLockState.gif")}, 53 | {"NormalLock", 54 | XIUtil.createImage( 55 | XIImagesBdl.class, "resources/NormalLockState.gif")}, 56 | {"Help", 57 | XIUtil.createImage( 58 | XIImagesBdl.class, "resources/HelpState.gif")}, 59 | {"Message", 60 | XIUtil.createImage( 61 | XIImagesBdl.class, "resources/Message.gif")}, 62 | {"Flash", 63 | XIUtil.createImage( 64 | XIImagesBdl.class, "resources/Flash.gif")}, 65 | {"Connect", 66 | XIUtil.createImage( 67 | XIImagesBdl.class, "resources/Connect.gif")}, 68 | {"Disconnect", 69 | XIUtil.createImage( 70 | XIImagesBdl.class, "resources/Disconnect.gif")}, 71 | {"InFrame", 72 | XIUtil.createImage( 73 | XIImagesBdl.class, "resources/InFrame.gif")}, 74 | {"SnapShot", 75 | XIUtil.createImage( 76 | XIImagesBdl.class, "resources/SnapShot.gif")}, 77 | }; 78 | 79 | Object[][] superContents = 80 | net.infordata.em.crt5250.XIImagesBdl.getImagesBdl().getContents(); 81 | cvContents = new Object[superContents.length + contents.length][2]; 82 | System.arraycopy(superContents, 0, cvContents, 0, superContents.length); 83 | System.arraycopy(contents, 0, cvContents, superContents.length, contents.length); 84 | } 85 | 86 | private XIImagesBdl() { 87 | } 88 | 89 | public static XIImagesBdl getImagesBdl() { 90 | if (cvImagesBdl == null) { 91 | cvImagesBdl = new XIImagesBdl(); 92 | } 93 | return cvImagesBdl; 94 | } 95 | 96 | @Override 97 | public Object[][] getContents() { 98 | return cvContents; 99 | } 100 | 101 | public final Image getImage(String anImageName) { 102 | return ((ImageIcon)getIcon(anImageName)).getImage(); 103 | } 104 | 105 | private Map ivIcons = new HashMap<>(); 106 | 107 | public synchronized final Icon getIcon(String anImageName) { 108 | Icon icon = ivIcons.get(anImageName); 109 | if (icon == null) { 110 | icon = new ImageIcon((Image)getObject(anImageName)); 111 | ivIcons.put(anImageName, icon); 112 | } 113 | return icon; 114 | } 115 | 116 | } 117 | 118 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIDataOrd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 15/07/97 rel. 1.02c- XIDataOrd includes 0x1F char. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | import net.infordata.em.crt5250.XIEbcdicTranslator; 29 | import net.infordata.em.tnprot.XITelnet; 30 | 31 | /** 32 | * 5250 Data Order 33 | * 34 | * @author Valentino Proietti - Infordata S.p.A. 35 | */ 36 | public class XIDataOrd extends XI5250Ord { 37 | 38 | protected String ivData; 39 | protected byte ivColor; 40 | 41 | /** 42 | * see IBM 43 | * functions reference and IBM SA21-9247-6 pg. 2.13 44 | * 45 | * @param bb byte representation to check if is a data character or not 46 | * @return true if is a data character, false otherwise. 47 | */ 48 | public static boolean isDataCharacter(int bb) { 49 | // 0x1F instead of 0x20 and keep 0xFF chars 50 | switch (bb) { 51 | case XI5250Emulator.ORD_IC: 52 | case XI5250Emulator.ORD_RA: 53 | case XI5250Emulator.ORD_SBA: 54 | case XI5250Emulator.ORD_SF: 55 | case XI5250Emulator.ORD_SOH: 56 | case XI5250Emulator.ORD_MC: 57 | case XI5250Emulator.ORD_EA: 58 | case XI5250Emulator.ORD_TD: 59 | case XI5250Emulator.ORD_WEA: 60 | case XI5250Emulator.ORD_WDSF: 61 | case XI5250Emulator.ESC: 62 | return false; 63 | default: 64 | return true; 65 | } 66 | } 67 | 68 | @Override 69 | protected void readFrom5250Stream(InputStream inStream) throws IOException { 70 | XIEbcdicTranslator translator = ivEmulator.getTranslator(); 71 | int bb; 72 | 73 | ivColor = 0; 74 | StringBuilder sb = new StringBuilder(128); 75 | 76 | for (int i = 0; ; i++) { 77 | inStream.mark(1); 78 | bb = inStream.read(); 79 | 80 | if (bb == -1) { 81 | break; 82 | } 83 | 84 | // see IBM SA21-9247-6 pg. 2.13 85 | if (isDataCharacter(bb)) { 86 | // is it a color ? 87 | if (bb > 0x1F && bb <= 0x3F) { 88 | if (i == 0) { 89 | ivColor = (byte) bb; 90 | } else { 91 | // cut string if different color 92 | inStream.reset(); 93 | break; 94 | } 95 | } else { 96 | sb.append(translator.toChar((byte) bb)); 97 | } 98 | } else { 99 | inStream.reset(); 100 | break; 101 | } 102 | } 103 | ivData = sb.toString(); 104 | } 105 | 106 | @Override 107 | protected void execute() { 108 | if (ivColor != 0) { 109 | ivEmulator.setDefAttr(XITelnet.toInt(ivColor)); 110 | ivEmulator.drawString(String.valueOf(XI5250Emulator.ATTRIBUTE_PLACE_HOLDER), 111 | ivEmulator.getSBACol(), ivEmulator.getSBARow()); 112 | ivEmulator.setSBA(ivEmulator.getSBA() + 1); 113 | } 114 | ivEmulator.drawString(ivData, ivEmulator.getSBACol(), ivEmulator.getSBARow()); 115 | ivEmulator.setSBA(ivEmulator.getSBA() + ivData.length()); 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return super.toString() + " [" + XITelnet.toHex(ivColor) + "," + ",\"" + ivData + "\"" + "]"; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XICCCmd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | 01/09/97 rel. 1.04a- executeCC1() implemented. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.awt.Toolkit; 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | 29 | import net.infordata.em.crt5250.XI5250Field; 30 | import net.infordata.em.tnprot.XITelnet; 31 | 32 | /** 33 | * Abstract base class for all 5250 commands with CC parameter. 34 | * 35 | * @author Valentino Proietti - Infordata S.p.A. 36 | */ 37 | public abstract class XICCCmd extends XI5250Cmd { 38 | 39 | protected byte[] ivCC; 40 | 41 | /** 42 | * @param inStream input stream from where to read the command from. 43 | * @throws IOException raised if there is an input/output problem. 44 | * @throws XI5250Exception raised if command parameters are wrong. 45 | */ 46 | @Override 47 | protected abstract void readFrom5250Stream(InputStream inStream) 48 | throws IOException, XI5250Exception; 49 | 50 | @Override 51 | protected abstract void execute(); 52 | 53 | /** 54 | * @param inStream input stream from where to read the CC parameter from. 55 | * @throws IOException raised if there is an input/output problem. 56 | * @throws XI5250Exception raised if command parameters are wrong. 57 | */ 58 | protected void readCC(InputStream inStream) 59 | throws IOException, XI5250Exception { 60 | 61 | int bb; 62 | int i; 63 | ivCC = new byte[2]; 64 | 65 | for (i = 0; (i < 2) && ((bb = inStream.read()) != -1); i++) { 66 | ivCC[i] = (byte) bb; 67 | } 68 | 69 | if (i < 2) { 70 | throw new XI5250Exception("CC required", XI5250Emulator.ERR_INVALID_COMMAND); 71 | } 72 | } 73 | 74 | protected void executeCC1() { 75 | int cc1 = ivCC[0] & 0xE0; 76 | 77 | // reset pending aid; lock keyboard 78 | if (cc1 != 0) { 79 | ivEmulator.ivPendingCmd = null; 80 | ivEmulator.setState(XI5250Emulator.ST_NORMAL_LOCKED); 81 | } 82 | 83 | // clear master mdt; reset mdt in nonbypass-fields 84 | if (cc1 == 0x40 || cc1 == 0xA0 || cc1 == 0xC0) { 85 | //!!V gestire master mdt 86 | for (XI5250Field field : ivEmulator.getFields()) { 87 | if (!field.isOrgBypassField()) { 88 | field.resetMDT(); 89 | } 90 | } 91 | } 92 | 93 | // clear master mdt; reset mdt in all fields 94 | if (cc1 == 0x60 || cc1 == 0xE0) { 95 | //!!V gestire master mdt 96 | for (XI5250Field field : ivEmulator.getFields()) { 97 | field.resetMDT(); 98 | } 99 | } 100 | 101 | // null non bypass-fields with mdt on 102 | if (cc1 == 0x80 || cc1 == 0xC0) { 103 | for (XI5250Field field : ivEmulator.getFields()) { 104 | if (!field.isOrgBypassField() && field.isMDTOn()) { 105 | field.clear(); 106 | } 107 | } 108 | } 109 | 110 | // null all non bypass-fields 111 | if (cc1 == 0xA0 || cc1 == 0xE0) { 112 | for (XI5250Field field : ivEmulator.getFields()) { 113 | if (!field.isBypassField()) { 114 | field.clear(); 115 | } 116 | } 117 | } 118 | } 119 | 120 | protected void executeCC2() { 121 | if ((ivCC[1] & 0x10) != 0) { 122 | ivEmulator.setBlinkingCursor(true); 123 | } else if ((ivCC[1] & 0x20) != 0) { 124 | ivEmulator.setBlinkingCursor(false); 125 | } 126 | 127 | // unlock the keyboard 128 | if ((ivCC[1] & 0x08) != 0) { 129 | ivEmulator.setState(XI5250Emulator.ST_NORMAL_UNLOCKED); 130 | } 131 | 132 | if ((ivCC[1] & 0x04) != 0) { 133 | ivEmulator.soundAlarm(); 134 | } 135 | } 136 | 137 | @Override 138 | public String toString() { 139 | return super.toString() + " [CC=[" + XITelnet.toHex(ivCC[0]) + "," + XITelnet.toHex(ivCC[1]) 140 | + "]]"; 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/test/resources/login.yml: -------------------------------------------------------------------------------- 1 | - !server {data: FFFD27FFFD18, delayMillis: 195} 2 | - !client {data: FFFC27} 3 | - !client {data: FFFB18} 4 | - !server {data: FFFA1801FFF0} 5 | - !client {data: FFFA1800} 6 | - !client {data: 49424D2D333437372D4643FFF0} 7 | - !server {data: FFFD19FFFB19FFFD00FFFB00} 8 | - !client {data: FFFB19} 9 | - !client {data: FFFD19FFFB00FFFD00} 10 | # Server welcome screen 11 | - !server {data: 01F512A00000040000030440041100180107000000190000001101162240404040404040404040404040E289879540D695020137402011022F20E2A8A2A3859440404B404B404B404B404B407A2011024520E3C5E2E3E2E8E2402011032F20E2A482A2A8A2A38594404B404B404B404B407A2011034520E3C5E2E3E240404040402011042F20C489A2979381A8404B404B404B404B404B407A2011044520E3C5E2E3C4C9E2D7D3E82011061020E4A2859940404B404B404B404B404B404B404B404B404B404B404B404B404B404B201106341D402024000A000000000000000000001107341D402027000A11081020D799968799819461979996838584A49985404B404B404B404B404B404B404B404B201108341D400024000A0000000000000000000011091020D48595A440404B404B404B404B404B404B404B404B404B404B404B404B404B404B201109341D400024000A00000000000000000000110A1020C3A499998595A340938982998199A8404B404B404B404B404B404B404B404B404B20110A341D400024000A0000000000000000000011071020D781A2A2A696998440404B404B404B404B404B404B404B404B404B404B404B404B201107342702073E0011182722404DC35D40C3D6D7E8D9C9C7C8E340C9C2D440C3D6D9D74B40F1F9F8F06B40F2F0F1F34B404040402004520000FFEF, 12 | delayMillis: 5} 13 | # User sends user and password 14 | - !client {data: 002112A0000004000000073CF1110635E3C5E2E3E4E2D9110735E3C5E2E3D7E2E6FFEF} 15 | - !server {data: 001112A000000400000304F30005D97000FFEF, delayMillis: 1522} 16 | - !client {data: 004712A0000004000000000088003AD9708006000101000000000000000000000000000000000001F5F2F5F1F0F1F1020000000000000100000000014300000000000000000000FFEF} 17 | - !server {data: 000A12A000000400000CFFEF} 18 | # Server menu screen 19 | - !server {data: 028C12A00000040000030440041100001114061D50002000991101013AD4C1C9D5000000000000200000000000000000000000000000000000000022C9C2D4408940D481899540D48595A420110202274020400000400000274020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020E2A8A2A385947A200020E3C5E2E3E2E8E200201103013AE285938583A34096958540968640A38885408696939396A68995877A2011050620F14B00E4A2859940A381A292A22011060620F24B00D6868689838540A381A292A22011080620F44B00C6899385A26B409389829981998985A26B4081958440869693848599A220110A0620F64B00C3969494A495898381A3899695A220110C0620F84B00D799968293859440888195849389958720110D0620F94B00C489A2979381A8408140948595A420110E0520F1F04B00C9958696999481A389969540C1A2A289A2A38195A3409697A3899695A220110F0520F1F14B00C9C2D4408940C1838385A2A240A381A292A22011110520F9F04B00E2898795409686862011130120E285938583A3899695409699408396949481958420111401207E7E7E6E24111550201116013AC6F37EC5A789A320003AC6F47ED799969497A320003AC6F97ED985A3998985A58520003AC6F1F27EC3819583859320003AC6F1F37EC9958696999481A389969540C1A2A289A2A38195A3201117013AC6F2F37EE285A340899589A389819340948595A420111801224DC35D40C3D6D7E8D9C9C7C8E340C9C2D440C3D6D9D74B40F1F9F8F06B40F2F0F1F34B00000000000000000000000000000000000000000000000000000000000000000000000000000000002200201314070411001C04520000FFEF, 20 | delayMillis: 89} 21 | # User selects tasks menu item 22 | - !client {data: 001112A00000040000001408F1111407F1FFEF} 23 | # Server tasks menu screen 24 | - !server {data: 02F012A00000040000030440041100001114061D50002000991101013AE4E2C5D9000000000000200000000000000000000000000000000000000000000022E4A2859940E381A292A220110202274020400000400000274020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020E2A8A2A385947A200020E3C5E2E3E2E8E200201103013AE285938583A34096958540968640A38885408696939396A68995877A2011050620F14B00C489A2979381A84096994083888195878540A896A499409196822011060620F24B00C489A2979381A8409485A2A2818785A22011070620F34B00E28595844081409485A2A28187852011080620F44B00E2A4829489A34081409196822011090620F54B00E696999240A689A38840A896A49940A29796969385844096A4A397A4A34086899385A220110A0620F64B00E696999240A689A38840A896A499408281A3838840919682A220110B0620F74B00C489A2979381A84096994083888195878540A896A49940938982998199A8409389A2A320110C0620F84B00C3888195878540A896A499409781A2A2A696998420110D0620F94B00C3888195878540A896A49940A4A28599409799968689938520110F0520F6F04B00D496998540A4A2859940A381A292409697A3899695A22011110520F9F04B00E2898795409686862011130120E285938583A3899695409699408396949481958420111401207E7E7E6E24111550201116013AC6F37EC5A789A320003AC6F47ED799969497A320003AC6F97ED985A3998985A58520003AC6F1F27EC3819583859320003AC6F1F37EC9958696999481A389969540C1A2A289A2A38195A3201117013AC6F1F67EE2A8A2A3859440D481899540948595A420111801224DC35D40C3D6D7E8D9C9C7C8E340C9C2D440C3D6D9D74B40F1F9F8F06B40F2F0F1F34B00000000000000000000000000000000000000000000000000000000000000000000000000000000002200201314070411001804520000FFEF, 25 | delayMillis: 2} 26 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XIFieldTo5250Stream.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 10/04/97 rel. 0.93 - some fix to add SignedNumeric fields handling. 19 | 06/08/97 rel. 1.03c- bug fix. 20 | 02/09/97 rel. 1.04a- changed to make XIReadFieldsCmd and XIReadImmediateCmd work. 21 | *** 22 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 23 | */ 24 | 25 | 26 | package net.infordata.em.tn5250; 27 | 28 | import java.io.IOException; 29 | import java.io.OutputStream; 30 | 31 | import net.infordata.em.crt5250.XI5250Field; 32 | import net.infordata.em.crt5250.XI5250FieldSaver; 33 | import net.infordata.em.crt5250.XIEbcdicTranslator; 34 | 35 | /** 36 | * Implements XI5250FieldSaver to write fields content to an OutputStream. 37 | * 38 | * @see XI5250Emulator#send5250Data 39 | * 40 | * @author Valentino Proietti - Infordata S.p.A. 41 | */ 42 | public class XIFieldTo5250Stream implements XI5250FieldSaver { 43 | 44 | XI5250Emulator ivEmulator; 45 | OutputStream ivOut; 46 | boolean ivOnlyMDT; 47 | 48 | public XIFieldTo5250Stream(XI5250Emulator aEmulator, OutputStream aOutStream, 49 | boolean onlyMDT) { 50 | ivEmulator = aEmulator; 51 | ivOut = aOutStream; 52 | ivOnlyMDT = onlyMDT; 53 | } 54 | 55 | public void write(XI5250Field aField, String aStr) 56 | throws IOException { 57 | if (ivOnlyMDT && !aField.isMDTOn()) 58 | return; 59 | 60 | XIEbcdicTranslator translator = ivEmulator.getTranslator(); 61 | 62 | // requires some special handling 63 | // see IBM 5250 function reference manual page 2-70 64 | if (aStr.length() > 0) { 65 | if (aField.isSignedNumeric()) { 66 | StringBuilder strBuf = new StringBuilder(aStr); 67 | int i; 68 | 69 | // find last digit char 70 | for (i = strBuf.length() - 1; 71 | (i >= 0) && !Character.isDigit(strBuf.charAt(i)); i--) 72 | ; 73 | 74 | // replace non digit chars between digit char with zeroes 75 | for (int j = i - 1; j >= 0; j--) 76 | if (!Character.isDigit(strBuf.charAt(j))) 77 | strBuf.setCharAt(j, '0'); 78 | 79 | if (strBuf.charAt(strBuf.length() - 1) == '-') { 80 | if (i >= 0) { 81 | byte xx = translator.toEBCDIC(strBuf.charAt(i)); 82 | xx &= 0x0F; 83 | xx |= 0xD0; 84 | strBuf.setCharAt(i, translator.toChar(xx)); 85 | aStr = new String(strBuf).substring(0, strBuf.length() - 1); 86 | } 87 | else 88 | aStr = ""; 89 | } 90 | else 91 | aStr = new String(strBuf); 92 | } 93 | } 94 | 95 | int i = aStr.length() - 1; 96 | 97 | if (ivOnlyMDT) { 98 | byte[] cBuf = {XI5250Emulator.ORD_SBA, 99 | (byte)(aField.getRow() + 1), 100 | (byte)(aField.getCol() + 1)}; 101 | 102 | ivOut.write(cBuf); 103 | 104 | // exclude trailing null chars 105 | for (; (i >= 0) && (aStr.charAt(i) == '\u0000'); i--) 106 | ; 107 | } 108 | 109 | byte[] strBuf = new byte[i + 1]; 110 | { 111 | int linearPos = ivEmulator.toLinearPos(aField.getCol(), aField.getRow()); 112 | int j; 113 | int len = Math.min(i + 1, aStr.length()); 114 | byte space = translator.toEBCDIC(' '); 115 | 116 | for (j = 0; j < len; j++) { 117 | char ch = aStr.charAt(j); 118 | if (ch == XI5250Emulator.ATTRIBUTE_PLACE_HOLDER) { 119 | ch = (char)ivEmulator.getAttr(ivEmulator.toColPos(linearPos + j), 120 | ivEmulator.toRowPos(linearPos + j)); 121 | strBuf[j] = (byte)ch; // leave attributes as is 122 | } 123 | else if (ch == '\u0000') { 124 | strBuf[j] = space; 125 | } 126 | else { 127 | strBuf[j] = translator.toEBCDIC(ch); 128 | } 129 | } 130 | // fill with space 131 | for (j = len; j < i + 1; j++) 132 | strBuf[j] = space; 133 | } 134 | 135 | if (i >= 0) { 136 | for (int j = 0; j < (i + 1); j++) { 137 | // convert nulls to EBCDIC spaces 138 | if (strBuf[j] == 0) 139 | strBuf[j] = 0x40; 140 | } 141 | 142 | ivOut.write(strBuf, 0, i + 1); 143 | } 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,maven,eclipse,intellij+all,intellij+iml,macos 3 | 4 | ### Eclipse ### 5 | 6 | .metadata 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | .recommenders 17 | 18 | # External tool builders 19 | .externalToolBuilders/ 20 | 21 | # Locally stored "Eclipse launch configurations" 22 | *.launch 23 | 24 | # PyDev specific (Python IDE for Eclipse) 25 | *.pydevproject 26 | 27 | # CDT-specific (C/C++ Development Tooling) 28 | .cproject 29 | 30 | # Java annotation processor (APT) 31 | .factorypath 32 | 33 | # PDT-specific (PHP Development Tools) 34 | .buildpath 35 | 36 | # sbteclipse plugin 37 | .target 38 | 39 | # Tern plugin 40 | .tern-project 41 | 42 | # TeXlipse plugin 43 | .texlipse 44 | 45 | # STS (Spring Tool Suite) 46 | .springBeans 47 | 48 | # Code Recommenders 49 | .recommenders/ 50 | 51 | # Scala IDE specific (Scala & Java development for Eclipse) 52 | .cache-main 53 | .scala_dependencies 54 | .worksheet 55 | 56 | ### Eclipse Patch ### 57 | # Eclipse Core 58 | .project 59 | 60 | # JDT-specific (Eclipse Java Development Tools) 61 | .classpath 62 | 63 | ### Intellij+all ### 64 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 65 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 66 | 67 | # User-specific stuff: 68 | .idea/**/workspace.xml 69 | .idea/**/tasks.xml 70 | .idea/dictionaries 71 | 72 | # Sensitive or high-churn files: 73 | .idea/**/dataSources/ 74 | .idea/**/dataSources.ids 75 | .idea/**/dataSources.xml 76 | .idea/**/dataSources.local.xml 77 | .idea/**/sqlDataSources.xml 78 | .idea/**/dynamic.xml 79 | .idea/**/uiDesigner.xml 80 | 81 | # Gradle: 82 | .idea/**/gradle.xml 83 | .idea/**/libraries 84 | 85 | # CMake 86 | cmake-build-debug/ 87 | 88 | # Mongo Explorer plugin: 89 | .idea/**/mongoSettings.xml 90 | 91 | ## File-based project format: 92 | *.iws 93 | 94 | ## Plugin-specific files: 95 | 96 | # IntelliJ 97 | /out/ 98 | 99 | # mpeltonen/sbt-idea plugin 100 | .idea_modules/ 101 | 102 | # JIRA plugin 103 | atlassian-ide-plugin.xml 104 | 105 | # Cursive Clojure plugin 106 | .idea/replstate.xml 107 | 108 | # Ruby plugin and RubyMine 109 | /.rakeTasks 110 | 111 | # Crashlytics plugin (for Android Studio and IntelliJ) 112 | com_crashlytics_export_strings.xml 113 | crashlytics.properties 114 | crashlytics-build.properties 115 | fabric.properties 116 | 117 | ### Intellij+all Patch ### 118 | # Ignores the whole idea folder 119 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 120 | 121 | .idea/ 122 | 123 | ### Intellij+iml ### 124 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 125 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 126 | 127 | # User-specific stuff: 128 | 129 | # Sensitive or high-churn files: 130 | 131 | # Gradle: 132 | 133 | # CMake 134 | 135 | # Mongo Explorer plugin: 136 | 137 | ## File-based project format: 138 | 139 | ## Plugin-specific files: 140 | 141 | # IntelliJ 142 | 143 | # mpeltonen/sbt-idea plugin 144 | 145 | # JIRA plugin 146 | 147 | # Cursive Clojure plugin 148 | 149 | # Ruby plugin and RubyMine 150 | 151 | # Crashlytics plugin (for Android Studio and IntelliJ) 152 | 153 | ### Intellij+iml Patch ### 154 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 155 | 156 | *.iml 157 | modules.xml 158 | .idea/misc.xml 159 | *.ipr 160 | 161 | ### Java ### 162 | # Compiled class file 163 | *.class 164 | 165 | # Log file 166 | *.log 167 | 168 | # BlueJ files 169 | *.ctxt 170 | 171 | # Mobile Tools for Java (J2ME) 172 | .mtj.tmp/ 173 | 174 | # Package Files # 175 | *.jar 176 | *.war 177 | *.ear 178 | *.zip 179 | *.tar.gz 180 | *.rar 181 | 182 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 183 | hs_err_pid* 184 | 185 | ### macOS ### 186 | *.DS_Store 187 | .AppleDouble 188 | .LSOverride 189 | 190 | # Icon must end with two \r 191 | Icon 192 | 193 | # Thumbnails 194 | ._* 195 | 196 | # Files that might appear in the root of a volume 197 | .DocumentRevisions-V100 198 | .fseventsd 199 | .Spotlight-V100 200 | .TemporaryItems 201 | .Trashes 202 | .VolumeIcon.icns 203 | .com.apple.timemachine.donotpresent 204 | 205 | # Directories potentially created on remote AFP share 206 | .AppleDB 207 | .AppleDesktop 208 | Network Trash Folder 209 | Temporary Items 210 | .apdisk 211 | 212 | ### Maven ### 213 | target/ 214 | pom.xml.tag 215 | pom.xml.releaseBackup 216 | pom.xml.versionsBackup 217 | pom.xml.next 218 | release.properties 219 | dependency-reduced-pom.xml 220 | buildNumber.properties 221 | .mvn/timing.properties 222 | 223 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 224 | !/.mvn/wrapper/maven-wrapper.jar 225 | 226 | 227 | # End of https://www.gitignore.io/api/java,maven,eclipse,intellij+all,intellij+iml,macos 228 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/util/XIUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | !!V 07/07/98 rel. 1.07 - creation. 20 | 02/05/00 rel. 1.15b- Jdk 1.3rc2. 21 | */ 22 | 23 | package net.infordata.em.util; 24 | 25 | import java.applet.Applet; 26 | import java.awt.Component; 27 | import java.awt.Frame; 28 | import java.awt.Image; 29 | import java.awt.Toolkit; 30 | import java.awt.Window; 31 | import java.io.BufferedInputStream; 32 | import java.io.ByteArrayOutputStream; 33 | import java.io.IOException; 34 | import java.io.InputStream; 35 | import java.lang.reflect.Method; 36 | 37 | public class XIUtil { 38 | 39 | 40 | public static final boolean is1dot2 = is1dot2(); 41 | public static final boolean is1dot3 = is1dot3(); 42 | 43 | private static boolean is1dot2() { 44 | try { 45 | // Test if method introduced in 1.2 is available. 46 | Method m = Class.class.getMethod("getProtectionDomain"); 47 | return (m != null); 48 | } 49 | catch (NoSuchMethodException e) { 50 | return false; 51 | } 52 | } 53 | 54 | private static boolean is1dot3() { 55 | try { 56 | // Test if method introduced in 1.3 is available. 57 | Method m = Runtime.class.getMethod("addShutdownHook", 58 | new Class[] {Thread.class}); 59 | return (m != null); 60 | } 61 | catch (NoSuchMethodException e) { 62 | return false; 63 | } 64 | } 65 | 66 | private XIUtil() { 67 | } 68 | 69 | public static final Frame getFrame(Component aComponent) { 70 | Component comp = aComponent; 71 | while (comp != null && !(comp instanceof Frame)) 72 | comp = comp.getParent(); 73 | return (Frame)comp; 74 | } 75 | 76 | public static final Window getWindow(Component aComponent) { 77 | Component comp = aComponent; 78 | while (comp != null && !(comp instanceof Window)) 79 | comp = comp.getParent(); 80 | return (Window)comp; 81 | } 82 | 83 | public static final Applet getApplet(Component aComponent) { 84 | Component comp = aComponent; 85 | while (comp != null && !(comp instanceof Applet)) 86 | comp = comp.getParent(); 87 | return (Applet)comp; 88 | } 89 | 90 | public static Image createImage(final Class baseClass, 91 | final String gifFile) { 92 | byte[] buffer; 93 | try { 94 | /* Copy resource into a byte array. This is 95 | * necessary because several browsers consider 96 | * Class.getResource a security risk because it 97 | * can be used to load additional classes. 98 | * Class.getResourceAsStream just returns raw 99 | * bytes, which we can convert to an image. 100 | */ 101 | InputStream resource = baseClass.getResourceAsStream(gifFile); 102 | if (resource == null) { 103 | throw new IllegalArgumentException(baseClass.getName() + "/" + 104 | gifFile + " not found."); 105 | } 106 | BufferedInputStream in = new BufferedInputStream(resource); 107 | ByteArrayOutputStream out = new ByteArrayOutputStream(1024); 108 | buffer = new byte[1024]; 109 | int n; 110 | while ((n = in.read(buffer)) > 0) { 111 | out.write(buffer, 0, n); 112 | } 113 | in.close(); 114 | out.flush(); 115 | 116 | buffer = out.toByteArray(); 117 | if (buffer.length == 0) { 118 | throw new IllegalStateException("warning: " + gifFile + 119 | " is zero-length"); 120 | } 121 | } 122 | catch (IOException ex) { 123 | throw new IllegalStateException(ex.toString()); 124 | } 125 | 126 | return Toolkit.getDefaultToolkit().createImage(buffer); 127 | } 128 | 129 | public static char getMnemonic(String str) { 130 | char ch; 131 | int state = 0; 132 | for (int i = 0; i < str.length(); i++) { 133 | ch = str.charAt(i); 134 | switch (state) { 135 | case 0: 136 | if (ch == '&') 137 | state = 1; 138 | break; 139 | case 1: 140 | if (ch != '&') 141 | return ch; 142 | state = 0; 143 | break; 144 | } 145 | } 146 | return '\u0000'; 147 | } 148 | 149 | public static String removeMnemonics(String str) { 150 | StringBuilder sb = new StringBuilder(str.length()); 151 | char ch; 152 | int state = 0; 153 | for (int i = 0; i < str.length(); i++) { 154 | ch = str.charAt(i); 155 | switch (state) { 156 | case 0: 157 | if (ch == '&') 158 | state = 1; 159 | else 160 | sb.append(ch); 161 | break; 162 | case 1: 163 | sb.append(ch); 164 | state = 0; 165 | break; 166 | } 167 | } 168 | return sb.toString(); 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250EmulatorCtrl.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | !!V 09/07/98 rel. 1.10 - creation. 20 | */ 21 | 22 | package net.infordata.em.tn5250; 23 | 24 | import java.util.ResourceBundle; 25 | 26 | import javax.swing.JOptionPane; 27 | 28 | import net.infordata.em.crt5250.XI5250Crt; 29 | import net.infordata.em.crt5250.XI5250CrtCtrl; 30 | import net.infordata.em.crt5250.XI5250CrtFrame; 31 | 32 | /** 33 | * Handles common commands shared by XI5250Frame and XI5250Applet. 34 | */ 35 | public class XI5250EmulatorCtrl extends XI5250CrtCtrl { 36 | 37 | // images 38 | private static XIImagesBdl cvImagesBdl = 39 | net.infordata.em.tn5250.XIImagesBdl.getImagesBdl(); 40 | 41 | private static ResourceBundle cvRes = 42 | ResourceBundle.getBundle("net.infordata.em.tn5250.resources.Res"); 43 | 44 | public static final String CONNECT_CMD = "CONNECT_CMD"; 45 | public static final String DISCONNECT_CMD = "DISCONNECT_CMD"; 46 | 47 | public static final String ABOUT_CMD = "ABOUT_CMD"; 48 | 49 | public static final String SNAPSHOT_CMD = "SNAPSHOT_CMD"; 50 | 51 | private int ivSnapShotCount = 0; 52 | 53 | public XI5250EmulatorCtrl(XI5250Emulator aCrt) { 54 | super(aCrt); 55 | 56 | getEmulator().addEmulatorListener(new EmulatorListener()); 57 | 58 | // Connect command 59 | getCommandMgr().enableCommand( 60 | CONNECT_CMD, !getEmulator().isActive()); 61 | getCommandMgr().setCommand(CONNECT_CMD, this::processConnectCmd); 62 | 63 | // Disconnect command 64 | getCommandMgr().enableCommand( 65 | DISCONNECT_CMD, getEmulator().isActive()); 66 | getCommandMgr().setCommand(DISCONNECT_CMD, this::processDisconnectCmd); 67 | 68 | // About command 69 | getCommandMgr().setCommand(ABOUT_CMD, this::processAboutCmd); 70 | 71 | // Snapshot command 72 | getCommandMgr().setCommand(SNAPSHOT_CMD, this::processSnapShotCmd); 73 | } 74 | 75 | public final XI5250Emulator getEmulator() { 76 | return (XI5250Emulator)getCrt(); 77 | } 78 | 79 | protected void processConnectCmd() { 80 | if (!getEmulator().isActive()) { 81 | Object ret = JOptionPane.showInputDialog( 82 | getEmulator(), 83 | cvRes.getString("TXT_HostNameInput"), 84 | "", JOptionPane.QUESTION_MESSAGE, null, 85 | null, getEmulator().getHost()); 86 | if (ret == null) 87 | return; 88 | getEmulator().setHost((String)ret); 89 | } 90 | getEmulator().setActive(true); 91 | } 92 | 93 | protected void processDisconnectCmd() { 94 | if (getEmulator().isActive()) { 95 | int ret = JOptionPane.showConfirmDialog( 96 | getEmulator(), 97 | cvRes.getString("TXT_ConfirmDisconnect"), 98 | "", JOptionPane.YES_NO_OPTION); 99 | if (ret == JOptionPane.NO_OPTION) 100 | return; 101 | } 102 | getEmulator().setActive(false); 103 | } 104 | 105 | protected void processAboutCmd() { 106 | JOptionPane.showMessageDialog(getEmulator(), 107 | "Version " + XI5250Emulator.VERSION + "\n" + 108 | "\n" + 109 | "Infordata S.p.A.\n" + 110 | "http://xtn5250.sourceforge.net", 111 | "About", 112 | JOptionPane.INFORMATION_MESSAGE, 113 | cvImagesBdl.getIcon("Logo")); 114 | } 115 | 116 | protected void processSnapShotCmd() { 117 | XI5250Crt clone = getEmulator().getStaticClone(); 118 | String title = "Snap-shot " + getEmulator().getHost() + " #" + 119 | (++ivSnapShotCount); 120 | XI5250CrtFrame frm = new XI5250CrtFrame(title, clone); 121 | frm.setBounds(0, 0, 728, 512); 122 | frm.centerOnScreen(); 123 | frm.setVisible(true); 124 | } 125 | 126 | /** 127 | * Usata per sincronizzare i comandi con lo stato dell' emulator. 128 | */ 129 | class EmulatorListener extends XI5250EmulatorAdapter { 130 | 131 | protected void enableCmd() { 132 | getCommandMgr().enableCommand( 133 | CONNECT_CMD, !getEmulator().isActive()); 134 | getCommandMgr().enableCommand( 135 | DISCONNECT_CMD, getEmulator().isActive()); 136 | } 137 | 138 | @Override 139 | public void connecting(XI5250EmulatorEvent e) { 140 | enableCmd(); 141 | } 142 | 143 | @Override 144 | public void connected(XI5250EmulatorEvent e) { 145 | enableCmd(); 146 | } 147 | 148 | @Override 149 | public void disconnected(XI5250EmulatorEvent e) { 150 | enableCmd(); 151 | } 152 | 153 | @Override 154 | public void stateChanged(XI5250EmulatorEvent e) { 155 | } 156 | 157 | } 158 | 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250CmdList.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | *** 19 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 20 | */ 21 | 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | import java.util.logging.Level; 30 | import java.util.logging.Logger; 31 | 32 | import net.infordata.em.tnprot.XITelnet; 33 | 34 | /** 35 | * 5250 Commands list (Works like a macro command). 36 | * 37 | * @author Valentino Proietti - Infordata S.p.A. 38 | */ 39 | public class XI5250CmdList extends XI5250Cmd { 40 | 41 | private static final Logger LOGGER = Logger.getLogger(XI5250CmdList.class.getName()); 42 | 43 | private static Class[] cv5250CmdClasses = new Class[256]; 44 | 45 | protected List ivCmdVect; 46 | 47 | // flags used across command execution 48 | protected boolean ivICOrderExecuted; 49 | 50 | 51 | static { 52 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_READ_IMMEDIATE)] = 53 | XIReadImmediateCmd.class; 54 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_READ_FIELDS)] = 55 | XIReadFieldsCmd.class; 56 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_READ_MDT_FIELDS)] = 57 | XIReadMdtFieldsCmd.class; 58 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_READ_SCREEN)] = 59 | XIReadScreenCmd.class; 60 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_SAVE_SCREEN)] = 61 | XISaveScreenCmd.class; 62 | 63 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_CLEAR_FMT_TABLE)] = 64 | XIClearFmtTableCmd.class; 65 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_CLEAR_UNIT)] = 66 | XIClearUnitCmd.class; 67 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_CLEAR_UNIT_ALT)] = 68 | XIClearUnitAltCmd.class; 69 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_RESTORE_SCREEN)] = 70 | XIRestoreScreenCmd.class; 71 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_ROLL)] = 72 | XIRollCmd.class; 73 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_WRITE_ERROR_CODE)] = 74 | XIWriteErrorCodeCmd.class; 75 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_WRITE_TO_DISPLAY)] = 76 | XIWriteToDisplayCmd.class; 77 | 78 | cv5250CmdClasses[XITelnet.toInt(XI5250Emulator.CMD_QUERY_DEVICE)] = 79 | XIQueryCmd.class; 80 | } 81 | 82 | protected XI5250CmdList(XI5250Emulator aEmulator) { 83 | init(aEmulator); 84 | } 85 | 86 | /** 87 | * Parses the command list from the given input stream. 88 | * 89 | * @param inStream stream to read from. 90 | * @throws IOException raised if there is some problem in communication with server. 91 | * @throws XI5250Exception raised if command parameters are wrong. 92 | */ 93 | @Override 94 | protected void readFrom5250Stream(InputStream inStream) 95 | throws IOException, XI5250Exception { 96 | int bb; 97 | XI5250Cmd cmd; 98 | ivCmdVect = new ArrayList<>(100); 99 | 100 | if (LOGGER.isLoggable(Level.FINER)) { 101 | LOGGER.finer("START OF COMMANDS LIST"); 102 | } 103 | 104 | // jump until ESC is found 105 | while ((bb = inStream.read()) != -1 && (byte) bb != XI5250Emulator.ESC) { 106 | } 107 | 108 | // start from 1 because ESC is already read 109 | for (int i = 1; (bb = inStream.read()) != -1; i++) { 110 | switch (i % 2) { 111 | case 0: 112 | if ((byte) bb != XI5250Emulator.ESC) { 113 | throw new XI5250Exception("Malformed 5250 packet", XI5250Emulator.ERR_INVALID_COMMAND); 114 | } 115 | break; 116 | case 1: 117 | cmd = createCmdInstance(XITelnet.toInt((byte) bb)); 118 | 119 | if (cmd != null) { 120 | cmd.init(ivEmulator); 121 | cmd.readFrom5250Stream(inStream); 122 | 123 | if (LOGGER.isLoggable(Level.FINER)) { 124 | LOGGER.finer("" + cmd); 125 | } 126 | 127 | ivCmdVect.add(cmd); 128 | } else { 129 | throw new XI5250Exception("Command not supported : 0x" + 130 | XITelnet.toHex((byte) bb), 131 | XI5250Emulator.ERR_INVALID_COMMAND); 132 | } 133 | break; 134 | } 135 | } 136 | } 137 | 138 | @Override 139 | protected void execute() { 140 | for (XI5250Cmd anIvCmdVect : ivCmdVect) { 141 | anIvCmdVect.execute(); 142 | } 143 | } 144 | 145 | /** 146 | * Creates the 5250 command related to the given 5250 command id. 147 | * 148 | * @param aCmd byte identification for the command. 149 | * @return created command. 150 | */ 151 | protected XI5250Cmd createCmdInstance(int aCmd) { 152 | Class cls; 153 | 154 | cls = cv5250CmdClasses[aCmd]; 155 | if (cls != null) { 156 | try { 157 | return (XI5250Cmd) cls.newInstance(); 158 | } catch (InstantiationException | IllegalAccessException e) { 159 | throw new RuntimeException(e); 160 | } 161 | } else { 162 | return null; 163 | } 164 | } 165 | 166 | @Override 167 | public String toString() { 168 | return super.toString() + ivCmdVect.toString(); 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/Test.java: -------------------------------------------------------------------------------- 1 | package net.infordata.em.tn5250ext; 2 | import java.awt.Font; 3 | import java.awt.Insets; 4 | import java.awt.SystemColor; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.awt.event.KeyEvent; 8 | import java.awt.event.WindowAdapter; 9 | import java.awt.event.WindowEvent; 10 | import java.util.ArrayList; 11 | import java.util.Iterator; 12 | import java.util.List; 13 | 14 | import javax.swing.JButton; 15 | import javax.swing.JMenuItem; 16 | import javax.swing.JPopupMenu; 17 | 18 | import net.infordata.em.crt.XICrt; 19 | import net.infordata.em.crt5250.XI5250Field; 20 | import net.infordata.em.tn5250.XI5250Emulator; 21 | import net.infordata.em.tn5250.XI5250Frame; 22 | 23 | public class Test { 24 | 25 | private Test() { } 26 | 27 | public static void main(String[] argv) { 28 | XI5250EmulatorExt em = new XI5250EmulatorExt(); 29 | em.setTerminalType("IBM-3477-FC"); 30 | em.setKeyboardQueue(true); 31 | 32 | em.setHintOnActiveField(true); 33 | XI5250PanelsDispatcher disp = new XI5250SimplePanelsDispatcher(em); 34 | new TestHandler(disp); 35 | 36 | if (argv.length >= 1) { 37 | em.setHost(argv[0]); 38 | em.setActive(true); 39 | } 40 | 41 | XI5250Frame frm = new XI5250Frame("tn5250ext" + " " + 42 | XI5250Emulator.VERSION, em); 43 | 44 | //3D FX 45 | if (argv.length >= 2 && "3DFX".equals(argv[1].toUpperCase())) { 46 | em.setDefFieldsBorderStyle(XI5250Field.LOWERED_BORDER); 47 | em.setDefBackground(SystemColor.control); 48 | } 49 | 50 | frm.addWindowListener(new WindowAdapter() { 51 | @Override 52 | public void windowClosed(WindowEvent e) { 53 | System.exit(0); 54 | } 55 | }); 56 | frm.setBounds(0, 0, 570, 510); 57 | frm.centerOnScreen(); 58 | frm.setVisible(true); 59 | } 60 | 61 | private static class TestHandler extends XI5250PanelHandler { 62 | 63 | private FontsCache ivFontsCache; 64 | private List ivButtons = new ArrayList(); 65 | 66 | public TestHandler(XI5250PanelsDispatcher disp) { 67 | super(disp, ""); 68 | } 69 | 70 | @Override 71 | protected void sizeChanged() { 72 | super.sizeChanged(); 73 | final XI5250EmulatorExt em = getEmulator(); 74 | for (JButton btn : ivButtons) { 75 | btn.setFont(ivFontsCache.getFont( 76 | Math.max(1, em.getFont().getSize() - 2))); 77 | } 78 | } 79 | 80 | @Override 81 | protected boolean detailedTest() { 82 | return true; 83 | } 84 | 85 | @Override 86 | protected void start() { 87 | ivButtons.clear(); 88 | final XI5250EmulatorExt em = getEmulator(); 89 | final int crtWidth = em.getCrtSize().width; 90 | for (Iterator e = getFields().iterator(); e.hasNext(); ) { 91 | final XI5250Field field = e.next(); 92 | boolean isButton = false; 93 | if (field.isIOOnly()) { 94 | final int col = field.getCol() - 1; 95 | final int row = field.getRow(); 96 | if (col >= 0 && 97 | "<".equals(em.getString(col, row, 1))) { 98 | final int len; 99 | { 100 | final int fieldEnd = col + field.getLength(); 101 | String str = em.getString(fieldEnd + 1, row, crtWidth - fieldEnd); 102 | int idx = str.indexOf(">"); 103 | len = (idx < 0) ? -1 : idx + 2 + 1; 104 | } 105 | if (len > 0) { 106 | isButton = true; 107 | final String txt = em.getString(col + 1, row, len - 2); 108 | JButton btn = new JButton(txt); 109 | if (ivFontsCache == null) 110 | ivFontsCache = new FontsCache(btn.getFont()); 111 | btn.setFont(ivFontsCache.getFont(Math.max(1, em.getFont().getSize() - 2))); 112 | btn.setMargin(new Insets(2, 2, 2, 2)); 113 | btn.setFocusable(false); 114 | btn.addActionListener(new ActionListener() { 115 | public void actionPerformed(ActionEvent e) { 116 | em.setCursorPos(field.getCol(), field.getRow()); 117 | em.requestFocusInWindow(); 118 | em.processRawKeyEvent(new KeyEvent(em, KeyEvent.KEY_PRESSED, 0, 119 | 0, KeyEvent.VK_ENTER, (char)KeyEvent.VK_ENTER)); 120 | } 121 | }); 122 | ivButtons.add(btn); 123 | new XI5250PanelConnection(this, 124 | btn, col, row, len, 1); 125 | } 126 | } 127 | } 128 | 129 | if (!isButton) { 130 | setFieldHint(field, new XIHint(field.toString())); 131 | 132 | JPopupMenu pm = new JPopupMenu(); 133 | pm.add(new JMenuItem(field.toString())); 134 | setFieldPopupMenu(field, pm); 135 | 136 | JButton btn = new JButton(); 137 | new XI5250FieldConnection(this, field, btn); 138 | } 139 | 140 | new XI5250PanelConnection(this, 141 | new JButton("+-"), 142 | 15, 15, 10, 6); 143 | } 144 | } 145 | 146 | @Override 147 | protected void stop() { 148 | ivButtons.clear(); 149 | } 150 | 151 | } 152 | 153 | private static class FontsCache { 154 | 155 | private Font[] ivFonts = new Font[XICrt.MAX_FONT_SIZE - XICrt.MIN_FONT_SIZE + 1]; 156 | private Font ivFont; 157 | 158 | public FontsCache(Font font) { 159 | ivFont = font; 160 | } 161 | 162 | public Font getFont(int size) { 163 | if (ivFonts[size - XICrt.MIN_FONT_SIZE] == null) { 164 | ivFonts[size - XICrt.MIN_FONT_SIZE] = 165 | new Font(ivFont.getName(), 166 | ivFont.getStyle(), 167 | size); 168 | } 169 | return ivFonts[size - XICrt.MIN_FONT_SIZE]; 170 | } 171 | 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250ext/XI5250SimplePanelsDispatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 06/08/97 rel. 1.00a- bug fix. 19 | 06/10/97 rel. 1.05b- newPanelReceived event sended also in the PRE_HELP state. 20 | *** 21 | 10/07/98 rel. _.___- Swing, JBuilder2 e VSS. 22 | */ 23 | 24 | package net.infordata.em.tn5250ext; 25 | 26 | import java.util.ArrayList; 27 | import java.util.HashMap; 28 | import java.util.StringTokenizer; 29 | import java.util.logging.Level; 30 | import java.util.logging.Logger; 31 | 32 | import net.infordata.em.tn5250.XI5250Emulator; 33 | 34 | /** 35 | * Maintains a set of XI5250PanelHandler and activates them when the related 5250 screen (or panel) 36 | * is received. 37 | * 38 | * @author Valentino Proietti - Infordata S.p.A. 39 | */ 40 | public class XI5250SimplePanelsDispatcher extends XI5250PanelsDispatcher { 41 | 42 | private static final Logger LOGGER = Logger 43 | .getLogger(XI5250SimplePanelsDispatcher.class.getName()); 44 | 45 | transient private static String DELIMITERS; 46 | 47 | /** 48 | * Contains relations between XI5250PanelHandler and a tokenized version of the related 5250 49 | * screen first line. It really contains Vectors of XI5250PanelHandler (one to many relation) 50 | */ 51 | transient private HashMap> ivPanels; 52 | 53 | static { 54 | DELIMITERS = ""; 55 | for (int i = 0; i <= 32; i++) { 56 | DELIMITERS += (char) i; 57 | } 58 | } 59 | 60 | /** 61 | * Creates a XI5250SimplePanelsDispatcher. 62 | */ 63 | public XI5250SimplePanelsDispatcher() { 64 | } 65 | 66 | /** 67 | * Creates a XI5250SimplePanelsDispatcher to handle panels of the given XI5250Emulator instance. 68 | * 69 | * @param aEmulator emulator to set on the panel dispatcher 70 | */ 71 | public XI5250SimplePanelsDispatcher(XI5250EmulatorExt aEmulator) { 72 | super(aEmulator); 73 | } 74 | 75 | private static String calcKey(String str, int excludeTokens) { 76 | String res = ""; 77 | StringTokenizer st = new StringTokenizer(str, DELIMITERS); 78 | int n = Math.max(0, st.countTokens() - excludeTokens); 79 | 80 | for (int i = n - 1; i >= 0; i--) { 81 | res += " " + st.nextToken(); 82 | } 83 | 84 | return res; 85 | } 86 | 87 | /** 88 | * Adds the given XI5250PanelHandler instance to the list of panel handlers waiting to be 89 | * activated. 90 | * 91 | * @param aPanel panel to add 92 | */ 93 | @Override 94 | public synchronized void addPanelHandler(XI5250PanelHandler aPanel) { 95 | if (ivPanels == null) { 96 | ivPanels = new HashMap<>(); 97 | } 98 | 99 | String key = calcKey(aPanel.getTitle(), 0); 100 | 101 | if (LOGGER.isLoggable(Level.FINER)) { 102 | LOGGER.finer("addPanelHandler: [" + key + "] " + aPanel); 103 | } 104 | 105 | ArrayList vt = ivPanels 106 | .computeIfAbsent(key, k -> new ArrayList<>(10)); 107 | 108 | if (!vt.contains(aPanel)) { 109 | vt.add(aPanel); 110 | } 111 | } 112 | 113 | /** 114 | * Removes the panel handler. 115 | * 116 | * @param aPanel panel to remove 117 | */ 118 | @Override 119 | public synchronized void removePanelHandler(XI5250PanelHandler aPanel) { 120 | if (ivPanels == null) { 121 | return; 122 | } 123 | 124 | String key = calcKey(aPanel.getTitle(), 0); 125 | 126 | if (LOGGER.isLoggable(Level.FINER)) { 127 | LOGGER.finer("removePanelHandler: [" + 128 | key + "] " + aPanel); 129 | } 130 | 131 | ArrayList vt = ivPanels.get(key); 132 | 133 | if (vt == null) { 134 | return; 135 | } 136 | 137 | vt.remove(aPanel); 138 | 139 | if (vt.size() <= 0) { 140 | ivPanels.remove(key); 141 | } 142 | } 143 | 144 | 145 | /** 146 | * Searches the XI5250PanelHandler instance related to the current 5250 panel. Uses a two step 147 | * search. First step is based on the contents of the first line present on screen then the 148 | * detailedTest() method provided by XI5250PanelHandler is used. 149 | * 150 | * @return panel associated to the current panel. 151 | * @see XI5250PanelHandler#detailedTest 152 | */ 153 | @Override 154 | protected synchronized XI5250PanelHandler getCurrentPanelHandler() { 155 | final XI5250Emulator em = getEmulator(); 156 | String title = em.getString().substring(0, em.getCrtSize().width); 157 | 158 | int j = 0; 159 | String key; 160 | ArrayList vt; 161 | 162 | // first step 163 | // find the XI5250PanelHandler vector using as key the tokenized title 164 | // minus j ending tokens 165 | do { 166 | key = calcKey(title, j++); 167 | vt = ivPanels.get(key); 168 | 169 | if (LOGGER.isLoggable(Level.FINER)) { 170 | LOGGER.finer("try [" + key + "] " + 171 | ((vt != null) ? "found" : "next")); 172 | } 173 | } 174 | while (vt == null && key != null && key.length() > 0); 175 | 176 | if (vt == null) { 177 | return null; 178 | } 179 | 180 | XI5250PanelHandler panelHndl; 181 | 182 | // second step 183 | for (int i = vt.size() - 1; i >= 0; i--) { 184 | panelHndl = vt.get(i); 185 | if (panelHndl.detailedTest()) { 186 | // increase priority 187 | vt.remove(panelHndl); 188 | vt.add(panelHndl); 189 | 190 | return panelHndl; 191 | } 192 | } 193 | 194 | return null; 195 | } 196 | 197 | } 198 | -------------------------------------------------------------------------------- /src/main/java/net/infordata/em/tn5250/XI5250OrdList.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2007 Infordata S.p.A. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /* 18 | !!V 15/07/97 rel. 1.02c- XIDataOrd includes 0x1F char. 19 | *** 20 | 30/06/98 rel. _.___- Swing, JBuilder2 e VSS. 21 | */ 22 | 23 | package net.infordata.em.tn5250; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.util.ArrayList; 28 | import java.util.Arrays; 29 | import java.util.List; 30 | import java.util.logging.Level; 31 | import java.util.logging.Logger; 32 | 33 | import net.infordata.em.tnprot.XITelnet; 34 | 35 | /** 36 | * 5250 Orders list. 37 | * @author Valentino Proietti - Infordata S.p.A. 38 | */ 39 | public class XI5250OrdList extends XI5250Ord { 40 | 41 | private static final Logger LOGGER = Logger.getLogger(XI5250OrdList.class.getName()); 42 | 43 | private static Class[] cv5250OrdClasses = new Class[256]; 44 | 45 | protected List ivOrdVect; 46 | 47 | protected boolean[] ivOrdPresent = new boolean[256]; 48 | 49 | static { 50 | cv5250OrdClasses[XI5250Emulator.ORD_IC] = XIICOrd.class; 51 | cv5250OrdClasses[XI5250Emulator.ORD_RA] = XIRAOrd.class; 52 | cv5250OrdClasses[XI5250Emulator.ORD_SBA] = XISBAOrd.class; 53 | cv5250OrdClasses[XI5250Emulator.ORD_SF] = XISFOrd.class; 54 | cv5250OrdClasses[XI5250Emulator.ORD_SOH] = XISOHOrd.class; 55 | cv5250OrdClasses[XI5250Emulator.ORD_MC] = XIMCOrd.class; 56 | cv5250OrdClasses[XI5250Emulator.ORD_EA] = XIEAOrd.class; 57 | cv5250OrdClasses[XI5250Emulator.ORD_TD] = XITDOrd.class; 58 | cv5250OrdClasses[XI5250Emulator.ORD_WEA] = XIWEAOrd.class; 59 | cv5250OrdClasses[XI5250Emulator.ORD_WDSF] = XIWdsfOrd.class; 60 | } 61 | 62 | protected XI5250OrdList(XI5250Emulator aEmulator) { 63 | init(aEmulator); 64 | } 65 | 66 | public boolean isOrderPresent(byte aOrder) { 67 | return ivOrdPresent[aOrder]; 68 | } 69 | 70 | /** 71 | * @param inStream the stream from where to read the order list from. 72 | * @throws XI5250Exception raised if order parameters are wrong. 73 | * @throws IOException raised when there is an input/output problem. 74 | */ 75 | @Override 76 | protected void readFrom5250Stream(InputStream inStream) 77 | throws IOException, XI5250Exception { 78 | 79 | int bb; 80 | XI5250Ord ord; 81 | ivOrdVect = new ArrayList<>(100); 82 | 83 | if (LOGGER.isLoggable(Level.FINER)) 84 | LOGGER.finer(" START OF ORDERS LIST"); 85 | 86 | while(true) { 87 | inStream.mark(1); 88 | if ((bb = inStream.read()) == -1) 89 | break; 90 | 91 | if ((byte)bb == XI5250Emulator.ESC) { 92 | inStream.reset(); 93 | break; 94 | } 95 | 96 | if (XIDataOrd.isDataCharacter(bb)) { 97 | inStream.reset(); // need it (it is also the color attribute) 98 | if (ivEmulator.isStrPcCmdEnabled()) { 99 | inStream.mark(XI5250Emulator.STRPCCMD.length); 100 | byte[] lhbb = new byte[XI5250Emulator.STRPCCMD.length]; 101 | int sz = inStream.read(lhbb); 102 | if (sz == XI5250Emulator.STRPCCMD.length) { 103 | if (Arrays.equals(lhbb, XI5250Emulator.STRPCCMD)) { 104 | ivEmulator.receivedStrPcCmd(); 105 | } 106 | else if (Arrays.equals(lhbb, XI5250Emulator.ENDSTRPCCMD)) { 107 | ivEmulator.receivedEndStrPcCmd(); 108 | } 109 | else { 110 | inStream.reset(); 111 | } 112 | } 113 | else { 114 | inStream.reset(); 115 | } 116 | } 117 | } 118 | else 119 | ivOrdPresent[bb] = true; // remember orders present 120 | 121 | try { 122 | ord = createOrdInstance(bb); 123 | } 124 | catch (Exception ex) { 125 | throw new RuntimeException(ex); 126 | } 127 | 128 | if (ord != null) { 129 | ord.init(ivEmulator); 130 | ord.readFrom5250Stream(inStream); 131 | 132 | if (LOGGER.isLoggable(Level.FINER)) 133 | LOGGER.finer(" " + ord); 134 | 135 | ivOrdVect.add(ord); 136 | } 137 | else { 138 | if (LOGGER.isLoggable(Level.FINE)) { 139 | LOGGER.fine("Order not supported : 0x" + XITelnet.toHex((byte)bb)); 140 | for (int ii = 0; ii < ivOrdVect.size(); ii++) { 141 | LOGGER.fine("Prev. order[" + ii + "]: " + ivOrdVect.get(ii)); 142 | } 143 | byte[] buf = new byte[10]; 144 | int count = inStream.read(buf); 145 | LOGGER.fine("Next " + count + " bytes: " + XITelnet.toHex(buf, count)); 146 | } 147 | throw new XI5250Exception("Order not supported : 0x" + XITelnet.toHex((byte)bb), 148 | XI5250Emulator.ERR_INVALID_COMMAND); 149 | } 150 | } 151 | } 152 | 153 | @Override 154 | protected void execute() { 155 | for (XI5250Ord anIvOrdVect : ivOrdVect) { 156 | anIvOrdVect.execute(); 157 | } 158 | } 159 | 160 | /** 161 | * Creates the 5250 order instance related to the given 5250 order id. 162 | * @param aOrd order id to create 163 | * @return created order 164 | * @throws IllegalAccessException . 165 | * @throws InstantiationException . 166 | */ 167 | public XI5250Ord createOrdInstance(int aOrd) 168 | throws IllegalAccessException, InstantiationException { 169 | 170 | Class cls; 171 | 172 | if (XIDataOrd.isDataCharacter(aOrd)) 173 | cls = XIDataOrd.class; 174 | else 175 | cls = cv5250OrdClasses[aOrd]; 176 | 177 | if (cls != null) 178 | return (XI5250Ord)cls.newInstance(); 179 | else 180 | return null; 181 | } 182 | 183 | @Override 184 | public String toString() { 185 | return super.toString() + ivOrdVect.toString(); 186 | } 187 | 188 | } 189 | --------------------------------------------------------------------------------