📄 soapmonitorapplet.java
字号:
} /** * Get row count (part of table model interface) */ public int getRowCount() { int count = data.size(); if (filter_data != null) { count = filter_data.size(); } return count; } /** * Get column name (part of table model interface) */ public String getColumnName(int col) { return column_names[col]; } /** * Get value at (part of table model interface) */ public Object getValueAt(int row, int col) { SOAPMonitorData soap; String value = null; soap = (SOAPMonitorData) data.elementAt(row); if (filter_data != null) { soap = (SOAPMonitorData) filter_data.elementAt(row); } switch (col) { case 0: value = soap.getTime(); break; case 1: value = soap.getTargetService(); break; case 2: value = soap.getStatus(); break; } return value; } /** * Check if soap data matches filter */ public boolean filterMatch(SOAPMonitorData soap) { boolean match = true; if (filter_include != null) { // Check for service match Enumeration e = filter_include.elements(); match = false; while (e.hasMoreElements() && !match) { String service = (String) e.nextElement(); if (service.equals(soap.getTargetService())) { match = true; } } } if (filter_exclude != null) { // Check for service match Enumeration e = filter_exclude.elements(); while (e.hasMoreElements() && match) { String service = (String) e.nextElement(); if (service.equals(soap.getTargetService())) { match = false; } } } if (filter_active) { // Check for active status match if (soap.getSOAPResponse() != null) { match = false; } } if (filter_complete) { // Check for complete status match if (soap.getSOAPResponse() == null) { match = false; } } // The "most recent" is always a match if (soap.getId() == null) { match = true; } return match; } /** * Add data to the table as a new row */ public void addData(SOAPMonitorData soap) { int row = data.size(); data.addElement(soap); if (filter_data != null) { if (filterMatch(soap)) { row = filter_data.size(); filter_data.addElement(soap); fireTableRowsInserted(row,row); } } else { fireTableRowsInserted(row,row); } } /** * Find the data for a given id */ public SOAPMonitorData findData(Long id) { SOAPMonitorData soap = null; for (int row=data.size(); (row > 0) && (soap == null); row--) { soap = (SOAPMonitorData) data.elementAt(row-1); if (soap.getId().longValue() != id.longValue()) { soap = null; } } return soap; } /** * Find the row in the table for a given message id */ public int findRow(SOAPMonitorData soap) { int row = -1; if (filter_data != null) { row = filter_data.indexOf(soap); } else { row = data.indexOf(soap); } return row; } /** * Remove all messages from the table (but leave "most recent") */ public void clearAll() { int last_row = data.size() - 1; if (last_row > 0) { data.removeAllElements(); SOAPMonitorData soap = new SOAPMonitorData(null,null,null); data.addElement(soap); if (filter_data != null) { filter_data.removeAllElements(); filter_data.addElement(soap); } fireTableDataChanged(); } } /** * Remove a message from the table */ public void removeRow(int row) { SOAPMonitorData soap = null; if (filter_data == null) { soap = (SOAPMonitorData) data.elementAt(row); data.remove(soap); } else { soap = (SOAPMonitorData) filter_data.elementAt(row); filter_data.remove(soap); data.remove(soap); } fireTableRowsDeleted(row,row); } /** * Set a new filter */ public void setFilter(SOAPMonitorFilter filter) { // Save new filter criteria filter_include = filter.getFilterIncludeList(); filter_exclude = filter.getFilterExcludeList(); filter_active = filter.getFilterActive(); filter_complete = filter.getFilterComplete(); applyFilter(); } /** * Refilter the list of messages */ public void applyFilter() { // Re-filter using new criteria filter_data = null; if ((filter_include != null) || (filter_exclude != null) || filter_active || filter_complete ) { filter_data = new Vector(); Enumeration e = data.elements(); SOAPMonitorData soap; while (e.hasMoreElements()) { soap = (SOAPMonitorData) e.nextElement(); if (filterMatch(soap)) { filter_data.addElement(soap); } } } fireTableDataChanged(); } /** * Get the data for a row */ public SOAPMonitorData getData(int row) { SOAPMonitorData soap = null; if (filter_data == null) { soap = (SOAPMonitorData) data.elementAt(row); } else { soap = (SOAPMonitorData) filter_data.elementAt(row); } return soap; } /** * Update a message */ public void updateData (SOAPMonitorData soap) { int row; if (filter_data == null) { // No filter, so just fire table updated row = data.indexOf(soap); if (row != -1) { fireTableRowsUpdated(row,row); } } else { // Check if the row was being displayed row = filter_data.indexOf(soap); if (row == -1) { // Row was not displayed, so check for if it // now needs to be displayed if (filterMatch(soap)) { int index = -1; row = data.indexOf(soap) + 1; while ((row < data.size()) && (index == -1)) { index = filter_data.indexOf(data.elementAt(row)); if (index != -1) { // Insert at this location filter_data.add(index,soap); } row++; } if (index == -1) { // Insert at end index = filter_data.size(); filter_data.addElement(soap); } fireTableRowsInserted(index,index); } } else { // Row was displayed, so check if it needs to // be updated or removed if (filterMatch(soap)) { fireTableRowsUpdated(row,row); } else { filter_data.remove(soap); fireTableRowsDeleted(row,row); } } } } } /** * Panel with checkbox and list */ class ServiceFilterPanel extends JPanel implements ActionListener, ListSelectionListener, DocumentListener { private JCheckBox service_box = null; private Vector filter_list = null; private Vector service_data = null; private JList service_list = null; private JScrollPane service_scroll = null; private JButton remove_service_button = null; private JPanel remove_service_panel = null; private EmptyBorder indent_border = null; private EmptyBorder empty_border = null; private JPanel service_area = null; private JPanel add_service_area = null; private JTextField add_service_field = null; private JButton add_service_button = null; private JPanel add_service_panel = null; /** * Constructor */ public ServiceFilterPanel(String text, Vector list) { empty_border = new EmptyBorder(5,5,0,5); indent_border = new EmptyBorder(5,25,5,5); service_box = new JCheckBox(text); service_box.addActionListener(this); service_data = new Vector(); if (list != null) { service_box.setSelected(true); service_data = (Vector) list.clone(); } service_list = new JList(service_data); service_list.setBorder(new EtchedBorder()); service_list.setVisibleRowCount(5); service_list.addListSelectionListener(this); service_list.setEnabled(service_box.isSelected()); service_scroll = new JScrollPane(service_list); service_scroll.setBorder(new EtchedBorder()); remove_service_button = new JButton("Remove"); remove_service_button.addActionListener(this); remove_service_button.setEnabled(false); remove_service_panel = new JPanel(); remove_service_panel.setLayout(new FlowLayout()); remove_service_panel.add(remove_service_button); service_area = new JPanel(); service_area.setLayout(new BorderLayout()); service_area.add(service_scroll, BorderLayout.CENTER); service_area.add(remove_service_panel, BorderLayout.EAST); service_area.setBorder(indent_border); add_service_field = new JTextField(); add_service_field.addActionListener(this); add_service_field.getDocument().addDocumentListener(this); add_service_field.setEnabled(service_box.isSelected()); add_service_button = new JButton("Add"); add_service_button.addActionListener(this); add_service_button.setEnabled(false); add_service_panel = new JPanel(); add_service_panel.setLayout(new BorderLayout()); JPanel dummy = new JPanel(); dummy.setBorder(empty_border); add_service_panel.add(dummy, BorderLayout.WEST); add_service_panel.add(add_service_button, BorderLayout.EAST); add_service_area = new JPanel(); add_service_area.setLayout(new BorderLayout()); add_service_area.add(add_service_field, BorderLayout.CENTER); add_service_area.add(add_service_panel, BorderLayout.EAST); add_service_area.setBorder(indent_border); setLayout(new BorderLayout()); add(service_box, BorderLayout.NORTH); add(service_area, BorderLayout.CENTER); add(add_service_area, BorderLayout.SOUTH); setBorder(empty_border); } /** * Get the current list of services */ public Vector getServiceList() { Vector list = null; if (service_box.isSelected()) { list = service_data; } return list; } /** * Listener to handle button actions */ public void actionPerformed(ActionEvent e) { // Check if the user changed the service filter option if (e.getSource() == service_box) { service_list.setEnabled(service_box.isSelected()); service_list.clearSelection(); remove_service_button.setEnabled(false); add_service_field.setEnabled(service_box.isSelected()); add_service_field.setText(""); add_service_button.setEnabled(false); } // Check if the user pressed the add service button if ((e.getSource() == add_service_button) || (e.getSource() == add_service_field)) { String text = add_service_field.getText(); if ((text != null) && (text.length() > 0)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -