View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarcommands;
2   
3   import java.util.*;
4   import cz.cuni.amis.pogamut.base.communication.messages.*;
5   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
6   
7   /**
8    *
9    * This command is used to send a command to a camera.
10   *
11   *
12   *
13   * Corresponding GameBots command is SET.
14   *
15   */
16  public class SetCamera extends CommandMessage
17  {
18      //constructor for the camera
19      public SetCamera(String Type, String Name, Double FOV)
20      {
21          this.Type = Type;
22          this.NamesFovs.put(Name, FOV);
23      }
24  
25      //also constructor for the camera
26      public SetCamera(String Type, String[] Names, Double[] FOVs)
27      {
28          this.Type = Type;
29          if(Names.length == FOVs.length)
30          {
31              for(int i = 0; i < Names.length; i++)
32              {
33                  this.NamesFovs.put(Names[i], FOVs[i]);
34              }
35          }
36      }
37  
38      /**
39       * <p></p>WARNING: this is empty-command constructor, you have to use
40       * Setters to fill it up!
41       */
42      public SetCamera()
43      {
44      }
45      /////// Properties BEGIN
46      /*
47       * NOTE: There is a difference between moving and controlling a camera.
48       * Moving a camera (i.e. pan/tilt) is achieved by controlling the mission
49       * package that the camera is attached to. Controlling a camera is used to
50       * set its field of view.
51       */
52      protected String Type = "Camera";
53  
54      public String getType()
55      {
56          return Type;
57      }
58      Map<String, Double> NamesFovs = new HashMap<String, Double>();
59  
60      public Map<String, Double> getNamesFovs()
61      {
62          return NamesFovs;
63      }
64  
65      public SetCamera setNamesFovs(Map<String, Double> NamesFovs)
66      {
67          this.NamesFovs = NamesFovs;
68          return this;
69      }
70  
71      public SetCamera addNameFOV(String Name, Double FOV)
72      {
73          this.NamesFovs.put(Name, FOV);
74          return this;
75      }
76  
77      /*
78       * Example: SET {Type Camera} {Name Camera} {FOV 1} will set the field of
79       * view of camera “Camera” to 1 radian. SET {Type Camera} {Name Camera} {FOV
80       * 0} will set the field of view of camera “Camera” to its default field of
81       * view.
82       */
83      /////// Properties END
84      /////// Extra Java code BEGIN
85      /////// Additional code from xslt BEGIN
86      /////// Additional code from xslt END
87      /////// Extra Java from XML BEGIN
88      /////// Extra Java from XML END
89      /////// Extra Java code END
90      /**
91       * Cloning constructor.
92       */
93      public SetCamera(SetCamera original)
94      {
95          this.NamesFovs.putAll(original.NamesFovs);
96      }
97  
98      @Override
99      public String toString()
100     {
101         return toMessage();
102     }
103 
104     public String toHtmlString()
105     {
106         StringBuilder buf = new StringBuilder();
107         buf.append(super.toString());
108 
109         buf.append("<b>Type</b> : ").append(String.valueOf(Type)).append(" <br/> ");
110 
111         if(!NamesFovs.isEmpty())
112         {
113 
114             Iterator it = NamesFovs.entrySet().iterator();
115             while(it.hasNext())
116             {
117                 Map.Entry en = (Map.Entry) it.next();
118                 buf.append("<b>Name</b> : ").append(en.getKey()).append("</br> <b>FOV</b> : ").append(en.getValue()).append("}");
119             }
120         }
121 
122 
123         return buf.toString();
124 
125     }
126 
127     public String toMessage()
128     {
129         StringBuilder buf = new StringBuilder();
130         buf.append("SET");
131 
132         if(Type != null)
133         {
134             buf.append(" {Type ").append(Type).append("}");
135         }
136 
137         if(!NamesFovs.isEmpty())
138         {
139 
140             Iterator it = NamesFovs.entrySet().iterator();
141             while(it.hasNext())
142             {
143                 Map.Entry en = (Map.Entry) it.next();
144                 buf.append(" {Name ").append(en.getKey()).append("} {FOV ").append(en.getValue()).append("}");
145             }
146         }
147 
148         return buf.toString();
149     }
150 }