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

📄 xconnectionoptionpage.java

📁 XBrowser是一个完全免费并且开源的Web浏览器
💻 JAVA
字号:
/****************************************************************
*              XBrowser  -  eXtended web Browser                *
*                                                               *
*           Copyright (c) 2000-2001  Armond Avanes              *
*     Refer to ReadMe & License files for more information      *
*                                                               *
*                                                               *
*                      By: Armond Avanes                        *
*       Armond555@yahoo.com     &    Armond333@yahoo.com        *
*                http://xbrowser.sourceforge.net/               *
*****************************************************************/
package xbrowser.options;

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;

import xbrowser.*;
import xbrowser.util.*;
import xbrowser.widgets.*;

public class XConnectionOptionPage extends XOptionPage
{
	public XConnectionOptionPage()
	{
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();

    	setLayout(gridbag);

        constraints.fill = GridBagConstraints.BOTH;
        constraints.insets = new Insets(5,5,5,5);

		addToContainer(getConnectionPage1(),this,gridbag,constraints,GridBagConstraints.REMAINDER,1);

        constraints.gridheight = GridBagConstraints.REMAINDER;
        constraints.weighty = 1;
		addToContainer(getConnectionPage2(),this,gridbag,constraints,GridBagConstraints.REMAINDER,1);

		registerListeners();
	}

    private JComponent getConnectionPage1()
    {
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    JPanel pnl_connection = new JPanel(gridbag);
	char valid_chars[] = {'0','1','2','3','4','5','6','7','8','9'};

	    txfHttpProxyPort.setDocument( new XLimitedDocument(valid_chars) );
	    txfFtpProxyPort.setDocument( new XLimitedDocument(valid_chars) );
	    txfSocksProxyPort.setDocument( new XLimitedDocument(valid_chars) );
	    txfGopherProxyPort.setDocument( new XLimitedDocument(valid_chars) );

        constraints.fill = GridBagConstraints.BOTH;
        constraints.insets = new Insets(2,2,2,2);
		pnl_connection.setBorder( BorderFactory.createEtchedBorder() );

		addToContainer(XRepository.getComponentBuilder().buildLabel(this, "UseProxy"),pnl_connection,gridbag,constraints,2,1);
		addToContainer(XRepository.getComponentBuilder().buildLabel(this, "ProxyType"),pnl_connection,gridbag,constraints,2,1);
		addToContainer(XRepository.getComponentBuilder().buildLabel(this, "ProxyAddress"),pnl_connection,gridbag,constraints,5,1);
		addToContainer(XRepository.getComponentBuilder().buildLabel(this, "ProxyPort"),pnl_connection,gridbag,constraints,GridBagConstraints.REMAINDER,1);

		addToContainer(chkUseHttpProxy,pnl_connection,gridbag,constraints,2,1);
		addToContainer(lblHttpType,pnl_connection,gridbag,constraints,2,1);
		addToContainer(txfHttpProxyAddress,pnl_connection,gridbag,constraints,4,1);
		addToContainer(lblHttpColon,pnl_connection,gridbag,constraints,1,0);
		addToContainer(txfHttpProxyPort,pnl_connection,gridbag,constraints,GridBagConstraints.REMAINDER,1);

		addToContainer(chkUseFtpProxy,pnl_connection,gridbag,constraints,2,1);
		addToContainer(lblFtpType,pnl_connection,gridbag,constraints,2,1);
		addToContainer(txfFtpProxyAddress,pnl_connection,gridbag,constraints,4,1);
		addToContainer(lblFtpColon,pnl_connection,gridbag,constraints,1,0);
		addToContainer(txfFtpProxyPort,pnl_connection,gridbag,constraints,GridBagConstraints.REMAINDER,1);

		addToContainer(chkUseGopherProxy,pnl_connection,gridbag,constraints,2,1);
		addToContainer(lblGopherType,pnl_connection,gridbag,constraints,2,1);
		addToContainer(txfGopherProxyAddress,pnl_connection,gridbag,constraints,4,1);
		addToContainer(lblGopherColon,pnl_connection,gridbag,constraints,1,0);
		addToContainer(txfGopherProxyPort,pnl_connection,gridbag,constraints,GridBagConstraints.REMAINDER,1);

		addToContainer(chkUseSocksProxy,pnl_connection,gridbag,constraints,2,1);
		addToContainer(lblSocksType,pnl_connection,gridbag,constraints,2,1);
		addToContainer(txfSocksProxyAddress,pnl_connection,gridbag,constraints,4,1);
		addToContainer(lblSocksColon,pnl_connection,gridbag,constraints,1,0);
		addToContainer(txfSocksProxyPort,pnl_connection,gridbag,constraints,GridBagConstraints.REMAINDER,1);

		return pnl_connection;
	}

    private JComponent getConnectionPage2()
    {
	JPanel pnl_connection = new JPanel( new BorderLayout() );
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
	JPanel pnl_north = new JPanel(gridbag);
	JPanel pnl_center = new JPanel( new BorderLayout() );

        constraints.fill = GridBagConstraints.BOTH;
        constraints.insets = new Insets(5,5,5,5);

		addToContainer(XRepository.getComponentBuilder().buildLabel(this, "UserName"),pnl_north,gridbag,constraints,1,0);
		addToContainer(txfUserName,pnl_north,gridbag,constraints,2,1);
		addToContainer(XRepository.getComponentBuilder().buildLabel(this, "Password"),pnl_north,gridbag,constraints,1,0);
		addToContainer(txfPassword,pnl_north,gridbag,constraints,GridBagConstraints.REMAINDER,1);
		pnl_north.setBorder( new TitledBorder(XRepository.getResourceManager().getProperty(this, "AuthInfo")) );

		pnl_center.add(BorderLayout.NORTH, XRepository.getComponentBuilder().buildLabel(this, "ExceptionDescription"));
		pnl_center.add(BorderLayout.CENTER, new JScrollPane(txaExceptions, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
		pnl_center.add(BorderLayout.SOUTH, XRepository.getComponentBuilder().buildLabel(this, "SeparatingEntries"));
		pnl_center.setBorder( new TitledBorder(XRepository.getResourceManager().getProperty(this, "Exception")) );

		pnl_connection.add(BorderLayout.NORTH, pnl_north);
		pnl_connection.add(BorderLayout.CENTER, pnl_center);
		pnl_connection.setBorder( BorderFactory.createEtchedBorder() );

		return pnl_connection;
	}

	private void registerListeners()
	{
        chkUseHttpProxy.addItemListener( new ItemListener() {
			public void itemStateChanged(ItemEvent e)
			{
				txfHttpProxyAddress.setEnabled(chkUseHttpProxy.isSelected());
				txfHttpProxyPort.setEnabled(chkUseHttpProxy.isSelected());
				lblHttpType.setEnabled(chkUseHttpProxy.isSelected());
				lblHttpColon.setEnabled(chkUseHttpProxy.isSelected());
			}
		});

        chkUseFtpProxy.addItemListener( new ItemListener() {
			public void itemStateChanged(ItemEvent e)
			{
				txfFtpProxyAddress.setEnabled(chkUseFtpProxy.isSelected());
				txfFtpProxyPort.setEnabled(chkUseFtpProxy.isSelected());
				lblFtpType.setEnabled(chkUseFtpProxy.isSelected());
				lblFtpColon.setEnabled(chkUseFtpProxy.isSelected());
			}
		});

        chkUseSocksProxy.addItemListener( new ItemListener() {
			public void itemStateChanged(ItemEvent e)
			{
				txfSocksProxyAddress.setEnabled(chkUseSocksProxy.isSelected());
				txfSocksProxyPort.setEnabled(chkUseSocksProxy.isSelected());
				lblSocksType.setEnabled(chkUseSocksProxy.isSelected());
				lblSocksColon.setEnabled(chkUseSocksProxy.isSelected());
			}
		});

        chkUseGopherProxy.addItemListener( new ItemListener() {
			public void itemStateChanged(ItemEvent e)
			{
				txfGopherProxyAddress.setEnabled(chkUseGopherProxy.isSelected());
				txfGopherProxyPort.setEnabled(chkUseGopherProxy.isSelected());
				lblGopherType.setEnabled(chkUseGopherProxy.isSelected());
				lblGopherColon.setEnabled(chkUseGopherProxy.isSelected());
			}
		});
	}

	public String getName()
	{
		return XRepository.getResourceManager().getProperty(this, "Title");
	}

	public ImageIcon getIcon()
	{
		return XRepository.getComponentBuilder().buildImageIcon(this, "image.icon");
	}

	public void loadInfo()
	{
    XProxyServer proxy;

        proxy = XRepository.getConfiguration().getHttpProxy();
        chkUseHttpProxy.setSelected(proxy.getUseProxy());
        txfHttpProxyAddress.setText(proxy.getProxyAddress());
        txfHttpProxyPort.setText(proxy.getProxyPort());

        proxy = XRepository.getConfiguration().getFtpProxy();
        chkUseFtpProxy.setSelected(proxy.getUseProxy());
        txfFtpProxyAddress.setText(proxy.getProxyAddress());
        txfFtpProxyPort.setText(proxy.getProxyPort());

        proxy = XRepository.getConfiguration().getSocksProxy();
        chkUseSocksProxy.setSelected(proxy.getUseProxy());
        txfSocksProxyAddress.setText(proxy.getProxyAddress());
        txfSocksProxyPort.setText(proxy.getProxyPort());

        proxy = XRepository.getConfiguration().getGopherProxy();
        chkUseGopherProxy.setSelected(proxy.getUseProxy());
        txfGopherProxyAddress.setText(proxy.getProxyAddress());
        txfGopherProxyPort.setText(proxy.getProxyPort());

        txfUserName.setText(XRepository.getConfiguration().getUserName());
        txfPassword.setText(XRepository.getConfiguration().getPassword());
        txaExceptions.setText(XRepository.getConfiguration().getProxyExceptions());
	}

	public void saveInfo()
	{
    XProxyServer proxy;

        proxy = new XProxyServer();
        proxy.setUseProxy( chkUseHttpProxy.isSelected() );
        proxy.setProxyAddress( txfHttpProxyAddress.getText() );
        proxy.setProxyPort( txfHttpProxyPort.getText() );
        XRepository.getConfiguration().setHttpProxy(proxy);

        proxy = new XProxyServer();
        proxy.setUseProxy( chkUseFtpProxy.isSelected() );
        proxy.setProxyAddress( txfFtpProxyAddress.getText() );
        proxy.setProxyPort( txfFtpProxyPort.getText() );
        XRepository.getConfiguration().setFtpProxy(proxy);

        proxy = new XProxyServer();
        proxy.setUseProxy( chkUseSocksProxy.isSelected() );
        proxy.setProxyAddress( txfSocksProxyAddress.getText() );
        proxy.setProxyPort( txfSocksProxyPort.getText() );
        XRepository.getConfiguration().setSocksProxy(proxy);

        proxy = new XProxyServer();
        proxy.setUseProxy( chkUseGopherProxy.isSelected() );
        proxy.setProxyAddress( txfGopherProxyAddress.getText() );
        proxy.setProxyPort( txfGopherProxyPort.getText() );
        XRepository.getConfiguration().setGopherProxy(proxy);

        XRepository.getConfiguration().setUserName( txfUserName.getText() );
        XRepository.getConfiguration().setPassword( new String(txfPassword.getPassword()) );
        XRepository.getConfiguration().setProxyExceptions( txaExceptions.getText() );
	}

// Attribute:
    private JCheckBox chkUseHttpProxy = new JCheckBox();
    private JTextField txfHttpProxyAddress = new JTextField(20);
    private JTextField txfHttpProxyPort = new JTextField(5);
    private JLabel lblHttpType = new JLabel("HTTP");
    private JLabel lblHttpColon = new JLabel(":");

    private JCheckBox chkUseFtpProxy = new JCheckBox();
    private JTextField txfFtpProxyAddress = new JTextField(20);
    private JTextField txfFtpProxyPort = new JTextField(5);
    private JLabel lblFtpType = new JLabel("FTP");
    private JLabel lblFtpColon = new JLabel(":");

    private JCheckBox chkUseSocksProxy = new JCheckBox();
    private JTextField txfSocksProxyAddress = new JTextField(20);
    private JTextField txfSocksProxyPort = new JTextField(5);
    private JLabel lblSocksType = new JLabel("Socks");
    private JLabel lblSocksColon = new JLabel(":");

    private JCheckBox chkUseGopherProxy = new JCheckBox();
    private JTextField txfGopherProxyAddress = new JTextField(20);
    private JTextField txfGopherProxyPort = new JTextField(5);
    private JLabel lblGopherType = new JLabel("Gopher");
    private JLabel lblGopherColon = new JLabel(":");

    private JTextField txfUserName = new JTextField(7);
    private JPasswordField txfPassword = new JPasswordField(7);
    private JTextArea txaExceptions = new JTextArea();
}

⌨️ 快捷键说明

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