View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  /******************************************************************************
25  * FactDialog.java
26  *
27  * A pop-up dialog that prompts selection of a fact
28  *****************************************************************************/
29  
30  package zeus.generator.util;
31  
32  import javax.swing.*;
33  import javax.swing.border.*;
34  import java.awt.*;
35  import java.awt.event.*;
36  
37  import zeus.concepts.*;
38  import zeus.ontology.facts.*;
39  
40  
41  public class FactDialog extends JDialog implements ActionListener {
42    protected FactTreeUI     treeView; 
43    protected JButton        okBtn, cancelBtn;
44    protected FactSelector   caller = null;
45  
46    public FactDialog(Frame parent, OntologyDb ontologyDb) {
47      super(parent,"Select Fact");
48      
49      JPanel pane = (JPanel)getContentPane();
50      pane.setBorder(new EmptyBorder(10,10,10,10));  
51      pane.setBackground(Color.lightGray);
52      pane.setLayout(new BorderLayout());
53  
54      treeView = new FactTreeUI(ontologyDb);
55      JScrollPane treePane = new JScrollPane();
56      treePane.setPreferredSize(new Dimension(300,150));
57      treePane.getViewport().add(treeView);
58      pane.add(treePane,BorderLayout.CENTER);
59  
60      JPanel controlpane = new JPanel();
61      controlpane.setLayout(new GridLayout(1,2,10,10));
62      pane.add(controlpane,BorderLayout.SOUTH);
63  
64      okBtn = new JButton("OK");
65      okBtn.addActionListener(this);
66      cancelBtn = new JButton("Cancel");
67      cancelBtn.addActionListener(this);
68      controlpane.add(okBtn);
69      controlpane.add(cancelBtn);
70  
71      setModal(true);
72      setVisible(false);
73    }
74  
75    public void actionPerformed(ActionEvent evt) {
76      if ( evt.getSource() == okBtn ) {
77         setVisible(false);
78         String[] names = treeView.getSelectedNodeNames();
79         caller.factSelected(names);
80      }
81      else if ( evt.getSource() == cancelBtn ) {
82         setVisible(false);
83      }
84    }
85  
86    public void display(FactSelector caller) {
87      this.caller = caller;
88      treeView.refresh();
89      pack();
90      setVisible(true);
91    }
92  }