1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /******************************************************************************
25 *
26 *
27 * A pop-up dialog that prompts selection of a fact
28 *****************************************************************************/
29 package zeus.generator.task.rulebase;
30
31 import javax.swing.*;
32 import javax.swing.tree.*;
33 import javax.swing.border.*;
34
35 import java.awt.*;
36 import java.awt.event.*;
37 import java.io.*;
38
39 import zeus.ontology.facts.*;
40 import zeus.ontology.*;
41 import zeus.util.*;
42 import zeus.concepts.*;
43 import zeus.concepts.fn.*;
44
45
46 public class FactPanel extends JPanel implements ActionListener {
47 static final String FACT_MARKER = "<-";
48
49 protected FactTreeUI treeView;
50 protected JButton factIDBtn, factBtn;
51 RuleUI parent;
52 OntologyDb db;
53
54 public FactPanel(RuleUI parent, OntologyDb db) {
55 this.parent = parent;
56 this.db = db;
57 setBorder(new EmptyBorder(10,10,10,10));
58 setBackground(Color.lightGray);
59 setLayout(new BorderLayout());
60
61 treeView = new FactTreeUI(db );
62 JScrollPane treePane = new JScrollPane(treeView);
63 treePane.setPreferredSize(new Dimension(400,150));
64 add(treePane,BorderLayout.CENTER);
65
66 JPanel controlpane = new JPanel();
67 controlpane.setLayout(new GridLayout(1,2,10,10));
68 add(controlpane,BorderLayout.SOUTH);
69
70 factBtn = new JButton("Insert Fact");
71 factBtn.addActionListener(this);
72 factIDBtn = new JButton("Insert with ID");
73 factIDBtn.addActionListener(this);
74 controlpane.add(factBtn);
75 controlpane.add(factIDBtn);
76 }
77
78 public void actionPerformed(ActionEvent evt) {
79 String aValue = null;
80 Fact f = null;
81
82 String name = treeView.getSelectedNodeName();
83 if ( name == null ) return;
84
85 f = db.getFact(Fact.VARIABLE,name);
86
87 if ( evt.getSource() == factBtn && f != null) {
88 aValue = getAttributeValues(f);
89 }
90 else if ( evt.getSource() == factIDBtn && f != null ) {
91 aValue = f.getId() + " " + FACT_MARKER + " " + getAttributeValues(f);
92 }
93 if ( aValue != null ) {
94 parent.appendTextTo(aValue);
95
96 }
97
98 }
99
100 public String getAttributeValues(Fact f){
101 String[] a = f.listAttributes();
102 ValueFunction[] v = f.listValues();
103 String attValues = "(" + f.getType();
104
105 for(int i = 0; i < a.length; i++ )
106 attValues += " (" + a[i] + " " + v[i] + ")";
107
108 return attValues + ")";
109 }
110
111 }