summaryrefslogtreecommitdiff
path: root/TAO/examples/Simulator/Sim_Display/Display_Weapons.java
blob: c23e68f15beea2d797f3b4c87f7a1b0568414b40 (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
// $Id$ 

import java.io.*;
import java.net.*;
import java.util.*;
import java.awt.*;

public class Display_Weapons
  extends Panel
  implements Display_Object
{
  private final static String ONLINE = "Online",
    OFFLINE = "Offline";
  private final static Font FONT_BIG = new Font ("Dialog", Font.BOLD, 14),
    FONT_SMALL = new Font ("Dialog", Font.BOLD, 10);
  private final static Color BLUE = new Color (30, 144, 255);

  private int count_ = 0;
  private Hashtable weapons_ = new Hashtable ();
  private GridBagLayout gbl_= new GridBagLayout ();
  private GridBagConstraints gbc_ = new GridBagConstraints ();
  
  public Display_Weapons ()
    {
      Label default_label =
	new Label ("No weapons available", Label.CENTER);

      default_label.setFont (FONT_BIG);
      default_label.setForeground (BLUE);

      setLayout (gbl_);
      gbc_.gridx = 0;
      gbc_.gridy = 0;
      gbc_.gridheight = 1;
      gbc_.gridwidth  = 1;
      gbc_.anchor = GridBagConstraints.NORTH;
      gbc_.fill = GridBagConstraints.NONE;
      setBackground (Color.black);

      gbl_.setConstraints (default_label, gbc_);
      add (default_label);
    }

  public Dimension getPreferredSize ()
    {
      return new Dimension (250, 200);
    }

  public Dimension getMinimumSize ()
    {
      return new Dimension (250, 100);
    }
  
  public int update_display (Display_Push_Consumer display_push_consumer)
    {      
      Weapons weapons = display_push_consumer.get_weapons ();

      for (int i = 0; i < weapons.number_of_weapons && i < 5; i++)
	{
	  String weapon;
	  int status;
	  switch (i)
	    {
	    default:
	    case 0: weapon = weapons.weapon1_identifier;						      
	      status = weapons.weapon1_status;
	      break;
	    case 1: weapon = weapons.weapon2_identifier;						      
	      status = weapons.weapon2_status;
	      break;
	    case 2: weapon = weapons.weapon3_identifier;						      
	      status = weapons.weapon3_status;
	      break;
	    case 3: weapon = weapons.weapon4_identifier;						      
	      status = weapons.weapon4_status;
	      break;
	    case 4: weapon = weapons.weapon5_identifier;						      
	      status = weapons.weapon5_status;
	      break;
	    }


	  Label status_label = (Label)weapons_.get (weapon);

	  if (status_label != null)
	    status_label.setText ((status == 1) ? ONLINE : OFFLINE);
	  else
	    {
	      if (count_ == 0)
		removeAll ();

	      count_++;
	      Label weapon_label =
		new Label (count_ + ". " + weapon, Label.LEFT);
	      status_label =
		new Label ((status == 1) ? ONLINE : OFFLINE, Label.RIGHT);

	      status_label.setFont (FONT_SMALL);
	      weapon_label.setFont (FONT_SMALL);
	      weapon_label.setForeground (BLUE);
	      
	      gbc_.gridx = 0;
	      gbc_.anchor = GridBagConstraints.WEST;
	      gbl_.setConstraints (weapon_label, gbc_);
	      add (weapon_label);
	      gbc_.gridx = 1;
	      gbc_.anchor = GridBagConstraints.EAST;
	      gbl_.setConstraints (status_label, gbc_);
	      add (status_label);
	      
	      gbc_.gridy++;
	      weapons_.put (weapon, status_label);
	    }

	  status_label.setForeground ((status == 1) ?
				      Color.lightGray :
				      Color.darkGray);
	}

      validate ();
      return 0;
    }
}