Skip to content

Commit

Permalink
GUI Update still need to fix top area with to much white space
Browse files Browse the repository at this point in the history
  • Loading branch information
DomAtTheShack committed Jun 5, 2023
1 parent b556327 commit a9e7120
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 24 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.class
Binary file not shown.
8 changes: 4 additions & 4 deletions src/FTPClientJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static boolean connect(String server,String user, String pass,int port){
return true;
}
public static boolean FTPUpFile(String sendFile, String remoteDir) {
String server = "192.168.5.118";
String server = "domserver.xyz";
int port = 21;
String username = "dominichann";
String password = "Hidom@123";
Expand All @@ -35,7 +35,7 @@ public static boolean FTPUpFile(String sendFile, String remoteDir) {
ftpClient.connect(server, port);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
System.out.println("FTP server refused connection.");
Main.loadingBar.addConsoleText("FTP server refused connection.");
return false;
}

Expand Down Expand Up @@ -73,8 +73,8 @@ public static boolean FTPUpFile(String sendFile, String remoteDir) {

System.out.println("File upload completed successfully.");
return true;
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
Main.loadingBar.addConsoleText(e.toString());
} finally {
try {
if (fileInputStream != null) {
Expand Down
85 changes: 65 additions & 20 deletions src/FileBrowserGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.URL;
import java.util.Stack;
import org.apache.commons.net.ftp.FTPClient;

public class FileBrowserGUI extends JFrame {
private JList<String> fileList;
Expand All @@ -21,14 +18,16 @@ public class FileBrowserGUI extends JFrame {
private JTextField textField2;
private JTextField textField3;
private JTextField textField4;
private JTextArea console; // Added console component
private JTextArea console;

private File currentDirectory;

public FileBrowserGUI() {
setTitle("FTP Client");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1200, 800);
Image icon = Toolkit.getDefaultToolkit().getImage("/icons/ftp.png");
setIconImage(icon);

JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(new EmptyBorder(10, 20, 20, 20));
Expand All @@ -40,13 +39,19 @@ public FileBrowserGUI() {
JScrollPane scrollPane = new JScrollPane(fileList);
contentPane.add(scrollPane, BorderLayout.CENTER);


console = new JTextArea(5, 10); // Create console component
console.setEditable(false);
selectedFileLabel = new JLabel();
selectedFileLabel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
JPanel topPanel = new JPanel(new BorderLayout()); // Create a top panel for console
topPanel.setPreferredSize(new Dimension(10, 300)); // Set preferred size for the top panel
console = new JTextArea(5, 10); // Create console component
console.setEditable(false);
JScrollPane consoleScrollPane = new JScrollPane(console);
topPanel.add(consoleScrollPane, BorderLayout.SOUTH); // Add console to the top panel
topPanel.add(selectedFileLabel,BorderLayout.PAGE_START);

JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(selectedFileLabel, BorderLayout.CENTER);
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(topPanel, BorderLayout.NORTH); // Add top panel to the north region

JPanel connectPanel = new JPanel(); // Panel for connect and disconnect buttons
connectPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
Expand All @@ -60,7 +65,6 @@ public FileBrowserGUI() {

connectPanel.add(connectButton);
connectPanel.add(disconnectButton);
//setVisible(true);

JPanel inputPanel = new JPanel();
inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.X_AXIS));
Expand All @@ -87,9 +91,7 @@ public FileBrowserGUI() {

contentPane.add(inputPanel, BorderLayout.SOUTH);

console = new JTextArea(5, 10); // Create console component
console.setEditable(false);
JScrollPane consoleScrollPane = new JScrollPane(console);

JPanel rightPanel = new JPanel(new BorderLayout()); // Panel for the right side components

JPanel buttonsPanel = new JPanel(new GridLayout(1, 3)); // Panel for buttons
Expand All @@ -101,18 +103,28 @@ public FileBrowserGUI() {
buttonsPanel.add(button2);
buttonsPanel.add(button1);

JPanel directoryPanel = new JPanel(); // Panel for FTP directory
directoryPanel.setLayout(new BoxLayout(directoryPanel, BoxLayout.Y_AXIS));

JLabel directoryLabel = new JLabel("FTP Directory");
directoryLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
JList<String> ftpDirectoryList = new JList<>(new DefaultListModel<>());
JScrollPane ftpDirectoryScrollPane = new JScrollPane(ftpDirectoryList);

directoryPanel.add(directoryLabel);
directoryPanel.add(ftpDirectoryScrollPane);

JPanel spacePanel = new JPanel(); // Panel for white space
spacePanel.setPreferredSize(new Dimension(10, 50)); // Adjust the preferred height as needed

loadingBar = new JProgressBar();
loadingBar.setStringPainted(true);

rightPanel.add(consoleScrollPane, BorderLayout.CENTER); // Add console to the center
rightPanel.add(buttonsPanel, BorderLayout.PAGE_START); // Add buttons to the center
rightPanel.add(directoryPanel, BorderLayout.LINE_START); // Add directory panel to the left
rightPanel.add(loadingBar, BorderLayout.PAGE_END); // Add loading bar to the bottom

contentPane.add(rightPanel, BorderLayout.EAST);

contentPane.add(rightPanel, BorderLayout.EAST); // Add right panel to the center

fileList.addMouseListener(new MouseAdapter() {
@Override
Expand Down Expand Up @@ -150,12 +162,43 @@ public void valueChanged(ListSelectionEvent e) {
}
});




navigateToDirectory(new File(System.getProperty("user.home")));
selectedFileLabel.setText(currentDirectory.getPath());
setVisible(true);
connectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addConsoleText("Fuck java");
}
});

disconnectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// disconnectFromServer();
}
});

button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FTPClientJ.FTPUpFile("/","/");
}
});

button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// performButton2Action();
}
});

button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// performButton3Action();
}
});
}

private void navigateToDirectory(File directory) {
Expand Down Expand Up @@ -188,12 +231,14 @@ private void updateFileList(File directory) {
}
}


public void setLoadingBar(int x) {
loadingBar.setValue(x);
}

public void setLoadingBarText(String str) {
loadingBar.setString(str);
}
}
public void addConsoleText(String text) {
console.append(text + "\n");
}
}
Binary file added src/icons/ftp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a9e7120

Please sign in to comment.