1 | /******************************************************************************
|
---|
2 | *
|
---|
3 | * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
|
---|
4 | * www.mindbright.se, [email protected]
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | *****************************************************************************
|
---|
17 | * $Author: mats $
|
---|
18 | * $Date: 2000/04/07 07:14:55 $
|
---|
19 | * $Name: rel1-2-1 $
|
---|
20 | *****************************************************************************/
|
---|
21 | package mindbright.ssh;
|
---|
22 |
|
---|
23 | import java.awt.*;
|
---|
24 | import java.awt.event.*;
|
---|
25 |
|
---|
26 | import mindbright.util.AWTConvenience;
|
---|
27 |
|
---|
28 | public class SSHSCPDialog {
|
---|
29 | private final static String TXT_LOCAL_IS_SOURCE = "Copy from local files/directories:";
|
---|
30 | private final static String TXT_REMOTE_IS_TARGET = "To directory/file on server:";
|
---|
31 | private final static String TXT_LOCAL_IS_TARGET = "Copy to local directory/file:";
|
---|
32 | private final static String TXT_REMOTE_IS_SOURCE = "From files/directories on server:";
|
---|
33 |
|
---|
34 | static Dialog scpDialog;
|
---|
35 | static TextField localFile;
|
---|
36 | static TextField remoteFile;
|
---|
37 | static Label localPos, remotePos;
|
---|
38 | static Checkbox cbRecursive, cbBackground;
|
---|
39 | static FileDialog scpLocFD;
|
---|
40 | static boolean toRemote;
|
---|
41 |
|
---|
42 | static SSHPropertyHandler propsHandler;
|
---|
43 | static SSHInteractor interactor;
|
---|
44 | static Frame parent;
|
---|
45 |
|
---|
46 | public static void show(String title, Frame p,
|
---|
47 | SSHPropertyHandler props,
|
---|
48 | SSHInteractor itor) {
|
---|
49 | parent = p;
|
---|
50 | propsHandler = props;
|
---|
51 | interactor = itor;
|
---|
52 |
|
---|
53 | if(SSH.NETSCAPE_SECURITY_MODEL) {
|
---|
54 | try {
|
---|
55 | netscape.security.PrivilegeManager.enablePrivilege("UniversalFileAccess");
|
---|
56 | } catch (netscape.security.ForbiddenTargetException e) {
|
---|
57 | // !!!
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | if(scpDialog == null) {
|
---|
62 | scpDialog = new Dialog(parent, title, false);
|
---|
63 |
|
---|
64 | GridBagLayout grid = new GridBagLayout();
|
---|
65 | GridBagConstraints gridc = new GridBagConstraints();
|
---|
66 |
|
---|
67 | scpLocFD = new FileDialog(parent, "MindTerm - Select file to copy", FileDialog.LOAD);
|
---|
68 | scpLocFD.setDirectory(propsHandler.getSSHHomeDir());
|
---|
69 |
|
---|
70 | scpDialog.setLayout(grid);
|
---|
71 |
|
---|
72 | gridc.fill = GridBagConstraints.HORIZONTAL;
|
---|
73 | gridc.anchor = GridBagConstraints.WEST;
|
---|
74 | gridc.gridwidth = 2;
|
---|
75 | gridc.gridy = 0;
|
---|
76 |
|
---|
77 | gridc.insets = new Insets(8, 4, 4, 8);
|
---|
78 |
|
---|
79 | localPos = new Label(TXT_LOCAL_IS_SOURCE);
|
---|
80 | grid.setConstraints(localPos, gridc);
|
---|
81 | scpDialog.add(localPos);
|
---|
82 |
|
---|
83 | gridc.gridy = 1;
|
---|
84 | gridc.gridwidth = 3;
|
---|
85 |
|
---|
86 | localFile = new TextField("", 38);
|
---|
87 | grid.setConstraints(localFile, gridc);
|
---|
88 | scpDialog.add(localFile);
|
---|
89 |
|
---|
90 | localFile.setText(scpLocFD.getDirectory());
|
---|
91 |
|
---|
92 | gridc.gridwidth = 1;
|
---|
93 | Button b = new Button("...");
|
---|
94 | b.addActionListener(new ActionListener() {
|
---|
95 | public void actionPerformed(ActionEvent e) {
|
---|
96 | scpLocFD.setVisible(true);
|
---|
97 | if(scpLocFD.getFile() != null && scpLocFD.getFile().length() > 0) {
|
---|
98 | String file = scpLocFD.getDirectory() + scpLocFD.getFile();
|
---|
99 | if(file.indexOf(' ') != -1)
|
---|
100 | file = "\"" + file + "\"";
|
---|
101 | localFile.setText(file);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | });
|
---|
105 | gridc.fill = GridBagConstraints.NONE;
|
---|
106 | grid.setConstraints(b, gridc);
|
---|
107 | scpDialog.add(b);
|
---|
108 |
|
---|
109 | toRemote = true;
|
---|
110 | gridc.gridy = 2;
|
---|
111 | b = new Button("Change Direction");
|
---|
112 | b.addActionListener(new ActionListener() {
|
---|
113 | public void actionPerformed(ActionEvent e) {
|
---|
114 | toRemote = !toRemote;
|
---|
115 | if(toRemote) {
|
---|
116 | localPos.setText(TXT_LOCAL_IS_SOURCE);
|
---|
117 | remotePos.setText(TXT_REMOTE_IS_TARGET);
|
---|
118 | } else {
|
---|
119 | localPos.setText(TXT_LOCAL_IS_TARGET);
|
---|
120 | remotePos.setText(TXT_REMOTE_IS_SOURCE);
|
---|
121 | }
|
---|
122 | }
|
---|
123 | });
|
---|
124 | gridc.gridwidth = GridBagConstraints.REMAINDER;
|
---|
125 | gridc.fill = GridBagConstraints.NONE;
|
---|
126 | gridc.anchor = GridBagConstraints.CENTER;
|
---|
127 | grid.setConstraints(b, gridc);
|
---|
128 | scpDialog.add(b);
|
---|
129 |
|
---|
130 | gridc.gridy = 3;
|
---|
131 | gridc.anchor = GridBagConstraints.WEST;
|
---|
132 | gridc.gridwidth = 2;
|
---|
133 | gridc.fill = GridBagConstraints.HORIZONTAL;
|
---|
134 |
|
---|
135 | remotePos = new Label(TXT_REMOTE_IS_TARGET);
|
---|
136 | grid.setConstraints(remotePos, gridc);
|
---|
137 | scpDialog.add(remotePos);
|
---|
138 |
|
---|
139 | gridc.gridy = 4;
|
---|
140 | gridc.gridwidth = 3;
|
---|
141 |
|
---|
142 | remoteFile = new TextField("", 38);
|
---|
143 | grid.setConstraints(remoteFile, gridc);
|
---|
144 | scpDialog.add(remoteFile);
|
---|
145 |
|
---|
146 | /* !!! TODO make a remote file-browser (SSHClient -> cd, ls -l)
|
---|
147 | b = new Button("...");
|
---|
148 | b.addActionListener(new ActionListener() {
|
---|
149 | public void actionPerformed(ActionEvent e) {
|
---|
150 | }
|
---|
151 | });
|
---|
152 | gridc.fill = GridBagConstraints.NONE;
|
---|
153 | grid.setConstraints(b, gridc);
|
---|
154 | scpDialog.add(b);
|
---|
155 | */
|
---|
156 |
|
---|
157 | gridc.gridy = 5;
|
---|
158 | gridc.gridwidth = 1;
|
---|
159 |
|
---|
160 | cbRecursive = new Checkbox("Recursive copy", false);
|
---|
161 | grid.setConstraints(cbRecursive, gridc);
|
---|
162 | scpDialog.add(cbRecursive);
|
---|
163 |
|
---|
164 | cbBackground = new Checkbox("Low priority", false);
|
---|
165 | grid.setConstraints(cbBackground, gridc);
|
---|
166 | scpDialog.add(cbBackground);
|
---|
167 |
|
---|
168 | gridc.gridy = 6;
|
---|
169 | gridc.gridwidth = 2;
|
---|
170 |
|
---|
171 | Button okBut, cancBut;
|
---|
172 | Panel bp = new Panel(new FlowLayout());
|
---|
173 | bp.add(okBut = new Button("Start Copy"));
|
---|
174 | okBut.addActionListener(new ActionListener() {
|
---|
175 | public void actionPerformed(ActionEvent e) {
|
---|
176 | try {
|
---|
177 | String srvHost = propsHandler.getSrvHost();
|
---|
178 | int srvPort = propsHandler.getSrvPort();
|
---|
179 | String localFN = localFile.getText();
|
---|
180 | String remoteFN = remoteFile.getText();
|
---|
181 | String curDir = scpLocFD.getDirectory();
|
---|
182 | boolean recursive = cbRecursive.getState();
|
---|
183 | boolean background = cbBackground.getState();
|
---|
184 |
|
---|
185 | SSHSCPGUIThread progress =
|
---|
186 | new SSHSCPGUIThread(srvHost, srvPort,
|
---|
187 | propsHandler,
|
---|
188 | propsHandler, interactor,
|
---|
189 | parent, curDir,
|
---|
190 | localFN, remoteFN,
|
---|
191 | recursive,
|
---|
192 | background, toRemote);
|
---|
193 | } catch (Exception ee) {
|
---|
194 | SSHMiscDialogs.alert("MindTerm - Alert",
|
---|
195 | "Error starting SCP-tread: " + ee.getMessage(),
|
---|
196 | parent);
|
---|
197 | }
|
---|
198 | }
|
---|
199 | });
|
---|
200 | bp.add(cancBut = new Button("Close Dialog"));
|
---|
201 | cancBut.addActionListener(new AWTConvenience.CloseAction(scpDialog));
|
---|
202 |
|
---|
203 | AWTConvenience.setKeyListenerOfChildren(scpDialog,
|
---|
204 | new AWTConvenience.OKCancelAdapter(okBut, cancBut),
|
---|
205 | null);
|
---|
206 |
|
---|
207 | gridc.gridwidth = GridBagConstraints.REMAINDER;
|
---|
208 | gridc.anchor = GridBagConstraints.CENTER;
|
---|
209 | grid.setConstraints(bp, gridc);
|
---|
210 | scpDialog.add(bp);
|
---|
211 |
|
---|
212 | scpDialog.addWindowListener(new AWTConvenience.CloseAdapter(cancBut));
|
---|
213 |
|
---|
214 | AWTConvenience.setBackgroundOfChildren(scpDialog);
|
---|
215 |
|
---|
216 | scpDialog.setResizable(true);
|
---|
217 | scpDialog.pack();
|
---|
218 | }
|
---|
219 |
|
---|
220 | scpDialog.setTitle(title);
|
---|
221 |
|
---|
222 | AWTConvenience.placeDialog(scpDialog);
|
---|
223 | scpDialog.setVisible(true);
|
---|
224 | }
|
---|
225 | }
|
---|