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  package zeus.agentviewer;
25  
26  import javax.swing.*;
27  import java.awt.*;
28  import java.text.NumberFormat;
29  import java.awt.event.*;
30  import zeus.util.*;
31  import zeus.actors.AgentContext;
32  import zeus.gui.fields.*;
33  
34  class ControlOptionsDialog extends JDialog implements ActionListener {
35  
36      AgentContext context;
37      JPanel contentPane;
38  
39      RealNumberField registration_timeout, facilitator_timeout,
40                      address_timeout, accept_timeout, addressbook_refresh,
41  		    facilitator_refresh, replan_period;
42  
43      JPanel centerPanel, leftPanel, rightPanel;
44      JCheckBox share_plan, execute_earliest;
45      JLabel label;
46  
47      JButton okBtn,applyBtn,cancelBtn;
48  
49  
50      /***
51          class constructor for this dialog. 
52          <p> 
53          NOTES:<br> 
54          refactored during 1.1 to allow compilation with interfaced AgentContexts. 
55          <P> 
56          TO DO: <br>
57          work out what the hell this really is for....
58          */
59     public ControlOptionsDialog(AgentViewer agentviewer,AgentContext context) {
60        super(agentviewer,"Set Agent's Context");
61        this.context = context;
62  
63        //---leftpanel
64        leftPanel = new JPanel(new GridLayout(9,2));
65        leftPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
66        leftPanel.add(new JLabel("Share plan "));
67        share_plan = new JCheckBox();
68        share_plan.setSelected(SystemProps.getState("share.plan"));
69        //share_plan.setFont(new Font("Helvetica", Font.PLAIN, 8));
70        leftPanel.add(share_plan);
71  
72        leftPanel.add(new JLabel("Execute earliest"));
73        execute_earliest = new JCheckBox();
74        execute_earliest.setSelected(SystemProps.getState("execute.earliest"));
75        //execute_earliest.setFont(new Font("Helvetica", Font.PLAIN, 8));
76        leftPanel.add(execute_earliest);
77  
78        leftPanel.add(new JLabel("Registration timeout"));
79        registration_timeout = new RealNumberField(0,10);
80        registration_timeout.setValue(context.getRegistrationTimeout());
81        leftPanel.add(registration_timeout);
82  
83        leftPanel.add(new JLabel("Broker timeout"));
84        facilitator_timeout = new RealNumberField(0,10);
85        facilitator_timeout.setValue(context.getFacilitatorTimeout());
86        leftPanel.add(facilitator_timeout);
87  
88        leftPanel.add(new JLabel("Address timeout"));
89        address_timeout = new RealNumberField(0,10);
90        address_timeout.setValue(context.getAddressTimeout());
91        leftPanel.add(address_timeout);
92  
93        leftPanel.add(new JLabel("Accept timeout"));
94        accept_timeout = new RealNumberField(0,10);
95        accept_timeout.setValue(context.getAcceptTimeout());
96        leftPanel.add(accept_timeout);
97  
98        leftPanel.add(new JLabel("Addressbook refresh "));
99        addressbook_refresh = new RealNumberField(0,10);
100       addressbook_refresh.setValue(context.getAddressBookRefresh());
101       leftPanel.add(addressbook_refresh);
102 
103       leftPanel.add(new JLabel("Broker refresh"));
104       facilitator_refresh = new RealNumberField(0,10);
105       facilitator_refresh.setValue(context.getFacilitatorRefresh());
106       leftPanel.add(facilitator_refresh);
107 
108       leftPanel.add(new JLabel("Replan period"));
109       replan_period = new RealNumberField(0,10);
110       replan_period.setValue(context.getReplanPeriod());
111       leftPanel.add(replan_period);
112 
113       //--    buttons
114       JPanel outerBtn = new JPanel(new BorderLayout());
115 
116       JPanel btnPanel = new JPanel();
117       btnPanel.setLayout(new BoxLayout(btnPanel,BoxLayout.X_AXIS));
118 
119       outerBtn.add(BorderLayout.NORTH,new JSeparator(SwingConstants.HORIZONTAL));
120       outerBtn.add(BorderLayout.CENTER,btnPanel);
121 
122       okBtn = new JButton("OK");
123       okBtn.addActionListener(this);
124       okBtn.setForeground(Color.black);
125       okBtn.setFont(new  Font("Helvetica", Font.BOLD, 14));
126       btnPanel.add(okBtn);
127       btnPanel.add(Box.createRigidArea(new Dimension(20,10)));
128 
129       applyBtn = new JButton("Apply");
130       applyBtn.addActionListener(this);
131       applyBtn.setForeground(Color.black);
132       applyBtn.setFont(new  Font("Helvetica", Font.BOLD, 14));
133 
134       btnPanel.add(applyBtn);
135       btnPanel.add(Box.createRigidArea(new Dimension(20,10)));
136 
137       cancelBtn = new JButton("Cancel");
138       cancelBtn.setForeground(Color.black);
139       cancelBtn.setFont(new  Font("Helvetica", Font.BOLD, 14));
140       cancelBtn.addActionListener(this);
141       btnPanel.add(cancelBtn);
142 
143 
144       contentPane = (JPanel) getContentPane();
145       contentPane.setLayout(new BorderLayout());
146       contentPane.add(BorderLayout.CENTER,leftPanel);
147       contentPane.add(BorderLayout.SOUTH,outerBtn);
148 
149       pack();
150       setVisible(true);
151       setModal(true);
152    }
153 
154 
155     /***
156         applySettings is a package protected method that is used to set the agents working 
157         parameters 
158         <P> notes: heavily refactored during the 1.1 rearchitect
159         */
160       void applySettings() {
161          context.setSharePlan (share_plan.isSelected());
162          context.setExecuteEarliest(execute_earliest.isSelected());
163 
164          Double value;
165 	     value = registration_timeout.getValue(context.getRegistrationTimeout());
166          context.setRegistrationTimeout (value.doubleValue());
167 
168 	     value = facilitator_timeout.getValue(context.getFacilitatorTimeout());
169          context.setFacilitatorTimeout(value.doubleValue());
170          
171 	     value = address_timeout.getValue(context.getAddressTimeout());
172          context.setAddressTimeout (value.doubleValue());
173 	 
174 	     value = accept_timeout.getValue(context.getAcceptTimeout());
175          context.setAcceptTimeout(value.doubleValue());
176 	 
177 	     value = addressbook_refresh.getValue(context.getAddressBookRefresh());
178          context.setAddressBookRefresh(value.doubleValue());
179 
180 	     value = facilitator_refresh.getValue(context.getFacilitatorRefresh());
181          context.setFacilitatorRefresh (value.doubleValue());
182 
183 	     value = replan_period.getValue(context.getReplanPeriod());
184          context.setReplanPeriod(value.doubleValue());
185       }
186 
187 
188 
189      public void actionPerformed(ActionEvent evt) {
190          Object source = evt.getSource();
191 
192          if ( source == applyBtn ) {
193             applySettings();
194            return;
195          }
196          else if ( source == okBtn) {
197            applySettings();
198            this.dispose();
199          }
200          else if (source == cancelBtn) {
201            this.dispose();
202          }
203      }
204 
205 }