Fix issue with inconsistent formatting of "GPS off" buses.
[frank.git] / prod / net / jaekl / frank / Schedule.java
index edd1b398a602afff7e23aa734d892ee5de6c8a1f..eb8cb2bce26cee168d800d2baef13770ff96c580 100644 (file)
@@ -13,13 +13,15 @@ import net.jaekl.frank.octranspo.StopInfo;
 import net.jaekl.frank.octranspo.Trip;
 
 public class Schedule {
-       Locale m_locale;
-       FrankBundle m_bundle;
        DateFormat m_hourMinFmt;
        DateFormat m_hourMinSecFmt;
+       FrankBundle m_bundle;
+       Locale m_locale;
+       Style m_style;
        
        public Schedule(Locale locale) {
                m_locale = locale;
+               m_style = new Style();
                m_bundle = FrankBundle.getInst(locale);
                m_hourMinFmt = new SimpleDateFormat("hh:mma", locale);
                m_hourMinSecFmt = new SimpleDateFormat("hh:mm:ssa", locale);
@@ -40,17 +42,7 @@ public class Schedule {
        String mapUrl(double latitude, double longitude) {
                return "http://www.openstreetmap.org/?mlat=" + latitude + "&mlon=" + longitude + "&zoom=15";
        }
-       
-       void writeStyle(PrintWriter pw) {
-               pw.println("<STYLE>");
-               pw.println("  body {background-color: #F0F0C0; font-size: 1.5em; }");
-               pw.println("  #trips {border-collapse: collapse; font-size: 1.5em; }");
-               pw.println("  #trips td, #trips th {border: 1px solid #600000; padding: 3px 3px 3px 3px; text-align: center;}");
-               pw.println("  #trips th {background-color: #800000; color: #FFFFFF; }");
-               pw.println("  #trips tr.ghost td {background-color: #C0C0C0;}");
-               pw.println("</STYLE>");
-       }
-       
+
        // Countdown timer that updates time remaining until each bus is expected.
        void writeScript(PrintWriter pw, String remainArray, int remainCount) {
                String min = trans(FrankBundle.MINUTES);
@@ -70,7 +62,7 @@ public class Schedule {
            pw.println("    if (remain_delta <= 0) {");
            pw.println("      element.innerHTML = \"----\";");
            pw.println("    } else {");
-           pw.println("      element.innerHTML = (Math.floor(remain_delta / 60)) + \"" + trans(min) + "\";");
+           pw.println("      element.innerHTML = (Math.floor(remain_delta / 60)) + \"" + min + "\";");
            pw.println("    }");
            pw.println("  }");
            pw.println("}");
@@ -82,7 +74,7 @@ public class Schedule {
                pw.println("<HTML>");
                pw.println("<HEAD>");
                pw.println("<TITLE>" + title + "</TITLE>");
-               writeStyle(pw);
+               new Style().writeStyle(pw);
                pw.println("</HEAD>");
        }
        
@@ -115,7 +107,7 @@ public class Schedule {
                        Route route = stopInfo.getRoute(routeIdx);
                        for (int tripIdx = 0; tripIdx < route.getNumTrips(); ++tripIdx) {
                                Trip trip = route.getTrip(tripIdx);
-                               boolean isGhost = ((-1) == trip.getAdjAge());
+                               boolean isGhost = (trip.getAdjAge() < 0);
                                if (isGhost) {
                                        // GPS is off.  This bus may not exist.
                                        pw.println("    <TR CLASS=\"ghost\">");
@@ -133,7 +125,7 @@ public class Schedule {
                                remainArray.append(trip.getAdjTime());
                                remainCount++;
                                
-                               if (trip.getAdjAge() < 0) {
+                               if (isGhost) {
                                        pw.println("      <TD>" + trans(FrankBundle.GPS_OFF) + "</TD>");
                                }
                                else {