return allVehicleDisplayPanel;
}
//Otherwise add a label with the route schedule number for each potential vehicle.
for ( int i = 0; i < theInterface.getNumCurrentDisplaySchedules(); i++ ) {
//Get the schedule id and vehicle position.
RouteSchedule rs = theInterface.getDisplaySchedule(theRouteList.getSelectedValue().toString().split(":")[0], i);
String schedId = rs.toString();
String[] vehiclePos = rs.getCurrentStop(theSimulator.getCurrentSimTime(), theSimulator);
String thisVehiclePos = vehiclePos[0];
long timeSecs = Long.parseLong(vehiclePos[1]);
logger.debug(schedId + " is at " + thisVehiclePos + " in " + timeSecs + " seconds with delay " + rs.getDelay() + " minutes.");
/*if ( rs.hasDelay() ) {
theInterface.addMessage(theSimulator.getMessageDisplaySimTime() + ": Vehicle " + schedId + " is running " + rs.getDelay() + " minutes late.");
}*/
//Get direction first of all we are travelling in!
LinkedList<String> outwardStops = new LinkedList<String>();
for ( int j = 0; j < theStopPanels.size(); j++ ) {
outwardStops.add(((JLabel) theStopPanels.get(j).getComponent(0)).getText());
}
int direction = DrawingPanel.RIGHTTOLEFT;
if ( rs.getCurrentService(theSimulator.getCurrentSimTime()) == null ) {
continue; //Don't print if the vehicle is at a terminus.
}
if ( rs.getCurrentService(theSimulator.getCurrentSimTime()).isOutwardService(outwardStops) ) {
direction = DrawingPanel.LEFTTORIGHT;
}
//Now we want to find the position where we draw the triangle i.e. position of JLabel.
int xPos = 0;
String previousStop = "N/A";
for ( int j = 0; j < theStopPanels.size(); j++ ) {
//Each stopPanel has one component which is JLabel.
JLabel myLabel = (JLabel) theStopPanels.get(j).getComponent(0);
//Now check where this stop is and get its position.
//logger.debug("Comparing " + myLabel.getText() + " against " + thisVehiclePos);
if ( myLabel.getText().equalsIgnoreCase(thisVehiclePos) ) {
int panelSize = 800 / theStopPanels.size();
int startPos = 0 + ( panelSize * j);
int endPos = (panelSize * (j+1))-1;
if ( j == (theStopPanels.size()-1) ) {
endPos = (panelSize * (j+1))-(panelSize/2);
}
//Debug.
logger.debug("This is stop " + myLabel.getText() + " - range is from " + startPos + " to " + endPos);
//xPos = startPos + (panelSize/2 - (panelSize/4));
if ( previousStop.equalsIgnoreCase("N/A") ) {
xPos = startPos;
} else {
long maxTimeDiff = Math.abs(rs.getCurrentService(theSimulator.getCurrentSimTime()).getStopMaxTimeDiff(previousStop, myLabel.getText()));
if ( maxTimeDiff == Integer.MAX_VALUE ) {
xPos = startPos;
}
double percent = (double)timeSecs/(double)maxTimeDiff;
logger.debug("Percentage is " + percent + "% for positioning! - timeSecs = " + timeSecs + " and maxTimeDiff = " + maxTimeDiff);
//If inward, then low percentage means close, high means far away.
if ( direction == DrawingPanel.RIGHTTOLEFT ) {
xPos = (int) Math.round((percent * (endPos - startPos))) + startPos;
logger.debug("Recommeding xPos of " + xPos);
} else {
double invertPercent = 1 - percent;
xPos = (int) Math.round((invertPercent * (endPos - startPos))) + startPos;
logger.debug("Recommeding xPos of " + xPos);
}
//xPos = startPos + (panelSize/2 - (panelSize/4));
}
} else {
previousStop = myLabel.getText();
}
}
logger.debug("I'm drawing route schedule " + rs.toString());
JPanel drawPanel = new DrawingPanel(xPos, direction, rs.hasDelay() );
drawPanel.addMouseListener(new BusMouseListener(theInterface.getDisplaySchedule(theRouteList.getSelectedValue().toString().split(":")[0], i), theInterface));
vehiclePanel.add(drawPanel);
allVehicleDisplayPanel.add(vehiclePanel, BorderLayout.CENTER);
allVehicleDisplayPanel.add(makeVehicleInfoPanel(), BorderLayout.SOUTH);
/*JPanel busPanel = new JPanel();