Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Simulator / DOVEBrowser / DemoCore.java
blobd526f1ec777625f3eb0f809d5f4d183372dd4a87
1 //
2 // = FILENAME
3 // DemoCore.java
4 //
5 // = AUTHOR
6 // Michael Kircher (mk1@cs.wustl.edu)
7 //
8 // = DESCRIPTION
9 // This class servers as the core class of the simulation demo.
10 // It connects the push consumer of the event service with
11 // one or several Java Beans.
13 // ============================================================================
16 import java.awt.*;
17 import java.awt.event.*;
19 public class DemoCore extends Frame {
21 private static final int MAX_VIS_COMPS = 10;
23 private PushConsumerFactory pushConsumerFactory_;
24 private VisCompFactory visCompFactory_;
25 private DataHandler dataHandler_;
26 private java.util.Vector vis_comp_list_;
27 private int countVisComp_ = 0;
28 private GridBagLayout gridbag_;
29 private GridBagConstraints constraints_;
30 private boolean use_queueing_ = false;
31 private boolean connections_established_ = false;
33 DemoCore (String nameServiceIOR,
34 String nameServicePort,
35 String[] args,
36 boolean use_queueing,
37 java.applet.Applet applet) {
38 super ();
40 use_queueing = use_queueing;
42 setSize (600,400);
43 setBounds (new Rectangle (50,50,800,500));
44 setVisible (true);
46 gridbag_ = new GridBagLayout();
47 constraints_ = new GridBagConstraints();
48 constraints_.fill = GridBagConstraints.BOTH;
49 constraints_.weightx = 1.0;
50 constraints_.weighty = 1.0;
51 this.setLayout (gridbag_);
53 // Instantiate the DataHandler and the PushConsumer
54 dataHandler_ = new NavWeapDataHandler ();
55 pushConsumerFactory_ = new PushConsumerFactory (dataHandler_,
56 nameServiceIOR,
57 nameServicePort,
58 args,
59 use_queueing_,
60 applet);
62 // List of Visualization Components
63 vis_comp_list_ = new java.util.Vector();
65 MenuBar menubar_ = new MenuBar ();
66 Menu menu_ = new Menu ("File");
67 MenuItem menu_quit_item_ = new MenuItem ("Quit");
68 menu_quit_item_.setEnabled (true);
69 MenuItem menu_add_item_ = new MenuItem ("Add");
70 menu_add_item_.setEnabled (true);
71 menu_.add (menu_add_item_);
72 menu_.add (menu_quit_item_);
73 menubar_.add (menu_);
75 setMenuBar (menubar_);
77 menu_quit_item_.addActionListener (new ActionListener ()
79 public void actionPerformed (ActionEvent e) {
80 System.exit (0);
82 });
84 menu_add_item_.addActionListener (new ActionListener ()
86 public void actionPerformed (ActionEvent e) {
87 ObservablesDialog obsDialog_ =
88 new ObservablesDialog (DemoCore.this,
89 dataHandler_.getObservablesList());
90 obsDialog_.addAnswerListener (new AnswerListener ()
92 public void ok (AnswerEvent e)
94 DemoCore.this.addConnection (e.selected_);
96 });
97 obsDialog_.setVisible (true);
99 });
101 // instantiate the Factory for Visualization Components
102 visCompFactory_ = new VisCompFactory ();
104 // Traverse the args looking for switches that determine connections.
105 int arg_index = 0;
106 while (args.length > arg_index)
108 if (args[arg_index].equals ("-dualECdemo") ||
109 args[arg_index].equals ("-dualECdemo1") ||
110 args[arg_index].equals ("-dualECdemo2"))
112 // Use monotonic scales in the double precision data windows
113 DoubleVisComp.monotonic_scale (true);
115 // Establish connections
116 if (! connections_established_)
118 connections_established_ = true;
119 addConnection ("Weapons");
120 addConnection ("Weapons Latency (100 ns)");
121 addConnection ("Weapons Latency Jitter (100 ns)");
122 addConnection ("Navigation");
123 addConnection ("Navigation Latency (100 ns)");
124 addConnection ("Navigation Latency Jitter (100 ns)");
125 break;
128 if (args[arg_index].equals ("-dualECdemo") ||
129 args[arg_index].equals ("-dualECdemo1") ||
130 args[arg_index].equals ("-dualECdemo2"))
132 // Use monotonic scales in the double precision data windows
133 DoubleVisComp.monotonic_scale (true);
135 // Establish connections
136 if (! connections_established_)
138 connections_established_ = true;
139 addConnection ("Weapons");
140 addConnection ("Weapons Latency (100 ns)");
141 addConnection ("Weapons Latency Jitter (100 ns)");
142 addConnection ("Navigation");
143 addConnection ("Navigation Latency (100 ns)");
144 addConnection ("Navigation Latency Jitter (100 ns)");
145 break;
149 else if (args[arg_index].equals ("-PRdemo"))
151 // Establish connections
152 if (! connections_established_)
154 connections_established_ = true;
155 addConnection ("High Consumer Persian Recursion", 2);
156 addConnection ("Low Consumer Persian Recursion", 2);
157 // addConnection ("High Consumer Execution Time (100 ns)", 2);
158 // addConnection ("Low Consumer Execution Time (100 ns)", 2);
159 break;
163 // Skip over anything else.
164 else
166 arg_index ++;
171 // If connections have not been established, set up defaults
172 if (! connections_established_)
174 connections_established_ = true;
175 addConnection ("Weapons");
176 addConnection ("Weapons Latency (100 ns)");
177 addConnection ("Navigation");
178 addConnection ("Navigation Latency (100 ns)");
183 public boolean addConnection (String selected, int max_in_a_row) {
184 // to not fill too many into it
185 if (countVisComp_ < MAX_VIS_COMPS) {
187 // get a reference to the Observable
188 DemoObservable observable_ = dataHandler_.getObservable (selected);
190 if (observable_ != null) {
192 VisComp visComp_ = visCompFactory_.getNewVisComp (observable_.getProperty (), selected);
194 if (visComp_ != null) {
195 vis_comp_list_.addElement (visComp_);
197 // connect the Observer with the Observable
198 observable_.addObserver (visComp_);
200 countVisComp_++;
202 // not more than three in a row
203 if (countVisComp_ == max_in_a_row){
204 constraints_.gridwidth = GridBagConstraints.REMAINDER;
206 if (countVisComp_ > max_in_a_row) {
207 constraints_.gridwidth = 1;
210 gridbag_.setConstraints ((java.awt.Component) visComp_, constraints_);
212 // add the Visualization Component to the Frame
213 DemoCore.this.add ((java.awt.Component) visComp_);
214 DemoCore.this.show ();
216 return true;
220 return false;
223 public boolean addConnection (String selected) {
224 return addConnection (selected, 3);
227 public void init ()
231 public void paint (Graphics g)
235 public void run ()
237 // Wait passive until events come in
238 pushConsumerFactory_.run ();