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

📄 configdialog.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

            setState(defaultState);
            useMe.addItemListener(this);
        }
    }

    class AutoLoader extends Dialog implements ActionListener, MouseListener {

        HostListPanel list1;
        HostListPanel list2;
        HostListPanel list3;
        Button load;
        Button quit;
        TextField urlField1;
        TextField urlField2;
        TextField urlField3;
        Label helpLabel;
        boolean once;

        String helpText =
        "Edit the urls below and click \"Load\". "
        + "Blank those you do not want to load. "
        + "Repeat if needed.";

        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(helpText);
        }

        private boolean loadList(TextField urlField, HostListPanel list) {
            String urlString = urlField.getText();
            if (urlString.equals("")) return true;
            helpLabel.setForeground(Color.black);
            helpLabel.setText("Trying " + urlString + "...");

            InputStream inp = null;
            try {
                inp = (new URL(urlString)).openStream();
                BufferedReader l
                = new BufferedReader(new InputStreamReader(inp));

                String s;
                int valid = 0;
                while ((s = l.readLine()) != null) {
                    if (list.addItem(s)) ++valid;
                }
                if (valid == 0) {
                    helpLabel.setForeground(Color.red.darker());
                    helpLabel.setText(urlString + ": not a valid list.");
                    return false;
                }
            } catch (MalformedURLException e) {
                helpLabel.setForeground(Color.red.darker());
                helpLabel.setText(urlString + ": malformed URL.");
                return false;
            } catch (IOException e) {
                helpLabel.setForeground(Color.red.darker());
                helpLabel.setText(urlString + ": not accessible. " +
                (idPanel.proxyPanel.getState() ? "" :
                    "You might need a proxy."));
                    return false;
            }
            try {
                inp.close();
            } catch (Exception e) {
            }
            helpLabel.setForeground(Color.black);
            helpLabel.setText(helpText);
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == quit) {
                dispose();
                return;
            }
            try {

                // XXX under JDK 1.x, system properties can not be set during
                // runtime
                if (idPanel.proxyPanel.getState()) {
                    //PDA requirements 19.02.2002
                    //java.lang.System.setProperty(String key, String value) vas not presented in jdk 1.1.8
                    //System.setProperty("http.proxyHost",
                    //idPanel.proxyPanel.getHost());
                    //System.setProperty("http.proxyPort",
                    //idPanel.proxyPanel.getPort());
                    Properties props = System.getProperties();
                    props.put("http.proxyHost", idPanel.proxyPanel.getHost());
                    props.put("http.proxyPort", idPanel.proxyPanel.getPort());
                    System.setProperties(props);
                    //PDA requirements 19.02.2002
                }
            } catch(Exception ee) {
                helpLabel.setForeground(Color.red.darker());
                helpLabel.setText("Cannot turn-on proxying w/ JDK 1.1. "
                + "you must edit your system properties.");
            }
            if (loadList(urlField1, list1)
            && loadList(urlField2, list2)
            && loadList(urlField3, list3)
            && once) {
                dispose();
            }
        }

        public AutoLoader(Frame owner,
        HostListPanel lst1,
        HostListPanel lst2,
        HostListPanel lst3,
        String defaultUrl1,
        String defaultUrl2,
        String defaultUrl3,
        boolean once) {
            super(owner, "Load list from URL", true);

            this.once = once;
            if (once) {
                helpText = "Edit the urls below and click \"Done\". "
                + "Blank those you do not want to load.";
            }
            setLayout(new BorderLayout());
            Panel cent = new Panel(new GridLayout(0, 1, 0, 0)) {
                public Insets getInsets() { return new Insets(0, 5, 0, 5); } };

                list1 = lst1;
                list2 = lst2;
                list3 = lst3;
                urlField1 = new TextField(defaultUrl1, 50);
                urlField2 = new TextField(defaultUrl2, 50);
                urlField3 = new TextField(defaultUrl3, 50);
                helpLabel = new Label(helpText, Label.CENTER);
                helpLabel.setBackground(new Color(220, 220, 220));
                helpLabel.setForeground(Color.black);
                load = new Button(once ? " Done " : " Load ");
                quit = new Button(once ? " Cancel " : " Dismiss ");
                Panel okPanel = new Panel();
                okPanel.add(load);
                okPanel.add(quit);
                Panel urlPanel1 = new Panel(new FlowLayout(FlowLayout.RIGHT));
                Panel urlPanel2 = new Panel(new FlowLayout(FlowLayout.RIGHT));
                Panel urlPanel3 = new Panel(new FlowLayout(FlowLayout.RIGHT));

                urlPanel1.add(new Label("Tcp rendez-vous list:"));
                urlPanel2.add(new Label("Http rendez-vous list:"));
                urlPanel3.add(new Label("HTTP relays list:"));

                urlPanel1.add(urlField1);
                urlPanel2.add(urlField2);
                urlPanel3.add(urlField3);

                add(helpLabel, BorderLayout.NORTH);
                cent.add(new Label("See also: http://platform.jxta.org/"
                + "java/rendezvous.html"));
                cent.add(urlPanel1);
                cent.add(urlPanel2);
                cent.add(urlPanel3);
                add(cent, BorderLayout.CENTER);
                add(okPanel, BorderLayout.SOUTH);

                helpLabel.addMouseListener(this);
                load.addActionListener(this);
                quit.addActionListener(this);

                pack();
                show();
        }
    }


    class HostListPanel extends PanelGBL
    implements ActionListener, ItemListener {

        public Checkbox useMe;
        private TextField host;
        private TextField port;
        private Button insert;
        private Button remove;

        private java.awt.List list;
        private Label listLabel;

        private ItemListener listener;

        public void setState(boolean state) {
            if (useMe != null) useMe.setState(state);
            list.setEnabled(state);
            host.setEnabled(state);
            port.setEnabled(state);
            insert.setEnabled(state);
            remove.setEnabled(state);
            listLabel.setEnabled(state);
        }

        public boolean getState() {
            return useMe.getState();
        }

        public void itemStateChanged(ItemEvent e) {
            if (e.getSource() == useMe) {
                if (useMe != null) setState(useMe.getState());
                listener.itemStateChanged(e);
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == insert) {
                if (addItem(host.getText() + ":" + port.getText())) {
                    host.setText("");
                    port.setText("");
                }
                return;
            }

            if (e.getSource() == remove) {
                int[] sel = list.getSelectedIndexes();
                int i = sel.length;
                while (i-- > 0) {
                    list.remove(sel[i]);
                }
                return;
            }
        }


        public HostListPanel(String lstLabel) {
            this(null, null, lstLabel, true);
        }

        public HostListPanel(ItemListener l, String checkLabel,
        String lstLabel,
        boolean defaultState) {

            super();
            listener = l;
            host = new TextField("", 16);
            port = new TextField("", 4);
            insert = new Button(" + ");
            remove = new Button(" - ");

            list = new java.awt.List(3, true);
            listLabel = new Label(lstLabel);

            PanelGBL p1 = new PanelGBL();
            PanelGBL p2 = new PanelGBL();

            GridBagConstraints c1 =
            (GridBagConstraints) leftLineConstr.clone();
            c1.insets = new Insets(0,0,0,0);

            p1.add(host, c1);
            p1.add(port, rightLineConstr);
            p1.add(list, fillConstr);
            p2.add(insert, fillConstr);
            p2.add(remove, fillConstr);

            GridBagConstraints c2 =
            (GridBagConstraints) rightLineConstr.clone();
            c2.anchor = GridBagConstraints.NORTHWEST;
            c2.insets = new Insets(4,2,2,8);

            if ((listener != null) && (checkLabel != null)) {
                useMe = new Checkbox(checkLabel, null, defaultState);
                add(useMe, stdConstr);
                useMe.addItemListener(this);
            }

            add(listLabel, stdConstr);
            add(p1, c1);
            add(p2, c2);

            setState(defaultState);
            insert.addActionListener(this);
            remove.addActionListener(this);
        }

        public boolean addItem(String item) {
            int i = item.indexOf(':');
            if (i == -1) return false;
            try {
                String ips = item.substring(0, i);
                String ports = item.substring(i + 1);
                int port = Integer.parseInt(ports);
                if (port < 0 || port > 65535) return false;
                list.add(ips.trim() + ":" + port);
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        public String[] getItems() {
            return list.getItems();
        }
    }

    class IfAddrPanel extends Panel implements ItemListener {
        private Choice ips;
        private Checkbox manual;
        private Checkbox alwaysManual;
        private TextField interfaceAddr;
        private Panel addrPanel;
        private CardLayout addrLayout;

        private void setManual(boolean m) {
            if (m) {
                addrLayout.show(addrPanel, "man");
            } else {
                addrLayout.show(addrPanel, "auto");
            }
            validate();
        }

        public void itemStateChanged(ItemEvent e) {
            if (e.getSource() == manual) {
                setManual(manual.getState());
            }
        }

        public String getAddress() {
            if (manual.getState()) {
                return interfaceAddr.getText();
            }
            return ips.getSelectedItem();
        }

        public String getMode() {
            if (manual.getState()) {
                if (alwaysManual.getState()) {
                    return "alwaysManual";
                } else {
                    return "manual";
                }
            } else {
                return "auto";
            }
        }

        public IfAddrPanel(String defaultInterfaceAddr,
        boolean prefAlwaysManual) {

            super();

            ips = new Choice();
            interfaceAddr = new TextField(defaultInterfaceAddr, 20);
            boolean modeManual = false;

            try {
                String hostName = InetAddress.getLocalHost().getHostAddress();
                InetAddress[] all = InetAddress.getAllByName(hostName);
                int i = all.length;
                while (i-->0) {
                    ips.addItem(all[i].getHostAddress());
                }

                // if an address was previously configured, switch to manual
                // if we do not find any interface, switch to manual too.
                if ( all.length == 0 || (defaultInterfaceAddr != null
                && !defaultInterfaceAddr.equals(""))) {

                    modeManual = true;

                    // However, if this address is in the automatic list,
                    // switch back to automatic and select it.
                    i = all.length;
                    while (i-->0) {
                        if (defaultInterfaceAddr.equals(all[i].getHostAddress())) {
                            modeManual = false;
                            ips.select(defaultInterfaceAddr);
                        }
                    }
                }
            } catch (Exception e) {

⌨️ 快捷键说明

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