01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11:
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package net.sf.jftp.gui.tasks;
17:
18: import net.sf.jftp.*;
19: import net.sf.jftp.gui.framework.*;
20: import net.sf.jftp.net.*;
21: import net.sf.jftp.system.logging.Log;
22: import net.sf.jftp.util.*;
23:
24: import java.awt.*;
25: import java.awt.event.*;
26:
27: import java.io.*;
28:
29: public class Renamer extends HFrame implements ActionListener {
30: public HTextField text;
31: private HButton ok = new HButton("Ok");
32: private HPanel okP = new HPanel();
33: private String oldName;
34: private String path;
35:
36: public Renamer(String oldName, String path) {
37: this .oldName = oldName;
38: this .path = path;
39:
40: setSize(400, 80);
41: setTitle("Enter new name...");
42: setLocation(150, 150);
43: getContentPane().setLayout(new FlowLayout());
44:
45: text = new HTextField("Name: ", oldName);
46: getContentPane().add(text);
47: getContentPane().add(ok);
48: ok.addActionListener(this );
49: text.text.addActionListener(this );
50:
51: setVisible(true);
52: }
53:
54: public void actionPerformed(ActionEvent e) {
55: if ((e.getSource() == ok) || (e.getSource() == text.text)) {
56: String name = text.getText();
57: setVisible(false);
58:
59: File f = new File(path + oldName);
60:
61: if (f.exists()) {
62: f.renameTo(new File(path + name));
63: }
64:
65: JFtp.localUpdate();
66:
67: Log.debug("Successfully renamed.");
68: }
69: }
70: }
|