FTPFrame.java 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. // Copyright (C) 2002-2005 Ultr@VNC Team. All Rights Reserved.
  2. // Copyright (C) 2004 Kenn Min Chong, John Witchel. All Rights Reserved.
  3. //
  4. //This is free software; you can redistribute it and/or modify
  5. //it under the terms of the GNU General Public License as published by
  6. //the Free Software Foundation; either version 2 of the License, or
  7. //(at your option) any later version.
  8. //
  9. //This software is distributed in the hope that it will be useful,
  10. //but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. //GNU General Public License for more details.
  13. //
  14. //You should have received a copy of the GNU General Public License
  15. //along with this software; if not, write to the Free Software
  16. //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. //USA.
  18. //
  19. import javax.swing.JFrame;
  20. import java.awt.*;
  21. import java.awt.event.*;
  22. import java.io.*;
  23. import java.util.ArrayList;
  24. import java.util.Vector;
  25. import javax.swing.*;
  26. /*
  27. * Created on Feb 25, 2004
  28. *
  29. */
  30. /**
  31. * @author John Witchel, Kenn Min Chong
  32. *
  33. */
  34. public class FTPFrame extends JFrame implements ActionListener, MouseListener {
  35. VncViewer viewer;
  36. private javax.swing.JPanel jContentPane = null;
  37. private javax.swing.JPanel topPanel = null;
  38. private javax.swing.JPanel topPanelLocal = null;
  39. private javax.swing.JPanel topPanelRemote = null;
  40. private javax.swing.JPanel topPanelCenter = null;
  41. private javax.swing.JPanel statusPanel = null;
  42. private javax.swing.JPanel remotePanel = null;
  43. private javax.swing.JPanel localPanel = null;
  44. private javax.swing.JPanel buttonPanel = null;
  45. private javax.swing.JButton sendButton = null;
  46. private javax.swing.JButton receiveButton = null;
  47. private javax.swing.JButton deleteButton = null;
  48. private javax.swing.JButton newFolderButton = null;
  49. private javax.swing.JButton stopButton = null;
  50. private javax.swing.JButton closeButton = null;
  51. private javax.swing.JButton dummyButton = null;
  52. private javax.swing.JComboBox localDrivesComboBox = null;
  53. private javax.swing.JComboBox remoteDrivesComboBox = null;
  54. private javax.swing.JTextField localMachineLabel = null;
  55. private javax.swing.JTextField remoteMachineLabel = null;
  56. private javax.swing.JButton localTopButton = null;
  57. private javax.swing.JButton remoteTopButton = null;
  58. private javax.swing.JScrollPane localScrollPane = null;
  59. private javax.swing.JList localFileTable = null;
  60. private javax.swing.JScrollPane remoteScrollPane = null;
  61. private javax.swing.JList remoteFileTable = null;
  62. private javax.swing.JTextField remoteLocation = null;
  63. private javax.swing.JTextField localLocation = null;
  64. private javax.swing.JTextField localStatus = null;
  65. public javax.swing.JTextField remoteStatus = null;
  66. public javax.swing.JComboBox historyComboBox = null;
  67. public javax.swing.JProgressBar jProgressBar = null;
  68. public javax.swing.JTextField connectionStatus = null;
  69. public boolean updateDriveList;
  70. private Vector remoteList = null;
  71. private Vector localList = null;
  72. private File currentLocalDirectory = null; // Holds the current local Directory
  73. private File currentRemoteDirectory = null; // Holds the current remote Directory
  74. private File localSelection = null; // Holds the currently selected local file
  75. private String remoteSelection = null; // Holds the currently selected remote file
  76. public String selectedTable = null;
  77. // sf@2004 - Separate directories and files for better lisibility
  78. private ArrayList DirsList;
  79. private ArrayList FilesList;
  80. public static void main(String[] args) {
  81. }
  82. /**
  83. * This is the default constructor
  84. public FTPFrame() {
  85. super();
  86. initialize();
  87. }
  88. */
  89. /**
  90. * This is Kenn's Constructor
  91. *
  92. */
  93. FTPFrame(VncViewer v) {
  94. super("Ultr@VNC File Transfer");
  95. viewer = v;
  96. // this.setUndecorated(true); // sf@2004
  97. this.setResizable(false); // sf@2004
  98. setSize(320, 240);
  99. // sf@2004
  100. DirsList = new ArrayList();
  101. FilesList = new ArrayList();
  102. initialize();
  103. }
  104. /* Refreshing local and remote directory lists
  105. * after an operation has been performed
  106. */
  107. void refreshLocalLocation()
  108. {
  109. File f = new File(localLocation.getText());
  110. this.changeLocalDirectory(f);
  111. }
  112. void refreshRemoteLocation()
  113. {
  114. remoteList.clear();
  115. remoteFileTable.setListData(remoteList);
  116. viewer.rfb.readServerDirectory(remoteLocation.getText());
  117. }
  118. /*
  119. * Prints the list of drives on the remote directory and returns a String[].
  120. * str takes as string like A:fC:lD:lE:lF:lG:cH:c
  121. * in the form Drive Letter:Drive Type where
  122. * f = floppy, l = local drive, c=CD-ROM, n = network
  123. */
  124. String[] printDrives(String str) {
  125. System.out.println(str);
  126. updateDriveList = true;
  127. remoteDrivesComboBox.removeAllItems();
  128. int size = str.length();
  129. String driveType = null;
  130. String[] drive = new String[str.length() / 3];
  131. // Loop through the string to create a String[]
  132. for (int i = 0; i < size; i = i + 3) {
  133. drive[i / 3] = str.substring(i, i + 2);
  134. driveType = str.substring(i + 2, i + 3);
  135. if (driveType.compareTo("f") == 0)
  136. drive[i / 3] += "\\ Floppy";
  137. if (driveType.compareTo("l") == 0)
  138. drive[i / 3] += "\\ Local Disk";
  139. if (driveType.compareTo("c") == 0)
  140. drive[i / 3] += "\\ CD-ROM";
  141. if (driveType.compareTo("n") == 0)
  142. drive[i / 3] += "\\ Network";
  143. remoteDrivesComboBox.addItem(drive[i / 3]);
  144. }
  145. //sf@ - Select Drive C:as default if possible
  146. boolean bFound = false;
  147. for(int i = 0; i < remoteDrivesComboBox.getItemCount() ; i++)
  148. {
  149. if(remoteDrivesComboBox.getItemAt(i).toString().substring(0,1).toUpperCase().equals("C"))
  150. {
  151. remoteDrivesComboBox.setSelectedIndex(i);
  152. bFound = true;
  153. }
  154. }
  155. if (!bFound) remoteDrivesComboBox.setSelectedIndex(0);
  156. updateDriveList = false;
  157. return drive;
  158. }
  159. /*Disable buttons/lists while file transfer is in progress*/
  160. public void disableButtons()
  161. {
  162. closeButton.setEnabled(false);
  163. deleteButton.setEnabled(false);
  164. localTopButton.setEnabled(false);
  165. newFolderButton.setEnabled(false);
  166. stopButton.setVisible(true);
  167. stopButton.setEnabled(true);
  168. receiveButton.setEnabled(false);
  169. remoteTopButton.setEnabled(false);
  170. sendButton.setEnabled(false);
  171. remoteFileTable.setEnabled(false);
  172. localFileTable.setEnabled(false);
  173. localLocation.setEnabled(false);
  174. remoteLocation.setEnabled(false);
  175. remoteDrivesComboBox.setEnabled(false);
  176. localDrivesComboBox.setEnabled(false);
  177. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // sf@2004
  178. }
  179. /*Enable buttons/lists after file transfer is done*/
  180. public void enableButtons()
  181. {
  182. closeButton.setEnabled(true);
  183. deleteButton.setEnabled(true);
  184. localTopButton.setEnabled(true);
  185. newFolderButton.setEnabled(true);
  186. stopButton.setVisible(false);
  187. stopButton.setEnabled(false);
  188. receiveButton.setEnabled(true);
  189. remoteTopButton.setEnabled(true);
  190. sendButton.setEnabled(true);
  191. remoteFileTable.setEnabled(true);
  192. localFileTable.setEnabled(true);
  193. localLocation.setEnabled(true);
  194. remoteLocation.setEnabled(true);
  195. remoteDrivesComboBox.setEnabled(true);
  196. localDrivesComboBox.setEnabled(true);
  197. // setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); // sf@2004
  198. }
  199. /*
  200. * Print Directory prints out all the contents of a directory
  201. */
  202. void printDirectory(ArrayList a) {
  203. for (int i = 0; i < a.size(); i++) {
  204. remoteList.addElement(a.get(i));
  205. }
  206. remoteFileTable.setListData(remoteList);
  207. }
  208. /**
  209. * This method initializes this
  210. *
  211. * @return void
  212. */
  213. private void initialize() {
  214. this.setSize(794, 500);
  215. this.setContentPane(getJContentPane());
  216. updateDriveList = true;
  217. }
  218. /**
  219. * This method initializes jContentPane. This is the main content pane
  220. *
  221. * @return javax.swing.JPanel
  222. */
  223. private javax.swing.JPanel getJContentPane() {
  224. if (jContentPane == null) {
  225. jContentPane = new javax.swing.JPanel();
  226. jContentPane.setLayout(new java.awt.BorderLayout());
  227. jContentPane.add(getTopPanel(), java.awt.BorderLayout.NORTH);
  228. jContentPane.add(getStatusPanel(), java.awt.BorderLayout.SOUTH);
  229. jContentPane.add(getRemotePanel(), java.awt.BorderLayout.EAST);
  230. jContentPane.add(getLocalPanel(), java.awt.BorderLayout.WEST);
  231. jContentPane.add(getButtonPanel(), java.awt.BorderLayout.CENTER);
  232. }
  233. return jContentPane;
  234. }
  235. /**
  236. * This method initializes topPanel
  237. *
  238. * @return javax.swing.JPanel
  239. */
  240. private javax.swing.JPanel getTopPanelLocal() {
  241. if (topPanelLocal == null) {
  242. topPanelLocal = new javax.swing.JPanel();
  243. topPanelLocal.setLayout(new java.awt.BorderLayout());
  244. topPanelLocal.setPreferredSize(new java.awt.Dimension(325, 22));
  245. topPanelLocal.add(getLocalDrivesComboBox(), java.awt.BorderLayout.WEST);
  246. topPanelLocal.add(getLocalMachineLabel(), java.awt.BorderLayout.CENTER);
  247. topPanelLocal.add(getLocalTopButton(), java.awt.BorderLayout.EAST);
  248. topPanelLocal.setBackground(java.awt.Color.lightGray);
  249. }
  250. return topPanelLocal;
  251. }
  252. /**
  253. * This method initializes topPanelRemote
  254. *
  255. * @return javax.swing.JPanel
  256. */
  257. private javax.swing.JPanel getTopPanelRemote() {
  258. if (topPanelRemote == null) {
  259. topPanelRemote = new javax.swing.JPanel();
  260. topPanelRemote.setLayout(new java.awt.BorderLayout());
  261. topPanelRemote.setPreferredSize(new java.awt.Dimension(325, 20));
  262. topPanelRemote.add(getRemoteDrivesComboBox(), java.awt.BorderLayout.WEST);
  263. topPanelRemote.add(getRemoteMachineLabel(), java.awt.BorderLayout.CENTER);
  264. topPanelRemote.add(getRemoteTopButton(), java.awt.BorderLayout.EAST);
  265. topPanelRemote.setBackground(java.awt.Color.lightGray);
  266. }
  267. return topPanelRemote;
  268. }
  269. /**
  270. * This method initializes topPanelRemote
  271. *
  272. * @return javax.swing.JPanel
  273. */
  274. private javax.swing.JPanel getTopPanelCenter() {
  275. if (topPanelCenter == null) {
  276. topPanelCenter = new javax.swing.JPanel();
  277. topPanelCenter.add(getDummyButton(), null);
  278. }
  279. return topPanelCenter;
  280. }
  281. /**
  282. * This method initializes topPanel
  283. *
  284. * @return javax.swing.JPanel
  285. */
  286. private javax.swing.JPanel getTopPanel() {
  287. if (topPanel == null) {
  288. topPanel = new javax.swing.JPanel();
  289. topPanel.setLayout(new java.awt.BorderLayout());
  290. //sf@2004 - We manage 2 top panels
  291. topPanel.add(getTopPanelLocal(), java.awt.BorderLayout.WEST);
  292. // topPanel.add(getTopPanelCenter(), java.awt.BorderLayout.CENTER);
  293. topPanel.add(getTopPanelRemote(), java.awt.BorderLayout.EAST);
  294. /*
  295. topPanel.add(getLocalDrivesComboBox(), null);
  296. topPanel.add(getLocalMachineLabel(), null);
  297. topPanel.add(getLocalTopButton(), null);
  298. topPanel.add(getRemoteDrivesComboBox(), null);
  299. topPanel.add(getRemoteMachineLabel(), null);
  300. topPanel.add(getRemoteTopButton(), null);
  301. topPanel.setBackground(java.awt.Color.lightGray);
  302. */
  303. }
  304. return topPanel;
  305. }
  306. /**
  307. * This method initializes statusPanel
  308. *
  309. * @return javax.swing.JPanel
  310. */
  311. private javax.swing.JPanel getStatusPanel() {
  312. if (statusPanel == null) {
  313. statusPanel = new javax.swing.JPanel();
  314. statusPanel.setLayout(
  315. new javax.swing.BoxLayout(
  316. statusPanel,
  317. javax.swing.BoxLayout.Y_AXIS));
  318. statusPanel.add(getHistoryComboBox(), null);
  319. statusPanel.add(getJProgressBar(), null);
  320. statusPanel.add(getConnectionStatus(), null);
  321. statusPanel.setBackground(java.awt.Color.lightGray);
  322. }
  323. return statusPanel;
  324. }
  325. /**
  326. * This method initializes remotePanel
  327. *
  328. * @return javax.swing.JPanel
  329. */
  330. private javax.swing.JPanel getRemotePanel() {
  331. if (remotePanel == null) {
  332. remotePanel = new javax.swing.JPanel();
  333. remotePanel.setLayout(
  334. new javax.swing.BoxLayout(
  335. remotePanel,
  336. javax.swing.BoxLayout.Y_AXIS));
  337. remotePanel.add(getRemoteLocation(), null);
  338. remotePanel.add(getRemoteScrollPane(), null);
  339. remotePanel.add(getRemoteStatus(), null);
  340. remotePanel.setBackground(java.awt.Color.lightGray);
  341. }
  342. return remotePanel;
  343. }
  344. /**
  345. * This method initializes localPanel
  346. *
  347. * @return javax.swing.JPanel
  348. */
  349. private javax.swing.JPanel getLocalPanel() {
  350. if (localPanel == null) {
  351. localPanel = new javax.swing.JPanel();
  352. localPanel.setLayout(
  353. new javax.swing.BoxLayout(
  354. localPanel,
  355. javax.swing.BoxLayout.Y_AXIS));
  356. localPanel.add(getLocalLocation(), null);
  357. localPanel.add(getLocalScrollPane(), null);
  358. localPanel.add(getLocalStatus(), null);
  359. localPanel.setBackground(java.awt.Color.lightGray);
  360. localPanel.setComponentOrientation(
  361. java.awt.ComponentOrientation.UNKNOWN);
  362. localPanel.setName("localPanel");
  363. }
  364. return localPanel;
  365. }
  366. /**
  367. * This method initializes buttonPanel
  368. *
  369. * @return javax.swing.JPanel
  370. */
  371. private javax.swing.JPanel getButtonPanel()
  372. {
  373. if (buttonPanel == null)
  374. {
  375. buttonPanel = new javax.swing.JPanel();
  376. buttonPanel.setLayout(null);
  377. buttonPanel.add(getReceiveButton(), null);
  378. buttonPanel.add(getNewFolderButton(), null);
  379. buttonPanel.add(getCloseButton(), null);
  380. buttonPanel.add(getDeleteButton(), null);
  381. buttonPanel.add(getSendButton(), null);
  382. buttonPanel.add(getStopButton(), null);
  383. buttonPanel.setBackground(java.awt.Color.lightGray);
  384. }
  385. return buttonPanel;
  386. }
  387. /**
  388. * This method initializes sendButton
  389. *
  390. * @return javax.swing.JButton
  391. */
  392. private javax.swing.JButton getSendButton() {
  393. if (sendButton == null) {
  394. sendButton = new javax.swing.JButton();
  395. sendButton.setBounds(20, 30, 97, 25);
  396. sendButton.setText("Send >>");
  397. sendButton.setName("sendButton");
  398. sendButton.addActionListener(this);
  399. }
  400. return sendButton;
  401. }
  402. /**
  403. * This method initializes receiveButton
  404. *
  405. * @return javax.swing.JButton
  406. */
  407. private javax.swing.JButton getReceiveButton() {
  408. if (receiveButton == null) {
  409. receiveButton = new javax.swing.JButton();
  410. receiveButton.setBounds(20, 60, 97, 25);
  411. receiveButton.setText("<< Receive");
  412. receiveButton.setName("receiveButton");
  413. receiveButton.addActionListener(this);
  414. }
  415. return receiveButton;
  416. }
  417. /**
  418. * This method initializes deleteButton
  419. *
  420. * @return javax.swing.JButton
  421. */
  422. private javax.swing.JButton getDeleteButton() {
  423. if (deleteButton == null) {
  424. deleteButton = new javax.swing.JButton();
  425. deleteButton.setBounds(20, 110, 97, 25);
  426. deleteButton.setText("Delete File");
  427. deleteButton.setName("deleteButton");
  428. deleteButton.addActionListener(this);
  429. }
  430. return deleteButton;
  431. }
  432. /**
  433. * This method initializes newFolderButton
  434. *
  435. * @return javax.swing.JButton
  436. */
  437. private javax.swing.JButton getNewFolderButton() {
  438. if (newFolderButton == null) {
  439. newFolderButton = new javax.swing.JButton();
  440. newFolderButton.setBounds(20, 140, 97, 25);
  441. newFolderButton.setText("New Folder");
  442. newFolderButton.setName("newFolderButton");
  443. newFolderButton.addActionListener(this);
  444. }
  445. return newFolderButton;
  446. }
  447. /**
  448. * This method initializes stopButton
  449. *
  450. * @return javax.swing.JButton
  451. */
  452. private javax.swing.JButton getStopButton()
  453. {
  454. if (stopButton == null)
  455. {
  456. stopButton = new javax.swing.JButton();
  457. stopButton.setBounds(20, 200, 97, 25);
  458. stopButton.setText("Stop");
  459. stopButton.setName("stopButton");
  460. stopButton.addActionListener(this);
  461. stopButton.setVisible(false);
  462. }
  463. return stopButton;
  464. }
  465. /**
  466. * This method initializes closeButton
  467. *
  468. * @return javax.swing.JButton
  469. */
  470. private javax.swing.JButton getCloseButton() {
  471. if (closeButton == null) {
  472. closeButton = new javax.swing.JButton();
  473. closeButton.setBounds(20, 325, 97, 25);
  474. closeButton.setText("Close");
  475. closeButton.setName("closeButton");
  476. closeButton.addActionListener(this);
  477. }
  478. return closeButton;
  479. }
  480. /**
  481. * This method initializes dummyButton
  482. *
  483. * @return javax.swing.JButton
  484. */
  485. private javax.swing.JButton getDummyButton() {
  486. if (dummyButton == null) {
  487. dummyButton = new javax.swing.JButton();
  488. dummyButton.setBounds(12, 206, 99, 25);
  489. dummyButton.setText("aaaaaaaaaaaaaaa");
  490. dummyButton.setName("DummyButton");
  491. dummyButton.setVisible(false);
  492. }
  493. return dummyButton;
  494. }
  495. /**
  496. * This method initializes localDrivesComboBox
  497. *
  498. * @return javax.swing.JComboBox
  499. */
  500. private javax.swing.JComboBox getLocalDrivesComboBox() {
  501. updateDriveList = true;
  502. // Read in Drive letters from local disk
  503. File[] roots = File.listRoots();
  504. String[] localDisks = new String[roots.length];
  505. for (int i = 0; i < roots.length; i++) {
  506. localDisks[i] = roots[i].toString();
  507. }
  508. // Create the combo box
  509. if (localDrivesComboBox == null) {
  510. localDrivesComboBox = new javax.swing.JComboBox(localDisks);
  511. localDrivesComboBox.setName("LocalDisks");
  512. localDrivesComboBox.setFont(
  513. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  514. //Select the second entry (e.g. C:\)
  515. // localDrivesComboBox.setSelectedIndex(1);
  516. localDrivesComboBox.addActionListener(this);
  517. }
  518. updateDriveList = false;
  519. return localDrivesComboBox;
  520. }
  521. /**
  522. * This method initializes remoteDrivesComboBox
  523. *
  524. * @return javax.swing.JComboBox
  525. */
  526. public javax.swing.JComboBox getRemoteDrivesComboBox() {
  527. if (remoteDrivesComboBox == null) {
  528. remoteDrivesComboBox = new javax.swing.JComboBox();
  529. remoteDrivesComboBox.setName("remoteDisks");
  530. remoteDrivesComboBox.setFont(
  531. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  532. remoteDrivesComboBox.addActionListener(this);
  533. }
  534. return remoteDrivesComboBox;
  535. }
  536. /**
  537. * This method initializes localMachineLabel
  538. *
  539. * @return javax.swing.JTextField
  540. */
  541. private javax.swing.JTextField getLocalMachineLabel() {
  542. if (localMachineLabel == null) {
  543. localMachineLabel = new javax.swing.JTextField();
  544. localMachineLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  545. // localMachineLabel.setPreferredSize(new java.awt.Dimension(150, 19));
  546. localMachineLabel.setBackground(java.awt.Color.lightGray);
  547. localMachineLabel.setText(" LOCAL MACHINE");
  548. localMachineLabel.setName("localLocation");
  549. localMachineLabel.setFont(
  550. new java.awt.Font("Dialog", java.awt.Font.BOLD, 11));
  551. localMachineLabel.setEditable(false);
  552. }
  553. return localMachineLabel;
  554. }
  555. /**
  556. * This method initializes remoteMachineLabel
  557. *
  558. * @return javax.swing.JTextField
  559. */
  560. private javax.swing.JTextField getRemoteMachineLabel() {
  561. if (remoteMachineLabel == null) {
  562. remoteMachineLabel = new javax.swing.JTextField();
  563. // remoteMachineLabel.setPreferredSize(new java.awt.Dimension(150, 19));
  564. remoteMachineLabel.setName("remoteLocation");
  565. remoteMachineLabel.setText(" REMOTE MACHINE");
  566. remoteMachineLabel.setBackground(java.awt.Color.lightGray);
  567. remoteMachineLabel.setFont(
  568. new java.awt.Font("Dialog", java.awt.Font.BOLD, 11));
  569. remoteMachineLabel.setEditable(false);
  570. }
  571. return remoteMachineLabel;
  572. }
  573. /**
  574. * This method initializes localTopButton
  575. *
  576. * @return javax.swing.JButton
  577. */
  578. private javax.swing.JButton getLocalTopButton() {
  579. if (localTopButton == null) {
  580. localTopButton = new javax.swing.JButton();
  581. localTopButton.setText("Root (\\)");
  582. // localTopButton.setPreferredSize(new java.awt.Dimension(30, 19));
  583. localTopButton.setFont(
  584. new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
  585. localTopButton.addActionListener(this);
  586. }
  587. return localTopButton;
  588. }
  589. /**
  590. * This method initializes remoteTopButton
  591. *
  592. * @return javax.swing.JButton
  593. */
  594. private javax.swing.JButton getRemoteTopButton() {
  595. if (remoteTopButton == null) {
  596. remoteTopButton = new javax.swing.JButton();
  597. remoteTopButton.setText("Root (\\)");
  598. // remoteTopButton.setPreferredSize(new java.awt.Dimension(49, 25));
  599. remoteTopButton.setFont(
  600. new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
  601. remoteTopButton.addActionListener(this);
  602. }
  603. return remoteTopButton;
  604. }
  605. /**
  606. * This method initializes localFileTable
  607. *
  608. * @return javax.swing.JTable
  609. */
  610. private javax.swing.JList getLocalFileTable() {
  611. if (localFileTable == null) {
  612. localList = new Vector(0);
  613. localFileTable = new JList(localList);
  614. localFileTable.addMouseListener(this);
  615. localFileTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  616. }
  617. return localFileTable;
  618. }
  619. /**
  620. * This method initializes localScrollPane
  621. *
  622. * @return javax.swing.JScrollPane
  623. */
  624. private javax.swing.JScrollPane getLocalScrollPane() {
  625. if (localScrollPane == null) {
  626. localScrollPane = new javax.swing.JScrollPane();
  627. localScrollPane.setViewportView(getLocalFileTable());
  628. localScrollPane.setPreferredSize(new java.awt.Dimension(325, 418));
  629. localScrollPane.setFont(
  630. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  631. localScrollPane.setName("localFileList");
  632. }
  633. return localScrollPane;
  634. }
  635. /**
  636. * This method initializes remoteFileTable
  637. *
  638. * @return javax.swing.JTable
  639. */
  640. private javax.swing.JList getRemoteFileTable() {
  641. if (remoteFileTable == null) {
  642. remoteList = new Vector(0);
  643. remoteFileTable = new JList(remoteList);
  644. remoteFileTable.addMouseListener(this);
  645. remoteFileTable.setSelectedValue("C:\\", false);
  646. remoteFileTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  647. }
  648. return remoteFileTable;
  649. }
  650. /**
  651. * This method initializes remoteScrollPane
  652. *
  653. * @return javax.swing.JScrollPane
  654. */
  655. private javax.swing.JScrollPane getRemoteScrollPane() {
  656. if (remoteScrollPane == null) {
  657. remoteScrollPane = new javax.swing.JScrollPane();
  658. remoteScrollPane.setViewportView(getRemoteFileTable());
  659. remoteScrollPane.setPreferredSize(new java.awt.Dimension(325, 418));
  660. }
  661. return remoteScrollPane;
  662. }
  663. /**
  664. * This method initializes remoteLocation
  665. *
  666. * @return javax.swing.JTextField
  667. */
  668. private javax.swing.JTextField getRemoteLocation()
  669. {
  670. if (remoteLocation == null)
  671. {
  672. remoteLocation = new javax.swing.JTextField();
  673. remoteLocation.setText("");
  674. remoteLocation.setEditable(false); // sf@2004
  675. remoteLocation.setBackground(new Color(255,255,238));
  676. remoteLocation.setFont(
  677. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  678. }
  679. return remoteLocation;
  680. }
  681. /**
  682. * This method initializes localLocation
  683. *
  684. * @return javax.swing.JTextField
  685. */
  686. private javax.swing.JTextField getLocalLocation() {
  687. if (localLocation == null) {
  688. localLocation = new javax.swing.JTextField();
  689. localLocation.setText("");
  690. localLocation.setEditable(false); // sf@2004
  691. localLocation.setBackground( new Color(255,255,238));
  692. localLocation.setFont(
  693. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  694. }
  695. return localLocation;
  696. }
  697. /**
  698. * This method initializes localStatus
  699. *
  700. * @return javax.swing.JTextField
  701. */
  702. private javax.swing.JTextField getLocalStatus() {
  703. if (localStatus == null) {
  704. localStatus = new javax.swing.JTextField();
  705. // localStatus.setText("> Found 63 File(s) 7 Directorie(s)");
  706. localStatus.setBackground(java.awt.Color.lightGray);
  707. localStatus.setFont(
  708. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  709. localStatus.setEditable(false);
  710. }
  711. return localStatus;
  712. }
  713. /**
  714. * This method initializes remoteStatus
  715. *
  716. * @return javax.swing.JTextField
  717. */
  718. private javax.swing.JTextField getRemoteStatus() {
  719. if (remoteStatus == null) {
  720. remoteStatus = new javax.swing.JTextField();
  721. // remoteStatus.setText("> Found 15 File(s) 2 Directorie(s)");
  722. remoteStatus.setBackground(java.awt.Color.lightGray);
  723. remoteStatus.setFont(
  724. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  725. remoteStatus.setEditable(false);
  726. }
  727. return remoteStatus;
  728. }
  729. /**
  730. * This method initializes historyComboBox
  731. *
  732. * @return javax.swing.JComboBox
  733. */
  734. private javax.swing.JComboBox getHistoryComboBox() {
  735. if (historyComboBox == null) {
  736. historyComboBox = new javax.swing.JComboBox();
  737. historyComboBox.setFont(
  738. new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
  739. historyComboBox.insertItemAt(new String("Pulldown to view history ..."),0);
  740. historyComboBox.setSelectedIndex(0);
  741. historyComboBox.addActionListener(this);
  742. }
  743. return historyComboBox;
  744. }
  745. /**
  746. * This method initializes jProgressBar
  747. *
  748. * @return javax.swing.JProgressBar
  749. */
  750. private javax.swing.JProgressBar getJProgressBar() {
  751. if (jProgressBar == null) {
  752. jProgressBar = new javax.swing.JProgressBar();
  753. }
  754. return jProgressBar;
  755. }
  756. /**
  757. * This method initializes connectionStatus
  758. *
  759. * @return javax.swing.JTextField
  760. */
  761. private javax.swing.JTextField getConnectionStatus() {
  762. if (connectionStatus == null) {
  763. connectionStatus = new javax.swing.JTextField();
  764. connectionStatus.setText("Connected...");
  765. connectionStatus.setBackground(java.awt.Color.lightGray);
  766. connectionStatus.setFont(
  767. new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
  768. }
  769. connectionStatus.setEditable(false);
  770. return connectionStatus;
  771. }
  772. /**
  773. * Implements Action listener.
  774. */
  775. public void actionPerformed(ActionEvent evt) {
  776. System.out.println(evt.getSource());
  777. if (evt.getSource() == closeButton)
  778. { // Close Button
  779. doClose();
  780. }
  781. else if (evt.getSource() == sendButton)
  782. {
  783. doSend();
  784. }
  785. else if (evt.getSource() == receiveButton)
  786. {
  787. doReceive();
  788. }
  789. else if (evt.getSource() == localDrivesComboBox)
  790. {
  791. changeLocalDrive();
  792. }
  793. else if (evt.getSource() == remoteDrivesComboBox)
  794. {
  795. changeRemoteDrive();
  796. remoteList.clear();
  797. remoteFileTable.setListData(remoteList);
  798. }
  799. else if (evt.getSource() == localTopButton)
  800. {
  801. changeLocalDrive();
  802. }
  803. else if (evt.getSource() == remoteTopButton)
  804. {
  805. changeRemoteDrive();
  806. }
  807. else if(evt.getSource() == deleteButton)
  808. {
  809. doDelete();
  810. }
  811. else if(evt.getSource()==newFolderButton)
  812. {
  813. doNewFolder();
  814. }
  815. else if (evt.getSource() == stopButton)
  816. {
  817. doStop();
  818. }
  819. }
  820. private void doNewFolder()
  821. {
  822. String name = JOptionPane.showInputDialog(null,"Enter new directory name", "Create New Directory", JOptionPane.QUESTION_MESSAGE);
  823. if(selectedTable.equals("remote"))
  824. {
  825. name = remoteLocation.getText()+name;
  826. viewer.rfb.createRemoteDirectory(name);
  827. }
  828. else
  829. {
  830. name = localLocation.getText()+name;
  831. File f = new File(name);
  832. f.mkdir();
  833. refreshLocalLocation();
  834. historyComboBox.insertItemAt(new String("Created Local Directory: " + name),0);
  835. historyComboBox.setSelectedIndex(0);
  836. }
  837. }
  838. private void doClose()
  839. {
  840. try {
  841. this.setVisible(false);
  842. viewer.rfb.writeFramebufferUpdateRequest(
  843. 0,
  844. 0,
  845. viewer.rfb.framebufferWidth,
  846. viewer.rfb.framebufferHeight,
  847. true);
  848. } catch (IOException e) {
  849. // TODO Auto-generated catch block
  850. e.printStackTrace();
  851. }
  852. }
  853. private void doDelete()
  854. {
  855. System.out.println("Delete Button Pressed");
  856. //Call this method to delete a file at server
  857. if(selectedTable.equals("remote"))
  858. {
  859. String sFileName = ((String) this.remoteFileTable.getSelectedValue());
  860. // sf@2004 - Directory can't be deleted
  861. if (sFileName.substring(0, 2).equals(" [") && sFileName.substring((sFileName.length() - 1), sFileName.length()).equals("]"))
  862. {
  863. JOptionPane.showMessageDialog(null, (String)"Directory Deletion is not yet available in this version...", "FileTransfer Info", JOptionPane.INFORMATION_MESSAGE);
  864. return;
  865. }
  866. // for (int i = 0; i < remoteList.contains(size(); i++)
  867. // remoteFileTable.g(i));
  868. // sf@2004 - Delete prompt
  869. if (remoteList.contains(sFileName))
  870. {
  871. int r = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete the file \n< " + sFileName + " >\n on Remote Machine ?", "File Transfer Warning", JOptionPane.YES_NO_OPTION);
  872. if (r == JOptionPane.NO_OPTION)
  873. return;
  874. }
  875. String fileName = remoteLocation.getText()+ sFileName.substring(1);
  876. viewer.rfb.deleteRemoteFile(fileName);
  877. }
  878. else
  879. {
  880. String sFileName = ((String) this.localFileTable.getSelectedValue());
  881. // sf@2004 - Directory can't be deleted
  882. if (sFileName.substring(0, 2).equals(" [") && sFileName.substring((sFileName.length() - 1), sFileName.length()).equals("]"))
  883. {
  884. JOptionPane.showMessageDialog(null, (String)"Directory Deletion is not yet available in this version...", "FileTransfer Info", JOptionPane.INFORMATION_MESSAGE);
  885. return;
  886. }
  887. // sf@2004 - Delete prompt
  888. if (localList.contains(sFileName))
  889. {
  890. int r = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete the file \n< " + sFileName + " >\n on Local Machine ?", "File Transfer Warning", JOptionPane.YES_NO_OPTION);
  891. if (r == JOptionPane.NO_OPTION)
  892. return;
  893. }
  894. String s = localLocation.getText() + sFileName.substring(1);
  895. File f = new File(s);
  896. f.delete();
  897. refreshLocalLocation();
  898. historyComboBox.insertItemAt(new String("Deleted On Local Disk: " + s),0);
  899. historyComboBox.setSelectedIndex(0);
  900. }
  901. }
  902. private void doReceive()
  903. {
  904. System.out.println("Received Button Pressed");
  905. String sFileName = ((String) this.remoteFileTable.getSelectedValue());
  906. // sf@2004 - Directory can't be transfered
  907. if (sFileName.substring(0, 2).equals(" [") && sFileName.substring((sFileName.length() - 1), sFileName.length()).equals("]"))
  908. {
  909. JOptionPane.showMessageDialog(null, (String)"Directory Transfer is not yet available in this version...", "FileTransfer Info", JOptionPane.INFORMATION_MESSAGE);
  910. return;
  911. }
  912. // sf@2004 - Overwrite prompt
  913. if (localList.contains(sFileName))
  914. {
  915. int r = JOptionPane.showConfirmDialog(null, "The file < " + sFileName + " >\n already exists on Local Machine\n Are you sure you want to overwrite it ?", "File Transfer Warning", JOptionPane.YES_NO_OPTION);
  916. if (r == JOptionPane.NO_OPTION)
  917. return;
  918. }
  919. //updateHistory("Downloaded " + localSelection.toString());
  920. String remoteFileName = this.remoteLocation.getText();
  921. remoteFileName+= ((String) this.remoteFileTable.getSelectedValue()).substring(1);
  922. String localDestinationPath = this.localLocation.getText()+((String)this.remoteFileTable.getSelectedValue()).substring(1);
  923. viewer.rfb.requestRemoteFile(remoteFileName,localDestinationPath);
  924. }
  925. private void doSend()
  926. {
  927. System.out.println("Send Button Pressed");
  928. String sFileName = ((String) this.localFileTable.getSelectedValue());
  929. // sf@2004 - Directory can't be transfered
  930. if (sFileName.substring(0, 2).equals(" [") && sFileName.substring((sFileName.length() - 1), sFileName.length()).equals("]"))
  931. {
  932. JOptionPane.showMessageDialog(null, (String)"Directory Transfer is not yet available in this version...", "FileTransfer Info", JOptionPane.INFORMATION_MESSAGE);
  933. return;
  934. }
  935. // sf@2004 - Overwrite prompt
  936. if (remoteList.contains(sFileName))
  937. {
  938. int r = JOptionPane.showConfirmDialog(null, "The file < " + sFileName + " >\n already exists on Remote Machine\n Are you sure you want to overwrite it ?", "File Transfer Warning", JOptionPane.YES_NO_OPTION);
  939. if (r == JOptionPane.NO_OPTION)
  940. return;
  941. }
  942. //updateHistory("Uploaded " + localSelection.toString());
  943. String source = this.localLocation.getText();
  944. source += ((String) this.localFileTable.getSelectedValue()).substring(1);
  945. String destinationPath = this.remoteLocation.getText();
  946. viewer.rfb.offerLocalFile(source,destinationPath);
  947. }
  948. //
  949. // sf@2004 - The user stops the current file transfer
  950. //
  951. private void doStop()
  952. {
  953. viewer.rfb.fAbort = true;
  954. }
  955. /**
  956. * Update History: This method updates the history pulldown menu with the message string
  957. *
  958. */
  959. private void updateHistory(String message)
  960. {
  961. System.out.println("History: " + message);
  962. historyComboBox.insertItemAt(new String(message), 0);
  963. }
  964. /**
  965. * This method updates the file table to the current selection of the remoteComboBox
  966. *
  967. */
  968. public void changeRemoteDrive()
  969. {
  970. remoteSelection = null;
  971. if (!updateDriveList) {
  972. String drive = remoteDrivesComboBox.getSelectedItem().toString().substring(0,1)+ ":\\";
  973. viewer.rfb.readServerDirectory(drive);
  974. remoteLocation.setText(drive);
  975. }
  976. remoteList.clear();
  977. remoteFileTable.setListData(remoteList);
  978. }
  979. /**
  980. * changeLocalDrive updates the file table
  981. * to the current selection of the localComboBox
  982. */
  983. private void changeLocalDrive()
  984. {
  985. File currentDrive = new File(localDrivesComboBox.getSelectedItem().toString());
  986. if(currentDrive.canRead())
  987. {
  988. localSelection = null;
  989. localStatus.setText("");
  990. changeLocalDirectory(currentDrive);
  991. }
  992. else
  993. {
  994. localList.clear();
  995. localStatus.setText("WARNING: Drive " + localDrivesComboBox.getSelectedItem().toString());
  996. connectionStatus.setText(" > WARNING - Local Drive unavailable (possibly restricted access or media not present)");
  997. }
  998. }
  999. /**
  1000. * Determines which FileTable was double-clicked and updates the table
  1001. */
  1002. public void mouseClicked(MouseEvent e)
  1003. {
  1004. if(e.getClickCount() == 1)
  1005. { // Single clicked
  1006. if (e.getSource() == localFileTable )
  1007. { // on local file table
  1008. updateLocalFileTableSelection();
  1009. }
  1010. else if (e.getSource() == remoteFileTable)
  1011. {
  1012. updateRemoteFileTableSelection(); // on a remote file table
  1013. }
  1014. }
  1015. else if (e.getClickCount() == 2)
  1016. { // Mouse Double clicked
  1017. if (e.getSource() == localFileTable)
  1018. { // Clicked on local file
  1019. updateLocalFileTable();
  1020. }
  1021. else if (e.getSource() == remoteFileTable)
  1022. { // Clicked on remote file
  1023. updateRemoteFileTable();
  1024. }
  1025. }
  1026. }
  1027. /*
  1028. * Updates the globally accessible remote file selection if a file is single clicked in the RemoteFileTable
  1029. *
  1030. */
  1031. private void updateRemoteFileTableSelection() {
  1032. selectedTable = "remote";
  1033. localFileTable.setBackground(new Color(238, 238, 238));
  1034. remoteFileTable.setBackground(new Color(255, 255, 255));
  1035. String name = (remoteFileTable.getSelectedValue().toString()).substring(1);
  1036. if( !name.substring(0, 2).equals(" ["))
  1037. remoteSelection = remoteLocation.getText() + name.substring(0, name.length());
  1038. }
  1039. /*
  1040. * Updates the globally accessible local file selection
  1041. * if a file is single clicked in the LocalFileTable
  1042. *
  1043. */
  1044. private void updateLocalFileTableSelection() {
  1045. selectedTable="local";
  1046. remoteFileTable.setBackground(new Color(238, 238, 238));
  1047. localFileTable.setBackground(new Color(255, 255, 255));
  1048. File currentSelection = new File(currentLocalDirectory, getTrimmedSelection());
  1049. if(currentSelection.isFile())
  1050. localSelection = currentSelection.getAbsoluteFile();
  1051. }
  1052. /**
  1053. * Updates the Remote File Table based on selection. Called from mouseClicked handler
  1054. */
  1055. public void updateRemoteFileTable() {
  1056. String name = null;
  1057. String action = null;
  1058. String drive = null;
  1059. name = (remoteFileTable.getSelectedValue().toString()).substring(1);
  1060. if (name.equals("[..]"))
  1061. {
  1062. action = "up";
  1063. remoteSelection = null;
  1064. drive = remoteLocation.getText().substring(0, remoteLocation.getText().length() - 1);
  1065. // JOptionPane.showMessageDialog(null, (String)drive, "FileTransfer DEBUG", JOptionPane.INFORMATION_MESSAGE);
  1066. int index = drive.lastIndexOf("\\");
  1067. drive = drive.substring(0, index + 1);
  1068. remoteLocation.setText(drive);
  1069. viewer.rfb.readServerDirectory(drive);
  1070. remoteList.clear();
  1071. remoteFileTable.setListData(remoteList);
  1072. }
  1073. else if (!name.substring(0, 2).equals(" [") && !name.substring((name.length() - 1), name.length()).equals("]"))
  1074. {
  1075. action = "file";
  1076. // Set the global remoteSelection field (used for get/put buttons)
  1077. remoteSelection = remoteLocation.getText() + name.substring(0, name.length());
  1078. drive = remoteLocation.getText();
  1079. // ??
  1080. }
  1081. else
  1082. {
  1083. action = "down";
  1084. remoteSelection = null;
  1085. name = name.substring(1, name.length() - 1);
  1086. drive = remoteLocation.getText() + name + "\\";
  1087. remoteLocation.setText(drive);
  1088. viewer.rfb.readServerDirectory(drive);
  1089. remoteList.clear();
  1090. remoteFileTable.setListData(remoteList);
  1091. }
  1092. //remoteLocation.setText(drive);
  1093. }
  1094. /**
  1095. * Updates the Local File Table based on selection. Called from MouseClicked handler
  1096. */
  1097. private void updateLocalFileTable()
  1098. {
  1099. localStatus.setText("");
  1100. File currentSelection = new File(currentLocalDirectory , getTrimmedSelection()); // Selection
  1101. if (getTrimmedSelection().equals(".."))
  1102. { // The [..] selected
  1103. localSelection = null; // No selection since directory changed
  1104. currentSelection = currentLocalDirectory.getParentFile();
  1105. if(currentSelection != null)
  1106. {
  1107. changeLocalDirectory(currentSelection);
  1108. }
  1109. else
  1110. {
  1111. localStatus.setText("You are at the root !");
  1112. }
  1113. }
  1114. else if (currentSelection.isFile())
  1115. {
  1116. localSelection = currentSelection.getAbsoluteFile();
  1117. }
  1118. else if (currentSelection.isDirectory())
  1119. {
  1120. localSelection = null; // No selection since directory changed
  1121. changeLocalDirectory(currentSelection);
  1122. }
  1123. }
  1124. /*
  1125. * Trims off the [] of a directory entry if it exists, else ignores it
  1126. *
  1127. */
  1128. private String getTrimmedSelection(){
  1129. String currentSelection = (localFileTable.getSelectedValue().toString()).substring(1);
  1130. if(currentSelection.substring(0,1).equals("[") &&
  1131. currentSelection.substring(currentSelection.length()-1,currentSelection.length()).equals("]")){
  1132. return currentSelection.substring(1,currentSelection.length()-1);
  1133. } else {
  1134. return currentSelection;
  1135. }
  1136. }
  1137. /*
  1138. * Reads the localDriveComboBox and returns the first readable drive for populating
  1139. * the file table on load, so it's not looking at the A:\ drive when it opens.
  1140. */
  1141. public File getFirstReadableLocalDrive(){
  1142. File currentDrive;
  1143. // sf@ - Select C: as default first readable drive
  1144. for(int i = 0; i < localDrivesComboBox.getItemCount() ; i++)
  1145. {
  1146. currentDrive = new File(localDrivesComboBox.getItemAt(i).toString());
  1147. if(localDrivesComboBox.getItemAt(i).toString().substring(0,1).toUpperCase().equals("C") && currentDrive.canRead())
  1148. {
  1149. localDrivesComboBox.setSelectedIndex(i);
  1150. return currentDrive;
  1151. }
  1152. }
  1153. // if C: not available, take the first readable drive, this time.
  1154. for(int i = 0; i < localDrivesComboBox.getItemCount() ; i++)
  1155. {
  1156. currentDrive = new File(localDrivesComboBox.getItemAt(i).toString());
  1157. if(currentDrive.canRead())
  1158. {
  1159. localDrivesComboBox.setSelectedIndex(i);
  1160. return currentDrive;
  1161. }
  1162. }
  1163. localStatus.setText("ERROR!: No Local Drives are Readable");
  1164. return null;
  1165. }
  1166. /*
  1167. * Navigates the local file structure up or down one directory
  1168. */
  1169. public void changeLocalDirectory(File dir)
  1170. {
  1171. currentLocalDirectory = dir; // Updates Global
  1172. File allFiles[] = dir.listFiles(); // Reads files
  1173. String[] contents = dir.list();
  1174. localList.clear();
  1175. localList.addElement(" [..]");
  1176. // Populate the Lists
  1177. for (int i = 0; i < contents.length; i++)
  1178. {
  1179. if (allFiles[i].isDirectory())
  1180. // localList.addElement("[" + contents[i] + "]");
  1181. DirsList.add(" [" + contents[i] + "]"); // sf@2004
  1182. else
  1183. {
  1184. // localList.addElement(contents[i]);
  1185. FilesList.add(" " + contents[i]); // sf@2004
  1186. }
  1187. }
  1188. // sf@2004
  1189. for (int i = 0; i < DirsList.size(); i++)
  1190. localList.addElement(DirsList.get(i));
  1191. for (int i = 0; i < FilesList.size(); i++)
  1192. localList.addElement(FilesList.get(i));
  1193. FilesList.clear();
  1194. DirsList.clear();
  1195. localFileTable.setListData(localList);
  1196. if(dir.toString().charAt(dir.toString().length()-1)==(File.separatorChar))
  1197. {
  1198. localLocation.setText(dir.toString());
  1199. }
  1200. else
  1201. {
  1202. localLocation.setText(dir.toString()+File.separator); // Display updated location above file table
  1203. }
  1204. localStatus.setText("Total Files / Folders: " + (localList.size()-1));
  1205. }
  1206. public void mouseEntered(MouseEvent e) {
  1207. }
  1208. public void mouseExited(MouseEvent e) {
  1209. }
  1210. public void mousePressed(MouseEvent e) {
  1211. }
  1212. public void mouseReleased(MouseEvent e) {
  1213. }
  1214. } // @jve:visual-info decl-index=0 visual-constraint="10,10"