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

📄 configdialog.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (c) 2001-2007 Sun Microsystems, Inc.  All rights reserved. *   *  The Sun Project JXTA(TM) Software License *   *  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 the 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 Sun Microsystems, Inc. for JXTA(TM) technology."  *     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 SUN  *  MICROSYSTEMS 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. *   *  JXTA is a registered trademark of Sun Microsystems, Inc. in the United  *  States and other countries. *   *  Please see the license information page at : *  <http://www.jxta.org/project/www/license.html> for instructions on use of  *  the license in source files. *   *  ==================================================================== *   *  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.  */package net.jxta.impl.peergroup;import java.awt.BorderLayout;import java.awt.Button;import java.awt.CardLayout;import java.awt.Checkbox;import java.awt.Choice;import java.awt.Color;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Frame;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.Label;import java.awt.Panel;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.net.InetAddress;import java.net.URI;import java.net.URISyntaxException;import java.util.ArrayList;import java.util.Arrays;import java.util.Enumeration;import java.util.Iterator;import java.util.List;import java.util.NoSuchElementException;import net.jxta.document.Advertisement;import net.jxta.document.AdvertisementFactory;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocumentFactory;import net.jxta.document.StructuredDocumentUtils;import net.jxta.document.XMLDocument;import net.jxta.document.XMLElement;import net.jxta.endpoint.EndpointAddress;import net.jxta.peergroup.PeerGroup;import net.jxta.protocol.TransportAdvertisement;import net.jxta.exception.JxtaError;import net.jxta.exception.ConfiguratorException;import net.jxta.impl.endpoint.IPUtils;import net.jxta.impl.membership.pse.PSEUtils;import net.jxta.impl.protocol.HTTPAdv;import net.jxta.impl.protocol.PSEConfigAdv;import net.jxta.impl.protocol.PlatformConfig;import net.jxta.impl.protocol.RdvConfigAdv;import net.jxta.impl.protocol.RdvConfigAdv.RendezVousConfiguration;import net.jxta.impl.protocol.RelayConfigAdv;import net.jxta.impl.protocol.TCPAdv;/** * The standard and much loved AWT Configuration dialog */@SuppressWarnings("serial")public class ConfigDialog extends Frame {    static final GridBagConstraints stdConstr;    static final GridBagConstraints centerConstr;    static final GridBagConstraints centerLastConstr;    static final GridBagConstraints fillConstr;    static final GridBagConstraints fillInsetConstr;    static {        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;        fillInsetConstr = (GridBagConstraints) fillConstr.clone();        fillInsetConstr.insets = new Insets(5, 5, 5, 5);    }    // A few widgets.    /**     * Grid Bag layout panel     */    static class PanelGBL extends Panel {        protected Insets insets = new Insets(0, 0, 0, 0);        GridBagLayout lay = new GridBagLayout();        private static final GridBagConstraints constrLabel = new GridBagConstraints();        static {            constrLabel.gridwidth = GridBagConstraints.REMAINDER;            constrLabel.gridheight = 1;            constrLabel.gridy = GridBagConstraints.RELATIVE;            constrLabel.weightx = 1;            constrLabel.weighty = 1;            constrLabel.anchor = GridBagConstraints.FIRST_LINE_START;            constrLabel.fill = GridBagConstraints.HORIZONTAL;        }        public PanelGBL(String label) {            this();            add(new Label(label, Label.LEFT), constrLabel);        }        public PanelGBL() {            super();            setLayout(lay);        }        /**         * {@inheritDoc}         */        @Override        public Insets getInsets() {            return insets;        }    }    /**     * A Grid Bag Panel with a border     */    static class BorderPanelGBL extends PanelGBL {        public static final int NONE = 0;        public static final int RAISED = 1;        public static final int LOWERED = 2;        public static final int GROOVE = 3;        public static final int BUMP = 4;        int style = GROOVE;        String title;        int ascent = 0;        int descent = 0;        int leading = 0;        int titleWidth = 0;        public BorderPanelGBL(String title) {            super();            this.title = title;        }        public BorderPanelGBL(String title, String advice) {            super(advice);            this.title = title;        }        public BorderPanelGBL(String title, String advice, int s) {            super(advice);            this.title = title;            if ((s < NONE) && (s > BUMP)) {                return;            }            if ((s == RAISED) || (s == LOWERED)) {                this.title = null;            }            style = s;        }        private void checkMetrics() {            Font font = getFont();            if ((title == null) || (font == null)) {                ascent = 2;            } else {                FontMetrics fmetrics = getFontMetrics(font);                ascent = fmetrics.getAscent();                descent = fmetrics.getDescent();                leading = fmetrics.getLeading();                titleWidth = fmetrics.stringWidth(title);            }            insets = new Insets(descent + ascent + leading + 2, 7, 7, 7);        }        /**         * {@inheritDoc}         */        @Override        public Insets getInsets() {            checkMetrics();            return insets;        }        private void paintLowered(Graphics g) {            checkMetrics();            if (ascent == 0) {                return;            }            Dimension d = getSize();            g.setColor(Color.black);            g.drawRect(1, ascent - 2, d.width - 4, d.height - ascent);            g.setColor(Color.white);            g.drawRect(2, ascent - 1, d.width - 4, d.height - ascent);            g.setColor(getBackground());            g.drawRect(2, ascent - 1, d.width - 5, d.height - ascent - 1);        }        private void paintRaised(Graphics g) {            checkMetrics();            if (ascent == 0) {                return;            }            Dimension d = getSize();            g.setColor(Color.white);            g.drawRect(1, ascent - 2, d.width - 4, d.height - ascent);            g.setColor(Color.black);            g.drawRect(2, ascent - 1, d.width - 4, d.height - ascent);            g.setColor(getBackground());            g.drawRect(2, ascent - 1, d.width - 5, d.height - ascent - 1);        }        private void paintGroove(Graphics g) {            checkMetrics();            if (ascent == 0) {                return;            }            Dimension d = getSize();            g.setColor(Color.black);            g.drawRect(1, ascent - 2, d.width - 4, d.height - ascent);            g.setColor(Color.white);            g.drawRect(2, ascent - 1, d.width - 4, d.height - ascent);            g.setColor(Color.white);            g.clearRect(10, 0, titleWidth + 6, descent + ascent + leading + 1);            g.drawString(title, 12, ascent + 1);            g.setColor(Color.black);            g.drawString(title, 13, ascent + 2);            // Work around a bug of at least the awt implem I'm using.            // A few wild pixels appear on that line during drawstring.            g.clearRect(0, 0, d.width, 1);        }        private void paintBump(Graphics g) {            checkMetrics();            if (ascent == 0) {                return;            }            Dimension d = getSize();            g.setColor(Color.white);            g.drawRect(1, ascent - 2, d.width - 4, d.height - ascent);            g.setColor(Color.black);            g.drawRect(2, ascent - 1, d.width - 4, d.height - ascent);            g.setColor(Color.white);            g.clearRect(10, 0, titleWidth + 6, descent + ascent + leading + 1);            g.drawString(title, 12, ascent + 1);            g.setColor(Color.black);            g.drawString(title, 13, ascent + 2);            // Work around a bug of at least the awt implem I'm using.            // A few wild pixels appear on that line during drawstring.            g.clearRect(0, 0, d.width, 1);        }        /**         * {@inheritDoc}         */        @Override        public void paint(Graphics g) {            switch (style) {                case GROOVE:                    paintGroove(g);                    break;                case BUMP:                    paintBump(g);                    break;                case RAISED:                    paintRaised(g);                    break;                case LOWERED:                    paintLowered(g);                    break;                default:            }            super.paint(g);        }    }    /**     * Panel implementing paged tabs.     */    static class PagesPanel extends Panel implements ActionListener {        private final CardLayout layout;        private final Panel pages;        private final Panel buttons;        public PagesPanel() {            super(new BorderLayout());            layout = new CardLayout();            pages = new Panel(layout);            buttons = new Panel(new FlowLayout(FlowLayout.LEFT, 0, 0));            add(pages, BorderLayout.CENTER);            add(buttons, BorderLayout.NORTH);        }        /**         * {@inheritDoc}         */        public void actionPerformed(ActionEvent e) {

⌨️ 快捷键说明

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