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

📄 bsfiletransferdialog.java

📁 一款即时通讯软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package edu.ou.kmi.buddyspace.gui;

/*
 * BSFileTransferDialog.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 22 August 2002, 11:49
 */

import javax.swing.*;
import java.io.*;
import java.net.*;

import org.jabber.jabberbeans.util.*;

import edu.ou.kmi.buddyspace.utils.*;

/**
 * Dialog for file upload and download. Allows specification of used proxy,
 * file and web server. After confirm up/downloads the file using
 * <code>URLFileTransfer</code> class methods.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class BSFileTransferDialog extends javax.swing.JDialog {
    
    private boolean receiving = false;
    private JID jid;
    private String urlStr = null;
    private BSMainFrame mainFrame;
    
    /** Creates new form BSFileTransferDialog for file download*/
    public BSFileTransferDialog(BSMainFrame mainFrame, String url, JID jid,
                                String proxy, String proxyPort) {
        super(mainFrame, true);
        this.mainFrame = mainFrame;
        initComponents();
        setTitle("Download file");
        
        receiving = true;
        
        addUrlPanel();
        jidLabel.setText("Sender");
        urlTextField.setText(url);
        urlTextField.setEnabled(false);
        urlStr = url;
        
        pack();
        setLocationRelativeTo(mainFrame);
        
        /*try {
            URL u = new URL(urlStr);
            File f = new File(u.getFile());
            fileTextField.setText(f.getName());
        } catch (MalformedURLException e) {}*/
        
        this.jid = jid;
        jidTextField.setText(jid.toString());
        proxyTextField.setText(proxy);
        proxyPortTextField.setText(proxyPort);
        
        boolean b = (proxy != null && !(new String("").equals(proxy)));
        useProxyCheckBox.setSelected(b);
        enableProxyPanel(b);
    }
    
    /** Creates new form BSFileTransferDialog for file upload*/
    public BSFileTransferDialog(BSMainFrame mainFrame, JID jid, 
                                String server, String port, String uploadPath,
                                String proxy, String proxyPort) {
        super(mainFrame, true);
        this.mainFrame = mainFrame;
        initComponents();
        setTitle("Upload file");
        
        receiving = false;
        
        addServerPanel();
        jidLabel.setText("Receiver");
        hostTextField.setText(server);
        portTextField.setText(port);
        pathTextField.setText(uploadPath);
        
        pack();
        setLocationRelativeTo(mainFrame);
        
        this.jid = jid;
        jidTextField.setText(jid.toString());
        proxyTextField.setText(proxy);
        proxyPortTextField.setText(proxyPort);
        
        boolean b = (proxy != null && !(new String("").equals(proxy)));
        useProxyCheckBox.setSelected(b);
        enableProxyPanel(b);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        proxyPanel = new javax.swing.JPanel();
        useProxyCheckBox = new javax.swing.JCheckBox();
        proxyParamPanel = new javax.swing.JPanel();
        proxyLabel = new javax.swing.JLabel();
        proxyPortLabel = new javax.swing.JLabel();
        proxyTextField = new javax.swing.JTextField();
        proxyPortTextField = new javax.swing.JTextField();
        jidPanel = new javax.swing.JPanel();
        jidLabel = new javax.swing.JLabel();
        jidTextField = new javax.swing.JTextField();
        filePanel = new javax.swing.JPanel();
        fileLabel = new javax.swing.JLabel();
        fileTextField = new javax.swing.JTextField();
        browseButton = new javax.swing.JButton();
        buttonPanel = new javax.swing.JPanel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        proxyPanel.setLayout(new java.awt.GridBagLayout());

        proxyPanel.setBorder(new javax.swing.border.TitledBorder("Proxy server"));
        useProxyCheckBox.setText("Use proxy server");
        useProxyCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BSFileTransferDialog.this.actionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        proxyPanel.add(useProxyCheckBox, gridBagConstraints);

        proxyParamPanel.setLayout(new java.awt.GridBagLayout());

        proxyLabel.setText("Proxy server");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 10);
        proxyParamPanel.add(proxyLabel, gridBagConstraints);

        proxyPortLabel.setText("Port");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 10);
        proxyParamPanel.add(proxyPortLabel, gridBagConstraints);

        proxyTextField.setColumns(30);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        proxyParamPanel.add(proxyTextField, gridBagConstraints);

        proxyPortTextField.setColumns(30);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        proxyParamPanel.add(proxyPortTextField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        proxyPanel.add(proxyParamPanel, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.5;
        getContentPane().add(proxyPanel, gridBagConstraints);

        jidPanel.setLayout(new java.awt.BorderLayout());

        jidPanel.setBorder(new javax.swing.border.TitledBorder(""));
        jidLabel.setText("Receiver");
        jidPanel.add(jidLabel, java.awt.BorderLayout.WEST);

        jidTextField.setColumns(30);
        jidTextField.setEditable(false);
        jidPanel.add(jidTextField, java.awt.BorderLayout.EAST);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(jidPanel, gridBagConstraints);

        filePanel.setLayout(new java.awt.GridBagLayout());

        filePanel.setBorder(new javax.swing.border.TitledBorder("File"));
        fileLabel.setText("File");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 10);
        filePanel.add(fileLabel, gridBagConstraints);

        fileTextField.setColumns(30);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
        filePanel.add(fileTextField, gridBagConstraints);

        browseButton.setText("Browse");
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BSFileTransferDialog.this.actionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        filePanel.add(browseButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.5;
        getContentPane().add(filePanel, gridBagConstraints);

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BSFileTransferDialog.this.actionPerformed(evt);
            }
        });

        buttonPanel.add(okButton);

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BSFileTransferDialog.this.actionPerformed(evt);
            }
        });

        buttonPanel.add(cancelButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(buttonPanel, gridBagConstraints);

        pack();
    }//GEN-END:initComponents

    /** Handles actions from buttons,.. */
    private void actionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionPerformed
        Object c = evt.getSource();
        
        // en/disables proxy
        if (c == useProxyCheckBox) {
            boolean b = useProxyCheckBox.isSelected();
            enableProxyPanel(b);
        }
        
        // opens file chooser
        else if (c == browseButton) {
            JFileChooser fileChooser;
            String path = fileTextField.getText();
            //if (path != "")

⌨️ 快捷键说明

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