📄 soapmonitorapplet.java
字号:
/* * Copyright 2001,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.text.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.table.*;import org.apache.axis.monitor.SOAPMonitorConstants;/** * This is a SOAP Mointor Applet class. This class provides * the user interface for displaying data from the SOAP * monitor service. * * @author Brian Price (pricebe@us.ibm.com) * */public class SOAPMonitorApplet extends JApplet { /** * Private data */ private JPanel main_panel = null; private JTabbedPane tabbed_pane = null; private int port = 0; private Vector pages = null; /** * Constructor */ public SOAPMonitorApplet() { } /** * Applet initialization */ public void init() { // Get the port to be used String port_str = getParameter("port"); if (port_str != null) { port = Integer.parseInt(port_str); } // Try to use the system look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e){ } // Create main panel to hold notebook main_panel = new JPanel(); main_panel.setBackground(Color.white); main_panel.setLayout(new BorderLayout()); setContentPane(main_panel); // Create the notebook tabbed_pane = new JTabbedPane(JTabbedPane.TOP); main_panel.add(tabbed_pane,BorderLayout.CENTER); // Add notebook page for default host connection pages = new Vector(); addPage(new SOAPMonitorPage(getCodeBase().getHost())); } /** * Add a page to the notebook */ private void addPage(SOAPMonitorPage pg) { tabbed_pane.addTab(" "+pg.getHost()+" ", pg); pages.addElement(pg); } /** * Applet is being displayed */ public void start() { // Tell all pages to start talking to the server Enumeration e = pages.elements(); while (e.hasMoreElements()) { SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); if (pg != null) { pg.start(); } } } /* * Applet is no longer displayed */ public void stop() { // Tell all pages to stop talking to the server Enumeration e = pages.elements(); while (e.hasMoreElements()) { SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); if (pg != null) { pg.stop(); } } } /** * Applet cleanup */ public void destroy() { tabbed_pane = null; main_panel = null; } /** * This class provides the contents of a notebook page * representing a server connection. */ class SOAPMonitorPage extends JPanel implements Runnable, ListSelectionListener, ActionListener { /** * Status Strings */ private final String STATUS_ACTIVE = "The SOAP Monitor is started."; private final String STATUS_STOPPED = "The SOAP Monitor is stopped."; private final String STATUS_CLOSED = "The server communication has been terminated."; private final String STATUS_NOCONNECT = "The SOAP Monitor is unable to communcate with the server."; /** * Private data */ private String host = null; private Socket socket = null; private ObjectInputStream in = null; private ObjectOutputStream out = null; private SOAPMonitorTableModel model = null; private JTable table = null; private JScrollPane scroll = null; private JPanel list_panel = null; private JPanel list_buttons = null; private JButton remove_button = null; private JButton remove_all_button = null; private JButton filter_button = null; private JPanel details_panel = null; private JPanel details_header = null; private JSplitPane details_soap = null; private JPanel details_buttons = null; private JLabel details_time = null; private JLabel details_target = null; private JLabel details_status = null; private JLabel details_time_value = null; private JLabel details_target_value = null; private JLabel details_status_value = null; private EmptyBorder empty_border = null; private EtchedBorder etched_border = null; private JPanel request_panel = null; private JPanel response_panel = null; private JLabel request_label = null; private JLabel response_label = null; private SOAPMonitorTextArea request_text = null; private SOAPMonitorTextArea response_text = null; private JScrollPane request_scroll = null; private JScrollPane response_scroll = null; private JButton layout_button = null; private JSplitPane split = null; private JPanel status_area = null; private JPanel status_buttons = null; private JButton start_button = null; private JButton stop_button = null; private JLabel status_text = null; private JPanel status_text_panel = null; private SOAPMonitorFilter filter = null; private GridBagLayout details_header_layout = null; private GridBagConstraints details_header_constraints = null; private JCheckBox reflow_xml = null; /** * Constructor (create and layout page) */ public SOAPMonitorPage(String host_name) { host = host_name; // Set up default filter (show all messages) filter = new SOAPMonitorFilter(); // Use borders to help improve appearance etched_border = new EtchedBorder(); // Build top portion of split (list panel) model = new SOAPMonitorTableModel(); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionInterval(0,0); table.setPreferredScrollableViewportSize(new Dimension(600, 96)); table.getSelectionModel().addListSelectionListener(this); scroll = new JScrollPane(table); remove_button = new JButton("Remove"); remove_button.addActionListener(this); remove_button.setEnabled(false); remove_all_button = new JButton("Remove All"); remove_all_button.addActionListener(this); filter_button = new JButton("Filter ..."); filter_button.addActionListener(this); list_buttons = new JPanel(); list_buttons.setLayout(new FlowLayout()); list_buttons.add(remove_button); list_buttons.add(remove_all_button); list_buttons.add(filter_button); list_panel = new JPanel(); list_panel.setLayout(new BorderLayout()); list_panel.add(scroll,BorderLayout.CENTER); list_panel.add(list_buttons, BorderLayout.SOUTH); list_panel.setBorder(empty_border); // Build bottom portion of split (message details) details_time = new JLabel("Time: ", SwingConstants.RIGHT); details_target = new JLabel("Target Service: ", SwingConstants.RIGHT); details_status = new JLabel("Status: ", SwingConstants.RIGHT); details_time_value = new JLabel(); details_target_value = new JLabel(); details_status_value = new JLabel(); Dimension preferred_size = details_time.getPreferredSize(); preferred_size.width = 1; details_time.setPreferredSize(preferred_size); details_target.setPreferredSize(preferred_size); details_status.setPreferredSize(preferred_size); details_time_value.setPreferredSize(preferred_size); details_target_value.setPreferredSize(preferred_size); details_status_value.setPreferredSize(preferred_size); details_header = new JPanel(); details_header_layout = new GridBagLayout(); details_header.setLayout(details_header_layout); details_header_constraints = new GridBagConstraints(); details_header_constraints.fill=GridBagConstraints.BOTH; details_header_constraints.weightx=0.5; details_header_layout.setConstraints(details_time,details_header_constraints); details_header.add(details_time); details_header_layout.setConstraints(details_time_value,details_header_constraints); details_header.add(details_time_value); details_header_layout.setConstraints(details_target,details_header_constraints); details_header.add(details_target); details_header_constraints.weightx=1.0; details_header_layout.setConstraints(details_target_value,details_header_constraints); details_header.add(details_target_value); details_header_constraints.weightx=.5; details_header_layout.setConstraints(details_status,details_header_constraints); details_header.add(details_status); details_header_layout.setConstraints(details_status_value,details_header_constraints); details_header.add(details_status_value); details_header.setBorder(etched_border); request_label = new JLabel("SOAP Request", SwingConstants.CENTER); request_text = new SOAPMonitorTextArea(); request_text.setEditable(false); request_scroll = new JScrollPane(request_text); request_panel = new JPanel(); request_panel.setLayout(new BorderLayout()); request_panel.add(request_label, BorderLayout.NORTH); request_panel.add(request_scroll, BorderLayout.CENTER); response_label = new JLabel("SOAP Response", SwingConstants.CENTER); response_text = new SOAPMonitorTextArea(); response_text.setEditable(false); response_scroll = new JScrollPane(response_text); response_panel = new JPanel(); response_panel.setLayout(new BorderLayout()); response_panel.add(response_label, BorderLayout.NORTH); response_panel.add(response_scroll, BorderLayout.CENTER); details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); details_soap.setTopComponent(request_panel); details_soap.setRightComponent(response_panel); details_soap.setResizeWeight(.5); details_panel = new JPanel(); layout_button = new JButton("Switch Layout"); layout_button.addActionListener(this); reflow_xml = new JCheckBox("Reflow XML text"); reflow_xml.addActionListener(this); details_buttons = new JPanel(); details_buttons.setLayout(new FlowLayout()); details_buttons.add(reflow_xml); details_buttons.add(layout_button); details_panel.setLayout(new BorderLayout()); details_panel.add(details_header,BorderLayout.NORTH); details_panel.add(details_soap,BorderLayout.CENTER); details_panel.add(details_buttons,BorderLayout.SOUTH); details_panel.setBorder(empty_border); // Add the two parts to the age split pane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setTopComponent(list_panel); split.setRightComponent(details_panel); // Build status area start_button = new JButton("Start"); start_button.addActionListener(this); stop_button = new JButton("Stop"); stop_button.addActionListener(this); status_buttons = new JPanel(); status_buttons.setLayout(new FlowLayout()); status_buttons.add(start_button); status_buttons.add(stop_button); status_text = new JLabel(); status_text.setBorder(new BevelBorder(BevelBorder.LOWERED)); status_text_panel = new JPanel(); status_text_panel.setLayout(new BorderLayout()); status_text_panel.add(status_text, BorderLayout.CENTER); status_text_panel.setBorder(empty_border); status_area = new JPanel(); status_area.setLayout(new BorderLayout()); status_area.add(status_buttons, BorderLayout.WEST); status_area.add(status_text_panel, BorderLayout.CENTER); status_area.setBorder(etched_border); // Add the split and status area to page setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); add(status_area, BorderLayout.SOUTH); } /** * Get the name of the host we are displaying */ public String getHost() { return host; } /** * Set the status text */ public void setStatus(String txt) { status_text.setForeground(Color.black); status_text.setText(" "+txt); } /** * Set the status text to an error */ public void setErrorStatus(String txt) { status_text.setForeground(Color.red); status_text.setText(" "+txt); } /** * Start talking to the server */ public void start() { String codehost = getCodeBase().getHost(); if (socket == null) { try { // Open the socket to the server socket = new Socket(codehost, port); // Create output stream out = new ObjectOutputStream(socket.getOutputStream()); out.flush(); // Create input stream and start background // thread to read data from the server in = new ObjectInputStream(socket.getInputStream()); new Thread(this).start(); } catch (Exception e) { // Exceptions here are unexpected, but we can't // really do anything (so just write it to stdout // in case someone cares and then ignore it) System.out.println("Exception! "+e.toString()); e.printStackTrace(); setErrorStatus(STATUS_NOCONNECT); socket = null; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -