Package trams.data

Examples of trams.data.Timetable


        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++ ) {
View Full Code Here


   
    private Timetable createAndStoreTimetable(String name, Calendar validFromDate, Calendar validToDate, ServicePattern servicePattern) {
        //Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        //session.beginTransaction();

        Timetable theTimetable = new Timetable();
        theTimetable.addServicePattern(servicePattern.getName(), servicePattern);
        theTimetable.setName(name);
        theTimetable.setValidFromDate(validFromDate);
        theTimetable.setValidToDate(validToDate);
       
        return theTimetable;
        //session.save(theTimetable);

        //session.getTransaction().commit();
View Full Code Here

            route.appendChild(instops);
            //Now do timetables for this route.
            Iterator<String> timetableNames = myRoute.getTimetableNames();
            while ( timetableNames.hasNext() ) {
                //Create a timetable element with attributes name, validFrom and validTo dates.
                Timetable myTimetable = myRoute.getTimetable(timetableNames.next());
                Element timetable = doc.createElement("timetable");
                timetable.setAttribute("name", myTimetable.getName());
                //Do valid from date.
                Calendar validFromDate = myTimetable.getValidFrom();
                int vfMonthNum = validFromDate.get(Calendar.MONTH)+1; String vfMonth = "" + vfMonthNum; if ( vfMonthNum < MAX_SINGLE_DIGIT ) { vfMonth = "0" + vfMonthNum; }
                int vfDateNum = validFromDate.get(Calendar.DATE); String vfDate = "" + vfDateNum; if ( vfDateNum < MAX_SINGLE_DIGIT ) { vfDate = "0" + vfDateNum; }
                timetable.setAttribute("validFrom", validFromDate.get(Calendar.YEAR) + "-" + vfMonth + "-" + vfDate );
                //Do valid to date.
                Calendar validToDate = myTimetable.getValidTo();
                int vtMonthNum = validToDate.get(Calendar.MONTH)+1; String vtMonth = "" + vtMonthNum; if ( vtMonthNum < MAX_SINGLE_DIGIT ) { vtMonth = "0" + vtMonthNum; }
                int vtDateNum = validToDate.get(Calendar.DATE); String vtDate = "" + vtDateNum; if ( vtDateNum < MAX_SINGLE_DIGIT ) { vtDate = "0" + vtDateNum; }
                timetable.setAttribute("validTo", validToDate.get(Calendar.YEAR) + "-" + vtMonth + "-" + vtDate );
                //Now for all service patterns.
                Iterator<String> servicePatternNames = myTimetable.getServicePatternNames().iterator();
                while ( servicePatternNames.hasNext() ) {
                    ServicePattern myServicePattern = myTimetable.getServicePattern(servicePatternNames.next());
                    //Create element with appropriate attributes.
                    Element servicePattern = doc.createElement("servicePattern");
                    servicePattern.setAttribute("name", myServicePattern.getName());
                    servicePattern.setAttribute("days", myServicePattern.getDaysOfOperation());
                    servicePattern.setAttribute("returnTerminus", myServicePattern.getReturnTerminus());
View Full Code Here

                    String[] validFromDates = timetableElement.getAttribute("validFrom").split("-");
                    Calendar validFrom = new GregorianCalendar(Integer.parseInt(validFromDates[0]), Integer.parseInt(validFromDates[1])-1, Integer.parseInt(validFromDates[2]));
                    String[] validToDates = timetableElement.getAttribute("validTo").split("-");
                    Calendar validTo = new GregorianCalendar(Integer.parseInt(validToDates[0]), Integer.parseInt(validToDates[1])-1, Integer.parseInt(validToDates[2]));
                    //Create timetable object.
                    Timetable myTimetable = new Timetable(timetableElement.getAttribute("name"), validFrom, validTo);
                    //Now add all service patterns.
                    NodeList serviceNodes = timetableElement.getElementsByTagName("servicePattern");
                    for ( int k = 0; k < serviceNodes.getLength(); k++ ) {
                        Element serviceElement = (Element) serviceNodes.item(k);
                        //Get service information.
                        String daysOfOperation = serviceElement.getAttribute("days");
                        String[] timeFrom = serviceElement.getAttribute("startTime").split(":");
                        Calendar startTime = new GregorianCalendar(2009,Calendar.AUGUST,5,Integer.parseInt(timeFrom[0]),Integer.parseInt(timeFrom[1]));
                        String[] timeTo = serviceElement.getAttribute("endTime").split(":");
                        Calendar endTime = new GregorianCalendar(2009,Calendar.AUGUST,5,Integer.parseInt(timeTo[0]),Integer.parseInt(timeTo[1]));
                        //Create service object.
                        ServicePattern myService = new ServicePattern(serviceElement.getAttribute("name"), daysOfOperation, serviceElement.getAttribute("returnTerminus"), serviceElement.getAttribute("outgoingTerminus"), startTime, endTime, Integer.parseInt(serviceElement.getAttribute("frequency")), Integer.parseInt(serviceElement.getAttribute("duration")));
                        //Add to timetable.
                        myTimetable.addServicePattern(serviceElement.getAttribute("name"), myService);
                    }
                    //Finally add this timetable to the route.
                    logger.debug("Adding " + myTimetable.getName() + " to " + route.getRouteNumber());
                    route.addTimetable(timetableElement.getAttribute("name"), myTimetable);
                }
                //Generate timetables.
                List<Service> outgoingServices = route.generateServiceTimetables(getSimulator().getCurrentSimTime(), myScenario, Route.OUTWARDSTOPS);
                List<Service> returnServices = route.generateServiceTimetables(getSimulator().getCurrentSimTime(), myScenario, Route.RETURNSTOPS);
View Full Code Here

TOP

Related Classes of trams.data.Timetable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.