testclient.java
来自「关于 RFID 读写器的相关内容」· Java 代码 · 共 456 行 · 第 1/2 页
JAVA
456 行
/*
* Copyright (C) 2007 ETH Zurich
*
* This file is part of Fosstrak (www.fosstrak.org).
*
* Fosstrak is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* Fosstrak 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Fosstrak; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package org.fosstrak.reader.rp.client;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.fosstrak.reader.rp.client.actions.ConnectAction;
import org.fosstrak.reader.rp.client.actions.CreateCommandAction;
import org.fosstrak.reader.rp.client.actions.DisconnectAction;
import org.fosstrak.reader.rp.client.actions.ObjectChangeAction;
import org.fosstrak.reader.rp.client.actions.SendAction;
import org.fosstrak.reader.rp.client.actions.SetMessageFormatText;
import org.fosstrak.reader.rp.client.actions.SetMessageFormatXML;
import org.fosstrak.reader.rp.client.actions.SetTransportProtocolHttp;
import org.fosstrak.reader.rp.client.actions.SetTransportProtocolTcp;
import org.fosstrak.reader.rp.client.model.MethodComboBoxModel;
import org.fosstrak.reader.rp.client.model.ObjectComboBoxModel;
import org.fosstrak.reader.rp.proxy.msg.Client;
import org.fosstrak.reader.rp.proxy.msg.ClientConnection;
import org.fosstrak.reader.rp.proxy.msg.Handshake;
import org.fosstrak.reader.rp.proxy.msg.Parameter;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
/**
* This is a test client which can be used to test an implementation
* of the reader protocol. Command can be created by using an
* interactive user interface, the command is generated into the appropriate
* message format. In this version only the XML format is supported.
*
* Because I didn't focus on this client in my semester thesis the code
* quality of this client might be not optimal :-)
*
*
* @author Andreas F黵er, ETH Zurich Switzerland, Winter 2005/06
*
*/
public class TestClient extends JFrame implements Client {
private JTextArea outText;
private JTextArea inText;
private JTextField hostField;
private JTextField portField;
private JButton sendButton;
private JButton closeButton;
private JButton connectButton;
private JLabel transportLabel;
private JRadioButton tcpConnectionButton;
private JRadioButton httpConnectionButton;
private JLabel formatLabel;
private JRadioButton xmlFormatButton;
private JRadioButton textFormatButton;
private JLabel hostLabel;
private JLabel portLabel;
private Font monospaceFont;
private JComboBox objComboBox;
private JComboBox cmdComboBox;
private JLabel targetLabel;
private JLabel objLabel;
private JLabel cmdLabel;
private JTextField targetField;
private JButton createCmdButton;
private ParameterPanel parameterPanel;
/* the model */
private Handshake handshake;
private ClientConnection conn;
public void initialize() {
handshake = new Handshake();
this.setTitle("Reader Protocol Test Client");
monospaceFont = new Font( "Monospaced", Font.PLAIN, 12 );
Container content = this.getContentPane();
content.setLayout(new BorderLayout());
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
getOutputPanel(),
getInputPanel());
splitPane.setOneTouchExpandable(true);
splitPane.setResizeWeight(0.5);
JPanel northPane = new JPanel();
northPane.setLayout(new BoxLayout(northPane, BoxLayout.PAGE_AXIS));
northPane.add(getConnectPanel());
northPane.add(getCommandCreatorPanel());
content.add(northPane, BorderLayout.NORTH);
content.add(splitPane, BorderLayout.CENTER);
content.add(getCommandPanel(), BorderLayout.SOUTH);
setMainPanelEnabled(false);
}
private JPanel getOutputPanel() {
JPanel outPane = new JPanel();
outPane.setLayout(new GridBagLayout());
outText = new JTextArea(5, 20);
outText.setLineWrap(true);
outText.setFont(monospaceFont);
JScrollPane scrollPane = new JScrollPane(outText,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//Add Components to this panel.
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
outPane.add(scrollPane, c);
outPane.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Request"),
BorderFactory.createEmptyBorder(5,5,5,5)),
outPane.getBorder()));
return outPane;
}
private JPanel getInputPanel() {
JPanel inPane = new JPanel();
inPane.setLayout(new GridBagLayout());
inText = new JTextArea(5, 20);
inText.setLineWrap(true);
inText.setFont(monospaceFont);
JScrollPane scrollPane = new JScrollPane(inText,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//Add Components to this panel.
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
inPane.add(scrollPane, c);
inPane.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Response"),
BorderFactory.createEmptyBorder(5,5,5,5)),
inPane.getBorder()));
return inPane;
}
/**
* Creates the panel with the UI to create a command.
* @return Panel with the command UI.
*/
private JPanel getCommandCreatorPanel() {
JPanel cmdCreatorPanel = new JPanel();
cmdCreatorPanel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Command"),
BorderFactory.createEmptyBorder(5,5,5,5)),
cmdCreatorPanel.getBorder()));
FormLayout layout = new FormLayout(
"65dlu, 4dlu, left:pref:grow , 4dlu ,4dlu,pref", // columns
"pref, 2dlu, pref, 2dlu, pref, 8dlu, pref"); // rows
cmdCreatorPanel.setLayout(layout);
objLabel = new JLabel("Object");
cmdLabel = new JLabel("Command");
objComboBox = new JComboBox();
objComboBox.setModel(new ObjectComboBoxModel());
objComboBox.addActionListener(new ObjectChangeAction(this));
targetLabel = new JLabel("Target:");
targetField = new JTextField();
createCmdButton = new JButton();
createCmdButton.setAction(new CreateCommandAction(this));
cmdComboBox = new JComboBox();
cmdComboBox.setModel(MethodComboBoxModel.getInstance().rdModel);
parameterPanel = new ParameterPanel(this);
CellConstraints cc = new CellConstraints();
cmdCreatorPanel.add(objLabel, cc.xy(1,1));
cmdCreatorPanel.add(cmdLabel, cc.xy(3,1));
cmdCreatorPanel.add(objComboBox, cc.xy(1,3));
cmdCreatorPanel.add(cmdComboBox, cc.xywh(3,3,2,1));
cmdCreatorPanel.add(createCmdButton, cc.xy(6,3));
cmdCreatorPanel.add(targetLabel, cc.xy(1,5));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?