Lightpen on
Build and Test j3270 / Build JAR & Run Tests (push) Successful in 37s

This commit is contained in:
2026-08-24 16:45:55 +00:00
parent d9df1052a1
commit e28b7dc30a
2 changed files with 25 additions and 16 deletions
@@ -120,7 +120,7 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
// Actions menu
JMenu actionsMenu = createMenu("Actions");
actionsMenu.add(createMenuItem("Clear", KeyEvent.VK_L, () -> {
actionsMenu.add(createMenuItem("Clear", KeyEvent.VK_K, () -> {
if (client != null)
client.sendClear();
terminalPanel.repaint();
@@ -73,7 +73,7 @@ public class TerminalPanel extends JPanel {
*/
private int getRenderOffsetX() {
int termCols = 80;
if (client != null) termCols = client.getScreenBuffer().getCols();
if (client != null) termCols = client.getScreenBuffer().getDisplayCols();
int gridW = termCols * cellWidth;
int extra = getWidth() - gridW;
return Math.max(padding, extra / 2);
@@ -81,10 +81,11 @@ public class TerminalPanel extends JPanel {
/**
* Compute the vertical render offset to center the grid within the panel.
* Must use getDisplayRows() to match paintComponent's iteration.
*/
private int getRenderOffsetY() {
int termRows = 24;
if (client != null) termRows = client.getScreenBuffer().getRows();
if (client != null) termRows = client.getScreenBuffer().getDisplayRows();
int gridH = termRows * cellHeight;
int extra = getHeight() - gridH;
return Math.max(padding, extra / 2);
@@ -151,10 +152,12 @@ public class TerminalPanel extends JPanel {
ScreenBuffer sb = client.getScreenBuffer();
int ox = getRenderOffsetX();
int oy = getRenderOffsetY();
int displayCols = sb.getDisplayCols();
int displayRows = sb.getDisplayRows();
int col = (e.getX() - ox) / cellWidth;
int row = (e.getY() - oy) / cellHeight;
col = Math.max(0, Math.min(col, sb.getCols() - 1));
row = Math.max(0, Math.min(row, sb.getRows() - 1));
col = Math.max(0, Math.min(col, displayCols - 1));
row = Math.max(0, Math.min(row, displayRows - 1));
// Start selection
selectionStartRow = row;
@@ -174,8 +177,8 @@ public class TerminalPanel extends JPanel {
int oy = getRenderOffsetY();
int col = (e.getX() - ox) / cellWidth;
int row = (e.getY() - oy) / cellHeight;
col = Math.max(0, Math.min(col, sb.getCols() - 1));
row = Math.max(0, Math.min(row, sb.getRows() - 1));
col = Math.max(0, Math.min(col, sb.getDisplayCols() - 1));
row = Math.max(0, Math.min(row, sb.getDisplayRows() - 1));
selectionEndRow = row;
selectionEndCol = col;
@@ -207,7 +210,8 @@ public class TerminalPanel extends JPanel {
if (selectionStartRow == selectionEndRow && selectionStartCol == selectionEndCol) {
if (client != null && client.getConnectionState().isFullSession()) {
ScreenBuffer sb = client.getScreenBuffer();
int newAddr = selectionStartRow * sb.getCols() + selectionStartCol;
int displayCols = sb.getDisplayCols();
int newAddr = selectionStartRow * displayCols + selectionStartCol;
sb.setCursorAddress(newAddr);
clearSelection();
if (lightPenMode) {
@@ -444,8 +448,8 @@ public class TerminalPanel extends JPanel {
int termRows = 24;
if (client != null) {
ScreenBuffer sb = client.getScreenBuffer();
termCols = sb.getCols();
termRows = sb.getRows();
termCols = sb.getDisplayCols();
termRows = sb.getDisplayRows();
}
// Use minimal padding for the fit calculation
@@ -869,8 +873,8 @@ public class TerminalPanel extends JPanel {
// Use the CURRENT screen dimensions (not max) to eliminate extra space.
// When the host switches to alternate screen, onScreenSizeChanged fires
// and the frame re-packs.
int displayCols = sb.getCols();
int displayRows = sb.getRows();
int displayCols = sb.getDisplayCols();
int displayRows = sb.getDisplayRows();
return new Dimension(displayCols * cellWidth + padding * 2,
displayRows * cellHeight + padding * 2);
}
@@ -1084,6 +1088,13 @@ public class TerminalPanel extends JPanel {
g2.fillRect(cx, cy, cellWidth, cellHeight);
g2.setPaintMode();
}
// Draw Light Pen mode indicator
if (lightPenMode) {
g2.setFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
g2.setColor(new Color(50, 255, 50));
g2.drawString("LP", ox + 2, oy + rows * cellHeight + 14);
}
}
private Color getColorForAttribute(ExtendedAttribute ea, ExtendedAttribute currentFieldEa, byte currentFA) {
@@ -1126,10 +1137,8 @@ public class TerminalPanel extends JPanel {
}
public void toggleLightPen() {
this.lightPenMode = !this.lightPenMode;
if (client != null && client.getGocaDecoder() != null) {
client.getGocaDecoder().setGraphicsCursorActive(this.lightPenMode);
repaint();
}
System.out.println("Light Pen mode: " + (this.lightPenMode ? "ON" : "OFF"));
repaint();
}
public boolean isLightPenMode() {