Package trams.data

Examples of trams.data.Route


        theCreateTimetableButton.setEnabled(false);
        theCreateTimetableButton.addActionListener(new ActionListener() {
            public void actionPerformed ( ActionEvent e ) {
                //First of all, set the selected route.
                if ( theSelectedRoute == null && theTimetableModel.getSize() == 0 ) {
                    theSelectedRoute = new Route();
                    theSelectedRoute.setRouteNumber(theRouteNumberField.getText());
                    for ( int i = 0; i < theStopModel.getSize(); i++ ) {
                      theSelectedRoute.addStop(theStopModel.get(i).toString(), Route.OUTWARDSTOPS);
                    }
                    for ( int i = (theStopModel.getSize()-1); i >=0; i-- ) {
View Full Code Here


   
    private Route createAndStoreRoute ( ) {
      //Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        //session.beginTransaction();
       
        Route theRoute = new Route();
        theRoute.setRouteNumber("155");
        theRoute.addStop("Rathaus Pankow", Route.OUTWARDSTOPS);
        theRoute.addStop("Pankow Kirche", Route.OUTWARDSTOPS);
        theRoute.addStop("S + U Pankow", Route.OUTWARDSTOPS);
        theRoute.addStop("S + U Pankow", Route.RETURNSTOPS);
        theRoute.addStop("Pankow Kirche", Route.RETURNSTOPS);
        theRoute.addStop("Rathaus Pankow", Route.RETURNSTOPS);
        List<RouteSchedule> theRouteSchedulesList = new ArrayList<RouteSchedule>();
        theRouteSchedulesList.add(createAndStoreRouteSchedule("155", 1, 0));
        theRoute.setRouteSchedules(theRouteSchedulesList);
        theRoute.addAllocation(theRouteSchedulesList.get(0).toString(), createAndStoreVehicle("CV58 2XD", Calendar.getInstance(), DEPRECIATION_FACTOR, "image.png", "Mercedes", 40, 60, 200.99));
        ServicePattern sp = new ServicePattern("Mon-Fri","2,3,4,5,6","Rathaus Pankow","S + U Pankow",Calendar.getInstance(),Calendar.getInstance(),FREQUENCY,3);
        theRoute.addTimetable("myTimetable", createAndStoreTimetable("myTimetable", Calendar.getInstance(), Calendar.getInstance(), sp));
       
        //session.save(theRoute);
        //session.getTransaction().commit();
        return theRoute;
    }
View Full Code Here

            scenario.appendChild(message);
        }
        //Create route elements.
        for ( int i = 0; i < theSimulator.getScenario().getNumberRoutes(); i++ ) {
            //Store route element - it will be a lot quicker.
            Route myRoute = theSimulator.getScenario().getRoute(i);
            //First of all, create route element.
            Element route = doc.createElement("route");
            route.setAttribute("number", myRoute.getRouteNumber());
            //Now do outward stops.
            Element outstops = doc.createElement("outstops");
            for ( int j = 0; j < myRoute.getNumStops(Route.OUTWARDSTOPS); j++ ) {
                Element outstop = doc.createElement("outstop");
                outstop.setAttribute("name", myRoute.getStop(Route.OUTWARDSTOPS, j).getStopName());
                outstops.appendChild(outstop);
            }
            route.appendChild(outstops);
            //Now do inward stops.
            Element instops = doc.createElement("instops");
            for ( int j = 0; j < myRoute.getNumStops(Route.RETURNSTOPS); j++ ) {
                Element instop = doc.createElement("instop");
                instop.setAttribute("name", myRoute.getStop(Route.RETURNSTOPS, j).getStopName());
                instops.appendChild(instop);
            }
            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; }
View Full Code Here

            for ( int i = 0; i < routeNode.getLength(); i++ ) {
                Element routeElement = (Element) routeNode.item(i);
                //Create the route by creating the route number and valid from and valid to dates.
                String routeNumber = routeElement.getAttribute("number");
                //Create route object.
                Route route = new Route();
                route.setRouteNumber(routeNumber);
                //Now get the outward stops.
                NodeList outwardStopNodes = routeElement.getElementsByTagName("outstop");
                for ( int j = 0; j < outwardStopNodes.getLength(); j++ ) {
                    //Add each stop to the route object.
                    Element stopElement = (Element) outwardStopNodes.item(j);
                    route.addStop(stopElement.getAttribute("name"), Route.OUTWARDSTOPS);
                }
                //Now get the inward stops.
                NodeList inwardStopNodes = routeElement.getElementsByTagName("instop");
                for ( int j = 0; j < inwardStopNodes.getLength(); j++ ) {
                    //Add each stop to the route object.
                    Element stopElement = (Element) inwardStopNodes.item(j);
                    route.addStop(stopElement.getAttribute("name"), Route.RETURNSTOPS);
                }
                //Now go through and get the timetable elements.
                NodeList timetableNodes = routeElement.getElementsByTagName("timetable");
                for ( int j = 0; j < timetableNodes.getLength(); j++ ) {
                    Element timetableElement = (Element) timetableNodes.item(j);
                    //Get timetable information.
                    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);
                route.generateRouteSchedules(outgoingServices, returnServices);
                //Add route.
                //theRoutes.add(route);
                myScenario.addRoute(route);
            }
            //Sixthly, get the vehicles and create relevant vehicle objects.
View Full Code Here

TOP

Related Classes of trams.data.Route

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.