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

📄 configdialog.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                }            }        });        cancel = new Button("Cancel");        cancel.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                beCanceled();            }        });        Panel okPanel = new Panel();        okPanel.add(ok);        okPanel.add(cancel);        // build basic panel        Panel basicsPanel = pages.addPage("Basic", "Basic settings");        GridBagConstraints centerWConstr = (GridBagConstraints) centerConstr.clone();        centerWConstr.weighty = 1;        basicsPanel.add(idPanel, centerWConstr);        // build Advanced panel        Panel advancedPanel = pages.addPage("Advanced", "Experienced Users Only");        advancedPanel.add(enablingPanel, fillInsetConstr);        advancedPanel.add(tcpPanel, fillInsetConstr);        advancedPanel.add(httpPanel, fillInsetConstr);        Panel proxyRdvRelayPanel = pages.addPage("Rendezvous/Relays", "Experienced Users Only");        proxyRdvRelayPanel.add(rdvPanel, fillInsetConstr);        proxyRdvRelayPanel.add(relayPanel, fillInsetConstr);        add(helpLabel, fillConstr);        add(pages, fillInsetConstr);        add(okPanel, centerLastConstr);        pack();        setVisible(true);    }    public synchronized boolean untilDone() {        try {            while (!done) {                wait();            }        } catch (InterruptedException e) {            Thread.interrupted();        }        if (canceled) {            throw new JxtaError("Canceled during configuration");        }        return (done);    }    private synchronized boolean beDone() {        done = true;        notify();        dispose();        return canceled;    }    private synchronized boolean beCanceled() {        canceled = true;        done = true;        notify();        dispose();        return canceled;    }    private boolean verifyPort(String portName, String ports, boolean dynamicok) {        int p1;        if ((null == ports) || (0 == ports.trim().length())) {            ports = "0";        }        try {            p1 = Integer.parseInt(ports);        } catch (Exception ex) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText(portName + " port number must be an integer: " + ports);            return false;        }        if ((p1 > 65535) || (p1 < (dynamicok ? 0 : 1))) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText(                    portName + " port number must be an integer between " + (dynamicok ? "0" : "1") + " and 65535, found " + p1);            return false;        }        return true;    }    private boolean verifyAddr(String proto, boolean serverOn, String localPort, String publicAddress, String publicPort) {        // if a public name is specified, check its port.        if (serverOn && (publicAddress.length() > 0)) {            if (!verifyPort(proto + " local", localPort, false)) {                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Dynamic tcp port selection not supported when server public address is specified.");                pages.showPage("Advanced");                return false;            }            if (!verifyPort(proto + " public", publicPort, false)) {                pages.showPage("Advanced");                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Dynamic tcp port selection not supported for server public address.");                return false;            }        } else if (!verifyPort(proto + " local", localPort, true)) {            pages.showPage("Advanced");            return false;        }        return true;    }    private boolean verifyInput() {        if (0 == idPanel.getName().trim().length()) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText("A peer name is required.");            pages.showPage("Basic");            return false;        }        // Verify security parameters if we are not initialized        // Password and principal        if (null != idPanel.passwd) {            String passwd = idPanel.getPassword();            String vpasswd = idPanel.getVerifyPassword();            // Verify password            // must be at least 8 chars a la unix            if (passwd.length() < 8) {                // Clear password text boxes                idPanel.clearPasswords();                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Passwords must be at least 8 characters");                pages.showPage("Basic");                return false;            }            // must be identical            if (!passwd.equals(vpasswd)) {                // Clear password text boxes                idPanel.clearPasswords();                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Password does not match Verify Password");                pages.showPage("Basic");                return false;            }        }        // make sure *some* transport is enabled.        if ((!(httpPanel.useMe.getState())) && (!(tcpPanel.useMe.getState()))) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText("At least one of TCP or HTTP must be enabled.");            pages.showPage("Advanced");            return false;        }        // http settings        if (httpPanel.useMe.getState()) {            // make sure at least incoming or outgoing enabled.            if (!httpPanel.clientEnabled.getState() && !httpPanel.publicAddr.getState()) {                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Must enable incoming and/or outcoming to enable HTTP");                pages.showPage("Advanced");                return false;            }            // Check the http port fields.            boolean valid = verifyAddr("HTTP", httpPanel.publicAddr.getState(), httpPanel.ifAddr.getPort(),                    httpPanel.publicAddr.getHost(), httpPanel.publicAddr.getPort());            if (!valid) {                return false;            }        }        // tcp settings        if (tcpPanel.useMe.getState()) {            // make sure at least incoming or outgoing enabled.            if (!tcpPanel.clientEnabled.getState() && !tcpPanel.publicAddr.getState() && !tcpPanel.multicast.getState()) {                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Must enable at least one of incoming, outcoming or multicast to enable TCP");                pages.showPage("Advanced");                return false;            }            // Check the tcp port fields.            boolean valid = verifyAddr("TCP", tcpPanel.publicAddr.getState(), tcpPanel.ifAddr.getPort(),                    tcpPanel.publicAddr.getHost(), tcpPanel.publicAddr.getPort());            if (!valid) {                return false;            }        }        if (!relayPanel.useRelay.getState() && (!httpPanel.useMe.getState() || !httpPanel.publicAddr.getState())                && (!tcpPanel.useMe.getState() || !tcpPanel.publicAddr.getState())) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText("Must use Relay if incoming not enabled for TCP and/or HTTP");            pages.showPage("Relay/Rendezvous");            return false;        }        if (enablingPanel.isRelay.getState() && (!httpPanel.useMe.getState() || !httpPanel.publicAddr.getState())                && (!tcpPanel.useMe.getState() || !tcpPanel.publicAddr.getState())) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText("Must enable incoming for TCP and/or HTTP to enable Relay");            pages.showPage("Advanced");            return false;        }        if (enablingPanel.isRendezvous.getState() && (!httpPanel.useMe.getState() || !httpPanel.publicAddr.getState())                && (!tcpPanel.useMe.getState() || !tcpPanel.publicAddr.getState())) {            helpLabel.setForeground(Color.red.darker());            helpLabel.setText("Must enable incoming for TCP and/or HTTP to enable Rendezvous");            pages.showPage("Advanced");            return false;        }        // if use only seeds is specified then at least one seed must be        // provided.        if (rdvPanel.useOnlySeeds.getState()) {            String[] rdvAddrs = rdvPanel.seeds.getItems();            String[] rdvSeedAddrs = rdvPanel.seeding.getItems();            if ((rdvAddrs.length == 0) && (rdvSeedAddrs.length == 0)) {                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Must provide at least one seed rendezvous");                pages.showPage("Rendezvous/Relays");                return false;            }        }        // if relay is to be used, make sure we have atleast one relay        // addr for the enabled transport(s)        if (relayPanel.useRelay.getState()) {            String[] relayaddrs = relayPanel.seeds.getItems();            String[] relaySeedaddrs = relayPanel.seeding.getItems();            if ((relayaddrs.length == 0) && (relaySeedaddrs.length == 0)) {                helpLabel.setForeground(Color.red.darker());                helpLabel.setText("Must provide at least one seed Relay address");                pages.showPage("Rendezvous/Relays");                return false;            }        }        return true;    }    /*     * Updates the PlatformConfig Advertisement     */    private boolean saveValues() {        try {            // set the peer name            configAdv.setName(idPanel.getName());            // Save the http config            HTTPAdv httpAdv = (HTTPAdv) AdvertisementFactory.newAdvertisement(HTTPAdv.getAdvertisementType());            httpAdv.setConfigMode(httpPanel.getConfigMode());            String chosenIntf = httpPanel.getInterfaceAddress();            if (chosenIntf.startsWith("A")) {                httpAdv.setInterfaceAddress(null);            } else {                httpAdv.setInterfaceAddress(chosenIntf);            }            httpAdv.setPort(Integer.parseInt(httpPanel.ifAddr.getPort()));            httpAdv.setClientEnabled(httpPanel.clientEnabled.getState());            httpAdv.setServerEnabled(httpPanel.publicAddr.getState());            // If there's nothing interesting inthere, do not save it.            if (0 == httpPanel.publicAddr.getHost().trim().length()) {                httpAdv.setServer(null);            } else {                httpAdv.setServer(httpPanel.publicAddr.getHost() + ":" + httpPanel.publicAddr.getPort());            }            httpAdv.setPublicAddressOnly(httpPanel.getPubAddrOnly());            configAdv.putServiceParam(PeerGroup.httpProtoClassID, wrapParm(httpAdv, httpPanel.useMe.getState()));            // Save tcp configuration            TCPAdv tcpAdv = (TCPAdv) AdvertisementFactory.newAdvertisement(TCPAdv.getAdvertisementType());            tcpAdv.setConfigMode(tcpPanel.getConfigMode());            chosenIntf = tcpPanel.getInterfaceAddress();            if (chosenIntf.startsWith("A")) {                tcpAdv.setInterfaceAddress(null);            } else {                tcpAdv.setInterfaceAddress(chosenIntf);            }            try {                int theTcpPort = Integer.parseInt(tcpPanel.ifAddr.getPort());                tcpAdv.setPort(theTcpPort);                if (0 == theTcpPort) {                    tcpAdv.setStartPort(0);                    tcpAdv.setEndPort(0);                }            } catch (NumberFormatException ignored) {                /* verifyInput already checked it */            }            tcpAdv.setClientEnabled(tcpPanel.clientEnabled.getState());            tcpAdv.setServerEnabled(tcpPanel.publicAddr.getState());            if (0 == tcpPanel.publicAddr.getHost().trim().length()) {                tcpAdv.setServer(null);            } else {                tcpAdv.setServer(tcpPanel.publicAddr.getHost() + ":" + tcpPanel.publicAddr.getPort());            }            tcpAdv.setMulticastState(tcpPanel.multicast.getState());            tcpAdv.setMulticastAddr(tcpMulticastAddr);            tcpAdv.setMulticastPort(tcpMulticastPort);            tcpAdv.setMulticastSize(tcpMulticastLength);            tcpAdv.setPublicAddressOnly(tcpPanel.getPubAddrOnly());            configAdv.putServiceParam(PeerGroup.tcpProtoClassID, wrapParm(tcpAdv, tcpPanel.useMe.getState()));            // save the proxy service settings            XMLDocument proxy = (XMLDocument) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Parm");            if (!enablingPanel.isJxmeProxy.getState()) {                proxy.appendChild(proxy.createElement("isOff"));            }            configAdv.putServiceParam(PeerGroup.proxyClassID, proxy);            // Save the Rendezvous Configuration            RdvConfigAdv rdvConf = (RdvConfigAdv) AdvertisementFactory.newAdvertisement(RdvConfigAdv.getAdvertisementType());            rdvConf.setConfiguration(                    enablingPanel.isRendezvous.getState() ? RendezVousConfiguration.RENDEZVOUS :                            rdvPanel.useRdv.getState() ? RendezVousConfiguration.EDGE : RendezVousConfiguration.AD_HOC);            rdvConf.setUseOnlySeeds(rdvPanel.useOnlySeeds.getState());            for (String s2 : Arrays.asList(rdvPanel.seeds.getItems())) {                rdvConf.addSeedRendezvous(s2);            }            for (String s3 : Arrays.asList(rdvPanel.seeding.getItems())) {                rdvConf.addSeedingURI(s3);            }            XMLDocument rdvDoc = (XMLDocument) rdvConf.getDocument(MimeMediaType.XMLUTF8);            configAdv.putServiceParam(PeerGroup.rendezvousClassID, rdvDoc);            // save the relay settings            RelayConfigAdv relayConfig = (RelayConfigAdv) AdvertisementFactory.newAdvertisement(                    RelayConfigAdv.getAdvertisementType());            relayConfig.setServerEnabled(enablingPanel.isRelay.getState());            relayConfig.setClientEnabled(relayPanel.useRelay.getState());            for (String s : Arrays.asList(relayPanel.seeds.getItems())) {                relayConfig.addSeedRelay(s);            }            for (String s1 : Arrays.asList(relayPanel.seeding.getItems())) {                relayConfig.addSeedingURI(s1);            }            relayConfig.setUseOnlySeeds(relayPanel.useOnlySeeds

⌨️ 快捷键说明

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