package frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import javax.swing.JLabel; import javax.swing.JOptionPane; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import filesystem.FSUtil; /** * Based off of RenameWindow.java. Edited to support FTPFile * */ @SuppressWarnings("serial") public class renameFTPWindow extends javax.swing.JFrame { //The file to be renamed private FTPFile file; private FTPClient client; /** Creates new form NewJFrame */ public renameFTPWindow(FTPFile f, FTPClient c) { file = f; client = c; initComponents(); initUI(); renameTextField.setText(file.getName()); renameTextField.selectAll(); setVisible(true); this.setLocationRelativeTo(null); } private void initComponents() { okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); renameTextField = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); okButton.setText(" OK "); cancelButton.setText("Cancel"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(renameTextField, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(renameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(okButton) .addComponent(cancelButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// private void initUI() { cancelButton.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { dispose(); } }); okButton.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { renameTextField.selectAll(); String newName = renameTextField.getSelectedText(); try { //TODO implement properly if(client.rename(file.getName(), newName)) { JOptionPane.showMessageDialog(null, new JLabel("Rename Successful"), "Success", JOptionPane.INFORMATION_MESSAGE);; } } catch (IOException e) { JOptionPane.showMessageDialog(null, new JLabel("Rename Unsuccessful"), "Network Error", JOptionPane.WARNING_MESSAGE); } dispose(); } }); } // Variables declaration - do not modify private javax.swing.JButton cancelButton; private javax.swing.JButton okButton; private javax.swing.JTextField renameTextField; // End of variables declaration }