frmmain.java
来自「SRI international 发布的OAA框架软件」· Java 代码 · 共 822 行 · 第 1/2 页
JAVA
822 行
// Then, once the connection is established, performs handshaking with the facilitator
if (!myOaa.oaaRegister("parent", "oaa_debug_agent", IclTerm.fromString(true, "[inform_ui(debug, Message)]"), new IclList()))
{
lblStatus.setText("Could not register");
return false;
}
// Connection succeeded!
myOaa.oaaReady(true);
mnuConnect.setText("OAA Disconnect");
lblStatus.setText("Connected to Facilitator");
return true;
}
/********************************************************************************
* OAA Call Methods
*
* These methods call OAA API functions like oaaSolve(), oaaPostEvent(), etc.
* which are the methods of LibOaa
********************************************************************************/
public boolean callOaa(String sOaaCallString)
{
IclTerm toBeInterpreted = IclTerm.fromString(true, sOaaCallString);
if(toBeInterpreted==null)
{
lblStatus.setText("WARNING : Could not parse : " + sOaaCallString);
return false;
}
// Add a block(false) to the parameters, so
// the Debug agents always sends asynchronous requests
if ((toBeInterpreted.isStruct() && ((IclStruct)toBeInterpreted).getFunctor().toString().equals("oaa_Solve")))
toBeInterpreted.getTerm(1).add(IclTerm.fromString(true, "block(false)"));
IclList localSolutions = new IclList();
IclList localParams = new IclList();
myOaa.oaaInterpret(toBeInterpreted, localParams, localSolutions);
// DEBUG
//System.out.println("Solutions " + localSolutions);
txtAction.insertItemAt(sOaaCallString, 0);
txtAction.setSelectedItem("");
return true;
}
/*******************************************************************************
* UI Initialization Methods
********************************************************************************/
private void initMenus()
{
// File menu
menuFile.setText("File");
mnuConnect.setText("OAA Connect");
mnuConnect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
mnuOaaConnect_actionPerformed();
}
});
mnuExit.setText("Exit");
mnuExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
fileExit_actionPerformed(e);
}
});
// Options menu
String uiName = UIManager.getLookAndFeel().getName();
jPanel1.setLayout(null);
menuOptions.setText("Options");
//set the looks
mnuMotifLook.setText("Motif Look");
mnuMotifLook.setState(uiName.equals("Motif"));
mnuMotifLook.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (mnuMotifLook.getState())
{
setNewLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
mnuMetalLook.setState(false);
mnuWindowsLook.setState(false);
}
else
{
mnuMotifLook.setState(true);
}
}
});
mnuMetalLook.setText("Metal Look");
mnuMetalLook.setState(uiName.equals("Metal"));
mnuMetalLook.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (mnuMetalLook.getState())
{
setNewLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
mnuMotifLook.setState(false);
mnuWindowsLook.setState(false);
}
else
{
mnuMetalLook.setState(true);
}
}
});
mnuWindowsLook.setText("Windows Look");
mnuWindowsLook.setState(uiName.equals("Windows"));
mnuWindowsLook.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (mnuWindowsLook.getState())
{
setNewLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
mnuMotifLook.setState(false);
mnuMetalLook.setState(false);
}
else
{
mnuWindowsLook.setState(true);
}
}
});
// noDisplay button
mnuNoDisplay.setText("Display to Console");
mnuNoDisplay.setState(false);
mnuNoDisplay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (mnuNoDisplay.getState()) {
mnuNoDisplay.setState(false);
addLog("Sending display to Console.");
mnuNoDisplay.setState(true);
} else {
mnuNoDisplay.setState(true);
addLog("Displaying results in Debug Window.");
mnuNoDisplay.setState(false);
}
}
});
// help menu
menuHelp.setText("Help");
menuHelpAbout.setText("About");
menuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
helpAbout_actionPerformed(e);
}
});
mnuHelp.setText("Help on Debug");
mnuHelp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
help_actionPerformed(e);
}
});
// Create menu
menuFile.add(mnuConnect);
menuFile.add(mnuExit);
menuHelp.add(mnuHelp);
menuHelp.add(menuHelpAbout);
menuBar1.add(menuFile);
menuBar1.add(menuOptions);
menuOptions.add(mnuWindowsLook);
menuOptions.add(mnuMotifLook);
menuOptions.add(mnuMetalLook);
menuOptions.add(mnuNoDisplay);
menuBar1.add(menuHelp);
this.setJMenuBar(menuBar1);
}
private void initToolbars()
{
// ToolBar: button shortcuts
btnClearWindow.setText("Clear Window");
btnClearWindow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
evtLog.removeAllElements();
lstEvents.setListData(evtLog);
lstEvents.repaint();
}
});
btnSolve.setText("Solve");
btnSolve.setToolTipText(TIP_SOLVE_GOAL);
btnSolve.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnShortCut_actionPerformed(e);
}
});
btnTraceAll.setText("Trace All");
btnTraceAll.setToolTipText(TIP_TRACE_ALL);
btnTraceAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnShortCut_actionPerformed(e);
}
});
btnTraceFac.setText("TCP Trace Facilitator");
btnTraceFac.setToolTipText(TIP_TCP_TRACE_FACILITATOR);
btnTraceFac.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnShortCut_actionPerformed(e);
}
});
btnDebugOne.setText("Agent Hosts");
btnDebugOne.setToolTipText(TIP_AGENT_HOST);
btnDebugOne.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnShortCut_actionPerformed(e);
}
});
btnAgentInfo.setText("Agent Info");
btnAgentInfo.setToolTipText(TIP_AGENT_INFO);
btnAgentInfo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnShortCut_actionPerformed(e);
}
});
jtoolbar1.add(btnClearWindow, null);
jtoolbar1.add(btnSolve, null);
jtoolbar1.add(btnTraceAll, null);
jtoolbar1.add(btnTraceFac, null);
jtoolbar1.add(btnDebugOne, null);
jtoolbar1.add(btnAgentInfo, null);
jtoolbar1.setFloatable(false);
}
private void initCommandPanel()
{
jPanel1.setPreferredSize(new Dimension(655,110));
lblEnglish.setBounds(10,10,120,25);
lblEnglish.setText("English Request:");
lblAction.setBounds(10,50,120,25);
lblAction.setText("ICL Request:");
txtEnglish.setBounds(140,10,450,25);
txtEnglish.setEditable(true);
btnSendEng.setBounds(600, 10, 25, 25);
btnSendEng.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnSendEng_actionPerformed(e);
}
});
txtAction.setBounds(140,50,450,25);
txtAction.setEditable(true);
txtAction.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
txtAction_actionPerformed(e);
}
});
/* DEBUG
txtAction.addKeyListener(new java.awt.event.KeyListener() {
public void keyPressed(KeyEvent e)
{
System.out.println("Key pressed" + e);
}
public void keyReleased(KeyEvent e)
{
//System.out.println("Key typed" + e);
}
public void keyTyped(KeyEvent e)
{
System.out.println("Key typed" + e);
}
});
*/
btnSendAct.setBounds(600, 50, 25, 25);
btnSendAct.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnSendAct_actionPerformed(e);
}
});
lblStatus.setBorder(bevBorder);
lblStatus.setBounds(0, 90, 655, 20);
jPanel1.add(lblEnglish, null);
jPanel1.add(txtEnglish, null);
jPanel1.add(btnSendEng, null);
jPanel1.add(lblAction, null);
jPanel1.add(txtAction, null);
jPanel1.add(btnSendAct, null);
jPanel1.add(lblStatus, null);
this.getContentPane().add(jtoolbar1, BorderLayout.NORTH);
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
this.getContentPane().add(jPanel1, BorderLayout.SOUTH);
}
//File | Exit action performed
public void fileExit_actionPerformed(ActionEvent e)
{
System.exit(0);
}
/**
* Help | About action performed
*/
public void helpAbout_actionPerformed(ActionEvent e)
{
OaaAboutDialog dlg = new OaaAboutDialog("OAA Debug", "version 2.3.1");
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
lblStatus.setText(" ");
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setVisible(true);
}
/**
* Help | Debug action performed
*/
public void help_actionPerformed(ActionEvent e)
{
java.net.URL helpURL = getClass().getResource("debug_help.html");
OaaHelpDialog dlg = new OaaHelpDialog(helpURL);
/*
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
lblStatus.setText(" ");
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setVisible(true);
*/
}
public void txtAction_actionPerformed(ActionEvent e){
//System.out.println("Action");
//System.out.println(e.getActionCommand());
};
/**
* Overriden so we can exit on System Close
*/
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
fileExit_actionPerformed(null);
}
/**
* setNewLookAndFeel: Updates the application with the selected look and feel
*/
void setNewLookAndFeel(LookAndFeel lf)
{
try
{
UIManager.setLookAndFeel(lf);
SwingUtilities.updateComponentTreeUI(this.getRootPane());
this.validate();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
/**
* addLog: Adds msg to log window
*/
public void addLog(String msg)
{
if(mnuNoDisplay.getState()){
System.out.println(msg);
} else {
// A very strange bug happens with listboxes if msgline gets too long...
if (msg.length() > 4000) msg = msg.substring(0, 4000);
/* DEBUG
if (evtLog.size()>50) {
evtLog.removeAllElements();
lstEvents.setListData(evtLog);
}
*/
evtLog.addElement(msg);
lstEvents.setListData(evtLog);
lstEvents.repaint();
lstEvents.ensureIndexIsVisible(lstEvents.getModel().getSize()-1);
}
}
} // END OF FRMMAIN CLASS
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?