?? ftpframe.java
字號:
// Copyright (C) 2002-2005 Ultr@VNC Team. All Rights Reserved.
// Copyright (C) 2004 Kenn Min Chong, John Witchel. All Rights Reserved.
//
//This is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//
//This software is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this software; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
//USA.
//
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.*;
/*
* Created on Feb 25, 2004
*
*/
/**
* @author John Witchel, Kenn Min Chong
*
*/
public class FTPFrame extends JFrame implements ActionListener, MouseListener {
VncViewer viewer;
private javax.swing.JPanel jContentPane = null;
private javax.swing.JPanel topPanel = null;
private javax.swing.JPanel topPanelLocal = null;
private javax.swing.JPanel topPanelRemote = null;
private javax.swing.JPanel topPanelCenter = null;
private javax.swing.JPanel statusPanel = null;
private javax.swing.JPanel remotePanel = null;
private javax.swing.JPanel localPanel = null;
private javax.swing.JPanel buttonPanel = null;
private javax.swing.JButton sendButton = null;
private javax.swing.JButton receiveButton = null;
private javax.swing.JButton deleteButton = null;
private javax.swing.JButton newFolderButton = null;
private javax.swing.JButton stopButton = null;
private javax.swing.JButton closeButton = null;
private javax.swing.JButton dummyButton = null;
private javax.swing.JComboBox localDrivesComboBox = null;
private javax.swing.JComboBox remoteDrivesComboBox = null;
private javax.swing.JTextField localMachineLabel = null;
private javax.swing.JTextField remoteMachineLabel = null;
private javax.swing.JButton localTopButton = null;
private javax.swing.JButton remoteTopButton = null;
private javax.swing.JScrollPane localScrollPane = null;
private javax.swing.JList localFileTable = null;
private javax.swing.JScrollPane remoteScrollPane = null;
private javax.swing.JList remoteFileTable = null;
private javax.swing.JTextField remoteLocation = null;
private javax.swing.JTextField localLocation = null;
private javax.swing.JTextField localStatus = null;
public javax.swing.JTextField remoteStatus = null;
public javax.swing.JComboBox historyComboBox = null;
public javax.swing.JProgressBar jProgressBar = null;
public javax.swing.JTextField connectionStatus = null;
public boolean updateDriveList;
private Vector remoteList = null;
private Vector localList = null;
private File currentLocalDirectory = null; // Holds the current local Directory
private File currentRemoteDirectory = null; // Holds the current remote Directory
private File localSelection = null; // Holds the currently selected local file
private String remoteSelection = null; // Holds the currently selected remote file
public String selectedTable = null;
// sf@2004 - Separate directories and files for better lisibility
private ArrayList DirsList;
private ArrayList FilesList;
public static void main(String[] args) {
}
/**
* This is the default constructor
public FTPFrame() {
super();
initialize();
}
*/
/**
* This is Kenn's Constructor
*
*/
FTPFrame(VncViewer v) {
super("Ultr@VNC File Transfer");
viewer = v;
// this.setUndecorated(true); // sf@2004
this.setResizable(false); // sf@2004
setSize(320, 240);
// sf@2004
DirsList = new ArrayList();
FilesList = new ArrayList();
initialize();
}
/* Refreshing local and remote directory lists
* after an operation has been performed
*/
void refreshLocalLocation()
{
File f = new File(localLocation.getText());
this.changeLocalDirectory(f);
}
void refreshRemoteLocation()
{
remoteList.clear();
remoteFileTable.setListData(remoteList);
viewer.rfb.readServerDirectory(remoteLocation.getText());
}
/*
* Prints the list of drives on the remote directory and returns a String[].
* str takes as string like A:fC:lD:lE:lF:lG:cH:c
* in the form Drive Letter:Drive Type where
* f = floppy, l = local drive, c=CD-ROM, n = network
*/
String[] printDrives(String str) {
System.out.println(str);
updateDriveList = true;
remoteDrivesComboBox.removeAllItems();
int size = str.length();
String driveType = null;
String[] drive = new String[str.length() / 3];
// Loop through the string to create a String[]
for (int i = 0; i < size; i = i + 3) {
drive[i / 3] = str.substring(i, i + 2);
driveType = str.substring(i + 2, i + 3);
if (driveType.compareTo("f") == 0)
drive[i / 3] += "\\ Floppy";
if (driveType.compareTo("l") == 0)
drive[i / 3] += "\\ Local Disk";
if (driveType.compareTo("c") == 0)
drive[i / 3] += "\\ CD-ROM";
if (driveType.compareTo("n") == 0)
drive[i / 3] += "\\ Network";
remoteDrivesComboBox.addItem(drive[i / 3]);
}
//sf@ - Select Drive C:as default if possible
boolean bFound = false;
for(int i = 0; i < remoteDrivesComboBox.getItemCount() ; i++)
{
if(remoteDrivesComboBox.getItemAt(i).toString().substring(0,1).toUpperCase().equals("C"))
{
remoteDrivesComboBox.setSelectedIndex(i);
bFound = true;
}
}
if (!bFound) remoteDrivesComboBox.setSelectedIndex(0);
updateDriveList = false;
return drive;
}
/*Disable buttons/lists while file transfer is in progress*/
public void disableButtons()
{
closeButton.setEnabled(false);
deleteButton.setEnabled(false);
localTopButton.setEnabled(false);
newFolderButton.setEnabled(false);
stopButton.setVisible(true);
stopButton.setEnabled(true);
receiveButton.setEnabled(false);
remoteTopButton.setEnabled(false);
sendButton.setEnabled(false);
remoteFileTable.setEnabled(false);
localFileTable.setEnabled(false);
localLocation.setEnabled(false);
remoteLocation.setEnabled(false);
remoteDrivesComboBox.setEnabled(false);
localDrivesComboBox.setEnabled(false);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // sf@2004
}
/*Enable buttons/lists after file transfer is done*/
public void enableButtons()
{
closeButton.setEnabled(true);
deleteButton.setEnabled(true);
localTopButton.setEnabled(true);
newFolderButton.setEnabled(true);
stopButton.setVisible(false);
stopButton.setEnabled(false);
receiveButton.setEnabled(true);
remoteTopButton.setEnabled(true);
sendButton.setEnabled(true);
remoteFileTable.setEnabled(true);
localFileTable.setEnabled(true);
localLocation.setEnabled(true);
remoteLocation.setEnabled(true);
remoteDrivesComboBox.setEnabled(true);
localDrivesComboBox.setEnabled(true);
// setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); // sf@2004
}
/*
* Print Directory prints out all the contents of a directory
*/
void printDirectory(ArrayList a) {
for (int i = 0; i < a.size(); i++) {
remoteList.addElement(a.get(i));
}
remoteFileTable.setListData(remoteList);
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(794, 500);
this.setContentPane(getJContentPane());
updateDriveList = true;
}
/**
* This method initializes jContentPane. This is the main content pane
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(new java.awt.BorderLayout());
jContentPane.add(getTopPanel(), java.awt.BorderLayout.NORTH);
jContentPane.add(getStatusPanel(), java.awt.BorderLayout.SOUTH);
jContentPane.add(getRemotePanel(), java.awt.BorderLayout.EAST);
jContentPane.add(getLocalPanel(), java.awt.BorderLayout.WEST);
jContentPane.add(getButtonPanel(), java.awt.BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes topPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getTopPanelLocal() {
if (topPanelLocal == null) {
topPanelLocal = new javax.swing.JPanel();
topPanelLocal.setLayout(new java.awt.BorderLayout());
topPanelLocal.setPreferredSize(new java.awt.Dimension(325, 22));
topPanelLocal.add(getLocalDrivesComboBox(), java.awt.BorderLayout.WEST);
topPanelLocal.add(getLocalMachineLabel(), java.awt.BorderLayout.CENTER);
topPanelLocal.add(getLocalTopButton(), java.awt.BorderLayout.EAST);
topPanelLocal.setBackground(java.awt.Color.lightGray);
}
return topPanelLocal;
}
/**
* This method initializes topPanelRemote
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getTopPanelRemote() {
if (topPanelRemote == null) {
topPanelRemote = new javax.swing.JPanel();
topPanelRemote.setLayout(new java.awt.BorderLayout());
topPanelRemote.setPreferredSize(new java.awt.Dimension(325, 20));
topPanelRemote.add(getRemoteDrivesComboBox(), java.awt.BorderLayout.WEST);
topPanelRemote.add(getRemoteMachineLabel(), java.awt.BorderLayout.CENTER);
topPanelRemote.add(getRemoteTopButton(), java.awt.BorderLayout.EAST);
topPanelRemote.setBackground(java.awt.Color.lightGray);
}
return topPanelRemote;
}
/**
* This method initializes topPanelRemote
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getTopPanelCenter() {
if (topPanelCenter == null) {
topPanelCenter = new javax.swing.JPanel();
topPanelCenter.add(getDummyButton(), null);
}
return topPanelCenter;
}
/**
* This method initializes topPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getTopPanel() {
if (topPanel == null) {
topPanel = new javax.swing.JPanel();
topPanel.setLayout(new java.awt.BorderLayout());
//sf@2004 - We manage 2 top panels
topPanel.add(getTopPanelLocal(), java.awt.BorderLayout.WEST);
// topPanel.add(getTopPanelCenter(), java.awt.BorderLayout.CENTER);
topPanel.add(getTopPanelRemote(), java.awt.BorderLayout.EAST);
/*
topPanel.add(getLocalDrivesComboBox(), null);
topPanel.add(getLocalMachineLabel(), null);
topPanel.add(getLocalTopButton(), null);
topPanel.add(getRemoteDrivesComboBox(), null);
topPanel.add(getRemoteMachineLabel(), null);
topPanel.add(getRemoteTopButton(), null);
topPanel.setBackground(java.awt.Color.lightGray);
*/
}
return topPanel;
}
/**
* This method initializes statusPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getStatusPanel() {
if (statusPanel == null) {
statusPanel = new javax.swing.JPanel();
statusPanel.setLayout(
new javax.swing.BoxLayout(
statusPanel,
javax.swing.BoxLayout.Y_AXIS));
statusPanel.add(getHistoryComboBox(), null);
statusPanel.add(getJProgressBar(), null);
statusPanel.add(getConnectionStatus(), null);
statusPanel.setBackground(java.awt.Color.lightGray);
}
return statusPanel;
}
/**
* This method initializes remotePanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getRemotePanel() {
if (remotePanel == null) {
remotePanel = new javax.swing.JPanel();
remotePanel.setLayout(
new javax.swing.BoxLayout(
remotePanel,
javax.swing.BoxLayout.Y_AXIS));
remotePanel.add(getRemoteLocation(), null);
remotePanel.add(getRemoteScrollPane(), null);
remotePanel.add(getRemoteStatus(), null);
remotePanel.setBackground(java.awt.Color.lightGray);
}
return remotePanel;
}
/**
* This method initializes localPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getLocalPanel() {
if (localPanel == null) {
localPanel = new javax.swing.JPanel();
localPanel.setLayout(
new javax.swing.BoxLayout(
localPanel,
javax.swing.BoxLayout.Y_AXIS));
localPanel.add(getLocalLocation(), null);
localPanel.add(getLocalScrollPane(), null);
localPanel.add(getLocalStatus(), null);
localPanel.setBackground(java.awt.Color.lightGray);
localPanel.setComponentOrientation(
java.awt.ComponentOrientation.UNKNOWN);
localPanel.setName("localPanel");
}
return localPanel;
}
/**
* This method initializes buttonPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getButtonPanel()
{
if (buttonPanel == null)
{
buttonPanel = new javax.swing.JPanel();
buttonPanel.setLayout(null);
buttonPanel.add(getReceiveButton(), null);
buttonPanel.add(getNewFolderButton(), null);
buttonPanel.add(getCloseButton(), null);
buttonPanel.add(getDeleteButton(), null);
buttonPanel.add(getSendButton(), null);
buttonPanel.add(getStopButton(), null);
buttonPanel.setBackground(java.awt.Color.lightGray);
}
return buttonPanel;
}
/**
* This method initializes sendButton
*
* @return javax.swing.JButton
*/
private javax.swing.JButton getSendButton() {
if (sendButton == null) {
sendButton = new javax.swing.JButton();
sendButton.setBounds(20, 30, 97, 25);
sendButton.setText("Send >>");
sendButton.setName("sendButton");
sendButton.addActionListener(this);
}
return sendButton;
}
/**
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -