?? configuratorlistener.java
字號(hào):
/* * Copyright (c) 2001 Sun Microsystems, Inc. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and thproe following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Sun Microsystems, Inc. for Project JXTA." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" * must not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact Project JXTA at http://www.jxta.org. * * 5. Products derived from this software may not be called "JXTA", * nor may "JXTA" appear in their name, without prior written * permission of Sun. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of Project JXTA. For more * information on Project JXTA, please see * <http://www.jxta.org/>. * * This license is based on the BSD license adopted by the Apache Foundation. * * $Id: ConfiguratorListener.java,v 1.7 2006/06/20 20:34:05 gonzo Exp $ */package net.jxta.ext.config.ui;import java.awt.Component;import java.awt.FileDialog;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowEvent;import java.lang.reflect.Field;import java.net.MalformedURLException;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;import java.util.Enumeration;import java.util.Iterator;import java.util.List;import java.util.Vector;import javax.swing.DefaultListModel;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JViewport;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.JTree;import javax.swing.ListModel;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.TreeModel;// import net.jxta.ext.config.Default;import net.jxta.exception.ConfiguratorException;import net.jxta.ext.config.Address;//import net.jxta.ext.config.Configurator;import net.jxta.ext.config.HttpTransport;import net.jxta.ext.config.MulticastAddress;import net.jxta.ext.config.Profile;import net.jxta.ext.config.Protocol;import net.jxta.ext.config.ProxyAddress;import net.jxta.ext.config.PublicAddress;import net.jxta.ext.config.TcpTransport;import net.jxta.ext.config.TcpTransportAddress;import net.jxta.ext.config.Trace;import net.jxta.ext.config.Transport;import net.jxta.ext.config.Util;import org.apache.log4j.Level;import org.apache.log4j.Logger;import org.swixml.SwingEngine;/** * Listener for ext:config:ui events * * @author volker john [volkerj at jxta dot org] */public class ConfiguratorListener implements ActionListener { private final transient static Logger LOG = Logger.getLogger(ConfiguratorListener.class.getName()); private static final String DLG_AUTOLOAD = "net/jxta/ext/config/ui/resource/Autoloader.xml"; static SwingEngine swix; static JTextField tcpPublicAddr; static JTextField tcpPublicPort; static JTextField httpPublicAddr; static JTextField httpPublicPort; static JTextField httpProxyAddr; static JTextField httpProxyPort; static JCheckBox tcpEnabled; static JCheckBox tcpManualEnabled; private JCheckBox tcpPublicEnabled; static JCheckBox httpEnabled; static JCheckBox httpManualEnabled; private JCheckBox httpPublicEnabled; static JCheckBox profileManualEnabled; static JTextField certFile; static JCheckBox rlyUsageEnabled; static JCheckBox rlySvcEnabled; static JCheckBox rdvSvcEnabled; static JCheckBox endpSvcEnabled; static JCheckBox proxySvcEnabled; static JPanel tcpPanel; static JPanel httpPanel; static JPanel rlyPanel; static JPanel rlySvcPanel; static JPanel rdvSvcPanel; static JPanel endpSvcPanel; static JPanel proxySvcPanel; static JCheckBox advEnabled; private Configurator configurator = null; public ConfiguratorListener(Configurator configurator, SwingEngine swix) { this.configurator = configurator; ConfiguratorListener.swix = swix; // _TODO we should certainly get rid of the static variables ('twas just simple) profileManualEnabled = (JCheckBox) swix.find("id_peerprofilemethod"); tcpPublicAddr = (JTextField) swix.find("id_tcppublicaddress"); tcpPublicPort = (JTextField) swix.find("id_tcppublicport"); httpPublicAddr = (JTextField) swix.find("id_httppublicaddress"); httpPublicPort = (JTextField) swix.find("id_httppublicport"); httpProxyAddr = (JTextField) swix.find("id_httpproxyaddress"); httpProxyPort = (JTextField) swix.find("id_httpproxyport"); tcpEnabled = (JCheckBox) swix.find("id_tcpenabled"); tcpManualEnabled = (JCheckBox) swix.find("id_tcpmanualaddresses"); tcpPublicEnabled = (JCheckBox) swix.find("id_tcphaspublicaddress"); httpEnabled = (JCheckBox) swix.find("id_httpenabled"); httpManualEnabled = (JCheckBox) swix.find("id_httpmanualaddresses"); httpPublicEnabled = (JCheckBox) swix.find("id_httphaspublicaddress"); certFile = (JTextField) swix.find("id_certfile"); rlyUsageEnabled = (JCheckBox) swix.find("id_cfguserly"); rlySvcEnabled = (JCheckBox) swix.find("id_cfgrlyservice"); rdvSvcEnabled = (JCheckBox) swix.find("id_cfgrdvservice"); endpSvcEnabled = (JCheckBox) swix.find("id_cfgendpservice"); proxySvcEnabled = (JCheckBox) swix.find("id_cfgproxyservice"); // do we have advanced settings available in the tree? advEnabled = (JCheckBox) swix.find("id_advenabled"); // find the panels we need tcpPanel = (JPanel) swix.find("id_cfgtcpcard"); httpPanel = (JPanel) swix.find("id_cfghttpcard"); rlyPanel = (JPanel) swix.find("id_cfgrlycard"); rlySvcPanel = (JPanel) swix.find("id_cfgrlyservicecard"); rdvSvcPanel = (JPanel) swix.find("id_cfgrdvservicecard"); endpSvcPanel = (JPanel) swix.find("id_cfgendpservicecard"); proxySvcPanel = (JPanel) swix.find("id_cfgproxyservicecard"); try { // get data from existing platform config, if any.// Configurator cfg = net.jxta.ext.config.ui.Configurator.getConfigurator(); // xxx: need to ensure backing configurator exists // look at AbstractConfigurator->Configurator life cycle net.jxta.ext.config.Configurator cfg = this.configurator.getConfigurator(); ((JTextField)swix.find("id_peername")).setText(cfg.getName()); // TODO principal does not equal secure peername! ((JTextField)swix.find("id_securepeername")).setText(cfg.getPrincipal()); // do the transport thing! Iterator transports = cfg.getTransports().iterator(); while (transports.hasNext()) { Transport t = (Transport)transports.next(); if (t instanceof TcpTransport) { // TODO same for http: why does getPublicAdresses return <null>? Iterator a = t.getAddresses().iterator(); if (a.hasNext()) { JComboBox auto = (JComboBox)swix.find("id_tcpautoentry"); TcpAddressComboModel model = ((TcpAddressComboModel) auto.getModel()); model.removeAllElements(); model.addDefault(); while (a.hasNext()) { URI addr = ((TcpTransportAddress)a.next()).getAddress(); model.addElement( addr.getScheme()+Protocol.URI_DELIMITER+ addr.getHost()); } } } else if (t instanceof HttpTransport) { Iterator a = t.getAddresses().iterator(); if (a.hasNext()) { JComboBox auto = (JComboBox)swix.find("id_httpautoentry"); TcpAddressComboModel model = ((TcpAddressComboModel) auto.getModel()); model.removeAllElements(); model.addDefault(); while (a.hasNext()) { URI addr = ((Address)a.next()).getAddress(); model.addElement( addr.getScheme()+Protocol.URI_DELIMITER+ addr.getHost()); } } } } // TODO how to find out about endpoint service setting? // maybe: if value == default then ignore? If yes, how to get the default? // endpSvcEnabled.setSelected(cfg.isEndpointService()); // TODO the frigging isProxy() does not work?! proxySvcEnabled.setSelected(cfg.isProxy()); JComboBox trace = ((JComboBox)swix.find("id_tracelevel")); trace.setSelectedItem(cfg.getTrace().toString()); JCheckBox rdvSvcAutostart = (JCheckBox) swix.find("id_rdvautostart"); JTextField rdvSvcAutoInterval = (JTextField) swix.find("id_rdvautostartinterval"); if (cfg.isRendezVous()) { rdvSvcEnabled.setSelected(true); // TODO getRdvAutostart vs. isRdvAutostart? rdvSvcAutostart.setSelected(cfg.isRendezVousAutoStart()); enable(((JPanel)(rdvSvcPanel.getComponents()[0])).getComponents()); rdvSvcAutoInterval.setText(String.valueOf(cfg.getRendezVousAutoStart())); } if (cfg.isRelay()) { rlySvcEnabled.setSelected(true); enable(((JPanel)(rlySvcPanel.getComponents()[0])).getComponents()); JTextField rlyQueueSize = (JTextField) swix.find("id_cfgrlyqueuesize"); JCheckBox rlyIncomingEnable = (JCheckBox) swix.find("id_cfgrlyincoming"); JTextField rlyIncomingMax = (JTextField) swix.find("id_rlyincomingmax"); JTextField rlyIncomingLease = (JTextField) swix.find("id_rlyincominglease"); JCheckBox rlyOutgoingEnable = (JCheckBox) swix.find("id_cfgrlyoutgoing"); JTextField rlyOutgoingMax = (JTextField) swix.find("id_rlyoutgoingmax"); JTextField rlyOutgoingLease = (JTextField) swix.find("id_rlyoutgoinglease"); rlyQueueSize.setText(String.valueOf(cfg.getRelayQueueSize())); rlyIncomingEnable.setSelected(cfg.isRelayIncoming()); int max = cfg.getRelayIncomingMaximum(); rlyIncomingMax.setText(String.valueOf(max)); rlyIncomingLease.setText(String.valueOf(cfg.getRelayIncomingLease())); rlyOutgoingEnable.setSelected(cfg.isRelayOutgoing()); rlyOutgoingMax.setText(String.valueOf(cfg.getRelayOutgoingMaximum())); rlyOutgoingLease.setText(String.valueOf(cfg.getRelayOutgoingLease())); } // TODO any way to find out whether manual settings are to be employed? tcpManualEnabled = (JCheckBox) swix.find("id_tcpmanualaddresses"); httpManualEnabled = (JCheckBox) swix.find("id_httpmanualaddresses"); tcpManualEnabled.setSelected(false); httpManualEnabled.setSelected(false); Iterator i = cfg.getRendezVous().iterator(); JList tcplist = (JList) swix.find("id_cfgtcprdvlist"); DefaultListModel tcpmodel = (DefaultListModel) tcplist.getModel(); JList httplist = (JList) swix.find("id_cfghttprdvlist"); DefaultListModel httpmodel = (DefaultListModel) httplist.getModel(); while (i.hasNext()) { URI addr = (URI)i.next(); // XXX if there ever are other rdvs than tcp and http, this is the place to change // of course you didn't notice, the would require a more flexible handling of the model stuff if (addr.getScheme().equalsIgnoreCase(Protocol.TCP)) { tcpmodel.addElement(addr.getAuthority()); } else { httpmodel.addElement(addr.getAuthority()); } } // the relay settings. // how to get information on whether relays are to be used or not? i = cfg.getRelays().iterator(); tcplist = (JList) swix.find("id_cfgtcprlylist"); tcpmodel = (DefaultListModel) tcplist.getModel(); httplist = (JList) swix.find("id_cfghttprlylist"); httpmodel = (DefaultListModel) httplist.getModel(); if (i.hasNext()) { rlyUsageEnabled.setSelected(true); enable(((JPanel)(rlyPanel.getComponents()[0])).getComponents()); setPublicHttp(); setHttpProxy(); while (i.hasNext()) { URI addr = (URI)i.next();
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -