Exemplo n.º 1
0
  public JSONArray buildSpotifyJsonObject(ArrayList<Trip> list) {
    JSONArray array = new JSONArray();

    try {
      for (Trip trip : list) {
        JSONArray tracks = new JSONArray();

        for (Track track : trip.getTracks()) {
          tracks.put(
              new JSONObject()
                  .put("name", track.getName())
                  .put("artist", track.getArtist())
                  .put("duration", track.getDuration())
                  .put("url", track.getUrl()));
        }
        array.put(
            new JSONObject()
                .put("origin", trip.getOrigin())
                .put("destination", trip.getDest())
                .put("id", trip.getId())
                .put("duration", trip.getDurationMs())
                .put("originDate", trip.getOriginDate())
                .put("destinationDate", trip.getDestDate())
                .put("originTime", trip.getOriginTime())
                .put("destinationTime", trip.getDestTime())
                .put("playlist", tracks));
      }

    } catch (Exception E) {

    }
    System.out.println(array);
    return array;
  }
Exemplo n.º 2
0
  // test Track load support
  public void testTrackLoadSupport() {
    Location l = new Location("Location Test Load id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track Car id", "Test id", t.getId());
    Assert.assertEquals("Location Track Car Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Car Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    /* Test Load Swapable */
    Assert.assertEquals("Location Track Load Swapable default", false, t.isLoadSwapEnabled());
    t.setLoadSwapEnabled(true);
    Assert.assertEquals("Location Track Load Swapable true", true, t.isLoadSwapEnabled());
    t.setLoadSwapEnabled(false);
    Assert.assertEquals("Location Track Load Swapable false", false, t.isLoadSwapEnabled());

    /* Test Remove Loads */
    Assert.assertEquals(
        "Location Track Remove Loads default", false, t.isRemoveCustomLoadsEnabled());
    t.setRemoveCustomLoadsEnabled(true);
    Assert.assertEquals("Location Track Remove Loads true", true, t.isRemoveCustomLoadsEnabled());
    t.setRemoveCustomLoadsEnabled(false);
    Assert.assertEquals("Location Track Remove Loads false", false, t.isRemoveCustomLoadsEnabled());

    /* Test Add Loads */
    Assert.assertEquals("Location Track Add Loads default", false, t.isAddCustomLoadsEnabled());
    t.setAddCustomLoadsEnabled(true);
    Assert.assertEquals("Location Track Add Loads true", true, t.isAddCustomLoadsEnabled());
    t.setAddCustomLoadsEnabled(false);
    Assert.assertEquals("Location Track Add Loads false", false, t.isAddCustomLoadsEnabled());
  }
Exemplo n.º 3
0
  // test Track drop support
  public void testTrackDropSupport() {
    Location l = new Location("Location Test Drop id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track Car id", "Test id", t.getId());
    Assert.assertEquals("Location Track Car Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Car Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    Assert.assertEquals("Location Track Drops Start", 0, t.getDropRS());
    Assert.assertEquals("Location Track Drops Start Reserved", 0, t.getReserved());

    Car c1 = new Car("TESTROAD", "TESTNUMBER1");
    c1.setLength("40");
    t.addDropRS(c1);
    Assert.assertEquals("Location Track Drops 1st", 1, t.getDropRS());
    Assert.assertEquals("Location Track Drops 1st Reserved", 40 + 4, t.getReserved());

    Car c2 = new Car("TESTROAD", "TESTNUMBER2");
    c2.setLength("50");
    t.addDropRS(c2);
    Assert.assertEquals("Location Track Drops 2nd", 2, t.getDropRS());
    Assert.assertEquals("Location Track Drops 2nd Reserved", 40 + 4 + 50 + 4, t.getReserved());

    t.deleteDropRS(c2);
    Assert.assertEquals("Location Track Drops 3rd", 1, t.getDropRS());
    Assert.assertEquals("Location Track Drops 3rd Reserved", 40 + 4, t.getReserved());

    t.deleteDropRS(c1);
    Assert.assertEquals("Location Track Drops 4th", 0, t.getDropRS());
    Assert.assertEquals("Location Track Drops 4th Reserved", 0, t.getReserved());
  }
  /**
   * Test loading a session with a bedtools analysis track
   *
   * @throws Exception
   */
  @Test
  public void testLoadBedtools_Subtract() throws Exception {
    String toolPath = "/usr/local/bin/bedtools";
    boolean haveTool = PluginSpecReader.isToolPathValid(toolPath);
    Assume.assumeTrue(haveTool);

    String sessionPath = TestUtils.DATA_DIR + "sessions/GSM_bedtools_subtract.xml";

    rewriteRestoreSession(sessionPath);

    String trackAname = "GSM1004654_100k.bed";
    String trackBname = "GSM1004654_10k.bed";
    String analId = "BEDTools Remove/Subtract";

    FeatureTrack analTrack = null, trackA = null, trackB = null;
    for (Track track : IGV.getInstance().getAllTracks()) {
      if (track.getId().equals(analId)) {
        analTrack = (FeatureTrack) track;
      } else if (track.getName().equals(trackAname)) {
        trackA = (FeatureTrack) track;
      } else if (track.getName().equals(trackBname)) {
        trackB = (FeatureTrack) track;
      }
    }

    String chr = "chr2";
    int start = 177932002;
    int end = 180561093;

    List<Feature> aFeatures = trackA.getFeatures(chr, start, end);
    List<Feature> bFeatures = trackB.getFeatures(chr, start, end);
    List<Feature> analFeatures = analTrack.getFeatures(chr, start, end);

    // Fairly coarse check, these actually might not exactly be true
    // due to splitting of exons
    int checked = 0;
    for (Feature afeat : analFeatures) {
      if (afeat.getStart() < start || afeat.getStart() > end) continue;
      // This particular feature splits funny, it's not a bug, at least not with IGV
      if (afeat.getStart() == 178625608) continue;

      assertTrue(listContainsFeature(aFeatures, afeat));
      assertFalse(listContainsFeature(bFeatures, afeat));
      checked++;
    }
    assert checked > 0;
  }
Exemplo n.º 5
0
  @Override
  protected void onDestroy() {
    final LocalizedStringSet stringSet = raceService.getLocalizedStringSet();
    player.sendMessage(
        Color.LIGHTBLUE,
        stringSet.format(player, "TrackEditor.EndEditingTrackMessage", track.getName()));

    for (MapIcon icon : mapIcons.values()) icon.destroy();
    mapIcons.clear();
  }
Exemplo n.º 6
0
  @Override
  protected void onInit() {

    eventManagerNode.registerHandler(
        PlayerUpdateEvent.class,
        HandlerPriority.NORMAL,
        Attentions.create().object(player),
        (e) -> {
          if (player.getUpdateCount() % 40 == 0) updateMapIcons();
        });

    final LocalizedStringSet stringSet = raceService.getLocalizedStringSet();
    player.sendMessage(
        Color.LIGHTBLUE,
        stringSet.format(player, "TrackEditor.StartEditingTrackMessage", track.getName()));
  }
Exemplo n.º 7
0
  /**
   * Test loading segmented data file from a sql database, using a profile
   *
   * @throws Exception
   */
  @Test
  public void testLoadSegProfile() throws Exception {
    String path = TestUtils.DATA_DIR + "sql/seg_canFam2_profile.dbxml";

    int expectedTracks = 6;
    List<Track> tracks = trackLoader.load(new ResourceLocator(path), genome);
    assertEquals(expectedTracks, tracks.size());
    Set<String> expSampleIds =
        new HashSet<String>(
            Arrays.asList("0123-A", "0123-B-1", "0123-C-1", "0123-C-2", "0123-C-3"));
    Set<String> actSampleIds = new HashSet<String>(5);
    for (Track track : tracks) {
      if (track instanceof DataSourceTrack) {
        actSampleIds.add(track.getName());
      }
    }
    assertEquals(expSampleIds, actSampleIds);
  }
Exemplo n.º 8
0
  // test Track schedule support
  public void testTrackScheduleSupport() {
    Location l = new Location("Location Test Schedule id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", Track.SPUR, l);
    Assert.assertEquals("Location Track Car id", "Test id", t.getId());
    Assert.assertEquals("Location Track Car Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Car Type", Track.SPUR, t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    t.setScheduleId("Test Schedule Id");
    Assert.assertEquals("Location Track set Schedule Name", "Test Schedule Id", t.getScheduleId());
    t.setScheduleItemId("Test Schedule Item Id");
    Assert.assertEquals(
        "Location Track set Schedule Item Id", "Test Schedule Item Id", t.getScheduleItemId());
    t.setScheduleCount(2);
    Assert.assertEquals("Location Track set Schedule Count", 2, t.getScheduleCount());

    t.setScheduleMode(Track.SEQUENTIAL);
    Assert.assertEquals("Track mode sequential", Track.SEQUENTIAL, t.getScheduleMode());
    t.setScheduleMode(Track.MATCH);
    Assert.assertEquals("Track mode sequential", Track.MATCH, t.getScheduleMode());
  }
Exemplo n.º 9
0
 // this table listens for changes to a location and it's interchanges
 @Override
 public void propertyChange(PropertyChangeEvent e) {
   if (Control.SHOW_PROPERTY) {
     log.debug(
         "Property change: ({}) old: ({}) new: ({})",
         e.getPropertyName(),
         e.getOldValue(),
         e.getNewValue());
   }
   super.propertyChange(e);
   if (e.getSource().getClass().equals(Track.class)) {
     Track track = ((Track) e.getSource());
     if (track.getTrackType().equals(Track.INTERCHANGE)) {
       int row = tracksList.indexOf(track);
       if (Control.SHOW_PROPERTY) {
         log.debug("Update interchange table row: {} track: {}", row, track.getName());
       }
       if (row >= 0) {
         fireTableRowsUpdated(row, row);
       }
     }
   }
 }
Exemplo n.º 10
0
  private ContentValues createContentValues(Track track) {
    ContentValues values = new ContentValues();
    TripStatistics tripStatistics = track.getTripStatistics();

    // Value < 0 indicates no id is available
    if (track.getId() >= 0) {
      values.put(TracksColumns._ID, track.getId());
    }
    values.put(TracksColumns.NAME, track.getName());
    values.put(TracksColumns.DESCRIPTION, track.getDescription());
    values.put(TracksColumns.CATEGORY, track.getCategory());
    values.put(TracksColumns.STARTID, track.getStartId());
    values.put(TracksColumns.STOPID, track.getStopId());
    values.put(TracksColumns.STARTTIME, tripStatistics.getStartTime());
    values.put(TracksColumns.STOPTIME, tripStatistics.getStopTime());
    values.put(TracksColumns.NUMPOINTS, track.getNumberOfPoints());
    values.put(TracksColumns.TOTALDISTANCE, tripStatistics.getTotalDistance());
    values.put(TracksColumns.TOTALTIME, tripStatistics.getTotalTime());
    values.put(TracksColumns.MOVINGTIME, tripStatistics.getMovingTime());
    values.put(TracksColumns.MINLAT, tripStatistics.getBottom());
    values.put(TracksColumns.MAXLAT, tripStatistics.getTop());
    values.put(TracksColumns.MINLON, tripStatistics.getLeft());
    values.put(TracksColumns.MAXLON, tripStatistics.getRight());
    values.put(TracksColumns.AVGSPEED, tripStatistics.getAverageSpeed());
    values.put(TracksColumns.AVGMOVINGSPEED, tripStatistics.getAverageMovingSpeed());
    values.put(TracksColumns.MAXSPEED, tripStatistics.getMaxSpeed());
    values.put(TracksColumns.MINELEVATION, tripStatistics.getMinElevation());
    values.put(TracksColumns.MAXELEVATION, tripStatistics.getMaxElevation());
    values.put(TracksColumns.ELEVATIONGAIN, tripStatistics.getTotalElevationGain());
    values.put(TracksColumns.MINGRADE, tripStatistics.getMinGrade());
    values.put(TracksColumns.MAXGRADE, tripStatistics.getMaxGrade());
    values.put(TracksColumns.MAPID, track.getMapId());
    values.put(TracksColumns.TABLEID, track.getTableId());
    values.put(TracksColumns.ICON, track.getIcon());
    return values;
  }
Exemplo n.º 11
0
  // test Track pickup support
  public void testTrackPickUpSupport() {
    Location l = new Location("Location Test Pickup id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track Car id", "Test id", t.getId());
    Assert.assertEquals("Location Track Car Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Car Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    Assert.assertEquals("Location Track Pick Ups Start", 0, t.getPickupRS());
    Car c1 = new Car("TESTROAD", "TESTNUMBER1");
    c1.setLength("40");

    t.addPickupRS(c1);
    Assert.assertEquals("Location Track Pick Ups 1st", 1, t.getPickupRS());

    t.addPickupRS(c1);
    Assert.assertEquals("Location Track Pick Ups 2nd", 2, t.getPickupRS());

    t.deletePickupRS(c1);
    Assert.assertEquals("Location Track Pick Ups 3rd", 1, t.getPickupRS());

    t.deletePickupRS(c1);
    Assert.assertEquals("Location Track Pick Ups 4th", 0, t.getPickupRS());
  }
Exemplo n.º 12
0
  // test Track attributes
  public void testTrackAttributes() {
    Location l = new Location("Location Test Attridutes id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track id", "Test id", t.getId());
    Assert.assertEquals("Location Track Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    t.setName("New Test Name");
    Assert.assertEquals("Location Track set Name", "New Test Name", t.getName());

    t.setComment("New Test Comment");
    Assert.assertEquals("Location Track set Comment", "New Test Comment", t.getComment());

    t.setMoves(40);
    Assert.assertEquals("Location Track Moves", 40, t.getMoves());

    t.setLength(400);
    Assert.assertEquals("Location Track Length", 400, t.getLength());

    t.setReserved(200);
    Assert.assertEquals("Location Track Reserved", 200, t.getReserved());

    t.setUsedLength(100);
    Assert.assertEquals("Location Track Used Length", 100, t.getUsedLength());

    t.setTrainDirections(Track.NORTH);
    Assert.assertEquals("Location Track Direction North", Track.NORTH, t.getTrainDirections());

    t.setTrainDirections(Track.SOUTH);
    Assert.assertEquals("Location Track Direction South", Track.SOUTH, t.getTrainDirections());

    t.setTrainDirections(Track.EAST);
    Assert.assertEquals("Location Track Direction East", Track.EAST, t.getTrainDirections());

    t.setTrainDirections(Track.WEST);
    Assert.assertEquals("Location Track Direction West", Track.WEST, t.getTrainDirections());

    t.setTrainDirections(Track.NORTH + Track.SOUTH);
    Assert.assertEquals(
        "Location Track Direction North+South", Track.NORTH + Track.SOUTH, t.getTrainDirections());

    t.setTrainDirections(Track.EAST + Track.WEST);
    Assert.assertEquals(
        "Location Track Direction East+West", Track.EAST + Track.WEST, t.getTrainDirections());

    t.setTrainDirections(Track.NORTH + Track.SOUTH + Track.EAST + Track.WEST);
    Assert.assertEquals(
        "Location Track Direction North+South+East+West",
        Track.NORTH + Track.SOUTH + Track.EAST + Track.WEST,
        t.getTrainDirections());

    t.setRoadOption("New Test Road Option");
    Assert.assertEquals(
        "Location Track set Road Option", "New Test Road Option", t.getRoadOption());

    t.setDropOption("New Test Drop Option");
    Assert.assertEquals(
        "Location Track set Drop Option", "New Test Drop Option", t.getDropOption());

    t.setPickupOption("New Test Pickup Option");
    Assert.assertEquals(
        "Location Track set Pickup Option", "New Test Pickup Option", t.getPickupOption());
  }
Exemplo n.º 13
0
  // test Track typename support
  public void testTrackTypeNameSupport() {
    Location l = new Location("Location Test Name id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track id", "Test id", t.getId());
    Assert.assertEquals("Location Track Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    /* Test Type Name */
    Assert.assertEquals(
        "Location Track Accepts Type Name undefined", false, t.acceptsTypeName("TestTypeName"));

    t.addTypeName("TestTypeName");
    Assert.assertEquals(
        "Location Track Accepts Type Name defined", false, t.acceptsTypeName("TestTypeName"));

    // now add to car types
    CarTypes ct = CarTypes.instance();
    ct.addName("TestTypeName");
    t.addTypeName("TestTypeName");
    Assert.assertEquals(
        "Location Track Accepts Type Name defined after ct",
        false,
        t.acceptsTypeName("TestTypeName"));

    // location must also accept the same type
    l.addTypeName("TestTypeName");
    Assert.assertEquals(
        "Location Track Accepts Type Name defined after location",
        true,
        t.acceptsTypeName("TestTypeName"));

    t.deleteTypeName("TestTypeName");
    Assert.assertEquals(
        "Location Track Accepts Type Name deleted", false, t.acceptsTypeName("TestTypeName"));

    /* Needed so later tests will behave correctly */
    ct.deleteName("TestTypeName");

    ct.addName("Baggager");
    t.addTypeName("Baggager");
    l.addTypeName("Baggager");

    Assert.assertEquals(
        "Location Track Accepts Type Name Baggager", true, t.acceptsTypeName("Baggager"));

    /* Test Road Name */
    t.setRoadOption(Track.INCLUDE_ROADS);
    Assert.assertEquals(
        "Location Track set Road Option INCLUDEROADS", "Include", t.getRoadOption());

    Assert.assertEquals(
        "Location Track Accepts Road Name undefined", false, t.acceptsRoadName("TestRoadName"));

    t.addRoadName("TestRoadName");
    Assert.assertEquals(
        "Location Track Accepts Road Name defined", true, t.acceptsRoadName("TestRoadName"));

    t.addRoadName("TestOtherRoadName");
    Assert.assertEquals(
        "Location Track Accepts Road Name other defined", true, t.acceptsRoadName("TestRoadName"));

    t.deleteRoadName("TestRoadName");
    Assert.assertEquals(
        "Location Track Accepts Road Name deleted", false, t.acceptsRoadName("TestRoadName"));

    t.setRoadOption(Track.ALL_ROADS);
    Assert.assertEquals("Location Track set Road Option AllROADS", "All", t.getRoadOption());
    Assert.assertEquals(
        "Location Track Accepts All Road Names", true, t.acceptsRoadName("TestRoadName"));

    t.setRoadOption(Track.EXCLUDE_ROADS);
    Assert.assertEquals(
        "Location Track set Road Option EXCLUDEROADS", "Exclude", t.getRoadOption());
    Assert.assertEquals(
        "Location Track Excludes Road Names", true, t.acceptsRoadName("TestRoadName"));

    t.addRoadName("TestRoadName");
    Assert.assertEquals(
        "Location Track Excludes Road Names 2", false, t.acceptsRoadName("TestRoadName"));

    /* Test Drop IDs */
    Assert.assertEquals(
        "Location Track Accepts Drop ID undefined", false, t.containsDropId("TestDropId"));

    t.addDropId("TestDropId");
    Assert.assertEquals(
        "Location Track Accepts Drop ID defined", true, t.containsDropId("TestDropId"));

    t.addDropId("TestOtherDropId");
    Assert.assertEquals(
        "Location Track Accepts Drop ID other defined", true, t.containsDropId("TestDropId"));

    t.deleteDropId("TestDropId");
    Assert.assertEquals(
        "Location Track Accepts Drop ID deleted", false, t.containsDropId("TestDropId"));

    /* Test Pickup IDs */
    Assert.assertEquals(
        "Location Track Accepts Pickup ID undefined", false, t.containsPickupId("TestPickupId"));

    t.addPickupId("TestPickupId");
    Assert.assertEquals(
        "Location Track Accepts Pickup ID defined", true, t.containsPickupId("TestPickupId"));

    t.addPickupId("TestOtherPickupId");
    Assert.assertEquals(
        "Location Track Accepts Pickup ID other defined", true, t.containsPickupId("TestPickupId"));

    t.deletePickupId("TestPickupId");
    Assert.assertEquals(
        "Location Track Accepts Pickup ID deleted", false, t.containsPickupId("TestPickupId"));
  }
Exemplo n.º 14
0
  // test Track car support
  public void testTrackCarSupport() {
    Location l = new Location("Location Test Car id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track Car id", "Test id", t.getId());
    Assert.assertEquals("Location Track Car Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Car Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    Assert.assertEquals("Location Track Car Start Used Length", 0, t.getUsedLength());
    Assert.assertEquals("Location Track Car Start Number of Rolling Stock", 0, t.getNumberRS());
    Assert.assertEquals("Location Track Car Start Number of Cars", 0, t.getNumberCars());
    Assert.assertEquals("Location Track Car Start Number of Engines", 0, t.getNumberEngines());

    Car c1 = new Car("TESTROAD", "TESTNUMBER1");
    c1.setLength("40");
    t.addRS(c1);

    Assert.assertEquals("Location Track Car First Number of Rolling Stock", 1, t.getNumberRS());
    Assert.assertEquals("Location Track Car First Number of Cars", 1, t.getNumberCars());
    Assert.assertEquals("Location Track Car First Number of Engines", 0, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car First Used Length", 40 + 4, t.getUsedLength()); // Drawbar length is 4

    Car c2 = new Car("TESTROAD", "TESTNUMBER2");
    c2.setLength("33");
    t.addRS(c2);

    Assert.assertEquals("Location Track Car 2nd Number of Rolling Stock", 2, t.getNumberRS());
    Assert.assertEquals("Location Track Car 2nd Number of Cars", 2, t.getNumberCars());
    Assert.assertEquals("Location Track Car 2nd Number of Engines", 0, t.getNumberEngines());
    Assert.assertEquals("Location Track Car 2nd Used Length", 40 + 4 + 33 + 4, t.getUsedLength());

    jmri.jmrit.operations.rollingstock.engines.Engine e1 =
        new jmri.jmrit.operations.rollingstock.engines.Engine("TESTROAD", "TESTNUMBERE1");
    e1.setModel("E8"); // Default length == 70
    t.addRS(e1);

    Assert.assertEquals("Location Track Car 3rd Number of Rolling Stock", 3, t.getNumberRS());
    Assert.assertEquals("Location Track Car 3rd Number of Cars", 2, t.getNumberCars());
    Assert.assertEquals("Location Track Car 3rd Number of Engines", 1, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car 3rd Used Length", 40 + 4 + 33 + 4 + 70 + 4, t.getUsedLength());

    Car c3 = new Car("TESTROAD", "TESTNUMBER3");
    c3.setLength("50");
    t.addRS(c3);

    Assert.assertEquals("Location Track Car 4th Number of Rolling Stock", 4, t.getNumberRS());
    Assert.assertEquals("Location Track Car 4th Number of Cars", 3, t.getNumberCars());
    Assert.assertEquals("Location Track Car 4th Number of Engines", 1, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car 4th Used Length", 40 + 4 + 33 + 4 + 70 + 4 + 50 + 4, t.getUsedLength());

    Engine e2 = new Engine("TESTROAD", "TESTNUMBERE2");
    e2.setModel("E8"); // Default length == 70
    t.addRS(e2);

    Assert.assertEquals("Location Track Car 5th Number of Rolling Stock", 5, t.getNumberRS());
    Assert.assertEquals("Location Track Car 5th Number of Cars", 3, t.getNumberCars());
    Assert.assertEquals("Location Track Car 5th Number of Engines", 2, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car 5th Used Length",
        40 + 4 + 33 + 4 + 70 + 4 + 50 + 4 + 70 + 4,
        t.getUsedLength()); // Drawbar length is 4

    t.deleteRS(c2);

    Assert.assertEquals("Location Track Car 6th Number of Rolling Stock", 4, t.getNumberRS());
    Assert.assertEquals("Location Track Car 6th Number of Cars", 2, t.getNumberCars());
    Assert.assertEquals("Location Track Car 6th Number of Engines", 2, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car 6th Used Length", 40 + 4 + 70 + 4 + 50 + 4 + 70 + 4, t.getUsedLength());

    t.deleteRS(c1);

    Assert.assertEquals("Location Track Car 7th Number of Rolling Stock", 3, t.getNumberRS());
    Assert.assertEquals("Location Track Car 7th Number of Cars", 1, t.getNumberCars());
    Assert.assertEquals("Location Track Car 7th Number of Engines", 2, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car 7th Used Length", 70 + 4 + 50 + 4 + 70 + 4, t.getUsedLength());

    t.deleteRS(e2);

    Assert.assertEquals("Location Track Car 8th Number of Rolling Stock", 2, t.getNumberRS());
    Assert.assertEquals("Location Track Car 8th Number of Cars", 1, t.getNumberCars());
    Assert.assertEquals("Location Track Car 8th Number of Engines", 1, t.getNumberEngines());
    Assert.assertEquals("Location Track Car 8th Used Length", 70 + 4 + 50 + 4, t.getUsedLength());

    t.deleteRS(e1);

    Assert.assertEquals("Location Track Car 9th Number of Rolling Stock", 1, t.getNumberRS());
    Assert.assertEquals("Location Track Car 9th Number of Cars", 1, t.getNumberCars());
    Assert.assertEquals("Location Track Car 9th Number of Engines", 0, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car 9th Used Length", 50 + 4, t.getUsedLength()); // Drawbar length is 4

    t.deleteRS(c3);

    Assert.assertEquals("Location Track Car Last Number of Rolling Stock", 0, t.getNumberRS());
    Assert.assertEquals("Location Track Car Last Number of Cars", 0, t.getNumberCars());
    Assert.assertEquals("Location Track Car Last Number of Engines", 0, t.getNumberEngines());
    Assert.assertEquals(
        "Location Track Car Last Used Length", 0, t.getUsedLength()); // Drawbar length is 4
  }
Exemplo n.º 15
0
 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
     value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
     justification = "CarManager only provides Car Objects")
 private void runUpdate() {
   log.debug("run update");
   removePropertyChangeListerners();
   trainCommon.clearUtilityCarTypes(); // reset the utility car counts
   carCheckBoxes.clear();
   pTrack.removeAll();
   boolean pickup = false;
   boolean setout = false;
   if (_track != null) {
     pTrackPane.setBorder(BorderFactory.createTitledBorder(_track.getName()));
     textTrackCommentPane.setText(_track.getComment());
     textTrackCommentPane.setVisible(!_track.getComment().equals(Track.NONE));
     textTrackCommentWorkPane.setText("");
     for (Train train : trainManager.getTrainsArrivingThisLocationList(_track.getLocation())) {
       JPanel pTrain = new JPanel();
       pTrain.setLayout(new BoxLayout(pTrain, BoxLayout.Y_AXIS));
       pTrain.setBorder(
           BorderFactory.createTitledBorder(
               MessageFormat.format(
                   TrainSwitchListText.getStringScheduledWork(),
                   new Object[] {train.getName(), train.getDescription()})));
       // List locos first
       List<Engine> engList = engManager.getByTrainBlockingList(train);
       if (Setup.isPrintHeadersEnabled()) {
         for (Engine engine : engList) {
           if (engine.getTrack() == _track) {
             JLabel header = new JLabel(Tab + trainCommon.getPickupEngineHeader());
             setLabelFont(header);
             pTrain.add(header);
             break;
           }
         }
       }
       for (Engine engine : engList) {
         if (engine.getTrack() == _track) {
           engine.addPropertyChangeListener(this);
           rollingStock.add(engine);
           JCheckBox checkBox = new JCheckBox(trainCommon.pickupEngine(engine));
           setCheckBoxFont(checkBox);
           pTrain.add(checkBox);
           carCheckBoxes.put(engine.getId(), checkBox);
           pTrack.add(pTrain);
         }
       }
       if (Setup.isPrintHeadersEnabled()) {
         for (Engine engine : engList) {
           if (engine.getDestinationTrack() == _track) {
             JLabel header = new JLabel(Tab + trainCommon.getDropEngineHeader());
             setLabelFont(header);
             pTrain.add(header);
             break;
           }
         }
       }
       for (Engine engine : engList) {
         if (engine.getDestinationTrack() == _track) {
           engine.addPropertyChangeListener(this);
           rollingStock.add(engine);
           JCheckBox checkBox = new JCheckBox(trainCommon.dropEngine(engine));
           setCheckBoxFont(checkBox);
           pTrain.add(checkBox);
           carCheckBoxes.put(engine.getId(), checkBox);
           pTrack.add(pTrain);
         }
       }
       List<Car> carList = carManager.getByTrainDestinationList(train);
       if (Setup.isPrintHeadersEnabled()) {
         for (Car car : carList) {
           if (car.getTrack() == _track && car.getRouteDestination() != car.getRouteLocation()) {
             JLabel header =
                 new JLabel(
                     Tab
                         + trainCommon.getPickupCarHeader(
                             !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK));
             setLabelFont(header);
             pTrain.add(header);
             break;
           }
         }
       }
       // sort car pick ups by their destination
       List<RouteLocation> routeList = train.getRoute().getLocationsBySequenceList();
       for (RouteLocation rl : routeList) {
         for (Car car : carList) {
           if (car.getTrack() == _track
               && car.getRouteDestination() != car.getRouteLocation()
               && car.getRouteDestination() == rl) {
             car.addPropertyChangeListener(this);
             rollingStock.add(car);
             String text;
             if (car.isUtility()) {
               text =
                   trainCommon.pickupUtilityCars(
                       carList, car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
               if (text == null) {
                 continue; // this car type has already been processed
               }
             } else {
               text = trainCommon.pickupCar(car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
             }
             pickup = true;
             JCheckBox checkBox = new JCheckBox(text);
             setCheckBoxFont(checkBox);
             pTrain.add(checkBox);
             carCheckBoxes.put(car.getId(), checkBox);
             pTrack.add(pTrain);
           }
         }
       }
       // now do car set outs
       if (Setup.isPrintHeadersEnabled()) {
         for (Car car : carList) {
           if (car.getDestinationTrack() == _track
               && car.getRouteDestination() != car.getRouteLocation()) {
             JLabel header =
                 new JLabel(
                     Tab
                         + trainCommon.getDropCarHeader(
                             !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK));
             setLabelFont(header);
             pTrain.add(header);
             break;
           }
         }
       }
       for (Car car : carList) {
         if (car.getDestinationTrack() == _track
             && car.getRouteLocation() != car.getRouteDestination()) {
           car.addPropertyChangeListener(this);
           rollingStock.add(car);
           String text;
           if (car.isUtility()) {
             text = trainCommon.setoutUtilityCars(carList, car, !TrainCommon.LOCAL, !IS_MANIFEST);
             if (text == null) {
               continue; // this car type has already been processed
             }
           } else {
             text = trainCommon.dropCar(car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
           }
           setout = true;
           JCheckBox checkBox = new JCheckBox(text);
           setCheckBoxFont(checkBox);
           pTrain.add(checkBox);
           carCheckBoxes.put(car.getId(), checkBox);
           pTrack.add(pTrain);
         }
       }
       // now do local car moves
       if (Setup.isPrintHeadersEnabled()) {
         for (Car car : carList) {
           if ((car.getTrack() == _track || car.getDestinationTrack() == _track)
               && car.getRouteDestination() == car.getRouteLocation()) {
             JLabel header = new JLabel(Tab + trainCommon.getLocalMoveHeader(!IS_MANIFEST));
             setLabelFont(header);
             pTrain.add(header);
             break;
           }
         }
       }
       for (Car car : carList) {
         if ((car.getTrack() == _track || car.getDestinationTrack() == _track)
             && car.getRouteLocation() != null
             && car.getRouteLocation() == car.getRouteDestination()) {
           car.addPropertyChangeListener(this);
           rollingStock.add(car);
           String text;
           if (car.isUtility()) {
             text = trainCommon.setoutUtilityCars(carList, car, TrainCommon.LOCAL, !IS_MANIFEST);
             if (text == null) {
               continue; // this car type has already been processed
             }
           } else {
             text = trainCommon.localMoveCar(car, !IS_MANIFEST);
           }
           setout = true;
           JCheckBox checkBox = new JCheckBox(text);
           setCheckBoxFont(checkBox);
           pTrain.add(checkBox);
           carCheckBoxes.put(car.getId(), checkBox);
           pTrack.add(pTrain);
         }
       }
     }
     // now do car holds
     // we only need the cars on this track
     List<RollingStock> rsList = carManager.getByTrainList();
     List<Car> carList = new ArrayList<Car>();
     for (RollingStock rs : rsList) {
       if (rs.getTrack() != _track || rs.getRouteLocation() != null) continue;
       carList.add((Car) rs);
     }
     JPanel pHoldCars = new JPanel();
     pHoldCars.setLayout(new BoxLayout(pHoldCars, BoxLayout.Y_AXIS));
     pHoldCars.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("HoldCars")));
     for (Car car : carList) {
       String text;
       if (car.isUtility()) {
         String s =
             trainCommon.pickupUtilityCars(
                 carList, car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
         if (s == null) continue;
         text = TrainSwitchListText.getStringHoldCar().split("\\{")[0] + s.trim();
       } else {
         text =
             MessageFormat.format(
                 TrainSwitchListText.getStringHoldCar(),
                 new Object[] {
                   TrainCommon.padAndTruncateString(
                       car.getRoadName(), CarRoads.instance().getMaxNameLength()),
                   TrainCommon.padAndTruncateString(
                       car.getNumber(), Control.max_len_string_print_road_number),
                   TrainCommon.padAndTruncateString(
                       car.getTypeName().split("-")[0], CarTypes.instance().getMaxNameLength()),
                   TrainCommon.padAndTruncateString(
                       car.getLength() + TrainCommon.LENGTHABV,
                       Control.max_len_string_length_name),
                   TrainCommon.padAndTruncateString(
                       car.getLoadName(), CarLoads.instance().getMaxNameLength()),
                   TrainCommon.padAndTruncateString(
                       _track.getName(), LocationManager.instance().getMaxTrackNameLength()),
                   TrainCommon.padAndTruncateString(
                       car.getColor(), CarColors.instance().getMaxNameLength())
                 });
       }
       JCheckBox checkBox = new JCheckBox(text);
       setCheckBoxFont(checkBox);
       pHoldCars.add(checkBox);
       carCheckBoxes.put(car.getId(), checkBox);
       pTrack.add(pHoldCars);
     }
     pTrackPane.validate();
     if (pickup && !setout) {
       textTrackCommentWorkPane.setText(_track.getCommentPickup());
     } else if (!pickup && setout) {
       textTrackCommentWorkPane.setText(_track.getCommentSetout());
     } else if (pickup && setout) {
       textTrackCommentWorkPane.setText(_track.getCommentBoth());
     }
     textTrackCommentWorkPane.setVisible(!textTrackCommentWorkPane.getText().equals(""));
   } else {
     pTrackPane.setBorder(BorderFactory.createTitledBorder(""));
     textTrackCommentPane.setVisible(false);
     textTrackCommentWorkPane.setVisible(false);
   }
 }
Exemplo n.º 16
0
  public void initComponents(Location location, Track track) {
    _location = location;
    _track = track;

    // property changes
    _location.addPropertyChangeListener(this);
    // listen for car load name and type changes
    CarLoads.instance().addPropertyChangeListener(this);
    CarTypes.instance().addPropertyChangeListener(this);

    // the following code sets the frame's initial state
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    // Set up the panels
    // Layout the panel by rows
    // row 1
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
    p1.setMaximumSize(new Dimension(2000, 250));

    // row 1a
    JPanel pTrackName = new JPanel();
    pTrackName.setLayout(new GridBagLayout());
    pTrackName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Track")));
    addItem(pTrackName, trackName, 0, 0);

    // row 1b
    JPanel pLocationName = new JPanel();
    pLocationName.setLayout(new GridBagLayout());
    pLocationName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Location")));
    addItem(pLocationName, new JLabel(_location.getName()), 0, 0);

    p1.add(pTrackName);
    p1.add(pLocationName);

    // row 3
    JPanel p3 = new JPanel();
    p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
    JScrollPane pane3 = new JScrollPane(p3);
    pane3.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LoadsTrack")));
    pane3.setMaximumSize(new Dimension(2000, 400));

    JPanel pLoadRadioButtons = new JPanel();
    pLoadRadioButtons.setLayout(new FlowLayout());

    pLoadRadioButtons.add(loadNameAll);
    pLoadRadioButtons.add(loadNameInclude);
    pLoadRadioButtons.add(loadNameExclude);
    pLoadRadioButtons.add(loadAndTypeCheckBox);

    pLoadControls.setLayout(new FlowLayout());

    pLoadControls.add(comboBoxTypes);
    pLoadControls.add(comboBoxLoads);
    pLoadControls.add(addLoadButton);
    pLoadControls.add(deleteLoadButton);
    pLoadControls.add(deleteAllLoadsButton);

    pLoadControls.setVisible(false);

    p3.add(pLoadRadioButtons);
    p3.add(pLoadControls);

    // row 4
    panelLoads.setLayout(new GridBagLayout());
    paneLoads.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Loads")));

    ButtonGroup loadGroup = new ButtonGroup();
    loadGroup.add(loadNameAll);
    loadGroup.add(loadNameInclude);
    loadGroup.add(loadNameExclude);

    // row 6
    JPanel p6 = new JPanel();
    p6.setLayout(new BoxLayout(p6, BoxLayout.Y_AXIS));
    paneShipLoadControls = new JScrollPane(p6);
    paneShipLoadControls.setBorder(
        BorderFactory.createTitledBorder(Bundle.getMessage("ShipLoadsTrack")));
    paneShipLoadControls.setMaximumSize(new Dimension(2000, 400));

    JPanel pShipLoadRadioButtons = new JPanel();
    pShipLoadRadioButtons.setLayout(new FlowLayout());

    pShipLoadRadioButtons.add(shipLoadNameAll);
    pShipLoadRadioButtons.add(shipLoadNameInclude);
    pShipLoadRadioButtons.add(shipLoadNameExclude);
    pShipLoadRadioButtons.add(shipLoadAndTypeCheckBox);

    pShipLoadControls.setLayout(new FlowLayout());

    pShipLoadControls.add(comboBoxShipTypes);
    pShipLoadControls.add(comboBoxShipLoads);
    pShipLoadControls.add(addShipLoadButton);
    pShipLoadControls.add(deleteShipLoadButton);
    pShipLoadControls.add(deleteAllShipLoadsButton);

    pShipLoadControls.setVisible(false);

    p6.add(pShipLoadRadioButtons);
    p6.add(pShipLoadControls);

    // row 7
    panelShipLoads.setLayout(new GridBagLayout());
    paneShipLoads.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Loads")));

    ButtonGroup shipLoadGroup = new ButtonGroup();
    shipLoadGroup.add(shipLoadNameAll);
    shipLoadGroup.add(shipLoadNameInclude);
    shipLoadGroup.add(shipLoadNameExclude);

    JPanel pOptions = new JPanel();
    pOptions.setLayout(new GridBagLayout());
    pOptions.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Options")));
    pOptions.setMaximumSize(new Dimension(2000, 400));
    addItem(pOptions, holdCars, 0, 0);
    holdCars.setText(Bundle.getMessage("HoldCarsWithCustomLoads"));
    holdCars.setToolTipText(Bundle.getMessage("HoldCarsWithCustomLoadsTip"));

    // row 12
    JPanel panelButtons = new JPanel();
    panelButtons.setLayout(new GridBagLayout());
    panelButtons.setBorder(BorderFactory.createTitledBorder(""));
    panelButtons.setMaximumSize(new Dimension(2000, 200));

    // row 13
    addItem(panelButtons, saveTrackButton, 0, 0);

    getContentPane().add(p1);
    getContentPane().add(pane3);
    getContentPane().add(paneLoads);
    getContentPane().add(paneShipLoadControls);
    getContentPane().add(paneShipLoads);
    getContentPane().add(pOptions);
    getContentPane().add(panelButtons);

    // setup buttons
    addButtonAction(saveTrackButton);

    addButtonAction(deleteLoadButton);
    addButtonAction(deleteAllLoadsButton);
    addButtonAction(addLoadButton);

    addButtonAction(deleteShipLoadButton);
    addButtonAction(deleteAllShipLoadsButton);
    addButtonAction(addShipLoadButton);

    addRadioButtonAction(loadNameAll);
    addRadioButtonAction(loadNameInclude);
    addRadioButtonAction(loadNameExclude);

    addRadioButtonAction(shipLoadNameAll);
    addRadioButtonAction(shipLoadNameInclude);
    addRadioButtonAction(shipLoadNameExclude);

    addComboBoxAction(comboBoxTypes);
    addComboBoxAction(comboBoxShipTypes);

    paneShipLoadControls.setVisible(false);
    paneShipLoads.setVisible(false);
    pOptions.setVisible(false);

    // load fields and enable buttons
    if (_track != null) {
      _track.addPropertyChangeListener(this);
      trackName.setText(_track.getName());
      // only show ship loads for staging tracks
      paneShipLoadControls.setVisible(_track.getTrackType().equals(Track.STAGING));
      paneShipLoads.setVisible(_track.getTrackType().equals(Track.STAGING));
      pOptions.setVisible(_track.getTrackType().equals(Track.SPUR));
      holdCars.setSelected(_track.isHoldCarsWithCustomLoadsEnabled());
      updateButtons(true);
    } else {
      updateButtons(false);
    }

    // build menu
    // JMenuBar menuBar = new JMenuBar();
    // _toolMenu = new JMenu(Bundle.getMessage("Tools"));
    // menuBar.add(_toolMenu);
    // setJMenuBar(menuBar);
    // load
    updateTypeComboBoxes();
    updateLoadComboBoxes();
    updateLoadNames();
    updateShipLoadNames();

    loadAndTypeCheckBox.setSelected(loadAndType);
    shipLoadAndTypeCheckBox.setSelected(shipLoadAndType);

    initMinimumSize(new Dimension(Control.panelWidth600, Control.panelHeight400));
  }