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  * DefinitionPanel.java
26  *
27  * Panel through which agent attributes are entered
28  ***************************************************************************/
29  
30  package zeus.generator.agent;
31  
32  import java.awt.*;
33  import java.awt.event.*;
34  import java.util.*;
35  import javax.swing.*;
36  import javax.swing.border.*;
37  import javax.swing.text.*;
38  import javax.swing.event.*;
39  
40  import zeus.util.*;
41  import zeus.concepts.*;
42  import zeus.generator.*;
43  import zeus.generator.util.*;
44  import zeus.gui.fields.*;
45  
46  public class DefinitionPanel extends JPanel {
47    protected WholeNumberField planner_width;
48    protected WholeNumberField planner_length;
49    protected TaskPanel        taskPanel;
50    protected FactPanel        factPanel;
51    protected AgentDescription agent;
52  
53    public DefinitionPanel(AgentGenerator generator,
54                           GeneratorModel genmodel,
55                           OntologyDb ontologyDb,
56                           AgentEditor editor,
57                           AgentDescription agent)  {
58  
59      this.agent = agent;
60  
61      GridBagLayout gridBagLayout = new GridBagLayout();
62      GridBagConstraints gbc = new GridBagConstraints();
63      setLayout(gridBagLayout);
64      setBackground(Color.lightGray);    
65      setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
66      
67      // Add the control panel 
68      ControlPanel controlPane =
69         new ControlPanel(editor,"Agent Definition Panel",true,false);
70      
71      gbc.gridwidth = GridBagConstraints.REMAINDER;
72      gbc.anchor = GridBagConstraints.NORTHWEST;
73      gbc.fill = GridBagConstraints.HORIZONTAL;
74      gbc.insets = new Insets(8,8,8,8);
75      gridBagLayout.setConstraints(controlPane,gbc);
76      add(controlPane);
77      
78      // Add the panel containing planning parameters to this panel.
79      JPanel planningPanel = new JPanel();
80  
81      gbc.gridwidth = GridBagConstraints.REMAINDER;
82      gbc.anchor = GridBagConstraints.WEST;
83      gbc.fill = GridBagConstraints.HORIZONTAL;
84      gbc.insets = new Insets(8,8,8,8);
85      gridBagLayout.setConstraints(planningPanel,gbc);
86      add(planningPanel);
87  
88      // Add the panel containing the agent's tasks to the panel.
89      String[] tasks = agent.getTasks();
90      taskPanel = new TaskPanel(generator,genmodel,editor,tasks,
91                                "Task Identification");
92      gbc.gridwidth = GridBagConstraints.REMAINDER;
93      gbc.anchor = GridBagConstraints.NORTHEAST;
94      gbc.fill = GridBagConstraints.BOTH;
95      gbc.insets = new Insets(8,8,8,8);
96      gridBagLayout.setConstraints(taskPanel,gbc);
97      add(taskPanel);
98      
99      // Add the panel containing the agent's facts to this panel.
100     Fact[] facts = agent.getInitialFacts();
101     factPanel = new FactPanel(ontologyDb,editor,facts,Fact.FACT,
102                               "Initial Agent Resources");
103     gbc.anchor = GridBagConstraints.SOUTH;
104     gbc.fill = GridBagConstraints.BOTH;
105     gbc.weightx = gbc.weighty = 1;
106     gridBagLayout.setConstraints(factPanel,gbc);
107     add(factPanel);
108 
109     // create planning panel info
110     planningPanel.setBackground(Color.lightGray);
111 
112     int min_width = SystemProps.getInt("planner.processors.min");
113     int max_width = SystemProps.getInt("planner.processors.max");
114 
115     int min_length = SystemProps.getInt("planner.length.min");
116     int max_length = SystemProps.getInt("planner.length.max");
117 
118     planner_width = new WholeNumberField(min_width,max_width);
119     planner_width.setBackground(Color.white);
120     planner_width.setValue(agent.getPlannerWidth());
121     planner_width.addChangeListener(editor);
122 
123     planner_length = new WholeNumberField(min_length, max_length);
124     planner_length.setBackground(Color.white);
125     planner_length.setValue(agent.getPlannerLength());
126     planner_length.addChangeListener(editor);
127 
128     planner_width.setPreferredSize(new Dimension(200,20));
129     planner_length.setPreferredSize(new Dimension(200,20));
130 
131     TitledBorder border = BorderFactory.createTitledBorder("Planning Parameters");
132     border.setTitlePosition(TitledBorder.TOP);
133     border.setTitleJustification(TitledBorder.RIGHT);
134     border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
135     border.setTitleColor(Color.blue);
136     planningPanel.setBorder(border);
137 
138     GridBagLayout gb = new GridBagLayout();
139     planningPanel.setLayout(gb);
140 
141     gbc = new GridBagConstraints();
142 
143     JLabel label1 = new JLabel("Maximum Number of Simultaneous Tasks");
144     label1.setFont(new Font("Helvetica",Font.PLAIN, 12));
145     label1.setToolTipText("Minimum = " + min_width +
146                           ", Maximum = " + max_width);
147 
148     gbc.insets = new Insets(4,8,4,0);
149     gbc.fill = GridBagConstraints.NONE;
150     gbc.anchor = GridBagConstraints.WEST;
151     gb.setConstraints(label1,gbc);
152     planningPanel.add(label1);
153   
154     gbc.gridwidth = GridBagConstraints.REMAINDER;
155     gbc.fill = GridBagConstraints.NONE;
156     gbc.insets = new Insets(4,8,4,8);
157     gb.setConstraints(planner_width,gbc);
158     planningPanel.add(planner_width);
159 
160     JLabel label2 = new JLabel("Planner Length");
161     label2.setFont(new Font("Helvetica",Font.PLAIN, 12));
162     label2.setToolTipText("Minimum = " + min_length +
163                           ", Maximum = " + max_length);
164 
165     gbc.gridwidth = 1;
166     gbc.fill = GridBagConstraints.NONE;
167     gbc.insets = new Insets(4,8,4,0);
168     gb.setConstraints(label2,gbc);
169     planningPanel.add(label2);
170      
171     gbc.gridwidth = GridBagConstraints.REMAINDER;
172     gbc.fill = GridBagConstraints.NONE;
173     gbc.insets = new Insets(4,8,4,8);
174     gbc.weightx = 1;
175     gb.setConstraints(planner_length,gbc);
176     planningPanel.add(planner_length);
177   }
178 
179   public void save() {
180      Long value = planner_width.getValue();
181      if ( value != null ) agent.setPlannerWidth(value.intValue());
182      value = planner_length.getValue();
183      if ( value != null ) agent.setPlannerLength(value.intValue());
184      agent.setTasks(taskPanel.getData());
185      agent.setInitialFacts(factPanel.getData());
186   }
187 }