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

📄 configuratorlistener.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        // TODO if no rdv is configured, this should fail        // ((JCheckBox)swix.find("id_useonlycfgedrdv")).isSelected());        // use listmodel to check if rdvs have been entered        // JList list = (JList) swix.find("id_cfgtcprdvlist");        // JList list = (JList) swix.find("id_cfghttprdvlist");        // the same applies for relays                        // TODO might want to address manual network interfaces        // JTable table = (JTable) swix.find("id_cfgtcptransporttable");        // TcpTransportTableModel tmodel = (TcpTransportTableModel) table.getModel();        // same for http                String peername = ((JTextField)swix.find("id_peername")).getText();        String secpeername = ((JTextField)swix.find("id_securepeername")).getText();        String peerpw = new String(((JPasswordField)swix.find("id_peerpassword")).getPassword());        String verify = new String(((JPasswordField)swix.find("id_peerpasswordverify")).getPassword());                if (peername.equals("")) {            JOptionPane.showMessageDialog(swix.getRootComponent(),                "Peer name cannot be empty.",                "Input Error",                JOptionPane.ERROR_MESSAGE);        } else if (secpeername.equals("")) {            JOptionPane.showMessageDialog(swix.getRootComponent(),                "Secure peer name cannot be empty.",                "Input Error",                JOptionPane.ERROR_MESSAGE);        } else if (peerpw.equals("") || verify.equals("")) {            JOptionPane.showMessageDialog(swix.getRootComponent(),                "Password & Verification must not be empty.",                "Input Error",                JOptionPane.ERROR_MESSAGE);        } else if (!peerpw.equals(verify)) {            JOptionPane.showMessageDialog(swix.getRootComponent(),                "Passwords do not match.",                "Input Error",                JOptionPane.ERROR_MESSAGE);        } else {            valid = true;        }                return valid;    }        /**     * @return     *     */    private boolean writeConfig() {        boolean saved = false;                // _TODO need to add checking whether we have manual or auto profiles;        // URL profileURL = new URL(((JComboBox)swix.find("id_peerprofilecombo")).getSelectedItem().toString());        // for now, go with auto profiles.        Profile profile = Profile.get(((JComboBox)swix.find("id_peerprofilecombo")).getSelectedItem().toString());        //Configurator cfg = new Configurator(profile);//        Configurator cfg = net.jxta.ext.config.ui.Configurator.getConfigurator();        // xxx: gonzo        net.jxta.ext.config.Configurator cfg = this.configurator.getConfigurator();                try {                        // if advanced is not enabled, we can ignore many of the settings and rely            // on the profile. Otherwise, use profile and then introduce individual changes            // as specified in advanced configuration by the user.            if (advEnabled.isSelected()) {                                // network overrides                cfg.setRendezVousDiscovery(                    ((JCheckBox)swix.find("id_useonlycfgedrdv")).isSelected());                                // someone has gone all the way to set some rdv addresses                JList list = (JList) swix.find("id_cfgtcprdvlist");                DefaultListModel model = (DefaultListModel) list.getModel();                                Vector alist = new Vector();                Enumeration each = model.elements();                                while (each.hasMoreElements()) {                    alist.addElement(new URI(Protocol.TCP_URI + each.nextElement()));                }                                list = (JList) swix.find("id_cfghttprdvlist");                model = (DefaultListModel) list.getModel();                each = model.elements();                                while (each.hasMoreElements()) {                    alist.addElement(new URI(Protocol.HTTP_URI + each.nextElement()));                }                                if (!alist.isEmpty()) {                    cfg.clearRendezVous();                    cfg.setRendezVous(alist);                }                                // Act as JXTA Proxy on NETWORK | RDV;                // also corresponds to cfg.isProxy call                cfg.setProxy(proxySvcEnabled.isSelected());                                if (rlyUsageEnabled.isSelected()) {                    // someone has gone all the way to set some rly addresses                    list = (JList) swix.find("id_cfgtcprlylist");                    model = (DefaultListModel) list.getModel();                                        alist = new Vector();                    each = model.elements();                                        while (each.hasMoreElements()) {                        alist.addElement(new URI(Protocol.TCP_URI + each.nextElement()));                    }                                        list = (JList) swix.find("id_cfghttprlylist");                    model = (DefaultListModel) list.getModel();                    each = model.elements();                                        while (each.hasMoreElements()) {                        alist.addElement(new URI(Protocol.HTTP_URI + each.nextElement()));                    }                                        cfg.setRelaysDiscovery(true);                    cfg.clearRelays();                    cfg.setRelays(alist);                } else {                    cfg.setRelaysDiscovery(false);                }                                // transport overrides, TCP                if (tcpEnabled.isSelected()) {                                        JTable table = (JTable) swix.find("id_cfgtcptransporttable");                    TcpTransportTableModel tmodel = (TcpTransportTableModel) table.getModel();                                        TcpTransport tcp = null;                    each = tmodel.getRows().elements();                    while (each.hasMoreElements()) {                                                tcp = new TcpTransport();                        TcpTransportAddress tcpaddr = new TcpTransportAddress();                        Object[] row = (Object[]) each.nextElement();                                                String addr;                                                // _TODO externalize string                        if (row[0].equals("Any/All Local Addresses")) {                            // _TODO allow for more than one local address (depends                            // on Util.getLocalHost return value (currently, a single address))                            addr = Util.getLocalHost();                        } else {                            addr = (String) row[0];                        }                                                String port = (String)row[1];                        boolean hidePrivate = ((Boolean)row[2]).booleanValue();                        boolean enableOut = ((Boolean)row[3]).booleanValue();                        boolean enableIn = ((Boolean)row[4]).booleanValue();                        String publicAddr = (!((String)row[5]).equals("./.") ? (String)row[5] : null);                        String publicPort = (!((String)row[6]).equals("./.") ? (String)row[6] : null);                        boolean enableMC = ((Boolean)row[7]).booleanValue();                                                tcpaddr.setAddress(new URI("tcp://" +                            addr + ":" +                            port));                        tcpaddr.setPortRange(0);                                                // Multicast address is required and we will just use default                        // values; however, it may be disabled.                        MulticastAddress mc = new MulticastAddress();                        mc.setMulticast(enableMC);                        tcpaddr.setMulticastAddress(mc);                                                tcp.setAddress(tcpaddr);                        tcp.setProxy(false);                        tcp.setEnabled(true);                        tcp.setIncoming(enableIn);                        tcp.setOutgoing(enableOut);                                                if (null != publicAddr && null != publicPort) {                            PublicAddress pubAddr = new PublicAddress();                            pubAddr.setAddress(new URI(Protocol.TCP_URI +                                publicAddr + ":" +                                publicPort                                ));                            tcp.setPublicAddress(pubAddr);                        }                                                cfg.addTransport(tcp);                                            }                                    }                                // transport overrides, HTTP                if (httpEnabled.isSelected()) {                                        JTable table = (JTable) swix.find("id_cfghttptransporttable");                    HttpTransportTableModel hmodel = (HttpTransportTableModel) table.getModel();                                        HttpTransport http = null;                    each = hmodel.getRows().elements();                    while (each.hasMoreElements()) {                                                http = new HttpTransport();                        Address httpaddr = new Address();                        Object[] row = (Object[]) each.nextElement();                                                String addr;                                                // _TODO externalize string                        if (row[0].equals("Any/All Local Addresses")) {                            // _TODO allow for more than one local address (depends                            // on Util.getLocalHost return value (currently, a single address))                            addr = Util.getLocalHost();                        } else {                            addr = (String) row[0];                        }                                                String port = (String)row[1];                        boolean hidePrivate = ((Boolean)row[2]).booleanValue();                        boolean enableOut = ((Boolean)row[3]).booleanValue();                        boolean enableIn = ((Boolean)row[4]).booleanValue();                        String publicAddr = (!((String)row[5]).equals("./.") ? (String)row[5] : null);                        String publicPort = (!((String)row[6]).equals("./.") ? (String)row[6] : null);                        boolean enableProxy = ((Boolean)row[7]).booleanValue();                        String proxyAddr = (!((String)row[8]).equals("./.") ? (String)row[8] : null);                        String proxyPort = (!((String)row[9]).equals("./.") ? (String)row[9] : null);                                                httpaddr.setAddress(new URI(Protocol.HTTP_URI +                            addr + ":" +                            port                            ));                        httpaddr.setPortRange(0);                                                http.setAddress(httpaddr);                        http.setEnabled(true);                        http.setIncoming(enableIn);                        http.setOutgoing(enableOut);                                                if (null != publicAddr && null != publicPort) {                            PublicAddress pubAddr = new PublicAddress();                            pubAddr.setAddress(new URI(Protocol.TCP_URI +                                publicAddr + ":" +                                publicPort                                ));                            http.setPublicAddress(pubAddr);                        }                                                if (enableProxy) {                            ProxyAddress proxy = new ProxyAddress();                            proxy.setAddress(new URI(Protocol.HTTP_URI +                                proxyAddr + ":" +                                proxyPort                                ));                            http.setProxyAddress(proxy);                        }                        http.setProxy(enableProxy);                                                cfg.addTransport(http);                                            }                                    }                                // services overrides                if (rdvSvcEnabled.isSelected()) {                    JCheckBox rdvSvcAutostart = (JCheckBox) swix.find("id_rdvautostart");                    JTextField rdvSvcAutoInterval = (JTextField) swix.find("id_rdvautostartinterval");                    if (rdvSvcAutostart.isSelected()) {                        // deprecated                        // cfg.setRendezVousAutoStart(true);                        cfg.setRendezVousAutoStart(new Integer(rdvSvcAutoInterval.getText()).longValue());                    } else {                        cfg.setRendezVous(true);                    }                                    }                                if (rlySvcEnabled.isSelected()) {                    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");                                        cfg.setRelay(true);                    cfg.setRelayQueueSize(new Integer(rlyQueueSize.getText()).intValue());                                        if (rlyIncomingEnable.isSelected()) {                        cfg.setRelayIncoming(true);                        cfg.setRelayIncomingMaximum(new Integer(rlyIncomingMax.getText()).intValue());                        cfg.setRelayIncomingLease(new Integer(rlyIncomingLease.getText()).longValue());                    }                    if (rlyOutgoingEnable.isSelected()) {                        cfg.setRelayOutgoing(true);                        cfg.setRelayOutgoingMaximum(new Integer(rlyOutgoingMax.getText()).intValue());                        cfg.setRelayOutgoingLease(new Integer(rlyOutgoingLease.getText()).longValue());                    }                }                                if (endpSvcEnabled.isSelected()) {                    JTextField endpQueueSize = (JTextField) swix.find("id_cfgendpqueuesize");                    cfg.setEndpointOutgoingQueueSize(new Integer(endpQueueSize.getText()).intValue());                }                                if (proxySvcEnabled.isSelected()) {                    JTextField peerProxyAddr = (JTextField) swix.find("id_prxsvcuri");                    cfg.setPeerProxyAddress(new URI(peerProxyAddr.getText()));                }                            }                        // the following entries do not change regardless whether we are doing away            // with an advanced or not so advanced configuration            cfg.setName(((JTextField)swix.find("id_peername")).getText());            cfg.setSecurity(((JTextField)swix.find("id_securepeername")).getText(),                new String(((JPasswordField)swix.find("id_peerpassword")).getPassword()));                        // _TODO if we were to fill the trace combo with objects obtained from Trace.getTraces,            // we possibly could simply assign the obj that corresponds to getSelectedItem.            Trace trace = Trace.get(((JComboBox)swix.find("id_tracelevel")).getSelectedItem().toString());            cfg.setTrace(trace);                        cfg.save();            saved = true;

⌨️ 快捷键说明

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