Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Simulator / DOVEBrowser / WeaponsVisComp.java
blob83d30feb6732e8e02d4c32e6568e615bad388920
1 //
2 // = FILENAME
3 // WeaponsVisComp.java
4 //
5 // = AUTHOR
6 // Seth Widoff (core functionality)
7 // Michael Kircher (mk1@cs.wustl.edu)
8 //
9 // = DESCRIPTION
10 // This is a Visualization Component for displaying weapons.
12 // ============================================================================
15 import java.io.*;
16 import java.util.*;
17 import java.awt.*;
20 public class WeaponsVisComp extends Panel implements VisComp
22 private final static String ONLINE = "Online";
23 private final static String OFFLINE = "Offline";
24 private final static Font FONT_BIG = new Font ("Dialog", Font.BOLD, 14);
25 private final static Font FONT_SMALL = new Font ("Dialog", Font.BOLD, 10);
26 private final static Color BLUE = new Color (30, 144, 255);
28 private int count_ = 0;
29 private Hashtable weapons_table_ = new Hashtable ();
30 private GridBagLayout gbl_= new GridBagLayout ();
31 private GridBagConstraints gbc_ = new GridBagConstraints ();
33 Label default_label_ = new Label ("No weapons available", Label.CENTER);
35 public WeaponsVisComp ()
37 default_label_.setFont (FONT_BIG);
38 default_label_.setForeground (BLUE);
40 setLayout (gbl_);
41 gbc_.gridx = 0;
42 gbc_.gridy = 0;
43 gbc_.gridheight = 1;
44 gbc_.gridwidth = 1;
45 gbc_.anchor = GridBagConstraints.NORTH;
46 gbc_.fill = GridBagConstraints.NONE;
47 setBackground (Color.black);
49 gbl_.setConstraints (default_label_, gbc_);
50 add (default_label_);
53 public void setName (String title) {
56 public int getProperty () {
57 return Properties.WEAPONS;
60 public Dimension getPreferredSize () {
61 return new Dimension (250, 200);
64 public Dimension getMinimumSize () {
65 return new Dimension (80, 80);
68 public void update (java.util.Observable observable, java.lang.Object obj) {
69 Weapons weapons_ = null;
70 try {
71 weapons_ = (Weapons) obj;
73 catch (Exception excp) {
74 System.out.println (excp);
75 System.out.println ("Visualization Component received wrong data type!");
77 if (weapons_ != null)
79 for (int i = 0; i < weapons_.number_of_weapons && i < 5; i++)
81 String weapon = "";
82 int status = 0;
83 switch (i)
85 default:
86 break;
87 case 0: weapon = weapons_.weapon1_identifier;
88 status = weapons_.weapon1_status;
89 break;
90 case 1: weapon = weapons_.weapon2_identifier;
91 status = weapons_.weapon2_status;
92 break;
93 case 2: weapon = weapons_.weapon3_identifier;
94 status = weapons_.weapon3_status;
95 break;
96 case 3: weapon = weapons_.weapon4_identifier;
97 status = weapons_.weapon4_status;
98 break;
99 case 4: weapon = weapons_.weapon5_identifier;
100 status = weapons_.weapon5_status;
101 break;
105 Label status_label_ = (Label)weapons_table_.get (weapon);
107 if (status_label_ != null)
108 status_label_.setText ((status == 1) ? ONLINE : OFFLINE);
109 else
111 if (count_ == 0)
112 this.removeAll ();
114 count_++;
115 Label weapon_label_ = new Label (count_ + ". " + weapon, Label.LEFT);
116 status_label_ = new Label ((status == 1) ? ONLINE : OFFLINE, Label.RIGHT);
118 status_label_.setFont (FONT_SMALL);
119 weapon_label_.setFont (FONT_SMALL);
120 weapon_label_.setForeground (BLUE);
122 gbc_.gridx = 0;
123 gbc_.anchor = GridBagConstraints.WEST;
124 gbl_.setConstraints (weapon_label_, gbc_);
125 add (weapon_label_);
126 gbc_.gridx = 1;
127 gbc_.anchor = GridBagConstraints.EAST;
128 gbl_.setConstraints (status_label_, gbc_);
129 add (status_label_);
131 gbc_.gridy++;
132 weapons_table_.put (weapon, status_label_);
135 status_label_.setForeground ((status == 1) ?
136 Color.lightGray :
137 Color.darkGray);
140 validate ();