/* * FuzzyRulePanel.java * * Created on July 7, 2002, 5:44 PM */ package uk.ac.leeds.ccg.projects.MedAction.FuzzyInference; /** * a GUI to define rules for this model * @author jianhui jin */ import javax.swing.*; import java.io.*; public class FuzzyRulePanel extends javax.swing.JPanel { public FuzzyRulePanel() { setFuzzyRuleModel(new FuzzyRuleModel("no name")); initComponents(); //initialize the Variable and other's panel iniVariablePanel(variableComboBox.length); setBorder(new javax.swing.border.TitledBorder("No name" + " Fuzzy Rules")); } /** * * @param name */ public FuzzyRulePanel(String name) { setFuzzyRuleModel(new FuzzyRuleModel(name)); initComponents(); //initialize the Variable and other's panel iniVariablePanel(variableComboBox.length); setBorder(new javax.swing.border.TitledBorder(name + " Fuzzy Rules")); } /** * * @param model */ public FuzzyRulePanel( FuzzyRuleModel model ) { this.fuzzyRuleModel=model; initComponents(); //initialize the Variable and other's panel iniVariablePanel(model.getFuzzyVariableName(model.getFuzzyVariable()).length); setBorder(new javax.swing.border.TitledBorder(model.getName() + " Fuzzy Rules")); FuzzyRule[] rules=model.getFuzzyRule(); if(rules!=null&&rules.length!=0){ for(int i=0;i0)){ r[ruleCombo.getSelectedIndex()].setConfidence(Integer.parseInt(confidenceTextField.getText())); }// Add your handling code here: } private void iniVariablePanel(int length) { isLabel=new JLabel[length]; variableComboBox=new JComboBox[length]; variableMemberComboBox=new JComboBox[length]; operatorComboBox=new JComboBox[length-1]; variablePanel.removeAll(); for(int i=0;i0)){ int index=((JComboBox) evt.getSource()).getSelectedIndex(); if(index < temp.length&& index >= 0){ FuzzyRule selectedRule = temp[index]; iniRuleComponents(selectedRule); } } // Add your handling code here: } private void iniRuleComponents(FuzzyRule rule){ String[] vName=rule.getVariableName(); String[] mName=rule.getMemberName(); String[] opName=rule.getOperatorName(); iniVariablePanel(vName.length); setPanel(this.fuzzyRuleModel); for(int i=0;i0)&&(fuzzyRuleModel.getFuzzyRule()!=null)&&(fuzzyRuleModel.getFuzzyRule().length > 0)){ fuzzyRuleModel.removeRule(ruleCombo.getSelectedIndex()); ruleCombo.removeItemAt(ruleCombo.getItemCount()-1); int temp=ruleCombo.getSelectedIndex(); FuzzyRule[] rules=fuzzyRuleModel.getFuzzyRule(); if(temp>=0) iniRuleComponents(rules[temp]); } // Add your handling code here: } private void setNewRuleButtonActionPerformed(java.awt.event.ActionEvent evt) { if(variableComboBox[0].getItemCount()<0) return; String[] variableName=new String[variableComboBox.length]; String[] memberName=new String[variableMemberComboBox.length]; String[] operatorName=new String[operatorComboBox.length]; for(int i=0;i= 2){ // construct new arrays with old length increasing one variableComboBox=new JComboBox[variableComboBox.length-1]; variableMemberComboBox=new JComboBox[variableMemberComboBox.length-1]; isLabel=new JLabel[isLabel.length-1]; operatorComboBox=new JComboBox[operatorComboBox.length-1]; // assign old to new without the final one for(int i=0;i