summaryrefslogtreecommitdiff
path: root/TAO/examples/Simulator/DOVEBrowser/DemoCore.java
blob: 9c371342923abd3f476af089aa52cd14a025ac51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// $Id$
// 
// = FILENAME
//    DemoCore.java
//
// = AUTHOR
//    Michael Kircher (mk1@cs.wustl.edu)
//
// = DESCRIPTION
//   This class servers as the core class of the simulation demo.
//   It connects the push consumer of the event service with 
//   one or several Java Beans.
//
// ============================================================================


import java.awt.*;
import java.awt.event.*;

public class DemoCore extends Frame {

  private static final int MAX_VIS_COMPS = 10;

  private PushConsumerFactory pushConsumerFactory_;
  private VisCompFactory visCompFactory_;
  private DataHandler dataHandler_;
  private java.util.Vector vis_comp_list_;
  private int countVisComp_ = 0;
  private GridBagLayout gridbag_;
  private GridBagConstraints constraints_;
  private boolean use_queueing_ = false;
  private boolean connections_established_ = false;

  DemoCore (String nameServiceIOR, 
	    String nameServicePort,
            String[] args, 
            boolean use_queueing,
	    java.applet.Applet applet) {
    super ();
    
    use_queueing = use_queueing;

    setSize (600,400);
    setBounds (new Rectangle (50,50,800,500));
    setVisible (true);
    
    gridbag_ = new GridBagLayout();
    constraints_ = new GridBagConstraints();
    constraints_.fill = GridBagConstraints.BOTH;
    constraints_.weightx = 1.0;
    constraints_.weighty = 1.0;
    this.setLayout (gridbag_);

    // Instantiate the DataHandler and the PushConsumer
    dataHandler_ = new NavWeapDataHandler ();
    pushConsumerFactory_ = new PushConsumerFactory (dataHandler_, 
                                                    nameServiceIOR, 
                                                    nameServicePort,
                                                    args,
                                                    use_queueing_,
                                                    applet);

    // List of Visualization Components
    vis_comp_list_ = new java.util.Vector();

    MenuBar menubar_ = new MenuBar ();
    Menu menu_ = new Menu ("File");
    MenuItem menu_quit_item_ = new MenuItem ("Quit");
    menu_quit_item_.setEnabled (true);
    MenuItem menu_add_item_ = new MenuItem ("Add");
    menu_add_item_.setEnabled (true);
    menu_.add (menu_add_item_);
    menu_.add (menu_quit_item_);
    menubar_.add (menu_);
    
    setMenuBar (menubar_);
    
    menu_quit_item_.addActionListener (new ActionListener () 
				       {
					 public void actionPerformed (ActionEvent e) {
					   System.exit (0);
					 }
				       });      
      
    menu_add_item_.addActionListener (new ActionListener () 
				       {
					 public void actionPerformed (ActionEvent e) {
					   ObservablesDialog obsDialog_ = 
					     new ObservablesDialog (DemoCore.this,
								    dataHandler_.getObservablesList());
					   obsDialog_.addAnswerListener (new AnswerListener ()
									{
									  public void ok (AnswerEvent e)
									    {
									      DemoCore.this.addConnection (e.selected_);
									    }
									});
					   obsDialog_.setVisible (true);
					 }
				       });      
    
    // instantiate the Factory for Visualization Components
    visCompFactory_ = new VisCompFactory ();

    // Traverse the args looking for switches that determine connections.
    int arg_index = 0;
    while (args.length > arg_index) 
      {
        if (args[arg_index].equals ("-dualECdemo") ||
            args[arg_index].equals ("-dualECdemo1") ||
            args[arg_index].equals ("-dualECdemo2")) 
          {
            // Use monotonic scales in the double precision data windows
            DoubleVisComp.monotonic_scale (true);

            // Establish connections
            if (! connections_established_)
              {
                connections_established_ = true;
                addConnection ("Weapons");
                addConnection ("Weapons Latency (100 ns)");
                addConnection ("Weapons Latency Jitter (100 ns)");
                addConnection ("Navigation");
                addConnection ("Navigation Latency (100 ns)");
                addConnection ("Navigation Latency Jitter (100 ns)");
                break;
              }
          }
        // Skip over anything else.
        else
          {
            arg_index ++;
          }
      }

   
    // If connections have not been established, set up defaults
    if (! connections_established_)
      {
        connections_established_ = true;
        addConnection ("Weapons");
        addConnection ("Weapons Latency (100 ns)");
        addConnection ("Navigation");
        addConnection ("Navigation Latency (100 ns)");
      }
  }


  public boolean addConnection (String selected) {	
		// to not fill too many into it
    if (countVisComp_ < MAX_VIS_COMPS) {
      
      // get a reference to the Observable
      DemoObservable observable_ = dataHandler_.getObservable (selected);
      
      if (observable_ != null) {
	
        VisComp visComp_ = visCompFactory_.getNewVisComp (observable_.getProperty (), selected);

	if (visComp_ != null) {
	  vis_comp_list_.addElement (visComp_);	 
	  
	  // connect the Observer with the Observable
	  observable_.addObserver (visComp_);
	  
	  countVisComp_++;
	  
          // not more than three in a row
	  if (countVisComp_ == 3){
	    constraints_.gridwidth = GridBagConstraints.REMAINDER;
          }
          if (countVisComp_ > 3) {
	    constraints_.gridwidth = 1;
	  } 
	  
	  gridbag_.setConstraints ((java.awt.Component) visComp_, constraints_);
	  
	  // add the Visualization Component to the Frame
	  DemoCore.this.add ((java.awt.Component) visComp_);
	  DemoCore.this.show ();
	  
          return true;
        }
      }
    }
    return false;
  }
  
  public void init () 
    {
    }
  
  public void paint (Graphics g) 
    {
    }
  
  public void run () 
    {
      // Wait passive until events come in
      pushConsumerFactory_.run ();
    } 
}