KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > base > ResumeDialog


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.base;
17
18 import net.sf.jftp.*;
19 import net.sf.jftp.config.*;
20 import net.sf.jftp.gui.base.dir.DirEntry;
21 import net.sf.jftp.gui.framework.*;
22 import net.sf.jftp.net.*;
23
24 import java.awt.*;
25 import java.awt.event.*;
26
27 import java.io.*;
28
29 import javax.swing.*;
30 import javax.swing.event.*;
31
32
33 public class ResumeDialog extends HFrame implements ActionListener
34 {
35     private JButton resume = new JButton("Resume");
36     private JButton skip = new JButton("Skip");
37     private JButton over = new JButton("Overwrite");
38     private DirEntry dirEntry = null;
39
40     public ResumeDialog(DirEntry dirEntry)
41     {
42         this.dirEntry = dirEntry;
43
44         setLocation(150, 150);
45         setTitle("Question");
46
47         resume.setEnabled(false);
48
49         JTextArea text = new JTextArea();
50         text.append("A file named " + dirEntry.file +
51                     " already exists. \n\n");
52
53         File f = new File(JFtp.localDir.getPath() + dirEntry.file);
54         long diff = 0;
55
56         diff = dirEntry.getRawSize() - f.length();
57
58         if(diff == 0)
59         {
60             text.append("It has exactly the same size as the remote file.\n\n");
61         }
62         else if(diff < 0)
63         {
64             text.append("It is bigger than the remote file.\n\n");
65         }
66         else
67         {
68             text.append("It is smaller than the remote file.\n\n");
69             resume.setEnabled(true);
70         }
71
72         getContentPane().setLayout(new BorderLayout(5, 5));
73         getContentPane().add("Center", text);
74
75         HPanel p = new HPanel();
76         p.add(resume);
77         p.add(skip);
78         p.add(over);
79
80         getContentPane().add("South", p);
81
82         resume.addActionListener(this);
83         skip.addActionListener(this);
84         over.addActionListener(this);
85
86         pack();
87     fixLocation();
88         setVisible(true);
89     }
90
91     public void actionPerformed(ActionEvent e)
92     {
93         if(e.getSource() == resume)
94         {
95             this.dispose();
96             transfer();
97         }
98         else if(e.getSource() == skip)
99         {
100             this.dispose();
101         }
102         else if(e.getSource() == over)
103         {
104             this.dispose();
105
106             File f = new File(JFtp.localDir.getPath() + dirEntry.file);
107             f.delete();
108
109             transfer();
110         }
111     }
112
113     private void transfer()
114     {
115         if((dirEntry.getRawSize() < Settings.smallSize) &&
116                !dirEntry.isDirectory())
117         {
118             JFtp.remoteDir.getCon().download(dirEntry.file);
119         }
120         else
121         {
122             JFtp.remoteDir.getCon().handleDownload(dirEntry.file);
123         }
124     }
125 }
126
Popular Tags