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

📄 configdialog.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * Copyright (c) 2001 Sun Microsystems, Inc.  All rights
 * reserved.
 *
 * 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 the
 *       Sun Microsystems, Inc. for Project JXTA."
 *    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.
 * ====================================================================
 *
 * 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.
 *
 * $Id: ConfigDialog.java,v 1.2 2002/03/04 21:42:59 echtcherbina Exp $
 */

package net.jxta.impl.peergroup;

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import java.io.*;

import net.jxta.document.Advertisement;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.StructuredDocument;
import net.jxta.document.StructuredTextDocument;
import net.jxta.document.StructuredDocumentUtils;
import net.jxta.document.StructuredDocumentFactory;
import net.jxta.document.TextElement;
import net.jxta.document.MimeMediaType;
import net.jxta.document.Element;
import net.jxta.protocol.PeerAdvertisement;
import net.jxta.protocol.TransportAdvertisement;
import net.jxta.peergroup.PeerGroup;
import net.jxta.exception.JxtaError;

import net.jxta.impl.protocol.HTTPAdv;
import net.jxta.impl.protocol.TCPAdv;

import net.jxta.impl.endpoint.tls.TlsConfig;
import net.jxta.impl.endpoint.tls.JTlsDefs;

import org.apache.log4j.Category;
import org.apache.log4j.Priority;

// A few widgets.

class PanelGBL extends Panel {
    protected Insets insets = new Insets(0, 0, 0, 0);
    GridBagLayout lay = new GridBagLayout();

    private static GridBagConstraints constrLabel = new GridBagConstraints();
    static {
        constrLabel.gridwidth = GridBagConstraints.REMAINDER;
        constrLabel.gridheight = 1;
        constrLabel.gridx = 0;
        constrLabel.gridy = GridBagConstraints.RELATIVE;
        constrLabel.weightx = 2;
        constrLabel.weighty = 1;
        constrLabel.anchor = GridBagConstraints.NORTHWEST;
        constrLabel.fill = GridBagConstraints.HORIZONTAL;
    }

    public PanelGBL(String label) {
        super();
        setLayout(lay);
        add(new Label(label, Label.LEFT), constrLabel);
    }
    public PanelGBL() {
        super();
        setLayout(lay);
    }
    public Insets getInsets() {
        return insets;
    }
}


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;
    GridBagLayout lay = new GridBagLayout();

    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);
    }
    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.black);
        g.clearRect(10, 0, titleWidth+6, descent+ascent+leading + 1);
        g.drawString(title, 12, ascent + 1);
        g.setColor(Color.white);
        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);
    }

    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);
            default:
        }
        super.paint(g);
    }
}

class PagesPanel extends Panel implements ActionListener {
    Panel buttons;
    Panel pages;
    CardLayout l;

    public void actionPerformed(ActionEvent e) {
        l.show(pages, e.getActionCommand());
    }

    public PagesPanel() {
        super(new BorderLayout());
        l = new CardLayout();
        pages = new Panel(l);
        buttons = new Panel(new FlowLayout(FlowLayout.LEFT, 0, 0));
        add(pages, BorderLayout.CENTER);
        add(buttons, BorderLayout.NORTH);
    }
    public PanelGBL addPage(String buttonName, String comment) {
        BorderPanelGBL p = new BorderPanelGBL(buttonName, comment,
        BorderPanelGBL.RAISED);
        pages.add(p, buttonName);
        Button b = new Button(buttonName);
        buttons.add(b);
        b.addActionListener(this);
        return p;
    }
    public void showPage(String pageName) {
        l.show(pages, pageName);
    }
}


public class ConfigDialog
extends Frame
implements ItemListener, MouseListener {
    Frame mainFrame = this;

    PeerAdvertisement configAdv;
    HTTPAdv httpAdv;
    TCPAdv tcpAdv;

    GridBagConstraints stdConstr;
    GridBagConstraints centerConstr;
    GridBagConstraints centerLastConstr;
    GridBagConstraints fillConstr;
    GridBagConstraints leftLineConstr;
    GridBagConstraints midLineConstr;
    GridBagConstraints midLineEastConstr;
    GridBagConstraints rightLineConstr;
    GridBagConstraints leftPanelConstr;
    GridBagConstraints rightPanelConstr;


    Label   helpLabel;
    IdPanel idPanel;
    HttpPanel httpPanel;
    TcpPanel tcpPanel;
    RdvPanel rdvPanel;
    RouterPanel routerPanel;
    DebugPanel  debugPanel;
    SecPanel secPanel;

    Button ok;
    Button cancel;
    PagesPanel pages = new PagesPanel();


    class HostPortPanel extends PanelGBL implements ItemListener {


        public Checkbox  useMe;

        private TextField host;
        private TextField port;

        Label addressLabel;
        ItemListener listener;

        public String getHost() {
            return host.getText();
        }

        public String getPort() {
            return port.getText();
        }

        public void setState(boolean state) {
            useMe.setState(state); // sometimes redundant but not always.
            host.setEnabled(state);
            port.setEnabled(state);
            addressLabel.setEnabled(state);
        }

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

        public void itemStateChanged(ItemEvent e) {
            setState(useMe.getState());
            listener.itemStateChanged(e);
        }

        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
        }

        HostPortPanel(ItemListener l,
        String checkLabel,
        String addrLabel,
        String defaultHost, String defaultPort,
        boolean defaultState) {

            super();

            if (checkLabel == null) checkLabel = "";

            listener = l;
            useMe = new Checkbox(checkLabel, null, defaultState);
            host = new TextField(defaultHost, 20);
            port = new TextField(defaultPort, 8);
            addressLabel = new Label(addrLabel);

            if (! checkLabel.equals("")) {
                add(useMe, stdConstr);
            }
            add(addressLabel, leftLineConstr);
            add(host, midLineConstr);
            add(port, rightLineConstr);

⌨️ 快捷键说明

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