Skip to content

Commit

Permalink
GUI update
Browse files Browse the repository at this point in the history
  • Loading branch information
DomAtTheShack committed Jun 4, 2023
1 parent 1fe3e6c commit 73e2ad2
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 31 deletions.
Binary file modified out/production/Dom-s-FTP-Client/FTPClientJ.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$1.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$2.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$3.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$4.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$5.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$6.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$7.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$8.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI.class
Binary file not shown.
4 changes: 1 addition & 3 deletions src/FTPClientJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class FTPClientJ {

public static void main(String[] args) {
public static void FTPClient(String sendFile, String RemoteDir, Boolean send) {
String server = "192.168.5.118";
int port = 21;
String username = "dominichann";
Expand All @@ -21,8 +21,6 @@ public static void main(String[] args) {

if (loggedIn) {
System.out.println("Logged in to FTP server.");

//ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

File localFile = new File(localFilePath);
Expand Down
61 changes: 33 additions & 28 deletions src/FileBrowserGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FileBrowserGUI extends JFrame {
private JLabel selectedFileLabel;
private JButton backButton;
private JButton forwardButton;
private JProgressBar loadingBar; // Added loading bar component

private Stack<File> backStack;
private Stack<File> forwardStack;
Expand Down Expand Up @@ -64,16 +65,13 @@ public void actionPerformed(ActionEvent e) {
buttonPanel.add(forwardButton, BorderLayout.EAST);
contentPane.add(buttonPanel, BorderLayout.NORTH);

// Create the buttons section
JPanel buttonsSection = new JPanel();
buttonsSection.setLayout(new GridLayout(3, 1));
buttonsSection.setLayout(new GridLayout(4, 1)); // Changed to 4 rows

JButton button1 = new JButton("Button 1");
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Define the functionality for Button 1
// Add your custom code here
JOptionPane.showMessageDialog(null, "Button 1 clicked");
}
});
Expand All @@ -83,8 +81,6 @@ public void actionPerformed(ActionEvent e) {
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Define the functionality for Button 2
// Add your custom code here
JOptionPane.showMessageDialog(null, "Button 2 clicked");
}
});
Expand All @@ -94,14 +90,16 @@ public void actionPerformed(ActionEvent e) {
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Define the functionality for Button 3
// Add your custom code here
JOptionPane.showMessageDialog(null, "Button 3 clicked");
}
});
buttonsSection.add(button3);

contentPane.add(buttonsSection, BorderLayout.EAST);
loadingBar = new JProgressBar();
loadingBar.setStringPainted(true); // Display the percentage
buttonsSection.add(loadingBar); // Added loading bar to the layout

contentPane.add(buttonsSection, BorderLayout.EAST); // Aligned buttons section to the right

fileList.addMouseListener(new MouseAdapter() {
@Override
Expand All @@ -119,25 +117,22 @@ public void mouseClicked(MouseEvent e) {
}
});


fileList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
int selectedIndex = fileList.getSelectedIndex();
if (selectedIndex != -1) {
String selectedFile = listModel.getElementAt(selectedIndex);
File file = new File(selectedFile);
selectedFileLabel.setText(currentDirectory.getPath()+"\\"+file.getName());
File file = new File(currentDirectory, selectedFile);
selectedFileLabel.setText(file.getAbsolutePath());
} else {
selectedFileLabel.setText("");
}
}
}
});



backStack = new Stack<>();
forwardStack = new Stack<>();
navigateToDirectory(new File(System.getProperty("user.home")));
Expand All @@ -164,51 +159,61 @@ private void navigateToDirectory(File directory) {

updateFileList(directory);
currentDirectory = directory;
selectedFileLabel.setText(currentDirectory.getPath());
selectedFileLabel.setText(currentDirectory.getAbsolutePath());
}

private void navigateBack() {
if (!backStack.isEmpty()) {
forwardStack.push(currentDirectory);
forwardButton.setEnabled(true);

File directory = backStack.pop();
updateFileList(directory);
currentDirectory = directory;
currentDirectory = backStack.pop();
updateFileList(currentDirectory);

if (backStack.isEmpty()) {
backButton.setEnabled(false);
}
} else {
// Navigate to the parent directory
File parentDirectory = currentDirectory.getParentFile();
if (parentDirectory != null) {
forwardStack.push(currentDirectory);
forwardButton.setEnabled(true);

currentDirectory = parentDirectory;
updateFileList(currentDirectory);

backButton.setEnabled(true);
}
}
selectedFileLabel.setText(currentDirectory.getPath()+"\\");

selectedFileLabel.setText(currentDirectory.getAbsolutePath());
}


private void navigateForward() {
if (!forwardStack.isEmpty()) {
backStack.push(currentDirectory);
backButton.setEnabled(true);

File directory = forwardStack.pop();
updateFileList(directory);
currentDirectory = directory;
currentDirectory = forwardStack.pop();
updateFileList(currentDirectory);

if (forwardStack.isEmpty()) {
forwardButton.setEnabled(false);
}
}
selectedFileLabel.setText(currentDirectory.getPath()+"\\");

selectedFileLabel.setText(currentDirectory.getAbsolutePath());
}

private void updateFileList(File directory) {
listModel.clear();
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if(file.isDirectory()){
listModel.addElement(file.getName()+"\\");
}else {
if (file.isDirectory()) {
listModel.addElement(file.getName() + File.separator);
} else {
listModel.addElement(file.getName());
}
}
Expand All @@ -230,4 +235,4 @@ public void run() {
}
});
}
}
}
7 changes: 7 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.apache.commons.net.ftp.FTP;

public class Main {
public static void main(String[] args){
//FTPClientJ.FTPClient();
}
}

0 comments on commit 73e2ad2

Please sign in to comment.