package frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import filesystem.FSUtil; /** * * @author ablackbu */ @SuppressWarnings("serial") public class RenameWindow extends javax.swing.JFrame { //The file to be renamed private File file; /** Creates new form NewJFrame */ public RenameWindow(File f) { file = f; 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(); FSUtil.getInstance().rename(file, newName); 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 }