⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesenddialog.java

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA
字号:
/* Copyright (C) 2003 Adam Olsen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother;import com.valhalla.jbother.jabber.smack.*;import org.jivesoftware.smack.PacketListener;import org.jivesoftware.smack.PacketCollector;import org.jivesoftware.smack.SmackConfiguration;import org.jivesoftware.smack.filter.PacketIDFilter;import org.jivesoftware.smack.packet.Packet;import org.jivesoftware.smack.packet.IQ;import com.valhalla.jbother.preferences.*;import org.jivesoftware.smackx.filetransfer.*;import java.awt.*;import java.awt.event.KeyEvent;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.util.*;import java.net.*;import java.io.File;import com.valhalla.settings.Settings;import javax.swing.*;/** * dialog for sending files. It is also a packet listener * *@author     Lukasz Wiechec *@created    Feb 2, 2005 4:52:15 PM */public class FileSendDialog extends FileDialog {    private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault() );    private static JFileChooser fileChooser = new JFileChooser();    public FileSendDialog(String jid) throws HeadlessException {        setTitle( "Send file" );        fromToLabel.setText( "To:" );        fromToTF.setText(jid);        fromToTF.setEditable(false);        ayeButton.setText( "Send" );        ayeButton.setMnemonic( KeyEvent.VK_S );        nayButton.setText( "Cancel" );        nayButton.setMnemonic( KeyEvent.VK_C );        descriptionArea.setEditable( true );        selectFile();    }    /**     * "Send" button pressed     * note: sending initial StreamInitiation message is done in separate thread, in order to prevent     * locking up JBother while waiting for the reply     */    protected void doAye() {        new FileSendThread().start();        dispose();    }    /**     * "Cancel" button pressed     */    protected void doNay() {        setVisible(false);        dispose();    }    class FileSendThread extends Thread    {        public void run()        {            FileProgressListener listener = null;            try {                FileTransferManager ft = ConnectorThread.getInstance().getFileTransferManager();                ft.clearHosts();                                String[] proxies = DataTransferPreferencesPanel.getProxies();                for(int i = 0; i < proxies.length; i++)                {                    ft.addStreamHost(proxies[i]);                }                                boolean preferIBB = Settings.getInstance().getBoolean("preferIBB");                if(preferIBB) ft.setPreferredType(FileTransferManager.TYPE_IBB);                else ft.setPreferredType(-1);                                FileSend send = ft.getFileSend(new File(fileChooser.getSelectedFile().getPath()), descriptionArea.getText());                send.setTo(fromToTF.getText());                listener = FileProgressDialog.getInstance().addFile(send, fileChooser.getSelectedFile().getName(), 0, send.getSize());                send.addProgressListener(listener);                send.send(fromToTF.getText());            }            catch(SocketException ex)            {                listener.update(FileTransferManager.Event.CANCELLED, 0, 0);            }            catch(Exception ex)            {                ex.printStackTrace();                listener.update(FileTransferManager.Event.ERROR, 0, 0);            }            return;        }    }    /**     * displays file chooser window and lets user select file to send     */    private void selectFile() {        int retval = fileChooser.showOpenDialog(BuddyList.getInstance().getContainerFrame());        if( retval == JFileChooser.APPROVE_OPTION ) {            File selectedFile = fileChooser.getSelectedFile();            if( ! selectedFile.exists() ) {                JOptionPane.showMessageDialog(this,                resources.getString("fileNotFound"),                resources.getString("sendFileError"),                JOptionPane.ERROR_MESSAGE);                return;            }            setVisible(true);            fileTF.setText(selectedFile.getPath());            fileTF.setEditable(false);        } else if( retval == JFileChooser.CANCEL_OPTION ) {            doNay();            return;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -