Skip to content

Commit

Permalink
tabulated input improved to behave as a tabulator should
Browse files Browse the repository at this point in the history
Tabulator input has suffered some modifications in order to match behaves with a terminal tabulator.
For instance, when setting a zero offset and the current cursor position lacks field, the operation is canceled.
In another case, if the current cursor position does not contain a field, but we've got an offset bigger than zero, it will lookup for the field to positions above.
  • Loading branch information
Baraujo25 committed May 11, 2020
1 parent 28aad20 commit 2e44b8d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To use the emulator as maven dependency include in `pom.xml`:
<dependency>
<groupId>com.github.blazemeter</groupId>
<artifactId>xtn5250</artifactId>
<version>1.20</version>
<version>3.2.1</version>
</dependency>
...
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>xtn5250</artifactId>
<!-- This version has no relation to the released version since the release version is extracted
from git tag by Travis -->
<version>0.1-SNAPSHOT</version>
<version>3.2.2-SNAPSHOT</version>

<name>${project.artifactId}</name>
<description>This is a fork of https://sourceforge.net/projects/xtn5250/</description>
Expand Down Expand Up @@ -71,7 +71,7 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
<scope>test</scope>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
14 changes: 9 additions & 5 deletions src/main/java/net/infordata/em/TerminalClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.infordata.em;

import com.google.common.annotations.VisibleForTesting;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -89,7 +90,8 @@ public void setFieldTextByCoord(int row, int column, String text) {
updateCursorPosition(text, column - 1, row - 1);
}

private void updateCursorPosition(String text, int col, int row) {
@VisibleForTesting
public void updateCursorPosition(String text, int col, int row) {
emulator.setCursorPos((col + text.length()) % emulator.getCrtSize().width,
row + (col + text.length()) / emulator.getCrtSize().width);
}
Expand All @@ -107,15 +109,17 @@ public void setFieldTextByTabulator(int tabs, String text) {
int row = emulator.getCursorRow();
int col = emulator.getCursorCol();
XI5250Field field = emulator.getFieldFromPos(col, row);
for (int i = 0; i < tabs; i++) {
for (int i = tabs; i > 0; i--) {
field = emulator.getNextFieldFromPos(col, row);
row = field.getRow();
col = field.getCol();
}
if (field==null){
throw new NoSuchElementException("No field found");
if (field == null) {
throw new NoSuchElementException("No field found ");
}
field.setString(text);

String str = field.getTrimmedString() + text;
field.setString(str);
updateCursorPosition(text, field.getCol(), field.getRow());
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/infordata/em/crt5250/XI5250Crt.java
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,7 @@ protected void processMouseEvent(MouseEvent e) {
}
ivMousePressed = true;
// sets the start dragging row and col
ivStartDragging = new Point(assureColIn(e.getX() / getCharSize().width),
assureRowIn(e.getY() / getCharSize().height));
setIvStartDragging(e);
break;
case MouseEvent.MOUSE_RELEASED:
if (!ivMousePressed) {
Expand Down Expand Up @@ -782,6 +781,15 @@ protected void processMouseMotionEvent(MouseEvent e) {
checkFieldUnderMouse(e);
}

public void setIvMousePressed(boolean pressed) {
ivMousePressed = pressed;
}

public void setIvStartDragging(MouseEvent e) {
this.ivStartDragging = new Point(assureColIn(e.getX() / getCharSize().width),
assureRowIn(e.getY() / getCharSize().height));
}

private void setSelectedArea(Point p1, Point p2) {
setSelectedArea(new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y),
Math.abs(p1.x - p2.x) + 1, Math.abs(p1.y - p2.y) + 1));
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/net/infordata/em/TerminalClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -312,7 +313,14 @@ public void shouldGetSuccessScreenWhenLoginByTabulator()
.isEqualTo(getFileContent("user-menu-screen.txt"));

}


@Test(expected = NoSuchElementException.class)
public void shouldThrowExceptionWhenSetTabFieldAndCurrentPositionLacksField() throws Exception {
awaitKeyboardUnlock();
client.updateCursorPosition("", 1, 1);
client.setFieldTextByTabulator(0, "TESTUSR");
}

private static class TestField {

private static final byte FIELD_FORMAT_MASK = 0x40;
Expand Down

0 comments on commit 2e44b8d

Please sign in to comment.