IND$FILE receiving
This commit is contained in:
@@ -6,6 +6,8 @@ import org.lib3270j.listener.ScreenUpdateListener;
|
||||
import org.pubvm.j3270.ui.ConnectDialog;
|
||||
import org.pubvm.j3270.ui.StatusBar;
|
||||
import org.pubvm.j3270.ui.TerminalPanel;
|
||||
import org.pubvm.j3270.ft.FileTransfer;
|
||||
import org.pubvm.j3270.ft.FileTransferDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -31,6 +33,8 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
|
||||
private String lastHost = "";
|
||||
private int lastPort = 23;
|
||||
|
||||
private FileTransfer fileTransfer;
|
||||
|
||||
public J3270App() {
|
||||
super("j3270 — Java TN3270 Terminal Emulator");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@@ -125,6 +129,8 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
|
||||
client.reset();
|
||||
terminalPanel.repaint();
|
||||
}));
|
||||
actionsMenu.addSeparator();
|
||||
actionsMenu.add(createMenuItem("File Transfer...", KeyEvent.VK_T, this::showFileTransferDialog));
|
||||
menuBar.add(actionsMenu);
|
||||
|
||||
// Help menu
|
||||
@@ -154,6 +160,69 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
|
||||
return item;
|
||||
}
|
||||
|
||||
private void showFileTransferDialog() {
|
||||
if (client == null) {
|
||||
JOptionPane.showMessageDialog(this, "Connect to a host before using File Transfer.",
|
||||
"Not Connected", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileTransfer == null) {
|
||||
fileTransfer = new FileTransfer(client, new FileTransfer.FileTransferCallback() {
|
||||
private ProgressMonitor monitor;
|
||||
|
||||
@Override
|
||||
public void onTransferStarted() {
|
||||
monitor = new ProgressMonitor(J3270App.this, "Starting IND$FILE transfer...",
|
||||
"Waiting for host...", 0, 100);
|
||||
monitor.setMillisToDecideToPopup(0);
|
||||
monitor.setMillisToPopup(0);
|
||||
|
||||
// Start a timer to check for manual cancellation
|
||||
Timer cancelCheckTimer = new Timer(500, e -> {
|
||||
if (monitor != null && monitor.isCanceled() && fileTransfer != null) {
|
||||
fileTransfer.cancel();
|
||||
((Timer)e.getSource()).stop();
|
||||
}
|
||||
});
|
||||
cancelCheckTimer.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransferRunning() {
|
||||
if (monitor != null) {
|
||||
monitor.setNote("Transferring data...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBytesTransferred(long bytes) {
|
||||
if (monitor != null) {
|
||||
monitor.setNote(bytes + " bytes transferred");
|
||||
// We don't always know max size in IND$FILE, so we just pulse/update note
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransferComplete(String message) {
|
||||
if (monitor != null) monitor.close();
|
||||
monitor = null;
|
||||
JOptionPane.showMessageDialog(J3270App.this, message, "Transfer Complete", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransferAborted(String error) {
|
||||
if (monitor != null) monitor.close();
|
||||
monitor = null;
|
||||
JOptionPane.showMessageDialog(J3270App.this, "Transfer Failed: " + error, "Transfer Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FileTransferDialog dialog = new FileTransferDialog(this, fileTransfer);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
// ========== Connection management ==========
|
||||
|
||||
private void showConnectDialog() {
|
||||
@@ -221,6 +290,10 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
|
||||
|
||||
private void disconnect() {
|
||||
if (client != null) {
|
||||
if (fileTransfer != null) {
|
||||
fileTransfer.cancel();
|
||||
fileTransfer = null;
|
||||
}
|
||||
client.disconnect();
|
||||
client = null;
|
||||
terminalPanel.setClient(null);
|
||||
@@ -280,6 +353,9 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
|
||||
if (client != null) {
|
||||
client.getInputProcessor().setKeyboardLocked(false);
|
||||
}
|
||||
if (fileTransfer != null) {
|
||||
fileTransfer.onScreenUpdated();
|
||||
}
|
||||
terminalPanel.repaint();
|
||||
statusBar.updateStatus();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user