001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.base;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.config.*;
020: import net.sf.jftp.gui.base.dir.DirEntry;
021: import net.sf.jftp.gui.framework.*;
022: import net.sf.jftp.net.*;
023:
024: import java.awt.*;
025: import java.awt.event.*;
026:
027: import java.io.*;
028:
029: import javax.swing.*;
030: import javax.swing.event.*;
031:
032: public class ResumeDialog extends HFrame implements ActionListener {
033: private JButton resume = new JButton("Resume");
034: private JButton skip = new JButton("Skip");
035: private JButton over = new JButton("Overwrite");
036: private DirEntry dirEntry = null;
037:
038: public ResumeDialog(DirEntry dirEntry) {
039: this .dirEntry = dirEntry;
040:
041: setLocation(150, 150);
042: setTitle("Question");
043:
044: resume.setEnabled(false);
045:
046: JTextArea text = new JTextArea();
047: text.append("A file named " + dirEntry.file
048: + " already exists. \n\n");
049:
050: File f = new File(JFtp.localDir.getPath() + dirEntry.file);
051: long diff = 0;
052:
053: diff = dirEntry.getRawSize() - f.length();
054:
055: if (diff == 0) {
056: text
057: .append("It has exactly the same size as the remote file.\n\n");
058: } else if (diff < 0) {
059: text.append("It is bigger than the remote file.\n\n");
060: } else {
061: text.append("It is smaller than the remote file.\n\n");
062: resume.setEnabled(true);
063: }
064:
065: getContentPane().setLayout(new BorderLayout(5, 5));
066: getContentPane().add("Center", text);
067:
068: HPanel p = new HPanel();
069: p.add(resume);
070: p.add(skip);
071: p.add(over);
072:
073: getContentPane().add("South", p);
074:
075: resume.addActionListener(this );
076: skip.addActionListener(this );
077: over.addActionListener(this );
078:
079: pack();
080: fixLocation();
081: setVisible(true);
082: }
083:
084: public void actionPerformed(ActionEvent e) {
085: if (e.getSource() == resume) {
086: this .dispose();
087: transfer();
088: } else if (e.getSource() == skip) {
089: this .dispose();
090: } else if (e.getSource() == over) {
091: this .dispose();
092:
093: File f = new File(JFtp.localDir.getPath() + dirEntry.file);
094: f.delete();
095:
096: transfer();
097: }
098: }
099:
100: private void transfer() {
101: if ((dirEntry.getRawSize() < Settings.smallSize)
102: && !dirEntry.isDirectory()) {
103: JFtp.remoteDir.getCon().download(dirEntry.file);
104: } else {
105: JFtp.remoteDir.getCon().handleDownload(dirEntry.file);
106: }
107: }
108: }
|