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

📄 interactiveserver.java

📁 cqME :java framework for TCK test.
💻 JAVA
字号:
/*
 * $Id$
 *
 * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details (a copy is
 * included at /legal/license.txt).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 *
 */

package example.server;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import com.sun.javatest.Status;
import com.sun.tck.midp.lib.DistribInteractiveTest;

public class InteractiveServer extends DistribInteractiveTest {

    private volatile String clientName;
    private JPanel controlPanel;
    private JTextArea[] testInfo;
    private GridBagLayout gbl;
    private GridBagConstraints gbc;

    public InteractiveServer() {
        super("YesNo", true);
        setName("InteractiveServer");
    }

    public void handle_runTestCase(String from, String[] args) {
        clientName = from;
        runTestCase(from, args[1]);
    }

    public void handle_endRun(String from, String[] args) {
        endRun();
    }

    public void handle_test1(String from, String[] args) {
    }

    public Status test1() {
        String[] intro = {
                "Verify that the \"Hello test.\" alert created.",
                "Note: the sample images(180x210) taken from the reference ",
                "implementation can be used to validate appearance." };
        initialization(intro, "Simple Interactive Test", "", "test1", 1, false);
        testInfo[0].setText(
                "Parameters: Title = \"Hello test\", Text = \"Hello test.\"");

        return Status.passed(""); // will be ignored
    }

    private void initialization(String[] intro, String title,
            String qn, String name, int num, boolean doubleImage) {
        String passMsg = "OKAY";
        String failMsg = "Alert test DOES NOT work as expected.";

        // Add user information
        for (int i = 0; i < intro.length; i++) {
            addInfo(intro[i]);
        }

        controlPanel = new JPanel(new GridLayout(1, num, 10, 10));
        gbl = new GridBagLayout();
        gbc = new GridBagConstraints();
        testInfo = new JTextArea[num];
        JPanel mainPanel;
        ImagePanel ip;
        JButton button;
        ButtonListener listener;

        for (int i = 0; i < num; i++) {
            mainPanel = new JPanel(gbl);

            button = new JButton("Test " + (i + 1));

            gbc.gridy = 0;
            gbc.gridheight = 1;
            gbc.fill = GridBagConstraints.NONE;
            gbc.insets = new Insets(10, 10, 5, 5);
            gbc.anchor = GridBagConstraints.CENTER;
            gbc.weightx = 0.0;
            gbc.weighty = 0.0;
            gbl.setConstraints(button, gbc);
            listener = new ButtonListener(name, i + 1);
            button.addActionListener(listener);
            mainPanel.add(button);

            ip = new ImagePanel(testdirurl + "images/"
                    + name + "-" + (i + 1) + ".png");

            gbc.gridy = 1;
            gbc.gridheight = 4;
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.insets = new Insets(3, 3, 3, 3);
            gbl.setConstraints(ip, gbc);
            mainPanel.add(ip);

            testInfo[i] = new JTextArea("", 4, 20);
            testInfo[i].setEditable(false);
            testInfo[i].setFocusable(false);
            gbc.gridy = 5;
            gbc.gridheight = 1;
            gbc.insets = new Insets(5, 5, 5, 5);
            gbl.setConstraints(testInfo[i], gbc);
            mainPanel.add(testInfo[i]);

            controlPanel.add(mainPanel);
        }

        addTestPanel(controlPanel);

        // prepare the main test frame
        setQuestion(qn);
        setStatusMessages(passMsg, failMsg);
        setFrameTitle(title);
        setTimeout(180);
    }

    class ButtonListener implements ActionListener {
        private String test;
        private int index;

        ButtonListener(String test, int index) {
            this.test = test;
            this.index = index;
        }

        public void actionPerformed(ActionEvent e) {
            try {
                send(clientName, new String[] {test, String.valueOf(index)});
            } catch (IOException ioe) {
                ioe.printStackTrace(ref);
                ioe.printStackTrace();
            }
        }
    }

    class ImagePanel extends JPanel {
        private Image image1;
        private int x = 1;

        ImagePanel(String s) {
            try {
                image1 = Toolkit.getDefaultToolkit().getImage(
                        new java.net.URL(s));
            } catch (MalformedURLException e) {
                e.printStackTrace();
                throw new RuntimeException(e.getMessage());
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension(x * 190, 210);
        }

        public Dimension getMinimumSize() {
            return new Dimension(x * 190, 210);
        }

        public void paint(Graphics g) {
            Dimension d = getSize();
            g.drawImage(image1, d.width/2 - 90, 0, this);
        }
    }
}

⌨️ 快捷键说明

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