summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/server_discovery/Server_Discovery_Selection.java
blob: 17431dc58314a7d860575cd1302423cf31afbe3a (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
205
206
207
208
209
210
211
212
213
214
215
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.tree.*;
import com.sun.java.swing.table.*;
import com.sun.java.swing.border.*;
import Server_Discovery;
import Server_Discovery_Util;

public class Server_Discovery_Selection
  extends JInternalFrame
{
  JTree tree_;
  Server_Discovery sd_;
  JScrollPane table_scroller_ = new JScrollPane ();
  DefaultMutableTreeNode root_ = new DefaultMutableTreeNode ("Movies");
  String selected_movie_ = null, selected_server_ = null;
  Hashtable movie_map_ = new Hashtable ();
  JTable movie_table;
  TAO_VR.Movie selected_movie_info_; 
  
  public Server_Discovery_Selection (Server_Discovery sd)
    {
      super ("Movie Selection", true, true, true, true);
      this.sd_ = sd;

      tree_ = new JTree (this.root_);
      JScrollPane tree_scroller = new JScrollPane (this.tree_);
      JSplitPane split_pane =
        new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, false,
                        tree_scroller, this.table_scroller_);

      TreeSelectionListener tsl = new TreeSelectionListener ()
        {
          public void valueChanged (TreeSelectionEvent e)
            {
              
              DefaultMutableTreeNode tree_node =
                (DefaultMutableTreeNode) (e.getPath().getLastPathComponent ());
             
              if(tree_node.getChildCount()==1)
                {  
                  String movie_name = (String) tree_node.getUserObject ();
                  System.out.println("The moviename is" + movie_name);
                  
                    DefaultMutableTreeNode child_node =
                      (DefaultMutableTreeNode) tree_node.getChildAt (0);
                    String host_name = (String) child_node.getUserObject();
                    System.out.println("The hostname is" + host_name);
                    
                    String key = host_name + movie_name;
                    System.out.println("The host and movie name are " +key);
                    TAO_VR.Movie movie = (TAO_VR.Movie) movie_map_.get (key);
                    
                    generate_table (host_name, movie);
                    movie_table.updateUI();
                    selected_server_=host_name;
                    selected_movie_=movie_name;
                    selected_movie_info_=movie;
                    System.out.println("Movie Name is "+movie.name_);
                }
            }
        };
          
      
      this.tree_.addTreeSelectionListener (tsl);
      tree_scroller.setBackground (this.tree_.getBackground ());
      
      JPanel content_pane = new JPanel ();
      JPanel button_pane = new JPanel ();
      ImageIcon mmedia = new ImageIcon ("select", "mmedia3.gif");
      JButton select_button = new JButton ("View This Selection", mmedia);
      button_pane.setBorder (new EtchedBorder ());
      button_pane.add (select_button);
      content_pane.setLayout (new BorderLayout ());
      content_pane.add ("Center", split_pane);
      content_pane.add ("South", button_pane);

      ActionListener al = new ActionListener ()
        {
          public void actionPerformed (ActionEvent e)
            {
              if (selected_server_ != null && selected_movie_ != null)
                {
                  Server_Discovery_Util.load_movie (selected_server_,selected_movie_info_);
                }
            }
        };
      
      select_button.addActionListener (al);      
      
      this.setContentPane (content_pane);
      this.setSize (350, 400);
      this.setLocation (15, 15);
    }

  public void add_movie (String host_name, TAO_VR.Movie movie)
    {
      // @ TODO: Order the movies alphabetically by name.
      //      DefaultMutableTreeNode category =
      //new DefaultMutableTreeNode (movie.category_);
      DefaultMutableTreeNode movie_name =
        new DefaultMutableTreeNode (movie.name_);
      DefaultMutableTreeNode server_name =
        new DefaultMutableTreeNode (host_name);

      root_.add(movie_name);
      movie_name.add(server_name);
      //Object[] path = { movie_name, server_name };
      //TreePath tree_path = new TreePath (path);

      String key = host_name + movie.name_;
      this.movie_map_.put (key, movie);
      //this.tree_.addSelectionPath (tree_path);      
    }

  public void flush ()
    {
    }

  private void generate_table (String host_name, TAO_VR.Movie movie)
    {
      // The user object here is going to be a JTable instead of a
      // simply a string. The table will contain values for each of
      // the fields of the TAO_VR.Movie struct, where the description
      // URL will be hightlighted as a link. Clicking on that link in
      // the table will call up a JEditorPane with the html file in
      // it. In addition, there will be a button in one of table
      // entries for viewing performance numbers.
      DefaultTableModel table_model = new DefaultTableModel (10, 2);

      // Set the column values:
      table_model.setValueAt ("Name", 0, 0);
      table_model.setValueAt ("AudioFile Name", 1, 0);
      table_model.setValueAt ("VideoFile Name", 2, 0);
      table_model.setValueAt ("Description", 3, 0);
      table_model.setValueAt ("Format", 4, 0);
      table_model.setValueAt ("File Size", 5, 0);
      table_model.setValueAt ("Duration", 6, 0);
      table_model.setValueAt ("Frame Rate", 7, 0);
      table_model.setValueAt ("Frame Size", 8, 0);
      table_model.setValueAt ("Server Performance", 9, 0);

      table_model.setValueAt (movie.name_, 0, 1);
      table_model.setValueAt (movie.audio_filename_, 1, 1);
      table_model.setValueAt (movie.video_filename_, 2, 1);
      table_model.setValueAt (movie.description_, 3, 1);
      table_model.setValueAt ("MPEG1", 4, 1);
      table_model.setValueAt ("0", 5, 1);
      table_model.setValueAt ("0", 6, 1);
      table_model.setValueAt ("0", 7, 1);
      table_model.setValueAt ("0", 8, 1);

      // Special cases:
      Font label_font = new Font ("Dialog", Font.BOLD, 12);
      ImageIcon link_icon = new ImageIcon ("link", "www1.gif");
      JLabel url_label = new JLabel (movie.description_, link_icon, JLabel.RIGHT);
      url_label.setFont (label_font);
      url_label.setForeground (Color.blue);
      url_label.addMouseListener (new Clicked_URL (movie.description_));      
      table_model.setValueAt (url_label, 3, 1);

      ImageIcon graph_icon = new ImageIcon ("graph", "graph02.gif");
      JLabel graph_label = new JLabel ("Display server performance", graph_icon, JLabel.RIGHT); 
      graph_label.setFont (label_font);
      graph_label.setForeground (Color.blue);
      graph_label.addMouseListener (new Clicked_Graph (movie.name_, host_name));
      table_model.setValueAt (graph_label, 9, 1);

      movie_table = new JTable (table_model);
      DefaultMutableTreeNode table_node = new DefaultMutableTreeNode (movie_table, false);

      JViewport viewport = new JViewport ();
      viewport.setView (movie_table);
      movie_table.updateUI();
      this.table_scroller_.setViewport (viewport);
      this.selected_movie_ = movie.name_;
      this.selected_server_ = host_name;
    }

  class Clicked_URL extends MouseAdapter
  {
    private String url_;

    public Clicked_URL (String url)
      {
        this.url_ = url;
      }

    public void mouseClicked (MouseEvent e)
      {
        sd_.load_page (this.url_);
      }    
  }

  class Clicked_Graph extends MouseAdapter
  {
    private String movie_, host_;

    public Clicked_Graph (String movie, String host)
      {
        this.movie_ = movie;
        this.host_ = host;
      }

    public void mouseClicked (MouseEvent e)
      {
        sd_.display_performance (this.movie_, this.host_);
      }
  }
}