Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/incenter/ngbclient/Scope.java


1   package org.incenter.ngbclient;
2   import org.incenter.ngbclient.*;
3   // Scope.java
4   
5   /*
6      This is a scope object.  It will set the scope variables based
7      on a scope string from the server
8   */
9   
10  import java.awt.*;
11  import java.lang.*;
12  import java.util.*;
13  
14  public class Scope
15  {
16      private String star, planet, scopeStr;
17      private Integer ship, level, actionPoints;
18      private int status;
19      public static final int OK = 0;
20      public static final int ERROR = 1;
21      public static final int LEVEL_UNIVERSE = 0;
22      public static final int LEVEL_STAR = 1;
23      public static final int LEVEL_PLANET = 2;
24      public static final int LEVEL_SHIP = 3;
25      public static final int LEVEL_UNSET = 4;
26  
27      public static boolean isScope(String scope) {
28    if(scope.startsWith(" ( ["))
29        return true;
30    else
31        return false;
32      }
33  
34      public Scope() {
35    star = planet = null;
36    ship = null;
37    level = new Integer(LEVEL_UNSET);
38      }
39  
40      public Scope(String scope) {
41    setScope(scope);
42      }
43  
44      public void setScope(String scope) {
45    scopeStr = scope;
46    if(!parseScope()) {
47        status = ERROR;
48        return;
49    } 
50  
51    star = getStar();
52    planet = getPlanet();
53    ship = getShip();
54    level = getLevel();
55      }
56  
57      public String getStar() {
58    return star;
59      }
60  
61      public String getPlanet() {
62    return planet;
63      }
64  
65      public Integer getShip() {
66    return ship;
67      }
68  
69      public Integer getLevel() {
70    return level;
71      }
72  
73      public int getAPs() {
74    return actionPoints.intValue();
75      }
76  
77      private boolean parseScope() {
78    StringTokenizer strtok;
79    String buf;
80    int numtoks, i;
81    
82    if(scopeStr == null) return false;
83    if(!scopeStr.startsWith(" ( [")) return false;
84    
85    strtok = new StringTokenizer(scopeStr, "() /[]");
86    numtoks = strtok.countTokens();
87  
88    switch(numtoks) {
89    case 1:
90        actionPoints = new Integer(strtok.nextToken());
91        level = new Integer(LEVEL_UNIVERSE);
92        break;
93    case 2:
94        // aps, star or ship
95        actionPoints = new Integer(strtok.nextToken());
96        buf = strtok.nextToken();
97        ship = getShipNo(buf);
98        if(ship == null) {
99      star = new String(buf);
100     level = new Integer(LEVEL_STAR);
101       } else {
102     level = new Integer(LEVEL_SHIP);
103       }
104       break;
105   case 3:
106       // aps, star, planet or ship
107       actionPoints = new Integer(strtok.nextToken());
108       star = new String(strtok.nextToken());
109       buf = strtok.nextToken();
110       ship = getShipNo(buf);
111       if(ship == null) {
112     planet = new String(buf);
113     level = new Integer(LEVEL_PLANET);
114       } else {
115     level = new Integer(LEVEL_SHIP);
116       }
117       break;
118   case 4:
119       // ship scope at star/planet
120       actionPoints = new Integer(strtok.nextToken());
121       star = new String(strtok.nextToken());
122       planet = new String(strtok.nextToken());
123       ship = getShipNo(strtok.nextToken());
124       if(ship == null) return false;
125       level = new Integer(LEVEL_SHIP);
126       break;
127   }
128   return true;
129     }
130 
131     private Integer getShipNo(String tok) {
132   if(!tok.startsWith("#")) return null;
133 
134   return new Integer(tok.substring(1));
135     }
136 }
137 
138 
139