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  * SummaryTaskNodeEditorDialog.java
26  *
27  * Main Frame for the task editing panels
28  ***************************************************************************/
29  
30  package zeus.generator.task;
31  
32  import java.util.*;
33  import java.awt.*;
34  import java.awt.event.*;
35  import javax.swing.*;
36  import javax.swing.border.*;
37  import javax.swing.event.*;
38  
39  import zeus.util.*;
40  import zeus.concepts.*;
41  import zeus.generator.*;
42  import zeus.generator.util.*;
43  
44  
45  public class SummaryTaskNodeEditorDialog extends JDialog
46                                     implements ActionListener, 
47  				              ChangeListener {
48  
49    protected JTabbedPane           tabbedPane;
50    protected JButton               okBtn;
51    protected JButton               cancelBtn;
52    protected boolean               changed = false;
53    protected SummaryTaskNodeEditor editor = null;
54  
55    protected TaskNodePanel nodePanel;
56    protected TaskLinkPanel linkPanel;
57  
58    public SummaryTaskNodeEditorDialog(Frame parent, OntologyDb ontologyDb) {
59      super(parent,"Summary Task Node Editor");
60  
61      JPanel pane = (JPanel)getContentPane();
62      pane.setBackground(Color.lightGray);
63      pane.setLayout(new BorderLayout());
64  
65      tabbedPane = new JTabbedPane();
66      nodePanel = new TaskNodePanel(ontologyDb,this);
67      linkPanel = new TaskLinkPanel(this,nodePanel,
68         nodePanel.getPreconditionsManager(),nodePanel.getPostconditionsManager()
69      );
70  
71      tabbedPane.addTab("Preconditions and Effects", nodePanel);
72      tabbedPane.addTab("Links", linkPanel);
73  
74      tabbedPane.setSelectedIndex(0);
75      tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
76      pane.add(tabbedPane,BorderLayout.CENTER);
77  
78      JPanel controlpane = new JPanel();
79      controlpane.setLayout(new GridLayout(1,2,10,10));
80      pane.add(controlpane,BorderLayout.SOUTH);
81      CompoundBorder cbr = new CompoundBorder(new EtchedBorder(),
82                                              new EmptyBorder(5,5,5,5));
83      controlpane.setBorder(cbr);
84  
85      okBtn = new JButton("OK");
86      okBtn.addActionListener(this);
87      cancelBtn = new JButton("Cancel");
88      cancelBtn.addActionListener(this);
89      controlpane.add(okBtn);
90      controlpane.add(cancelBtn);
91  
92      this.addWindowListener(new WindowAdapter() {
93            public void windowClosing(WindowEvent evt) { closeDown(false); }
94         }
95      );
96      setModal(false);
97      setVisible(false);
98    }
99  
100   public void actionPerformed(ActionEvent e) {
101      Object src = e.getSource();
102      if ( src == okBtn )
103         closeDown(changed);
104      else if ( src == cancelBtn )
105         closeDown(false);
106   }
107 
108   protected void closeDown(boolean state) {
109      if ( state ) {
110         TaskNode node = nodePanel.getNode();
111         Hashtable names = nodePanel.getNameTable();
112         TaskLink[] links = linkPanel.getLinks();
113         editor.editingStopped(node,links,names);
114      }
115      else {
116         editor.editingCancelled();
117      }
118   }
119 
120   public void reset(SummaryTaskNodeEditor editor, TaskNode node,
121                     TaskNode[] others, TaskLink[] links) {
122      this.editor = editor;
123      nodePanel.reset(node);
124      linkPanel.reset(node,others,links);
125      changed = false;
126      tabbedPane.setSelectedIndex(0);
127      pack();
128   }
129 
130   public void stateChanged(ChangeEvent evt) {
131      changed = true;
132   }
133 }