1 package nl.tudelft.goal.ut2004.visualizer.util;
2
3 import java.rmi.RemoteException;
4 import java.util.ArrayList;
5 import java.util.Collection;
6
7 import nl.tudelft.goal.ut2004.visualizer.connection.EnvironmentService;
8
9 import cz.cuni.amis.pogamut.unreal.bot.IUnrealBot;
10
11 public class SelectableEnvironment {
12
13 private final EnvironmentService environment;
14
15 public SelectableEnvironment(EnvironmentService environment) {
16 this.environment = environment;
17 }
18
19 public EnvironmentService getItem() {
20 return environment;
21 }
22
23
24
25
26
27
28
29
30
31
32
33 private String simplefyID(String id) {
34
35 int index = id.lastIndexOf('/');
36
37 if (index < 0) {
38 index = id.length();
39
40 }
41 return id.substring(0, index);
42 }
43
44 @Override
45 public String toString() {
46 try {
47 return simplefyID(environment.getAgentId().getToken());
48 } catch (RemoteException e) {
49 return "Unconnected Environment";
50 }
51 }
52
53 public static Collection<SelectableEnvironment> fromCollection(
54 Collection<? extends EnvironmentService> environments) {
55
56 Collection<SelectableEnvironment> ret = new ArrayList<SelectableEnvironment>(
57 environments.size());
58
59 for (EnvironmentService env : environments) {
60 ret.add(new SelectableEnvironment(env));
61 }
62
63 return ret;
64 }
65
66 }