mirror of
https://github.com/xfarrow/guify.git
synced 2025-06-05 22:09:25 +02:00
Code formatting
This commit is contained in:
@ -8,7 +8,8 @@ import views.*;
|
|||||||
*/
|
*/
|
||||||
public class JFrameFactory implements IFrameFactory {
|
public class JFrameFactory implements IFrameFactory {
|
||||||
|
|
||||||
public static Object createJFrame(int frameType, Object controller) throws Exception{
|
public static Object createJFrame(int frameType, Object controller)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
switch (frameType) {
|
switch (frameType) {
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import code.GuiAbstractions.Interfaces.IGenericTextArea;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A class implementing an interface for a generic text
|
* A class implementing an interface for a generic text area. It is currently
|
||||||
* area. It is currently using JTextArea (Java Swing)
|
* using JTextArea (Java Swing)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JGenericTextArea implements IGenericTextArea {
|
public class JGenericTextArea implements IGenericTextArea {
|
||||||
|
@ -3,17 +3,13 @@ package code.GuiAbstractions.Interfaces;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Interface for a generic TextArea.
|
* Interface for a generic TextArea. It is used to create an abstraction of a
|
||||||
* It is used to create an abstraction of a
|
* TextArea, without using view-specific objects (such as JTextArea).
|
||||||
* TextArea, without using view-specific objects
|
|
||||||
* (such as JTextArea).
|
|
||||||
*
|
*
|
||||||
* This increases modularity, flexibility and
|
* This increases modularity, flexibility and creates a separation of concerns.
|
||||||
* creates a separation of concerns.
|
|
||||||
*
|
*
|
||||||
* In case of change of the GUI library you
|
* In case of change of the GUI library you do not need to change neither the
|
||||||
* do not need to change neither the Controllers nor
|
* Controllers nor these interfaces, but only the implementations.
|
||||||
* these interfaces, but only the implementations.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface IGenericTextArea {
|
public interface IGenericTextArea {
|
||||||
|
@ -11,7 +11,8 @@ public class GuifySftpProgressMonitor implements SftpProgressMonitor {
|
|||||||
public boolean count(long bytes) {
|
public boolean count(long bytes) {
|
||||||
|
|
||||||
if (transferProgress != null) {
|
if (transferProgress != null) {
|
||||||
transferProgress.setTransferredBytes(transferProgress.getTransferredBytes() + bytes);
|
transferProgress.setTransferredBytes(
|
||||||
|
transferProgress.getTransferredBytes() + bytes);
|
||||||
transferProgress.setTransferStatus(TransferProgress.UPDATING);
|
transferProgress.setTransferStatus(TransferProgress.UPDATING);
|
||||||
QueueEventManager.getInstance().notify(transferProgress);
|
QueueEventManager.getInstance().notify(transferProgress);
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,10 @@ public class Helper {
|
|||||||
public static String getParentPath(String path) {
|
public static String getParentPath(String path) {
|
||||||
if (path.equals("/")) {
|
if (path.equals("/")) {
|
||||||
return "/";
|
return "/";
|
||||||
}
|
} else if (path.equals("~")) {
|
||||||
else if(path.equals("~")) {
|
return Path.of(SshEngine.executeCommand("pwd")).getParent()
|
||||||
return Path.of(SshEngine.executeCommand("pwd")).getParent().toString().replace('\\', '/');
|
.toString().replace('\\', '/');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return Path.of(path).getParent().toString().replace('\\', '/');
|
return Path.of(path).getParent().toString().replace('\\', '/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Interface describing a DirectoryNodeButton,
|
* Interface describing a DirectoryNodeButton, independently of how a concrete
|
||||||
* independently of how a concrete DirectoryNodeButton
|
* DirectoryNodeButton will be (currently it is concretely a JButton)
|
||||||
* will be (currently it is concretely a JButton)
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface IDirectoryNodeButton {
|
public interface IDirectoryNodeButton {
|
||||||
|
@ -7,12 +7,13 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A JButton representing a Directory Node.
|
* A JButton representing a Directory Node. Useful when a Directory Node is
|
||||||
* Useful when a Directory Node is needed
|
* needed to be drew on screen.
|
||||||
* to be drew on screen.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JDirectoryNodeButton extends JButton implements IDirectoryNodeButton {
|
public class JDirectoryNodeButton extends JButton
|
||||||
|
implements
|
||||||
|
IDirectoryNodeButton {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
public ChannelSftp.LsEntry node = null;
|
public ChannelSftp.LsEntry node = null;
|
||||||
|
@ -21,3 +21,5 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In loving memory of L.B. and E.B.
|
||||||
|
@ -8,9 +8,11 @@ public class QueueEventManager extends Observable {
|
|||||||
private static QueueEventManager instance;
|
private static QueueEventManager instance;
|
||||||
|
|
||||||
// Cannot instantiate from outside
|
// Cannot instantiate from outside
|
||||||
private QueueEventManager() {}
|
private QueueEventManager() {
|
||||||
|
}
|
||||||
|
|
||||||
// We need this object in order to retrieve old transfers which are not being transferred
|
// We need this object in order to retrieve old transfers which are not
|
||||||
|
// being transferred
|
||||||
ConcurrentLinkedQueue<TransferProgress> queue = new ConcurrentLinkedQueue<TransferProgress>();
|
ConcurrentLinkedQueue<TransferProgress> queue = new ConcurrentLinkedQueue<TransferProgress>();
|
||||||
|
|
||||||
public static synchronized QueueEventManager getInstance() {
|
public static synchronized QueueEventManager getInstance() {
|
||||||
@ -29,8 +31,8 @@ public class QueueEventManager extends Observable {
|
|||||||
private void updateQueue(TransferProgress transferProgressObj) {
|
private void updateQueue(TransferProgress transferProgressObj) {
|
||||||
if (transferProgressObj.getTransferStatus() == TransferProgress.INIT) {
|
if (transferProgressObj.getTransferStatus() == TransferProgress.INIT) {
|
||||||
queue.add(transferProgressObj);
|
queue.add(transferProgressObj);
|
||||||
}
|
} else if (transferProgressObj
|
||||||
else if(transferProgressObj.getTransferStatus() == TransferProgress.END) {
|
.getTransferStatus() == TransferProgress.END) {
|
||||||
queue.remove();
|
queue.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,7 @@ import java.nio.file.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Underlying SSH engine for
|
* Underlying SSH engine for the application
|
||||||
* the application
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SshEngine {
|
public class SshEngine {
|
||||||
@ -38,7 +37,8 @@ public class SshEngine {
|
|||||||
JSch jsch = new JSch();
|
JSch jsch = new JSch();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
session = jsch.getSession(LoginController.LoginCredentials.username, LoginController.LoginCredentials.host,
|
session = jsch.getSession(LoginController.LoginCredentials.username,
|
||||||
|
LoginController.LoginCredentials.host,
|
||||||
LoginController.LoginCredentials.port);
|
LoginController.LoginCredentials.port);
|
||||||
session.setPassword(LoginController.LoginCredentials.password);
|
session.setPassword(LoginController.LoginCredentials.password);
|
||||||
session.setConfig(config);
|
session.setConfig(config);
|
||||||
@ -70,14 +70,13 @@ public class SshEngine {
|
|||||||
* ========== END SSH Utilities ==========
|
* ========== END SSH Utilities ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN SFTP get() and put() methods ==========
|
* ========== BEGIN SFTP get() and put() methods ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads a file from remote host to local machine.
|
* Downloads a file from remote host to local machine. Executed
|
||||||
* Executed asynchronously.
|
* asynchronously.
|
||||||
*/
|
*/
|
||||||
public static void downloadFile(String source, String dest) {
|
public static void downloadFile(String source, String dest) {
|
||||||
// We execute the lengthy and time-consuming operation on a different
|
// We execute the lengthy and time-consuming operation on a different
|
||||||
@ -91,8 +90,10 @@ public class SshEngine {
|
|||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.get(source, dest, new GuifySftpProgressMonitor());
|
channelSftp.get(source, dest,
|
||||||
System.out.println("File " + source + " downloaded in " + dest);
|
new GuifySftpProgressMonitor());
|
||||||
|
System.out.println(
|
||||||
|
"File " + source + " downloaded in " + dest);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -104,10 +105,10 @@ public class SshEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads a directory recursively.
|
* Downloads a directory recursively. Executed asynchronously.
|
||||||
* Executed asynchronously.
|
|
||||||
*/
|
*/
|
||||||
public static void downloadDirectoryRecursively(String source, String dest) {
|
public static void downloadDirectoryRecursively(String source,
|
||||||
|
String dest) {
|
||||||
// We execute the lengthy and time-consuming operation on a different
|
// We execute the lengthy and time-consuming operation on a different
|
||||||
// thread instead of the Event Dispatch Thread.
|
// thread instead of the Event Dispatch Thread.
|
||||||
// We use SwingWorker so any GUI changes requested by this thread will
|
// We use SwingWorker so any GUI changes requested by this thread will
|
||||||
@ -131,14 +132,19 @@ public class SshEngine {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Private utility
|
* Private utility
|
||||||
* @param channel_aux An auxiliary SFTP channel
|
*
|
||||||
|
* @param channel_aux
|
||||||
|
* An auxiliary SFTP channel
|
||||||
* @param remoteDirectory
|
* @param remoteDirectory
|
||||||
* @param localDirectory
|
* @param localDirectory
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
private static void downloadDirectoryRecursively_aux(ChannelSftp channel_aux, String remoteDirectory, String localDirectory) throws SftpException {
|
private static void downloadDirectoryRecursively_aux(
|
||||||
|
ChannelSftp channel_aux, String remoteDirectory,
|
||||||
|
String localDirectory) throws SftpException {
|
||||||
channel_aux.cd(remoteDirectory);
|
channel_aux.cd(remoteDirectory);
|
||||||
String newLocalDir = Helper.combinePath(localDirectory, Paths.get(remoteDirectory).getFileName().toString());
|
String newLocalDir = Helper.combinePath(localDirectory,
|
||||||
|
Paths.get(remoteDirectory).getFileName().toString());
|
||||||
new java.io.File(newLocalDir).mkdirs();
|
new java.io.File(newLocalDir).mkdirs();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Vector<LsEntry> entries = channel_aux.ls("*");
|
Vector<LsEntry> entries = channel_aux.ls("*");
|
||||||
@ -148,20 +154,27 @@ public class SshEngine {
|
|||||||
// File - download it
|
// File - download it
|
||||||
// Creates a thread for each file. If there are a lot of files
|
// Creates a thread for each file. If there are a lot of files
|
||||||
// it may be resource-draining. Consider using a ThreadPool
|
// it may be resource-draining. Consider using a ThreadPool
|
||||||
downloadFile(Helper.combinePath(remoteDirectory, entry.getFilename()), Helper.combinePath(newLocalDir, entry.getFilename()));
|
downloadFile(
|
||||||
} else if (!".".equals(entry.getFilename()) && !"..".equals(entry.getFilename())) {
|
Helper.combinePath(remoteDirectory,
|
||||||
|
entry.getFilename()),
|
||||||
|
Helper.combinePath(newLocalDir, entry.getFilename()));
|
||||||
|
} else if (!".".equals(entry.getFilename())
|
||||||
|
&& !"..".equals(entry.getFilename())) {
|
||||||
// Directory - download recursively
|
// Directory - download recursively
|
||||||
String newRemoteDir = Helper.combinePath(remoteDirectory, entry.getFilename());
|
String newRemoteDir = Helper.combinePath(remoteDirectory,
|
||||||
downloadDirectoryRecursively_aux(channel_aux, newRemoteDir, newLocalDir);
|
entry.getFilename());
|
||||||
|
downloadDirectoryRecursively_aux(channel_aux, newRemoteDir,
|
||||||
|
newLocalDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads a file from the local machine to the remote host.
|
* Uploads a file from the local machine to the remote host. Executed
|
||||||
* Executed asynchronously.
|
* asynchronously.
|
||||||
*/
|
*/
|
||||||
public static void uploadFile(File fileToUpload, String remoteDirectory) throws SftpException {
|
public static void uploadFile(File fileToUpload, String remoteDirectory)
|
||||||
|
throws SftpException {
|
||||||
// We execute the lengthy and time-consuming operation on a different
|
// We execute the lengthy and time-consuming operation on a different
|
||||||
// thread instead of the Event Dispatch Thread.
|
// thread instead of the Event Dispatch Thread.
|
||||||
// We use SwingWorker so any GUI changes requested by this thread will
|
// We use SwingWorker so any GUI changes requested by this thread will
|
||||||
@ -174,14 +187,15 @@ public class SshEngine {
|
|||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
remotePath = Helper.combinePath(remoteDirectory, fileToUpload.getName());
|
remotePath = Helper.combinePath(remoteDirectory,
|
||||||
channelSftp.put(fileToUpload.getAbsolutePath(), remotePath, new GuifySftpProgressMonitor());
|
fileToUpload.getName());
|
||||||
System.out.println("File: " + fileToUpload.getAbsolutePath() + " uploaded to remote path: " + remotePath);
|
channelSftp.put(fileToUpload.getAbsolutePath(), remotePath,
|
||||||
}
|
new GuifySftpProgressMonitor());
|
||||||
catch(SftpException sftpex) {
|
System.out.println("File: " + fileToUpload.getAbsolutePath()
|
||||||
|
+ " uploaded to remote path: " + remotePath);
|
||||||
|
} catch (SftpException sftpex) {
|
||||||
// TODO maybe no permissions
|
// TODO maybe no permissions
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -192,13 +206,16 @@ public class SshEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads directory recursively.
|
* Uploads directory recursively. Executed asynchronously.
|
||||||
* Executed asynchronously.
|
*
|
||||||
* @param directory Full path of the local directory to upload
|
* @param directory
|
||||||
* @param remoteDirectory Full path of the remote directory which the local
|
* Full path of the local directory to upload
|
||||||
* directory will be uploaded in
|
* @param remoteDirectory
|
||||||
|
* Full path of the remote directory which the local directory
|
||||||
|
* will be uploaded in
|
||||||
*/
|
*/
|
||||||
public static void uploadDirectoriesRecursively(File directory, String remoteDirectory) throws SftpException {
|
public static void uploadDirectoriesRecursively(File directory,
|
||||||
|
String remoteDirectory) throws SftpException {
|
||||||
// We execute the lengthy and time-consuming operation on a different
|
// We execute the lengthy and time-consuming operation on a different
|
||||||
// thread instead of the Event Dispatch Thread.
|
// thread instead of the Event Dispatch Thread.
|
||||||
// We use SwingWorker so any GUI changes requested by this thread will
|
// We use SwingWorker so any GUI changes requested by this thread will
|
||||||
@ -210,12 +227,11 @@ public class SshEngine {
|
|||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
uploadDirectoriesRecursively_aux(channelSftp, directory, remoteDirectory);
|
uploadDirectoriesRecursively_aux(channelSftp, directory,
|
||||||
}
|
remoteDirectory);
|
||||||
catch(SftpException sftpex) {
|
} catch (SftpException sftpex) {
|
||||||
// TODO maybe no permissions
|
// TODO maybe no permissions
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -227,26 +243,39 @@ public class SshEngine {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Private utility
|
* Private utility
|
||||||
|
*
|
||||||
* @param channel_aux
|
* @param channel_aux
|
||||||
* @param localPath
|
* @param localPath
|
||||||
* @param remoteDirectory
|
* @param remoteDirectory
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
private static void uploadDirectoriesRecursively_aux(ChannelSftp channel_aux, File localPath, String remoteDirectory) throws SftpException {
|
private static void uploadDirectoriesRecursively_aux(
|
||||||
|
ChannelSftp channel_aux, File localPath, String remoteDirectory)
|
||||||
|
throws SftpException {
|
||||||
if (localPath != null) {
|
if (localPath != null) {
|
||||||
String subDirectoryPath = Helper.combinePath(remoteDirectory, localPath.getName());
|
String subDirectoryPath = Helper.combinePath(remoteDirectory,
|
||||||
|
localPath.getName());
|
||||||
channel_aux.mkdir(subDirectoryPath);
|
channel_aux.mkdir(subDirectoryPath);
|
||||||
|
|
||||||
File[] files = localPath.listFiles();
|
File[] files = localPath.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
// Creates a thread for each file. If there are a lot of files
|
// Creates a thread for each file. If there are a lot of
|
||||||
// it may be resource-draining. Consider using a ThreadPool
|
// files
|
||||||
channel_aux.put(file.getAbsolutePath(), Helper.combinePath(subDirectoryPath, file.getName()), new GuifySftpProgressMonitor());
|
// it may be resource-draining. Consider using a
|
||||||
System.out.println("File: " + file.getAbsolutePath() + " uploaded to remote path: " + Helper.combinePath(subDirectoryPath, file.getName()));
|
// ThreadPool
|
||||||
|
channel_aux.put(file.getAbsolutePath(),
|
||||||
|
Helper.combinePath(subDirectoryPath,
|
||||||
|
file.getName()),
|
||||||
|
new GuifySftpProgressMonitor());
|
||||||
|
System.out.println("File: " + file.getAbsolutePath()
|
||||||
|
+ " uploaded to remote path: "
|
||||||
|
+ Helper.combinePath(subDirectoryPath,
|
||||||
|
file.getName()));
|
||||||
} else if (file.isDirectory()) {
|
} else if (file.isDirectory()) {
|
||||||
uploadDirectoriesRecursively_aux(channel_aux, file, subDirectoryPath);
|
uploadDirectoriesRecursively_aux(channel_aux, file,
|
||||||
|
subDirectoryPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,7 +286,6 @@ public class SshEngine {
|
|||||||
* ========== END SFTP get() and put() methods ==========
|
* ========== END SFTP get() and put() methods ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN File System operations ==========
|
* ========== BEGIN File System operations ==========
|
||||||
*/
|
*/
|
||||||
@ -269,11 +297,9 @@ public class SshEngine {
|
|||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.mkdir(path);
|
channelSftp.mkdir(path);
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -303,7 +329,8 @@ public class SshEngine {
|
|||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.put(new ByteArrayInputStream(content.getBytes()), pathToFile);
|
channelSftp.put(new ByteArrayInputStream(content.getBytes()),
|
||||||
|
pathToFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -312,18 +339,17 @@ public class SshEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rename(String oldPath, String newPath) throws SftpException {
|
public static void rename(String oldPath, String newPath)
|
||||||
|
throws SftpException {
|
||||||
ChannelSftp channelSftp = null;
|
ChannelSftp channelSftp = null;
|
||||||
try {
|
try {
|
||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.rename(oldPath, newPath);
|
channelSftp.rename(oldPath, newPath);
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -333,6 +359,7 @@ public class SshEngine {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty file in the specified remote file path
|
* Creates an empty file in the specified remote file path
|
||||||
|
*
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
public static void touch(String remoteFilePath) throws SftpException {
|
public static void touch(String remoteFilePath) throws SftpException {
|
||||||
@ -341,12 +368,11 @@ public class SshEngine {
|
|||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.put(new ByteArrayInputStream(new byte[0]), remoteFilePath);
|
channelSftp.put(new ByteArrayInputStream(new byte[0]),
|
||||||
}
|
remoteFilePath);
|
||||||
catch(SftpException sftpex) {
|
} catch (SftpException sftpex) {
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -361,11 +387,9 @@ public class SshEngine {
|
|||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.rm(remoteFilePath);
|
channelSftp.rm(remoteFilePath);
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -382,11 +406,9 @@ public class SshEngine {
|
|||||||
for (String remoteFilePath : remoteFilePaths) {
|
for (String remoteFilePath : remoteFilePaths) {
|
||||||
rm(remoteFilePath, channelSftp);
|
rm(remoteFilePath, channelSftp);
|
||||||
}
|
}
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -394,7 +416,8 @@ public class SshEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void rm(String remoteFilePath, ChannelSftp channelSftp) throws SftpException, JSchException {
|
private static void rm(String remoteFilePath, ChannelSftp channelSftp)
|
||||||
|
throws SftpException, JSchException {
|
||||||
channelSftp.rm(remoteFilePath);
|
channelSftp.rm(remoteFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,11 +428,9 @@ public class SshEngine {
|
|||||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
channelSftp.rmdir(remoteFilePath);
|
channelSftp.rmdir(remoteFilePath);
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -426,11 +447,9 @@ public class SshEngine {
|
|||||||
for (String remotePath : remotePaths) {
|
for (String remotePath : remotePaths) {
|
||||||
rmdir(remotePath, channelSftp);
|
rmdir(remotePath, channelSftp);
|
||||||
}
|
}
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (channelSftp != null)
|
if (channelSftp != null)
|
||||||
@ -438,12 +457,14 @@ public class SshEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void rmdir(String remotePath, ChannelSftp channelSftp) throws SftpException, JSchException {
|
private static void rmdir(String remotePath, ChannelSftp channelSftp)
|
||||||
|
throws SftpException, JSchException {
|
||||||
channelSftp.rmdir(remotePath);
|
channelSftp.rmdir(remotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Vector<ChannelSftp.LsEntry> ls(String path) throws SftpException{
|
public static Vector<ChannelSftp.LsEntry> ls(String path)
|
||||||
|
throws SftpException {
|
||||||
ChannelSftp channelSftp = null;
|
ChannelSftp channelSftp = null;
|
||||||
try {
|
try {
|
||||||
checkValidityOrCreateSession();
|
checkValidityOrCreateSession();
|
||||||
@ -451,13 +472,13 @@ public class SshEngine {
|
|||||||
channelSftp.connect();
|
channelSftp.connect();
|
||||||
Vector<ChannelSftp.LsEntry> entries = channelSftp.ls(path);
|
Vector<ChannelSftp.LsEntry> entries = channelSftp.ls(path);
|
||||||
// remove hidden directories (TODO create a setting for that)
|
// remove hidden directories (TODO create a setting for that)
|
||||||
entries.removeIf(entry -> entry.getFilename().equals(".") || entry.getFilename().equals("..") || entry.getFilename().startsWith("."));
|
entries.removeIf(entry -> entry.getFilename().equals(".")
|
||||||
|
|| entry.getFilename().equals("..")
|
||||||
|
|| entry.getFilename().startsWith("."));
|
||||||
return entries;
|
return entries;
|
||||||
}
|
} catch (SftpException sftpex) {
|
||||||
catch(SftpException sftpex) {
|
|
||||||
throw sftpex;
|
throw sftpex;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
@ -470,7 +491,6 @@ public class SshEngine {
|
|||||||
* ========== END File System operations ==========
|
* ========== END File System operations ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Other ==========
|
* ========== BEGIN Other ==========
|
||||||
*/
|
*/
|
||||||
@ -485,7 +505,8 @@ public class SshEngine {
|
|||||||
((ChannelExec) channel).setCommand(command);
|
((ChannelExec) channel).setCommand(command);
|
||||||
channel.connect();
|
channel.connect();
|
||||||
in = channel.getInputStream();
|
in = channel.getInputStream();
|
||||||
String returnText = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
String returnText = new String(in.readAllBytes(),
|
||||||
|
StandardCharsets.UTF_8);
|
||||||
in.close();
|
in.close();
|
||||||
// Remove possible \r\n at the end of the string
|
// Remove possible \r\n at the end of the string
|
||||||
returnText = returnText.replaceAll("[\r\n]+$", "").trim();
|
returnText = returnText.replaceAll("[\r\n]+$", "").trim();
|
||||||
@ -507,7 +528,6 @@ public class SshEngine {
|
|||||||
* ========== END Other ==========
|
* ========== END Other ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* When executing a command on a remote server using SSH with Jsch in Java, we
|
* When executing a command on a remote server using SSH with Jsch in Java, we
|
||||||
|
@ -2,8 +2,8 @@ package code;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* An object representing the transfer progress of a
|
* An object representing the transfer progress of a file between the server and
|
||||||
* file between the server and the host machine.
|
* the host machine.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TransferProgress {
|
public class TransferProgress {
|
||||||
|
@ -2,8 +2,7 @@ package code;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A class representing a
|
* A class representing a "tree -J" result
|
||||||
* "tree -J" result
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TreeNode {
|
public class TreeNode {
|
||||||
|
@ -7,74 +7,77 @@ import javax.swing.SwingUtilities;
|
|||||||
/**
|
/**
|
||||||
* FlowLayout subclass that fully supports wrapping of components.
|
* FlowLayout subclass that fully supports wrapping of components.
|
||||||
*/
|
*/
|
||||||
public class WrapLayout extends FlowLayout
|
public class WrapLayout extends FlowLayout {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>WrapLayout</code> with a left
|
* Constructs a new <code>WrapLayout</code> with a left alignment and a
|
||||||
* alignment and a default 5-unit horizontal and vertical gap.
|
* default 5-unit horizontal and vertical gap.
|
||||||
*/
|
*/
|
||||||
public WrapLayout()
|
public WrapLayout() {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>FlowLayout</code> with the specified
|
* Constructs a new <code>FlowLayout</code> with the specified alignment and
|
||||||
* alignment and a default 5-unit horizontal and vertical gap.
|
* a default 5-unit horizontal and vertical gap. The value of the alignment
|
||||||
* The value of the alignment argument must be one of
|
* argument must be one of <code>WrapLayout</code>, <code>WrapLayout</code>,
|
||||||
* <code>WrapLayout</code>, <code>WrapLayout</code>,
|
|
||||||
* or <code>WrapLayout</code>.
|
* or <code>WrapLayout</code>.
|
||||||
* @param align the alignment value
|
*
|
||||||
|
* @param align
|
||||||
|
* the alignment value
|
||||||
*/
|
*/
|
||||||
public WrapLayout(int align)
|
public WrapLayout(int align) {
|
||||||
{
|
|
||||||
super(align);
|
super(align);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new flow layout manager with the indicated alignment
|
* Creates a new flow layout manager with the indicated alignment and the
|
||||||
* and the indicated horizontal and vertical gaps.
|
* indicated horizontal and vertical gaps.
|
||||||
* <p>
|
* <p>
|
||||||
* The value of the alignment argument must be one of
|
* The value of the alignment argument must be one of
|
||||||
* <code>WrapLayout</code>, <code>WrapLayout</code>,
|
* <code>WrapLayout</code>, <code>WrapLayout</code>, or
|
||||||
* or <code>WrapLayout</code>.
|
* <code>WrapLayout</code>.
|
||||||
* @param align the alignment value
|
*
|
||||||
* @param hgap the horizontal gap between components
|
* @param align
|
||||||
* @param vgap the vertical gap between components
|
* the alignment value
|
||||||
|
* @param hgap
|
||||||
|
* the horizontal gap between components
|
||||||
|
* @param vgap
|
||||||
|
* the vertical gap between components
|
||||||
*/
|
*/
|
||||||
public WrapLayout(int align, int hgap, int vgap)
|
public WrapLayout(int align, int hgap, int vgap) {
|
||||||
{
|
|
||||||
super(align, hgap, vgap);
|
super(align, hgap, vgap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the preferred dimensions for this layout given the
|
* Returns the preferred dimensions for this layout given the <i>visible</i>
|
||||||
* <i>visible</i> components in the specified target container.
|
* components in the specified target container.
|
||||||
* @param target the component which needs to be laid out
|
*
|
||||||
* @return the preferred dimensions to lay out the
|
* @param target
|
||||||
* subcomponents of the specified container
|
* the component which needs to be laid out
|
||||||
|
* @return the preferred dimensions to lay out the subcomponents of the
|
||||||
|
* specified container
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Dimension preferredLayoutSize(Container target)
|
public Dimension preferredLayoutSize(Container target) {
|
||||||
{
|
|
||||||
return layoutSize(target, true);
|
return layoutSize(target, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the minimum dimensions needed to layout the <i>visible</i>
|
* Returns the minimum dimensions needed to layout the <i>visible</i>
|
||||||
* components contained in the specified target container.
|
* components contained in the specified target container.
|
||||||
* @param target the component which needs to be laid out
|
*
|
||||||
* @return the minimum dimensions to lay out the
|
* @param target
|
||||||
* subcomponents of the specified container
|
* the component which needs to be laid out
|
||||||
|
* @return the minimum dimensions to lay out the subcomponents of the
|
||||||
|
* specified container
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Dimension minimumLayoutSize(Container target)
|
public Dimension minimumLayoutSize(Container target) {
|
||||||
{
|
|
||||||
Dimension minimum = layoutSize(target, false);
|
Dimension minimum = layoutSize(target, false);
|
||||||
minimum.width -= (getHgap() + 1);
|
minimum.width -= (getHgap() + 1);
|
||||||
return minimum;
|
return minimum;
|
||||||
@ -84,23 +87,24 @@ public class WrapLayout extends FlowLayout
|
|||||||
* Returns the minimum or preferred dimension needed to layout the target
|
* Returns the minimum or preferred dimension needed to layout the target
|
||||||
* container.
|
* container.
|
||||||
*
|
*
|
||||||
* @param target target to get layout size for
|
* @param target
|
||||||
* @param preferred should preferred size be calculated
|
* target to get layout size for
|
||||||
|
* @param preferred
|
||||||
|
* should preferred size be calculated
|
||||||
* @return the dimension to layout the target container
|
* @return the dimension to layout the target container
|
||||||
*/
|
*/
|
||||||
private Dimension layoutSize(Container target, boolean preferred)
|
private Dimension layoutSize(Container target, boolean preferred) {
|
||||||
{
|
synchronized (target.getTreeLock()) {
|
||||||
synchronized (target.getTreeLock())
|
|
||||||
{
|
|
||||||
// Each row must fit with the width allocated to the containter.
|
// Each row must fit with the width allocated to the containter.
|
||||||
// When the container width = 0, the preferred width of the container
|
// When the container width = 0, the preferred width of the
|
||||||
|
// container
|
||||||
// has not yet been calculated so lets ask for the maximum.
|
// has not yet been calculated so lets ask for the maximum.
|
||||||
|
|
||||||
int targetWidth = target.getSize().width;
|
int targetWidth = target.getSize().width;
|
||||||
Container container = target;
|
Container container = target;
|
||||||
|
|
||||||
while (container.getSize().width == 0 && container.getParent() != null)
|
while (container.getSize().width == 0
|
||||||
{
|
&& container.getParent() != null) {
|
||||||
container = container.getParent();
|
container = container.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +116,8 @@ public class WrapLayout extends FlowLayout
|
|||||||
int hgap = getHgap();
|
int hgap = getHgap();
|
||||||
int vgap = getVgap();
|
int vgap = getVgap();
|
||||||
Insets insets = target.getInsets();
|
Insets insets = target.getInsets();
|
||||||
int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
|
int horizontalInsetsAndGap = insets.left + insets.right
|
||||||
|
+ (hgap * 2);
|
||||||
int maxWidth = targetWidth - horizontalInsetsAndGap;
|
int maxWidth = targetWidth - horizontalInsetsAndGap;
|
||||||
|
|
||||||
// Fit components into the allowed width
|
// Fit components into the allowed width
|
||||||
@ -123,18 +128,17 @@ public class WrapLayout extends FlowLayout
|
|||||||
|
|
||||||
int nmembers = target.getComponentCount();
|
int nmembers = target.getComponentCount();
|
||||||
|
|
||||||
for (int i = 0; i < nmembers; i++)
|
for (int i = 0; i < nmembers; i++) {
|
||||||
{
|
|
||||||
Component m = target.getComponent(i);
|
Component m = target.getComponent(i);
|
||||||
|
|
||||||
if (m.isVisible())
|
if (m.isVisible()) {
|
||||||
{
|
Dimension d = preferred
|
||||||
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
|
? m.getPreferredSize()
|
||||||
|
: m.getMinimumSize();
|
||||||
|
|
||||||
// Can't add the component to current row. Start a new row.
|
// Can't add the component to current row. Start a new row.
|
||||||
|
|
||||||
if (rowWidth + d.width > maxWidth)
|
if (rowWidth + d.width > maxWidth) {
|
||||||
{
|
|
||||||
addRow(dim, rowWidth, rowHeight);
|
addRow(dim, rowWidth, rowHeight);
|
||||||
rowWidth = 0;
|
rowWidth = 0;
|
||||||
rowHeight = 0;
|
rowHeight = 0;
|
||||||
@ -142,8 +146,7 @@ public class WrapLayout extends FlowLayout
|
|||||||
|
|
||||||
// Add a horizontal gap for all components after the first
|
// Add a horizontal gap for all components after the first
|
||||||
|
|
||||||
if (rowWidth != 0)
|
if (rowWidth != 0) {
|
||||||
{
|
|
||||||
rowWidth += hgap;
|
rowWidth += hgap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,10 +165,10 @@ public class WrapLayout extends FlowLayout
|
|||||||
// target containter so shrinking the container size works
|
// target containter so shrinking the container size works
|
||||||
// correctly. Removing the horizontal gap is an easy way to do this.
|
// correctly. Removing the horizontal gap is an easy way to do this.
|
||||||
|
|
||||||
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
|
Container scrollPane = SwingUtilities
|
||||||
|
.getAncestorOfClass(JScrollPane.class, target);
|
||||||
|
|
||||||
if (scrollPane != null && target.isValid())
|
if (scrollPane != null && target.isValid()) {
|
||||||
{
|
|
||||||
dim.width -= (hgap + 1);
|
dim.width -= (hgap + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,19 +177,19 @@ public class WrapLayout extends FlowLayout
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A new row has been completed. Use the dimensions of this row
|
* A new row has been completed. Use the dimensions of this row to update
|
||||||
* to update the preferred size for the container.
|
* the preferred size for the container.
|
||||||
*
|
*
|
||||||
* @param dim update the width and height when appropriate
|
* @param dim update the width and height when appropriate
|
||||||
|
*
|
||||||
* @param rowWidth the width of the row to add
|
* @param rowWidth the width of the row to add
|
||||||
|
*
|
||||||
* @param rowHeight the height of the row to add
|
* @param rowHeight the height of the row to add
|
||||||
*/
|
*/
|
||||||
private void addRow(Dimension dim, int rowWidth, int rowHeight)
|
private void addRow(Dimension dim, int rowWidth, int rowHeight) {
|
||||||
{
|
|
||||||
dim.width = Math.max(dim.width, rowWidth);
|
dim.width = Math.max(dim.width, rowWidth);
|
||||||
|
|
||||||
if (dim.height > 0)
|
if (dim.height > 0) {
|
||||||
{
|
|
||||||
dim.height += getVgap();
|
dim.height += getVgap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ public class DesktopController {
|
|||||||
|
|
||||||
public DesktopController() {
|
public DesktopController() {
|
||||||
try {
|
try {
|
||||||
frame = (IDesktopFrame) JFrameFactory.createJFrame(JFrameFactory.DESKTOP, this);
|
frame = (IDesktopFrame) JFrameFactory
|
||||||
|
.createJFrame(JFrameFactory.DESKTOP, this);
|
||||||
frame.drawComponentsForDirectory("~");
|
frame.drawComponentsForDirectory("~");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,6 @@ public class DesktopController {
|
|||||||
* ========== END Constructors ==========
|
* ========== END Constructors ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Getters and Setters ==========
|
* ========== BEGIN Getters and Setters ==========
|
||||||
*/
|
*/
|
||||||
@ -62,8 +61,7 @@ public class DesktopController {
|
|||||||
public void setCurrentWorkingDirectory(String directory) {
|
public void setCurrentWorkingDirectory(String directory) {
|
||||||
if (directory.equals("~")) {
|
if (directory.equals("~")) {
|
||||||
currentWorkingDirectory = SshEngine.executeCommand("pwd");
|
currentWorkingDirectory = SshEngine.executeCommand("pwd");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
currentWorkingDirectory = directory.trim();
|
currentWorkingDirectory = directory.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,8 +79,7 @@ public class DesktopController {
|
|||||||
|
|
||||||
if (directory.equals("~")) {
|
if (directory.equals("~")) {
|
||||||
lastSafeDirectory = SshEngine.executeCommand("pwd");
|
lastSafeDirectory = SshEngine.executeCommand("pwd");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
lastSafeDirectory = directory.trim();
|
lastSafeDirectory = directory.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +88,6 @@ public class DesktopController {
|
|||||||
* ========== END Getters and Setters ==========
|
* ========== END Getters and Setters ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Create desktop helper methods ==========
|
* ========== BEGIN Create desktop helper methods ==========
|
||||||
*/
|
*/
|
||||||
@ -109,19 +105,20 @@ public class DesktopController {
|
|||||||
// Might throw Invalid JSON exception because of incorrect
|
// Might throw Invalid JSON exception because of incorrect
|
||||||
// JSON output returned from tree:
|
// JSON output returned from tree:
|
||||||
// https://gitlab.com/OldManProgrammer/unix-tree/-/issues/11
|
// https://gitlab.com/OldManProgrammer/unix-tree/-/issues/11
|
||||||
// Fixed in tree 2.1.1 https://gitlab.com/OldManProgrammer/unix-tree/-/commit/84fa3ddff51b30835a0f9c4a9e4c9225970f9aff
|
// Fixed in tree 2.1.1
|
||||||
|
// https://gitlab.com/OldManProgrammer/unix-tree/-/commit/84fa3ddff51b30835a0f9c4a9e4c9225970f9aff
|
||||||
//
|
//
|
||||||
// For this reason, we temporarily explicitly avoid it to happen
|
// For this reason, we temporarily explicitly avoid it to happen
|
||||||
jsonTree = jsonTree.replace("}{\"error\"", "},{\"error\"");
|
jsonTree = jsonTree.replace("}{\"error\"", "},{\"error\"");
|
||||||
tree = new Gson().fromJson(jsonTree, TreeNode[].class);
|
tree = new Gson().fromJson(jsonTree, TreeNode[].class);
|
||||||
return tree[0];
|
return tree[0];
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch(Exception ex) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector<ChannelSftp.LsEntry> getDirectoryElements() throws SftpException {
|
public Vector<ChannelSftp.LsEntry> getDirectoryElements()
|
||||||
|
throws SftpException {
|
||||||
return SshEngine.ls(currentWorkingDirectory);
|
return SshEngine.ls(currentWorkingDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,15 +126,17 @@ public class DesktopController {
|
|||||||
* ========== END Create desktop helper methods ==========
|
* ========== END Create desktop helper methods ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Download and Upload section ==========
|
* ========== BEGIN Download and Upload section ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads a file from the remote server to the local machine
|
* Downloads a file from the remote server to the local machine
|
||||||
* @param sourcePath Remote file's full path
|
*
|
||||||
* @param destinationPath Local file's full path
|
* @param sourcePath
|
||||||
|
* Remote file's full path
|
||||||
|
* @param destinationPath
|
||||||
|
* Local file's full path
|
||||||
*/
|
*/
|
||||||
public void downloadFile(String sourcePath, String destinationPath) {
|
public void downloadFile(String sourcePath, String destinationPath) {
|
||||||
SshEngine.downloadFile(sourcePath, destinationPath);
|
SshEngine.downloadFile(sourcePath, destinationPath);
|
||||||
@ -145,18 +144,19 @@ public class DesktopController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads files and folders to the remote server
|
* Uploads files and folders to the remote server
|
||||||
|
*
|
||||||
* @param selectedNodes
|
* @param selectedNodes
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
public void uploadToRemoteServer(File[] selectedNodes) throws SftpException {
|
public void uploadToRemoteServer(File[] selectedNodes)
|
||||||
|
throws SftpException {
|
||||||
if (selectedNodes.length > 0) {
|
if (selectedNodes.length > 0) {
|
||||||
List<File> selectedFiles = new ArrayList<File>();
|
List<File> selectedFiles = new ArrayList<File>();
|
||||||
List<File> selectedDirectories = new ArrayList<File>();
|
List<File> selectedDirectories = new ArrayList<File>();
|
||||||
for (java.io.File file : selectedNodes) {
|
for (java.io.File file : selectedNodes) {
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
selectedFiles.add(file);
|
selectedFiles.add(file);
|
||||||
}
|
} else if (file.isDirectory()) {
|
||||||
else if(file.isDirectory()) {
|
|
||||||
selectedDirectories.add(file);
|
selectedDirectories.add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,10 +165,10 @@ public class DesktopController {
|
|||||||
SshEngine.uploadFile(file, this.getCurrentWorkingDirectory());
|
SshEngine.uploadFile(file, this.getCurrentWorkingDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (selectedDirectories.size() > 0) {
|
if (selectedDirectories.size() > 0) {
|
||||||
for (File directory : selectedDirectories) {
|
for (File directory : selectedDirectories) {
|
||||||
SshEngine.uploadDirectoriesRecursively(directory, this.getCurrentWorkingDirectory());
|
SshEngine.uploadDirectoriesRecursively(directory,
|
||||||
|
this.getCurrentWorkingDirectory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +178,6 @@ public class DesktopController {
|
|||||||
* ========== END Download and Upload section ==========
|
* ========== END Download and Upload section ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Selected Nodes section ==========
|
* ========== BEGIN Selected Nodes section ==========
|
||||||
*/
|
*/
|
||||||
@ -219,10 +218,15 @@ public class DesktopController {
|
|||||||
|
|
||||||
for (IDirectoryNodeButton node : selectedNodes) {
|
for (IDirectoryNodeButton node : selectedNodes) {
|
||||||
if (node.getNode().getAttrs().isDir()) {
|
if (node.getNode().getAttrs().isDir()) {
|
||||||
directoriesToDelete.add(Helper.combinePath(getCurrentWorkingDirectory(), node.getNode().getFilename()).replace("\"", "\\\""));
|
directoriesToDelete.add(Helper
|
||||||
}
|
.combinePath(getCurrentWorkingDirectory(),
|
||||||
else {
|
node.getNode().getFilename())
|
||||||
filesToDelete.add(Helper.combinePath(getCurrentWorkingDirectory(), node.getNode().getFilename()).replace("\"", "\\\""));
|
.replace("\"", "\\\""));
|
||||||
|
} else {
|
||||||
|
filesToDelete.add(Helper
|
||||||
|
.combinePath(getCurrentWorkingDirectory(),
|
||||||
|
node.getNode().getFilename())
|
||||||
|
.replace("\"", "\\\""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,11 +241,11 @@ public class DesktopController {
|
|||||||
List<String> files = new ArrayList<String>();
|
List<String> files = new ArrayList<String>();
|
||||||
String tmp;
|
String tmp;
|
||||||
for (IDirectoryNodeButton node : selectedNodes) {
|
for (IDirectoryNodeButton node : selectedNodes) {
|
||||||
tmp = Helper.combinePath(getCurrentWorkingDirectory(), node.getNode().getFilename());
|
tmp = Helper.combinePath(getCurrentWorkingDirectory(),
|
||||||
|
node.getNode().getFilename());
|
||||||
if (node.getNode().getAttrs().isDir()) {
|
if (node.getNode().getAttrs().isDir()) {
|
||||||
directories.add(tmp);
|
directories.add(tmp);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
files.add(tmp);
|
files.add(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +263,6 @@ public class DesktopController {
|
|||||||
* ========== END Selected Nodes section ==========
|
* ========== END Selected Nodes section ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN CutCopyPasteController controller ==========
|
* ========== BEGIN CutCopyPasteController controller ==========
|
||||||
*/
|
*/
|
||||||
@ -268,19 +271,23 @@ public class DesktopController {
|
|||||||
private List<String> sources = new ArrayList<String>();
|
private List<String> sources = new ArrayList<String>();
|
||||||
private int selectedOperation = Constants.Constants_FSOperations.NONE;
|
private int selectedOperation = Constants.Constants_FSOperations.NONE;
|
||||||
|
|
||||||
public void startCopying(List<IDirectoryNodeButton> selectedNodes, String currentPath) {
|
public void startCopying(List<IDirectoryNodeButton> selectedNodes,
|
||||||
|
String currentPath) {
|
||||||
String fullPath = null;
|
String fullPath = null;
|
||||||
for (IDirectoryNodeButton nodeBtn : selectedNodes) {
|
for (IDirectoryNodeButton nodeBtn : selectedNodes) {
|
||||||
fullPath = Helper.combinePath(currentPath, nodeBtn.getNode().getFilename());
|
fullPath = Helper.combinePath(currentPath,
|
||||||
|
nodeBtn.getNode().getFilename());
|
||||||
sources.add(fullPath);
|
sources.add(fullPath);
|
||||||
}
|
}
|
||||||
selectedOperation = Constants.Constants_FSOperations.COPY;
|
selectedOperation = Constants.Constants_FSOperations.COPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startCuttying(List<IDirectoryNodeButton> selectedNodes, String currentPath) {
|
public void startCuttying(List<IDirectoryNodeButton> selectedNodes,
|
||||||
|
String currentPath) {
|
||||||
String fullPath = null;
|
String fullPath = null;
|
||||||
for (IDirectoryNodeButton nodeBtn : selectedNodes) {
|
for (IDirectoryNodeButton nodeBtn : selectedNodes) {
|
||||||
fullPath = Helper.combinePath(currentPath, nodeBtn.getNode().getFilename());
|
fullPath = Helper.combinePath(currentPath,
|
||||||
|
nodeBtn.getNode().getFilename());
|
||||||
sources.add(fullPath);
|
sources.add(fullPath);
|
||||||
}
|
}
|
||||||
selectedOperation = Constants.Constants_FSOperations.CUT;
|
selectedOperation = Constants.Constants_FSOperations.CUT;
|
||||||
@ -342,15 +349,15 @@ public class DesktopController {
|
|||||||
* ========== END CutCopyPasteController controller ==========
|
* ========== END CutCopyPasteController controller ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN File System Operations ==========
|
* ========== BEGIN File System Operations ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new folder
|
* Creates a new folder
|
||||||
* @param newFolderPath Folder's path
|
*
|
||||||
|
* @param newFolderPath
|
||||||
|
* Folder's path
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
public void mkdir(String newFolderPath) throws SftpException {
|
public void mkdir(String newFolderPath) throws SftpException {
|
||||||
@ -359,7 +366,9 @@ public class DesktopController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a file in the remote file path
|
* Creates a file in the remote file path
|
||||||
* @param remoteFilePath remote file path
|
*
|
||||||
|
* @param remoteFilePath
|
||||||
|
* remote file path
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
public void touch(String remoteFilePath) throws SftpException {
|
public void touch(String remoteFilePath) throws SftpException {
|
||||||
@ -368,11 +377,15 @@ public class DesktopController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Renames a file
|
* Renames a file
|
||||||
* @param oldNamePath Path of the old name
|
*
|
||||||
* @param newNamePath Path of the new name
|
* @param oldNamePath
|
||||||
|
* Path of the old name
|
||||||
|
* @param newNamePath
|
||||||
|
* Path of the new name
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
public void rename(String oldNamePath, String newNamePath) throws SftpException {
|
public void rename(String oldNamePath, String newNamePath)
|
||||||
|
throws SftpException {
|
||||||
SshEngine.rename(oldNamePath, newNamePath);
|
SshEngine.rename(oldNamePath, newNamePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,43 +399,46 @@ public class DesktopController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a remote file path, opens a graphical notepad for it
|
* Given a remote file path, opens a graphical notepad for it
|
||||||
* @param filePath remote file path to display in the notepad
|
*
|
||||||
|
* @param filePath
|
||||||
|
* remote file path to display in the notepad
|
||||||
*/
|
*/
|
||||||
public void openNotepadForFile(String filePath) {
|
public void openNotepadForFile(String filePath) {
|
||||||
new NotepadController(filePath).show();
|
new NotepadController(filePath).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes resources which need to be freed before exiting
|
* Disposes resources which need to be freed before exiting the application
|
||||||
* the application
|
|
||||||
*/
|
*/
|
||||||
public void disposeResources() {
|
public void disposeResources() {
|
||||||
SshEngine.disconnectSession();
|
SshEngine.disconnectSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This method is deprecated.
|
* @deprecated This method is deprecated. Catch SftpException and look for
|
||||||
* Catch SftpException
|
* "Permission denied" instead. This prevents unnecessary
|
||||||
* and look for "Permission denied" instead. This prevents
|
* overhead
|
||||||
* unnecessary overhead
|
|
||||||
*/
|
*/
|
||||||
public boolean isReadable(String path) {
|
public boolean isReadable(String path) {
|
||||||
StringBuilder command = new StringBuilder();
|
StringBuilder command = new StringBuilder();
|
||||||
command.append("[ -r \"");
|
command.append("[ -r \"");
|
||||||
command.append(path.equals("~") ? SshEngine.executeCommand("pwd").replace("\"", "\\\"") : path.replace("\"", "\\\""));
|
command.append(path.equals("~")
|
||||||
|
? SshEngine.executeCommand("pwd").replace("\"", "\\\"")
|
||||||
|
: path.replace("\"", "\\\""));
|
||||||
command.append("\" ] && echo 1 || echo 0"); // short circuiting
|
command.append("\" ] && echo 1 || echo 0"); // short circuiting
|
||||||
return SshEngine.executeCommand(command.toString()).trim().equals("1");
|
return SshEngine.executeCommand(command.toString()).trim().equals("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This method is deprecated.
|
* @deprecated This method is deprecated. Catch SftpException and look for
|
||||||
* Catch SftpException
|
* "Permission denied" instead
|
||||||
* and look for "Permission denied" instead
|
|
||||||
*/
|
*/
|
||||||
public boolean isWriteable(String path) {
|
public boolean isWriteable(String path) {
|
||||||
StringBuilder command = new StringBuilder();
|
StringBuilder command = new StringBuilder();
|
||||||
command.append("[ -w \"");
|
command.append("[ -w \"");
|
||||||
command.append(path.equals("~") ? SshEngine.executeCommand("pwd").replace("\"", "\\\"") : path.replace("\"", "\\\""));
|
command.append(path.equals("~")
|
||||||
|
? SshEngine.executeCommand("pwd").replace("\"", "\\\"")
|
||||||
|
: path.replace("\"", "\\\""));
|
||||||
command.append("\" ] && echo 1 || echo 0"); // short circuiting
|
command.append("\" ] && echo 1 || echo 0"); // short circuiting
|
||||||
return SshEngine.executeCommand(command.toString()).trim().equals("1");
|
return SshEngine.executeCommand(command.toString()).trim().equals("1");
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@ public class FindAndReplaceController {
|
|||||||
public FindAndReplaceController(IGenericTextArea textArea) {
|
public FindAndReplaceController(IGenericTextArea textArea) {
|
||||||
this.textArea = textArea;
|
this.textArea = textArea;
|
||||||
try {
|
try {
|
||||||
frame = (IFindAndReplaceFrame) JFrameFactory.createJFrame(IFrameFactory.FIND_AND_REPLACE, this);
|
frame = (IFindAndReplaceFrame) JFrameFactory
|
||||||
|
.createJFrame(IFrameFactory.FIND_AND_REPLACE, this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -23,8 +24,10 @@ public class FindAndReplaceController {
|
|||||||
* Show frame centered to parent
|
* Show frame centered to parent
|
||||||
*/
|
*/
|
||||||
public void showAtTheCenterOfFrame(INotepadFrame notepadFrame) {
|
public void showAtTheCenterOfFrame(INotepadFrame notepadFrame) {
|
||||||
int childX = notepadFrame.getX() + (notepadFrame.getWidth() - frame.getWidth()) / 2;
|
int childX = notepadFrame.getX()
|
||||||
int childY = notepadFrame.getY() + (notepadFrame.getHeight() - frame.getHeight()) / 2;
|
+ (notepadFrame.getWidth() - frame.getWidth()) / 2;
|
||||||
|
int childY = notepadFrame.getY()
|
||||||
|
+ (notepadFrame.getHeight() - frame.getHeight()) / 2;
|
||||||
frame.setLocation(childX, childY);
|
frame.setLocation(childX, childY);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
@ -47,17 +50,17 @@ public class FindAndReplaceController {
|
|||||||
|
|
||||||
if (textArea.hasHighlightedText()) {
|
if (textArea.hasHighlightedText()) {
|
||||||
cutAt = textArea.getSelectionStart();
|
cutAt = textArea.getSelectionStart();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cutAt = textArea.getCaretPosition();
|
cutAt = textArea.getCaretPosition();
|
||||||
}
|
}
|
||||||
String firstPart = text.substring(0, cutAt);
|
String firstPart = text.substring(0, cutAt);
|
||||||
int previousIndex = firstPart.lastIndexOf(searchText, firstPart.length() - 1);
|
int previousIndex = firstPart.lastIndexOf(searchText,
|
||||||
|
firstPart.length() - 1);
|
||||||
if (previousIndex != -1) {
|
if (previousIndex != -1) {
|
||||||
textArea.selectText(previousIndex, previousIndex + searchText.length());
|
textArea.selectText(previousIndex,
|
||||||
|
previousIndex + searchText.length());
|
||||||
return previousIndex;
|
return previousIndex;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +69,8 @@ public class FindAndReplaceController {
|
|||||||
int index = findNext(toReplace);
|
int index = findNext(toReplace);
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
textArea.replaceRange(replaceWith, index, index + toReplace.length());
|
textArea.replaceRange(replaceWith, index,
|
||||||
|
index + toReplace.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
|
@ -15,14 +15,15 @@ public class LoginController {
|
|||||||
|
|
||||||
public LoginController() {
|
public LoginController() {
|
||||||
try {
|
try {
|
||||||
frame = (ILoginFrame) JFrameFactory.createJFrame(IFrameFactory.LOGIN, this);
|
frame = (ILoginFrame) JFrameFactory
|
||||||
}
|
.createJFrame(IFrameFactory.LOGIN, this);
|
||||||
catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean Login(String host, String username, String password, String port) throws IllegalArgumentException {
|
public boolean Login(String host, String username, String password,
|
||||||
|
String port) throws IllegalArgumentException {
|
||||||
LoginCredentials.host = host;
|
LoginCredentials.host = host;
|
||||||
LoginCredentials.username = username;
|
LoginCredentials.username = username;
|
||||||
LoginCredentials.password = password;
|
LoginCredentials.password = password;
|
||||||
@ -32,13 +33,13 @@ public class LoginController {
|
|||||||
frame.setVisible(false);
|
frame.setVisible(false);
|
||||||
new DesktopController().showFrame(true);;
|
new DesktopController().showFrame(true);;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ValidateInput(String host, String username, String password, String port) throws IllegalArgumentException {
|
public void ValidateInput(String host, String username, String password,
|
||||||
|
String port) throws IllegalArgumentException {
|
||||||
|
|
||||||
// Host Validation. Consider its necessity.
|
// Host Validation. Consider its necessity.
|
||||||
try {
|
try {
|
||||||
@ -50,8 +51,7 @@ public class LoginController {
|
|||||||
// Port Validation
|
// Port Validation
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(port);
|
Integer.parseInt(port);
|
||||||
}
|
} catch (NumberFormatException ex) {
|
||||||
catch(NumberFormatException ex) {
|
|
||||||
throw new IllegalArgumentException("Invalid port number", ex);
|
throw new IllegalArgumentException("Invalid port number", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,8 @@ public class NotepadController {
|
|||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
initialText = SshEngine.readFile(filePath);
|
initialText = SshEngine.readFile(filePath);
|
||||||
try {
|
try {
|
||||||
notepadFrame = (INotepadFrame) JFrameFactory.createJFrame(IFrameFactory.NOTEPAD, this);
|
notepadFrame = (INotepadFrame) JFrameFactory
|
||||||
|
.createJFrame(IFrameFactory.NOTEPAD, this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
@ -30,39 +30,53 @@ public class QueueController implements Observer{
|
|||||||
// Executed by the EDT
|
// Executed by the EDT
|
||||||
public QueueController() {
|
public QueueController() {
|
||||||
try {
|
try {
|
||||||
frame = (IQueueFrame) JFrameFactory.createJFrame(IFrameFactory.QUEUE, this);
|
frame = (IQueueFrame) JFrameFactory
|
||||||
|
.createJFrame(IFrameFactory.QUEUE, this);
|
||||||
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
|
||||||
|
|
||||||
// Register observer of the changes
|
// Register observer of the changes
|
||||||
QueueEventManager.getInstance().addObserver(this);
|
QueueEventManager.getInstance().addObserver(this);
|
||||||
|
|
||||||
// Get previous enqueued elements. Do not place before addObserver(this) or some
|
// Get previous enqueued elements. Do not place before addObserver(this)
|
||||||
|
// or some
|
||||||
// transfers could go lost.
|
// transfers could go lost.
|
||||||
//
|
//
|
||||||
// A necessary but not sufficient condition in order to claim that the Queue
|
// A necessary but not sufficient condition in order to claim that the
|
||||||
// works well, is that when it gets opened at time x, all the non-finished
|
// Queue
|
||||||
|
// works well, is that when it gets opened at time x, all the
|
||||||
|
// non-finished
|
||||||
// transfers initiated in a time t such that t < x must be shown
|
// transfers initiated in a time t such that t < x must be shown
|
||||||
// in the table.
|
// in the table.
|
||||||
// More specifically, x represents the time of completion of the instruction
|
// More specifically, x represents the time of completion of the
|
||||||
|
// instruction
|
||||||
// QueueEventManager.getInstance().addObserver(this); as
|
// QueueEventManager.getInstance().addObserver(this); as
|
||||||
// any subsequent transfer initiated after this point will be guaranteed to
|
// any subsequent transfer initiated after this point will be guaranteed
|
||||||
|
// to
|
||||||
// be shown in the table (handled by the "update()" method).
|
// be shown in the table (handled by the "update()" method).
|
||||||
//
|
//
|
||||||
// Having understood this, we may now suppose t1 to be the time of completion of the
|
// Having understood this, we may now suppose t1 to be the time of
|
||||||
|
// completion of the
|
||||||
// instruction QueueEventManager.getInstance().getQueue() and t2 to be
|
// instruction QueueEventManager.getInstance().getQueue() and t2 to be
|
||||||
// the time of completion of the instruction
|
// the time of completion of the instruction
|
||||||
// QueueEventManager.getInstance().addObserver(this) where t1 < t2.
|
// QueueEventManager.getInstance().addObserver(this) where t1 < t2.
|
||||||
// This would've meant that any transfer initiated in a time t such that
|
// This would've meant that any transfer initiated in a time t such that
|
||||||
// t1 < t < t2 would not have been adequately processed as "getQueue()" was
|
// t1 < t < t2 would not have been adequately processed as "getQueue()"
|
||||||
// already executed, and "addObserver(this)" would not have been performed yet,
|
// was
|
||||||
// making the transfer not visible in the queue when the Queue frame would've
|
// already executed, and "addObserver(this)" would not have been
|
||||||
|
// performed yet,
|
||||||
|
// making the transfer not visible in the queue when the Queue frame
|
||||||
|
// would've
|
||||||
// been opened.
|
// been opened.
|
||||||
//
|
//
|
||||||
// One could argue that when any chunk of data is transferred at any time t
|
// One could argue that when any chunk of data is transferred at any
|
||||||
// where t > t2, the update() method will be called, showing the transfer in
|
// time t
|
||||||
// the queue. It's not guaranteed that this happens (as it may encounter an
|
// where t > t2, the update() method will be called, showing the
|
||||||
// error before t2 and after t1 or simply in may complete in this time frame)
|
// transfer in
|
||||||
|
// the queue. It's not guaranteed that this happens (as it may encounter
|
||||||
|
// an
|
||||||
|
// error before t2 and after t1 or simply in may complete in this time
|
||||||
|
// frame)
|
||||||
|
|
||||||
TransferProgress[] queued = QueueEventManager.getInstance().getQueue();
|
TransferProgress[] queued = QueueEventManager.getInstance().getQueue();
|
||||||
for (TransferProgress transferProgress : queued) {
|
for (TransferProgress transferProgress : queued) {
|
||||||
@ -84,7 +98,8 @@ public class QueueController implements Observer{
|
|||||||
// denoted as (update(o, arg)_1 , update(o, arg)_2) having the same
|
// denoted as (update(o, arg)_1 , update(o, arg)_2) having the same
|
||||||
// object "arg", it holds that
|
// object "arg", it holds that
|
||||||
// ((TransferProgress)arg).getTransferredBytes() evaluated during
|
// ((TransferProgress)arg).getTransferredBytes() evaluated during
|
||||||
// update(o, arg)_1 is less or equal than ((TransferProgress)arg).getTransferredBytes()
|
// update(o, arg)_1 is less or equal than
|
||||||
|
// ((TransferProgress)arg).getTransferredBytes()
|
||||||
// evaluated during update(o, arg)_2.
|
// evaluated during update(o, arg)_2.
|
||||||
// In simple words, if update() is called at time t1 and at time t2,
|
// In simple words, if update() is called at time t1 and at time t2,
|
||||||
// where arg is the same TransferProgress object, then the second time
|
// where arg is the same TransferProgress object, then the second time
|
||||||
@ -93,7 +108,8 @@ public class QueueController implements Observer{
|
|||||||
// than the value of
|
// than the value of
|
||||||
// transferProgress.getTransferredBytes() evaluated the first time.
|
// transferProgress.getTransferredBytes() evaluated the first time.
|
||||||
// This happens as the transfer of a single object is an operation executed
|
// This happens as the transfer of a single object is an operation executed
|
||||||
// on a single thread, hence any update will have a getTransferredBytes() greater
|
// on a single thread, hence any update will have a getTransferredBytes()
|
||||||
|
// greater
|
||||||
// or equal than the previous one.
|
// or equal than the previous one.
|
||||||
//
|
//
|
||||||
// Keep also in mind that SwingUtilities.invokeLater() called at time t1
|
// Keep also in mind that SwingUtilities.invokeLater() called at time t1
|
||||||
@ -107,21 +123,25 @@ public class QueueController implements Observer{
|
|||||||
// will go down (e.g. from 50% to 49%), but this would be true even if
|
// will go down (e.g. from 50% to 49%), but this would be true even if
|
||||||
// the concept described above would be false. This happens because
|
// the concept described above would be false. This happens because
|
||||||
// the TransferProgress
|
// the TransferProgress
|
||||||
// handled by manageTransferProgress will always have the latest updated values
|
// handled by manageTransferProgress will always have the latest updated
|
||||||
|
// values
|
||||||
// for that specific object, as it is shared with the thread
|
// for that specific object, as it is shared with the thread
|
||||||
// which continuously updates it.
|
// which continuously updates it.
|
||||||
// We do not need any locks as no race conditions
|
// We do not need any locks as no race conditions
|
||||||
// can happen because in the EDT thread we only read said object, nor any
|
// can happen because in the EDT thread we only read said object, nor any
|
||||||
// inconsistencies can arise.
|
// inconsistencies can arise.
|
||||||
// For more information you can view the comments at Queue@manageTransferProgress
|
// For more information you can view the comments at
|
||||||
|
// Queue@manageTransferProgress
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
TransferProgress transferProgress = (TransferProgress) arg;
|
TransferProgress transferProgress = (TransferProgress) arg;
|
||||||
|
|
||||||
// Do not invoke the Event Dispatch Thread too frequently as
|
// Do not invoke the Event Dispatch Thread too frequently as
|
||||||
// it may impact the performance of low-end computer systems.
|
// it may impact the performance of low-end computer systems.
|
||||||
if(System.currentTimeMillis() - lastGuiExecutionTime >= THROTTLE_TIME_MS ||
|
if (System.currentTimeMillis()
|
||||||
transferProgress.getTransferStatus() == TransferProgress.END) {
|
- lastGuiExecutionTime >= THROTTLE_TIME_MS
|
||||||
|
|| transferProgress
|
||||||
|
.getTransferStatus() == TransferProgress.END) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -134,24 +154,30 @@ public class QueueController implements Observer{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the transfer completion percentage
|
* Computes the transfer completion percentage
|
||||||
* @param transferProgress A transferProgress object
|
*
|
||||||
* @return A value in the range [0, 100] indicating
|
* @param transferProgress
|
||||||
* the transfer completion percentage
|
* A transferProgress object
|
||||||
|
* @return A value in the range [0, 100] indicating the transfer completion
|
||||||
|
* percentage
|
||||||
*/
|
*/
|
||||||
public int computePercentage(TransferProgress transferProgress) {
|
public int computePercentage(TransferProgress transferProgress) {
|
||||||
// Avoid division by zero
|
// Avoid division by zero
|
||||||
if (transferProgress.getTotalBytes() == 0) {
|
if (transferProgress.getTotalBytes() == 0) {
|
||||||
// The percentage is 100% if ∀ byte in the file, byte was transferred.
|
// The percentage is 100% if ∀ byte in the file, byte was
|
||||||
// If there are no bytes in the file, this logic proposition holds true (vacuous truth)
|
// transferred.
|
||||||
|
// If there are no bytes in the file, this logic proposition holds
|
||||||
|
// true (vacuous truth)
|
||||||
return 100;
|
return 100;
|
||||||
}
|
} else {
|
||||||
else {
|
return (int) Math
|
||||||
return (int) Math.round( ((transferProgress.getTransferredBytes() * 100F) / transferProgress.getTotalBytes()) );
|
.round(((transferProgress.getTransferredBytes() * 100F)
|
||||||
|
/ transferProgress.getTotalBytes()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a TransferProgress object, retrieve its index
|
* Given a TransferProgress object, retrieve its index
|
||||||
|
*
|
||||||
* @param transferProgress
|
* @param transferProgress
|
||||||
* @return Its index or null if not present
|
* @return Its index or null if not present
|
||||||
*/
|
*/
|
||||||
@ -161,20 +187,26 @@ public class QueueController implements Observer{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Put index in the HashMap
|
* Put index in the HashMap
|
||||||
* @param transferProgress TransferProgress object
|
*
|
||||||
* @param index An integer value representing the index
|
* @param transferProgress
|
||||||
|
* TransferProgress object
|
||||||
|
* @param index
|
||||||
|
* An integer value representing the index
|
||||||
*/
|
*/
|
||||||
public void putTableIndex(TransferProgress transferProgress, Integer index) {
|
public void putTableIndex(TransferProgress transferProgress,
|
||||||
|
Integer index) {
|
||||||
indexHashMap.put(transferProgress, index);
|
indexHashMap.put(transferProgress, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a specific TransferProgress is contained in
|
* Checks if a specific TransferProgress is contained in the HashMap
|
||||||
* the HashMap
|
*
|
||||||
* @param transferProgress A TransferProgress object
|
* @param transferProgress
|
||||||
|
* A TransferProgress object
|
||||||
* @return true if present, false otherwise
|
* @return true if present, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isTransferProgressInHashMap(TransferProgress transferProgress) {
|
public boolean isTransferProgressInHashMap(
|
||||||
|
TransferProgress transferProgress) {
|
||||||
return getTableIndex(transferProgress) != null;
|
return getTableIndex(transferProgress) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,6 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
* ========== END Attributes ==========
|
* ========== END Attributes ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Constructors ==========
|
* ========== BEGIN Constructors ==========
|
||||||
*/
|
*/
|
||||||
@ -107,7 +106,8 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
});
|
});
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(desktopPanel);
|
JScrollPane scrollPane = new JScrollPane(desktopPanel);
|
||||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
scrollPane.setHorizontalScrollBarPolicy(
|
||||||
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
scrollPane.getVerticalScrollBar().setUnitIncrement(25);
|
scrollPane.getVerticalScrollBar().setUnitIncrement(25);
|
||||||
getContentPane().add(scrollPane, BorderLayout.CENTER);
|
getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
@ -154,13 +154,25 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
Transferable data = dtde.getTransferable();
|
Transferable data = dtde.getTransferable();
|
||||||
if (data.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
if (data.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||||
try {
|
try {
|
||||||
File[] droppedFileArray = ((Collection<?>)(data.getTransferData(DataFlavor.javaFileListFlavor))).toArray(new File[((Collection<?>)(data.getTransferData(DataFlavor.javaFileListFlavor))).size()]);
|
File[] droppedFileArray = ((Collection<?>) (data
|
||||||
|
.getTransferData(
|
||||||
|
DataFlavor.javaFileListFlavor)))
|
||||||
|
.toArray(new File[((Collection<?>) (data
|
||||||
|
.getTransferData(
|
||||||
|
DataFlavor.javaFileListFlavor)))
|
||||||
|
.size()]);
|
||||||
try {
|
try {
|
||||||
((DesktopController)controller).uploadToRemoteServer(droppedFileArray);
|
((DesktopController) controller)
|
||||||
drawComponentsForDirectory(((DesktopController)controller).getCurrentWorkingDirectory());
|
.uploadToRemoteServer(droppedFileArray);
|
||||||
|
drawComponentsForDirectory(
|
||||||
|
((DesktopController) controller)
|
||||||
|
.getCurrentWorkingDirectory());
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
if (e.getMessage().contains("Permission denied")) {
|
if (e.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Permission denied", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(),
|
||||||
|
"Permission denied",
|
||||||
|
"Permission denied",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,21 +182,21 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
dtde.dropComplete(true);
|
dtde.dropComplete(true);
|
||||||
desktopPanel.setBorder(null);
|
desktopPanel.setBorder(null);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== END Constructors ==========
|
* ========== END Constructors ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Frame Drawing ==========
|
* ========== BEGIN Frame Drawing ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws all the components which need to be drew for a specific
|
* Draws all the components which need to be drew for a specific directory
|
||||||
* directory
|
*
|
||||||
* @param directory
|
* @param directory
|
||||||
*/
|
*/
|
||||||
public void drawComponentsForDirectory(String directory) {
|
public void drawComponentsForDirectory(String directory) {
|
||||||
@ -198,10 +210,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (controller.getLastSafeDirectory() == null) {
|
if (controller.getLastSafeDirectory() == null) {
|
||||||
System.exit(ERROR);
|
System.exit(ERROR);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
drawComponentsForDirectory(controller.getLastSafeDirectory());
|
drawComponentsForDirectory(controller.getLastSafeDirectory());
|
||||||
controller.setLastSafeDirectory(null); // Prevents infinite re-tries
|
controller.setLastSafeDirectory(null); // Prevents infinite
|
||||||
|
// re-tries
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,6 +225,7 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the desktop view
|
* Loads the desktop view
|
||||||
|
*
|
||||||
* @throws SftpException
|
* @throws SftpException
|
||||||
*/
|
*/
|
||||||
private void loadDesktop() throws SftpException {
|
private void loadDesktop() throws SftpException {
|
||||||
@ -221,9 +234,16 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
Image folderIcon = null;
|
Image folderIcon = null;
|
||||||
Image fileIcon = null;
|
Image fileIcon = null;
|
||||||
try {
|
try {
|
||||||
folderIcon = ImageIO.read(getClass().getClassLoader().getResource("folder_icon.png")).getScaledInstance(32, 32, Image.SCALE_DEFAULT);
|
folderIcon = ImageIO
|
||||||
fileIcon = ImageIO.read(getClass().getClassLoader().getResource("file_icon.png")).getScaledInstance(32, 32, Image.SCALE_DEFAULT);
|
.read(getClass().getClassLoader()
|
||||||
} catch (IOException e1) {}
|
.getResource("folder_icon.png"))
|
||||||
|
.getScaledInstance(32, 32, Image.SCALE_DEFAULT);
|
||||||
|
fileIcon = ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("file_icon.png"))
|
||||||
|
.getScaledInstance(32, 32, Image.SCALE_DEFAULT);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
}
|
||||||
|
|
||||||
Vector<LsEntry> elementsToDisplay = null;
|
Vector<LsEntry> elementsToDisplay = null;
|
||||||
try {
|
try {
|
||||||
@ -233,13 +253,15 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
if (e.getMessage().contains("Permission denied")) {
|
if (e.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Permission denied", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(), "Permission denied",
|
||||||
|
"Permission denied", JOptionPane.ERROR_MESSAGE);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LsEntry node : elementsToDisplay) {
|
for (LsEntry node : elementsToDisplay) {
|
||||||
ImageIcon icon = new ImageIcon( node.getAttrs().isDir()? folderIcon : fileIcon );
|
ImageIcon icon = new ImageIcon(
|
||||||
|
node.getAttrs().isDir() ? folderIcon : fileIcon);
|
||||||
JDirectoryNodeButton element = new JDirectoryNodeButton(node);
|
JDirectoryNodeButton element = new JDirectoryNodeButton(node);
|
||||||
JLabel iconLabel = new JLabel(icon);
|
JLabel iconLabel = new JLabel(icon);
|
||||||
iconLabel.setVerticalTextPosition(JLabel.BOTTOM);
|
iconLabel.setVerticalTextPosition(JLabel.BOTTOM);
|
||||||
@ -265,9 +287,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the action to take upon a click on the element
|
* Specifies the action to take upon a click on the element of a desktop
|
||||||
* of a desktop
|
*
|
||||||
* @param e A MouseEvent
|
* @param e
|
||||||
|
* A MouseEvent
|
||||||
*/
|
*/
|
||||||
private void desktopElementClick(MouseEvent e) {
|
private void desktopElementClick(MouseEvent e) {
|
||||||
JDirectoryNodeButton sender = (JDirectoryNodeButton) e.getSource();
|
JDirectoryNodeButton sender = (JDirectoryNodeButton) e.getSource();
|
||||||
@ -276,29 +299,32 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
if (e.getClickCount() == 2) {
|
if (e.getClickCount() == 2) {
|
||||||
ImageIcon questionMarkIcon = null;
|
ImageIcon questionMarkIcon = null;
|
||||||
try {
|
try {
|
||||||
questionMarkIcon = new ImageIcon(
|
questionMarkIcon = new ImageIcon(ImageIO
|
||||||
ImageIO.read(getClass().getClassLoader().getResource("question_mark.png")).getScaledInstance(32, 32, Image.SCALE_SMOOTH));
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("question_mark.png"))
|
||||||
|
.getScaledInstance(32, 32, Image.SCALE_SMOOTH));
|
||||||
|
} catch (IOException e1) {
|
||||||
}
|
}
|
||||||
catch (IOException e1) {}
|
|
||||||
|
|
||||||
// Double click on a directory
|
// Double click on a directory
|
||||||
if (sender.node.getAttrs().isDir()) {
|
if (sender.node.getAttrs().isDir()) {
|
||||||
String newDirectory = Helper.combinePath(controller.getCurrentWorkingDirectory(), sender.node.getFilename());
|
String newDirectory = Helper.combinePath(
|
||||||
|
controller.getCurrentWorkingDirectory(),
|
||||||
|
sender.node.getFilename());
|
||||||
drawComponentsForDirectory(newDirectory);
|
drawComponentsForDirectory(newDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Double click on a file
|
// Double click on a file
|
||||||
else {
|
else {
|
||||||
String filePath = Helper.combinePath(controller.getCurrentWorkingDirectory(), sender.node.getFilename());
|
String filePath = Helper.combinePath(
|
||||||
|
controller.getCurrentWorkingDirectory(),
|
||||||
|
sender.node.getFilename());
|
||||||
Object[] options = {"Download", "View", "Cancel"};
|
Object[] options = {"Download", "View", "Cancel"};
|
||||||
|
|
||||||
int choice = JOptionPane.showOptionDialog(null,
|
int choice = JOptionPane.showOptionDialog(null,
|
||||||
"What would you like to do with this file?",
|
"What would you like to do with this file?",
|
||||||
Constants.APP_NAME,
|
Constants.APP_NAME, JOptionPane.YES_NO_CANCEL_OPTION,
|
||||||
JOptionPane.YES_NO_CANCEL_OPTION,
|
JOptionPane.QUESTION_MESSAGE, questionMarkIcon, options,
|
||||||
JOptionPane.QUESTION_MESSAGE,
|
|
||||||
questionMarkIcon,
|
|
||||||
options,
|
|
||||||
options[0]);
|
options[0]);
|
||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
@ -307,11 +333,14 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
case 0 :
|
case 0 :
|
||||||
|
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
fileChooser.setFileSelectionMode(
|
||||||
int choiceFileChooser = fileChooser.showDialog(this, "Save here");
|
JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
int choiceFileChooser = fileChooser.showDialog(this,
|
||||||
|
"Save here");
|
||||||
|
|
||||||
if (choiceFileChooser == JFileChooser.APPROVE_OPTION) {
|
if (choiceFileChooser == JFileChooser.APPROVE_OPTION) {
|
||||||
controller.downloadFile(filePath, fileChooser.getSelectedFile().toString());
|
controller.downloadFile(filePath,
|
||||||
|
fileChooser.getSelectedFile().toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -331,7 +360,8 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
// Select a node
|
// Select a node
|
||||||
else if (e.getClickCount() == 1) {
|
else if (e.getClickCount() == 1) {
|
||||||
|
|
||||||
boolean isControlDown = (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0;
|
boolean isControlDown = (e.getModifiersEx()
|
||||||
|
& InputEvent.CTRL_DOWN_MASK) != 0;
|
||||||
|
|
||||||
// If already selected, unselect
|
// If already selected, unselect
|
||||||
if (sender.getSelected()) {
|
if (sender.getSelected()) {
|
||||||
@ -354,8 +384,7 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the file system tree seen
|
* Loads the file system tree seen on the left
|
||||||
* on the left
|
|
||||||
*/
|
*/
|
||||||
private void loadTree() {
|
private void loadTree() {
|
||||||
TreeNode root = this.controller.getTree();
|
TreeNode root = this.controller.getTree();
|
||||||
@ -369,12 +398,12 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
if (e.getClickCount() == 2) {
|
if (e.getClickCount() == 2) {
|
||||||
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
|
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
|
||||||
|
.getLastPathComponent();
|
||||||
if (node.getAllowsChildren()) { // is a directory
|
if (node.getAllowsChildren()) { // is a directory
|
||||||
String fullPath = getFullPathFromTreeNode(node);
|
String fullPath = getFullPathFromTreeNode(node);
|
||||||
drawComponentsForDirectory(fullPath);
|
drawComponentsForDirectory(fullPath);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Do nothing. Probably a "What to do?" prompt would
|
// Do nothing. Probably a "What to do?" prompt would
|
||||||
// be nice
|
// be nice
|
||||||
}
|
}
|
||||||
@ -386,11 +415,12 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auxiliary function which recursively
|
* Auxiliary function which recursively creates a tree given its root
|
||||||
* creates a tree given its root
|
*
|
||||||
* @param node A TreeNode element
|
* @param node
|
||||||
* @return A DefaultMutableTreeNode element representing the root
|
* A TreeNode element
|
||||||
* of the created tree
|
* @return A DefaultMutableTreeNode element representing the root of the
|
||||||
|
* created tree
|
||||||
*/
|
*/
|
||||||
private DefaultMutableTreeNode loadTreeAux(TreeNode node) {
|
private DefaultMutableTreeNode loadTreeAux(TreeNode node) {
|
||||||
|
|
||||||
@ -400,7 +430,8 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
if (node.error != null)
|
if (node.error != null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(node.name, node.type.equals("directory"));
|
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(node.name,
|
||||||
|
node.type.equals("directory"));
|
||||||
|
|
||||||
if (node.contents != null) {
|
if (node.contents != null) {
|
||||||
for (TreeNode child : node.contents) {
|
for (TreeNode child : node.contents) {
|
||||||
@ -415,16 +446,18 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the full path in the file system of a specified
|
* Retrieves the full path in the file system of a specified tree node
|
||||||
* tree node
|
*
|
||||||
* @param node A DefaultMutableTreeNode element
|
* @param node
|
||||||
|
* A DefaultMutableTreeNode element
|
||||||
* @return Full path of the node
|
* @return Full path of the node
|
||||||
*/
|
*/
|
||||||
private String getFullPathFromTreeNode(DefaultMutableTreeNode node) {
|
private String getFullPathFromTreeNode(DefaultMutableTreeNode node) {
|
||||||
javax.swing.tree.TreeNode[] path = node.getPath();
|
javax.swing.tree.TreeNode[] path = node.getPath();
|
||||||
StringBuilder fullPath = new StringBuilder();
|
StringBuilder fullPath = new StringBuilder();
|
||||||
for (int i = 0; i < path.length; i++) {
|
for (int i = 0; i < path.length; i++) {
|
||||||
Object userObject = ((DefaultMutableTreeNode) path[i]).getUserObject();
|
Object userObject = ((DefaultMutableTreeNode) path[i])
|
||||||
|
.getUserObject();
|
||||||
fullPath.append(userObject.toString());
|
fullPath.append(userObject.toString());
|
||||||
if (i != path.length - 1) {
|
if (i != path.length - 1) {
|
||||||
fullPath.append("/");
|
fullPath.append("/");
|
||||||
@ -443,7 +476,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
backBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
backBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
||||||
backBtn.setToolTipText("Back");
|
backBtn.setToolTipText("Back");
|
||||||
try {
|
try {
|
||||||
backBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("back_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
backBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("back_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
backBtn.setBorderPainted(false);
|
backBtn.setBorderPainted(false);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
backBtn.setText("Back");
|
backBtn.setText("Back");
|
||||||
@ -454,7 +490,8 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
if (controller.getCurrentWorkingDirectory().equals("/")) {
|
if (controller.getCurrentWorkingDirectory().equals("/")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String parentPath = Helper.getParentPath(controller.getCurrentWorkingDirectory());
|
String parentPath = Helper
|
||||||
|
.getParentPath(controller.getCurrentWorkingDirectory());
|
||||||
drawComponentsForDirectory(parentPath);
|
drawComponentsForDirectory(parentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,7 +514,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
cutBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
cutBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
||||||
cutBtn.setToolTipText("Cut");
|
cutBtn.setToolTipText("Cut");
|
||||||
try {
|
try {
|
||||||
cutBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("cut_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
cutBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("cut_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
cutBtn.setBackground(GuifyColors.GRAY);
|
cutBtn.setBackground(GuifyColors.GRAY);
|
||||||
cutBtn.setBorderPainted(false);
|
cutBtn.setBorderPainted(false);
|
||||||
cutBtn.setEnabled(false);
|
cutBtn.setEnabled(false);
|
||||||
@ -488,7 +528,9 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if (cutBtn.isEnabled()) {
|
if (cutBtn.isEnabled()) {
|
||||||
controller.cutCopyPasteController.startCuttying(controller.getSelectedNodes(), controller.getCurrentWorkingDirectory());
|
controller.cutCopyPasteController.startCuttying(
|
||||||
|
controller.getSelectedNodes(),
|
||||||
|
controller.getCurrentWorkingDirectory());
|
||||||
pasteBtn.setEnabled(true);
|
pasteBtn.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -512,7 +554,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
copyBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
copyBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
||||||
copyBtn.setToolTipText("Copy");
|
copyBtn.setToolTipText("Copy");
|
||||||
try {
|
try {
|
||||||
copyBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("copy_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
copyBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("copy_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
copyBtn.setBackground(GuifyColors.GRAY);
|
copyBtn.setBackground(GuifyColors.GRAY);
|
||||||
copyBtn.setBorderPainted(false);
|
copyBtn.setBorderPainted(false);
|
||||||
copyBtn.setEnabled(false);
|
copyBtn.setEnabled(false);
|
||||||
@ -522,7 +567,9 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
copyBtn.addMouseListener(new MouseAdapter() {
|
copyBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
controller.cutCopyPasteController.startCopying(controller.getSelectedNodes(), controller.getCurrentWorkingDirectory());
|
controller.cutCopyPasteController.startCopying(
|
||||||
|
controller.getSelectedNodes(),
|
||||||
|
controller.getCurrentWorkingDirectory());
|
||||||
pasteBtn.setEnabled(true);
|
pasteBtn.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,7 +592,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
pasteBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
pasteBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
||||||
pasteBtn.setToolTipText("Paste");
|
pasteBtn.setToolTipText("Paste");
|
||||||
try {
|
try {
|
||||||
pasteBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("paste_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
pasteBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("paste_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
pasteBtn.setBorderPainted(false);
|
pasteBtn.setBorderPainted(false);
|
||||||
pasteBtn.setEnabled(false);
|
pasteBtn.setEnabled(false);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -554,8 +604,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
pasteBtn.addMouseListener(new MouseAdapter() {
|
pasteBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
controller.cutCopyPasteController.paste(controller.getCurrentWorkingDirectory());
|
controller.cutCopyPasteController
|
||||||
drawComponentsForDirectory(controller.getCurrentWorkingDirectory());
|
.paste(controller.getCurrentWorkingDirectory());
|
||||||
|
drawComponentsForDirectory(
|
||||||
|
controller.getCurrentWorkingDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hover on
|
// Hover on
|
||||||
@ -577,7 +629,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
renameBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
renameBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
||||||
renameBtn.setToolTipText("Rename");
|
renameBtn.setToolTipText("Rename");
|
||||||
try {
|
try {
|
||||||
renameBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("rename_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
renameBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("rename_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
renameBtn.setBackground(GuifyColors.GRAY);
|
renameBtn.setBackground(GuifyColors.GRAY);
|
||||||
renameBtn.setBorderPainted(false);
|
renameBtn.setBorderPainted(false);
|
||||||
renameBtn.setEnabled(false);
|
renameBtn.setEnabled(false);
|
||||||
@ -588,36 +643,43 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
|
||||||
// Something's off and the rename button shouldn't have been active in the first place
|
// Something's off and the rename button shouldn't have been
|
||||||
|
// active in the first place
|
||||||
if (controller.getSelectedNodes().size() != 1) {
|
if (controller.getSelectedNodes().size() != 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String oldPath = Helper.combinePath(controller.getCurrentWorkingDirectory(), controller.getSelectedNodes().get(0).getNode().getFilename());
|
String oldPath = Helper.combinePath(
|
||||||
|
controller.getCurrentWorkingDirectory(),
|
||||||
|
controller.getSelectedNodes().get(0).getNode()
|
||||||
|
.getFilename());
|
||||||
|
|
||||||
String newName = (String) JOptionPane.showInputDialog(
|
String newName = (String) JOptionPane.showInputDialog(
|
||||||
Desktop.this,
|
Desktop.this,
|
||||||
"Rename \"" + controller.getSelectedNodes().get(0).getNode().getFilename() + "\"",
|
"Rename \"" + controller.getSelectedNodes().get(0)
|
||||||
"Rename",
|
.getNode().getFilename() + "\"",
|
||||||
JOptionPane.PLAIN_MESSAGE,
|
"Rename", JOptionPane.PLAIN_MESSAGE, null, null, null);
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
|
|
||||||
// has closed or canceled
|
// has closed or canceled
|
||||||
if (newName == null) {
|
if (newName == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String newPath = Helper.combinePath(controller.getCurrentWorkingDirectory(), newName);
|
String newPath = Helper.combinePath(
|
||||||
|
controller.getCurrentWorkingDirectory(), newName);
|
||||||
try {
|
try {
|
||||||
controller.rename(oldPath, newPath);
|
controller.rename(oldPath, newPath);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
if (e1.getMessage().contains("Permission denied")) {
|
if (e1.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Not enough permissions to rename this element", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(),
|
||||||
|
"Not enough permissions to rename this element",
|
||||||
|
"Permission denied", JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawComponentsForDirectory(controller.getCurrentWorkingDirectory()); // TODO optimize this
|
drawComponentsForDirectory(
|
||||||
|
controller.getCurrentWorkingDirectory()); // TODO
|
||||||
|
// optimize
|
||||||
|
// this
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hover on
|
// Hover on
|
||||||
@ -639,7 +701,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
newBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
newBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
||||||
newBtn.setToolTipText("New");
|
newBtn.setToolTipText("New");
|
||||||
try {
|
try {
|
||||||
newBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("plus_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
newBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("plus_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
newBtn.setBackground(GuifyColors.GRAY);
|
newBtn.setBackground(GuifyColors.GRAY);
|
||||||
newBtn.setBorderPainted(false);
|
newBtn.setBorderPainted(false);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -652,7 +717,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
|
|
||||||
JMenuItem newFileMenuItem = new JMenuItem("New file");
|
JMenuItem newFileMenuItem = new JMenuItem("New file");
|
||||||
try {
|
try {
|
||||||
newFileMenuItem.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("file_icon.png")).getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
|
newFileMenuItem.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("file_icon.png"))
|
||||||
|
.getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -660,31 +728,36 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
String newFileName = (String)JOptionPane.showInputDialog(
|
String newFileName = (String) JOptionPane
|
||||||
Desktop.this,
|
.showInputDialog(Desktop.this, "Name:",
|
||||||
"Name:",
|
"New file", JOptionPane.PLAIN_MESSAGE,
|
||||||
"New file",
|
null, null, null);
|
||||||
JOptionPane.PLAIN_MESSAGE,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
|
|
||||||
String newFilePath = Helper.combinePath(controller.getCurrentWorkingDirectory(), newFileName);
|
String newFilePath = Helper.combinePath(
|
||||||
|
controller.getCurrentWorkingDirectory(),
|
||||||
|
newFileName);
|
||||||
try {
|
try {
|
||||||
controller.touch(newFilePath);
|
controller.touch(newFilePath);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
if (e1.getMessage().contains("Permission denied")) {
|
if (e1.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Not enough permissions to create a file here", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(),
|
||||||
|
"Not enough permissions to create a file here",
|
||||||
|
"Permission denied",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawComponentsForDirectory(controller.getCurrentWorkingDirectory());
|
drawComponentsForDirectory(
|
||||||
|
controller.getCurrentWorkingDirectory());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JMenuItem newFolderMenuItem = new JMenuItem("New folder");
|
JMenuItem newFolderMenuItem = new JMenuItem("New folder");
|
||||||
try {
|
try {
|
||||||
newFolderMenuItem.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("folder_icon.png")).getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
|
newFolderMenuItem.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("folder_icon.png"))
|
||||||
|
.getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -692,30 +765,37 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
String newFolderName = (String)JOptionPane.showInputDialog(
|
String newFolderName = (String) JOptionPane
|
||||||
Desktop.this,
|
.showInputDialog(Desktop.this, "Name:",
|
||||||
"Name:",
|
"New folder", JOptionPane.PLAIN_MESSAGE,
|
||||||
"New folder",
|
null, null, null);
|
||||||
JOptionPane.PLAIN_MESSAGE,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
|
|
||||||
// User has canceled
|
// User has canceled
|
||||||
if (newFolderName == null) {
|
if (newFolderName == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String newFolderPath = Helper.combinePath(controller.getCurrentWorkingDirectory(), newFolderName);
|
String newFolderPath = Helper.combinePath(
|
||||||
|
controller.getCurrentWorkingDirectory(),
|
||||||
|
newFolderName);
|
||||||
try {
|
try {
|
||||||
controller.mkdir(newFolderPath);
|
controller.mkdir(newFolderPath);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
if (e1.getMessage().contains("Permission denied")) {
|
if (e1.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Not enough permissions to create a folder here", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(),
|
||||||
|
"Not enough permissions to create a folder here",
|
||||||
|
"Permission denied",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawComponentsForDirectory(controller.getCurrentWorkingDirectory()); //TODO: avoid a complete desktop reload
|
drawComponentsForDirectory(
|
||||||
|
controller.getCurrentWorkingDirectory()); // TODO:
|
||||||
|
// avoid
|
||||||
|
// a
|
||||||
|
// complete
|
||||||
|
// desktop
|
||||||
|
// reload
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -744,7 +824,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
deleteBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
deleteBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
||||||
deleteBtn.setToolTipText("Delete");
|
deleteBtn.setToolTipText("Delete");
|
||||||
try {
|
try {
|
||||||
deleteBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("delete_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
deleteBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("delete_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
deleteBtn.setBackground(GuifyColors.GRAY);
|
deleteBtn.setBackground(GuifyColors.GRAY);
|
||||||
deleteBtn.setBorderPainted(false);
|
deleteBtn.setBorderPainted(false);
|
||||||
deleteBtn.setEnabled(false);
|
deleteBtn.setEnabled(false);
|
||||||
@ -756,28 +839,30 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
ImageIcon deleteIcon = null;
|
ImageIcon deleteIcon = null;
|
||||||
try {
|
try {
|
||||||
deleteIcon = new ImageIcon(
|
deleteIcon = new ImageIcon(ImageIO
|
||||||
ImageIO.read(getClass().getClassLoader().getResource("delete_icon.png")).getScaledInstance(32, 32, Image.SCALE_SMOOTH));
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("delete_icon.png"))
|
||||||
|
.getScaledInstance(32, 32, Image.SCALE_SMOOTH));
|
||||||
|
} catch (IOException e1) {
|
||||||
}
|
}
|
||||||
catch (IOException e1) {}
|
|
||||||
int choice = JOptionPane.showOptionDialog(null,
|
int choice = JOptionPane.showOptionDialog(null,
|
||||||
"Do you really want to delete the selected items?",
|
"Do you really want to delete the selected items?",
|
||||||
Constants.APP_NAME,
|
Constants.APP_NAME, JOptionPane.YES_NO_OPTION,
|
||||||
JOptionPane.YES_NO_OPTION,
|
JOptionPane.QUESTION_MESSAGE, deleteIcon, null, null);
|
||||||
JOptionPane.QUESTION_MESSAGE,
|
|
||||||
deleteIcon,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
|
|
||||||
if (choice == 0) { // yes
|
if (choice == 0) { // yes
|
||||||
try {
|
try {
|
||||||
controller.deleteSelectedNodes();
|
controller.deleteSelectedNodes();
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
if (e1.getMessage().contains("Permission denied")) {
|
if (e1.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Deletion process has encountered an item which cannot be deleted", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(),
|
||||||
|
"Deletion process has encountered an item which cannot be deleted",
|
||||||
|
"Permission denied",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawComponentsForDirectory(controller.getCurrentWorkingDirectory());
|
drawComponentsForDirectory(
|
||||||
|
controller.getCurrentWorkingDirectory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,10 +882,14 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
|
|
||||||
downloadBtn = new JButton();
|
downloadBtn = new JButton();
|
||||||
downloadBtn.setBorderPainted(false);
|
downloadBtn.setBorderPainted(false);
|
||||||
downloadBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
downloadBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty
|
||||||
|
// border);
|
||||||
downloadBtn.setToolTipText("Download");
|
downloadBtn.setToolTipText("Download");
|
||||||
try {
|
try {
|
||||||
downloadBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("download_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
downloadBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("download_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
downloadBtn.setBorderPainted(false);
|
downloadBtn.setBorderPainted(false);
|
||||||
downloadBtn.setEnabled(false);
|
downloadBtn.setEnabled(false);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -811,9 +900,11 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
int choiceFileChooser = fileChooser.showDialog(Desktop.this, "Save here");
|
int choiceFileChooser = fileChooser.showDialog(Desktop.this,
|
||||||
|
"Save here");
|
||||||
if (choiceFileChooser == JFileChooser.APPROVE_OPTION) {
|
if (choiceFileChooser == JFileChooser.APPROVE_OPTION) {
|
||||||
controller.downloadSelectedNodes(fileChooser.getSelectedFile().toString());
|
controller.downloadSelectedNodes(
|
||||||
|
fileChooser.getSelectedFile().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +927,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
uploadBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
uploadBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
||||||
uploadBtn.setToolTipText("Upload here");
|
uploadBtn.setToolTipText("Upload here");
|
||||||
try {
|
try {
|
||||||
uploadBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("upload_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
uploadBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("upload_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
uploadBtn.setBackground(GuifyColors.GRAY);
|
uploadBtn.setBackground(GuifyColors.GRAY);
|
||||||
uploadBtn.setBorderPainted(false);
|
uploadBtn.setBorderPainted(false);
|
||||||
uploadBtn.setEnabled(true);
|
uploadBtn.setEnabled(true);
|
||||||
@ -847,19 +941,27 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
fileChooser.setFileSelectionMode(
|
||||||
|
JFileChooser.FILES_AND_DIRECTORIES);
|
||||||
fileChooser.setMultiSelectionEnabled(true);
|
fileChooser.setMultiSelectionEnabled(true);
|
||||||
int choiceFileChooser = fileChooser.showDialog(Desktop.this, "Upload");
|
int choiceFileChooser = fileChooser.showDialog(Desktop.this,
|
||||||
if (choiceFileChooser == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFiles().length > 0) {
|
"Upload");
|
||||||
|
if (choiceFileChooser == JFileChooser.APPROVE_OPTION
|
||||||
|
&& fileChooser.getSelectedFiles().length > 0) {
|
||||||
try {
|
try {
|
||||||
controller.uploadToRemoteServer(fileChooser.getSelectedFiles());
|
controller.uploadToRemoteServer(
|
||||||
|
fileChooser.getSelectedFiles());
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
if (e1.getMessage().contains("Permission denied")) {
|
if (e1.getMessage().contains("Permission denied")) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "Not enough permissions to upload in this location", "Permission denied", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(),
|
||||||
|
"Not enough permissions to upload in this location",
|
||||||
|
"Permission denied",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawComponentsForDirectory(controller.getCurrentWorkingDirectory());
|
drawComponentsForDirectory(
|
||||||
|
controller.getCurrentWorkingDirectory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -882,7 +984,10 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
queueBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
queueBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
||||||
queueBtn.setToolTipText("Queue");
|
queueBtn.setToolTipText("Queue");
|
||||||
try {
|
try {
|
||||||
queueBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("queue_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
queueBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("queue_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
queueBtn.setBackground(GuifyColors.GRAY);
|
queueBtn.setBackground(GuifyColors.GRAY);
|
||||||
queueBtn.setBorderPainted(false);
|
queueBtn.setBorderPainted(false);
|
||||||
queueBtn.setEnabled(true);
|
queueBtn.setEnabled(true);
|
||||||
@ -910,34 +1015,38 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
pathTextBox = new JTextField();
|
pathTextBox = new JTextField();
|
||||||
pathTextBox.setMaximumSize(new Dimension(200, 35));
|
pathTextBox.setMaximumSize(new Dimension(200, 35));
|
||||||
pathTextBox.setMinimumSize(new Dimension(50, 35));
|
pathTextBox.setMinimumSize(new Dimension(50, 35));
|
||||||
pathTextBox.setPreferredSize(new Dimension(200, 35));
|
pathTextBox.setPreferredSize(new Dimension(200, 35));
|
||||||
Font font = pathTextBox.getFont();
|
Font font = pathTextBox.getFont();
|
||||||
Font biggerFont = font.deriveFont(font.getSize() + 4f); // Increase font size by 4
|
Font biggerFont = font.deriveFont(font.getSize() + 4f); // Increase font
|
||||||
|
// size by 4
|
||||||
pathTextBox.setFont(biggerFont);
|
pathTextBox.setFont(biggerFont);
|
||||||
pathTextBox.addFocusListener(new FocusListener() {
|
pathTextBox.addFocusListener(new FocusListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusLost(FocusEvent e) {
|
public void focusLost(FocusEvent e) {
|
||||||
if(pathTextBox != null && !pathTextBox.getText().equals(controller.getCurrentWorkingDirectory())) {
|
if (pathTextBox != null && !pathTextBox.getText()
|
||||||
|
.equals(controller.getCurrentWorkingDirectory())) {
|
||||||
drawComponentsForDirectory(pathTextBox.getText());
|
drawComponentsForDirectory(pathTextBox.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusGained(FocusEvent e) {}
|
public void focusGained(FocusEvent e) {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
JButton goToBtn = new JButton();
|
JButton goToBtn = new JButton();
|
||||||
goToBtn.setBorderPainted(false);
|
goToBtn.setBorderPainted(false);
|
||||||
goToBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
goToBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border);
|
||||||
goToBtn.setToolTipText("Go");
|
goToBtn.setToolTipText("Go");
|
||||||
try {
|
try {
|
||||||
goToBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("go_to_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
goToBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("go_to_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
goToBtn.setBackground(GuifyColors.GRAY);
|
goToBtn.setBackground(GuifyColors.GRAY);
|
||||||
goToBtn.setBorderPainted(false);
|
goToBtn.setBorderPainted(false);
|
||||||
goToBtn.setEnabled(true);
|
goToBtn.setEnabled(true);
|
||||||
@ -947,7 +1056,8 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
goToBtn.addMouseListener(new MouseAdapter() {
|
goToBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if(pathTextBox != null && !pathTextBox.getText().equals(controller.getCurrentWorkingDirectory())) {
|
if (pathTextBox != null && !pathTextBox.getText()
|
||||||
|
.equals(controller.getCurrentWorkingDirectory())) {
|
||||||
drawComponentsForDirectory(pathTextBox.getText());
|
drawComponentsForDirectory(pathTextBox.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -993,29 +1103,27 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables tool bar buttons
|
* Enables or disables tool bar buttons according to these propositions:
|
||||||
* according to these propositions:
|
|
||||||
*
|
*
|
||||||
* 1. At least a selected node is selected <--> cut, copy, delete, download ENABLED
|
* 1. At least a selected node is selected <--> cut, copy, delete, download
|
||||||
* 2. Only one selected node is selected <--> rename ENABLED
|
* ENABLED 2. Only one selected node is selected <--> rename ENABLED 3.
|
||||||
* 3. selectedToolBarOperation is not none <--> paste ENABLED
|
* selectedToolBarOperation is not none <--> paste ENABLED
|
||||||
*/
|
*/
|
||||||
private void updateToolBarItems() {
|
private void updateToolBarItems() {
|
||||||
|
|
||||||
int selectedNodes = controller.countSelectedNodes();
|
int selectedNodes = controller.countSelectedNodes();
|
||||||
int selectedToolBarOperation = controller.cutCopyPasteController.getSelectedOperation();
|
int selectedToolBarOperation = controller.cutCopyPasteController
|
||||||
|
.getSelectedOperation();
|
||||||
|
|
||||||
if (selectedToolBarOperation != Constants.Constants_FSOperations.NONE) {
|
if (selectedToolBarOperation != Constants.Constants_FSOperations.NONE) {
|
||||||
pasteBtn.setEnabled(true);
|
pasteBtn.setEnabled(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pasteBtn.setEnabled(false);
|
pasteBtn.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedNodes == 1) {
|
if (selectedNodes == 1) {
|
||||||
renameBtn.setEnabled(true);
|
renameBtn.setEnabled(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
renameBtn.setEnabled(false);
|
renameBtn.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1024,8 +1132,7 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
copyBtn.setEnabled(true);
|
copyBtn.setEnabled(true);
|
||||||
deleteBtn.setEnabled(true);
|
deleteBtn.setEnabled(true);
|
||||||
downloadBtn.setEnabled(true);
|
downloadBtn.setEnabled(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cutBtn.setEnabled(false);
|
cutBtn.setEnabled(false);
|
||||||
copyBtn.setEnabled(false);
|
copyBtn.setEnabled(false);
|
||||||
deleteBtn.setEnabled(false);
|
deleteBtn.setEnabled(false);
|
||||||
@ -1037,7 +1144,6 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
* ========== END Frame Drawing ==========
|
* ========== END Frame Drawing ==========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ========== BEGIN Node selection/deselection ==========
|
* ========== BEGIN Node selection/deselection ==========
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,8 @@ public class FindAndReplace extends JFrame implements IFindAndReplaceFrame {
|
|||||||
findNextBtn.addMouseListener(new MouseAdapter() {
|
findNextBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
((FindAndReplaceController) controller).findNext(findTextField.getText());
|
((FindAndReplaceController) controller)
|
||||||
|
.findNext(findTextField.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -31,7 +32,8 @@ public class FindAndReplace extends JFrame implements IFindAndReplaceFrame {
|
|||||||
findPreviousBtn.addMouseListener(new MouseAdapter() {
|
findPreviousBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
((FindAndReplaceController) controller).findPrevious(findTextField.getText());
|
((FindAndReplaceController) controller)
|
||||||
|
.findPrevious(findTextField.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -39,7 +41,8 @@ public class FindAndReplace extends JFrame implements IFindAndReplaceFrame {
|
|||||||
replaceNextBtn.addMouseListener(new MouseAdapter() {
|
replaceNextBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
((FindAndReplaceController) controller).replaceNext(findTextField.getText(), replaceTextField.getText());
|
((FindAndReplaceController) controller).replaceNext(
|
||||||
|
findTextField.getText(), replaceTextField.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,7 +50,8 @@ public class FindAndReplace extends JFrame implements IFindAndReplaceFrame {
|
|||||||
replaceAllBtn.addMouseListener(new MouseAdapter() {
|
replaceAllBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
((FindAndReplaceController) controller).replaceAll(findTextField.getText(), replaceTextField.getText());
|
((FindAndReplaceController) controller).replaceAll(
|
||||||
|
findTextField.getText(), replaceTextField.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,7 +91,6 @@ public class Login extends JFrame implements ILoginFrame {
|
|||||||
contentPane.add(portField);
|
contentPane.add(portField);
|
||||||
portField.setColumns(10);
|
portField.setColumns(10);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,15 +106,16 @@ public class Login extends JFrame implements ILoginFrame {
|
|||||||
// Perform validation
|
// Perform validation
|
||||||
try {
|
try {
|
||||||
controller.ValidateInput(host, username, password, port);
|
controller.ValidateInput(host, username, password, port);
|
||||||
}
|
} catch (IllegalArgumentException ex) {
|
||||||
catch(IllegalArgumentException ex) {
|
JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(),
|
||||||
JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "Attention required", JOptionPane.ERROR_MESSAGE);
|
"Attention required", JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform login
|
// Perform login
|
||||||
if (!controller.Login(host, username, password, port)) {
|
if (!controller.Login(host, username, password, port)) {
|
||||||
JOptionPane.showMessageDialog(new JFrame(), "SSH Login failed", "SSH Login failed", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(new JFrame(), "SSH Login failed",
|
||||||
|
"SSH Login failed", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,13 @@ public class Notepad extends JFrame implements INotepadFrame {
|
|||||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||||
JScrollPane scrollPane = new JScrollPane(textArea);
|
JScrollPane scrollPane = new JScrollPane(textArea);
|
||||||
contentPanel.add(scrollPane, BorderLayout.CENTER);
|
contentPanel.add(scrollPane, BorderLayout.CENTER);
|
||||||
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); // We want to create a spaced JPanel
|
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); // We
|
||||||
|
// want
|
||||||
|
// to
|
||||||
|
// create
|
||||||
|
// a
|
||||||
|
// spaced
|
||||||
|
// JPanel
|
||||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||||
textArea = new JTextArea();
|
textArea = new JTextArea();
|
||||||
scrollPane.setViewportView(textArea);
|
scrollPane.setViewportView(textArea);
|
||||||
@ -81,7 +87,10 @@ public class Notepad extends JFrame implements INotepadFrame {
|
|||||||
saveBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border
|
saveBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border
|
||||||
saveBtn.setToolTipText("Save");
|
saveBtn.setToolTipText("Save");
|
||||||
try {
|
try {
|
||||||
saveBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("save_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
saveBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("save_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
saveBtn.setBackground(new Color(240, 240, 240));
|
saveBtn.setBackground(new Color(240, 240, 240));
|
||||||
saveBtn.setBorderPainted(false);
|
saveBtn.setBorderPainted(false);
|
||||||
saveBtn.setEnabled(true);
|
saveBtn.setEnabled(true);
|
||||||
@ -91,7 +100,8 @@ public class Notepad extends JFrame implements INotepadFrame {
|
|||||||
saveBtn.addMouseListener(new MouseAdapter() {
|
saveBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
((NotepadController)controller).writeOnFile(textArea.getText());
|
((NotepadController) controller)
|
||||||
|
.writeOnFile(textArea.getText());
|
||||||
((NotepadController) controller).setUnsaved(false);
|
((NotepadController) controller).setUnsaved(false);
|
||||||
setTitle(((NotepadController) controller).getTitle());
|
setTitle(((NotepadController) controller).getTitle());
|
||||||
}
|
}
|
||||||
@ -115,7 +125,10 @@ public class Notepad extends JFrame implements INotepadFrame {
|
|||||||
searchBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
searchBtn.setBorder(new EmptyBorder(0, 0, 0, 0)); // Set empty border;
|
||||||
searchBtn.setToolTipText("Serch/Replace");
|
searchBtn.setToolTipText("Serch/Replace");
|
||||||
try {
|
try {
|
||||||
searchBtn.setIcon(new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("search_icon.png")).getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
searchBtn.setIcon(new ImageIcon(ImageIO
|
||||||
|
.read(getClass().getClassLoader()
|
||||||
|
.getResource("search_icon.png"))
|
||||||
|
.getScaledInstance(25, 25, Image.SCALE_SMOOTH)));
|
||||||
searchBtn.setBackground(new Color(240, 240, 240));
|
searchBtn.setBackground(new Color(240, 240, 240));
|
||||||
searchBtn.setBorderPainted(false);
|
searchBtn.setBorderPainted(false);
|
||||||
searchBtn.setEnabled(true);
|
searchBtn.setEnabled(true);
|
||||||
@ -125,7 +138,8 @@ public class Notepad extends JFrame implements INotepadFrame {
|
|||||||
searchBtn.addMouseListener(new MouseAdapter() {
|
searchBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
((NotepadController)controller).showFindAndReplace(new JGenericTextArea(textArea));
|
((NotepadController) controller)
|
||||||
|
.showFindAndReplace(new JGenericTextArea(textArea));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hover on
|
// Hover on
|
||||||
@ -155,8 +169,7 @@ public class Notepad extends JFrame implements INotepadFrame {
|
|||||||
getContentPane().add(toolBarPanel, BorderLayout.NORTH);
|
getContentPane().add(toolBarPanel, BorderLayout.NORTH);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close "Find and Replace" if this window
|
* Close "Find and Replace" if this window gets closed
|
||||||
* gets closed
|
|
||||||
*/
|
*/
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,11 +22,13 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Custom cell renderer in order to be able to display
|
* Custom cell renderer in order to be able to display a progress bar in the
|
||||||
* a progress bar in the JTable
|
* JTable
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static class ProgressBarTableCellRenderer extends DefaultTableCellRenderer {
|
public static class ProgressBarTableCellRenderer
|
||||||
|
extends
|
||||||
|
DefaultTableCellRenderer {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private JProgressBar progressBar;
|
private JProgressBar progressBar;
|
||||||
|
|
||||||
@ -37,8 +39,9 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
public Component getTableCellRendererComponent(JTable table,
|
||||||
boolean hasFocus, int row, int column) {
|
Object value, boolean isSelected, boolean hasFocus, int row,
|
||||||
|
int column) {
|
||||||
if (value instanceof Integer) {
|
if (value instanceof Integer) {
|
||||||
int progressValue = (Integer) value;
|
int progressValue = (Integer) value;
|
||||||
progressBar.setValue(progressValue);
|
progressBar.setValue(progressValue);
|
||||||
@ -58,7 +61,8 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
public Queue(Object controller) {
|
public Queue(Object controller) {
|
||||||
this.controller = (QueueController) controller;
|
this.controller = (QueueController) controller;
|
||||||
setTitle("Queue");
|
setTitle("Queue");
|
||||||
String[] columnNames = {"Source", "Destination", "Operation", "Percentage"};
|
String[] columnNames = {"Source", "Destination", "Operation",
|
||||||
|
"Percentage"};
|
||||||
tableModel = new DefaultTableModel(columnNames, 0);
|
tableModel = new DefaultTableModel(columnNames, 0);
|
||||||
JTable table = new JTable(tableModel);
|
JTable table = new JTable(tableModel);
|
||||||
table.setEnabled(false); // Prevents user editing
|
table.setEnabled(false); // Prevents user editing
|
||||||
@ -73,19 +77,25 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a row in the JTable
|
* Adds a row in the JTable
|
||||||
|
*
|
||||||
* @return The index of the inserted row
|
* @return The index of the inserted row
|
||||||
*/
|
*/
|
||||||
public int addRow(String source, String destination, String operation, int percentage) {
|
public int addRow(String source, String destination, String operation,
|
||||||
tableModel.addRow(new Object[]{source, destination, operation, percentage});
|
int percentage) {
|
||||||
|
tableModel.addRow(
|
||||||
|
new Object[]{source, destination, operation, percentage});
|
||||||
return tableModel.getRowCount() - 1;
|
return tableModel.getRowCount() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a value (representing the transfer completion percentage)
|
* Given a value (representing the transfer completion percentage) and an
|
||||||
* and an index representing the 0-based index of the row to update,
|
* index representing the 0-based index of the row to update, update that
|
||||||
* update that row with that value
|
* row with that value
|
||||||
* @param rowIndex 0-base index of the row to update
|
*
|
||||||
* @param percentage The transfer completion percentage to set
|
* @param rowIndex
|
||||||
|
* 0-base index of the row to update
|
||||||
|
* @param percentage
|
||||||
|
* The transfer completion percentage to set
|
||||||
*/
|
*/
|
||||||
public void updateRow(int rowIndex, int percentage) {
|
public void updateRow(int rowIndex, int percentage) {
|
||||||
if (rowIndex < tableModel.getRowCount()) {
|
if (rowIndex < tableModel.getRowCount()) {
|
||||||
@ -93,26 +103,36 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method can receive a transferProgress whose status can be INIT, UPDATING
|
// This method can receive a transferProgress whose status can be INIT,
|
||||||
|
// UPDATING
|
||||||
// or END.
|
// or END.
|
||||||
// In all of these cases it is possible that transferProgress is or is not in the HashMap,
|
// In all of these cases it is possible that transferProgress is or is not
|
||||||
|
// in the HashMap,
|
||||||
// and we'll prove its correctness in all the cases:
|
// and we'll prove its correctness in all the cases:
|
||||||
//
|
//
|
||||||
// 1. Init: This method can receive a transferProgress whose status is INIT and
|
// 1. Init: This method can receive a transferProgress whose status is INIT
|
||||||
// a. Not present in the HashMap: this can happen either when QueueController receives
|
// and
|
||||||
// an update() or when it iterates in the constructor over the previously enqueued
|
// a. Not present in the HashMap: this can happen either when
|
||||||
|
// QueueController receives
|
||||||
|
// an update() or when it iterates in the constructor over the previously
|
||||||
|
// enqueued
|
||||||
// elements. In both cases, the transfer gets correctly put in the table.
|
// elements. In both cases, the transfer gets correctly put in the table.
|
||||||
// b. Present in the HashMap: despite it's counterintuitive, this can happen when
|
// b. Present in the HashMap: despite it's counterintuitive, this can happen
|
||||||
// a transfer gets initialized after QueueEventManager.getInstance().addObserver(this);
|
// when
|
||||||
|
// a transfer gets initialized after
|
||||||
|
// QueueEventManager.getInstance().addObserver(this);
|
||||||
// and before QueueEventManager.getInstance().getQueue().
|
// and before QueueEventManager.getInstance().getQueue().
|
||||||
// This would lead either update()
|
// This would lead either update()
|
||||||
// or the QueueController's constructor to call this method over a transferProgress
|
// or the QueueController's constructor to call this method over a
|
||||||
|
// transferProgress
|
||||||
// already in the HashMap (because inserted by the other one)
|
// already in the HashMap (because inserted by the other one)
|
||||||
// but whose status is INIT. In this case, updateRow() will
|
// but whose status is INIT. In this case, updateRow() will
|
||||||
// be called, but without any side effects as the percentage would be zero regardless.
|
// be called, but without any side effects as the percentage would be zero
|
||||||
|
// regardless.
|
||||||
//
|
//
|
||||||
// 2. Updating:
|
// 2. Updating:
|
||||||
// a. Not present in the HashMap: This can happen when the Queue UI is opened
|
// a. Not present in the HashMap: This can happen when the Queue UI is
|
||||||
|
// opened
|
||||||
// while an element is already being transferred. This happens because when
|
// while an element is already being transferred. This happens because when
|
||||||
// the transfer had a "INIT" status, this object did not exist yet.
|
// the transfer had a "INIT" status, this object did not exist yet.
|
||||||
// If it's not present in the HashMap
|
// If it's not present in the HashMap
|
||||||
@ -137,20 +157,24 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void manageTransferProgress(TransferProgress transferProgress) {
|
public void manageTransferProgress(TransferProgress transferProgress) {
|
||||||
|
|
||||||
// Remember that when QueueController calls frame.manageTransferProgress(transferProgress),
|
// Remember that when QueueController calls
|
||||||
// here transferProgress might have different attributes than it was originally called on
|
// frame.manageTransferProgress(transferProgress),
|
||||||
|
// here transferProgress might have different attributes than it was
|
||||||
|
// originally called on
|
||||||
// (as it's updated by a different thread).
|
// (as it's updated by a different thread).
|
||||||
// We do not need a lock as we do not edit it, but just keep it in mind.
|
// We do not need a lock as we do not edit it, but just keep it in mind.
|
||||||
|
|
||||||
if (!controller.isTransferProgressInHashMap(transferProgress)) {
|
if (!controller.isTransferProgressInHashMap(transferProgress)) {
|
||||||
controller.putTableIndex(transferProgress,
|
controller.putTableIndex(transferProgress, addRow(
|
||||||
addRow(transferProgress.getSource(),
|
transferProgress.getSource(),
|
||||||
transferProgress.getDestination(),
|
transferProgress.getDestination(),
|
||||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
transferProgress.getOperation() == SftpProgressMonitor.GET
|
||||||
|
? "Download"
|
||||||
|
: "Upload",
|
||||||
controller.computePercentage(transferProgress)));
|
controller.computePercentage(transferProgress)));
|
||||||
}
|
} else {
|
||||||
else {
|
updateRow(controller.getTableIndex(transferProgress),
|
||||||
updateRow(controller.getTableIndex(transferProgress), controller.computePercentage(transferProgress));
|
controller.computePercentage(transferProgress));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user