package infosapient.ui;
/*
* Copyright (c) 2001, Workplace Performance Tools, All Rights Reserved.
*
* LICENSE TO USE THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE 0.5
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
* The license may be viewed at:
* http://www.opensource.org/licenses/cpl.html
*/
import infosapient.resolution.FzyCorrelation;
import infosapient.resolution.FzyCorrelationMinimum;
import infosapient.resolution.FzyCorrelationAverage;
import infosapient.resolution.FzyCorrelationProduct;
import infosapient.resolution.FzyImplicationMethod;
import infosapient.resolution.FzyImplicationADDAGGREGATION;
import infosapient.resolution.FzyImplicationMINMAX;
import infosapient.resolution.FzyResolutionMethod;
import infosapient.resolution.FzyResCENTROID;
import infosapient.resolution.FzyResMAXPLATEAU;
import infosapient.resolution.FzyResMAXIMUM;
import infosapient.control.InfoSapientController;
import infosapient.system.FzyKnowledgebase;
import infosapient.system.FSEvent;
import infosapient.system.Observer;
import infosapient.system.ObservableImpl;
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
/**
* InfoSapientInferenceEditor permits the knowledge engineer to modify the kb
* correlation, implication and resolution properties.
* @author Michael McConnell
* @version $Revision: 1.1.1.1 $
* @package infosapient.ui
*/
public class InfoSapientInferenceEditor extends JPanel implements Observer{
transient GridBagConstraints gbC;
transient GridBagLayout gbL;
transient javax.swing.JRadioButton afterRB;
transient javax.swing.JRadioButton beforeRB;
transient ButtonGroup rbGroup;
transient javax.swing.JFrame frame;
transient javax.swing.JList inferMethodsLst;
transient javax.swing.JList corrMethodsLst;
transient javax.swing.JList reslvMethodsLst;
transient boolean runBefore = true;
transient InfoSapientController controller;
class RBActionListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("before")) runBefore = true;
else
if (ae.getActionCommand().equals("after")) runBefore = false;
}
}
class aLIEWinListener extends WindowAdapter {
public void windowClosing(WindowEvent wevnt) {
closeSelected();
}
}
class FileMenuListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("ie-apply")) updateKBReasoningMethods();
else
if (ae.getActionCommand().equals("ie-close")) closeSelected();
}
}
public InfoSapientInferenceEditor(InfoSapientController theC) {
controller = theC;
controller.addObserver(this);
initialize();
}
public void applySelected() {
updateKBReasoningMethods();
}
public void cancelBtn_Clicked(){}
public void cancelSelected() {}
public void closeSelected() {
this.setVisible(false);
}
protected InfoSapientController getController() {
return controller;
}
protected FzyKnowledgebase getKB() {
return (FzyKnowledgebase) getController().getKB();
}
public void handleFSEvent(FSEvent anEvent){}
public void initialize() {
/**
* setup window
*/
frame = new javax.swing.JFrame();
frame.setSize( getInsets().left + 620,
getInsets().top + 420);
frame.getContentPane().setFont(new Font("Helvetica",Font.PLAIN,12));
frame.getContentPane().setLayout(new BorderLayout());
frame.addWindowListener(this.new aLIEWinListener());
gbL = new GridBagLayout();
gbC = new GridBagConstraints();
gbC.insets = new Insets(10,10,10,10);
javax.swing.JPanel displayPanel = new javax.swing.JPanel(new BorderLayout());
javax.swing.JPanel panel1 = new javax.swing.JPanel(gbL);
panel1.setBorder(BorderFactory.createTitledBorder(((javax.swing.border.Border)BorderFactory.createEtchedBorder()),
("Knowledgebase "
+ getController().getKB().getName())));
//gbC.anchor = GridBagConstraints.WEST;
gbC.gridwidth = GridBagConstraints.RELATIVE;
gbC.fill = GridBagConstraints.HORIZONTAL;
gbC.weightx = 0.5;
gbC.weighty = 0.0;
panel1.add(new javax.swing.JPanel(), gbC);
/**
* set up rbBtnPanel;
*/
RBActionListener rbAction = new RBActionListener();
javax.swing.JPanel rbBtnPanel = new javax.swing.JPanel(new GridLayout(2,1,3,3));
rbBtnPanel.setBorder(BorderFactory.createTitledBorder(((javax.swing.border.Border)BorderFactory.createEtchedBorder()),
("When to apply unconditional rules")));
rbGroup = new ButtonGroup();
beforeRB = new javax.swing.JRadioButton("BEFORE executing conditional rules");
beforeRB.setSelected(controller.getKB().isRunBefore());
beforeRB.addActionListener(rbAction);
beforeRB.setActionCommand("before");
rbBtnPanel.add(beforeRB);
rbGroup.add(beforeRB);
afterRB = new javax.swing.JRadioButton("AFTER executing conditional rules");
afterRB.setSelected(!controller.getKB().isRunBefore());
afterRB.addActionListener(rbAction);
afterRB.setActionCommand("after");
rbGroup.add(afterRB);
rbBtnPanel.add(afterRB);
gbC.gridwidth = GridBagConstraints.REMAINDER;
panel1.add(rbBtnPanel, gbC);
/**
* Setup list javax.swing.JPanel
*/
javax.swing.JPanel listPanel = new javax.swing.JPanel();
listPanel.setLayout(new GridLayout(1,3,3,3));
/**
* setup Correlation list
*/
corrMethodsLst = new javax.swing.JList();
corrMethodsLst.setVisibleRowCount(10);
Vector tList = new Vector();
tList.addElement(new FzyCorrelationAverage());
tList.addElement(new FzyCorrelationMinimum());
tList.addElement(new FzyCorrelationProduct());
javax.swing.JScrollPane sPane1 = new javax.swing.JScrollPane();
sPane1.setBorder(
BorderFactory.createTitledBorder(
((javax.swing.border.Border)BorderFactory.createEtchedBorder()),
("Rule Correlation Methods")
)
);
corrMethodsLst.setListData(tList);
sPane1.getViewport().add (corrMethodsLst);
Class className = controller.getKB().getCorrelationMethod().getClass();
for (int i = 0;i < tList.size();i++){
if (tList.elementAt(i).getClass() == className){
corrMethodsLst.setSelectedIndex(i);
break;
}
}
listPanel.add(sPane1);
/**
* setup Rule Implication Methods
*/
inferMethodsLst = new javax.swing.JList();
inferMethodsLst.setVisibleRowCount(10);
tList = new Vector();
tList.addElement(new FzyImplicationMINMAX());
tList.addElement(new FzyImplicationADDAGGREGATION());
inferMethodsLst.setListData(tList);
javax.swing.JScrollPane sPane2 = new javax.swing.JScrollPane();
sPane2.setBorder(
BorderFactory.createTitledBorder(
((javax.swing.border.Border)BorderFactory.createEtchedBorder()),
("Rule Implication Methods")
)
);
inferMethodsLst.setListData(tList);
sPane2.getViewport().add (inferMethodsLst);
className = controller.getKB().getImplicationMethod().getClass();
for (int i = 0;i < tList.size();i++){
if (tList.elementAt(i).getClass() == className){
inferMethodsLst.setSelectedIndex(i);
break;
}
}
listPanel.add(sPane2);
/**
* setup Resolution Methods list
*/
reslvMethodsLst = new javax.swing.JList();
reslvMethodsLst.setVisibleRowCount(10);
tList = new Vector();
tList.addElement(new FzyResMAXIMUM());
tList.addElement(new FzyResMAXPLATEAU());
tList.addElement(new FzyResCENTROID());
reslvMethodsLst.setListData(tList);
javax.swing.JScrollPane sPane3 = new javax.swing.JScrollPane();
sPane3.setBorder(
BorderFactory.createTitledBorder(
((javax.swing.border.Border)BorderFactory.createEtchedBorder()),
("Rule Resolution Methods")
)
);
sPane3.getViewport().add (reslvMethodsLst);
className = controller.getKB().getResolutionMethod().getClass();
for (int i = 0;i < tList.size();i++){
if (tList.elementAt(i).getClass() == className){
reslvMethodsLst.setSelectedIndex(i);
break;
}
}
listPanel.add(sPane3);
gbC.gridwidth = GridBagConstraints.REMAINDER;
gbC.gridheight = 3;
gbC.weighty = 1;
panel1.add(listPanel, gbC);
/**
* set up menu options
*/
FileMenuListener fml = new FileMenuListener();
javax.swing.JMenuBar mBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu("File");
javax.swing.JMenuItem applyI = new javax.swing.JMenuItem("apply");
applyI.setActionCommand("ie-apply");
applyI.addActionListener(fml);
javax.swing.JMenuItem closeI = new javax.swing.JMenuItem("close");
closeI.setActionCommand("ie-close");
closeI.addActionListener(fml);
fileMenu.add(applyI);
fileMenu.add(new javax.swing.JSeparator());
fileMenu.add(closeI);
mBar.add(fileMenu);
displayPanel.add("North", mBar);
displayPanel.add("Center", panel1);
frame.getContentPane().add("Center",displayPanel);
frame.pack();
frame.setTitle("ARC Light Inference Editor");
}
public void newName(String s){}
public void setVisible(boolean f) {
if (f){
frame.setLocation(50, 175);
frame.setVisible(f);
} else {
frame.setVisible(f);
frame.dispose();
//getController().setInferenceEditor(null);
}
}
public void update(infosapient.system.Observable observ, Object obj) {
}
public void updateKBReasoningMethods() {
getKB().setRunBefore(runBefore);
getKB().setResolutionMethod((infosapient.resolution.FzyResolutionMethod)reslvMethodsLst.getSelectedValue());
getKB().setImplicationMethod((infosapient.resolution.FzyImplicationMethod)inferMethodsLst.getSelectedValue());
getKB().setCorrelationMethod((infosapient.resolution.FzyCorrelation)corrMethodsLst.getSelectedValue());
getKB().notifyObservers(new FSEvent(this, "KB:InferMethodsSet", getKB()));
}
}