source: branches/2.2/jabberit_messenger/java_source/src/nu/fw/jeti/plugins/filetransfer/SendFileWindow.java @ 3102

Revision 3102, 5.7 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

  • Property svn:executable set to *
Line 
1/*
2 *      Jeti, a Java Jabber client, Copyright (C) 2004 E.S. de Boer 
3 *
4 *  This program is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program; if not, write to the Free Software
16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *      For questions, comments etc,
19 *      use the website at http://jeti.jabberstudio.org
20 *  or mail me at eric@jeti.tk
21 */
22 
23package nu.fw.jeti.plugins.filetransfer;
24
25import java.awt.GridBagConstraints;
26import java.awt.GridBagLayout;
27import java.awt.Insets;
28import java.awt.event.ActionEvent;
29import java.io.File;
30import java.text.MessageFormat;
31
32import javax.swing.*;
33
34import nu.fw.jeti.jabber.Backend;
35import nu.fw.jeti.jabber.JID;
36import nu.fw.jeti.util.I18N;
37import nu.fw.jeti.util.Popups;
38import nu.fw.jeti.util.Preferences;
39import nu.fw.jeti.util.Utils;
40
41//24-0kt-2004
42public class SendFileWindow extends JFrame
43{
44        private Backend backend;
45        private JID  jid;
46    private JLabel jLabel1 = new JLabel();
47    private JTextArea txtDescription = new JTextArea(4, 30);
48    private JButton btnSelect = new JButton();
49    private JTextField txtFilename = new JTextField();
50    private JLabel jLabel2 = new JLabel();
51    private JPanel btnPanel = new JPanel();
52    private JButton btnSend = new JButton();
53    private JButton btnCancel = new JButton();
54        private File file;
55
56        public SendFileWindow(Backend backend,JID to) {
57        this(backend, to, new File(""));
58    }
59
60        public SendFileWindow(Backend backend, JID to, File file) {
61                this.backend = backend;
62        this.file = file;
63                jid = to;
64                try {
65                        jbInit();
66        } catch(Exception e) {
67            e.printStackTrace();
68        }
69                pack();
70                setLocationRelativeTo(null);
71        toFront();
72                //TODO check if si supported by using disco
73        }
74
75        private void jbInit() throws Exception
76    {
77                getRootPane().setDefaultButton(btnSend);
78        setTitle(I18N.gettext("filetransfer.File_Transfer"));
79
80                txtFilename.setText(file.toString());
81
82        I18N.setTextAndMnemonic("filetransfer.Description", jLabel1);
83        jLabel1.setLabelFor(txtDescription);
84                jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
85        btnSelect.setText("...");
86        btnSelect.addActionListener(new java.awt.event.ActionListener()
87        {
88            public void actionPerformed(ActionEvent e)
89            {
90                btnSelect_actionPerformed(e);
91            }
92        });
93        I18N.setTextAndMnemonic("filetransfer.File_Name",jLabel2);
94        jLabel2.setLabelFor(txtFilename);
95                I18N.setTextAndMnemonic("filetransfer.Send",btnSend);
96        btnSend.addActionListener(new java.awt.event.ActionListener()
97        {
98            public void actionPerformed(ActionEvent e)
99            {
100                btnSend_actionPerformed(e);
101
102            }
103        });
104        Action cancelAction = new AbstractAction(I18N.gettext("Cancel"))
105                {
106                        public void actionPerformed(ActionEvent e)
107                        {
108                                dispose();
109                        }
110                };
111                Utils.addCancelButton(this, btnCancel, cancelAction);
112               
113        getContentPane().setLayout(new GridBagLayout());
114        GridBagConstraints c = new GridBagConstraints();
115        c.gridwidth = GridBagConstraints.REMAINDER;
116        c.anchor = GridBagConstraints.LINE_START;
117        c.fill = GridBagConstraints.BOTH;
118        c.insets = new Insets(3, 5, 0, 3);
119        c.weightx = 1.0;
120
121        getContentPane().add(jLabel2, c);
122
123        c.gridwidth = 1;
124        getContentPane().add(txtFilename, c);
125
126        c.weightx = 0.0;
127        c.gridwidth = GridBagConstraints.REMAINDER;
128        getContentPane().add(btnSelect, c);
129
130        getContentPane().add(jLabel1, c);
131
132        c.weightx = 1.0;
133        c.weighty = 1.0;
134        getContentPane().add(new JScrollPane(txtDescription), c);
135
136        c.weighty = 0.0;
137
138        btnPanel.add(btnSend, null);
139        btnPanel.add(btnCancel, null);
140        getContentPane().add(btnPanel, c);
141    }
142
143    void btnSelect_actionPerformed(ActionEvent e)
144    {
145       
146        JFileChooser fileChooser = Plugin.getFileChooser();
147        String dir = Preferences.getString("filetransfer", "uploadDir",null);
148        if(dir!=null)fileChooser.setCurrentDirectory(new File(dir));
149                int s = fileChooser.showOpenDialog(this);
150                if(s != JFileChooser.APPROVE_OPTION) {
151            return; //cancel
152        }
153                File file = fileChooser.getSelectedFile();
154                Preferences.putString("filetransfer", "uploadDir",file.getParent());
155                txtFilename.setText(file.getAbsolutePath());
156    }
157
158        void btnSend_actionPerformed(ActionEvent e)
159    {
160                file = new File(txtFilename.getText());
161        if (!file.isAbsolute()) {
162            file = new File(Plugin.getFileChooser().getCurrentDirectory(),
163                            txtFilename.getText());
164        }
165                if(!file.exists())
166                {
167                        Popups.errorPopup(MessageFormat.format(I18N.gettext("filetransfer.{0}_does_not_exist"), new Object[] { txtFilename.getText() }),I18N.gettext("filetransfer.File_Error"));
168                        return;
169                }
170                if(!file.canRead())
171                {
172                        Popups.errorPopup(MessageFormat.format(I18N.gettext("filetransfer.{0}_is_not_readable"), new Object[] { txtFilename.getText() }),"File Error");
173                        return;
174                }
175
176        new SendFileProgress(backend,jid,file,txtDescription.getText()).setVisible(true);
177        this.dispose();
178        }
179}
180/*
181 * Overrides for emacs
182 * Local variables:
183 * tab-width: 4
184 * End:
185 */
Note: See TracBrowser for help on using the repository browser.