View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.visualizer.util;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  import javax.swing.JList;
23  
24  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
25  import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
26  
27  /**
28   * Wrapper around {@link NavPoint} to make it more human readable in {@link JList}.
29   * 
30   * @author Lennard de Rijk
31   * 
32   */
33  public class SelectableWayPoint {
34  
35  	/**
36  	 * The {@link NavPoint} wrapped in this object.
37  	 */
38  	private final Waypoint navPoint;
39  
40  	/**
41  	 * 
42  	 * @param navPoint
43  	 *            The {@link NavPoint} to wrap in this object.
44  	 */
45  	public SelectableWayPoint(Waypoint navPoint) {
46  		this.navPoint = navPoint;
47  
48  	}
49  
50  	/**
51  	 * @return the navPoint wrapped in this class.
52  	 */
53  	public Waypoint getWaypoint() {
54  		return navPoint;
55  	}
56  
57  	/**
58  	 * Represents a {@link NavPoint} in a human readable form.
59  	 */
60  	@Override
61  	public String toString() {
62  		String ret = navPoint.getID();
63  
64  		return ret;
65  	}
66  
67  	/**
68  	 * Transforms a {@link Collection} of {@link NavPoint} into an Array of {@link SelectableWayPoint}.
69  	 * 
70  	 * @param navCollection
71  	 *            The {@link Collection} of {@link NavPoint} to transform
72  	 * @return An Array of {@link SelectableWayPoint}
73  	 */
74  	public static Collection<SelectableWayPoint> getFromWaypointCollection(
75  			Collection<Waypoint> navCollection) {
76  		Collection<SelectableWayPoint> selectablePoints = new ArrayList<SelectableWayPoint>(navCollection.size());
77  
78  		for (Waypoint navPoint : navCollection) {
79  			selectablePoints.add(new SelectableWayPoint(navPoint));
80  		}
81  
82  		return selectablePoints;
83  	}
84  
85  }