KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > tasks > Renamer


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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
30 public class Renamer extends HFrame implements ActionListener
31 {
32     public HTextField text;
33     private HButton ok = new HButton("Ok");
34     private HPanel okP = new HPanel();
35     private String JavaDoc oldName;
36     private String JavaDoc path;
37
38     public Renamer(String JavaDoc oldName, String JavaDoc path)
39     {
40         this.oldName = oldName;
41         this.path = path;
42
43         setSize(400, 80);
44         setTitle("Enter new name...");
45         setLocation(150, 150);
46         getContentPane().setLayout(new FlowLayout());
47
48         text = new HTextField("Name: ", oldName);
49         getContentPane().add(text);
50         getContentPane().add(ok);
51         ok.addActionListener(this);
52         text.text.addActionListener(this);
53
54         setVisible(true);
55     }
56
57     public void actionPerformed(ActionEvent e)
58     {
59         if((e.getSource() == ok) || (e.getSource() == text.text))
60         {
61             String JavaDoc name = text.getText();
62             setVisible(false);
63
64             File f = new File(path + oldName);
65
66             if(f.exists())
67             {
68                 f.renameTo(new File(path + name));
69             }
70
71             JFtp.localUpdate();
72
73             Log.debug("Successfully renamed.");
74         }
75     }
76 }
77
Popular Tags