use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.
the class ManageLocationsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (f == null || !f.isVisible()) {
// Handle the Listener
listenerLoc = VSDecoderManager.instance().getVSDecoderPreferences().getListenerPosition();
// Handle Reporters
ReporterManager rmgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
String[] reporterNameArray = rmgr.getSystemNameArray();
Object[][] reporterTable = new Object[reporterNameArray.length][6];
reporterMap = new HashMap<String, PhysicalLocation>();
int i = 0;
for (String s : reporterNameArray) {
Reporter r = rmgr.getByDisplayName(s);
if (r instanceof PhysicalLocationReporter) {
reporterMap.put(s, ((PhysicalLocationReporter) r).getPhysicalLocation());
PhysicalLocation p = ((PhysicalLocationReporter) r).getPhysicalLocation();
reporterTable[i][0] = s;
reporterTable[i][1] = true;
reporterTable[i][2] = p.getX();
reporterTable[i][3] = p.getY();
reporterTable[i][4] = p.getZ();
reporterTable[i][5] = p.isTunnel();
} else {
reporterTable[i][0] = s;
reporterTable[i][1] = false;
reporterTable[i][2] = Float.valueOf(0.0f);
reporterTable[i][3] = Float.valueOf(0.0f);
reporterTable[i][4] = Float.valueOf(0.0f);
reporterTable[i][5] = false;
}
i++;
}
// Handle Blocks
BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
String[] blockNameArray = bmgr.getSystemNameArray();
Object[][] blockTable = new Object[blockNameArray.length][6];
blockMap = new HashMap<String, PhysicalLocation>();
i = 0;
for (String s : blockNameArray) {
Block b = bmgr.getByDisplayName(s);
// NOTE: Unlike Reporters, all Blocks are (now) PhysicalLocationReporters, so no need to do a check here.
// We'll keep the explicit cast for now, but it's not actually necessary.
blockMap.put(s, ((PhysicalLocationReporter) b).getPhysicalLocation());
PhysicalLocation p = ((PhysicalLocationReporter) b).getPhysicalLocation();
blockTable[i][0] = s;
blockTable[i][1] = true;
blockTable[i][2] = p.getX();
blockTable[i][3] = p.getY();
blockTable[i][4] = p.getZ();
blockTable[i][5] = p.isTunnel();
i++;
}
// Handle Ops Locations
LocationManager lmgr = LocationManager.instance();
List<Location> locations = lmgr.getLocationsByIdList();
opsMap = new HashMap<String, PhysicalLocation>();
log.debug("TableSize : " + locations.size());
Object[][] opsTable = new Object[locations.size()][6];
i = 0;
for (Location l : locations) {
if (log.isDebugEnabled()) {
log.debug("i = " + i + "MLA " + l.getId() + " Name: " + l.getName() + " table " + java.util.Arrays.toString(opsTable[i]));
}
PhysicalLocation p = l.getPhysicalLocation();
Boolean use = false;
if (p == PhysicalLocation.Origin) {
use = false;
} else {
use = true;
}
opsTable[i][0] = l.getName();
opsTable[i][1] = use;
opsTable[i][2] = p.getX();
opsTable[i][3] = p.getY();
opsTable[i][4] = p.getZ();
opsTable[i][5] = p.isTunnel();
opsMap.put(l.getName(), l.getPhysicalLocation());
i++;
}
f = new ManageLocationsFrame(listenerLoc, reporterTable, opsTable, blockTable);
}
f.setExtendedState(Frame.NORMAL);
}
use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.
the class OperationsRoutesGuiTest method testRouteEditFrame.
@Test
public void testRouteEditFrame() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
RouteEditFrame f = new RouteEditFrame();
f.setTitle("Test Add Route Frame");
f.initComponents(null);
f.routeNameTextField.setText("New Test Route");
f.commentTextField.setText("New Text Route Comment");
enterClickAndLeave(f.addRouteButton);
loadRoutes();
RouteManager rManager = RouteManager.instance();
Assert.assertEquals("should be 6 routes", 6, rManager.getRoutesByNameList().size());
Route newRoute = rManager.getRouteByName("New Test Route");
Assert.assertNotNull(newRoute);
Assert.assertEquals("route comment", "New Text Route Comment", newRoute.getComment());
// Add some locations to the route
loadLocations();
LocationManager lManager = LocationManager.instance();
f.locationBox.setSelectedItem(lManager.getLocationByName("Test Loc B"));
//f.addLocationButton.doClick();
enterClickAndLeave(f.addLocationButton);
f.locationBox.setSelectedItem(lManager.getLocationByName("Test Loc D"));
//f.addLocationButton.doClick();
enterClickAndLeave(f.addLocationButton);
f.locationBox.setSelectedItem(lManager.getLocationByName("Test Loc A"));
//f.addLocationButton.doClick();
enterClickAndLeave(f.addLocationButton);
// put the next two locations at the start of the route
//f.addLocAtTop.doClick();
enterClickAndLeave(f.addLocAtTop);
f.locationBox.setSelectedItem(lManager.getLocationByName("Test Loc C"));
//f.addLocationButton.doClick();
enterClickAndLeave(f.addLocationButton);
f.locationBox.setSelectedItem(lManager.getLocationByName("Test Loc E"));
//f.addLocationButton.doClick();
enterClickAndLeave(f.addLocationButton);
// confirm that the route sequence is correct
List<RouteLocation> routeLocations = newRoute.getLocationsBySequenceList();
Assert.assertEquals("1st location", "Test Loc E", routeLocations.get(0).getName());
Assert.assertEquals("2nd location", "Test Loc C", routeLocations.get(1).getName());
Assert.assertEquals("3rd location", "Test Loc B", routeLocations.get(2).getName());
Assert.assertEquals("4th location", "Test Loc D", routeLocations.get(3).getName());
Assert.assertEquals("5th location", "Test Loc A", routeLocations.get(4).getName());
f.routeNameTextField.setText("Newer Test Route");
//f.saveRouteButton.doClick();
enterClickAndLeave(f.saveRouteButton);
Assert.assertEquals("changed route name", "Newer Test Route", newRoute.getName());
// test delete button
//f.deleteRouteButton.doClick();
enterClickAndLeave(f.deleteRouteButton);
// click "Yes" in the confirm popup
pressDialogButton(f, Bundle.getMessage("DeleteRoute?"), "Yes");
Assert.assertEquals("should be 5 routes", 5, rManager.getRoutesByNameList().size());
f.dispose();
}
use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.
the class OperationsRoutesTest method testXMLCreate.
/**
* Test route Xml create, read, and backup support. Originally written as
* three separate tests, now combined into one as of 8/29/2013
*
* @throws JDOMException
* @throws IOException
*/
public void testXMLCreate() throws JDOMException, IOException {
RouteManager manager = RouteManager.instance();
List<Route> temprouteList = manager.getRoutesByIdList();
Assert.assertEquals("Starting Number of Routes", 0, temprouteList.size());
Route r1 = manager.newRoute("Test Number 1");
Route r2 = manager.newRoute("Test Number 2");
Route r3 = manager.newRoute("Test Number 3");
temprouteList = manager.getRoutesByIdList();
Assert.assertEquals("New Number of Routes", 3, temprouteList.size());
RouteManagerXml.instance().writeOperationsFile();
// Add some more routes and write file again
// so we can test the backup facility
Route r4 = manager.newRoute("Test Number 4");
Route r5 = manager.newRoute("Test Number 5");
Route r6 = manager.newRoute("Test Number 6");
Assert.assertNotNull("route r1 exists", r1);
Assert.assertNotNull("route r2 exists", r2);
Assert.assertNotNull("route r3 exists", r3);
Assert.assertNotNull("route r4 exists", r4);
Assert.assertNotNull("route r5 exists", r5);
Assert.assertNotNull("route r6 exists", r6);
LocationManager lmanager = LocationManager.instance();
Location Acton = lmanager.newLocation("Acton");
Location Bedford = lmanager.newLocation("Bedford");
Location Chelmsford = lmanager.newLocation("Chelmsford");
r1.setComment("r1 comment");
RouteLocation r1l1 = r1.addLocation(Acton);
r1.addLocation(Bedford);
r1.addLocation(Chelmsford);
r1.addLocation(Bedford);
r1.addLocation(Acton);
r1l1.setDropAllowed(false);
r1l1.setPickUpAllowed(false);
// this value isn't saved
r1l1.setCarMoves(3);
r1l1.setComment("rl1 comment");
r1l1.setGrade(Double.valueOf("5"));
r1l1.setMaxCarMoves(8);
r1l1.setMaxTrainLength(345);
r1l1.setTrainDirection(Location.SOUTH);
r1l1.setTrainIconX(56);
r1l1.setTrainIconY(78);
// this value isn't saved
r1l1.setTrainLength(234);
// this value isn't saved
r1l1.setTrainWeight(987);
r2.setComment("r2 comment");
r2.addLocation(Chelmsford);
RouteLocation r2l2 = r2.addLocation(Bedford);
r2.addLocation(Chelmsford);
RouteLocation r2l4 = r2.addLocation(Bedford);
r2l2.setDropAllowed(false);
r2l2.setPickUpAllowed(true);
// this value isn't saved
r2l2.setCarMoves(3);
r2l2.setComment("r2l2 comment");
r2l2.setGrade(Double.valueOf("1"));
r2l2.setMaxCarMoves(181);
r2l2.setMaxTrainLength(4561);
r2l2.setTrainDirection(Location.EAST);
r2l2.setTrainIconX(651);
r2l2.setTrainIconY(871);
// this value isn't saved
r2l2.setTrainLength(234);
// this value isn't saved
r2l2.setTrainWeight(987);
r2l4.setDropAllowed(true);
r2l4.setPickUpAllowed(false);
// this value isn't saved
r2l4.setCarMoves(3);
r2l4.setComment("r2l4 comment");
r2l4.setGrade(Double.valueOf("2"));
r2l4.setMaxCarMoves(18);
r2l4.setMaxTrainLength(456);
r2l4.setTrainDirection(Location.NORTH);
r2l4.setTrainIconX(65);
r2l4.setTrainIconY(87);
// this value isn't saved
r2l4.setTrainLength(234);
// this value isn't saved
r2l4.setTrainWeight(987);
r3.setComment("r3 comment");
r4.setComment("r4 comment");
r5.setComment("r5 comment");
r6.setComment("r6 comment");
RouteManagerXml.instance().writeOperationsFile();
// now perform read operation
manager.dispose();
manager = RouteManager.instance();
temprouteList = manager.getRoutesByIdList();
Assert.assertEquals("Starting Number of Routes", 0, temprouteList.size());
RouteManagerXml.instance().readFile(RouteManagerXml.instance().getDefaultOperationsFilename());
temprouteList = manager.getRoutesByIdList();
Assert.assertEquals("Number of Routes", 6, temprouteList.size());
r1 = manager.getRouteByName("Test Number 1");
r2 = manager.getRouteByName("Test Number 2");
r3 = manager.getRouteByName("Test Number 3");
r4 = manager.getRouteByName("Test Number 4");
r5 = manager.getRouteByName("Test Number 5");
r6 = manager.getRouteByName("Test Number 6");
Assert.assertNotNull("route r1 exists", r1);
Assert.assertNotNull("route r2 exists", r2);
Assert.assertNotNull("route r3 exists", r3);
Assert.assertNotNull("route r4 exists", r4);
Assert.assertNotNull("route r5 exists", r5);
Assert.assertNotNull("route r6 exists", r6);
Assert.assertEquals("r1 comment", "r1 comment", r1.getComment());
List<RouteLocation> locs = r1.getLocationsBySequenceList();
Assert.assertEquals("number of locations in route r1", 5, locs.size());
RouteLocation rl1 = locs.get(0);
Assert.assertEquals("rl1 can drop", false, rl1.isDropAllowed());
Assert.assertEquals("rl1 can pickup", false, rl1.isPickUpAllowed());
// default
Assert.assertEquals("rl1 car moves", 0, rl1.getCarMoves());
Assert.assertEquals("rl1 comment", "rl1 comment", rl1.getComment());
Assert.assertEquals("rl1 grade", "5.0", Double.toString(rl1.getGrade()));
Assert.assertEquals("rl1 max car moves", 8, rl1.getMaxCarMoves());
Assert.assertEquals("rl1 max train length", 345, rl1.getMaxTrainLength());
Assert.assertEquals("rl1 train direction", Location.SOUTH, rl1.getTrainDirection());
Assert.assertEquals("rl1 IconX", 56, rl1.getTrainIconX());
Assert.assertEquals("rl1 IconY", 78, rl1.getTrainIconY());
// default
Assert.assertEquals("rl1 train length", 0, rl1.getTrainLength());
// default
Assert.assertEquals("rl1 train weight", 0, rl1.getTrainWeight());
Assert.assertEquals("r2 comment", "r2 comment", r2.getComment());
locs = r2.getLocationsBySequenceList();
Assert.assertEquals("number of locations in route r2", 4, locs.size());
RouteLocation rl2 = locs.get(1);
Assert.assertEquals("rl2 can drop", false, rl2.isDropAllowed());
Assert.assertEquals("rl2 can pickup", true, rl2.isPickUpAllowed());
// default
Assert.assertEquals("rl2 car moves", 0, rl2.getCarMoves());
Assert.assertEquals("rl2 comment", "r2l2 comment", rl2.getComment());
Assert.assertEquals("rl2 grade", "1.0", Double.toString(rl2.getGrade()));
Assert.assertEquals("rl2 max car moves", 181, rl2.getMaxCarMoves());
Assert.assertEquals("rl2 max train length", 4561, rl2.getMaxTrainLength());
Assert.assertEquals("rl2 train direction", Location.EAST, rl2.getTrainDirection());
Assert.assertEquals("rl2 IconX", 651, rl2.getTrainIconX());
Assert.assertEquals("rl2 IconY", 871, rl2.getTrainIconY());
// default
Assert.assertEquals("rl2 train length", 0, rl2.getTrainLength());
// default
Assert.assertEquals("rl2 train weight", 0, rl2.getTrainWeight());
RouteLocation rl4 = locs.get(3);
Assert.assertEquals("rl4 can drop", true, rl4.isDropAllowed());
Assert.assertEquals("rl4 can pickup", false, rl4.isPickUpAllowed());
// default
Assert.assertEquals("rl4 car moves", 0, rl4.getCarMoves());
Assert.assertEquals("rl4 comment", "r2l4 comment", rl4.getComment());
Assert.assertEquals("rl4 grade", "2.0", Double.toString(rl4.getGrade()));
Assert.assertEquals("rl4 max car moves", 18, rl4.getMaxCarMoves());
Assert.assertEquals("rl4 max train length", 456, rl4.getMaxTrainLength());
Assert.assertEquals("rl4 train direction", Location.NORTH, rl4.getTrainDirection());
Assert.assertEquals("rl4 IconX", 65, rl4.getTrainIconX());
Assert.assertEquals("rl4 IconY", 87, rl4.getTrainIconY());
// default
Assert.assertEquals("rl4 train length", 0, rl4.getTrainLength());
// default
Assert.assertEquals("rl4 train weight", 0, rl4.getTrainWeight());
Assert.assertEquals("r3 comment", "r3 comment", r3.getComment());
Assert.assertEquals("r4 comment", "r4 comment", r4.getComment());
Assert.assertEquals("r5 comment", "r5 comment", r5.getComment());
Assert.assertEquals("r6 comment", "r6 comment", r6.getComment());
// now test backup file
manager.dispose();
// change default file name to backup
RouteManagerXml.instance().setOperationsFileName("OperationsJUnitTestRouteRoster.xml.bak");
manager = RouteManager.instance();
temprouteList = manager.getRoutesByIdList();
Assert.assertEquals("Starting Number of Routes", 0, temprouteList.size());
RouteManagerXml.instance().readFile(RouteManagerXml.instance().getDefaultOperationsFilename());
temprouteList = manager.getRoutesByIdList();
Assert.assertEquals("Number of Routes", 3, temprouteList.size());
r1 = manager.getRouteByName("Test Number 1");
r2 = manager.getRouteByName("Test Number 2");
r3 = manager.getRouteByName("Test Number 3");
r4 = manager.getRouteByName("Test Number 4");
r5 = manager.getRouteByName("Test Number 5");
r6 = manager.getRouteByName("Test Number 6");
Assert.assertNotNull("route r1 exists", r1);
Assert.assertNotNull("route r2 exists", r2);
Assert.assertNotNull("route r3 exists", r3);
Assert.assertNull("route r4 exists", r4);
Assert.assertNull("route r5 exists", r5);
Assert.assertNull("route r6 exists", r6);
}
use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.
the class CarsTableFrameTest method testCarsTableFrame.
@Test
public void testCarsTableFrame() throws Exception {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// remove previous cars
CarManager.instance().dispose();
CarRoads.instance().dispose();
// add Owner1 and Owner2
CarOwners co = CarOwners.instance();
co.addName("Owner1");
co.addName("Owner2");
// add road names
CarRoads cr = CarRoads.instance();
cr.addName("NH");
cr.addName("UP");
cr.addName("AA");
cr.addName("SP");
// add locations
LocationManager lManager = LocationManager.instance();
Location westford = lManager.newLocation("Newer Westford");
Track westfordYard = westford.addTrack("Yard", Track.YARD);
westfordYard.setLength(300);
Track westfordSiding = westford.addTrack("Siding", Track.SPUR);
westfordSiding.setLength(300);
Track westfordAble = westford.addTrack("Able", Track.SPUR);
westfordAble.setLength(300);
Location boxford = lManager.newLocation("Newer Boxford");
Track boxfordYard = boxford.addTrack("Yard", Track.YARD);
boxfordYard.setLength(300);
Track boxfordJacobson = boxford.addTrack("Jacobson", Track.SPUR);
boxfordJacobson.setLength(300);
Track boxfordHood = boxford.addTrack("Hood", Track.SPUR);
boxfordHood.setLength(300);
// enable rfid field
Setup.setRfidEnabled(true);
CarsTableFrame ctf = new CarsTableFrame(true, null, null);
// show all cars?
Assert.assertTrue("show all cars", ctf.showAllCars);
// table should be empty
Assert.assertEquals("number of cars", "0", ctf.numCars.getText());
CarManager cManager = CarManager.instance();
// confirm no cars
Assert.assertEquals("number of cars", 0, cManager.getNumEntries());
// add 5 cars to table
loadCars();
Car c1 = cManager.getByRoadAndNumber("NH", "1");
Assert.assertNotNull(c1);
Assert.assertEquals("c1 location", Track.OKAY, c1.setLocation(westford, westfordYard));
Assert.assertEquals("c1 destination", Track.OKAY, c1.setDestination(boxford, boxfordJacobson));
Car c2 = cManager.getByRoadAndNumber("UP", "22");
Assert.assertNotNull(c2);
Car c3 = cManager.getByRoadAndNumber("AA", "3");
Assert.assertNotNull(c3);
Assert.assertEquals("c3 location", Track.OKAY, c3.setLocation(boxford, boxfordHood));
Assert.assertEquals("c3 destination", Track.OKAY, c3.setDestination(boxford, boxfordYard));
Car c4 = cManager.getByRoadAndNumber("SP", "2");
Assert.assertNotNull(c4);
Assert.assertEquals("c4 location", Track.OKAY, c4.setLocation(westford, westfordSiding));
Assert.assertEquals("c4 destination", Track.OKAY, c4.setDestination(boxford, boxfordHood));
Car c5 = cManager.getByRoadAndNumber("NH", "5");
Assert.assertEquals("c5 location", Track.OKAY, c5.setLocation(westford, westfordAble));
Assert.assertEquals("c5 destination", Track.OKAY, c5.setDestination(westford, westfordAble));
Assert.assertEquals("number of cars", "5", ctf.numCars.getText());
// default is sort by number
List<RollingStock> cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by number list", c1.getId(), cars.get(0).getId());
Assert.assertEquals("2nd car in sort by number list", c4.getId(), cars.get(1).getId());
Assert.assertEquals("3rd car in sort by number list", c3.getId(), cars.get(2).getId());
Assert.assertEquals("4th car in sort by number list", c5.getId(), cars.get(3).getId());
Assert.assertEquals("5th car in sort by number list", c2.getId(), cars.get(4).getId());
// now sort by built date
enterClickAndLeave(ctf.sortByBuilt);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by built list", c5, cars.get(0));
Assert.assertEquals("2nd car in sort by built list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by built list", c2, cars.get(2));
Assert.assertEquals("4th car in sort by built list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by built list", c1, cars.get(4));
// now sort by color
enterClickAndLeave(ctf.sortByColor);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by color list", c4.getId(), cars.get(0).getId());
Assert.assertEquals("2nd car in sort by color list", c2.getId(), cars.get(1).getId());
Assert.assertEquals("3rd car in sort by color list", c5.getId(), cars.get(2).getId());
Assert.assertEquals("4th car in sort by color list", c1.getId(), cars.get(3).getId());
Assert.assertEquals("5th car in sort by color list", c3.getId(), cars.get(4).getId());
enterClickAndLeave(ctf.sortByDestination);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by destination list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by destination list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by destination list", c1, cars.get(2));
Assert.assertEquals("4th car in sort by destination list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by destination list", c5, cars.get(4));
enterClickAndLeave(ctf.sortByKernel);
//TODO add kernels
// now sort by load
enterClickAndLeave(ctf.sortByLoad);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by load list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by load list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by load list", c1, cars.get(2));
Assert.assertEquals("4th car in sort by load list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by load list", c5, cars.get(4));
// now sort by location
enterClickAndLeave(ctf.sortByLocation);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by location list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by location list", c3, cars.get(1));
Assert.assertEquals("3rd car in sort by location list", c5, cars.get(2));
Assert.assertEquals("4th car in sort by location list", c4, cars.get(3));
Assert.assertEquals("5th car in sort by location list", c1, cars.get(4));
// now sort by moves
enterClickAndLeave(ctf.sortByMoves);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by move list", c5, cars.get(0));
Assert.assertEquals("2nd car in sort by move list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by move list", c3, cars.get(2));
Assert.assertEquals("4th car in sort by move list", c2, cars.get(3));
Assert.assertEquals("5th car in sort by move list", c1, cars.get(4));
// test sort by number again
enterClickAndLeave(ctf.sortByNumber);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by number list 2", c1, cars.get(0));
Assert.assertEquals("2nd car in sort by number list 2", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by number list 2", c3, cars.get(2));
Assert.assertEquals("4th car in sort by number list 2", c5, cars.get(3));
Assert.assertEquals("5th car in sort by number list 2", c2, cars.get(4));
// test sort by owner
//enterClickAndLeave(ctf.sortByOwner);
ctf.sortByOwner.doClick();
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by owner list", c4, cars.get(0));
Assert.assertEquals("2nd car in sort by owner list", c3, cars.get(1));
Assert.assertEquals("3rd car in sort by owner list", c2, cars.get(2));
Assert.assertEquals("4th car in sort by owner list", c5, cars.get(3));
Assert.assertEquals("5th car in sort by owner list", c1, cars.get(4));
// test sort by rfid
//enterClickAndLeave(ctf.sortByRfid);
// use doClick() in case the radio button isn't visible due to scrollbars
ctf.sortByRfid.doClick();
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by rfid list", c5, cars.get(0));
Assert.assertEquals("2nd car in sort by rfid list", c2, cars.get(1));
Assert.assertEquals("3rd car in sort by rfid list", c1, cars.get(2));
Assert.assertEquals("4th car in sort by rfid list", c4, cars.get(3));
Assert.assertEquals("5th car in sort by rfid list", c3, cars.get(4));
// test sort by road
enterClickAndLeave(ctf.sortByRoad);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by road list", c3, cars.get(0));
Assert.assertEquals("2nd car in sort by road list", c1, cars.get(1));
Assert.assertEquals("3rd car in sort by road list", c5, cars.get(2));
Assert.assertEquals("4th car in sort by road list", c4, cars.get(3));
Assert.assertEquals("5th car in sort by road list", c2, cars.get(4));
enterClickAndLeave(ctf.sortByTrain);
//TODO add trains
// test sort by type
enterClickAndLeave(ctf.sortByType);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by type list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by type list", c1, cars.get(1));
Assert.assertEquals("3rd car in sort by type list", c5, cars.get(2));
Assert.assertEquals("4th car in sort by type list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by type list", c4, cars.get(4));
// test find text field
ctf.findCarTextBox.setText("*2");
enterClickAndLeave(ctf.findButton);
// table is sorted by type, cars with number 2 are in the first and last rows
Assert.assertEquals("find car by number 1st", 0, ctf.carsTable.getSelectedRow());
enterClickAndLeave(ctf.findButton);
Assert.assertEquals("find car by number 2nd", 4, ctf.carsTable.getSelectedRow());
// create the CarEditFrame
enterClickAndLeave(ctf.addButton);
ctf.dispose();
}
use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.
the class EngineAttributeEditFrameTest method loadEngines.
private void loadEngines() {
// add Owner1 and Owner2
CarOwners co = CarOwners.instance();
co.addName("Owner1");
co.addName("Owner2");
// add road names
CarRoads cr = CarRoads.instance();
cr.addName("NH");
cr.addName("UP");
cr.addName("AA");
cr.addName("SP");
// add locations
LocationManager lManager = LocationManager.instance();
Location westford = lManager.newLocation("Westford");
Track westfordYard = westford.addTrack("Yard", Track.YARD);
westfordYard.setLength(300);
Track westfordSiding = westford.addTrack("Siding", Track.SPUR);
westfordSiding.setLength(300);
Track westfordAble = westford.addTrack("Able", Track.SPUR);
westfordAble.setLength(300);
Location boxford = lManager.newLocation("Boxford");
Track boxfordYard = boxford.addTrack("Yard", Track.YARD);
boxfordYard.setLength(300);
Track boxfordJacobson = boxford.addTrack("Jacobson", Track.SPUR);
boxfordJacobson.setLength(300);
Track boxfordHood = boxford.addTrack("Hood", Track.SPUR);
boxfordHood.setLength(300);
EngineManager eManager = EngineManager.instance();
// add 5 Engines to table
Engine e1 = eManager.newEngine("NH", "1");
e1.setModel("RS1");
e1.setBuilt("2009");
e1.setMoves(55);
e1.setOwner("Owner2");
jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 3");
e1.setRfid("RFID 3");
e1.setWeightTons("Tons of Weight");
e1.setComment("Test Engine NH 1 Comment");
Assert.assertEquals("e1 location", Track.OKAY, e1.setLocation(westford, westfordYard));
Assert.assertEquals("e1 destination", Track.OKAY, e1.setDestination(boxford, boxfordJacobson));
Engine e2 = eManager.newEngine("UP", "2");
e2.setModel("FT");
e2.setBuilt("2004");
e2.setMoves(50);
e2.setOwner("AT");
jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 2");
e2.setRfid("RFID 2");
Engine e3 = eManager.newEngine("AA", "3");
e3.setModel("SW8");
e3.setBuilt("2006");
e3.setMoves(40);
e3.setOwner("AB");
jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 5");
e3.setRfid("RFID 5");
Assert.assertEquals("e3 location", Track.OKAY, e3.setLocation(boxford, boxfordHood));
Assert.assertEquals("e3 destination", Track.OKAY, e3.setDestination(boxford, boxfordYard));
Engine e4 = eManager.newEngine("SP", "2");
e4.setModel("GP35");
e4.setBuilt("1990");
e4.setMoves(30);
e4.setOwner("AAA");
jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 4");
e4.setRfid("RFID 4");
Assert.assertEquals("e4 location", Track.OKAY, e4.setLocation(westford, westfordSiding));
Assert.assertEquals("e4 destination", Track.OKAY, e4.setDestination(boxford, boxfordHood));
Engine e5 = eManager.newEngine("NH", "5");
e5.setModel("SW1200");
e5.setBuilt("1956");
e5.setMoves(25);
e5.setOwner("DAB");
jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 1");
e5.setRfid("RFID 1");
Assert.assertEquals("e5 location", Track.OKAY, e5.setLocation(westford, westfordAble));
Assert.assertEquals("e5 destination", Track.OKAY, e5.setDestination(westford, westfordAble));
}
Aggregations