📄 frmevfilter.java
字号:
//Title: frmEvFilter.Java
//Version:
//Copyright:
//Author: Adam Cheyer
//Company: SRI International
//Description: Dialog box to let user filter on certain events
/**
* The contents of this file are subject to the OAA Community Research
* 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.ai.sri.com/~oaa/. Software distributed under the License
* is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific language governing
* rights and limitations under the License. Portions of the software are
* Copyright (c) SRI International, 1999. All rights reserved.
* "OAA" is a registered trademark, and "Open Agent Architecture" is a
* trademark, of SRI International, a California nonprofit public benefit
* corporation.
*/
package com.sri.oaa2.agt.monitor;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class frmEvFilter extends JFrame {
Vector vecFilter = new Vector(); // Contains log of all events
frmMonitor fMonitor = null; // Pointer back to parent
JButton btnDel = new JButton();
JButton btnAdd = new JButton();
JTextField txtFilter = new JTextField();
JRadioButton rbMatches = new JRadioButton();
JRadioButton rbTo = new JRadioButton();
JRadioButton rbFrom = new JRadioButton();
JButton btnCurrentAgent = new JButton();
JScrollPane scrollPane = null;
JList lstFilter = new JList();
JRadioButton rbToFrom = new JRadioButton();
public frmEvFilter(frmMonitor f) {
try {
fMonitor = f;
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
// Main window
this.setSize(475,190);
this.getContentPane().setLayout(null);
this.setResizable(false);
this.setTitle("Event Filters");
// listbox
scrollPane = new JScrollPane();
scrollPane.setBounds(new Rectangle(16, 16, 152, 132));
scrollPane.getViewport().add(lstFilter, null);
// Buttons
btnDel.setText("Delete");
btnDel.setBounds(new Rectangle(375, 106, 68, 38));
btnDel.setEnabled(false);
btnDel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnDel_actionPerformed(e);
}
});
btnAdd.setText("Add");
btnAdd.setBounds(new Rectangle(375, 48, 68, 48));
btnAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnAdd_actionPerformed(e);
}
});
txtFilter.setBounds(new Rectangle(251, 15, 193, 26));
rbMatches.setText("Matches");
rbMatches.setToolTipText("Capture events MATCHING a specific event pattern");
rbMatches.setBounds(new Rectangle(174, 22, 90, 15));
rbMatches.setSelected(true);
rbTo.setText("To:");
rbTo.setToolTipText("Capture events going TO a specific agent");
rbTo.setBounds(new Rectangle(174, 46, 48, 15));
rbFrom.setText("From:");
rbFrom.setToolTipText("Capture events coming FROM a specific agent");
rbFrom.setBounds(new Rectangle(174, 61, 51, 15));
rbToFrom.setText("To or From:");
rbToFrom.setToolTipText("Capture events going TO or FROM a specific agent");
rbToFrom.setBounds(new Rectangle(174, 76, 91, 15));
btnCurrentAgent.setText("Current Agent");
btnCurrentAgent.setBounds(new Rectangle(251, 49, 102, 43));
btnCurrentAgent.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCurrentAgent_actionPerformed(e);
}
});
// Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(rbFrom);
group.add(rbTo);
group.add(rbToFrom);
group.add(rbMatches);
this.getContentPane().add(scrollPane, null);
this.getContentPane().add(btnDel, null);
this.getContentPane().add(btnAdd, null);
this.getContentPane().add(txtFilter, null);
this.getContentPane().add(btnCurrentAgent, null);
this.getContentPane().add(rbToFrom, null);
this.getContentPane().add(rbMatches, null);
this.getContentPane().add(rbTo, null);
this.getContentPane().add(rbFrom, null);
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
void btnAdd_actionPerformed(ActionEvent e) {
if (!txtFilter.getText().equals("")) {
vecFilter.addElement(new String(txtFilter.getText()));
txtFilter.setText("");
lstFilter.setListData(vecFilter);
lstFilter.setSelectedIndex(vecFilter.size()-1);
btnDel.setEnabled(true);
}
}
void btnDel_actionPerformed(ActionEvent e) {
int p = lstFilter.getSelectedIndex();
if (p >= 0) {
vecFilter.removeElement(vecFilter.elementAt(p));
lstFilter.setListData(vecFilter);
lstFilter.setSelectedIndex(0);
if (vecFilter.size() == 0)
btnDel.setEnabled(false);
}
}
void btnCurrentAgent_actionPerformed(ActionEvent e) {
if (fMonitor.selectedAgent == null) {
JOptionPane.showMessageDialog(null, "First select an agent in the main window.",
"Select agent", JOptionPane.INFORMATION_MESSAGE);
}
else {
if (rbTo.isSelected())
txtFilter.setText("TO: " + fMonitor.selectedAgent.name + " (" + fMonitor.selectedAgent.id + ")");
else
if (rbFrom.isSelected())
txtFilter.setText("FROM: " + fMonitor.selectedAgent.name + " (" + fMonitor.selectedAgent.id + ")");
else
if (rbToFrom.isSelected())
txtFilter.setText("FROM/TO: " + fMonitor.selectedAgent.name + " (" + fMonitor.selectedAgent.id + ")");
else
if (rbMatches.isSelected())
JOptionPane.showMessageDialog(null, "First choose TO or FROM option.",
"Current agent", JOptionPane.INFORMATION_MESSAGE);
}
}
void btnOk_actionPerformed(ActionEvent e) {
dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -