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

📄 configdialog.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        public HostPortPanel publicAddr;
        public HostListPanel remote;
        private ItemListener listener;
        
        
        public void itemStateChanged(ItemEvent e) {
            
            // Cannot be a router and need one in the same time.
            // We handle that one more or less as a checkbox group. If you try
            // to turn one on, the other goes off. The difference is: both
            // may be off.
            
            if (   routerPanel.publicAddr.getState()
            && routerPanel.remote.getState()) {
                // Figure out what the user is clicking to decide what to
                // to turn off.
                if (e.getSource() == routerPanel.remote.useMe) {
                    routerPanel.publicAddr.setState(false);
                } else {
                    routerPanel.remote.setState(false);
                }
            }
            
            listener.itemStateChanged(e);
        }
        
        public RouterPanel(ItemListener l,
        String title,
        String defaultName, String defaultPort,
        boolean serverDefault, boolean routerDefault) {
            
            super(title);
            listener = l;
            publicAddr = new HostPortPanel(this,
            "Act as a relay (Both TCP and HTTP "
            + "must be enabled.)",
            "Public address (static NAT address)",
            defaultName,
            defaultPort,
            serverDefault);
            remote = new HostListPanel(this,
            "Use a relay "
            + "(Required if behind firewall/NAT)",
            "Available relays",
            routerDefault);
            add(publicAddr, stdConstr);
            add(remote, stdConstr);
        }
    }
    
    public void mousePressed(MouseEvent e) {
    }
    
    public void mouseReleased(MouseEvent e) {
    }
    
    public void mouseEntered(MouseEvent e) {
    }
    
    public void mouseExited(MouseEvent e) {
    }
    
    public void mouseClicked(MouseEvent e) {
        helpLabel.setForeground(Color.black);
        helpLabel.setText("See \"http://shell.jxta.org/index.html\" for config help");
    }
    
    
    public void itemStateChanged(ItemEvent e) {
        
        boolean routerPossible =
        (   tcpPanel.getState()
        && httpPanel.getState());
        
        // A remore router makes sense only if http is on.
        routerPanel.remote.setEnabled(httpPanel.getState());
        
        // Rendez-vous make sense only if their respective transports are on.
        rdvPanel.http.setEnabled(httpPanel.getState());
        rdvPanel.tcp.setEnabled(tcpPanel.getState());
        
        // Can be a router only if both transports are on.
        routerPanel.publicAddr.setEnabled(routerPossible);
        
        // A proxy does not make sense if there's no router.
        if (httpPanel.getState()) {
            idPanel.proxyPanel.setEnabled(routerPanel.remote.getState());
        }
    }
    
    public ConfigDialog(PeerAdvertisement cadv){
        
        super("JXTA Configurator");
        
        stdConstr = new GridBagConstraints();
        stdConstr.gridwidth = GridBagConstraints.REMAINDER;
        stdConstr.gridheight = 1;
        stdConstr.gridx = 0;
        stdConstr.gridy = GridBagConstraints.RELATIVE;
        stdConstr.fill = GridBagConstraints.NONE;
        stdConstr.weightx = 1;
        stdConstr.anchor = GridBagConstraints.NORTHWEST;
        stdConstr.insets = new Insets(0,0,0,0);
        
        fillConstr = (GridBagConstraints) stdConstr.clone();
        fillConstr.fill = GridBagConstraints.HORIZONTAL;
        
        centerConstr = (GridBagConstraints) stdConstr.clone();
        centerConstr.anchor = GridBagConstraints.NORTH;
        
        centerLastConstr = (GridBagConstraints) centerConstr.clone();
        centerLastConstr.weighty = 1;
        
        midLineConstr = new GridBagConstraints();
        midLineConstr.gridwidth = 1;
        midLineConstr.gridheight = 1;
        midLineConstr.fill = GridBagConstraints.NONE;
        midLineConstr.anchor = GridBagConstraints.EAST;
        midLineConstr.weightx = 0;
        
        midLineEastConstr = (GridBagConstraints) midLineConstr.clone();
        midLineEastConstr.anchor = GridBagConstraints.EAST;
        midLineEastConstr.weightx = 1;
        
        rightLineConstr = (GridBagConstraints) midLineConstr.clone();
        rightLineConstr.gridwidth = GridBagConstraints.REMAINDER;
        rightLineConstr.weightx = 1;
        rightLineConstr.anchor = GridBagConstraints.WEST;
        
        leftLineConstr = (GridBagConstraints) midLineConstr.clone();
        leftLineConstr.gridx = 0;
        leftLineConstr.weightx = 0;
        leftLineConstr.anchor = GridBagConstraints.WEST;
        leftLineConstr.insets = new Insets(0,20, 0, 20);
        
        GridBagConstraints fillInsetConstr =
        (GridBagConstraints)fillConstr.clone();
        fillInsetConstr.insets = new Insets(5,5,5,5);
        
        leftPanelConstr = (GridBagConstraints)fillConstr.clone();
        leftPanelConstr.gridwidth = 1;
        
        rightPanelConstr = (GridBagConstraints)fillConstr.clone();
        rightPanelConstr.gridwidth = GridBagConstraints.REMAINDER;;
        rightPanelConstr.gridx = GridBagConstraints.RELATIVE;
        
        
        configAdv = cadv;
        
        String dftDebugLevel = configAdv.getDebugLevel();
        
        boolean isRendezvous = false;
        Vector rdvs = new Vector();
        try {
            TextElement param = (TextElement)
            configAdv.getServiceParam(PeerGroup.rendezvousClassID);
            
            if (param != null) {
                Enumeration rdvEnum = param.getChildren("Addr");
                while (rdvEnum.hasMoreElements()) {
                    rdvs.addElement( ( (TextElement)
                    rdvEnum.nextElement() ).getTextValue() );
                }
                Enumeration rdv = param.getChildren("Rdv");
                isRendezvous =
                rdv.hasMoreElements()
                && "true".equals(((TextElement) rdv.nextElement()).getTextValue());
            }
        } catch (Exception nobigdeal) {
            nobigdeal.printStackTrace();
        }
        
        boolean isJxtaProxy = true;
        try {
            Element param =
            configAdv.getServiceParam(PeerGroup.proxyClassID);
	    // If there is no such param at all, we'll create it but the
	    // initial value is "Off".
            if (   param == null
		|| param.getChildren("isOff").hasMoreElements()) {
                isJxtaProxy = false;
            }
        } catch (Exception nobigdeal) {
            nobigdeal.printStackTrace();
        }

        boolean tcpDefault = true;
        boolean httpDefault = true;
        
        try {
            Element param =
            configAdv.getServiceParam(PeerGroup.httpProtoClassID);
            if (param.getChildren("isOff").hasMoreElements()) {
                httpDefault = false;
            }
            
            // FIXME 20011220 bondolo@jxta.org Temporarily accept both nodes of
            // type HTTPAdv and TransportAdvertisement.
            Enumeration httpChilds = param.getChildren(
            TransportAdvertisement.getAdvertisementType());
            
            // get the TransportAdv from either TransportAdv or HttpAdv
            if( httpChilds.hasMoreElements() ) {
                param = (Element) httpChilds.nextElement();
            } else {
                httpChilds = param.getChildren(
                HTTPAdv.getAdvertisementType());
                
                if( httpChilds.hasMoreElements() ) {
                    param = (Element) httpChilds.nextElement();
                }
            }
            
            httpAdv = (HTTPAdv)
            AdvertisementFactory.newAdvertisement((TextElement) param);
        } catch (Exception thatsbad) {
            thatsbad.printStackTrace();
            throw new RuntimeException("Broken PeerAdvertisement. Cannot proceed.");
        }
        
        try {
            Element param =
            configAdv.getServiceParam(PeerGroup.tcpProtoClassID);
            if (param.getChildren("isOff").hasMoreElements()) {
                tcpDefault = false;
            }
            
            // FIXME 20011220 bondolo@jxta.org Temporarily accept both nodes of
            // type TCPAdv and TransportAdvertisement.
            Enumeration tcpChilds = param.getChildren(
            TransportAdvertisement.getAdvertisementType());
            
            // get the TransportAdv from either TransportAdv or HttpAdv
            if( tcpChilds.hasMoreElements() ) {
                param = (Element) tcpChilds.nextElement();
            } else {
                tcpChilds = param.getChildren(
                TCPAdv.getAdvertisementType());
                
                if( tcpChilds.hasMoreElements() ) {
                    param = (Element) tcpChilds.nextElement();
                }
            }
            
            tcpAdv = (TCPAdv)
            AdvertisementFactory.newAdvertisement((TextElement) param);
        } catch (Exception thatsbad2) {
            thatsbad2.printStackTrace();
            throw new RuntimeException("Broken PeerAdvertisement. Cannot proceed.");
        }
        
        // Read-in the adv as it is now.
        boolean serverDefault = httpAdv.getServerEnabled();
        boolean proxyDefault = httpAdv.getProxyEnabled();
        boolean routerDefault = httpAdv.getRouterEnabled();
        
        String defaultServerNameH = httpAdv.getServer();
        String defaultProxyName = httpAdv.getProxy();
        Vector defaultRouters = httpAdv.getRouters();
        String defaultInterfaceAddressH = httpAdv.getInterfaceAddress();
        String configModeH = httpAdv.getConfigMode();
        
        String defaultServerNameT = tcpAdv.getServer();
        String defaultInterfaceAddressT = tcpAdv.getInterfaceAddress();
        String configModeT = tcpAdv.getConfigMode();
        
        boolean prefAlwaysManualH = true;
        boolean prefAlwaysManualT = true;
        
        // Looks funny but that's the way it is. True is the default
        // which applies in auto or default mode as well if alwaysManual
        // is set explicitly. Only when "manual" is set do we set the
        // preference to false. configMode controls other things
        // than just this preference.
        if (   (configModeH != null)
        && (configModeH.equals("manual"))) {
            prefAlwaysManualH = false;
        }
        if (   (configModeT != null)
        && (configModeT.equals("manual"))) {
            prefAlwaysManualT = false;
        }
        
        int index;
        String defaultProxyPort = "8080";
        
        String defaultServerPortH = "9700";
        String defaultPortH = httpAdv.getPort();
        
        String defaultServerPortT = "9701";
        String defaultPortT = tcpAdv.getPort();
        
        if ( defaultProxyName != null ) {
            index = defaultProxyName.indexOf(":");
            defaultProxyPort = defaultProxyName.substring(index + 1);
            defaultProxyName = defaultProxyName.substring(0, index);
        }
        
        if (defaultServerNameH != null
        && (index = defaultServerNameH.indexOf(":")) != -1) {
            defaultServerPortH = defaultServerNameH.substring(index + 1);
            defaultServerNameH = defaultServerNameH.substring(0, index);
        } else {
            defaultServerNameH = "";
            defaultServerPortH = "9700";
        }
        
        if (defaultServerNameT != null
        && (index = defaultServerNameT.indexOf(":")) != -1) {
            defaultServerPortT = defaultServerNameT.substring(index + 1);
            defaultServerNameT = defaultServerNameT.substring(0, index);
        } else {
            defaultServerNameT = "";
            defaultServerPortT = "9701";
        }
        
        if (   (defaultPortT == null)
        || defaultPortT.equals("") ) {
            defaultPortT = "9701";
        }
        
        if (   (defaultPortH == null)
        || defaultPortH.equals("") ) {
            defaultPortH = "9700";
        }
        String pn = configAdv.getName();
        
        helpLabel = new Label("See \"http://shell.jxta.org/index.html\" for config help", Label.CENTER);
        helpLabel.setBackground(new Color(220, 220, 220));
        helpLabel.setForeground(Color.black);
        
        idPanel = new IdPanel(pn,
        defaultProxyName,
        defaultProxyPort,
        proxyDefault);
        
        debugPanel = new DebugPanel(
        dftDebugLevel);
        
        
        tcpPanel = new TcpPanel(this,
        defaultInterfaceAddressT,
        defaultPortT,
        defaultServerNameT,
        defaultServerPortT,
        tcpDefault,
        prefAlwaysManualT);
        
        httpPanel = new HttpPanel(this,
        defaultInterfaceAddressH,
        defaultPortH,
        httpDefault,
        prefAlwaysManualH
        );
        
        routerPanel = new RouterPanel(this, "HTTP Relay Settings",
        defaultServerNameH,
        defaultServerPortH,
        serverDefault,
        routerDefault);
        
        // If security is already in place, then the security
        // panel is disabled. A user can only define the
        // principal role one time.
        //
        // We check to see if we will configure TLS now.
        if (TlsConfig.willConfigureTls()) {
            
            // Use initial panel
            secPanel = new SecPanel(true);
            
        } else {
            
            // Use explanation panel(Nothing to do)
            secPanel = new SecPanel(false);

⌨️ 快捷键说明

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