return routeScreenPanel;
}
public JPanel makeCreateTimetablePanel(String timetableName) {
//Get the timetable here for initialise data parts.
Timetable myTimetable = theSelectedRoute.getTimetable(timetableName);
//Create timetableScreen panel to add things to.
JPanel timetableScreenPanel = new JPanel();
timetableScreenPanel.setLayout ( new BoxLayout ( timetableScreenPanel, BoxLayout.PAGE_AXIS ) );
timetableScreenPanel.setBackground(Color.WHITE);
//Create label at top of screen in a topLabelPanel added to screenPanel.
JPanel topLabelPanel = new JPanel(new BorderLayout());
topLabelPanel.setBackground(Color.WHITE);
JLabel topLabel = new JLabel("Create New Timetable", SwingConstants.CENTER);
if ( myTimetable != null ) {
topLabel.setText("Modify Timetable");
}
topLabel.setFont(new Font("Arial", Font.BOLD, 36));
topLabel.setVerticalAlignment(JLabel.CENTER);
topLabelPanel.add(topLabel, BorderLayout.CENTER);
timetableScreenPanel.add(topLabelPanel);
//Create timetable name panel.
JPanel timetableNamePanel = new JPanel(new GridBagLayout());
timetableNamePanel.setBackground(Color.WHITE);
JLabel timetableNameLabel = new JLabel("Name: ");
timetableNameLabel.setFont(new Font("Arial", Font.ITALIC, 16));
timetableNamePanel.add(timetableNameLabel);
theTimetableNameField = new JTextField(20);
if ( myTimetable != null ) { theTimetableNameField.setText(myTimetable.getName()); }
theTimetableNameField.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
if ( !theTimetableNameField.getText().equalsIgnoreCase("") ) {
theCreateServicePatternButton.setEnabled(true);
} else {
theCreateServicePatternButton.setEnabled(false);
}
}
public void keyTyped(KeyEvent e) { }
public void keyPressed(KeyEvent e) { }
});
theTimetableNameField.setFont(new Font("Arial", Font.PLAIN, MEDIUM_FONT_SIZE));
timetableNamePanel.add(theTimetableNameField);
timetableScreenPanel.add(timetableNamePanel);
//Create panel for validity first of all.
JPanel validityPanel = new JPanel(new GridBagLayout());
validityPanel.setBackground(Color.WHITE);
JLabel validFromLabel = new JLabel("Valid From: ", SwingConstants.CENTER);
validFromLabel.setFont(new Font("Arial", Font.ITALIC, 16));
validityPanel.add(validFromLabel);
//Get the calendar object with current time.
Calendar currTime = (Calendar) theInterface.getCurrentSimTime().clone();
currTime.add(Calendar.HOUR, 0); //Change this to 48!!!!
//Valid From Day.
theFromStartDay = currTime.get(Calendar.DAY_OF_MONTH);
theValidFromDayModel = new DefaultComboBoxModel();
for ( int i = currTime.get(Calendar.DAY_OF_MONTH); i <= getMonthLen(getMonth(currTime.get(Calendar.MONTH))); i++ ) {
theValidFromDayModel.addElement(i);
}
JComboBox validFromDayBox = new JComboBox(theValidFromDayModel);
if ( myTimetable != null ) {
validFromDayBox.setSelectedItem(myTimetable.getValidFrom().get(Calendar.DAY_OF_MONTH));
}
validFromDayBox.setFont(new Font("Arial", Font.PLAIN, MEDIUM_FONT_SIZE));
validityPanel.add(validFromDayBox);
//Valid From Month.
theValidFromMonthBox = new JComboBox();
for ( int i = 0; i < 4; i++ ) {
theValidFromMonthBox.addItem(getMonth(currTime.get(Calendar.MONTH)) + " " + currTime.get(Calendar.YEAR));
currTime.add(Calendar.MONTH, 1);
}
if ( myTimetable != null ) {
theValidFromMonthBox.setSelectedItem(getMonth(myTimetable.getValidFrom().get(Calendar.MONTH)) + " " + myTimetable.getValidFrom().get(Calendar.YEAR));
}
theValidFromMonthBox.setFont(new Font("Arial", Font.PLAIN, MEDIUM_FONT_SIZE));
theValidFromMonthBox.addActionListener( new ActionListener() {
public void actionPerformed ( ActionEvent e ) {
String month = theValidFromMonthBox.getSelectedItem().toString().split(" ")[0];
if ( theValidFromMonthBox.getSelectedIndex() == 0 ) {
theValidFromDayModel.removeAllElements();
for ( int i = theFromStartDay; i <= getMonthLen(month); i++ ) {
theValidFromDayModel.addElement(i);
}
} else {
theValidFromDayModel.removeAllElements();
for ( int i = 1; i <= getMonthLen(month); i++ ) {
theValidFromDayModel.addElement(i);
}
}
}
});
validityPanel.add(theValidFromMonthBox);
//Valid to!!!
JLabel validToLabel = new JLabel("Valid To: ", SwingConstants.CENTER);
validToLabel.setFont(new Font("Arial", Font.ITALIC, 16));
validityPanel.add(validToLabel);
//Get the calendar object with current time.
Calendar myCurrTime = (Calendar) theInterface.getCurrentSimTime().clone();
myCurrTime.add(Calendar.HOUR, 72);
//Valid To Day.
theToStartDay = myCurrTime.get(Calendar.DAY_OF_MONTH);
theValidToDayModel = new DefaultComboBoxModel();
for ( int i = myCurrTime.get(Calendar.DAY_OF_MONTH); i <= getMonthLen(getMonth(myCurrTime.get(Calendar.MONTH))); i++ ) {
theValidToDayModel.addElement(i);
}
JComboBox validToDayBox = new JComboBox(theValidToDayModel);
if ( myTimetable != null ) {
validToDayBox.setSelectedItem(myTimetable.getValidTo().get(Calendar.DAY_OF_MONTH));
}
validToDayBox.setFont(new Font("Arial", Font.PLAIN, MEDIUM_FONT_SIZE));
validityPanel.add(validToDayBox);
//Valid To Month.
theValidToMonthBox = new JComboBox();
for ( int i = 0; i < 25; i++ ) {
theValidToMonthBox.addItem(getMonth(myCurrTime.get(Calendar.MONTH)) + " " + myCurrTime.get(Calendar.YEAR));
myCurrTime.add(Calendar.MONTH, 1);
}
if ( myTimetable != null ) {
theValidToMonthBox.setSelectedItem(getMonth(myTimetable.getValidTo().get(Calendar.MONTH)) + " " + myTimetable.getValidTo().get(Calendar.YEAR));
}
theValidToMonthBox.setFont(new Font("Arial", Font.PLAIN, MEDIUM_FONT_SIZE));
theValidToMonthBox.addActionListener( new ActionListener() {
public void actionPerformed ( ActionEvent e ) {
String month = theValidToMonthBox.getSelectedItem().toString().split(" ")[0];
if ( theValidToMonthBox.getSelectedIndex() == 0 ) {
theValidToDayModel.removeAllElements();
for ( int i = theToStartDay; i <= getMonthLen(month); i++ ) {
theValidToDayModel.addElement(i);
}
} else {
theValidToDayModel.removeAllElements();
for ( int i = 1; i <= getMonthLen(month); i++ ) {
theValidToDayModel.addElement(i);
}
}
}
});
validityPanel.add(theValidToMonthBox);
//Add validityPanel to the screen panel.
timetableScreenPanel.add(validityPanel);
timetableScreenPanel.add(Box.createRigidArea(new Dimension(0,DIMENSION_SPACER))); //Spacer.
//Create label in middle of screen in a middleLabelPanel added to screenPanel.
JPanel middleLabelPanel = new JPanel(new BorderLayout());
middleLabelPanel.setBackground(Color.WHITE);
JLabel middleLabel = new JLabel("Service Pattern(s)", SwingConstants.CENTER);
middleLabel.setFont(new Font("Arial", Font.BOLD, 36));
middleLabel.setVerticalAlignment(JLabel.CENTER);
middleLabelPanel.add(middleLabel, BorderLayout.CENTER);
timetableScreenPanel.add(middleLabelPanel);
//Create the servicePattern list panel and three buttons.
JPanel servicePatternListPanel = new JPanel(new BorderLayout());
servicePatternListPanel.setBackground(Color.WHITE);
//Here is the actual service pattern list.
JPanel centreServicePatternListPanel = new JPanel(new GridBagLayout());
centreServicePatternListPanel.setBackground(Color.WHITE);
theServicePatternModel = new DefaultListModel();
//Now get all the service pattern which we have at the moment.
try {
Iterator<String> patternKeys = theSelectedRoute.getTimetable(theTimetableNameField.getText()).getServicePatternNames().iterator();
while ( patternKeys.hasNext() ) {
String servicePatternName = patternKeys.next();
theServicePatternModel.addElement(theSelectedRoute.getTimetable(theTimetableNameField.getText()).getServicePattern(servicePatternName).getName());
}
} catch (NullPointerException npe) { }
theServicePatternList = new JList(theServicePatternModel);
if ( theServicePatternModel.getSize() > 0 ) { theServicePatternList.setSelectedIndex(0); }
theServicePatternList.setVisibleRowCount(3);
theServicePatternList.setFixedCellWidth(450);
theServicePatternList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane timetablePane = new JScrollPane(theServicePatternList);
centreServicePatternListPanel.add(timetablePane);
servicePatternListPanel.add(centreServicePatternListPanel, BorderLayout.CENTER);
//Now the three create, modify and delete button.
JPanel servicePatternButtonPanel = new JPanel();
servicePatternButtonPanel.setBackground(Color.WHITE);
theCreateServicePatternButton = new JButton("Create");
if (theTimetableNameField.getText().equalsIgnoreCase("")) { theCreateServicePatternButton.setEnabled(false); }
theCreateServicePatternButton.addActionListener(new ActionListener() {
public void actionPerformed ( ActionEvent e ) {
//Create relevant calendar object.
if ( theSelectedRoute.getTimetable(theTimetableNameField.getText()) == null) {
int vfYear = Integer.parseInt(theValidFromMonthBox.getSelectedItem().toString().split(" ")[1]);
int vfMonth = getMonthNumber(theValidFromMonthBox.getSelectedItem().toString().split(" ")[0]);
int vfDay = Integer.parseInt(theValidFromDayModel.getSelectedItem().toString());
GregorianCalendar validFrom = new GregorianCalendar(vfYear, vfMonth, vfDay);
int vtYear = Integer.parseInt(theValidToMonthBox.getSelectedItem().toString().split(" ")[1]);
int vtMonth = getMonthNumber(theValidToMonthBox.getSelectedItem().toString().split(" ")[0]);
int vtDay = Integer.parseInt(theValidToDayModel.getSelectedItem().toString());
GregorianCalendar validTo = new GregorianCalendar(vtYear, vtMonth, vtDay);
//Save this timetable with valid dates first.
theSelectedRoute.addTimetable(theTimetableNameField.getText(), new Timetable(theTimetableNameField.getText(), validFrom, validTo));
//logger.debug("Adding timetable with name " + theTimetableNameField.getText() + " to route " + theSelectedRoute.getRouteNumber());
}
//Process the stops.
ArrayList<String> stops = new ArrayList<String>();
for ( int i = 0; i < theStopModel.getSize(); i++ ) {